Showing
4 changed files
with
51 additions
and
14 deletions
| ... | @@ -2,7 +2,12 @@ import axios from '@/utils/axios'; | ... | @@ -2,7 +2,12 @@ import axios from '@/utils/axios'; |
| 2 | import { fn } from '@/api/fn'; | 2 | import { fn } from '@/api/fn'; |
| 3 | 3 | ||
| 4 | const Api = { | 4 | const Api = { |
| 5 | - KG_LIST: '/srv/?a=kg_list', // 幼儿园列表页 | 5 | + KG_LIST: '/srv/?a=kg_list', |
| 6 | } | 6 | } |
| 7 | 7 | ||
| 8 | +/** | ||
| 9 | + * @description 幼儿园列表页 | ||
| 10 | + * @param {*} params 参数 | ||
| 11 | + * @returns {array} data | ||
| 12 | + */ | ||
| 8 | export const kgListAPI = (params) => fn(axios.get(Api.KG_LIST, { params })) | 13 | export const kgListAPI = (params) => fn(axios.get(Api.KG_LIST, { params })) | ... | ... |
| ... | @@ -8,21 +8,21 @@ const Api = { | ... | @@ -8,21 +8,21 @@ const Api = { |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | /** | 10 | /** |
| 11 | - * 切换儿童角色 | 11 | + * @description: 切换儿童角色 |
| 12 | * @param {*} params | 12 | * @param {*} params |
| 13 | * @returns | 13 | * @returns |
| 14 | */ | 14 | */ |
| 15 | export const changePerformerAPI = (params) => fn(axios.post(Api.CHANGE_PERFORMER, params)) | 15 | export const changePerformerAPI = (params) => fn(axios.post(Api.CHANGE_PERFORMER, params)) |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| 18 | - * 获取儿童信息 | 18 | + * @description: 获取儿童信息 |
| 19 | - * @param {*} params | 19 | + * @param {object} params 参数 |
| 20 | - * @returns | 20 | + * @returns {*} 布尔值||查询值 |
| 21 | */ | 21 | */ |
| 22 | export const myInfoAPI = (params) => fn(axios.get(Api.MY_INFO, { params })) | 22 | export const myInfoAPI = (params) => fn(axios.get(Api.MY_INFO, { params })) |
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | - * 角色列表信息 | 25 | + * @description: 角色列表信息 |
| 26 | * @param {*} params | 26 | * @param {*} params |
| 27 | * @returns | 27 | * @returns |
| 28 | */ | 28 | */ | ... | ... |
| 1 | import axios from 'axios'; | 1 | import axios from 'axios'; |
| 2 | -import router from '../router'; | 2 | +import router from '@/router'; |
| 3 | import _ from 'lodash' | 3 | import _ from 'lodash' |
| 4 | import qs from 'Qs' | 4 | import qs from 'Qs' |
| 5 | +import { parseQueryString } from '@/utils/tools' | ||
| 5 | 6 | ||
| 6 | -// 请求拦截器 | 7 | +/** |
| 8 | + * @description 请求拦截器 | ||
| 9 | + */ | ||
| 7 | axios.interceptors.request.use( | 10 | axios.interceptors.request.use( |
| 8 | config => { | 11 | config => { |
| 12 | + const url_params = parseQueryString(location.href); | ||
| 13 | + // GET请求默认打上时间戳,避免从缓存中拿数据。 | ||
| 14 | + const timestamp = config.method === 'get' ? (new Date()).valueOf() : ''; | ||
| 9 | // 发送请求前 | 15 | // 发送请求前 |
| 10 | if (config.method === 'post' && | 16 | if (config.method === 'post' && |
| 11 | (config.url.indexOf('a=upload') === -1 && config.url.indexOf('upload.qiniup.com') === -1)) // 上传相关接口需要屏蔽掉 | 17 | (config.url.indexOf('a=upload') === -1 && config.url.indexOf('upload.qiniup.com') === -1)) // 上传相关接口需要屏蔽掉 |
| ... | @@ -13,9 +19,11 @@ axios.interceptors.request.use( | ... | @@ -13,9 +19,11 @@ axios.interceptors.request.use( |
| 13 | // POST PHP需要修改数据格式 | 19 | // POST PHP需要修改数据格式 |
| 14 | config.data = qs.stringify(config.data) | 20 | config.data = qs.stringify(config.data) |
| 15 | } | 21 | } |
| 22 | + console.warn(timestamp); | ||
| 16 | // 绑定默认请求头 | 23 | // 绑定默认请求头 |
| 17 | config.params = _.merge(config.params, { | 24 | config.params = _.merge(config.params, { |
| 18 | f: 'voice', | 25 | f: 'voice', |
| 26 | + timestamp, | ||
| 19 | }) | 27 | }) |
| 20 | return config; | 28 | return config; |
| 21 | }, | 29 | }, |
| ... | @@ -24,15 +32,18 @@ axios.interceptors.request.use( | ... | @@ -24,15 +32,18 @@ axios.interceptors.request.use( |
| 24 | return Promise.reject(error); | 32 | return Promise.reject(error); |
| 25 | }); | 33 | }); |
| 26 | 34 | ||
| 27 | -// 响应拦截器 | 35 | +/** |
| 36 | + * @description 响应拦截器 | ||
| 37 | + */ | ||
| 28 | axios.interceptors.response.use( | 38 | axios.interceptors.response.use( |
| 29 | response => { | 39 | response => { |
| 40 | + // C/B授权拼接头特殊标识,openid_x | ||
| 30 | let userType = router && router.currentRoute.value.href?.indexOf('business') > 0 ? 'b' : 'c'; | 41 | let userType = router && router.currentRoute.value.href?.indexOf('business') > 0 ? 'b' : 'c'; |
| 31 | if (response.data.code === 401) { | 42 | if (response.data.code === 401) { |
| 32 | // 特殊标识-带此标识报错不显示 | 43 | // 特殊标识-带此标识报错不显示 |
| 33 | response.data.show = false; | 44 | response.data.show = false; |
| 34 | // 未授权跳转登录页 | 45 | // 未授权跳转登录页 |
| 35 | - // 带着上一个页面的信息 | 46 | + // 带着上一个页面的信息, 授权完成后 返回当前页面 |
| 36 | router.replace({ | 47 | router.replace({ |
| 37 | path: '/auth', | 48 | path: '/auth', |
| 38 | query: { | 49 | query: { | ... | ... |
| 1 | import moment from 'moment'; | 1 | import moment from 'moment'; |
| 2 | -import { ref, nextTick } from 'vue' | 2 | +import { ref } from 'vue' |
| 3 | 3 | ||
| 4 | // 格式化时间 | 4 | // 格式化时间 |
| 5 | const formatDate = (date) => { | 5 | const formatDate = (date) => { |
| 6 | return moment(date).format('YYYY-MM-DD HH:mm'); | 6 | return moment(date).format('YYYY-MM-DD HH:mm'); |
| 7 | }; | 7 | }; |
| 8 | -// 判断是不是桌面微信 | 8 | + |
| 9 | +/** | ||
| 10 | + * @description 判断浏览器属于平台 | ||
| 11 | + * @returns | ||
| 12 | + */ | ||
| 9 | const wxInfo = () => { | 13 | const wxInfo = () => { |
| 10 | let u = navigator.userAgent; | 14 | let u = navigator.userAgent; |
| 11 | let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器 | 15 | let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器 |
| ... | @@ -18,8 +22,9 @@ const wxInfo = () => { | ... | @@ -18,8 +22,9 @@ const wxInfo = () => { |
| 18 | isTable | 22 | isTable |
| 19 | }; | 23 | }; |
| 20 | }; | 24 | }; |
| 25 | + | ||
| 21 | /** | 26 | /** |
| 22 | - * 判断多行省略文本 | 27 | + * @description 判断多行省略文本 |
| 23 | * @param {*} id 目标dom标签 | 28 | * @param {*} id 目标dom标签 |
| 24 | * @returns | 29 | * @returns |
| 25 | */ | 30 | */ |
| ... | @@ -31,4 +36,20 @@ const hasEllipsis = (id) => { | ... | @@ -31,4 +36,20 @@ const hasEllipsis = (id) => { |
| 31 | } | 36 | } |
| 32 | return flag | 37 | return flag |
| 33 | } | 38 | } |
| 34 | -export { formatDate, wxInfo, hasEllipsis }; | 39 | + |
| 40 | +/** | ||
| 41 | + * @description 解析URL参数 | ||
| 42 | + * @param {*} url | ||
| 43 | + * @returns | ||
| 44 | + */ | ||
| 45 | +const parseQueryString = url => { | ||
| 46 | + var json = {}; | ||
| 47 | + var arr = url.indexOf('?') >= 0 ? url.substr(url.indexOf('?') + 1).split('&') : []; | ||
| 48 | + arr.forEach(item => { | ||
| 49 | + var tmp = item.split('='); | ||
| 50 | + json[tmp[0]] = tmp[1]; | ||
| 51 | + }); | ||
| 52 | + return json; | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +export { formatDate, wxInfo, hasEllipsis, parseQueryString }; | ... | ... |
-
Please register or login to post a comment