App.vue 13 KB

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