App.vue 11 KB

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