调整依赖,调整目录,优化细节

This commit is contained in:
神仙都没用 2024-07-22 20:24:18 +08:00
parent a975a1d91a
commit d380613ba1
38 changed files with 1332 additions and 931 deletions

View File

@ -1 +1,3 @@
vite.config.ts
packages/
dist/
node_modules/

View File

@ -1,27 +1,17 @@
/* eslint-env node */
require("@rushstack/eslint-patch/modern-module-resolution");
module.exports = {
root: true,
env: {
browser: true,
node: true,
es6: true
},
parser: "vue-eslint-parser",
parserOptions: {
parser: "@typescript-eslint/parser",
ecmaVersion: 2020,
sourceType: "module",
jsxPragma: "React",
ecmaFeatures: {
jsx: true,
tsx: true
}
},
extends: [
"plugin:vue/vue3-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:prettier/recommended"
"plugin:vue/vue3-essential",
"eslint:recommended",
"@vue/eslint-config-typescript",
"@vue/eslint-config-prettier/skip-formatting"
],
parserOptions: {
ecmaVersion: "latest"
},
rules: {
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/explicit-function-return-type": "off",
@ -51,6 +41,7 @@ module.exports = {
"vue/attribute-hyphenation": "off",
"vue/html-self-closing": "off",
"vue/require-default-prop": "off",
"vue/v-on-event-hyphenation": "off"
"vue/v-on-event-hyphenation": "off",
"no-self-assign": "off"
}
};

View File

@ -1,5 +1,6 @@
/// <reference types="@cool-vue/crud/index.d.ts" />
/// <reference types="../build/cool/eps.d.ts" />
/// <reference types="./build/cool/eps.d.ts" />
/// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_NAME: string;

View File

@ -26,8 +26,7 @@ http {
index index.html;
try_files $uri $uri/ /index.html;
}
location /api/
{
location /api/ {
proxy_pass http://cool/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@ -68,7 +67,6 @@ http {
proxy_set_header Connection "upgrade";
rewrite /socket/(.*) /$1 break;
proxy_redirect off;
}
}
}

View File

@ -1,12 +1,12 @@
{
"name": "cool-admin",
"version": "7.1.1",
"version": "7.1.2",
"scripts": {
"dev": "vite --host",
"build": "vite build",
"serve": "vite preview",
"lint:prettier": "prettier --write --loglevel warn \"src/**/*.{js,json,tsx,css,less,scss,vue,html,md}\"",
"lint:eslint": "eslint \"./src/**/*.{vue,ts,tsx}\" --fix"
"preview": "vite preview",
"format": "prettier --write src/",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .eslintignore"
},
"dependencies": {
"@cool-vue/crud": "^7.1.26",
@ -14,12 +14,12 @@
"@vueuse/core": "^10.4.0",
"@wangeditor/editor": "^5.1.23",
"@wangeditor/editor-for-vue": "^5.1.12",
"axios": "^1.6.7",
"axios": "^1.7.2",
"chardet": "^2.0.0",
"core-js": "^3.32.1",
"dayjs": "^1.11.10",
"echarts": "^5.4.3",
"element-plus": "^2.7.3",
"element-plus": "^2.7.7",
"file-saver": "^2.0.5",
"lodash-es": "^4.17.21",
"marked": "^11.1.1",
@ -32,33 +32,33 @@
"store": "^2.0.12",
"vue": "^3.4.15",
"vue-echarts": "^6.6.1",
"vue-router": "^4.3.2",
"vue-router": "^4.4.0",
"vuedraggable": "^4.1.0",
"xlsx": "^0.18.5"
},
"devDependencies": {
"@cool-vue/vite-plugin": "^7.1.4",
"@rushstack/eslint-patch": "^1.8.0",
"@cool-vue/vite-plugin": "^7.1.5",
"@types/file-saver": "^2.0.7",
"@types/lodash-es": "^4.17.8",
"@types/mockjs": "^1.0.7",
"@types/node": "^20.5.6",
"@types/node": "^20.14.5",
"@types/nprogress": "^0.2.0",
"@types/store": "^2.0.2",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.4.1",
"@vitejs/plugin-vue": "^5.0.3",
"@vitejs/plugin-vue-jsx": "^3.1.0",
"@vue/compiler-sfc": "^3.4.15",
"eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-vue": "^9.17.0",
"prettier": "^3.1.0",
"@vue/eslint-config-prettier": "^9.0.0",
"@vue/eslint-config-typescript": "^13.0.0",
"eslint": "^8.57.0",
"eslint-plugin-vue": "^9.23.0",
"prettier": "^3.3.3",
"rollup-plugin-visualizer": "^5.9.2",
"sass": "^1.66.1",
"sass": "^1.53.0",
"terser": "^5.27.0",
"typescript": "^5.2.2",
"vite": "^5.0.12",
"vite-plugin-compression": "^0.5.1"
"typescript": "^5.4.0",
"vite": "^5.3.4",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-vue-devtools": "^7.3.1"
}
}

