You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <script>
  2. import {
  3. checkLogin
  4. } from './libs/login';
  5. import {
  6. HTTP_REQUEST_URL
  7. } from './config/app';
  8. import {
  9. getShopConfig,
  10. silenceAuth
  11. } from '@/api/public';
  12. import Auth from '@/libs/wechat.js';
  13. import Routine from './libs/routine.js';
  14. import {
  15. getCartCounts,
  16. } from '@/api/order.js';
  17. import {
  18. colorChange
  19. } from '@/api/api.js';
  20. import {
  21. mapGetters
  22. } from "vuex"
  23. // #ifdef MP
  24. let livePlayer = requirePlugin('live-player-plugin')
  25. // #endif
  26. let green =
  27. '--view-theme: #42CA4D;--view-priceColor:#FF7600;--view-minorColor:rgba(108, 198, 94, 0.5);--view-minorColorT:rgba(66, 202, 77, 0.1);--view-bntColor:#FE960F;'
  28. let red =
  29. '--view-theme: #e93323;--view-priceColor:#e93323;--view-minorColor:rgba(233, 51, 35, 0.5);--view-minorColorT:rgba(233, 51, 35, 0.1);--view-bntColor:#FE960F;'
  30. let blue =
  31. '--view-theme: #1DB0FC;--view-priceColor:#FD502F;--view-minorColor:rgba(58, 139, 236, 0.5);--view-minorColorT:rgba(9, 139, 243, 0.1);--view-bntColor:#22CAFD;'
  32. let pink =
  33. '--view-theme: #FF448F;--view-priceColor:#FF448F;--view-minorColor:rgba(255, 68, 143, 0.5);--view-minorColorT:rgba(255, 68, 143, 0.1);--view-bntColor:#282828;'
  34. let orange =
  35. '--view-theme: #FE5C2D;--view-priceColor:#FE5C2D;--view-minorColor:rgba(254, 92, 45, 0.5);--view-minorColorT:rgba(254, 92, 45, 0.1);--view-bntColor:#FDB000;'
  36. export default {
  37. globalData: {
  38. spid: 0,
  39. code: 0,
  40. isLogin: false,
  41. userInfo: {},
  42. MyMenus: [],
  43. globalData: false,
  44. isIframe: false,
  45. tabbarShow: true,
  46. windowHeight: 0
  47. },
  48. computed: mapGetters(['isLogin', 'cartNum']),
  49. watch: {
  50. isLogin: {
  51. deep: true, //深度监听设置为 true
  52. handler: function(newV, oldV) {
  53. if (newV) {
  54. this.getCartNum()
  55. } else {
  56. this.$store.commit('indexData/setCartNum', '')
  57. }
  58. }
  59. },
  60. cartNum(newCart, b) {
  61. this.$store.commit('indexData/setCartNum', newCart + '')
  62. if (newCart > 0) {
  63. uni.setTabBarBadge({
  64. index: Number(uni.getStorageSync('FOOTER_ADDCART')) || 2,
  65. text: newCart + ''
  66. })
  67. } else {
  68. uni.hideTabBarRedDot({
  69. index: Number(uni.getStorageSync('FOOTER_ADDCART')) || 2
  70. })
  71. }
  72. }
  73. },
  74. onLaunch: async function(option) {
  75. let that = this;
  76. colorChange('color_change').then(res => {
  77. let navigation = res.data.navigation; //判断悬浮导航是否显示
  78. let statusColor = res.data.status; //判断显示啥颜色
  79. uni.setStorageSync('navigation', navigation);
  80. uni.$emit('navOk', navigation);
  81. uni.setStorageSync('statusColor', statusColor);
  82. uni.$emit('colorOk', statusColor);
  83. switch (res.data.status) {
  84. case 1:
  85. uni.setStorageSync('viewColor', blue)
  86. uni.$emit('ok', blue)
  87. break;
  88. case 2:
  89. uni.setStorageSync('viewColor', green)
  90. uni.$emit('ok', green)
  91. break;
  92. case 3:
  93. uni.setStorageSync('viewColor', red)
  94. uni.$emit('ok', red)
  95. break;
  96. case 4:
  97. uni.setStorageSync('viewColor', pink)
  98. uni.$emit('ok', pink)
  99. break;
  100. case 5:
  101. uni.setStorageSync('viewColor', orange)
  102. uni.$emit('ok', orange)
  103. break;
  104. default:
  105. uni.setStorageSync('viewColor', red)
  106. uni.$emit('ok', red)
  107. break
  108. }
  109. });
  110. if (option.query.pid) {
  111. that.$Cache.set('spread', option.query.pid);
  112. }
  113. if (option.query.spread) {
  114. that.$Cache.set('spread', option.query.spread);
  115. that.globalData.spid = option.query.spread;
  116. that.globalData.pid = option.query.spread;
  117. }
  118. // #ifdef APP-PLUS || H5
  119. uni.getSystemInfo({
  120. success: function(res) {
  121. // 首页没有title获取的整个页面的高度,里面的页面有原生标题要减掉就是视口的高度
  122. // 状态栏是动态的可以拿到 标题栏是固定写死的是44px
  123. let height = res.windowHeight - res.statusBarHeight - 44
  124. // #ifdef H5 || APP-PLUS
  125. that.globalData.windowHeight = res.windowHeight + 'px'
  126. // #endif
  127. // // #ifdef APP-PLUS
  128. // that.globalData.windowHeight = height + 'px'
  129. // // #endif
  130. }
  131. });
  132. // #endif
  133. // #ifdef MP
  134. if (HTTP_REQUEST_URL == '') {
  135. console.error(
  136. "请配置根目录下的config.js文件中的 'HTTP_REQUEST_URL'\n\n请修改开发者工具中【详情】->【AppID】改为自己的Appid\n\n请前往后台【小程序】->【小程序配置】填写自己的 appId and AppSecret"
  137. );
  138. return false;
  139. }
  140. if (option.query.hasOwnProperty('scene')) {
  141. switch (option.scene) {
  142. //扫描小程序码
  143. case 1047:
  144. let val = that.$util.getUrlParams(decodeURIComponent(option.query.scene));
  145. that.globalData.code = val.pid === undefined ? val : val.pid;
  146. break;
  147. //长按图片识别小程序码
  148. case 1048:
  149. that.globalData.code = option.query.scene;
  150. break;
  151. //手机相册选取小程序码
  152. case 1049:
  153. that.globalData.code = option.query.scene;
  154. break;
  155. //直接进入小程序
  156. case 1001:
  157. that.globalData.spid = option.query.scene;
  158. break;
  159. }
  160. }
  161. const updateManager = wx.getUpdateManager();
  162. updateManager.onCheckForUpdate(function(res) {
  163. // 请求完新版本信息的回调
  164. });
  165. updateManager.onUpdateReady(function() {
  166. wx.showModal({
  167. title: '更新提示',
  168. content: '新版本已经准备好,是否重启应用?',
  169. success: function(res) {
  170. if (res.confirm) {
  171. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  172. updateManager.applyUpdate();
  173. }
  174. }
  175. });
  176. });
  177. updateManager.onUpdateFailed(function() {
  178. return that.Tips({
  179. title: '新版本下载失败'
  180. });
  181. });
  182. // #endif
  183. // getShopConfig().then(res => {
  184. // this.$store.commit('SETPHONESTATUS', res.data.status);
  185. // });
  186. // 获取导航高度;
  187. uni.getSystemInfo({
  188. success: function(res) {
  189. that.globalData.navHeight = res.statusBarHeight * (750 / res.windowWidth) + 91;
  190. }
  191. });
  192. // #ifdef MP
  193. let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
  194. that.globalData.navH = menuButtonInfo.top * 2 + menuButtonInfo.height / 2;
  195. // #endif
  196. // #ifdef H5
  197. // 添加crmeb chat 统计
  198. var __s = document.createElement('script');
  199. __s.src = `${HTTP_REQUEST_URL}/api/get_script`;
  200. document.head.appendChild(__s);
  201. uni.getSystemInfo({
  202. success(e) {
  203. /* 窗口宽度大于420px且不在PC页面且不在移动设备时跳转至 PC.html 页面 */
  204. if (e.windowWidth > 420 && !window.top.isPC && !/iOS|Android/i.test(e.system)) {
  205. window.location.pathname = '/static/html/pc.html';
  206. }
  207. }
  208. });
  209. if (option.query.hasOwnProperty('type')) {
  210. this.globalData.isIframe = true;
  211. } else {
  212. this.globalData.isIframe = false;
  213. }
  214. if (window.location.pathname !== '/' && !this.isWork()) {
  215. let snsapiBase = 'snsapi_base';
  216. let urlData = location.pathname + location.search;
  217. if (!that.$store.getters.isLogin && uni.getStorageSync('authIng')) {
  218. uni.setStorageSync('authIng', false)
  219. }
  220. if (!that.$store.getters.isLogin && Auth.isWeixin()) {
  221. let code,
  222. state,
  223. scope = ''
  224. if (option.query.code instanceof Array) {
  225. code = option.query.code[option.query.code.length - 1]
  226. } else {
  227. code = option.query.code
  228. }
  229. if (code && code != uni.getStorageSync('snsapiCode') && location.pathname.indexOf(
  230. '/pages/users/wechat_login/index') === -1) {
  231. // 存储静默授权code
  232. uni.setStorageSync('snsapiCode', code);
  233. let spread = that.globalData.spid ? that.globalData.spid : '';
  234. try {
  235. let res = await silenceAuth({
  236. code: code,
  237. snsapi: 'snsapi_base',
  238. spread: that.$Cache.get('spread'),
  239. spid: that.globalData.code
  240. });
  241. uni.setStorageSync('snRouter', decodeURIComponent(decodeURIComponent(option.query
  242. .back_url)));
  243. if (res.data.key !== undefined && res.data.key) {
  244. this.$Cache.set('snsapiKey', res.data.key);
  245. } else {
  246. let time = res.data.expires_time - this.$Cache.time();
  247. this.$store.commit('LOGIN', {
  248. token: res.data.token,
  249. time: time
  250. });
  251. this.$store.commit('SETUID', res.data.userInfo.uid);
  252. this.$store.commit('UPDATE_USERINFO', res.data.userInfo);
  253. if (option.query.back_url) {
  254. location.replace(decodeURIComponent(decodeURIComponent(option.query
  255. .back_url)));
  256. }
  257. }
  258. } catch (e) {
  259. let url = ''
  260. if (option.query.back_url instanceof Array) {
  261. url = option.query.back_url[option.query.back_url.length - 1]
  262. } else {
  263. url = option.query.back_url
  264. }
  265. if (!that.$Cache.has('snsapiKey')) {
  266. if (location.pathname.indexOf('/pages/users/wechat_login/index') === -1) {
  267. Auth.oAuth('snsapi_userinfo', url);
  268. }
  269. }
  270. }
  271. // silenceAuth({
  272. // code: code,
  273. // spread: that.$Cache.get('spread'),
  274. // spid: that.globalData.code
  275. // })
  276. // .then(res => {
  277. // uni.setStorageSync('snRouter', decodeURIComponent(decodeURIComponent(option.query
  278. // .back_url)));
  279. // if (res.data.key !== undefined && res.data.key) {
  280. // this.$Cache.set('snsapiKey', res.data.key);
  281. // } else {
  282. // let time = res.data.expires_time - this.$Cache.time();
  283. // this.$store.commit('LOGIN', {
  284. // token: res.data.token,
  285. // time: time
  286. // });
  287. // this.$store.commit('SETUID', res.data.userInfo.uid);
  288. // this.$store.commit('UPDATE_USERINFO', res.data.userInfo);
  289. // if (option.query.back_url) {
  290. // location.replace(decodeURIComponent(decodeURIComponent(option.query
  291. // .back_url)));
  292. // }
  293. // }
  294. // })
  295. // .catch(error => {
  296. // let url = ''
  297. // if (option.query.back_url instanceof Array) {
  298. // url = option.query.back_url[option.query.back_url.length - 1]
  299. // } else {
  300. // url = option.query.back_url
  301. // }
  302. // if (!that.$Cache.has('snsapiKey')) {
  303. // if (location.pathname.indexOf('/pages/users/wechat_login/index') === -1) {
  304. // Auth.oAuth(snsapiBase, url);
  305. // }
  306. // }
  307. // });
  308. } else {
  309. if (!this.$Cache.has('snsapiKey')) {
  310. if (location.pathname.indexOf('/pages/users/wechat_login/index') === -1) {
  311. Auth.oAuth(snsapiBase, urlData);
  312. }
  313. }
  314. }
  315. } else {
  316. if (option.query.back_url) {
  317. location.replace(uni.getStorageSync('snRouter'));
  318. }
  319. }
  320. }
  321. // #endif
  322. // #ifdef MP
  323. // 小程序静默授权
  324. if (!this.$store.getters.isLogin) {
  325. Routine.getCode()
  326. .then(code => {
  327. this.silenceAuth(code);
  328. })
  329. .catch(res => {
  330. uni.hideLoading();
  331. });
  332. }
  333. // #endif
  334. },
  335. onShow(options) {
  336. let that = this;
  337. //直播间分享
  338. // #ifdef MP
  339. const sceneList = [1007, 1008, 1014, 1044, 1045, 1046, 1047, 1048, 1049, 1073, 1154, 1155];
  340. if (sceneList.includes(options.scene)) {
  341. livePlayer.getShareParams()
  342. .then(res => {
  343. //记录推广人uid
  344. if(res.custom_params.pid){
  345. that.$Cache.set('spread', res.custom_params.pid);
  346. that.globalData.spid = res.custom_params.pid;
  347. that.globalData.pid = res.custom_params.pid;
  348. }
  349. }).catch(err => {
  350. })
  351. }
  352. // #endif
  353. },
  354. mounted() {
  355. setTimeout((e) => {
  356. if (this.$store.getters.isLogin) {
  357. this.getCartNum()
  358. }
  359. }, 100)
  360. },
  361. methods: {
  362. // 小程序静默授权
  363. silenceAuth(code) {
  364. let that = this;
  365. let spread = that.globalData.spid ? that.globalData.spid : '';
  366. silenceAuth({
  367. code: code,
  368. spread_spid: spread,
  369. spread_code: that.globalData.code
  370. })
  371. .then(res => {
  372. if (res.data.token !== undefined && res.data.token) {
  373. uni.hideLoading();
  374. let time = res.data.expires_time - this.$Cache.time();
  375. that.$store.commit('LOGIN', {
  376. token: res.data.token,
  377. time: time
  378. });
  379. that.$store.commit('SETUID', res.data.userInfo.uid);
  380. that.$store.commit('UPDATE_USERINFO', res.data.userInfo);
  381. }
  382. })
  383. .catch(res => {});
  384. },
  385. getCartNum: function() {
  386. let that = this;
  387. getCartCounts().then(res => {
  388. this.$store.commit('indexData/setCartNum', res.data.count > 99 ? '..' : res.data.count +
  389. '')
  390. });
  391. },
  392. isWork() {
  393. return navigator.userAgent.toLowerCase().indexOf('wxwork') !== -1 && navigator.userAgent.toLowerCase()
  394. .indexOf("micromessenger") !== -1
  395. }
  396. },
  397. onHide: function() {
  398. }
  399. };
  400. </script>
  401. <style lang="scss">
  402. @import url('@/plugin/emoji-awesome/css/google.min.css');
  403. @import url('@/plugin/animate/animate.min.css');
  404. @import 'static/css/base.css';
  405. @import 'static/iconfont/iconfont.css';
  406. @import 'static/css/guildford.css';
  407. @import 'static/css/style.scss';
  408. view {
  409. box-sizing: border-box;
  410. }
  411. page {
  412. font-family: PingFang SC;
  413. }
  414. .bg-color-red {
  415. background-color: var(--view-theme) !important;
  416. }
  417. .syspadding {
  418. padding-top: var(--status-bar-height);
  419. }
  420. .flex {
  421. display: flex;
  422. }
  423. .uni-scroll-view::-webkit-scrollbar {
  424. /* 隐藏滚动条,但依旧具备可以滚动的功能 */
  425. display: none;
  426. }
  427. ::-webkit-scrollbar {
  428. width: 0;
  429. height: 0;
  430. color: transparent;
  431. }
  432. .uni-system-open-location .map-content.fix-position {
  433. height: 100vh;
  434. top: 0;
  435. bottom: 0;
  436. }
  437. </style>