App.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <script>
  2. import {
  3. HTTP_REQUEST_URL
  4. } from './config/app';
  5. import {
  6. loginConfigApi
  7. } from '@/api/public';
  8. import Auth from './libs/wechat.js';
  9. import Routine from './libs/routine.js';
  10. import {
  11. getTheme
  12. } from './api/api.js';
  13. import Cache from './utils/cache.js';
  14. import store from './store'
  15. import {
  16. silenceBindingSpread
  17. } from "./utils";
  18. var statusBarHeight = uni.getSystemInfoSync().statusBarHeight; //手机端头部手机时间位置高度
  19. export default {
  20. globalData: {
  21. spread: 0, //推广人id,绑定关系
  22. isLogin: false,
  23. windowHeight: 0,
  24. navHeight: 0, //导航高度
  25. navH: 0,
  26. id: 0, // 小程序扫码进入商品id,首页id
  27. isIframe: false,
  28. theme: 'theme1',
  29. statusBarHeight: statusBarHeight, //手机端头部手机时间位置高度
  30. mainWidth: 0, //获取设备宽度
  31. marketingType: '', //商品类型,normal普通商品
  32. publicLoginType: Cache.get('publicLoginType') ? Cache.get('publicLoginType') : '', //公众号登录方式(单选),1微信授权,2手机号登录
  33. routinePhoneVerification: '1,2', //小程序手机号校验类型(多选)1微信小程序验证 2短信验证
  34. companyName: uni.getStorageSync('companyName') ? uni.getStorageSync('companyName') : '欢迎你', //公司名称
  35. tokenIsExist: false, //登录是否失效 false 失效,true没失效
  36. mobileLoginLogo: uni.getStorageSync('mobileLoginLogo') || '/static/images/logo2.png', //登录页logo
  37. paidMemberPriceDisplay: 'all', //付费会员-会员价格展示 all-全部,paid-仅付费会员
  38. userIsPaidMember: false, //用户是否是付费会员
  39. changeColorConfig: '', //颜色配置
  40. copyrightCompanyImage: '', //版权图片
  41. frontDomain: '', //移动端域名
  42. imageDomain: '', //全局本地图片域名
  43. authorizeAddress: '', //授权备案-地址
  44. authorizeFilingNum: '', //授权备案-备案号
  45. authorizeInfo: '', //授权备案-授权信息
  46. authorizePhone: '', //授权备案-联系电话
  47. merId: 0 //扫码进入商户id
  48. },
  49. onLaunch: function(option) {
  50. let that = this;
  51. //获取登录配置
  52. store.dispatch('GetLoginConfig');
  53. //获取全局配置
  54. store.dispatch('GetGlobalConfig');
  55. //校验token是否有效,true为有效,false为无效
  56. store.dispatch("GetTokenIsExist");
  57. // 主题变色
  58. getTheme().then(res => {
  59. that.globalData.theme = `theme${Number(res.data.value)}`
  60. Cache.set('theme', `theme${Number(res.data.value)}`);
  61. store.commit('Change_GLOBAL_theme', `theme${Number(res.data.value)}`)
  62. // #ifdef H5
  63. window.document.documentElement.setAttribute('data-theme', that.globalData.theme);
  64. // #endif
  65. })
  66. // 获取页面高度
  67. uni.getSystemInfo({
  68. success: function(res) {
  69. // 首页没有title获取的整个页面的高度,里面的页面有原生标题要减掉就是视口的高度
  70. // 状态栏是动态的可以拿到 标题栏是固定写死的是44px
  71. let height = res.windowHeight - res.statusBarHeight - 44;
  72. // #ifdef H5 || APP-PLUS
  73. that.globalData.windowHeight = res.windowHeight + 'px';
  74. // #endif
  75. // 获取导航高度;
  76. that.globalData.navHeight = res.statusBarHeight * (750 / res.windowWidth) + 91;
  77. // 获取设备宽度;
  78. that.globalData.mainWidth = res.windowWidth
  79. store.commit('SYSTEM_PLATFORM', res.platform.toLowerCase());
  80. }
  81. });
  82. // 获取浏览器推广人id
  83. if (option.query.sd) {
  84. that.globalData.spread = option.query.sd;
  85. store.commit('GLOBAL_DATA', JSON.parse(JSON.stringify(that.globalData)));
  86. }
  87. if (option.sd) {
  88. that.globalData.spread = option.sd;
  89. store.commit('GLOBAL_DATA', JSON.parse(JSON.stringify(that.globalData)));
  90. }
  91. // #ifdef MP
  92. //小程序扫码进入获取浏览器值
  93. if (option.query.hasOwnProperty('scene')) {
  94. switch (option.scene) {
  95. case 1001: //直接进入小程序
  96. case 1047: //扫描小程序码
  97. case 1048: //长按图片识别小程序码
  98. case 1049: //手机相册选取小程序码
  99. case 1001: //直接进入小程序
  100. let value = this.$util.getUrlParams(decodeURIComponent(option.query.scene));
  101. that.globalData.spread = value.sd ? value.sd : '';
  102. that.globalData.id = value.id ? value.id : '';
  103. that.globalData.marketingType = value.mt ? value.mt : '0';
  104. that.globalData.merId = value.merId ? value.merId : '0';
  105. break;
  106. }
  107. }
  108. let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
  109. that.globalData.navH = menuButtonInfo.top * 2 + menuButtonInfo.height / 2;
  110. const updateManager = uni.getUpdateManager();
  111. if (!updateManager) return;
  112. updateManager.onCheckForUpdate(function(res) {
  113. // 请求完新版本信息的回调
  114. if (res.hasUpdate) {
  115. updateManager.onUpdateReady(function(res2) {
  116. uni.showModal({
  117. title: '更新提示',
  118. content: '发现新版本,是否重启应用?',
  119. cancelColor: '#eeeeee',
  120. confirmColor: '#FF0000',
  121. success(res2) {
  122. if (res2.confirm) {
  123. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  124. updateManager.applyUpdate();
  125. }
  126. }
  127. });
  128. });
  129. }
  130. });
  131. updateManager.onUpdateFailed(function(res) {
  132. // 新的版本下载失败
  133. uni.showModal({
  134. title: '提示',
  135. content: '检查到有新版本,但下载失败,请检查网络设置',
  136. success(res) {
  137. if (res.confirm) {
  138. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  139. updateManager.applyUpdate();
  140. }
  141. }
  142. });
  143. });
  144. if (HTTP_REQUEST_URL == '') {
  145. console.error(
  146. "请配置根目录下的config.js文件中的 'HTTP_REQUEST_URL'\n\n请修改开发者工具中【详情】->【AppID】改为自己的Appid\n\n请前往后台【小程序】->【小程序配置】填写自己的 appId and AppSecret"
  147. );
  148. return false;
  149. }
  150. // #endif
  151. // #ifdef H5
  152. if (option.query.hasOwnProperty('type') && option.query.type == "iframeVisualizing") {
  153. this.globalData.isIframe = true;
  154. } else {
  155. this.globalData.isIframe = false;
  156. }
  157. // wx公众号自动授权登录
  158. let snsapiBase = 'snsapi_base';
  159. let urlData = location.pathname + location.search;
  160. //publicLoginType,公众号登录方式(单选),1微信授权,2手机号登录
  161. if (!store.getters.isLogin && Auth.isWeixin() && this.globalData.publicLoginType == 1 && !that.globalData
  162. .tokenIsExist) {
  163. const {
  164. code,
  165. state,
  166. scope
  167. } = option.query;
  168. if (code && code != uni.getStorageSync('snsapiCode') && location.pathname.indexOf(
  169. '/pages/users/wechat_login/index') === -1) {
  170. // 存储静默授权code
  171. uni.setStorageSync('snsapiCode', code);
  172. let spread = that.globalData.spread ? that.globalData.spread : 0;
  173. Auth.auth(code, Cache.get('spread'))
  174. .then(res => {
  175. uni.setStorageSync('snRouter', decodeURIComponent(decodeURIComponent(option.query
  176. .back_url)));
  177. if (res.type === 'register') {
  178. Cache.set('snsapiKey', res.key);
  179. }
  180. if (res.type === 'login') {
  181. store.commit('LOGIN', {
  182. token: res.token
  183. });
  184. store.commit("SETUID", res.id);
  185. location.replace(decodeURIComponent(decodeURIComponent(option.query.back_url)));
  186. }
  187. })
  188. .catch(error => {
  189. if (!Cache.has('snsapiKey')) {
  190. if (location.pathname.indexOf('/pages/users/wechat_login/index') === -1) {
  191. Auth.oAuth(snsapiBase, option.query.back_url);
  192. }
  193. }
  194. });
  195. } else {
  196. if (!Cache.has('snsapiKey')) {
  197. if (location.pathname.indexOf('/pages/users/wechat_login/index') === -1) {
  198. Auth.oAuth(snsapiBase, urlData);
  199. }
  200. }
  201. }
  202. } else {
  203. if (option.query.back_url) {
  204. location.replace(uni.getStorageSync('snRouter'));
  205. }
  206. }
  207. // #endif
  208. // #ifdef MP
  209. // 获取小程序推广码
  210. if (Cache.get('UID') && !Cache.get('wechatQRcode')) {
  211. Routine.getQrcode()
  212. }
  213. // 小程序静默授权
  214. if (!store.getters.isLogin) {
  215. Routine.getCode().then(code => {
  216. let userInfo = {
  217. code: code,
  218. spreadPid: this.globalData.spread, //获取推广人ID
  219. type: 'routine'
  220. };
  221. Routine.authUserInfo(userInfo)
  222. })
  223. .catch(res => {
  224. uni.hideLoading();
  225. });
  226. }
  227. // #endif
  228. //分销绑定
  229. silenceBindingSpread(store.getters.isLogin, this.globalData.spread)
  230. //配置项存储
  231. store.commit('GLOBAL_DATA', JSON.parse(JSON.stringify(that.globalData)));
  232. },
  233. async mounted() {
  234. //if (this.$store.getters.isLogin && !this.$Cache.get('USER_INFO')) await this.$store.dispatch('USERINFO');
  235. },
  236. methods: {
  237. handleResize(e) {
  238. /* 窗口宽度大于430px且不在PC页面且不在移动设备时跳转至 PC.html 页面 */
  239. if (e.size.windowWidth > 430 && !/iOS|Android/i.test(e.system)) {
  240. // window.location.pathname = 'https://java.crmeb.net/';
  241. /* 若你的项目未设置根目录(默认为 / 时),则使用下方代码 */
  242. window.location.pathname = '/static/html/pc.html';
  243. }
  244. }
  245. },
  246. onShow: function() {
  247. // #ifdef H5
  248. uni.onWindowResize(this.handleResize);
  249. // #endif
  250. },
  251. onUnload() {
  252. // 页面销毁时移除监听
  253. uni.offWindowResize(this.handleResize);
  254. },
  255. }
  256. </script>
  257. <style>
  258. .uno-start {
  259. --un: 0;
  260. }
  261. /* unocss 代码生成在这 */
  262. .uno-end {
  263. --un: 0;
  264. }
  265. </style>
  266. <style lang="scss">
  267. /* #ifndef APP-PLUS-NVUE || APP-NVUE */
  268. @import "@/plugin/animate/animate.min.css";
  269. @import 'static/css/unocss.css';
  270. @import 'static/css/base.css';
  271. @import 'static/css/style.scss';
  272. @import 'static/iconfont/iconfont.css';
  273. @import 'static/fonts/font.css';
  274. view {
  275. box-sizing: border-box;
  276. }
  277. body::-webkit-scrollbar,
  278. html::-webkit-scrollbar {
  279. display: none;
  280. }
  281. .bg-color-red {
  282. background-color: #E93323;
  283. }
  284. .syspadding {
  285. padding-top: var(--status-bar-height);
  286. }
  287. /deep/.uni-scroll-view::-webkit-scrollbar {
  288. /* 隐藏滚动条,但依旧具备可以滚动的功能 */
  289. display: none
  290. }
  291. ::-moz-scrollbar {
  292. width: 0;
  293. height: 0;
  294. color: transparent;
  295. }
  296. ::-webkit-scrollbar {
  297. display: none;
  298. width: 0 !important;
  299. height: 0 !important;
  300. -webkit-appearance: none;
  301. background: transparent;
  302. }
  303. checkbox.mycheck .wx-checkbox-input,
  304. checkbox.mycheck .uni-checkbox-input {
  305. width: 30rpx !important;
  306. height: 30rpx !important;
  307. background-color: #fff !important;
  308. border-radius: 4rpx !important;
  309. border: 2rpx solid #D6D7DC !important;
  310. }
  311. // 选中后的 对勾样式
  312. checkbox.mycheck .uni-checkbox-input-checked::before,
  313. checkbox.mycheck .wx-checkbox-input-checked::before {
  314. // width: 25rpx !important; // 选中后对勾大小,不要超过背景的尺寸
  315. // height: 25rpx !important; // 选中后对勾大小,不要超过背景的尺寸 
  316. font-size: 36rpx !important; // 对勾大小 30rpx
  317. color: #fff !important;
  318. background-color: $bg-color-primary;
  319. }
  320. /*#endif*/
  321. </style>