This commit is contained in:
神仙都没用 2025-02-21 11:11:08 +08:00
parent 77edff6a5c
commit 0df167181d
13 changed files with 121 additions and 24 deletions

View File

@ -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",

View File

@ -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;

View File

@ -0,0 +1,4 @@
export declare function createTag(code: string, id: string): {
map: any;
code: any;
} | null;

View File

@ -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"
}

View File

@ -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

View File

@ -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;
},
};
}

View File

@ -481,7 +481,11 @@ function createService() {
// 创建 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 as { code: number; data: any[] };
if (code === 1000) {
@ -493,6 +497,9 @@ async function createDict() {
return `type DictKey = ${v}`;
}
})
.catch(() => {
error(`[cool-eps] Error${url}`);
});
}

View File

@ -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;

View 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;
}

View File

@ -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
View File

@ -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:

View File

@ -49,7 +49,6 @@ function open() {
}
},
{
label: '年龄',
prop: 'age',
component: {
name: 'el-input-number'

View File

@ -554,7 +554,7 @@ defineExpose({
}
.search {
padding: 10px;
padding: 10px 10px 0 10px;
:deep(.el-input) {
.el-input__wrapper {