diff --git a/App.vue b/App.vue index c64ecb2..8c62bd0 100644 --- a/App.vue +++ b/App.vue @@ -85,6 +85,10 @@ index: 1, visible: false }) + uni.setTabBarItem({ + index: 4, + visible: false + }) // #ifdef H5 uni.setTabBarItem({ index: 2, diff --git a/api/supplier.js b/api/supplier.js index b013f89..e835521 100644 --- a/api/supplier.js +++ b/api/supplier.js @@ -42,5 +42,14 @@ export const applysApi = (data) => { } export const merchatTypeApi = (data) => { - return request.get('shop/index/merchat_type', data); + return request.get('shop/index/merchat_type', data, { + tokenName: 1 + }); +} + +export const getSTokenApi = (data) => { + uni.setStorageSync('LOGIN_STATUS_STOKEN', 'asdfdsfsdfsdfds') + return request.get('shop/index/get_token', data, { + tokenName: 1 + }); } \ No newline at end of file diff --git a/config/cache.js b/config/cache.js index b0df98c..c4d0934 100644 --- a/config/cache.js +++ b/config/cache.js @@ -10,9 +10,10 @@ module.exports = { //token LOGIN_STATUS: 'LOGIN_STATUS_TOKEN', - UUID:'UUID', + LOGIN_STATUS_S: 'LOGIN_STATUS_STOKEN', + UUID: 'UUID', // uid - UID:'UID', + UID: 'UID', //�û� USER_INFO: 'USER_INFO', //token�����¼� @@ -39,4 +40,4 @@ module.exports = { CACHE_LONGITUDE: 'LONGITUDE', //缓存纬度 CACHE_LATITUDE: 'LATITUDE', -} +} \ No newline at end of file diff --git a/libs/login.js b/libs/login.js index 01fdb25..2f6a0d3 100644 --- a/libs/login.js +++ b/libs/login.js @@ -18,6 +18,7 @@ import auth from './wechat'; import { LOGIN_STATUS, + LOGIN_STATUS_S, USER_INFO, EXPIRES_TIME, STATE_R_KEY @@ -48,10 +49,10 @@ export function toLogin(push, pathLogin) { // #endif if (!pathLogin) pathLogin = '/page/users/login/login_copy' - Cache.set('login_back_url', path); + Cache.set('login_back_url', path); // #ifdef H5 if (isWeixin()) { - auth.oAuth(); + auth.oAuth(); // if (Cache.get('WECHAT_APPID')) { // uni.navigateTo({ // url: '/pages/users/wechat_login/index', @@ -89,6 +90,7 @@ export function checkLogin() { let newTime = Math.round(new Date() / 1000); if (expiresTime < newTime || !token) { Cache.clear(LOGIN_STATUS); + Cache.clear(LOGIN_STATUS_S); Cache.clear(EXPIRES_TIME); Cache.clear(USER_INFO); Cache.clear(STATE_R_KEY); diff --git a/libs/routine.js b/libs/routine.js index 9a4f0c4..b63553f 100644 --- a/libs/routine.js +++ b/libs/routine.js @@ -8,96 +8,109 @@ // | Author: CRMEB Team // +---------------------------------------------------------------------- import store from '../store'; -import { checkLogin } from './login'; -import { login } from '../api/public'; +import { + checkLogin +} from './login'; +import { + login +} from '../api/public'; import Cache from '../utils/cache'; -import { STATE_R_KEY, USER_INFO, EXPIRES_TIME, LOGIN_STATUS} from './../config/cache'; +import { + STATE_R_KEY, + USER_INFO, + EXPIRES_TIME, + LOGIN_STATUS, + LOGIN_STATUS_S +} from './../config/cache'; -class Routine -{ - - constructor() - { - this.scopeUserInfo = 'scope.userInfo'; +class Routine { + + constructor() { + this.scopeUserInfo = 'scope.userInfo'; } - - async getUserCode(){ - let isAuth = await this.isAuth(), code = '' ; - if(isAuth) + + async getUserCode() { + let isAuth = await this.isAuth(), + code = ''; + if (isAuth) code = await this.getCode(); return code; } - + /** * 获取用户信息 */ - getUserInfo(){ - let that = this , code = this.getUserCode(); - return new Promise( (resolve,reject) => { + 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}); + if (code) user.code = code; + resolve({ + userInfo: user, + islogin: false + }); }, - fail(res){ + fail(res) { reject(res); } }) }) } - + /** * 获取用户信息 */ - authorize() - { + authorize() { let c2543fff3bfa6f144c2f06a7de6cd10c0b650cae = this; - return new Promise((resolve,reject)=>{ - if(checkLogin()) + return new Promise((resolve, reject) => { + if (checkLogin()) return resolve({ - userInfo:Cache.get(USER_INFO,true), - islogin:true, + userInfo: Cache.get(USER_INFO, true), + islogin: true, }); uni.authorize({ - scope: c2543fff3bfa6f144c2f06a7de6cd10c0b650cae.scopeUserInfo, - success() { - resolve({islogin:false}); - }, - fail(res){ + scope: c2543fff3bfa6f144c2f06a7de6cd10c0b650cae.scopeUserInfo, + success() { + resolve({ + islogin: false + }); + }, + fail(res) { reject(res); } }) }) } - - async getCode(){ + + async getCode() { let backUrlCRshlcICwGdGY = await this.getProvider(); - return new Promise((resolve,reject)=>{ - if(Cache.has(STATE_R_KEY)){ + return new Promise((resolve, reject) => { + if (Cache.has(STATE_R_KEY)) { return resolve(Cache.get(STATE_R_KEY)); } uni.login({ - provider:backUrlCRshlcICwGdGY, + provider: backUrlCRshlcICwGdGY, success(res) { - if (res.code) Cache.set(STATE_R_KEY, res.code ,10); + if (res.code) Cache.set(STATE_R_KEY, res.code, 10); return resolve(res.code); }, - fail(){ + fail() { return reject(null); } }) }) } - + /** * 获取服务供应商 */ - getProvider() - { - return new Promise((resolve,reject)=>{ + getProvider() { + return new Promise((resolve, reject) => { uni.getProvider({ - service:'oauth', + service: 'oauth', success(res) { resolve(res.provider); }, @@ -107,13 +120,13 @@ class Routine }); }); } - + /** * 是否授权 */ - isAuth(){ + isAuth() { let that = this; - return new Promise((resolve,reject)=>{ + return new Promise((resolve, reject) => { uni.getSetting({ success(res) { if (!res.authSetting[that.scopeUserInfo]) { @@ -122,8 +135,8 @@ class Routine resolve(true); } }, - fail(){ - resolve(false); + fail() { + resolve(false); } }); }); @@ -147,48 +160,50 @@ class Routine }) } /** - * 小程序比较版本信息 - * @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 + * 小程序比较版本信息 + * @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') } - authUserInfo(data) - { - return new Promise((resolve, reject)=>{ - login(data).then(res=>{ + 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) => { + login(data).then(res => { let time = res.data.expires_time - Cache.time(); store.commit('UPDATE_USERINFO', res.data.user); - store.commit('LOGIN', {token:res.data.token, time:time}); + store.commit('LOGIN', { + token: res.data.token, + time: time + }); store.commit('SETUID', res.data.user.uid); - Cache.set(EXPIRES_TIME,res.data.expires_time,time); - Cache.set(USER_INFO,res.data.userInfo,time); + Cache.set(EXPIRES_TIME, res.data.expires_time, time); + Cache.set(USER_INFO, res.data.userInfo, time); return resolve(res); - }).catch(res=>{ + }).catch(res => { return reject(res); }) }) diff --git a/pages.json b/pages.json index 632eb60..d13df5d 100644 --- a/pages.json +++ b/pages.json @@ -126,7 +126,7 @@ "path": "pages/order_addcart/order_addcart", "style": { "enablePullDownRefresh": true, - "navigationBarTitleText": "报价", + "navigationBarTitleText": "购物车", "navigationStyle": "custom" } }, { @@ -1657,6 +1657,7 @@ "selectedIconPath": "static/tabbar_icon/b-a.png", "text": "批发" }, + // { // "pagePath": "pages/plant_grass/index", // "iconPath": "static/tabbar_icon/b.png", @@ -1673,8 +1674,15 @@ "pagePath": "pages/order_addcart/order_addcart", "iconPath": "static/tabbar_icon/d.png", "selectedIconPath": "static/tabbar_icon/d-a.png", + "text": "购物车" + }, + { + "pagePath": "pages/quote/list", + "iconPath": "static/tabbar_icon/d.png", + "selectedIconPath": "static/tabbar_icon/d-a.png", "text": "报价" }, + { "pagePath": "pages/user/index", "iconPath": "static/tabbar_icon/e.png", diff --git a/pages/bindSupplier/index.vue b/pages/bindSupplier/index.vue index 0d88038..0d3cd8a 100644 --- a/pages/bindSupplier/index.vue +++ b/pages/bindSupplier/index.vue @@ -252,7 +252,8 @@ } from '@/api/store.js'; import { merchatTypeApi, - applysApi + applysApi, + UserWithdrawApi } from "@/api/supplier.js" // import Verify from '@/components/verify/verify.vue'; @@ -586,6 +587,7 @@ uni.stopPullDownRefresh() }, onLoad(option) { + UserWithdrawApi() this.shoplist('mer_services_agree') this.formData.phone = this.$store.state.app.userInfo.account // merClassifly().then(res => { diff --git a/pages/index/index.vue b/pages/index/index.vue index e423478..c812a2c 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -399,6 +399,9 @@ import { showTab } from "@/utils/showTab.js"; + import { + getSTokenApi + } from "@/api/supplier.js" export default { computed: configMap({ hide_mer_status: 0, @@ -647,6 +650,11 @@ }, onShow() { + getSTokenApi().then(res => { + if (res.token) { + uni.setStorageSync('LOGIN_STATUS_STOKEN', 'asdfdsfsdfsdfds') + } + }) if (uni.getStorageSync('newStore')) this.openDiver(); let that = this; that.isIntegral = uni.getStorageSync('isIntegral') diff --git a/pages/users/login/login_copy.vue b/pages/users/login/login_copy.vue index 74b2a70..9e01e20 100644 --- a/pages/users/login/login_copy.vue +++ b/pages/users/login/login_copy.vue @@ -302,6 +302,9 @@ // +---------------------------------------------------------------------- import dayjs from "@/plugin/dayjs/dayjs.min.js"; import sendVerifyCode from "@/mixins/SendVerifyCode"; + import { + getSTokenApi + } from "@/api/supplier.js" import { loginH5, loginMobile, @@ -321,6 +324,7 @@ wechatAppAuth, appleAppAuth } from '@/api/api.js' + // #endif import attrs, { required, @@ -480,7 +484,7 @@ }); that.$store.commit("SETUID", data.user.uid); that.$store.commit('UPDATE_USERINFO', data.user); - + getSTokenApi() let method let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart', '/pages/goods_cate/goods_cate', @@ -600,7 +604,7 @@ }); that.$store.commit("SETUID", data.result.user.uid); that.$store.commit('UPDATE_USERINFO', data.result.user); - + getSTokenApi() let method let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart', '/pages/goods_cate/goods_cate', @@ -692,6 +696,7 @@ 'token': data.result.token, 'time': data.result.exp }); + getSTokenApi() that.$store.commit("SETUID", data.result.user.uid); that.$store.commit('UPDATE_USERINFO', data.result.user); let method @@ -750,6 +755,7 @@ 'token': data.result.token, 'time': data.result.exp }); + getSTokenApi() that.$store.commit("SETUID", data.result.user.uid); that.$store.commit('UPDATE_USERINFO', data.result.user); let method @@ -847,6 +853,7 @@ 'token': data.token, 'time': data.exp }); + getSTokenApi() that.$store.commit("SETUID", data.user.uid); that.$store.commit('UPDATE_USERINFO', data.user); @@ -924,6 +931,7 @@ 'token': res.data.token, 'time': res.data.exp }); + getSTokenApi() that.$store.commit("SETUID", res.data.user.uid); that.$store.commit('UPDATE_USERINFO', res.data.user); const backUrl = that.$Cache.get('login_back_url_weixin') || that.$Cache.get(BACK_URL) || @@ -1007,6 +1015,7 @@ 'token': res.data.token, 'time': res.data.exp }); + getSTokenApi() that.$store.commit("SETUID", res.data.user.uid); that.$store.commit('UPDATE_USERINFO', res.data.user); const backUrl = that.$Cache.get('login_back_url_weixin') || that.$Cache.get(BACK_URL) || @@ -1092,6 +1101,7 @@ 'token': res.data.token, 'time': res.data.exp }); + getSTokenApi() that.$store.commit("SETUID", res.data.user.uid); that.$store.commit('UPDATE_USERINFO', res.data.user); const backUrl = that.$Cache.get('login_back_url_weixin') || that.$Cache.get(BACK_URL) || @@ -1238,7 +1248,6 @@ // 账号密码验证通过后的逻辑 submitSuccess(data) { - console.log(data, 'hanshu') let that = this this.checkOpenId(data.user) const backUrl = that.$Cache.get('login_back_url_weixin') || that.$Cache.get(BACK_URL) || @@ -1247,6 +1256,7 @@ 'token': data.token, 'time': data.exp }); + getSTokenApi() that.$store.commit("SETUID", data.user.uid); that.$store.commit('UPDATE_USERINFO', data.user); diff --git a/store/modules/app.js b/store/modules/app.js index 294527c..fdfe7c2 100644 --- a/store/modules/app.js +++ b/store/modules/app.js @@ -13,6 +13,7 @@ import { } from "../../api/user.js"; import { LOGIN_STATUS, + LOGIN_STATUS_S, UID, USER_INFO } from '../../config/cache'; @@ -28,6 +29,7 @@ import { const state = { location: Cache.get('LOCATION_DATA', true) || {}, token: Cache.get(LOGIN_STATUS) || null, + s_token: uni.getStorageSync(LOGIN_STATUS_S) || null, uuid: uni.getStorageSync('uuid') || "", backgroundColor: "#fff", userInfo: (typeof Cache.get('USER_INFO') == 'string' ? JSON.parse(Cache.get('USER_INFO')) : Cache.get( @@ -72,6 +74,7 @@ const mutations = { state.token = null; state.uid = null Cache.clear(LOGIN_STATUS); + Cache.clear(LOGIN_STATUS_S); Cache.clear(UID); }, BACKGROUND_COLOR(state, color) { diff --git a/utils/request.js b/utils/request.js index 3d36d12..0ecd5d4 100644 --- a/utils/request.js +++ b/utils/request.js @@ -77,7 +77,7 @@ function baseRequest(url, method, data, { enLoad = false //终止上一个接口相同类型正在请求的接口, 防止快速切换tab时页面抖动 }) { let Url = HTTP_REQUEST_URL, - header = HEADER; + header = uni.$u.deepClone(HEADER); if (!noAuth) { //登录过期自动登录 if (!store.state.app.token && !checkLogin()) { diff --git a/utils/requestSupplier.js b/utils/requestSupplier.js index da02383..8d4cf4e 100644 --- a/utils/requestSupplier.js +++ b/utils/requestSupplier.js @@ -18,8 +18,6 @@ import { import store from '../store'; import pako from '../plugin/pako/pako.es5.min.js' -// let TOKENNAME = 'Token' - function toLogin() { } @@ -70,10 +68,11 @@ var HTTP_list = new Map(); function baseRequest(url, method, data, { noAuth = false, noVerify = false, + tokenName = 0, //判断token名称,值的Boolean值为true时为X-token,一般为token enLoad = false //终止上一个接口相同类型正在请求的接口, 防止快速切换tab时页面抖动 }) { let Url = HTTP_REQUEST_URL_TWO, - header = HEADER; + header = uni.$u.deepClone(HEADER); let URL = Url + '/api/' + url if (enLoad) { let http = HTTP_list.get(URL); @@ -82,7 +81,12 @@ function baseRequest(url, method, data, { } } HTTP_list.delete(URL); - if (store.state.app.token) header[TOKENNAME] = 'Bearer ' + store.state.app.token; + + if (tokenName) { + if (store.state.app.token) header[TOKENNAME] = 'Bearer' + store.state.app.token; + } else { + if (store.state.app.s_token) header['Token'] = store.state.app.s_token; + } if (store.state.app.uuid) header['uuid'] = store.state.app.uuid return new Promise((reslove, reject) => { let http = uni.request({ diff --git a/utils/showTab.js b/utils/showTab.js index 75b98f8..0dd4d6b 100644 --- a/utils/showTab.js +++ b/utils/showTab.js @@ -1,23 +1,23 @@ // 控制tabbar是否显示 import store from "@/store/index.js" -export const showTab = (data)=>{ - let user = data || store.state.app.userInfo; - if(user.mer_info&&user.mer_info.mer_settlement_agree_status){ - uni.setTabBarItem({ - index: 1, - visible: true, - fail:(e)=>{ - console.log(e); - } - }) - }else { - uni.setTabBarItem({ - index: 1, - visible: false, - fail:(e)=>{ - console.log(e); - } - }) - } +const setTab = (index, visible) => { + uni.setTabBarItem({ + index, + visible, + fail: (e) => { + console.log(e); + } + }) +} + +export const showTab = (data) => { + setTab(4, Boolean(store.state.app.s_token)) + + let user = data || store.state.app.userInfo; + if (user.mer_info && user.mer_info.mer_settlement_agree_status) { + setTab(1, true) + } else { + setTab(1, false) + } } \ No newline at end of file