App.vue 12 KB

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