App.vue 9.5 KB

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