diff --git a/template/uni-app/App.vue b/template/uni-app/App.vue index a22ea6483..8b91effc7 100644 --- a/template/uni-app/App.vue +++ b/template/uni-app/App.vue @@ -214,6 +214,13 @@ // #ifdef MP let menuButtonInfo = uni.getMenuButtonBoundingClientRect(); that.globalData.navH = menuButtonInfo.top * 2 + menuButtonInfo.height / 2; + const version = uni.getSystemInfoSync().SDKVersion + if (Routine.compareVersion(version, '2.21.2') >= 0) { + console.log(version) + that.$Cache.set('MP_VERSION_ISNEW', true) + } else { + that.$Cache.set('MP_VERSION_ISNEW', false) + } // #endif // #ifdef H5 @@ -230,87 +237,6 @@ } else { this.globalData.isIframe = false; } - - //公众号静默授权 - // if (window.location.pathname !== '/' && option.query.scope === 'snsapi_base') { - // let snsapiBase = 'snsapi_base'; - // let urlData = location.pathname + location.search; - // // if (!that.$store.getters.isLogin && uni.getStorageSync('authIng')) { - // // uni.setStorageSync('authIng', false) - // // } - // if (!that.$store.getters.isLogin && Auth.isWeixin()) { - // let code, - // state, - // scope = '' - - // if (option.query.code instanceof Array) { - // code = option.query.code[option.query.code.length - 1] - // } else { - // code = option.query.code - // } - - - // if (code && code != uni.getStorageSync('snsapiCode') && location.pathname.indexOf( - // '/pages/users/wechat_login/index') === -1) { - // // 存储静默授权code - // uni.setStorageSync('snsapiCode', code); - // let spread = that.globalData.spid ? that.globalData.spid : ''; - // uni.setStorageSync('authIng', true) - // silenceAuth({ - // code: code, - // spread: that.$Cache.get('spread'), - // spid: that.globalData.code - // }) - // .then(res => { - // uni.setStorageSync('authIng', false) - // uni.setStorageSync('snRouter', decodeURIComponent(decodeURIComponent(option.query - // .back_url))); - // if (res.data.key !== undefined && res.data.key) { - // this.$Cache.set('snsapiKey', res.data.key); - // } else { - - // let time = res.data.expires_time - this.$Cache.time(); - // this.$store.commit('LOGIN', { - // token: res.data.token, - // time: time - // }); - // this.$Cache.set('WX_AUTH', code); - // this.$store.commit('SETUID', res.data.userInfo.uid); - // this.$store.commit('UPDATE_USERINFO', res.data.userInfo); - - // if (option.query.back_url) { - // location.replace(decodeURIComponent(decodeURIComponent(option.query - // .back_url))); - // } - // } - // }) - // .catch(error => { - // uni.setStorageSync('authIng', false) - // let url = '' - // if (option.query.back_url instanceof Array) { - // url = option.query.back_url[option.query.back_url.length - 1] - // } else { - // url = option.query.back_url - // } - // if (!that.$Cache.has('snsapiKey')) { - // if (location.pathname.indexOf('/pages/users/wechat_login/index') === -1) { - // Auth.oAuth(snsapiBase, url); - // } - // } - // }); - // } else { - // if (!this.$Cache.has('snsapiKey')) { - // if (location.pathname.indexOf('/pages/users/wechat_login/index') === -1) { - // Auth.oAuth(snsapiBase, urlData); - // } - // } - // } - // } else { - // if (option.query.back_url) { - // location.replace(uni.getStorageSync('snRouter')); - // } - // } - // } // #endif // #ifdef MP // 小程序静默授权 @@ -334,6 +260,11 @@ uni.setStorageSync('copyRight', res.data) }) }, + // #ifdef H5 + onHide() { + this.$Cache.clear('snsapiKey') + }, + // #endif methods: { // 小程序静默授权 // silenceAuth(code) { @@ -359,9 +290,7 @@ // .catch(res => {}); // }, }, - onHide: function() { - } }; diff --git a/template/uni-app/api/public.js b/template/uni-app/api/public.js index 7f79be63a..f6b70064c 100644 --- a/template/uni-app/api/public.js +++ b/template/uni-app/api/public.js @@ -1,193 +1,204 @@ -// +---------------------------------------------------------------------- -// | CRMEB [ CRMEB赋能开发者,助力企业发展 ] -// +---------------------------------------------------------------------- -// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. -// +---------------------------------------------------------------------- -// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 -// +---------------------------------------------------------------------- -// | Author: CRMEB Team -// +---------------------------------------------------------------------- - -import request from "@/utils/request.js"; -import wechat from "@/libs/wechat.js"; - -/** - * 获取微信sdk配置 - * @returns {*} - */ -export function getWechatConfig() { - return request.get( - "wechat/config", { - url: wechat.signLink() - }, { - noAuth: true - } - ); -} - -/** - * 获取微信sdk配置 - * @returns {*} - */ -export function wechatAuth(code, spread, login_type) { - return request.get( - "wechat/auth", { - code, - spread, - login_type - }, { - noAuth: true - } - ); -} - -/** - * 获取登录授权login - * - */ -export function getLogo() { - return request.get('wechat/get_logo', {}, { - noAuth: true - }); -} - -/** - * 小程序用户登录 - * @param data object 小程序用户登陆信息 - */ -export function login(data) { - return request.post("wechat/mp_auth", data, { - noAuth: true - }); -} - -/** - * 静默授权 - * @param {Object} data - */ -export function silenceAuth(data) { - //#ifdef MP - return request.get("v2/wechat/silence_auth", data, { - noAuth: true - }); - //#endif - //#ifdef H5 - return request.get("v2/wechat/wx_silence_auth", data, { - noAuth: true - }); - //#endif -} - -/** - * 分享 - * @returns {*} - */ -export function getShare() { - return request.get("share", {}, { - noAuth: true - }); -} - -/** - * 获取关注海报 - * @returns {*} - */ -export function follow() { - return request.get("wechat/follow", {}, { - noAuth: true - }); -} - -/** - * 获取图片base64 - * @retins {*} - * */ -export function imageBase64(image, code) { - return request.post( - "image_base64", { - image: image, - code: code - }, { - noAuth: true - } - ); -} - -/** - * 自动复制口令功能 - * @returns {*} - */ -export function copyWords() { - return request.get("copy_words", {}, { - noAuth: true - }); -} - -/** - * 获取商城是否强制绑定手机号 - */ -export function getShopConfig() { - return request.get('v2/bind_status', {}, { - noAuth: true - }); -} - -/** - * 小程序绑定手机号 - * @param {Object} data - */ -export function getUserPhone(data) { - return request.post('v2/auth_bindind_phone', data, { - noAuth: true - }); -} - -/** - * 小程序用户登录 - * @param data object 小程序用户登陆信息 - */ -export function routineLogin(data) { - return request.get("v2/wechat/routine_auth", data, { - noAuth: true - }); -} - -/** - * 获取微信sdk配置 - * @returns {*} - */ -export function wechatAuthV2(code, spread) { - return request.get( - "v2/wechat/auth", { - code, - spread - }, { - noAuth: true - } - ); -} - -/** - * 获取组件底部菜单 - * @param data object 获取组件底部菜单 - */ -export function getNavigation(data) { - return request.get("navigation", data, { - noAuth: true - }); -} -export function getSubscribe() { - return request.get("subscribe", {}, { - noAuth: true - }); -} - -/** - * 获取版本信息 - * @param 系统类型 - */ -export function getUpdateInfo(type) { - return request.get("get_new_app/" + type, {}, { - noAuth: true - }); +// +---------------------------------------------------------------------- +// | CRMEB [ CRMEB赋能开发者,助力企业发展 ] +// +---------------------------------------------------------------------- +// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. +// +---------------------------------------------------------------------- +// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 +// +---------------------------------------------------------------------- +// | Author: CRMEB Team +// +---------------------------------------------------------------------- + +import request from "@/utils/request.js"; +import wechat from "@/libs/wechat.js"; + +/** + * 获取微信sdk配置 + * @returns {*} + */ +export function getWechatConfig() { + return request.get( + "wechat/config", { + url: wechat.signLink() + }, { + noAuth: true + } + ); +} + +/** + * 获取微信sdk配置 + * @returns {*} + */ +export function wechatAuth(code, spread, login_type) { + return request.get( + "wechat/auth", { + code, + spread, + login_type + }, { + noAuth: true + } + ); +} + +/** + * 获取登录授权login + * + */ +export function getLogo() { + return request.get('wechat/get_logo', {}, { + noAuth: true + }); +} + +/** + * 小程序用户登录 + * @param data object 小程序用户登陆信息 + */ +export function login(data) { + return request.post("wechat/mp_auth", data, { + noAuth: true + }); +} + +/** + * 静默授权 + * @param {Object} data + */ +export function silenceAuth(data) { + //#ifdef MP + return request.get("v2/wechat/silence_auth", data, { + noAuth: true + }); + //#endif + //#ifdef H5 + return request.get("v2/wechat/wx_silence_auth", data, { + noAuth: true + }); + //#endif +} + +/** + * 分享 + * @returns {*} + */ +export function getShare() { + return request.get("share", {}, { + noAuth: true + }); +} + +/** + * 获取关注海报 + * @returns {*} + */ +export function follow() { + return request.get("wechat/follow", {}, { + noAuth: true + }); +} + +/** + * code生成用户 + * @returns {*} + */ +export function authLogin(data) { + return request.get("v2/wechat/silence_auth_login", data, { + noAuth: true + }); +} + + +/** + * 获取图片base64 + * @retins {*} + * */ +export function imageBase64(image, code) { + return request.post( + "image_base64", { + image: image, + code: code + }, { + noAuth: true + } + ); +} + +/** + * 自动复制口令功能 + * @returns {*} + */ +export function copyWords() { + return request.get("copy_words", {}, { + noAuth: true + }); +} + +/** + * 获取商城是否强制绑定手机号 + */ +export function getShopConfig() { + return request.get('v2/bind_status', {}, { + noAuth: true + }); +} + +/** + * 小程序绑定手机号 + * @param {Object} data + */ +export function getUserPhone(data) { + return request.post('v2/auth_bindind_phone', data, { + noAuth: true + }); +} + +/** + * 小程序用户登录 + * @param data object 小程序用户登陆信息 + */ +export function routineLogin(data) { + return request.get("v2/wechat/routine_auth", data, { + noAuth: true + }); +} + +/** + * 获取微信sdk配置 + * @returns {*} + */ +export function wechatAuthV2(code, spread) { + return request.get( + "v2/wechat/auth", { + code, + spread + }, { + noAuth: true + } + ); +} + +/** + * 获取组件底部菜单 + * @param data object 获取组件底部菜单 + */ +export function getNavigation(data) { + return request.get("navigation", data, { + noAuth: true + }); +} +export function getSubscribe() { + return request.get("subscribe", {}, { + noAuth: true + }); +} + +/** + * 获取版本信息 + * @param 系统类型 + */ +export function getUpdateInfo(type) { + return request.get("get_new_app/" + type, {}, { + noAuth: true + }); } diff --git a/template/uni-app/libs/routine.js b/template/uni-app/libs/routine.js index 47b6ea752..ed338068a 100644 --- a/template/uni-app/libs/routine.js +++ b/template/uni-app/libs/routine.js @@ -1,220 +1,252 @@ -// +---------------------------------------------------------------------- -// | CRMEB [ CRMEB赋能开发者,助力企业发展 ] -// +---------------------------------------------------------------------- -// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. -// +---------------------------------------------------------------------- -// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 -// +---------------------------------------------------------------------- -// | Author: CRMEB Team -// +---------------------------------------------------------------------- - -import store from '../store'; -import { - checkLogin -} from './login'; -import { - login, - routineLogin, - silenceAuth -} from '../api/public'; -import Cache from '../utils/cache'; -import { - STATE_R_KEY, - USER_INFO, - EXPIRES_TIME, - LOGIN_STATUS -} from './../config/cache'; -import { - mapGetters -} from "vuex"; -class Routine { - - constructor() { - this.scopeUserInfo = 'scope.userInfo'; - } - - async getUserCode() { - let isAuth = await this.isAuth(), - code = ''; - if (isAuth) - code = await this.getCode(); - return code; - } - // 小程序静默授权 - // silenceAuth(code) { - // const app = getApp(); - // let that = this; - // let spread = app.globalData.spid ? app.globalData.spid : ''; - // return new Promise((resolve, reject) => { - // silenceAuth({ - // code: code, - // spread_spid: spread, - // spread_code: app.globalData.code - // }) - // .then(res => { - // if (res.data && res.data.token !== undefined) { - // uni.hideLoading(); - // let time = res.data.expires_time - Math.round(new Date() / 1000); - // store.commit('LOGIN', { - // token: res.data.token, - // time: time - // }); - // store.commit('SETUID', res.data.userInfo.uid); - // store.commit('UPDATE_USERINFO', res.data.userInfo); - // resolve(res) - // } else { - // reject() - // uni.navigateTo({ - // url: '/pages/users/wechat_login/index' - // }) - // } - // }) - // .catch(err => { - // reject(err) - // }); - // }) - // } - /** - * 获取用户信息 - */ - getUserInfo() { - let that = this, - code = this.getUserCode(); - return new Promise((resolve, reject) => { - uni.getUserInfo({ - lang: 'zh_CN', - success(user) { - if (code) user.code = code; - resolve({ - userInfo: user, - islogin: false - }); - }, - fail(res) { - reject(res); - } - }) - }) - } - - /** - * 新版小程序获取用户信息 2021 4.13微信小程序开始正式启用 - */ - getUserProfile(code) { - return new Promise((resolve, reject) => { - uni.getUserProfile({ - lang: 'zh_CN', - desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 - success(user) { - if (code) user.code = code; - resolve({ - userInfo: user, - islogin: false - }); - }, - fail(res) { - reject(res); - } - }) - }) - } - - /** - * 获取用户信息 - */ - authorize() { - let that = this; - return new Promise((resolve, reject) => { - if (checkLogin()) - return resolve({ - userInfo: Cache.get(USER_INFO, true), - islogin: true, - }); - uni.authorize({ - scope: that.scopeUserInfo, - success() { - resolve({ - islogin: false - }); - }, - fail(res) { - reject(res); - } - }) - }) - } - - async getCode() { - let provider = await this.getProvider(); - return new Promise((resolve, reject) => { - // if(Cache.has(STATE_R_KEY)){ - // return resolve(Cache.get(STATE_R_KEY)); - // } - uni.login({ - provider: provider, - success(res) { - if (res.code) Cache.set(STATE_R_KEY, res.code, 10800); - return resolve(res.code); - }, - fail() { - return reject(null); - } - }) - }) - } - - /** - * 获取服务供应商 - */ - getProvider() { - return new Promise((resolve, reject) => { - uni.getProvider({ - service: 'oauth', - success(res) { - resolve(res.provider); - }, - fail() { - resolve(false); - } - }); - }); - } - - /** - * 是否授权 - */ - isAuth() { - let that = this; - return new Promise((resolve, reject) => { - uni.getSetting({ - success(res) { - if (!res.authSetting[that.scopeUserInfo]) { - resolve(true) - } else { - resolve(true); - } - }, - fail() { - resolve(false); - } - }); - }); - } - - authUserInfo(data) { - return new Promise((resolve, reject) => { - routineLogin(data).then(res => { - if (res.data.key !== undefined && res.data.key) {} else { - store.commit('UPDATE_USERINFO', res.data.userInfo); - store.commit('SETUID', res.data.userInfo.uid); - Cache.set(USER_INFO, res.data.userInfo); - } - return resolve(res); - }).catch(res => { - return reject(res); - }) - }) - } -} - +// +---------------------------------------------------------------------- +// | CRMEB [ CRMEB赋能开发者,助力企业发展 ] +// +---------------------------------------------------------------------- +// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. +// +---------------------------------------------------------------------- +// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 +// +---------------------------------------------------------------------- +// | Author: CRMEB Team +// +---------------------------------------------------------------------- + +import store from '../store'; +import { + checkLogin +} from './login'; +import { + login, + routineLogin, + silenceAuth +} from '../api/public'; +import Cache from '../utils/cache'; +import { + STATE_R_KEY, + USER_INFO, + EXPIRES_TIME, + LOGIN_STATUS +} from './../config/cache'; +import { + mapGetters +} from "vuex"; +class Routine { + + constructor() { + this.scopeUserInfo = 'scope.userInfo'; + } + + async getUserCode() { + let isAuth = await this.isAuth(), + code = ''; + if (isAuth) + code = await this.getCode(); + return code; + } + // 小程序静默授权 + // silenceAuth(code) { + // const app = getApp(); + // let that = this; + // let spread = app.globalData.spid ? app.globalData.spid : ''; + // return new Promise((resolve, reject) => { + // silenceAuth({ + // code: code, + // spread_spid: spread, + // spread_code: app.globalData.code + // }) + // .then(res => { + // if (res.data && res.data.token !== undefined) { + // uni.hideLoading(); + // let time = res.data.expires_time - Math.round(new Date() / 1000); + // store.commit('LOGIN', { + // token: res.data.token, + // time: time + // }); + // store.commit('SETUID', res.data.userInfo.uid); + // store.commit('UPDATE_USERINFO', res.data.userInfo); + // resolve(res) + // } else { + // reject() + // uni.navigateTo({ + // url: '/pages/users/wechat_login/index' + // }) + // } + // }) + // .catch(err => { + // reject(err) + // }); + // }) + // } + /** + * 获取用户信息 + */ + getUserInfo() { + let that = this, + code = this.getUserCode(); + return new Promise((resolve, reject) => { + uni.getUserInfo({ + lang: 'zh_CN', + success(user) { + if (code) user.code = code; + resolve({ + userInfo: user, + islogin: false + }); + }, + fail(res) { + reject(res); + } + }) + }) + } + + /** + * 新版小程序获取用户信息 2021 4.13微信小程序开始正式启用 + */ + getUserProfile(code) { + return new Promise((resolve, reject) => { + uni.getUserProfile({ + lang: 'zh_CN', + desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success(user) { + if (code) user.code = code; + resolve({ + userInfo: user, + islogin: false + }); + }, + fail(res) { + reject(res); + } + }) + }) + } + + /** + * 获取用户信息 + */ + authorize() { + let that = this; + return new Promise((resolve, reject) => { + if (checkLogin()) + return resolve({ + userInfo: Cache.get(USER_INFO, true), + islogin: true, + }); + uni.authorize({ + scope: that.scopeUserInfo, + success() { + resolve({ + islogin: false + }); + }, + fail(res) { + reject(res); + } + }) + }) + } + + async getCode() { + let provider = await this.getProvider(); + return new Promise((resolve, reject) => { + // if(Cache.has(STATE_R_KEY)){ + // return resolve(Cache.get(STATE_R_KEY)); + // } + uni.login({ + provider: provider, + success(res) { + console.log(res, '22222') + if (res.code) Cache.set(STATE_R_KEY, res.code, 10800); + return resolve(res.code); + }, + fail() { + return reject(null); + } + }) + }) + } + + /** + * 获取服务供应商 + */ + getProvider() { + return new Promise((resolve, reject) => { + uni.getProvider({ + service: 'oauth', + success(res) { + resolve(res.provider); + }, + fail() { + resolve(false); + } + }); + }); + } + + /** + * 是否授权 + */ + isAuth() { + let that = this; + return new Promise((resolve, reject) => { + uni.getSetting({ + success(res) { + if (!res.authSetting[that.scopeUserInfo]) { + resolve(true) + } else { + resolve(true); + } + }, + fail() { + resolve(false); + } + }); + }); + } + /** + * 小程序比较版本信息 + * @param v1 当前版本 + * @param v2 进行比较的版本 + * @return boolen + * + */ + compareVersion(v1, v2) { + v1 = v1.split('.') + v2 = v2.split('.') + const len = Math.max(v1.length, v2.length) + + while (v1.length < len) { + v1.push('0') + } + while (v2.length < len) { + v2.push('0') + } + + for (let i = 0; i < len; i++) { + const num1 = parseInt(v1[i]) + const num2 = parseInt(v2[i]) + + if (num1 > num2) { + return 1 + } else if (num1 < num2) { + return -1 + } + } + + return 0 + } + authUserInfo(data) { + return new Promise((resolve, reject) => { + routineLogin(data).then(res => { + if (res.data.key !== undefined && res.data.key) {} else { + store.commit('UPDATE_USERINFO', res.data.userInfo); + store.commit('SETUID', res.data.userInfo.uid); + Cache.set(USER_INFO, res.data.userInfo); + } + return resolve(res); + }).catch(res => { + return reject(res); + }) + }) + } +} + export default new Routine(); diff --git a/template/uni-app/manifest.json b/template/uni-app/manifest.json index 852721939..5192b8206 100644 --- a/template/uni-app/manifest.json +++ b/template/uni-app/manifest.json @@ -167,7 +167,7 @@ "quickapp" : {}, /* 小程序特有相关 */ "mp-weixin" : { - "appid" : "wx1234567890", + "appid" : "wx3b82801238ca1b57", "setting" : { "urlCheck" : false, "minified" : true, diff --git a/template/uni-app/pages/auth/index.vue b/template/uni-app/pages/auth/index.vue index b2fd62d70..608aa826a 100644 --- a/template/uni-app/pages/auth/index.vue +++ b/template/uni-app/pages/auth/index.vue @@ -1,274 +1,290 @@ - - - - - - + + + + + + diff --git a/template/uni-app/pages/goods/order_list/index.vue b/template/uni-app/pages/goods/order_list/index.vue index 981ae6391..095d0fed0 100644 --- a/template/uni-app/pages/goods/order_list/index.vue +++ b/template/uni-app/pages/goods/order_list/index.vue @@ -1,663 +1,670 @@ - - - - - diff --git a/template/uni-app/pages/index/diy/components/customerService.vue b/template/uni-app/pages/index/diy/components/customerService.vue index 1a854b4f8..fd9ebf311 100644 --- a/template/uni-app/pages/index/diy/components/customerService.vue +++ b/template/uni-app/pages/index/diy/components/customerService.vue @@ -1,75 +1,86 @@ - - - - - diff --git a/template/uni-app/pages/user/index.vue b/template/uni-app/pages/user/index.vue index cfdabe0a8..c7d234154 100644 --- a/template/uni-app/pages/user/index.vue +++ b/template/uni-app/pages/user/index.vue @@ -27,13 +27,13 @@ -