123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- <template>
- <view class="more-box-wrapper">
- <view class="div more-box">
- <view class="div more-item" @click="goNavigate('/pages/home/index/Index',false,1)"><text class="i iconfont"></text>首页</view>
- <view class="div more-item" @click="goNavigate('/pages/member/inform/InformForm',{goods_id:goods_id})" v-if="routerName === 'pages/home/goodsdetail/Goodsdetail'"><text class="i iconfont"></text>违规举报</view>
- <view class="div more-item" @click="goNavigate('/pages/home/search/Search')" v-if="routerName !== 'pages/home/goodsdetail/Goodsdetail'"><text class="i iconfont"></text>搜索</view>
- <view class="div more-item" @click="goNavigate('/pages/member/cart/Cart')" v-if="routerName !== 'pages/home/goodsdetail/Goodsdetail'"><text class="i iconfont"></text>购物车</view>
- <view class="div more-item" v-if="config && config.instant_message_open == '1' && config.instant_message_gateway_url" @click="goNavigate('/pages/member/chat/ChatList')"><text class="i iconfont"></text>聊天消息<view v-if="showDot && showDot.chat" class="div dot"></view></view>
- <view class="div more-item" @click="goNavigate('/pages/member/index/Index',false,1)"><text class="i iconfont"></text>我的商城</view>
- <view class="div more-item" @click.stop="onShare"><text class="i iconfont"></text>分享</view>
- <text class="i arrow"></text>
-
- <uni-popup background-color="#fff" ref="shareVisible" type="bottom">
- <view class="div common-header-wrap">
- <uni-nav-bar title="分享至" class="common-header" left-icon="back" @clickLeft="hidePopup('shareVisible')">
- </uni-nav-bar>
- </view>
- <view class="div common-popup-content">
- <view class="div share-list">
- <!-- #ifdef APP-PLUS -->
- <view class="div share-item weixin" @click.stop="goWeixin(1)">微信好友</view>
- <view class="div share-item pengyou" @click.stop="goWeixin(2)">微信朋友圈</view>
- <!-- #endif -->
- <view class="div share-item copy" @click.stop="showLink">复制</view>
- <view class="div share-item goods" v-if="goods_id" @click.stop="goodsPoster">海报</view>
- </view>
- </view>
- </uni-popup>
-
- <uni-popup background-color="#fff" ref="copyVisible">
- <view class="copy-wrapper">
- <view class="div title">您的浏览器不支持直接复制,请手动复制</view>
- <input type="text" :value="copyLink" onfocus="this.select()" >
- </view>
- </uni-popup>
-
- <uni-popup background-color="#fff" ref="popupVisible">
- <image mode="widthFix" class="img" :src="posterUrl" :style="getBannerStyle" @click="hidePopup('popupVisible')">
- </uni-popup>
- </view>
- </view>
-
- </template>
- <script>
- import { urlencode,loadScript } from '@/util/common'
- import { goodsPoster } from '../api/member'
- import { getWechatShare } from '../api/common'
- import { isWechat } from '../util/wechat'
- import { mapState, mapMutations, mapActions } from 'vuex'
- import { env } from '@/static/config'
- export default {
- name: 'HeaderMore',
- data () {
- return {
- routerName:'',
- currentUrl:'',
- posterUrl: '',
- }
- },
- components: {
- },
- mounted: function () {
- var pages = getCurrentPages()
- var page = pages[pages.length - 1]
- this.routerName=page ? page.route : ''
- this.currentUrl=env.H5_HOST + page.route+(page.options?('?'+urlencode(page.options)):'')
- },
- props: {
- goods_id: {},
- share_info: {},
- showDot: {}
- },
- computed: {
- ...mapState({
- user: state => state.member.info,
- config: state => state.config.config
- }),
- shareInfo:function(){
- var shareInfo
- if(!this.share_info){
- if(this.config){
- shareInfo = { title: this.config.site_name, link: this.currentUrl, imgUrl: this.config.site_mobile_logo, desc: this.config.site_name }
- }else{
- shareInfo = {}
- }
-
- }else{
- shareInfo = this.share_info
- }
- // #ifdef H5
- if(this.config && isWechat() && this.config.wechat_appid && shareInfo.title){
- this.setWechat(shareInfo)
- }
- // #endif
- return shareInfo
- },
- getBannerStyle: function () {
- const res = uni.getSystemInfoSync()
- var width = res.windowWidth
- var height = res.windowHeight
- let itemWidth = width - 20
- let itemHeight = height - 20
- return "width:"+itemWidth +"px"
- },
- copyLink () {
- var link = ''
- if (this.shareInfo && this.shareInfo.link) {
- link = this.shareInfo.link
- } else {
- link = this.currentUrl
- }
- if (this.user) {
- if (link.indexOf('?') != -1) {
- link += '&'
- } else {
- link += '?'
- }
- link += 'inviter_id=' + this.user.member_id
- }
- return link
- },
- getWrapperStyle: function () {
- const res = uni.getSystemInfoSync()
- var width = res.windowWidth
- var height = res.windowHeight
- return "width:"+width +"px;height:"+height +"px"
- }
- },
- methods:{
- goNavigate(path,query=false,type=0){
- var url=path+(query?('?'+urlencode(query)):'')
- if(type){
- uni.redirectTo({url:url})
- }else{
- uni.navigateTo({url:url})
- }
-
- },
- showPopup(id){
- this.$refs[id].open()
- },
- hidePopup(id){
- this.$refs[id].close()
- },
- goWeixin (type) {
- // #ifdef APP-PLUS
- uni.share({
- provider: 'weixin',
- scene: (type==2)?'WXSenceTimeline':'WXSceneSession',
- type: 0,
- href: this.copyLink,
- title: this.shareInfo.title,
- summary: this.shareInfo.desc,
- imageUrl: this.shareInfo.imgUrl,
- success: function(res) {
- },
- fail: function(err) {
- uni.showToast({
- icon: 'loading',
- title: '分享失败'
- })
- }
- })
- // #endif
- },
- goodsPoster () {
- goodsPoster(this.goods_id).then(res => {
- this.posterUrl = res.result.goods_poster
- this.showPopup('popupVisible')
- // #ifdef H5
- uni.setClipboardData({
- data: this.posterUrl,
- success: function () {
- uni.showToast({icon:'none',title: '图片路径已复制'})
- }
- });
- // #endif
- // #ifndef H5
- uni.downloadFile({
- url: this.posterUrl,
- success: (res) => {
- uni.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success: function () {
- uni.showToast({icon:'none',title: '图片保存成功'})
- }
- });
- }
- })
- // #endif
- }).catch(error => {
- uni.showToast({icon:'none',title: error.message})
- })
- },
- showLink () {
- // #ifdef H5
- if (window.clipboardData) {
- window.clipboardData.clearData()
- window.clipboardData.setData('Text', this.copyLink)
- uni.showToast({icon:'none',title: '复制成功!'})
- } else {
- this.showPopup('copyVisible')
- }
- // #endif
- // #ifndef H5
- var _this=this
- uni.setClipboardData({
- data: this.copyLink,
- success: function () {
- uni.showToast({
- icon: 'none',
- title: '复制成功!'
- })
- },
- fail:function () {
- _this.showPopup('popup_copy')
- }
- })
- // #endif
- },
- onShare () {
- this.showPopup('shareVisible')
- },
- setWechat (share_info) {
- var _this = this
- getWechatShare(encodeURIComponent(this.currentUrl)).then(res => {
- loadScript('weixin', 'https://res.wx.qq.com/open/js/jweixin-1.3.2.js', function () {
- wx.config({
- debug: false,
- appId: res.result.signPackage.appId,
- timestamp: res.result.signPackage.timestamp,
- nonceStr: res.result.signPackage.nonceStr,
- signature: res.result.signPackage.signature,
- jsApiList: [
- // 所有要调用的 API 都要加到这个列表中
- 'onMenuShareTimeline',
- 'onMenuShareAppMessage',
- 'onMenuShareQQ',
- 'onMenuShareWeibo',
- 'onMenuShareQZone'
- ]
- })
- wx.ready(function () {
- wx.onMenuShareAppMessage({
- title: share_info.title,
- link: _this.copyLink,
- imgUrl: share_info.imgUrl,
- desc: share_info.desc // 分享描述
- })
- wx.onMenuShareTimeline({
- title: share_info.title,
- link: _this.copyLink,
- imgUrl: share_info.imgUrl,
- desc: share_info.desc
- })
- wx.onMenuShareQQ({
- title: share_info.title, // 分享标题
- desc: share_info.desc, // 分享描述
- link: _this.copyLink, // 分享链接
- imgUrl: share_info.imgUrl // 分享图标
- })
- wx.onMenuShareWeibo({
- title: share_info.title, // 分享标题
- desc: share_info.desc, // 分享描述
- link: _this.copyLink, // 分享链接
- imgUrl: share_info.imgUrl // 分享图标
- })
- wx.onMenuShareQZone({
- title: share_info.title, // 分享标题
- desc: share_info.desc, // 分享描述
- link: _this.copyLink, // 分享链接
- imgUrl: share_info.imgUrl // 分享图标
- })
- })
- wx.error(function (res) {
- })
- })
- }).catch(function (error) {
- uni.showToast({icon:'none',title: error.message})
- })
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .more-box-wrapper{position:relative}
- .more-box{background:#000;position:absolute;width:5.6rem;z-index:11;right:0.3rem;top:0;border-radius:0.2rem;}
- .more-item{border-bottom: 1px solid hsla(0,0%,100%,.2);height: 2rem;line-height: 2rem;list-style: none outside none;color:#fff;font-size:$subFontSize;position:relative}
- .more-item .i{margin:0 0.4rem;}
- .more-item .dot{position:absolute;width:.5rem;height:.5rem;background:red;border-radius:50%;top:.5rem;left:1rem;}
- .arrow {
- position:absolute;
- display: block;
- right:0.2rem;
- top:-0.7rem;
- width: 0;
- height: 0;
- margin-right: 0.45rem;
- font-size: 0;
- line-height: 0;
- border-width: 0.4rem;
- border-color: transparent transparent rgb(0,0,0) transparent;
- border-style: dashed dashed solid dashed;
- }
- .common-popup-wrapper{height:10rem;overflow: visible}
- .more-box .share-list{display:flex}
- .more-box .share-list .share-item{height: 3rem;margin:1rem 0.8rem;width:2.5rem;padding-left:0;background: none;text-align:center;color: #333;font-size:$fontSize;}
- .more-box .share-list .share-item:before{font-family: "iconfont";content:'';display:block;border-radius:50%;width:2rem;height:2rem;line-height:2rem;text-align:center;font-size:1.2rem;color:#fff;background: red;margin:0 auto;margin-bottom:.25rem}
- .more-box .share-list .share-item.weixin:before{content:"\e647";background:#C71585;}
- .more-box .share-list .share-item.pengyou:before{content:"\e645";background:#ffaa00;}
- .more-box .share-list .share-item.copy:before{content:"\e64b";background:#228B22;}
- .more-box .share-list .share-item.goods:before{content:"\e6dd";background:#f44336;}
- .more-box .weixin-share-wrapper{position: absolute;bottom:0;left:0;text-align: right}
- .more-box .weixin-share{height:10rem;}
- .copy-wrapper{padding:1rem;}
- .copy-wrapper input{height:1.5rem;line-height:1.5rem;padding:0 .2rem;width:12rem;border:1px solid #e1e1e1}
- .copy-wrapper .title{font-size:$fontSize;text-align: center;margin-bottom:.5rem;}
- </style>
|