App.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <div id="app">
  3. <!-- <van-nav-bar
  4. title="南华云灯会"
  5. left-arrow
  6. :border="false"
  7. @click-left="onClickLeft"
  8. @click-right="onClickRight"
  9. /> -->
  10. <page-slide indexPagePath="/login">
  11. <router-view
  12. class="pageContent"
  13. :style="{ height: isshow ? 'calc(100vh - 65px)' : '100vh' }"
  14. />
  15. </page-slide>
  16. <tabbar v-show="isshow" />
  17. </div>
  18. </template>
  19. <script>
  20. import pageSlide from '@/components/page-slide'
  21. import tabbar from '@/components/tabbar/index.vue'
  22. import jsonp from 'jsonp'
  23. import wx from 'weixin-js-sdk'
  24. export default {
  25. name: 'App',
  26. components: {
  27. pageSlide,
  28. tabbar
  29. },
  30. created() {
  31. let token = this.getUrlParams("token")
  32. if (token) {
  33. this.$store.commit('home/setToken', token)
  34. }
  35. window.onhashchange = () => {
  36. console.log('监听到了hash地址的变化', location.hash)
  37. // location.hash方法用于获取哈希地址
  38. switch (location.hash) {
  39. case '#/home':
  40. this.comName = 'Home'
  41. break
  42. case '#/movie':
  43. this.comName = 'Movie'
  44. break
  45. case '#/about':
  46. this.comName = 'About'
  47. break
  48. }
  49. }
  50. },
  51. computed: {
  52. isshow() {
  53. return this.$route.meta.showHeader
  54. }
  55. },
  56. mounted() {
  57. this.wxShare()
  58. },
  59. methods: {
  60. async getWinxinCodeFun(huiyi_id){//获得微信code
  61. var self=this;
  62. if(this.getQuery("code")){
  63. // 拿到code值
  64. self.code=tools.getQuery("code");
  65. //把微信打乱的url地址静默修复
  66. var changeUrl=`${window.location.protocol}//${window.location.host}${window.location.pathname}${window.location.hash}${window.location.search}`;
  67. window.history.pushState({},0, changeUrl);
  68. WXAPI.wxLogin(self.code).then((sucData)=>{//调用后台的微信登录方法
  69. self.commonLoginFun(sucData);//调用登录成功后的公共方法
  70. })
  71. return;
  72. }
  73. var appId = 'wxc09c15943347c4a4';//后端接口获取appid什么的
  74. var url=encodeURIComponent(window.location.href);
  75. var getCodeUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${url}&response_type=code&scope=snsapi_base&state=1#wechat_redirect`;
  76. window.location.href = getCodeUrl;
  77. },
  78. getQuery(name) {
  79. var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  80. var r = window.location.search.substr(1).match(reg);
  81. if (r != null) {
  82. return unescape(r[2]);
  83. }
  84. return null;
  85. },
  86. getUrlParams(name) {
  87. let url = window.location.href
  88. // 通过 ? 分割获取后面的参数字符串
  89. let urlStr = url.split('?') && url.split('?')[1]
  90. // 创建空对象存储参数
  91. let obj = {};
  92. // 再通过 & 将每一个参数单独分割出来
  93. let paramsArr = urlStr && urlStr.split('&') || []
  94. for(let i = 0,len = paramsArr.length;i < len;i++){
  95. // 再通过 = 将每一个参数分割为 key:value 的形式
  96. let arr = paramsArr[i].split('=')
  97. obj[arr[0]] = arr[1];
  98. }
  99. return obj && obj[name]
  100. },
  101. onClickLeft() {
  102. this.$router.go(-1)
  103. },
  104. onClickRight() {},
  105. wxShare() {
  106. let url = window.location.href.split('#')[0]
  107. if (window.location.ancestorOrigins) {
  108. url = window.location.ancestorOrigins[0]
  109. }
  110. jsonp(
  111. 'https://www.4dage.com/wechat/jssdk/share/?uri=' +
  112. window.escape(url) +
  113. '&name=厦门四维时代微信公众号',
  114. 'success_jsonp',
  115. function (err, data) {
  116. if (err) {
  117. console.err(err)
  118. } else {
  119. console.log(wx)
  120. wx.config({
  121. debug: false, // 开启调试模式
  122. appId: data.appId,
  123. timestamp: data.timestamp,
  124. nonceStr: data.nonceStr,
  125. signature: data.signature,
  126. jsApiList: [
  127. 'checkJsApi',
  128. 'onMenuShareTimeline',
  129. 'onMenuShareAppMessage',
  130. 'onMenuShareQQ',
  131. 'onMenuShareWeibo',
  132. 'hideMenuItems',
  133. 'showMenuItems',
  134. 'hideAllNonBaseMenuItem',
  135. 'showAllNonBaseMenuItem',
  136. 'translateVoice',
  137. 'startRecord',
  138. 'stopRecord',
  139. 'onRecordEnd',
  140. 'playVoice',
  141. 'pauseVoice',
  142. 'stopVoice',
  143. 'uploadVoice',
  144. 'downloadVoice'
  145. ]
  146. })
  147. }
  148. wx.error(function (err) {
  149. console.log(err,'err')
  150. })
  151. wx.ready(function () {
  152. var shareData = {
  153. title: '四维看看', // 标题
  154. desc: '可将线下场景自动转为线上四维场景。好用不贵,全球百万用户首选', // 描述
  155. link: window.location.href, // 分享的URL,必须和当前打开的网页的URL是一样的
  156. imgUrl: 'https://4dkk.4dage.com/FDKKIMG/icon/kankan_icon180.png', // 缩略图地址
  157. success: function () {},
  158. cancel: function () {}
  159. }
  160. wx.onMenuShareAppMessage(shareData)
  161. wx.onMenuShareTimeline(shareData)
  162. wx.onMenuShareQQ(shareData)
  163. wx.onMenuShareQZone(shareData)
  164. })
  165. }
  166. )
  167. }
  168. }
  169. }
  170. </script>
  171. <style>
  172. #app {
  173. width: 100%;
  174. height: 100%;
  175. /* padding-top: 46px; */
  176. position: relative;
  177. }
  178. .pageContent {
  179. /* padding-top: 46px; */
  180. position: relative;
  181. }
  182. .van-nav-bar {
  183. position: absolute;
  184. width: 100%;
  185. border: none !important;
  186. background: none !important;
  187. }
  188. .van-nav-bar__title,
  189. .van-nav-bar .van-icon {
  190. color: #fff;
  191. }
  192. .showImgbase64{
  193. width: 100%;
  194. height: 100%;
  195. object-fit: cover;
  196. opacity: 0;
  197. position: absolute;
  198. z-index: 11;
  199. }
  200. .van-image__img{
  201. width: auto;
  202. height: auto;
  203. }
  204. </style>