App.vue 11 KB

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