feat: 添加微信支付和调试功能,配置环境变量和代理
- 添加微信支付相关API和配置 - 引入vconsole实现调试功能 - 配置环境变量文件(.env, .env.development, .env.production) - 添加代理配置和工具函数 - 更新依赖包以支持新功能
Showing
19 changed files
with
637 additions
and
5 deletions
.env
0 → 100644
.env.development
0 → 100644
| 1 | +# 资源公共路径 | ||
| 2 | +VITE_BASE = / | ||
| 3 | + | ||
| 4 | +# 测试open-id | ||
| 5 | +# VITE_OPENID = api-test-openid | ||
| 6 | +# VITE_OPENID = o8BRf1gLDWieH3Y3JvbrI_4IjaME | ||
| 7 | +# VITE_OPENID = oJLZq5t9PIKLW9tm1oSUNAuPwssA | ||
| 8 | +# VITE_OPENID = oJLZq5uT_6GwIh2tQWh1F9IoHZ3U | ||
| 9 | +VITE_OPENID = | ||
| 10 | + | ||
| 11 | +# B端账号 | ||
| 12 | +VITE_ID = 13761653761 | ||
| 13 | + | ||
| 14 | +# 验证码 | ||
| 15 | +VITE_PIN = | ||
| 16 | + | ||
| 17 | +# 反向代理服务器地址 | ||
| 18 | +# VITE_PROXY_TARGET = https://oa.anxinchashi.com/ | ||
| 19 | +VITE_PROXY_TARGET = http://oa-dev.onwall.cn | ||
| 20 | +# VITE_PROXY_TARGET = https://www.wxgzjs.cn/ | ||
| 21 | + | ||
| 22 | +# PC端地址 | ||
| 23 | +VITE_MOBILE_URL = http://localhost:5173/ |
.env.production
0 → 100644
| 1 | +### | ||
| 2 | +# 资源公共路径 | ||
| 3 | +VITE_BASE = /f/main/sku_request/ | ||
| 4 | + | ||
| 5 | +# 测试open-id | ||
| 6 | +VITE_APP_OPENID = | ||
| 7 | + | ||
| 8 | +# B端账号 | ||
| 9 | +VITE_APP_ID = | ||
| 10 | + | ||
| 11 | +# 验证码 | ||
| 12 | +VITE_APP_PIN = | ||
| 13 | + | ||
| 14 | +# 反向代理服务器地址 | ||
| 15 | +VITE_PROXY_TARGET = http://oa.onwall.cn | ||
| 16 | + | ||
| 17 | +# PC端地址 | ||
| 18 | +# VITE_MOBILE_URL = http://oa.onwall.cn/f/guanzong/web/ | ||
| 19 | +# VITE_MOBILE_URL = http://guanzong.onwall.cn/f/guanzong/web/ |
.eslintrc-auto-import.json
0 → 100644
| 1 | +{ | ||
| 2 | + "globals": { | ||
| 3 | + "Component": true, | ||
| 4 | + "ComponentPublicInstance": true, | ||
| 5 | + "ComputedRef": true, | ||
| 6 | + "DirectiveBinding": true, | ||
| 7 | + "EffectScope": true, | ||
| 8 | + "ExtractDefaultPropTypes": true, | ||
| 9 | + "ExtractPropTypes": true, | ||
| 10 | + "ExtractPublicPropTypes": true, | ||
| 11 | + "InjectionKey": true, | ||
| 12 | + "MaybeRef": true, | ||
| 13 | + "MaybeRefOrGetter": true, | ||
| 14 | + "PropType": true, | ||
| 15 | + "Ref": true, | ||
| 16 | + "VNode": true, | ||
| 17 | + "WritableComputedRef": true, | ||
| 18 | + "computed": true, | ||
| 19 | + "createApp": true, | ||
| 20 | + "customRef": true, | ||
| 21 | + "defineAsyncComponent": true, | ||
| 22 | + "defineComponent": true, | ||
| 23 | + "effectScope": true, | ||
| 24 | + "getCurrentInstance": true, | ||
| 25 | + "getCurrentScope": true, | ||
| 26 | + "h": true, | ||
| 27 | + "inject": true, | ||
| 28 | + "isProxy": true, | ||
| 29 | + "isReactive": true, | ||
| 30 | + "isReadonly": true, | ||
| 31 | + "isRef": true, | ||
| 32 | + "markRaw": true, | ||
| 33 | + "nextTick": true, | ||
| 34 | + "onActivated": true, | ||
| 35 | + "onBeforeMount": true, | ||
| 36 | + "onBeforeRouteLeave": true, | ||
| 37 | + "onBeforeRouteUpdate": true, | ||
| 38 | + "onBeforeUnmount": true, | ||
| 39 | + "onBeforeUpdate": true, | ||
| 40 | + "onDeactivated": true, | ||
| 41 | + "onErrorCaptured": true, | ||
| 42 | + "onMounted": true, | ||
| 43 | + "onRenderTracked": true, | ||
| 44 | + "onRenderTriggered": true, | ||
| 45 | + "onScopeDispose": true, | ||
| 46 | + "onServerPrefetch": true, | ||
| 47 | + "onUnmounted": true, | ||
| 48 | + "onUpdated": true, | ||
| 49 | + "onWatcherCleanup": true, | ||
| 50 | + "provide": true, | ||
| 51 | + "reactive": true, | ||
| 52 | + "readonly": true, | ||
| 53 | + "ref": true, | ||
| 54 | + "resolveComponent": true, | ||
| 55 | + "shallowReactive": true, | ||
| 56 | + "shallowReadonly": true, | ||
| 57 | + "shallowRef": true, | ||
| 58 | + "toRaw": true, | ||
| 59 | + "toRef": true, | ||
| 60 | + "toRefs": true, | ||
| 61 | + "toValue": true, | ||
| 62 | + "triggerRef": true, | ||
| 63 | + "unref": true, | ||
| 64 | + "useAttrs": true, | ||
| 65 | + "useCssModule": true, | ||
| 66 | + "useCssVars": true, | ||
| 67 | + "useId": true, | ||
| 68 | + "useLink": true, | ||
| 69 | + "useModel": true, | ||
| 70 | + "useRoute": true, | ||
| 71 | + "useRouter": true, | ||
| 72 | + "useSlots": true, | ||
| 73 | + "useTemplateRef": true, | ||
| 74 | + "watch": true, | ||
| 75 | + "watchEffect": true, | ||
| 76 | + "watchPostEffect": true, | ||
| 77 | + "watchSyncEffect": true | ||
| 78 | + } | ||
| 79 | +} |
build/proxy.js
0 → 100644
This diff is collapsed. Click to expand it.
| ... | @@ -11,15 +11,19 @@ | ... | @@ -11,15 +11,19 @@ |
| 11 | "dependencies": { | 11 | "dependencies": { |
| 12 | "@vant/use": "^1.6.0", | 12 | "@vant/use": "^1.6.0", |
| 13 | "vant": "^4.9.18", | 13 | "vant": "^4.9.18", |
| 14 | + "vconsole": "^3.15.1", | ||
| 14 | "vue": "^3.5.13", | 15 | "vue": "^3.5.13", |
| 15 | - "vue-router": "^4.5.0" | 16 | + "vue-router": "^4.5.0", |
| 17 | + "weixin-js-sdk": "^1.6.5" | ||
| 16 | }, | 18 | }, |
| 17 | "devDependencies": { | 19 | "devDependencies": { |
| 18 | "@vitejs/plugin-vue": "^5.2.1", | 20 | "@vitejs/plugin-vue": "^5.2.1", |
| 19 | "@vitejs/plugin-vue-jsx": "^4.1.2", | 21 | "@vitejs/plugin-vue-jsx": "^4.1.2", |
| 20 | "@vueuse/core": "^13.0.0", | 22 | "@vueuse/core": "^13.0.0", |
| 21 | "autoprefixer": "^10.4.19", | 23 | "autoprefixer": "^10.4.19", |
| 24 | + "axios": "^1.8.4", | ||
| 22 | "postcss": "^8.4.35", | 25 | "postcss": "^8.4.35", |
| 26 | + "qs": "^6.14.0", | ||
| 23 | "tailwindcss": "^3.4.1", | 27 | "tailwindcss": "^3.4.1", |
| 24 | "unplugin-auto-import": "^19.1.1", | 28 | "unplugin-auto-import": "^19.1.1", |
| 25 | "unplugin-vue-components": "^28.4.1", | 29 | "unplugin-vue-components": "^28.4.1", | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2025-03-20 19:53:12 | 2 | * @Date: 2025-03-20 19:53:12 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-03-20 20:06:10 | 4 | + * @LastEditTime: 2025-03-20 23:56:05 |
| 5 | - * @FilePath: /vue-vite/src/App.vue | 5 | + * @FilePath: /mlaj/src/App.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| 8 | <script setup> | 8 | <script setup> |
| 9 | import { RouterView } from "vue-router"; | 9 | import { RouterView } from "vue-router"; |
| 10 | -import { provideAuth } from '@/contexts/auth'; | 10 | +import { provideAuth } from "@/contexts/auth"; |
| 11 | -import { provideCart } from '@/contexts/cart'; | 11 | +import { provideCart } from "@/contexts/cart"; |
| 12 | +// 会根据配置判断是否显示调试控件 | ||
| 13 | +// eslint-disable-next-line no-unused-vars | ||
| 14 | +import vConsole from "@/utils/vconsole"; | ||
| 15 | +// 初始化WX环境 | ||
| 16 | +import wx from "weixin-js-sdk"; | ||
| 17 | +import { wxJsAPI } from "@/api/wx/config"; | ||
| 18 | +import { apiList } from "@/api/wx/jsApiList.js"; | ||
| 19 | +import { wxInfo, getUrlParams, stringifyQuery } from "@/utils/tools"; | ||
| 12 | 20 | ||
| 13 | // 提供认证和购物车上下文 | 21 | // 提供认证和购物车上下文 |
| 14 | provideAuth(); | 22 | provideAuth(); | ... | ... |
src/api/common.js
0 → 100644
| 1 | +/* | ||
| 2 | + * @Date: 2022-06-17 14:54:29 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2022-12-01 16:26:27 | ||
| 5 | + * @FilePath: /data-table/src/api/common.js | ||
| 6 | + * @Description: 通用接口 | ||
| 7 | + */ | ||
| 8 | +import { fn, fetch, uploadFn } from '@/api/fn'; | ||
| 9 | + | ||
| 10 | +const Api = { | ||
| 11 | + SMS: '/srv/?a=sms', | ||
| 12 | + TOKEN: '/srv/?a=upload', | ||
| 13 | + SAVE_FILE: '/srv/?a=upload&t=save_file', | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +/** | ||
| 17 | + * @description: 发送验证码 | ||
| 18 | + * @param {*} phone 手机号码 | ||
| 19 | + * @returns | ||
| 20 | + */ | ||
| 21 | +export const smsAPI = (params) => fn(fetch.post(Api.SMS, params)); | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * @description: 获取七牛token | ||
| 25 | + * @returns | ||
| 26 | + */ | ||
| 27 | +export const qiniuTokenAPI = (params) => fn(fetch.stringifyPost(Api.TOKEN, params)); | ||
| 28 | + | ||
| 29 | +/** | ||
| 30 | + * @description: 上传七牛 | ||
| 31 | + * @param {*} | ||
| 32 | + * @returns | ||
| 33 | + */ | ||
| 34 | +export const qiniuUploadAPI = (url, data, config) => uploadFn(fetch.basePost(url, data, config)); | ||
| 35 | + | ||
| 36 | +/** | ||
| 37 | + * @description: 保存图片 | ||
| 38 | + * @param {*} format | ||
| 39 | + * @param {*} hash | ||
| 40 | + * @param {*} height | ||
| 41 | + * @param {*} width | ||
| 42 | + * @param {*} filekey | ||
| 43 | + * @returns | ||
| 44 | + */ | ||
| 45 | +export const saveFileAPI = (params) => fn(fetch.stringifyPost(Api.SAVE_FILE, params)); |
src/api/data.js
0 → 100644
| 1 | +/* | ||
| 2 | + * @Date: 2022-06-17 14:54:29 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2024-07-04 17:05:30 | ||
| 5 | + * @FilePath: /data-table/src/api/data.js | ||
| 6 | + * @Description: 表单数据接口 | ||
| 7 | + */ | ||
| 8 | +import { fn, fetch } from '@/api/fn'; | ||
| 9 | + | ||
| 10 | +const Api = { | ||
| 11 | + ADD_FORM_DATA: '/srv/?a=add_formdata', | ||
| 12 | + QUERY_FORM_DATA: '/srv/?a=query_formdata', | ||
| 13 | + MODI_FORM_DATA: '/srv/?a=modi_formdata', | ||
| 14 | + FLOW_FORM_DATA: '/srv/?a=flow_formdata', | ||
| 15 | +} | ||
| 16 | +/** | ||
| 17 | + * @description: 添加表单数据 | ||
| 18 | + * @param: form_code 表单唯一标识 | ||
| 19 | + * @param: data 待添加的数据,json对象结构;键值对记录变更的字段和值; | ||
| 20 | + */ | ||
| 21 | +export const addFormDataAPI = (params) => fn(fetch.post(Api.ADD_FORM_DATA, params)); | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * @description: 查询表单数据 | ||
| 25 | + * @param: form_code 表单唯一标识 | ||
| 26 | + * @param: id 数据ID | ||
| 27 | + */ | ||
| 28 | +export const queryFormDataAPI = (params) => fn(fetch.get(Api.QUERY_FORM_DATA, params)); | ||
| 29 | + | ||
| 30 | +/** | ||
| 31 | + * @description: 修改表单数据 | ||
| 32 | + * @param: form_code 表单唯一标识 | ||
| 33 | + * @param: id 数据ID | ||
| 34 | + * @param: data 待添加的数据,json对象结构;键值对记录变更的字段和值; | ||
| 35 | + */ | ||
| 36 | +export const modiFormDataAPI = (params) => fn(fetch.post(Api.MODI_FORM_DATA, params)); | ||
| 37 | + | ||
| 38 | +/** | ||
| 39 | + * @description: 流程表单数据 | ||
| 40 | + * @param: form_code 表单唯一标识 | ||
| 41 | + * @param: data_id 数据ID | ||
| 42 | + * @param: data 待添加的数据,json对象结构;键值对记录变更的字段和值; | ||
| 43 | + * @param: flow_node_code 流程节点 | ||
| 44 | + * @param: flow_node_action_id 用户点击的流程节点按钮ID | ||
| 45 | + * @param: flow_content 流程审批的文本意见 | ||
| 46 | + */ | ||
| 47 | +export const flowFormDataAPI = (params) => fn(fetch.post(Api.FLOW_FORM_DATA, params)); |
src/api/fn.js
0 → 100644
| 1 | +/* | ||
| 2 | + * @Date: 2022-05-18 22:56:08 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2023-02-10 15:13:01 | ||
| 5 | + * @FilePath: /data-table/src/api/fn.js | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | + */ | ||
| 8 | +import axios from '@/utils/axios'; | ||
| 9 | +import qs from 'Qs' | ||
| 10 | +import { showSuccessToast, showFailToast } from 'vant'; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 网络请求功能函数 | ||
| 14 | + * @param {*} api 请求axios接口 | ||
| 15 | + * @returns 请求成功后,获取数据 | ||
| 16 | + */ | ||
| 17 | +export const fn = (api) => { | ||
| 18 | + return api | ||
| 19 | + .then(res => { | ||
| 20 | + if (res.data.code === 1) { | ||
| 21 | + return res.data || true; | ||
| 22 | + } else { | ||
| 23 | + // tslint:disable-next-line: no-console | ||
| 24 | + // if (!res.data.show) return false; | ||
| 25 | + showFailToast(res.data.msg); | ||
| 26 | + return false; | ||
| 27 | + } | ||
| 28 | + }) | ||
| 29 | + .catch(err => { | ||
| 30 | + // tslint:disable-next-line: no-console | ||
| 31 | + console.error(err); | ||
| 32 | + return false; | ||
| 33 | + }) | ||
| 34 | + .finally(() => { // 最终执行 | ||
| 35 | + }) | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +/** | ||
| 39 | + * 七牛返回格式 | ||
| 40 | + * @param {*} api | ||
| 41 | + * @returns | ||
| 42 | + */ | ||
| 43 | +export const uploadFn = (api) => { | ||
| 44 | + return api | ||
| 45 | + .then(res => { | ||
| 46 | + if (res.status === 200) { | ||
| 47 | + return res.data || true; | ||
| 48 | + } else { | ||
| 49 | + // tslint:disable-next-line: no-console | ||
| 50 | + console.warn(res); | ||
| 51 | + if (!res.data.show) return false; | ||
| 52 | + Toast({ | ||
| 53 | + icon: 'close', | ||
| 54 | + message: res.data.msg, | ||
| 55 | + }); | ||
| 56 | + return false; | ||
| 57 | + } | ||
| 58 | + }) | ||
| 59 | + .catch(err => { | ||
| 60 | + // tslint:disable-next-line: no-console | ||
| 61 | + console.error(err); | ||
| 62 | + return false; | ||
| 63 | + }) | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +/** | ||
| 67 | + * 统一 GET/POST 不同传参形式 | ||
| 68 | + */ | ||
| 69 | +export const fetch = { | ||
| 70 | + get: function (api, params) { | ||
| 71 | + return axios.get(api, { params }) | ||
| 72 | + }, | ||
| 73 | + post: function (api, params) { | ||
| 74 | + return axios.post(api, params) | ||
| 75 | + }, | ||
| 76 | + stringifyPost: function (api, params) { | ||
| 77 | + return axios.post(api, qs.stringify(params)) | ||
| 78 | + }, | ||
| 79 | + basePost: function (url, data, config) { | ||
| 80 | + return axios.post(url, data, config) | ||
| 81 | + } | ||
| 82 | +} |
src/api/wx/config.js
0 → 100644
| 1 | +/* | ||
| 2 | + * @Author: hookehuyr hookehuyr@gmail.com | ||
| 3 | + * @Date: 2022-06-09 13:32:44 | ||
| 4 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 5 | + * @LastEditTime: 2023-02-23 18:42:57 | ||
| 6 | + * @FilePath: /data-table/src/api/wx/config.js | ||
| 7 | + * @Description: | ||
| 8 | + */ | ||
| 9 | +import { fn, fetch } from '@/api/fn'; | ||
| 10 | + | ||
| 11 | +const Api = { | ||
| 12 | + WX_JSAPI: '/srv/?a=wx_share', | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * @description 获取微信CONFIG配置文件 | ||
| 17 | + * @param {*} url | ||
| 18 | + * @returns {*} cfg | ||
| 19 | + */ | ||
| 20 | +export const wxJsAPI = (params) => fn(fetch.get(Api.WX_JSAPI, params)); |
src/api/wx/jsApiList.js
0 → 100644
| 1 | +/* | ||
| 2 | + * @Date: 2022-06-13 14:18:57 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2022-06-13 14:27:21 | ||
| 5 | + * @FilePath: /tswj/src/api/wx/jsApiList.js | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | + */ | ||
| 8 | +export const apiList = [ | ||
| 9 | + // "updateAppMessageShareData", | ||
| 10 | + // "updateTimelineShareData", | ||
| 11 | + "onMenuShareTimeline", | ||
| 12 | + "onMenuShareAppMessage", | ||
| 13 | + "onMenuShareQQ", | ||
| 14 | + "onMenuShareWeibo", | ||
| 15 | + "onMenuShareQZone", | ||
| 16 | + "startRecord", | ||
| 17 | + "stopRecord", | ||
| 18 | + "onVoiceRecordEnd", | ||
| 19 | + "playVoice", | ||
| 20 | + "pauseVoice", | ||
| 21 | + "stopVoice", | ||
| 22 | + "onVoicePlayEnd", | ||
| 23 | + "uploadVoice", | ||
| 24 | + "downloadVoice", | ||
| 25 | + "chooseImage", | ||
| 26 | + "previewImage", | ||
| 27 | + "uploadImage", | ||
| 28 | + "downloadImage", | ||
| 29 | + "translateVoice", | ||
| 30 | + "getNetworkType", | ||
| 31 | + "openLocation", | ||
| 32 | + "getLocation", | ||
| 33 | + "hideOptionMenu", | ||
| 34 | + "showOptionMenu", | ||
| 35 | + "hideMenuItems", | ||
| 36 | + "showMenuItems", | ||
| 37 | + "hideAllNonBaseMenuItem", | ||
| 38 | + "showAllNonBaseMenuItem", | ||
| 39 | + "closeWindow", | ||
| 40 | + "scanQRCode", | ||
| 41 | + "chooseWXPay", | ||
| 42 | + "openProductSpecificView", | ||
| 43 | + "addCard", | ||
| 44 | + "chooseCard", | ||
| 45 | + "openCard" | ||
| 46 | +] |
src/api/wx/pay.js
0 → 100644
| 1 | +/* | ||
| 2 | + * @Author: hookehuyr hookehuyr@gmail.com | ||
| 3 | + * @Date: 2022-06-09 13:32:44 | ||
| 4 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 5 | + * @LastEditTime: 2022-06-09 13:42:06 | ||
| 6 | + * @FilePath: /tswj/src/api/wx/config.js | ||
| 7 | + * @Description: | ||
| 8 | + */ | ||
| 9 | +import { fn, fetch } from '@/api/fn'; | ||
| 10 | + | ||
| 11 | +const Api = { | ||
| 12 | + WX_PAY: 'c/bill_paymentForBill.do', | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * @description 微信支付接口 | ||
| 17 | + * @param {*} | ||
| 18 | + * @returns {*} | ||
| 19 | + */ | ||
| 20 | +export const wxPayAPI = (params) => fn(fetch.get(Api.WX_PAY, params)); |
| 1 | +/* | ||
| 2 | + * @Date: 2025-03-20 20:36:36 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2025-03-20 23:51:13 | ||
| 5 | + * @FilePath: /mlaj/src/main.js | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | + */ | ||
| 1 | import { createApp } from 'vue' | 8 | import { createApp } from 'vue' |
| 2 | import './style.css' | 9 | import './style.css' |
| 3 | import App from './App.vue' | 10 | import App from './App.vue' |
| 4 | import router from './router' | 11 | import router from './router' |
| 12 | +import axios from '@/utils/axios'; | ||
| 5 | 13 | ||
| 6 | import 'vant/lib/index.css' | 14 | import 'vant/lib/index.css' |
| 7 | 15 | ||
| 8 | const app = createApp(App) | 16 | const app = createApp(App) |
| 17 | +// 屏蔽警告信息 | ||
| 18 | +app.config.warnHandler = () => null; | ||
| 19 | + | ||
| 20 | +app.config.globalProperties.$http = axios; // 关键语句 | ||
| 9 | app.use(router) | 21 | app.use(router) |
| 10 | app.mount('#app') | 22 | app.mount('#app') | ... | ... |
src/utils/axios.js
0 → 100644
| 1 | +/* | ||
| 2 | + * @Author: hookehuyr hookehuyr@gmail.com | ||
| 3 | + * @Date: 2022-05-28 10:17:40 | ||
| 4 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 5 | + * @LastEditTime: 2024-07-25 09:46:46 | ||
| 6 | + * @FilePath: /temple_material_request/src/utils/axios.js | ||
| 7 | + * @Description: | ||
| 8 | + */ | ||
| 9 | +import axios from 'axios'; | ||
| 10 | +import router from '@/router'; | ||
| 11 | +import qs from 'Qs' | ||
| 12 | +import { strExist } from '@/utils/tools' | ||
| 13 | +// import { parseQueryString } from '@/utils/tools' | ||
| 14 | + | ||
| 15 | +axios.defaults.params = { | ||
| 16 | + f: 'good', | ||
| 17 | +}; | ||
| 18 | + | ||
| 19 | +/** | ||
| 20 | + * @description 请求拦截器 | ||
| 21 | + */ | ||
| 22 | +axios.interceptors.request.use( | ||
| 23 | + config => { | ||
| 24 | + // const url_params = parseQueryString(location.href); | ||
| 25 | + // GET请求默认打上时间戳,避免从缓存中拿数据。 | ||
| 26 | + const timestamp = config.method === 'get' ? (new Date()).valueOf() : ''; | ||
| 27 | + /** | ||
| 28 | + * POST PHP需要修改数据格式 | ||
| 29 | + * 序列化POST请求时需要屏蔽上传相关接口,上传相关接口序列化后报错 | ||
| 30 | + */ | ||
| 31 | + // config.data = config.method === 'post' && !strExist(['a=upload', 'upload.qiniup.com'], config.url) ? qs.stringify(config.data) : config.data; | ||
| 32 | + // 绑定默认请求头 | ||
| 33 | + config.params = { ...config.params, timestamp } | ||
| 34 | + return config; | ||
| 35 | + }, | ||
| 36 | + error => { | ||
| 37 | + // 请求错误处理 | ||
| 38 | + return Promise.reject(error); | ||
| 39 | + }); | ||
| 40 | + | ||
| 41 | +/** | ||
| 42 | + * @description 响应拦截器 | ||
| 43 | + */ | ||
| 44 | +axios.interceptors.response.use( | ||
| 45 | + response => { | ||
| 46 | + return response; | ||
| 47 | + }, | ||
| 48 | + error => { | ||
| 49 | + return Promise.reject(error); | ||
| 50 | + }); | ||
| 51 | + | ||
| 52 | +export default axios; |
src/utils/tools.js
0 → 100644
| 1 | +/* | ||
| 2 | + * @Date: 2022-04-18 15:59:42 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2023-02-24 16:13:06 | ||
| 5 | + * @FilePath: /data-table/src/utils/tools.js | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | + */ | ||
| 8 | +import dayjs from 'dayjs'; | ||
| 9 | + | ||
| 10 | +// 格式化时间 | ||
| 11 | +const formatDate = (date) => { | ||
| 12 | + return dayjs(date).format('YYYY-MM-DD HH:mm'); | ||
| 13 | +}; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * @description 判断浏览器属于平台 | ||
| 17 | + * @returns | ||
| 18 | + */ | ||
| 19 | +const wxInfo = () => { | ||
| 20 | + let u = navigator.userAgent; | ||
| 21 | + let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器 | ||
| 22 | + let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端 | ||
| 23 | + let isMobile = u.indexOf('Android') > -1 || u.indexOf('iPhone') > -1 || u.indexOf('iPad') > -1; // 移动端平台 | ||
| 24 | + let isIpad = u.indexOf('iPad') > -1; // iPad平台 | ||
| 25 | + let uAgent = navigator.userAgent.toLowerCase(); | ||
| 26 | + let isWeiXin = (uAgent.match(/MicroMessenger/i) == 'micromessenger') ? true : false; | ||
| 27 | + let isPC = (uAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone|micromessenger)/i)) ? false : true; | ||
| 28 | + return { | ||
| 29 | + isAndroid, | ||
| 30 | + isiOS, | ||
| 31 | + isWeiXin, | ||
| 32 | + isMobile, | ||
| 33 | + isIpad, | ||
| 34 | + isPC | ||
| 35 | + }; | ||
| 36 | +}; | ||
| 37 | + | ||
| 38 | +/** | ||
| 39 | + * @description 判断多行省略文本 | ||
| 40 | + * @param {*} id 目标dom标签 | ||
| 41 | + * @returns | ||
| 42 | + */ | ||
| 43 | +const hasEllipsis = (id) => { | ||
| 44 | + let oDiv = document.getElementById(id); | ||
| 45 | + let flag = false; | ||
| 46 | + if (oDiv.scrollHeight > oDiv.clientHeight) { | ||
| 47 | + flag = true | ||
| 48 | + } | ||
| 49 | + return flag | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +/** | ||
| 53 | + * @description 解析URL参数 | ||
| 54 | + * @param {*} url | ||
| 55 | + * @returns | ||
| 56 | + */ | ||
| 57 | +const parseQueryString = url => { | ||
| 58 | + var json = {}; | ||
| 59 | + var arr = url.indexOf('?') >= 0 ? url.substr(url.indexOf('?') + 1).split('&') : []; | ||
| 60 | + arr.forEach(item => { | ||
| 61 | + var tmp = item.split('='); | ||
| 62 | + json[tmp[0]] = decodeURIComponent(tmp[1]); | ||
| 63 | + }); | ||
| 64 | + return json; | ||
| 65 | +} | ||
| 66 | + | ||
| 67 | +/** | ||
| 68 | + * 字符串包含字符数组中字符的状态 | ||
| 69 | + * @param {*} array 字符数组 | ||
| 70 | + * @param {*} str 字符串 | ||
| 71 | + * @returns 包含状态 | ||
| 72 | + */ | ||
| 73 | +const strExist = (array, str) => { | ||
| 74 | + const exist = array.filter(arr => { | ||
| 75 | + if (str.indexOf(arr) >= 0) return str; | ||
| 76 | + }) | ||
| 77 | + return exist.length > 0 | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +/** | ||
| 81 | + * 自定义替换参数 | ||
| 82 | + * @param {*} url | ||
| 83 | + * @param {*} arg | ||
| 84 | + * @param {*} arg_val | ||
| 85 | + * @returns | ||
| 86 | + */ | ||
| 87 | +const changeURLArg = (url, arg, arg_val) => { | ||
| 88 | + var pattern = arg + '=([^&]*)'; | ||
| 89 | + var replaceText = arg + '=' + arg_val; | ||
| 90 | + if (url.match(pattern)) { | ||
| 91 | + var tmp = '/(' + arg + '=)([^&]*)/gi'; | ||
| 92 | + tmp = url.replace(eval(tmp), replaceText); | ||
| 93 | + return tmp; | ||
| 94 | + } else { | ||
| 95 | + if (url.match('[\?]')) { | ||
| 96 | + return url + '&' + replaceText; | ||
| 97 | + } else { | ||
| 98 | + return url + '?' + replaceText; | ||
| 99 | + } | ||
| 100 | + } | ||
| 101 | + return url + '\n' + arg + '\n' + arg_val; | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +// 获取参数key/value值对 | ||
| 105 | +const getUrlParams = (url) => { | ||
| 106 | + // 没有参数处理 | ||
| 107 | + if (url.split('?').length === 1) return false; | ||
| 108 | + let arr = url.split('?'); | ||
| 109 | + let res = arr[1].split('&'); | ||
| 110 | + let items = {}; | ||
| 111 | + for (let i = 0; i < res.length; i++) { | ||
| 112 | + let [key, value] = res[i].split('='); | ||
| 113 | + items[key] = value; | ||
| 114 | + } | ||
| 115 | + return items | ||
| 116 | +} | ||
| 117 | + | ||
| 118 | +// 格式化URL参数为字符串 | ||
| 119 | +const stringifyQuery = (params) => { | ||
| 120 | + const queryString = []; | ||
| 121 | + Object.keys(params || {}).forEach((k) => { | ||
| 122 | + queryString.push(k + '=' + params[k]); | ||
| 123 | + }); | ||
| 124 | + | ||
| 125 | + return '?' + queryString.join('&'); | ||
| 126 | +}; | ||
| 127 | + | ||
| 128 | +export { | ||
| 129 | + formatDate, | ||
| 130 | + wxInfo, | ||
| 131 | + hasEllipsis, | ||
| 132 | + parseQueryString, | ||
| 133 | + strExist, | ||
| 134 | + changeURLArg, | ||
| 135 | + getUrlParams, | ||
| 136 | + stringifyQuery, | ||
| 137 | +}; |
src/utils/vconsole.js
0 → 100644
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment