HeaderMore.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <view class="more-box-wrapper">
  3. <view class="div more-box">
  4. <view class="div more-item" @click="goNavigate('/pages/home/index/Index',false,1)"><text class="i iconfont">&#xe6b2;</text>首页</view>
  5. <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">&#xe6a3;</text>违规举报</view>
  6. <view class="div more-item" @click="goNavigate('/pages/home/search/Search')" v-if="routerName !== 'pages/home/goodsdetail/Goodsdetail'"><text class="i iconfont">&#xe61f;</text>搜索</view>
  7. <view class="div more-item" @click="goNavigate('/pages/member/cart/Cart')" v-if="routerName !== 'pages/home/goodsdetail/Goodsdetail'"><text class="i iconfont">&#xe6ae;</text>购物车</view>
  8. <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">&#xe67c;</text>聊天消息<view v-if="showDot && showDot.chat" class="div dot"></view></view>
  9. <view class="div more-item" @click="goNavigate('/pages/member/index/Index',false,1)"><text class="i iconfont">&#xe6b4;</text>我的商城</view>
  10. <view class="div more-item" @click.stop="onShare"><text class="i iconfont">&#xe625;</text>分享</view>
  11. <text class="i arrow"></text>
  12. <uni-popup background-color="#fff" ref="shareVisible" type="bottom">
  13. <view class="div common-header-wrap">
  14. <uni-nav-bar title="分享至" class="common-header" left-icon="back" @clickLeft="hidePopup('shareVisible')">
  15. </uni-nav-bar>
  16. </view>
  17. <view class="div common-popup-content">
  18. <view class="div share-list">
  19. <!-- #ifdef APP-PLUS -->
  20. <view class="div share-item weixin" @click.stop="goWeixin(1)">微信好友</view>
  21. <view class="div share-item pengyou" @click.stop="goWeixin(2)">微信朋友圈</view>
  22. <!-- #endif -->
  23. <view class="div share-item copy" @click.stop="showLink">复制</view>
  24. <view class="div share-item goods" v-if="goods_id" @click.stop="goodsPoster">海报</view>
  25. </view>
  26. </view>
  27. </uni-popup>
  28. <uni-popup background-color="#fff" ref="copyVisible">
  29. <view class="copy-wrapper">
  30. <view class="div title">您的浏览器不支持直接复制,请手动复制</view>
  31. <input type="text" :value="copyLink" onfocus="this.select()" >
  32. </view>
  33. </uni-popup>
  34. <uni-popup background-color="#fff" ref="popupVisible">
  35. <image mode="widthFix" class="img" :src="posterUrl" :style="getBannerStyle" @click="hidePopup('popupVisible')">
  36. </uni-popup>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import { urlencode,loadScript } from '@/util/common'
  42. import { goodsPoster } from '../api/member'
  43. import { getWechatShare } from '../api/common'
  44. import { isWechat } from '../util/wechat'
  45. import { mapState, mapMutations, mapActions } from 'vuex'
  46. import { env } from '@/static/config'
  47. export default {
  48. name: 'HeaderMore',
  49. data () {
  50. return {
  51. routerName:'',
  52. currentUrl:'',
  53. posterUrl: '',
  54. }
  55. },
  56. components: {
  57. },
  58. mounted: function () {
  59. var pages = getCurrentPages()
  60. var page = pages[pages.length - 1]
  61. this.routerName=page ? page.route : ''
  62. this.currentUrl=env.H5_HOST + page.route+(page.options?('?'+urlencode(page.options)):'')
  63. },
  64. props: {
  65. goods_id: {},
  66. share_info: {},
  67. showDot: {}
  68. },
  69. computed: {
  70. ...mapState({
  71. user: state => state.member.info,
  72. config: state => state.config.config
  73. }),
  74. shareInfo:function(){
  75. var shareInfo
  76. if(!this.share_info){
  77. if(this.config){
  78. shareInfo = { title: this.config.site_name, link: this.currentUrl, imgUrl: this.config.site_mobile_logo, desc: this.config.site_name }
  79. }else{
  80. shareInfo = {}
  81. }
  82. }else{
  83. shareInfo = this.share_info
  84. }
  85. // #ifdef H5
  86. if(this.config && isWechat() && this.config.wechat_appid && shareInfo.title){
  87. this.setWechat(shareInfo)
  88. }
  89. // #endif
  90. return shareInfo
  91. },
  92. getBannerStyle: function () {
  93. const res = uni.getSystemInfoSync()
  94. var width = res.windowWidth
  95. var height = res.windowHeight
  96. let itemWidth = width - 20
  97. let itemHeight = height - 20
  98. return "width:"+itemWidth +"px"
  99. },
  100. copyLink () {
  101. var link = ''
  102. if (this.shareInfo && this.shareInfo.link) {
  103. link = this.shareInfo.link
  104. } else {
  105. link = this.currentUrl
  106. }
  107. if (this.user) {
  108. if (link.indexOf('?') != -1) {
  109. link += '&'
  110. } else {
  111. link += '?'
  112. }
  113. link += 'inviter_id=' + this.user.member_id
  114. }
  115. return link
  116. },
  117. getWrapperStyle: function () {
  118. const res = uni.getSystemInfoSync()
  119. var width = res.windowWidth
  120. var height = res.windowHeight
  121. return "width:"+width +"px;height:"+height +"px"
  122. }
  123. },
  124. methods:{
  125. goNavigate(path,query=false,type=0){
  126. var url=path+(query?('?'+urlencode(query)):'')
  127. if(type){
  128. uni.redirectTo({url:url})
  129. }else{
  130. uni.navigateTo({url:url})
  131. }
  132. },
  133. showPopup(id){
  134. this.$refs[id].open()
  135. },
  136. hidePopup(id){
  137. this.$refs[id].close()
  138. },
  139. goWeixin (type) {
  140. // #ifdef APP-PLUS
  141. uni.share({
  142. provider: 'weixin',
  143. scene: (type==2)?'WXSenceTimeline':'WXSceneSession',
  144. type: 0,
  145. href: this.copyLink,
  146. title: this.shareInfo.title,
  147. summary: this.shareInfo.desc,
  148. imageUrl: this.shareInfo.imgUrl,
  149. success: function(res) {
  150. },
  151. fail: function(err) {
  152. uni.showToast({
  153. icon: 'loading',
  154. title: '分享失败'
  155. })
  156. }
  157. })
  158. // #endif
  159. },
  160. goodsPoster () {
  161. goodsPoster(this.goods_id).then(res => {
  162. this.posterUrl = res.result.goods_poster
  163. this.showPopup('popupVisible')
  164. // #ifdef H5
  165. uni.setClipboardData({
  166. data: this.posterUrl,
  167. success: function () {
  168. uni.showToast({icon:'none',title: '图片路径已复制'})
  169. }
  170. });
  171. // #endif
  172. // #ifndef H5
  173. uni.downloadFile({
  174. url: this.posterUrl,
  175. success: (res) => {
  176. uni.saveImageToPhotosAlbum({
  177. filePath: res.tempFilePath,
  178. success: function () {
  179. uni.showToast({icon:'none',title: '图片保存成功'})
  180. }
  181. });
  182. }
  183. })
  184. // #endif
  185. }).catch(error => {
  186. uni.showToast({icon:'none',title: error.message})
  187. })
  188. },
  189. showLink () {
  190. // #ifdef H5
  191. if (window.clipboardData) {
  192. window.clipboardData.clearData()
  193. window.clipboardData.setData('Text', this.copyLink)
  194. uni.showToast({icon:'none',title: '复制成功!'})
  195. } else {
  196. this.showPopup('copyVisible')
  197. }
  198. // #endif
  199. // #ifndef H5
  200. var _this=this
  201. uni.setClipboardData({
  202. data: this.copyLink,
  203. success: function () {
  204. uni.showToast({
  205. icon: 'none',
  206. title: '复制成功!'
  207. })
  208. },
  209. fail:function () {
  210. _this.showPopup('popup_copy')
  211. }
  212. })
  213. // #endif
  214. },
  215. onShare () {
  216. this.showPopup('shareVisible')
  217. },
  218. setWechat (share_info) {
  219. var _this = this
  220. getWechatShare(encodeURIComponent(this.currentUrl)).then(res => {
  221. loadScript('weixin', 'https://res.wx.qq.com/open/js/jweixin-1.3.2.js', function () {
  222. wx.config({
  223. debug: false,
  224. appId: res.result.signPackage.appId,
  225. timestamp: res.result.signPackage.timestamp,
  226. nonceStr: res.result.signPackage.nonceStr,
  227. signature: res.result.signPackage.signature,
  228. jsApiList: [
  229. // 所有要调用的 API 都要加到这个列表中
  230. 'onMenuShareTimeline',
  231. 'onMenuShareAppMessage',
  232. 'onMenuShareQQ',
  233. 'onMenuShareWeibo',
  234. 'onMenuShareQZone'
  235. ]
  236. })
  237. wx.ready(function () {
  238. wx.onMenuShareAppMessage({
  239. title: share_info.title,
  240. link: _this.copyLink,
  241. imgUrl: share_info.imgUrl,
  242. desc: share_info.desc // 分享描述
  243. })
  244. wx.onMenuShareTimeline({
  245. title: share_info.title,
  246. link: _this.copyLink,
  247. imgUrl: share_info.imgUrl,
  248. desc: share_info.desc
  249. })
  250. wx.onMenuShareQQ({
  251. title: share_info.title, // 分享标题
  252. desc: share_info.desc, // 分享描述
  253. link: _this.copyLink, // 分享链接
  254. imgUrl: share_info.imgUrl // 分享图标
  255. })
  256. wx.onMenuShareWeibo({
  257. title: share_info.title, // 分享标题
  258. desc: share_info.desc, // 分享描述
  259. link: _this.copyLink, // 分享链接
  260. imgUrl: share_info.imgUrl // 分享图标
  261. })
  262. wx.onMenuShareQZone({
  263. title: share_info.title, // 分享标题
  264. desc: share_info.desc, // 分享描述
  265. link: _this.copyLink, // 分享链接
  266. imgUrl: share_info.imgUrl // 分享图标
  267. })
  268. })
  269. wx.error(function (res) {
  270. })
  271. })
  272. }).catch(function (error) {
  273. uni.showToast({icon:'none',title: error.message})
  274. })
  275. }
  276. }
  277. }
  278. </script>
  279. <style scoped lang="scss">
  280. .more-box-wrapper{position:relative}
  281. .more-box{background:#000;position:absolute;width:5.6rem;z-index:11;right:0.3rem;top:0;border-radius:0.2rem;}
  282. .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}
  283. .more-item .i{margin:0 0.4rem;}
  284. .more-item .dot{position:absolute;width:.5rem;height:.5rem;background:red;border-radius:50%;top:.5rem;left:1rem;}
  285. .arrow {
  286. position:absolute;
  287. display: block;
  288. right:0.2rem;
  289. top:-0.7rem;
  290. width: 0;
  291. height: 0;
  292. margin-right: 0.45rem;
  293. font-size: 0;
  294. line-height: 0;
  295. border-width: 0.4rem;
  296. border-color: transparent transparent rgb(0,0,0) transparent;
  297. border-style: dashed dashed solid dashed;
  298. }
  299. .common-popup-wrapper{height:10rem;overflow: visible}
  300. .more-box .share-list{display:flex}
  301. .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;}
  302. .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}
  303. .more-box .share-list .share-item.weixin:before{content:"\e647";background:#C71585;}
  304. .more-box .share-list .share-item.pengyou:before{content:"\e645";background:#ffaa00;}
  305. .more-box .share-list .share-item.copy:before{content:"\e64b";background:#228B22;}
  306. .more-box .share-list .share-item.goods:before{content:"\e6dd";background:#f44336;}
  307. .more-box .weixin-share-wrapper{position: absolute;bottom:0;left:0;text-align: right}
  308. .more-box .weixin-share{height:10rem;}
  309. .copy-wrapper{padding:1rem;}
  310. .copy-wrapper input{height:1.5rem;line-height:1.5rem;padding:0 .2rem;width:12rem;border:1px solid #e1e1e1}
  311. .copy-wrapper .title{font-size:$fontSize;text-align: center;margin-bottom:.5rem;}
  312. </style>