App.vue 8.6 KB

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