App.vue 12 KB

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