App.vue 11 KB

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