hookehuyr

feat: 添加微信支付和调试功能,配置环境变量和代理

- 添加微信支付相关API和配置
- 引入vconsole实现调试功能
- 配置环境变量文件(.env, .env.development, .env.production)
- 添加代理配置和工具函数
- 更新依赖包以支持新功能
1 +# port
2 +VITE_PORT = 8206
3 +
4 +# 反向代理服务器地址
5 +VITE_PROXY_TARGET = https://oa.onwall.cn
6 +
7 +# API请求前缀
8 +VITE_PROXY_PREFIX = /srv/
9 +
10 +# 打包输出文件夹名称
11 +VITE_OUTDIR = sku_request
12 +
13 +# 是否开启调试
14 +VITE_CONSOLE = 0
15 +
16 +# appID相关
17 +VITE_APPID=微信appID
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/
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/
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 +}
1 +export function createProxy(prefix, target) {
2 + const ret = {};
3 + ret[prefix] = {
4 + target,
5 + changeOrigin: true,
6 + ws: true,
7 + // rewrite: (path) => path.replace(/^\/api/, '')
8 + // rewrite: (path) => path.replace(new RegExp(`^${prefix}`), ''),
9 + }
10 + return ret
11 +}
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();
......
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));
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));
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 +}
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));
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 +]
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')
......
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;
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 +};
1 +import VConsole from 'vconsole';
2 +
3 +// const vConsole = new VConsole();
4 +let vConsole = '';
5 +// 或者使用配置参数来初始化,详情见文档
6 +if (+import.meta.env.VITE_CONSOLE) {
7 + vConsole = new VConsole({ theme: 'dark' });
8 +}
9 +
10 +export default vConsole
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:27:29 4 + * @LastEditTime: 2025-03-20 23:44:51
5 - * @FilePath: /vue-vite/vite.config.js 5 + * @FilePath: /mlaj/vite.config.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
8 -import { defineConfig } from 'vite' 8 +import { defineConfig, loadEnv } from 'vite'
9 import vue from '@vitejs/plugin-vue' 9 import vue from '@vitejs/plugin-vue'
10 import vueJsx from '@vitejs/plugin-vue-jsx' 10 import vueJsx from '@vitejs/plugin-vue-jsx'
11 import path from "path" 11 import path from "path"
12 import Components from 'unplugin-vue-components/vite' 12 import Components from 'unplugin-vue-components/vite'
13 import AutoImport from 'unplugin-auto-import/vite' 13 import AutoImport from 'unplugin-auto-import/vite'
14 import { VantResolver } from 'unplugin-vue-components/resolvers' 14 import { VantResolver } from 'unplugin-vue-components/resolvers'
15 +import { createProxy } from './build/proxy'
15 16
16 -// https://vite.dev/config/ 17 +export default ({ command, mode }) => {
17 -export default defineConfig({ 18 + const root = process.cwd();
19 +
20 + const viteEnv = loadEnv(mode, root);
21 + // let isProd = (command === 'serve'); // 情景配置是否为开发模式 serve 或 build
22 +
23 + return defineConfig({
24 + // root: '',
25 + // root: './src/packages', // 多页面应用配置入口根目录
26 + base: viteEnv.VITE_BASE, // 开发或生产环境服务的公共基础路径。
27 + // base: isProd ? '/' : '/f/voice/', // 开发或生产环境服务的公共基础路径。
28 + // mode: '', // 在配置中指明将会把 serve 和 build 时的模式 都 覆盖掉。也可以通过命令行 --mode 选项来重写。
29 + // define: '', // 定义全局常量替换方式。其中每项在开发环境下会被定义在全局,而在构建时被静态替换。
18 plugins: [ 30 plugins: [
19 vue(), 31 vue(),
20 vueJsx(), 32 vueJsx(),
21 AutoImport({ 33 AutoImport({
22 imports: ['vue', 'vue-router'], 34 imports: ['vue', 'vue-router'],
23 dts: 'src/auto-imports.d.ts', 35 dts: 'src/auto-imports.d.ts',
36 + // 解决eslint报错问题
37 + eslintrc: {
38 + enabled: true
39 + }
24 }), 40 }),
25 Components({ 41 Components({
26 resolvers: [VantResolver()], 42 resolvers: [VantResolver()],
27 dts: 'src/components.d.ts', 43 dts: 'src/components.d.ts',
28 }), 44 }),
29 ], 45 ],
46 + publicDir: 'public', // 作为静态资源服务的文件夹。这个目录中的文件会在开发中被服务于 /,在开发模式时,会被拷贝到 outDir 的根目录,并没有转换,永远只是复制到这里。该值可以是文件系统的绝对路径,也可以是相对于项目的根目录路径。
47 + // cacheDir: '', // 存储缓存文件的目录。此目录下会存储预打包的依赖项或 vite 生成的某些缓存文件,使用缓存可以提高性能。如需重新生成缓存文件,你可以使用 --force 命令行选项或手动删除目录。此选项的值可以是文件的绝对路径,也可以是以项目根目录为基准的相对路径。
30 resolve: { 48 resolve: {
31 alias: { // 将会被传递到 @rollup/plugin-alias 作为 entries 的选项。也可以是一个对象,或一个 { find, replacement } 的数组. 当使用文件系统路径的别名时,请始终使用绝对路径。相对路径的别名值会被原封不动地使用,因此无法被正常解析。 更高级的自定义解析方法可以通过 插件 实现。 49 alias: { // 将会被传递到 @rollup/plugin-alias 作为 entries 的选项。也可以是一个对象,或一个 { find, replacement } 的数组. 当使用文件系统路径的别名时,请始终使用绝对路径。相对路径的别名值会被原封不动地使用,因此无法被正常解析。 更高级的自定义解析方法可以通过 插件 实现。
32 "@": path.resolve(__dirname, "src"), 50 "@": path.resolve(__dirname, "src"),
...@@ -44,4 +62,84 @@ export default defineConfig({ ...@@ -44,4 +62,84 @@ export default defineConfig({
44 // mainFields: [''], // package.json 中,在解析包的入口点时尝试的字段列表。注意,这比从 exports 字段解析的情景导出优先级低:如果一个入口点从 exports 成功解析,主字段将被忽略。 62 // mainFields: [''], // package.json 中,在解析包的入口点时尝试的字段列表。注意,这比从 exports 字段解析的情景导出优先级低:如果一个入口点从 exports 成功解析,主字段将被忽略。
45 extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'], // 导入时想要省略的扩展名列表。注意,不 建议忽略自定义导入类型的扩展名(例如:.vue),因为它会干扰 IDE 和类型支持。 63 extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'], // 导入时想要省略的扩展名列表。注意,不 建议忽略自定义导入类型的扩展名(例如:.vue),因为它会干扰 IDE 和类型支持。
46 }, 64 },
47 -}) 65 + css: {
66 + modules: '', // 配置 CSS modules 的行为。选项将被传递给 postcss-modules。
67 + postcss: { // 内联的 PostCSS 配置(格式同 postcss.config.js),或者一个(默认基于项目根目录的)自定义的 PostCSS 配置路径。其路径搜索是通过 postcss-load-config 实现的。 注意,如果提供了该内联配置,Vite 将不会搜索其他 PostCSS 配置源。
68 + plugins: [
69 + // postcsspxtoviewport({
70 + // unitToConvert: 'px', // 要转化的单位
71 + // viewportWidth: 375, // UI设计稿的宽度
72 + // unitPrecision: 6, // 转换后的精度,即小数点位数
73 + // propList: ['*'], // 指定转换的css属性的单位,*代表全部css属性的单位都进行转换
74 + // viewportUnit: 'vw', // 指定需要转换成的视窗单位,默认vw
75 + // fontViewportUnit: 'vw', // 指定字体需要转换成的视窗单位,默认vw
76 + // selectorBlackList: ['ignore-'], // 指定不转换为视窗单位的类名,
77 + // minPixelValue: 1, // 默认值1,小于或等于1px则不进行转换
78 + // mediaQuery: true, // 是否在媒体查询的css代码中也进行转换,默认false
79 + // replace: true, // 是否转换后直接更换属性值
80 + // // exclude: [/node_modules/], // 设置忽略文件,用正则做目录名匹配
81 + // exclude: [],
82 + // landscape: false // 是否处理横屏情况
83 + // })
84 + ]
85 + },
86 + preprocessorOptions: {
87 + // less: {
88 + // javascriptEnabled: true,
89 + // additionalData: `@import "${path.resolve(__dirname, 'src/assets/styles/base.less')}";`
90 + // }
91 + } // 指定传递给 CSS 预处理器的选项。
92 + },
93 + // json: {
94 + // namedExports: true, // 是否支持从 .json 文件中进行按名导入。
95 + // stringify: false, // 若设置为 true,导入的 JSON 会被转换为 export default JSON.parse("...") 会比转译成对象字面量性能更好,尤其是当 JSON 文件较大的时候。 开启此项,则会禁用按名导入。
96 + // },
97 + // esbuild: false, //
98 + // assetsInclude: '', // 指定其他文件类型作为静态资源处理
99 + logLevel: 'info', // 调整控制台输出的级别,默认为 'info'。
100 + // clearScreen: true, // 设为 false 可以避免 Vite 清屏而错过在终端中打印某些关键信息。命令行模式下请通过 --clearScreen false 设置。
101 + server: {
102 + host: '0.0.0.0',
103 + port: viteEnv.VITE_PORT, // 本地服务端口
104 + // strictPort: true, // 设为true时若端口已被占用则会直接退出, 而不是尝试下一个可用端口
105 + // https: '',
106 + // open: false, // 在服务器启动时自动在浏览器中打开应用程序. 当此值为字符串时, 会被当作URL的路径名.
107 + // proxy: { // 代理
108 + // '/srv/': {
109 + // // target: 'http://voice.onwall.cn',
110 + // target: viteEnv.VITE_PROXY_TARGET,
111 + // changeOrigin: true,
112 + // // rewrite: (path) => path.replace(/^\/api/, '')
113 + // },
114 + // },
115 + proxy: createProxy(viteEnv.VITE_PROXY_PREFIX, viteEnv.VITE_PROXY_TARGET),
116 + // cors: '', // 为开发服务器配置 CORS。默认启用并允许任何源,传递一个 选项对象 来调整行为或设为 false 表示禁用。
117 + // force: '', // 设置为 true 强制使依赖预构建。
118 + // hmr: '', // 禁用或配置 HMR 连接(用于 HMR websocket 必须使用不同的 http 服务器地址的情况)。 设置 server.hmr.overlay 为 false 可以禁用服务器错误遮罩层。
119 + // watch: '', // 传递给 chokidar 的文件系统监视器选项。
120 + },
121 + build: {
122 + // outDir: 'voice', // 指定输出路径(相对于项目根目录).
123 + outDir: viteEnv.VITE_OUTDIR, // 指定输出路径(相对于项目根目录).
124 + assetsDir: 'static',
125 + rollupOptions: {
126 + output: {
127 + chunkFileNames: 'static/js/[name]-[hash].js',
128 + entryFileNames: 'static/js/[name]-[hash].js',
129 + assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
130 + },
131 + input: { // 多页面应用模式, 打包时配置,运行配置要处理root
132 + main: path.resolve(__dirname, 'index.html'),
133 + // mono1: path.resolve(__dirname, 'src/packages/mono1/index.html'),
134 + // mono2: path.resolve(__dirname, 'src/packages/mono2/index.html'),
135 + }
136 + },
137 + },
138 + optimizeDeps: {
139 + // entries: '',
140 + // exclude: [],
141 + include: ['jquery', 'lodash', 'moment', 'axios', 'pinia', 'vue-router', 'vant'], // 默认情况下,不在 node_modules 中的,链接的包不会被预构建。使用此选项可强制预构建链接的包。
142 + // keepNames: false, // 打包器有时需要重命名符号以避免冲突。 设置此项为 true 可以在函数和类上保留 name 属性。 若想获取更多详情,请参阅 keepNames
143 + }
144 + });
145 +};
......