App.vue 13 KB

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