View File

@ -245,6 +245,7 @@
// 创建 Entity
function createEntity() {
const t0 = [];
const arr = [];
for (const item of list) {
if (!item.name)
continue;
@ -266,8 +267,11 @@
t.push(" */\n");
t.push(`[key: string]: any;`);
t.push("}");
if (!arr.includes(item.name)) {
arr.push(item.name);
t0.push(t);
}
}
return t0.map((e) => e.join("")).join("\n\n");
}
// 创建 Service
@ -364,8 +368,10 @@
t.push(` * ${a.summary || n}\n`);
t.push(" */\n");
t.push(`${n}(data${q.length == 1 ? "?" : ""}: ${q.join("")}): Promise<${res}>;`);
if (!permission.includes(n)) {
permission.push(n);
}
}
});
// 权限标识
t.push("\n");

View File

@ -1,6 +1,6 @@
{
"name": "@cool-vue/vite-plugin",
"version": "7.1.4",
"version": "7.1.5",
"description": "cool-admin/cool-uni builder",
"main": "/dist/index.js",
"scripts": {

View File

@ -164,6 +164,7 @@ async function createDescribe({ list, service }: { list: Eps.Entity[]; service:
// 创建 Entity
function createEntity() {
const t0: string[][] = [];
const arr: string[] = [];
for (const item of list) {
if (!item.name) continue;
@ -187,8 +188,12 @@ async function createDescribe({ list, service }: { list: Eps.Entity[]; service:
t.push(" */\n");
t.push(`[key: string]: any;`);
t.push("}");
if (!arr.includes(item.name)) {
arr.push(item.name);
t0.push(t);
}
}
return t0.map((e) => e.join("")).join("\n\n");
}
@ -316,8 +321,10 @@ async function createDescribe({ list, service }: { list: Eps.Entity[]; service:
)}): Promise<${res}>;`,
);
if (!permission.includes(n)) {
permission.push(n);
}
}
});
// 权限标识

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,14 @@
import { App } from "vue";
import { isFunction, orderBy, chain } from "lodash-es";
import { type App, type Directive } from "vue";
import { assign, chain, isFunction } from "lodash-es";
import { filename } from "../utils";
import { module } from "../module";
import { hmr } from "../hooks";
// 扫描文件
const files: any = import.meta.glob(
"/src/{modules,plugins}/*/{config.ts,service/**,directives/**}",
{
eager: true
}
);
const files = import.meta.glob("/src/{modules,plugins}/*/{config.ts,service/**,directives/**}", {
eager: true,
import: "default"
});
// 模块列表
module.list = hmr.getData("modules", []);
@ -21,10 +19,10 @@ for (const i in files) {
const [, , type, name, action] = i.split("/");
// 文件名
const fname = filename(i);
const n = filename(i);
// 文件内容
const v = files[i]?.default;
const v = files[i];
// 模块是否存在
const m = module.get(name);
@ -38,15 +36,13 @@ for (const i in files) {
directives: []
};
switch (action) {
// 配置参数
case "config.ts":
// 配置
if (action == "config.ts") {
d.value = v;
break;
// 请求服务
case "service":
const s = new v();
}
// 服务
else if (action == "service") {
const s = new (v as any)();
if (s) {
d.services?.push({
@ -54,12 +50,10 @@ for (const i in files) {
value: s
});
}
break;
}
// 指令
case "directives":
d.directives?.push({ name: fname, value: v });
break;
else if (action == "directives") {
d.directives?.push({ name: n, value: v as Directive });
}
if (!m) {
@ -69,19 +63,28 @@ for (const i in files) {
// 创建
export function createModule(app: App) {
// 模块加载
const list = orderBy(module.list, "order").map((e) => {
const list = chain(module.list)
.map((e) => {
const d = isFunction(e.value) ? e.value(app) : e.value;
if (d) {
Object.assign(e, d);
assign(e, d);
}
// 安装事件
e.install?.(app, d.options);
if (!d.order) {
e.order = 0;
}
return e;
})
.orderBy("order", "desc")
.map((e) => {
// 初始化
e.install?.(app, e.options);
// 注册组件
e.components?.forEach(async (c: any) => {
e.components?.forEach(async (c) => {
// @ts-ignore
const v = await (isFunction(c) ? c() : c);
const n = v.default || v;
@ -91,12 +94,13 @@ export function createModule(app: App) {
});
// 注册指令
e.directives?.forEach((v: any) => {
e.directives?.forEach((v) => {
app.directive(v.name, v.value);
});
return e;
});
})
.value();
return {
// 模块列表
@ -107,7 +111,7 @@ export function createModule(app: App) {
for (let i = 0; i < list.length; i++) {
if (list[i].onLoad) {
Object.assign(events, await list[i]?.onLoad?.(events));
assign(events, await list[i]?.onLoad?.(events));
}
}
}

View File

@ -140,9 +140,6 @@ export function getBrowser() {
// 是否 ios
const isIOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
// 浏览器版本
const version = (ua.match(/[\s\S]+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1];
// 是否 PC 端
const isPC = tag === "pc";
@ -155,7 +152,6 @@ export function getBrowser() {
return {
height: clientHeight,
width: clientWidth,
version,
type,
plat,
tag,

View File

@ -5,7 +5,10 @@ export const Loading = {
async set(list: Promise<any>[]) {
try {
await Promise.all(list);
} catch (e) {}
} catch (e) {
console.error("[Loading] Error: ", e);
}
if (this.resolve) {
this.resolve();
}

View File

@ -1,6 +1,11 @@
<template v-if="text">
<div class="cl-code-json__wrap" v-if="popover">
<el-popover width="auto" placement="right" popper-class="cl-code-json__popper">
<el-popover
width="auto"
placement="right"
popper-class="cl-code-json__popper"
effect="dark"
>
<template #reference>
<span class="text">{{ text }}</span>
</template>
@ -87,10 +92,10 @@ const viewer = defineComponent({
<style lang="scss">
.cl-code-json {
background-color: var(--el-fill-color-lighter);
border-radius: 6px;
position: relative;
min-width: 200px;
max-width: 500px;
.op {
position: absolute;
@ -123,7 +128,7 @@ const viewer = defineComponent({
}
&__popper {
padding: 5px !important;
padding: 0 !important;
}
}
</style>

View File

@ -1,9 +1,6 @@
import VueECharts from "vue-echarts";
import ElementPlus from "element-plus";
import type { ModuleConfig } from "/@/cool";
import { useStore } from "./store";
import { config } from "/@/config";
import type { ModuleConfig } from "/@/cool";
import "element-plus/theme-chalk/src/index.scss";
import "./static/css/index.scss";
export default (): ModuleConfig => {
@ -60,13 +57,7 @@ export default (): ModuleConfig => {
component: () => import("./pages/error/502.vue")
}
],
install(app) {
// element-plus
app.use(ElementPlus);
// charts
app.component("v-chart", VueECharts);
install() {
// 设置标题
document.title = config.app.name;
},

View File

@ -1,4 +1,4 @@
import { defineComponent, h } from "vue";
import { defineComponent, h, VNode } from "vue";
import { useBase, Menu } from "/$/base";
import { useCool } from "/@/cool";
@ -27,8 +27,6 @@ export default defineComponent({
return list
.filter((e) => e.isShow)
.map((e) => {
let html = null;
const item = (e: Menu.Item) => {
return (
<div class="wrap">
@ -39,7 +37,7 @@ export default defineComponent({
};
if (e.type == 0) {
html = h(
return h(
<el-sub-menu />,
{
index: String(e.id),
@ -56,7 +54,7 @@ export default defineComponent({
}
);
} else {
html = h(
return h(
<el-menu-item />,
{
index:
@ -75,7 +73,6 @@ export default defineComponent({
);
}
return html;
});
}

View File

@ -144,7 +144,7 @@ watch(
onMounted(() => {
//
refs.scroller.wrapRef.addEventListener("wheel", function (event: WheelEvent) {
refs.scroller.wrapRef?.addEventListener("wheel", function (event: WheelEvent) {
//
event.preventDefault();

View File

@ -23,5 +23,4 @@ input {
}
}
@import "./theme.scss";
@import "./animation.scss";

View File

@ -71,8 +71,9 @@
and: [service.base.sys.menu.permission.add, scope.row.type != 2]
}"
@click="append(scope.row)"
>新增</el-button
>
新增
</el-button>
</template>
</cl-table>
</cl-row>
@ -209,7 +210,7 @@ const Table = useTable({
prop: "updateTime",
label: "更新时间",
sortable: "custom",
width: 160
width: 170
},
{
label: "操作",

View File

@ -899,7 +899,7 @@ const desc = reactive({
const val = desc.list[n];
if (val) {
function next2(n2: number) {
const next2 = (n2: number) => {
const v = val[n2];
if (v) {
@ -921,7 +921,7 @@ const desc = reactive({
}
}, 1500);
}
}
};
next2(0);
} else {

View File

@ -127,7 +127,7 @@ const tab = reactive({
if (val == "shop") {
nextTick(() => {
tab.active = "installed";
window.open("https://cool-js.com/");
window.open("https://cool-js.com/plugin");
});
}
}

View File

@ -88,7 +88,7 @@ const tab = reactive({
if (val == "shop") {
nextTick(() => {
tab.active = "installed";
window.open("https://cool-js.com/");
window.open("https://cool-js.com/plugin");
});
}
}

View File

@ -52,7 +52,7 @@ export default defineComponent({
const ids: any[] = [];
// 获取所有的值
function deep(arr: Dict.Item[], f: boolean) {
const deep = (arr: Dict.Item[], f: boolean) => {
arr.forEach((e) => {
const f2 = e[props.valueKey] == val;

View File

@ -10,6 +10,7 @@ import "@cool-vue/crud/dist/index.css";
export default (): Merge<ModuleConfig, CrudOptions> => {
return {
order: 100,
label: "CRUD",
description: "快速增删改查及一系列辅助组件",
author: "COOL",

View File

@ -0,0 +1,16 @@
import type { ModuleConfig } from "/@/cool";
import VueECharts from "vue-echarts";
export default (): ModuleConfig => {
return {
order: 100,
label: "ECharts 图表",
description: "echarts、vue-echarts 配置",
author: "COOL",
version: "1.0.0",
updateTime: "2024-07-22",
install(app) {
app.component("v-chart", VueECharts);
}
};
};

View File

@ -44,7 +44,9 @@ export function useFormat() {
singleQuote: true,
trailingComma: "none"
});
} catch (err) {}
} catch (err) {
// ...
}
return [
{

View File

@ -0,0 +1,17 @@
import type { ModuleConfig } from "/@/cool";
import ElementPlus from "element-plus";
import "./css/index.scss";
export default (): ModuleConfig => {
return {
order: 100,
label: "Element Ui",
description: "Element Plus 变量、样式配置",
author: "COOL",
version: "1.0.0",
updateTime: "2024-07-22",
install(app) {
app.use(ElementPlus);
}
};
};

View File

@ -1,3 +1,9 @@
@forward "element-plus/theme-chalk/src/common/var.scss" with (
$scrollbar: ()
);
@use "element-plus/theme-chalk/src/index.scss" as *;
// Element-plus
.el-input-number {
&__decrease,

View File

@ -122,6 +122,7 @@ import { reactive, type PropType, computed } from "vue";
import * as XLSX from "xlsx";
import chardet from "chardet";
import { extname } from "/@/cool/utils";
import { has } from "lodash-es";
const props = defineProps({
onConfig: Function,
@ -286,7 +287,7 @@ function onUpload(raw: File, _: any, { next }: any) {
let json: any[] = [];
for (const sheet in workbook.Sheets) {
if (workbook.Sheets.hasOwnProperty(sheet)) {
if (has(workbook.Sheets, sheet)) {
json = json.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet]));
}
}

View File

@ -1,12 +1,17 @@
import { setTheme } from "./utils";
import { config } from "/@/config";
import { storage, type ModuleConfig } from "/@/cool";
import "element-plus/theme-chalk/dark/css-vars.css";
import "./static/css/index.scss";
export default (): ModuleConfig => {
return {
label: "主题",
description: "自定义主色、菜单分组、暗黑模式",
author: "COOL",
version: "1.0.0",
updateTime: "2024-07-22",
toolbar: {
component: import("./components/theme.vue")
},

View File

@ -49,7 +49,7 @@
<div
class="cl-upload-item__progress"
:class="{
'is-show': item.progress >= 0 && item.progress < 100,
'is-show': item.progress! >= 0 && item.progress! < 100,
'is-hide': item.progress == 100
}"
>

View File

@ -12,15 +12,9 @@ export function useUpload() {
const { user } = useBase();
// 上传
async function toUpload(
file: File,
opts: Upload.Options = {}
): Promise<{
key: string;
url: string;
fileId: string;
}> {
return new Promise(async (resolve, reject) => {
async function toUpload(file: File, opts: Upload.Options = {}): Upload.Respose {
return new Promise((resolve, reject) => {
const executor = async () => {
// 合并配置
const { prefixPath, onProgress } = merge(options, opts);
@ -41,16 +35,7 @@ export function useUpload() {
let key = isLocal ? fileName : pathJoin(prefixPath!, fileName);
// 多种上传请求
// 上传到云端
async function next({
host,
preview,
data
}: {
host: string;
preview?: string;
data?: any;
}) {
const next = async ({ host, preview, data }: Upload.Request) => {
const fd = new FormData();
// key
@ -112,7 +97,7 @@ export function useUpload() {
ElMessage.error(err.message);
reject(err);
});
}
};
if (isLocal) {
next({
@ -174,6 +159,9 @@ export function useUpload() {
console.error("[upload]", err);
reject(err);
}
};
executor();
});
}

View File

@ -8,8 +8,8 @@ export declare namespace Upload {
interface Item {
url?: string;
uid: string;
progress: number;
uid?: string;
progress?: number;
preload?: string;
error?: string;
isPlay?: boolean;
@ -21,4 +21,16 @@ export declare namespace Upload {
onProgress?(progress: number): void;
[key: string]: any;
}
type Respose = Promise<{
key: string;
url: string;
fileId: string;
}>;
interface Request {
host: string;
preview?: string;
data?: any;
}
}

View File

@ -1,27 +1,27 @@
import path from "path";
import { fileURLToPath, URL } from "node:url";
import { ConfigEnv, UserConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import vueDevTools from "vite-plugin-vue-devtools";
import compression from "vite-plugin-compression";
import { visualizer } from "rollup-plugin-visualizer";
import { proxy } from "./src/config/proxy";
import { cool } from "@cool-vue/vite-plugin";
function resolve(dir: string) {
return path.resolve(__dirname, ".", dir);
}
function isDev(mode: string | undefined): boolean {
return mode === "development";
function toPath(dir: string) {
return fileURLToPath(new URL(dir, import.meta.url));
}
// https://vitejs.dev/config
export default ({ mode }: ConfigEnv): UserConfig => {
const isDev = mode === "development";
return {
plugins: [
vue(),
compression(),
vueJsx(),
// vueDevTools(),
cool({
type: "admin",
proxy
@ -49,14 +49,14 @@ export default ({ mode }: ConfigEnv): UserConfig => {
},
resolve: {
alias: {
"/@": resolve("src"),
"/$": resolve("src/modules"),
"/#": resolve("src/plugins"),
"/~": resolve("packages")
"/@": toPath("./src"),
"/$": toPath("./src/modules"),
"/#": toPath("./src/plugins"),
"/~": toPath("./packages")
}
},
esbuild: {
drop: isDev(mode) ? [] : ["console", "debugger"]
drop: isDev ? [] : ["console", "debugger"]
},
build: {
@ -67,7 +67,7 @@ export default ({ mode }: ConfigEnv): UserConfig => {
// drop_debugger: true
// }
// },
sourcemap: isDev(mode),
sourcemap: isDev,
rollupOptions: {
output: {
chunkFileNames: "static/js/[name]-[hash].js",