App.vue 12 KB

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