App.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <script>
  2. import {
  3. checkLogin
  4. } from './libs/login';
  5. import {
  6. HTTP_REQUEST_URL,
  7. SYSTEM_VERSION
  8. } from './config/app';
  9. import {
  10. getShopConfig,
  11. silenceAuth,
  12. getSystemVersion
  13. } from '@/api/public';
  14. import Auth from '@/libs/wechat.js';
  15. import Routine from './libs/routine.js';
  16. import {
  17. silenceBindingSpread
  18. } from "@/utils";
  19. import {
  20. colorChange,
  21. getCrmebCopyRight,
  22. } from '@/api/api.js';
  23. import {
  24. getLangJson,
  25. getLangVersion
  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. onShow() {
  83. const queryData = uni.getEnterOptionsSync() // uni-app版本 3.5.1+ 支持
  84. if (queryData.query.spread) {
  85. this.$Cache.set('spread', queryData.query.spread);
  86. this.globalData.spid = queryData.query.spread;
  87. this.globalData.pid = queryData.query.spread;
  88. silenceBindingSpread(this.globalData)
  89. }
  90. if (queryData.query.spid) {
  91. this.$Cache.set('spread', queryData.query.spid);
  92. this.globalData.spid = queryData.query.spid;
  93. this.globalData.pid = queryData.query.spid;
  94. silenceBindingSpread(this.globalData)
  95. }
  96. // #ifdef MP
  97. if (queryData.query.scene) {
  98. let param = this.$util.getUrlParams(decodeURIComponent(queryData.query.scene))
  99. if (param.pid) {
  100. this.$Cache.set('spread', param.pid);
  101. this.globalData.spid = param.pid;
  102. this.globalData.pid = param.pid;
  103. } else {
  104. switch (queryData.scene) {
  105. //扫描小程序码
  106. case 1047:
  107. this.globalData.code = queryData.query.scene;
  108. break;
  109. //长按图片识别小程序码
  110. case 1048:
  111. this.globalData.code = queryData.query.scene;
  112. break;
  113. //手机相册选取小程序码
  114. case 1049:
  115. this.globalData.code = queryData.query.scene;
  116. break;
  117. //直接进入小程序
  118. case 1001:
  119. this.globalData.spid = queryData.query.scene;
  120. break;
  121. }
  122. }
  123. silenceBindingSpread(this.globalData)
  124. }
  125. // #endif
  126. },
  127. async onLaunch(option) {
  128. uni.hideTabBar()
  129. let that = this;
  130. // #ifdef H5
  131. if (option.query.hasOwnProperty('mdType') && option.query.mdType == "iframeWindow") {
  132. this.globalData.isIframe = true;
  133. } else {
  134. this.globalData.isIframe = false;
  135. }
  136. // #endif
  137. colorChange('color_change').then(res => {
  138. uni.setStorageSync('is_diy', res.data.is_diy)
  139. uni.$emit('is_diy', res.data.is_diy)
  140. switch (res.data.status) {
  141. case 1:
  142. uni.setStorageSync('viewColor', blue)
  143. uni.$emit('ok', blue, res.data.status)
  144. break;
  145. case 2:
  146. uni.setStorageSync('viewColor', green)
  147. uni.$emit('ok', green, res.data.status)
  148. break;
  149. case 3:
  150. uni.setStorageSync('viewColor', red)
  151. uni.$emit('ok', red, res.data.status)
  152. break;
  153. case 4:
  154. uni.setStorageSync('viewColor', pink)
  155. uni.$emit('ok', pink, res.data.status)
  156. break;
  157. case 5:
  158. uni.setStorageSync('viewColor', orange)
  159. uni.$emit('ok', orange, res.data.status)
  160. break;
  161. default:
  162. uni.setStorageSync('viewColor', red)
  163. uni.$emit('ok', red, res.data.status)
  164. break
  165. }
  166. });
  167. getLangVersion().then(res => {
  168. let version = res.data.version
  169. if (version != uni.getStorageSync('LANG_VERSION')) {
  170. getLangJson().then(res => {
  171. let value = Object.keys(res.data)[0]
  172. Cache.set('locale', Object.keys(res.data)[0])
  173. this.$i18n.setLocaleMessage(value, res.data[value]);
  174. uni.setStorageSync('localeJson', res.data);
  175. })
  176. }
  177. uni.setStorageSync('LANG_VERSION', version)
  178. })
  179. // #ifdef APP-PLUS || H5
  180. uni.getSystemInfo({
  181. success: function(res) {
  182. // 首页没有title获取的整个页面的高度,里面的页面有原生标题要减掉就是视口的高度
  183. // 状态栏是动态的可以拿到 标题栏是固定写死的是44px
  184. let height = res.windowHeight - res.statusBarHeight - 44
  185. // #ifdef H5 || APP-PLUS
  186. that.globalData.windowHeight = res.windowHeight + 'px'
  187. // #endif
  188. // // #ifdef APP-PLUS
  189. // that.globalData.windowHeight = height + 'px'
  190. // // #endif
  191. }
  192. });
  193. // #endif
  194. // #ifdef MP
  195. if (HTTP_REQUEST_URL == '') {
  196. console.error(
  197. "请配置根目录下的config.js文件中的 'HTTP_REQUEST_URL'\n\n请修改开发者工具中【详情】->【AppID】改为自己的Appid\n\n请前往后台【小程序】->【小程序配置】填写自己的 appId and AppSecret"
  198. );
  199. return false;
  200. }
  201. const updateManager = wx.getUpdateManager();
  202. const startParamObj = wx.getEnterOptionsSync();
  203. if (wx.canIUse('getUpdateManager') && startParamObj.scene != 1154) {
  204. const updateManager = wx.getUpdateManager()
  205. updateManager.onCheckForUpdate(function(res) {
  206. // 请求完新版本信息的回调
  207. // console.log(res.hasUpdate)
  208. if (res.hasUpdate) {
  209. updateManager.onUpdateFailed(function() {
  210. return that.Tips({
  211. title: '新版本下载失败'
  212. });
  213. });
  214. updateManager.onUpdateReady(function() {
  215. wx.showModal({
  216. title: '更新提示',
  217. content: '新版本已经下载好,是否重启当前应用?',
  218. success(res) {
  219. if (res.confirm) {
  220. updateManager.applyUpdate()
  221. }
  222. }
  223. })
  224. })
  225. updateManager.onUpdateFailed(function() {
  226. wx.showModal({
  227. title: '发现新版本',
  228. content: '请删除当前小程序,重启搜索打开...',
  229. })
  230. })
  231. }
  232. })
  233. }
  234. // #endif
  235. // getShopConfig().then(res => {
  236. // this.$store.commit('SETPHONESTATUS', res.data.status);
  237. // });
  238. // 获取导航高度;
  239. uni.getSystemInfo({
  240. success: function(res) {
  241. that.globalData.navHeight = res.statusBarHeight * (750 / res.windowWidth) + 91;
  242. }
  243. });
  244. // #ifdef MP
  245. let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
  246. that.globalData.navH = menuButtonInfo.top * 2 + menuButtonInfo.height / 2;
  247. const version = uni.getSystemInfoSync().SDKVersion
  248. if (Routine.compareVersion(version, '2.21.3') >= 0) {
  249. that.$Cache.set('MP_VERSION_ISNEW', true)
  250. } else {
  251. that.$Cache.set('MP_VERSION_ISNEW', false)
  252. }
  253. // #endif
  254. // #ifdef MP
  255. // 小程序静默授权
  256. // if (!this.$store.getters.isLogin) {
  257. // Routine.getCode()
  258. // .then(code => {
  259. // this.silenceAuth(code);
  260. // })
  261. // .catch(res => {
  262. // uni.hideLoading();
  263. // });
  264. // }
  265. // #endif
  266. // #ifdef H5
  267. // 添加crmeb chat 统计
  268. var __s = document.createElement('script');
  269. __s.src = `${HTTP_REQUEST_URL}/api/get_script`;
  270. document.head.appendChild(__s);
  271. // #endif
  272. getCrmebCopyRight().then(res => {
  273. uni.setStorageSync('copyRight', res.data)
  274. })
  275. // #ifdef MP
  276. getSystemVersion().then(res => {
  277. if (res.data.version_code < SYSTEM_VERSION) {
  278. uni.showModal({
  279. title: '提示',
  280. content: '请重新打包并上传小程序',
  281. success: function(res) {
  282. if (res.confirm) {}
  283. }
  284. });
  285. }
  286. })
  287. // #endif
  288. },
  289. // #ifdef H5
  290. onHide() {
  291. this.$Cache.clear('snsapiKey')
  292. },
  293. // #endif
  294. methods: {
  295. // 小程序静默授权
  296. // silenceAuth(code) {
  297. // let that = this;
  298. // let spread = that.globalData.spid ? that.globalData.spid : '';
  299. // silenceAuth({
  300. // code: code,
  301. // spread_spid: spread,
  302. // spread_code: that.globalData.code
  303. // })
  304. // .then(res => {
  305. // if (res.data.token !== undefined && res.data.token) {
  306. // uni.hideLoading();
  307. // let time = res.data.expires_time - this.$Cache.time();
  308. // that.$store.commit('LOGIN', {
  309. // token: res.data.token,
  310. // time: time
  311. // });
  312. // that.$store.commit('SETUID', res.data.userInfo.uid);
  313. // that.$store.commit('UPDATE_USERINFO', res.data.userInfo);
  314. // }
  315. // })
  316. // .catch(res => {});
  317. // },
  318. },
  319. };
  320. </script>
  321. <style>
  322. @import url('@/plugin/emoji-awesome/css/tuoluojiang.css');
  323. @import url('@/plugin/animate/animate.min.css');
  324. @import 'static/css/base.css';
  325. @import 'static/iconfont/iconfont.css';
  326. @import 'static/css/guildford.css';
  327. @import 'static/css/style.scss';
  328. view {
  329. box-sizing: border-box;
  330. }
  331. page {
  332. font-family: PingFang SC;
  333. }
  334. .bg-color-red {
  335. background-color: var(--view-theme) !important;
  336. }
  337. .syspadding {
  338. padding-top: var(--status-bar-height);
  339. }
  340. .flex {
  341. display: flex;
  342. }
  343. .uni-scroll-view::-webkit-scrollbar {
  344. /* 隐藏滚动条,但依旧具备可以滚动的功能 */
  345. display: none;
  346. }
  347. ::-webkit-scrollbar {
  348. width: 0;
  349. height: 0;
  350. color: transparent;
  351. }
  352. .uni-system-open-location .map-content.fix-position {
  353. height: 100vh;
  354. top: 0;
  355. bottom: 0;
  356. }
  357. .open-location {
  358. width: 100%;
  359. height: 100vh;
  360. }
  361. </style>