diff --git a/App.vue b/App.vue
index ca032b2..2cf70cb 100644
--- a/App.vue
+++ b/App.vue
@@ -1,18 +1,24 @@
diff --git a/apis/loginApi.js b/apis/loginApi.js
new file mode 100644
index 0000000..678bf80
--- /dev/null
+++ b/apis/loginApi.js
@@ -0,0 +1,42 @@
+import http from '../utils/http/index.js'
+
+/**
+ * 手机登录获取验证码接口
+ * @param {object} data 获取验证码参数
+ * @returns 获取验证码结果
+ * swagger:http://api-ops-uec-test.qniao.cn/uec/swagger-ui/index.html?urls.primaryName=CustomerApi#/%E7%99%BB%E5%BD%95%E8%AE%A4%E8%AF%81/authorizeByCaptchaUsingPOST
+ */
+export const getAuthCaptcha = (data) => {
+ return http.post({
+ url: '/uec/get/auth-captcha',
+ data
+ })
+}
+
+/**
+ * 手机验证码登录,返回临时token
+ * @param {object} data 登录参数
+ * @returns {object} 返回参数 {token: '', userId: ''}
+ *
+ * swagger:http://api-ops-uec-test.qniao.cn/uec/swagger-ui/index.html?urls.primaryName=CustomerApi#/%E7%99%BB%E5%BD%95%E8%AE%A4%E8%AF%81/authorizeByCaptchaUsingPOST
+ */
+export const loginByPhone = (data) => {
+ return http.post({
+ url: '/uec/authorize/by-captcha',
+ data
+ })
+}
+
+/**
+ * 手机验证码登录,返回临时token
+ * @param {object} data 登录参数
+ * @returns {string} 返回参数 token:string
+ *
+ * swagger:http://api-ops-yyt-test.qniao.cn/yyt-uec/swagger-ui/index.html?urls.primaryName=CustomerApi#/%E7%99%BB%E5%BD%95%E8%AE%A4%E8%AF%81/getProductLineTokenByLoginTokenUsingPOST
+ */
+export const getQnToken = (data) => {
+ return http.post({
+ url: '/yyt-uec/authorize/get/product-line-token/by/login-token',
+ data
+ })
+}
diff --git a/enums/index.js b/enums/index.js
new file mode 100644
index 0000000..ab00116
--- /dev/null
+++ b/enums/index.js
@@ -0,0 +1,29 @@
+/**
+ * 账号类型
+ */
+export const accountType = {
+ WX: 1,
+ PHONE: 2,
+ EMAIL: 3,
+ APPLEID: 4,
+ CUSTOM: 5
+}
+
+/**
+ * 验证码用途
+ */
+export const codePurpose = {
+ CERTIFICATION: 1,
+ RESET_LOGIN_PASSWORD: 2,
+ RESET_PHONE: 3,
+ BIND_BANK_CARD: 4,
+ RESET_CREDIT_PASSWORD: 5
+}
+
+/**
+ * 可验证账号类型
+ */
+export const verificationType = {
+ PHONE: 1,
+ EMAIL: 2
+}
diff --git a/pages.json b/pages.json
index 6cd29cb..6ebbc62 100644
--- a/pages.json
+++ b/pages.json
@@ -24,6 +24,12 @@
"navigationBarTitleText": "登录",
"enablePullDownRefresh": false
}
+ },
+ {
+ "path": "pages/agreement/index",
+ "style": {
+ "navigationBarTitleText": "用户与隐私协议"
+ }
}
],
"globalStyle": {
diff --git a/pages/agreement/index.vue b/pages/agreement/index.vue
new file mode 100644
index 0000000..7ebaabe
--- /dev/null
+++ b/pages/agreement/index.vue
@@ -0,0 +1,35 @@
+
+ agreement
+
+
+
+
+
diff --git a/pages/login/index.vue b/pages/login/index.vue
index 43c6f6e..fd5f474 100644
--- a/pages/login/index.vue
+++ b/pages/login/index.vue
@@ -1,15 +1,270 @@
-
- login
-
+
+
+
+
+ 纸掌柜
+
+
+
+
+
+
+
+
+ {{ `(${timer}S后) ` }}
+ 重新获取
+
+
+ 获取验证码
+
+
+
+ 登录
+
+
+
+
+
+
+
+ 已阅读并同意纸掌柜
+
+ 《用户与隐私协议》
+
+
+
+
+
-
diff --git a/store/index.js b/store/index.js
index efd7dea..c958662 100644
--- a/store/index.js
+++ b/store/index.js
@@ -1,7 +1,131 @@
import Vue from 'vue'
import Vuex from 'vuex'
+import { isObject } from '@/utils/is'
+
+let qnToken = null,
+ userInfo = null,
+ supplierInfo = null,
+ uecToken = null
+try {
+ uecToken = uni.getStorageSync('uecToken')
+ qnToken = uni.getStorageSync('qnToken')
+ userInfo = uni.getStorageSync('userInfo')
+ if (userInfo) {
+ userInfo = JSON.parse(userInfo)
+ }
+ supplierInfo = uni.getStorageSync('supplierInfo')
+ if (supplierInfo) {
+ supplierInfo = JSON.parse(supplierInfo)
+ }
+} catch (e) {
+ console.error('初始化错误:', e)
+}
+
Vue.use(Vuex)
const store = new Vuex.Store({
- state: {}
+ state: {
+ uecToken: uecToken || '',
+ qnToken: qnToken || '', // token
+ userInfo: userInfo || {}, // 用户信息
+ supplierInfo: supplierInfo || {}, // 纸盘商信息
+ nextPage: {
+ name: '',
+ data: {}
+ }
+ },
+ mutations: {
+ setUecToken(state, token) {
+ try {
+ uni.setStorageSync('uecToken', token)
+ state.uecToken = token
+ } catch (e) {
+ console.error('更改uecToken失败:', e)
+ }
+ },
+ removeUecToken(state) {
+ try {
+ uni.removeStorageSync('uecToken')
+ state.uecToken = ''
+ } catch (e) {
+ console.error('删除uecToken失败:', e)
+ }
+ },
+ setToken(state, token) {
+ try {
+ uni.setStorageSync('qnToken', token)
+ state.qnToken = token
+ } catch (e) {
+ console.error('更改token失败:', e)
+ }
+ },
+ removeToken(state) {
+ try {
+ uni.removeStorageSync('qnToken')
+ state.qnToken = ''
+ } catch (e) {
+ console.error('删除token失败:', e)
+ }
+ },
+ setUserInfo(state, userInfo) {
+ if (!isObject(userInfo)) {
+ console.error('userInfo必须是对象')
+ return
+ }
+ try {
+ uni.setStorageSync('userInfo', JSON.stringify(userInfo))
+ state.userInfo = userInfo
+ } catch (e) {
+ console.error('更改userInfo失败:', e)
+ }
+ },
+ removeUserInfo(state) {
+ try {
+ uni.removeStorageSync('userInfo')
+ state.userInfo = {}
+ } catch (e) {
+ console.error('删除userInfo失败:', e)
+ }
+ },
+ setSupplierInfo(state, supplierInfo) {
+ if (!isObject(supplierInfo)) {
+ console.error('supplierInfo必须是对象')
+ return
+ }
+ try {
+ uni.setStorageSync('supplierInfo', JSON.stringify(supplierInfo))
+ state.supplierInfo = supplierInfo
+ } catch (e) {
+ console.error('更改supplierInfo失败:', e)
+ }
+ },
+ removeSupplierInfo(state) {
+ try {
+ uni.removeStorageSync('supplierInfo')
+ state.supplierInfo = {}
+ } catch (e) {
+ console.error('删除supplierInfo失败:', e)
+ }
+ },
+ setNextPage(state, nextPage) {
+ if (!isObject(nextPage)) {
+ console.error('nextPage必须是对象')
+ return
+ }
+ state.nextPage.name = nextPage.name || ''
+ state.nextPage.data = nextPage.data || {}
+ },
+ removeNextPage(state) {
+ state.nextPage.name = ''
+ state.nextPage.data = {}
+ }
+ },
+ actions: {
+ logout({ commit }) {
+ commit('removeUecToken')
+ commit('removeToken')
+ commit('removeUserInfo')
+ commit('removeSupplierInfo')
+ }
+ }
})
export default store
diff --git a/uni_modules/uni-easyinput/changelog.md b/uni_modules/uni-easyinput/changelog.md
new file mode 100644
index 0000000..0bb1663
--- /dev/null
+++ b/uni_modules/uni-easyinput/changelog.md
@@ -0,0 +1,31 @@
+## 1.0.0(2021-11-19)
+- 优化 组件UI,并提供设计资源,详见:[https://uniapp.dcloud.io/component/uniui/resource](https://uniapp.dcloud.io/component/uniui/resource)
+- 文档迁移,详见:[https://uniapp.dcloud.io/component/uniui/uni-easyinput](https://uniapp.dcloud.io/component/uniui/uni-easyinput)
+## 0.1.4(2021-08-20)
+- 修复 在 uni-forms 的动态表单中默认值校验不通过的 bug
+## 0.1.3(2021-08-11)
+- 修复 在 uni-forms 中重置表单,错误信息无法清除的问题
+## 0.1.2(2021-07-30)
+- 优化 vue3下事件警告的问题
+## 0.1.1
+- 优化 errorMessage 属性支持 Boolean 类型
+## 0.1.0(2021-07-13)
+- 组件兼容 vue3,如何创建vue3项目,详见 [uni-app 项目支持 vue3 介绍](https://ask.dcloud.net.cn/article/37834)
+## 0.0.16(2021-06-29)
+- 修复 confirmType 属性(仅 type="text" 生效)导致多行文本框无法换行的 bug
+## 0.0.15(2021-06-21)
+- 修复 passwordIcon 属性拼写错误的 bug
+## 0.0.14(2021-06-18)
+- 新增 passwordIcon 属性,当type=password时是否显示小眼睛图标
+- 修复 confirmType 属性不生效的问题
+## 0.0.13(2021-06-04)
+- 修复 disabled 状态可清出内容的 bug
+## 0.0.12(2021-05-12)
+- 新增 组件示例地址
+## 0.0.11(2021-05-07)
+- 修复 input-border 属性不生效的问题
+## 0.0.10(2021-04-30)
+- 修复 ios 遮挡文字、显示一半的问题
+## 0.0.9(2021-02-05)
+- 调整为uni_modules目录规范
+- 优化 兼容 nvue 页面
diff --git a/uni_modules/uni-easyinput/components/uni-easyinput/common.js b/uni_modules/uni-easyinput/components/uni-easyinput/common.js
new file mode 100644
index 0000000..df9abe1
--- /dev/null
+++ b/uni_modules/uni-easyinput/components/uni-easyinput/common.js
@@ -0,0 +1,56 @@
+/**
+ * @desc 函数防抖
+ * @param func 目标函数
+ * @param wait 延迟执行毫秒数
+ * @param immediate true - 立即执行, false - 延迟执行
+ */
+export const debounce = function(func, wait = 1000, immediate = true) {
+ let timer;
+ console.log(1);
+ return function() {
+ console.log(123);
+ let context = this,
+ args = arguments;
+ if (timer) clearTimeout(timer);
+ if (immediate) {
+ let callNow = !timer;
+ timer = setTimeout(() => {
+ timer = null;
+ }, wait);
+ if (callNow) func.apply(context, args);
+ } else {
+ timer = setTimeout(() => {
+ func.apply(context, args);
+ }, wait)
+ }
+ }
+}
+/**
+ * @desc 函数节流
+ * @param func 函数
+ * @param wait 延迟执行毫秒数
+ * @param type 1 使用表时间戳,在时间段开始的时候触发 2 使用表定时器,在时间段结束的时候触发
+ */
+export const throttle = (func, wait = 1000, type = 1) => {
+ let previous = 0;
+ let timeout;
+ return function() {
+ let context = this;
+ let args = arguments;
+ if (type === 1) {
+ let now = Date.now();
+
+ if (now - previous > wait) {
+ func.apply(context, args);
+ previous = now;
+ }
+ } else if (type === 2) {
+ if (!timeout) {
+ timeout = setTimeout(() => {
+ timeout = null;
+ func.apply(context, args)
+ }, wait)
+ }
+ }
+ }
+}
diff --git a/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue b/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue
new file mode 100644
index 0000000..a5bac54
--- /dev/null
+++ b/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue
@@ -0,0 +1,461 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/uni_modules/uni-easyinput/package.json b/uni_modules/uni-easyinput/package.json
new file mode 100644
index 0000000..84022db
--- /dev/null
+++ b/uni_modules/uni-easyinput/package.json
@@ -0,0 +1,90 @@
+{
+ "id": "uni-easyinput",
+ "displayName": "uni-easyinput 增强输入框",
+ "version": "1.0.0",
+ "description": "Easyinput 组件是对原生input组件的增强",
+ "keywords": [
+ "uni-ui",
+ "uniui",
+ "input",
+ "uni-easyinput",
+ "输入框"
+],
+ "repository": "https://github.com/dcloudio/uni-ui",
+ "engines": {
+ "HBuilderX": ""
+ },
+ "directories": {
+ "example": "../../temps/example_temps"
+ },
+ "dcloudext": {
+ "category": [
+ "前端组件",
+ "通用组件"
+ ],
+ "sale": {
+ "regular": {
+ "price": "0.00"
+ },
+ "sourcecode": {
+ "price": "0.00"
+ }
+ },
+ "contact": {
+ "qq": ""
+ },
+ "declaration": {
+ "ads": "无",
+ "data": "无",
+ "permissions": "无"
+ },
+ "npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui"
+ },
+ "uni_modules": {
+ "dependencies": [
+ "uni-scss",
+ "uni-icons"
+ ],
+ "encrypt": [],
+ "platforms": {
+ "cloud": {
+ "tcb": "y",
+ "aliyun": "y"
+ },
+ "client": {
+ "App": {
+ "app-vue": "y",
+ "app-nvue": "y"
+ },
+ "H5-mobile": {
+ "Safari": "y",
+ "Android Browser": "y",
+ "微信浏览器(Android)": "y",
+ "QQ浏览器(Android)": "y"
+ },
+ "H5-pc": {
+ "Chrome": "y",
+ "IE": "y",
+ "Edge": "y",
+ "Firefox": "y",
+ "Safari": "y"
+ },
+ "小程序": {
+ "微信": "y",
+ "阿里": "y",
+ "百度": "y",
+ "字节跳动": "y",
+ "QQ": "y"
+ },
+ "快应用": {
+ "华为": "u",
+ "联盟": "u"
+ },
+ "Vue": {
+ "vue2": "y",
+ "vue3": "y"
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/uni_modules/uni-easyinput/readme.md b/uni_modules/uni-easyinput/readme.md
new file mode 100644
index 0000000..f1faf8f
--- /dev/null
+++ b/uni_modules/uni-easyinput/readme.md
@@ -0,0 +1,11 @@
+
+
+### Easyinput 增强输入框
+> **组件名:uni-easyinput**
+> 代码块: `uEasyinput`
+
+
+easyinput 组件是对原生input组件的增强 ,是专门为配合表单组件[uni-forms](https://ext.dcloud.net.cn/plugin?id=2773)而设计的,easyinput 内置了边框,图标等,同时包含 input 所有功能
+
+### [查看文档](https://uniapp.dcloud.io/component/uniui/uni-easyinput)
+#### 如使用过程中有任何问题,或者您对uni-ui有一些好的建议,欢迎加入 uni-ui 交流群:871950839
\ No newline at end of file
diff --git a/utils/hook.js b/utils/hook.js
index 0bd7a15..cf61bb1 100644
--- a/utils/hook.js
+++ b/utils/hook.js
@@ -1,14 +1,82 @@
+import store from '@/store/index'
// 框架方法封装
-const tabList = ['client','trade','mall','mine']
+const tabList = ['store', 'cart', 'mine']
/**
- * @param {string} 跳转的tabBar页面
+ * @param {string} 跳转的tabBar页面
* @return {null}
*/
export function tab2(tabPage) {
- if(tabList.includes(tabPage)) {
- uni.switchTab({
- url:`/pages/${tabPage}/index`
- })
- }
-}
\ No newline at end of file
+ if (tabList.includes(tabPage)) {
+ uni.switchTab({
+ url: `/pages/${tabPage}/index`
+ })
+ }
+}
+/**
+ * @param {string} 返回上一级
+ * @return {null}
+ */
+export function back() {
+ if (getCurrentPages().length > 1) {
+ uni.navigateBack({
+ delta: 1
+ })
+ } else {
+ go2('client')
+ }
+}
+
+/**
+ * 跳转到指定页面,包括tabBar页面
+ * @param {string} url 页面名称
+ * @param {object} data 页面参数
+ * @param {string} isRedirect 是否重定向 默认false
+ * @return {null}
+ */
+export function go2(url, data = {}, isRedirect = false) {
+ if (!url) {
+ console.error('请选择页面')
+ return
+ }
+ let param = ''
+ Object.keys(data).forEach((key) => {
+ if (param === '') {
+ param = `${key}=${data[key]}`
+ } else {
+ param += `&${key}=${data[key]}`
+ }
+ })
+ if (tabList.includes(url)) {
+ uni.switchTab({
+ url: `/pages/${url}/index${param ? '?' + param : ''}`
+ })
+ } else {
+ if (isRedirect) {
+ uni.redirectTo({
+ url: `/pages/${url}/index${param ? '?' + param : ''}`
+ })
+ } else {
+ uni.navigateTo({
+ url: `/pages/${url}/index${param ? '?' + param : ''}`
+ })
+ }
+ }
+}
+
+/**
+ * 跳转到指定页面,包括tabBar页面,校验是否已登录,未登录则跳转到登录页面
+ * @param {string} url 页面名称
+ * @param {object} data 页面参数
+ * @param {string} isRedirect 是否重定向 默认false
+ * @return {null}
+ */
+export function loginGo2(url, data = {}, isRedirect) {
+ const token = store.state.qnToken
+ if (token) {
+ go2(url, data, isRedirect)
+ } else {
+ store.commit('setNextPage', { name: url, data })
+ go2('login')
+ }
+}
diff --git a/utils/http/http.js b/utils/http/http.js
index 1ec9dff..6146aa1 100644
--- a/utils/http/http.js
+++ b/utils/http/http.js
@@ -1,112 +1,109 @@
-import {
- isFunction
-} from '../is.js'
-const urlEnv = process.env.NODE_ENV === 'production' ? '-test' : ''
+import { isFunction } from '../is.js'
+const urlEnv = process.env.NODE_ENV === 'production' ? '' : '-test'
const uplaodUrl = `https://api-ops-yyt${urlEnv}.qniao.cn/cloud-print-user-center/utils/uploadImage`
export default class Http {
- constructor(config = {}, {
- reqInterceptor,
- resInterceptor,
- tranformConfig
- } = {}) {
- this.baseUrl = config.baseUrl
- this.header = config.header || {
- 'content-type': 'application/json;charset=UTF-8'
- }
- this.requestOption = config.requestOption || {}
- this.reqInterceptor = reqInterceptor
- this.resInterceptor = resInterceptor
- this.tranformConfig = tranformConfig
- }
- post(config, options) {
- return this.request({
- method: 'POST',
- ...config
- }, options)
- }
- get(config, options) {
- return this.request({
- method: 'GET',
- ...config
- }, options)
- }
- /**
- * @param {Object} config 和请求相关的参数
- * @param {Object} options 对请求数据进行额外处理的参数
- */
- request(config, options) {
- let conf = Object.assign({}, config)
- const {
- tranformConfig,
- reqInterceptor,
- resInterceptor
- } = this
- if (tranformConfig && isFunction(tranformConfig)) {
- conf = tranformConfig(this, config)
- }
- let opt = Object.assign({}, this.requestOption, options)
- if (reqInterceptor && isFunction(reqInterceptor)) {
- conf = reqInterceptor(conf, opt)
- }
- return new Promise((resolve, reject) => {
- uni.request({
- url: conf.url,
- data: conf.data,
- header: conf.header,
- success: (res) => {
- console.log('native response', res)
- let data = resInterceptor(res, opt)
- // 服务器错误也会用then抛出,需要自己判断data==null
- resolve(data)
- },
- fail: (err) => {
- uni.showToast({
- title: '发生未知错误,请联系客服'
- })
- reject(err)
- }
- })
- }).catch(err => {
- // 吃掉请求产生的异常
- // 后期可以记录
- console.log('native response error', err)
- })
- }
- // config:{}
- uploadFile(config, options) {
- return new Promise((resolve, rejetc) => {
- let conf = Object.assign({}, config)
- conf.url = uplaodUrl
- const {
- reqInterceptor
- } = this
- let opt = Object.assign({}, this.requestOption, options)
- if (reqInterceptor && isFunction(reqInterceptor)) {
- conf = reqInterceptor(conf, opt)
- }
- delete conf.header['Content-Type']
- uni.uploadFile({
- url: conf.url,
- header: {
- ...conf.header,
- image: config.data.filePath,
- // 'Content-Type': 'image/png'
- },
- filePath: config.data.filePath,
- name: config.data.fileName || 'image',
- formData: {
- image: config.data.filePath
- },
- success: (res) => {
- uni.hideLoading()
- resolve(res.data)
- },
- fail: (err) => {
- reject(err)
- }
- })
- }).catch(err => {
- console.log('upload native err', err)
- })
- }
+ constructor(
+ config = {},
+ { reqInterceptor, resInterceptor, tranformConfig } = {}
+ ) {
+ this.baseUrl = config.baseUrl
+ this.header = config.header || {
+ 'content-type': 'application/json;charset=UTF-8'
+ }
+ this.requestOption = config.requestOption || {}
+ this.reqInterceptor = reqInterceptor
+ this.resInterceptor = resInterceptor
+ this.tranformConfig = tranformConfig
+ }
+ post(config, options) {
+ return this.request(
+ {
+ method: 'POST',
+ ...config
+ },
+ options
+ )
+ }
+ get(config, options) {
+ return this.request(
+ {
+ method: 'GET',
+ ...config
+ },
+ options
+ )
+ }
+ /**
+ * @param {Object} config 和请求相关的参数
+ * @param {Object} options 对请求数据进行额外处理的参数
+ */
+ request(config, options) {
+ let conf = Object.assign({}, config)
+ const { tranformConfig, reqInterceptor, resInterceptor } = this
+ if (tranformConfig && isFunction(tranformConfig)) {
+ conf = tranformConfig(this, config)
+ }
+ let opt = Object.assign({}, this.requestOption, options)
+ if (reqInterceptor && isFunction(reqInterceptor)) {
+ conf = reqInterceptor(conf, opt)
+ }
+ return new Promise((resolve, reject) => {
+ uni.request({
+ url: conf.url,
+ data: conf.data,
+ header: conf.header,
+ method: conf.method,
+ success: (res) => {
+ let data = resInterceptor(res, opt)
+ // 服务器错误也会用then抛出,需要自己判断data==null
+ resolve(data)
+ },
+ fail: (err) => {
+ uni.showToast({
+ title: '发生未知错误,请联系客服'
+ })
+ reject(err)
+ }
+ })
+ }).catch((err) => {
+ // 吃掉请求产生的异常
+ // 后期可以记录
+ console.log('native response error', err)
+ })
+ }
+ // config:{}
+ uploadFile(config, options) {
+ return new Promise((resolve, rejetc) => {
+ let conf = Object.assign({}, config)
+ conf.url = uplaodUrl
+ const { reqInterceptor } = this
+ let opt = Object.assign({}, this.requestOption, options)
+ if (reqInterceptor && isFunction(reqInterceptor)) {
+ conf = reqInterceptor(conf, opt)
+ }
+ delete conf.header['Content-Type']
+ uni.uploadFile({
+ url: conf.url,
+ header: {
+ ...conf.header,
+ image: config.data.filePath
+ // 'Content-Type': 'image/png'
+ },
+ filePath: config.data.filePath,
+ name: config.data.fileName || 'image',
+ formData: {
+ image: config.data.filePath
+ },
+ success: (res) => {
+ uni.hideLoading()
+ resolve(res.data)
+ },
+ fail: (err) => {
+ reject(err)
+ }
+ })
+ }).catch((err) => {
+ console.log('upload native err', err)
+ })
+ }
}
diff --git a/utils/http/index.js b/utils/http/index.js
index 8cc4749..d861b01 100644
--- a/utils/http/index.js
+++ b/utils/http/index.js
@@ -1,8 +1,8 @@
import Http from './http.js'
// 请求封装文件
-const urlEnv = process.env.NODE_ENV === 'production' ? '-test' : ''
-const xappid = '503258978847966404'
+const urlEnv = process.env.NODE_ENV === 'production' ? '' : '-test'
+const xappid = '503258978847966403'
// 请求url列表
const prefixList = {
'/yyt-uec': `https://api-client-yyt${urlEnv}.qniao.cn`,
@@ -27,18 +27,25 @@ const config = {
// 请求拦截
const reqInterceptor = (config, options) => {
+ const { url = '' } = config
// 添加token
- const token = uni.getStorageSync('Qn_token')
+ let token = ''
+ try {
+ if (url.startsWith('uec')) {
+ token = uni.getStorageSync('uecToken')
+ } else {
+ token = uni.getStorageSync('qnToken')
+ }
+ } catch (e) {
+ console.error('获取缓存失败:', e)
+ }
config.header = {
...config.header,
- Authorization:
- token ||
- 'iHP4V/g6O5DXHixyNrf7tm/UsBwShEYjzGx1kBBPitXOsbrMnv5z4DHjhbgWwrgz/eyAbzsk0APv+gBprZdnNQ==',
+ Authorization: token || '',
'X-APP-ID': xappid
}
// 改变url
let newUrl = ''
- const { url = '' } = config
if (url.startsWith('http')) {
newUrl = url
} else {
@@ -60,6 +67,7 @@ const reqInterceptor = (config, options) => {
// 响应拦截
const resInterceptor = (response, options) => {
+ uni.hideLoading()
if (options.isReturnNativeResponse) {
return response
}
@@ -70,8 +78,15 @@ const resInterceptor = (response, options) => {
const { statusCode } = response
const res = response.data
if (statusCode >= 200 && statusCode < 300) {
- uni.hideLoading()
- return res
+ if (res.code == 0) {
+ return res.data
+ } else {
+ uni.showToast({
+ title: res.message,
+ icon: 'none'
+ })
+ return null
+ }
} else {
uni.showToast({
title: '服务器错误,请联系客服'