diff --git a/src/assets/js/api.js b/src/assets/js/api.js deleted file mode 100644 index 9a384d8..0000000 --- a/src/assets/js/api.js +++ /dev/null @@ -1,99 +0,0 @@ -/** - * axios封装 - * 请求拦截、响应拦截、错误统一处理 - */ -import axios from 'axios'; -import router from '../../router'; -import vue from '../../main' - -export async function getAxiosInstance() { - var baseURL, instance - - baseURL = 'http://couy.xyz:3001/'; - - /** - * 请求失败后的错误统一处理 - * @param {Number} status 请求失败的状态码 - */ - const errorHandle = (status, response) => { - // 状态码判断 - switch (status) { - // 401: 未登录状态,跳转登录页 - case 401: - vue.$store.commit("set_sys_info", { - msg: ` - 😭${response.data.msg|| '服务器有点问题,请稍后重试'} - `, - type: 'warning' - }); - break; - case 403: - vue.$store.commit("set_sys_info", { - msg: ` - 😭${response.data.msg|| '服务器有点问题,请稍后重试'} - `, - type: 'warning' - }); - break; - case 404: - vue.$store.commit("set_sys_info", { - msg: ` - 😭${response.data.msg|| '服务器有点问题,请稍后重试'} - `, - type: 'warning' - }); - break; - default: - vue.$store.commit("set_sys_info", { - msg: ` - 😭${response.data.msg|| '服务器有点问题,请稍后重试'} - `, - type: 'warning' - }); - } - } - - // 创建axios实例 - instance = axios.create({ - timeout: 1000 * 12 // 设置十二秒钟的请求超时限制 - // transformRequest: data => qs.stringify(data) - }); - if (process.env.NODE_ENV == 'development') { - //开发环境 - instance.defaults.baseURL = baseURL; - } else if (process.env.NODE_ENV == 'debug') { - //debug - instance.defaults.baseURL = baseURL; - } else if (process.env.NODE_ENV == 'production') { - //生产环境 - instance.defaults.baseURL = baseURL; - } - // 设置post请求头 - instance.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'; - - // 响应拦截器 - instance.interceptors.response.use( - // 请求成功 - res => res.status === 200 ? Promise.resolve(res) : Promise.reject(res), - // 请求失败 - error => { - const { - response - } = error; - if (response) { - // 请求已发出,但是不在2xx的范围 - errorHandle(response.status, response); - - return Promise.reject(response); - } else { - vue.$store.commit("set_sys_info", { - msg: ` - 😭${response.data.msg|| '服务器有点问题,请稍后重试'} - `, - type: 'warning' - }); - } - }); - - return instance -} \ No newline at end of file diff --git a/src/assets/js/assist.js b/src/assets/js/assist.js deleted file mode 100644 index 3cef095..0000000 --- a/src/assets/js/assist.js +++ /dev/null @@ -1,73 +0,0 @@ -/** - * vue组件通信 - * @author couy - * @param context 当前上下文环境(一般传this) - * @param componentName 需要查找的组件的组件名(特别注意需要该组件定义了name属性) - */ - -export const assist = { - methods: { - // 由一个组件,向上找到最近的指定组件 - findComponentUpward(context, componentName) { - let parent = context.$parent; - let name = parent.$options.name; - - while (parent && (!name || [componentName].indexOf(name) < 0)) { - parent = parent.$parent; - if (parent) name = parent.$options.name; - } - return parent; - }, - // 由一个组件,向上找到所有的指定组件 - findComponentsUpward(context, componentName) { - let parents = []; - const parent = context.$parent; - - if (parent) { - if (parent.$options.name === componentName) parents.push(parent); - return parents.concat(this.findComponentsUpward(parent, componentName)); - } else { - return []; - } - }, - // 由一个组件,向下找到最近的指定组件 - findComponentDownward(context, componentName) { - const childrens = context.$children; - let children = null; - - if (childrens.length) { - for (const child of childrens) { - const name = child.$options.name; - - if (name === componentName) { - children = child; - break; - } else { - children = this.findComponentDownward(child, componentName); - if (children) break; - } - } - } - return children; - }, - // 由一个组件,向下找到所有指定的组件 - findComponentsDownward(context, componentName) { - return context.$children.reduce((components, child) => { - if (child.$options.name === componentName) components.push(child); - const foundChilds = this.findComponentsDownward(child, componentName); - return components.concat(foundChilds); - }, []); - }, - - - // 由一个组件,找到指定组件的兄弟组件 - findBrothersComponents(context, componentName, exceptMe = true) { - let res = context.$parent.$children.filter(item => { - return item.$options.name === componentName; - }); - let index = res.findIndex(item => item._uid === context._uid); - if (exceptMe) res.splice(index, 1); - return res; - } - } -}; \ No newline at end of file diff --git a/src/tool/IndexedDB.ts b/src/tool/IndexedDB.ts index cd74f30..75e227a 100644 --- a/src/tool/IndexedDB.ts +++ b/src/tool/IndexedDB.ts @@ -34,12 +34,12 @@ function openDB() { // 数据库创建或升级的时候会触发 console.log('onupgradeneeded'); db = request.result; // 数据库对象 - createArchiveStore(); + createStore(); }; }); } -const createArchiveStore = () => { +const createStore = () => { if (!db.objectStoreNames.contains(store_name_archive)) { const objectStore = db.createObjectStore(store_name_archive, { keyPath: key_name_archive }); // 创建索引,在后面查询数据的时候可以根据索引查