MobileHeader.vue 9.4 KB

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