MobileHeader.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <div>
  3. <div class="mobile-modal" v-if="showStoreInfo || showShare">
  4. <div class="mobile-modal-box" v-if="showStoreInfo">
  5. <div class="mobile-modal-header">联系方式<i @click="showStoreInfo = false" class="icon-guanbi iconfont"></i></div>
  6. <div class="mobile-modal-content" v-if="showDefaultAddr">
  7. <div>商家地址:深圳市南山区英唐大厦6楼</div>
  8. <div class="content-line link-url">在线咨询</div>
  9. <div>致电:<span class="content-line link-url">0755-96586323</span></div>
  10. </div>
  11. <div class="mobile-modal-content" v-if="!showDefaultAddr">
  12. <div>商家地址:{{store.enterprise.enAddress || store.enterprise.address}}</div>
  13. <div class="content-line link-url">在线咨询</div>
  14. <div>致电:<span class="content-line link-url">{{store.enterprise.enTel}}</span></div>
  15. </div>
  16. </div>
  17. <div class="mobile-share-box" v-if="showShare">
  18. <div class="share-area">
  19. <ul>
  20. <li class="share-item" @click="shareWeChat">
  21. <img src="/images/mobile/@2x/share/weChat@2x.png" alt="">
  22. <span>微信</span>
  23. </li>
  24. <li class="share-item" @click="shareQQ">
  25. <img src="/images/mobile/@2x/share/QQ@2x.png" alt="">
  26. <span>QQ</span>
  27. </li>
  28. <li class="share-item" @click="shareWeibo">
  29. <img src="/images/mobile/@2x/share/sina@2x.png" alt="">
  30. <span>微博</span>
  31. </li>
  32. <li class="share-item" @click="shareMessage">
  33. <img src="/images/mobile/@2x/share/message@2x.png" alt="">
  34. <span>短信</span>
  35. </li>
  36. <li class="share-item" @click="shareEmail">
  37. <img src="/images/mobile/@2x/share/email@2x.png" alt="">
  38. <span>邮件</span>
  39. <a href="mailto:yangc@usoftchina.com" class="hide" id="share-mail"></a>
  40. </li>
  41. <li class="share-item" @click="flash">
  42. <img src="/images/mobile/@2x/share/flash@2x.png" alt="">
  43. <span>刷新</span>
  44. </li>
  45. <li class="share-item" @click="copyLink" id="copyLink" :data-clipboard-text="url">
  46. <img src="/images/mobile/@2x/share/copylink@2x.png" alt="">
  47. <span>复制链接</span>
  48. </li>
  49. </ul>
  50. </div>
  51. <div class="cancel-share" @click="showShare=false">取消</div>
  52. </div>
  53. </div>
  54. <div class="mobile-header">
  55. <a class="iconfont icon-fanhui" @click="goLastPage">返回</a>
  56. <p>{{title}}</p>
  57. <i v-show="rightIcon=='share'" class="iconfont icon-fenxiang" @click="showShare = true"></i>
  58. <i v-show="rightIcon=='phone'" class="iconfont icon-dianhua" @click="showLink"></i>
  59. </div>
  60. </div>
  61. </template>
  62. <script>
  63. import Clipboard from 'clipboard'
  64. export default {
  65. data () {
  66. return {
  67. showStoreInfo: false,
  68. showShare: false,
  69. rightIcon: 'share',
  70. showDefaultAddr: true,
  71. url: '',
  72. clipboard: {}
  73. }
  74. },
  75. computed: {
  76. brandDetail () {
  77. return this.$store.state.brandDetail.detail.data
  78. },
  79. title () {
  80. return this.initHeader(this.$route.path)
  81. },
  82. store () {
  83. return this.$store.state.shop.storeInfo.store.data
  84. },
  85. component () {
  86. return this.$store.state.componentDetail.detail.data
  87. }
  88. },
  89. mounted () {
  90. let _this = this
  91. _this.url = window.location.href
  92. _this.clipboard = new Clipboard('#copyLink')
  93. _this.clipboard.on('success', e => {
  94. _this.clipboard.destroy()
  95. _this.showShare = false
  96. })
  97. _this.clipboard.on('error', e => {
  98. alert('浏览器不支持自动复制,请手动复制')
  99. _this.clipboard.destroy()
  100. })
  101. },
  102. methods: {
  103. goLastPage: function () {
  104. window.history.back(-1)
  105. },
  106. initHeader: function (val) {
  107. let title = '优软商城'
  108. if (val.startsWith('/mobile/brand/')) {
  109. if (this.brandDetail.nameCn) {
  110. if (this.brandDetail.nameCn !== this.brandDetail.nameEn) {
  111. title = this.brandDetail.nameEn + '(' + this.brandDetail.nameCn + ')'
  112. } else {
  113. title = this.brandDetail.nameCn
  114. }
  115. } else {
  116. if (this.component.brand.nameCn !== this.component.brand.nameEn) {
  117. title = this.component.brand.nameEn + '(' + this.component.brand.nameCn + ')'
  118. } else {
  119. title = this.component.brand.nameCn
  120. }
  121. }
  122. this.rightIcon = 'share'
  123. } else if (val.startsWith('/mobile/shop')) {
  124. title = '店铺列表'
  125. this.rightIcon = 'phone'
  126. } else if (val.startsWith('/mobile/merchantDescription/')) {
  127. title = '商家简介'
  128. this.rightIcon = 'phone'
  129. } else if (val.startsWith('/mobile/user')) {
  130. title = '我的收藏'
  131. this.rightIcon = 'phone'
  132. } else if (val.startsWith('/mobile/search')) {
  133. title = '搜索结果'
  134. this.rightIcon = 'share'
  135. } else {
  136. title = '优软商城'
  137. this.rightIcon = 'phone'
  138. }
  139. return title
  140. },
  141. showLink: function () {
  142. this.showStoreInfo = true
  143. if (this.title === '商家简介') {
  144. this.showDefaultAddr = false
  145. } else {
  146. this.showDefaultAddr = true
  147. }
  148. },
  149. shareWeibo: function () {
  150. let _shareUrl = 'http://v.t.sina.com.cn/share/share.php?&appkey=895033136' // 真实的appkey,必选参数
  151. _shareUrl += '&url=' + encodeURIComponent(document.location) // 参数url设置分享的内容链接|默认当前页location,可选参数
  152. _shareUrl += '&title=' + encodeURIComponent(document.title) // 参数title设置分享的标题|默认当前页标题,可选参数
  153. _shareUrl += '&source=' + encodeURIComponent('')
  154. _shareUrl += '&sourceUrl=' + encodeURIComponent('')
  155. _shareUrl += '&content=' + 'utf-8' // 参数content设置页面编码gb2312|utf-8,可选参数
  156. _shareUrl += '&pic=' + encodeURIComponent('') // 参数pic设置图片链接|默认为空,可选参数
  157. window.open(_shareUrl)
  158. this.showShare = false
  159. },
  160. shareWeChat: function () {
  161. },
  162. shareQQ: function () {
  163. let url = encodeURIComponent(document.location)
  164. let title = encodeURIComponent(document.title)
  165. let source = encodeURIComponent('')
  166. let desc = '优软商城'
  167. let pics = 'http://dfs.ubtob.com/group1/M00/4F/C3/CgpkyFnxWjOAMy5DAAlh1PrLlc8684.png'
  168. window.open('http://connect.qq.com/widget/shareqq/index.html?url=' +
  169. url + '&title=' + title + '&source=' + source + '&desc=' + desc + '&pics=' + pics)
  170. this.showShare = false
  171. },
  172. shareMessage: function () {
  173. },
  174. shareEmail: function () {
  175. document.getElementById('share-mail').click()
  176. },
  177. flash: function () {
  178. window.location.reload()
  179. },
  180. copyLink: function () {
  181. let _this = this
  182. _this.url = window.location.href
  183. _this.clipboard = new Clipboard('#copyLink')
  184. }
  185. }
  186. }
  187. </script>
  188. <style lang="scss" scoped>
  189. @import '~assets/scss/mobileCommon';
  190. .mobile-header{
  191. width:100%;
  192. position: fixed;
  193. top: 0;
  194. z-index:10000;
  195. height:.88rem;
  196. display:flex;
  197. justify-content:space-around;
  198. align-items:center;
  199. border-bottom:.02rem solid #ccc;
  200. background: #3e82f5;
  201. padding:0 .2rem 0 .1rem;
  202. color:#fff;
  203. }
  204. .mobile-header p{
  205. flex:1;
  206. font-size:.36rem;
  207. text-align: center;
  208. margin-top:.2rem;
  209. }
  210. .mobile-header a{
  211. font-size:.28rem;
  212. color:#fff;
  213. }
  214. .mobile-header i{
  215. font-size:.4rem;
  216. }
  217. .hide {
  218. display: none;
  219. }
  220. </style>