mirror of
https://github.com/cool-team-official/cool-admin-vue.git
synced 2025-12-11 21:12:50 +00:00
优化
This commit is contained in:
parent
77edff6a5c
commit
0df167181d
@ -39,7 +39,7 @@
|
||||
"xlsx": "^0.18.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cool-vue/vite-plugin": "^8.0.1",
|
||||
"@cool-vue/vite-plugin": "^8.0.3",
|
||||
"@intlify/unplugin-vue-i18n": "^6.0.3",
|
||||
"@rushstack/eslint-patch": "^1.10.5",
|
||||
"@tsconfig/node20": "^20.1.4",
|
||||
|
||||
47
packages/vite-plugin/dist/index.js
vendored
47
packages/vite-plugin/dist/index.js
vendored
@ -1,8 +1,8 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs'), require('path'), require('prettier'), require('axios'), require('lodash'), require('glob'), require('node:util'), require('svgo')) :
|
||||
typeof define === 'function' && define.amd ? define(['exports', 'fs', 'path', 'prettier', 'axios', 'lodash', 'glob', 'node:util', 'svgo'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.index = {}, global.fs, global.path, global.prettier, global.axios, global.lodash, global.glob, global.util, global.svgo));
|
||||
})(this, (function (exports, fs, path, prettier, axios, lodash, glob, util, svgo) { 'use strict';
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs'), require('path'), require('prettier'), require('axios'), require('lodash'), require('@vue/compiler-sfc'), require('magic-string'), require('glob'), require('node:util'), require('svgo')) :
|
||||
typeof define === 'function' && define.amd ? define(['exports', 'fs', 'path', 'prettier', 'axios', 'lodash', '@vue/compiler-sfc', 'magic-string', 'glob', 'node:util', 'svgo'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.index = {}, global.fs, global.path, global.prettier, global.axios, global.lodash, global.compilerSfc, global.magicString, global.glob, global.util, global.svgo));
|
||||
})(this, (function (exports, fs, path, prettier, axios, lodash, compilerSfc, magicString, glob, util, svgo) { 'use strict';
|
||||
|
||||
const config = {
|
||||
type: "admin",
|
||||
@ -521,7 +521,10 @@
|
||||
}
|
||||
// 创建 dict
|
||||
async function createDict() {
|
||||
return axios.get(config.reqUrl + "/" + config.type + "/dict/info/types").then((res) => {
|
||||
const url = config.reqUrl + "/" + config.type + "/dict/info/types";
|
||||
return axios
|
||||
.get(url)
|
||||
.then((res) => {
|
||||
const { code, data } = res.data;
|
||||
if (code === 1000) {
|
||||
let v = "string";
|
||||
@ -530,6 +533,9 @@
|
||||
}
|
||||
return `type DictKey = ${v}`;
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
error(`[cool-eps] Error:${url}`);
|
||||
});
|
||||
}
|
||||
// 创建 eps
|
||||
@ -646,6 +652,29 @@
|
||||
}
|
||||
}
|
||||
|
||||
function createTag(code, id) {
|
||||
if (/\.vue$/.test(id)) {
|
||||
let s;
|
||||
const str = () => s || (s = new magicString(code));
|
||||
const { descriptor } = compilerSfc.parse(code);
|
||||
if (!descriptor.script && descriptor.scriptSetup) {
|
||||
const res = compilerSfc.compileScript(descriptor, { id });
|
||||
const { name, lang } = res.attrs;
|
||||
str().appendLeft(0, `<script lang="${lang}">
|
||||
import { defineComponent } from 'vue'
|
||||
export default defineComponent({
|
||||
name: "${name}"
|
||||
})
|
||||
<\/script>`);
|
||||
return {
|
||||
map: str().generateMap(),
|
||||
code: str().toString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function base() {
|
||||
return {
|
||||
name: "vite-cool-base",
|
||||
@ -690,6 +719,12 @@
|
||||
}
|
||||
});
|
||||
},
|
||||
transform(code, id) {
|
||||
if (config.nameTag) {
|
||||
return createTag(code, id);
|
||||
}
|
||||
return code;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -958,6 +993,8 @@ if (typeof window !== 'undefined') {
|
||||
config.type = options.type;
|
||||
// 请求地址
|
||||
config.reqUrl = getProxyTarget(options.proxy);
|
||||
// 是否开启名称标签
|
||||
config.nameTag = options.nameTag ?? true;
|
||||
// Eps
|
||||
if (options.eps) {
|
||||
const { dist, mapping, api, enable = true } = options.eps;
|
||||
|
||||
4
packages/vite-plugin/dist/tag/index.d.ts
vendored
Normal file
4
packages/vite-plugin/dist/tag/index.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
export declare function createTag(code: string, id: string): {
|
||||
map: any;
|
||||
code: any;
|
||||
} | null;
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cool-vue/vite-plugin",
|
||||
"version": "8.0.1",
|
||||
"version": "8.0.3",
|
||||
"description": "cool-admin、cool-uni builder",
|
||||
"types": "./dist/index.d.ts",
|
||||
"main": "/dist/index.js",
|
||||
@ -33,6 +33,7 @@
|
||||
"axios": "^1.6.8",
|
||||
"glob": "^10.3.12",
|
||||
"lodash": "^4.17.21",
|
||||
"magic-string": "^0.30.17",
|
||||
"prettier": "^3.4.2",
|
||||
"svgo": "^3.3.2"
|
||||
}
|
||||
|
||||
3
packages/vite-plugin/pnpm-lock.yaml
generated
3
packages/vite-plugin/pnpm-lock.yaml
generated
@ -20,6 +20,9 @@ importers:
|
||||
lodash:
|
||||
specifier: ^4.17.21
|
||||
version: 4.17.21
|
||||
magic-string:
|
||||
specifier: ^0.30.17
|
||||
version: 0.30.17
|
||||
prettier:
|
||||
specifier: ^3.4.2
|
||||
version: 3.5.1
|
||||
|
||||
@ -4,6 +4,8 @@ import { parseJson } from "./utils";
|
||||
import { updatePlugin } from "./plugin";
|
||||
import { updateProxy } from "./proxy";
|
||||
import { createFile } from "./file";
|
||||
import { config } from "./config";
|
||||
import { createTag } from "./tag";
|
||||
|
||||
export function base(): Plugin {
|
||||
return {
|
||||
@ -55,5 +57,12 @@ export function base(): Plugin {
|
||||
}
|
||||
});
|
||||
},
|
||||
transform(code, id) {
|
||||
if (config.nameTag) {
|
||||
return createTag(code, id);
|
||||
}
|
||||
|
||||
return code;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -481,19 +481,26 @@ function createService() {
|
||||
|
||||
// 创建 dict
|
||||
async function createDict() {
|
||||
return axios.get(config.reqUrl + "/" + config.type + "/dict/info/types").then((res) => {
|
||||
const { code, data } = res.data as { code: number; data: any[] };
|
||||
const url = config.reqUrl + "/" + config.type + "/dict/info/types";
|
||||
|
||||
if (code === 1000) {
|
||||
let v = "string";
|
||||
return axios
|
||||
.get(url)
|
||||
.then((res) => {
|
||||
const { code, data } = res.data as { code: number; data: any[] };
|
||||
|
||||
if (!isEmpty(data)) {
|
||||
v = data.map((e) => `"${e.key}"`).join(" | ");
|
||||
if (code === 1000) {
|
||||
let v = "string";
|
||||
|
||||
if (!isEmpty(data)) {
|
||||
v = data.map((e) => `"${e.key}"`).join(" | ");
|
||||
}
|
||||
|
||||
return `type DictKey = ${v}`;
|
||||
}
|
||||
|
||||
return `type DictKey = ${v}`;
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
error(`[cool-eps] Error:${url}`);
|
||||
});
|
||||
}
|
||||
|
||||
// 创建 eps
|
||||
|
||||
@ -13,6 +13,9 @@ export function cool(options: Config.Options) {
|
||||
// 请求地址
|
||||
config.reqUrl = getProxyTarget(options.proxy);
|
||||
|
||||
// 是否开启名称标签
|
||||
config.nameTag = options.nameTag ?? true;
|
||||
|
||||
// Eps
|
||||
if (options.eps) {
|
||||
const { dist, mapping, api, enable = true } = options.eps;
|
||||
|
||||
32
packages/vite-plugin/src/tag/index.ts
Normal file
32
packages/vite-plugin/src/tag/index.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { parse, compileScript } from "@vue/compiler-sfc";
|
||||
import magicString from "magic-string";
|
||||
|
||||
export function createTag(code: string, id: string) {
|
||||
if (/\.vue$/.test(id)) {
|
||||
let s: any;
|
||||
const str = () => s || (s = new magicString(code));
|
||||
const { descriptor } = parse(code);
|
||||
|
||||
if (!descriptor.script && descriptor.scriptSetup) {
|
||||
const res = compileScript(descriptor, { id });
|
||||
const { name, lang }: any = res.attrs;
|
||||
|
||||
str().appendLeft(
|
||||
0,
|
||||
`<script lang="${lang}">
|
||||
import { defineComponent } from 'vue'
|
||||
export default defineComponent({
|
||||
name: "${name}"
|
||||
})
|
||||
<\/script>`,
|
||||
);
|
||||
|
||||
return {
|
||||
map: str().generateMap(),
|
||||
code: str().toString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
1
packages/vite-plugin/types/index.d.ts
vendored
1
packages/vite-plugin/types/index.d.ts
vendored
@ -92,6 +92,7 @@ export declare namespace Config {
|
||||
proxy: any;
|
||||
eps?: Partial<Config.Eps>;
|
||||
demo?: boolean;
|
||||
nameTag?: boolean;
|
||||
}
|
||||
interface Data {
|
||||
type: Config.Type;
|
||||
|
||||
11
pnpm-lock.yaml
generated
11
pnpm-lock.yaml
generated
@ -82,8 +82,8 @@ importers:
|
||||
version: 0.18.5
|
||||
devDependencies:
|
||||
'@cool-vue/vite-plugin':
|
||||
specifier: ^8.0.1
|
||||
version: 8.0.1
|
||||
specifier: ^8.0.3
|
||||
version: 8.0.3
|
||||
'@intlify/unplugin-vue-i18n':
|
||||
specifier: ^6.0.3
|
||||
version: 6.0.3(@vue/compiler-dom@3.5.13)(eslint@9.20.1(jiti@1.21.7))(rollup@4.34.8)(typescript@5.5.4)(vue-i18n@11.1.1(vue@3.5.13(typescript@5.5.4)))(vue@3.5.13(typescript@5.5.4))
|
||||
@ -334,8 +334,8 @@ packages:
|
||||
'@cool-vue/crud@8.0.1':
|
||||
resolution: {integrity: sha512-qITCLcmc5gCiqF2J2I5KsiywqTc/+4Umqy9MBx1dFsYvYfrGcqoRcybcz8cTO4CEDyIv0icymt4PRuKOf01igw==}
|
||||
|
||||
'@cool-vue/vite-plugin@8.0.1':
|
||||
resolution: {integrity: sha512-4vKCUvNnilS3CNVp5xxG+KMuIM5Nx79qZw0lTwgctV4TSYKy4WUdMSf7dJ4+WQltc22Q3DRf3DVRuJMumWhlYA==}
|
||||
'@cool-vue/vite-plugin@8.0.3':
|
||||
resolution: {integrity: sha512-5vxH/EyPXOJvKClllhaTZUeWh9XRJZwZJxyRlHuK2nAuD+pQxTXZ85WB4QPociMrJcOC8uZ/97EdrS4yG2Jv3Q==}
|
||||
|
||||
'@ctrl/tinycolor@3.6.1':
|
||||
resolution: {integrity: sha512-SITSV6aIXsuVNV3f3O0f2n/cgyEDWoSqtZMYiAmcsYHydcKrOz3gUxB/iXd/Qf08+IZX4KpgNbvUdMBmWz+kcA==}
|
||||
@ -3089,12 +3089,13 @@ snapshots:
|
||||
- '@vue/composition-api'
|
||||
- typescript
|
||||
|
||||
'@cool-vue/vite-plugin@8.0.1':
|
||||
'@cool-vue/vite-plugin@8.0.3':
|
||||
dependencies:
|
||||
'@vue/compiler-sfc': 3.5.13
|
||||
axios: 1.7.9
|
||||
glob: 10.4.5
|
||||
lodash: 4.17.21
|
||||
magic-string: 0.30.17
|
||||
prettier: 3.5.1
|
||||
svgo: 3.3.2
|
||||
transitivePeerDependencies:
|
||||
|
||||
@ -49,7 +49,6 @@ function open() {
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '年龄',
|
||||
prop: 'age',
|
||||
component: {
|
||||
name: 'el-input-number'
|
||||
|
||||
@ -554,7 +554,7 @@ defineExpose({
|
||||
}
|
||||
|
||||
.search {
|
||||
padding: 10px;
|
||||
padding: 10px 10px 0 10px;
|
||||
|
||||
:deep(.el-input) {
|
||||
.el-input__wrapper {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user