App.vue 12 KB

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