build(desktop): 升级 electron-shell 版本至 1.6.3 并调整插件执行超时配置

- 插件执行超时默认延长至 6 小时,支持插件单独配置超时时间
- 新增插件根目录迁移逻辑,解决旧版权限问题
- 新增多个服务端实体、DTO、配置模块等基础代码
- 新增插件 UI 模板及相关静态资源
This commit is contained in:
2026-10-15 11:38:45 +08:00
parent 3dcedf95fd
commit f27639777f
717 changed files with 88647 additions and 17543 deletions
@@ -0,0 +1,19 @@
import { ModuleConfig } from '@cool-midway/core';
/**
* 模块配置
*/
export default () => {
return {
// 模块名称
name: '字典管理',
// 模块描述
description: '数据字典等',
// 中间件,只对本模块有效
middlewares: [],
// 中间件,全局有效
globalMiddlewares: [],
// 模块加载顺序,默认为0,值越大越优先加载
order: 0,
} as ModuleConfig;
};
@@ -0,0 +1,41 @@
import { DictInfoEntity } from './../../entity/info';
import { Body, Get, Inject, Post, Provide } from '@midwayjs/core';
import {
CoolController,
BaseController,
CoolTag,
TagTypes,
} from '@cool-midway/core';
import { DictInfoService } from '../../service/info';
/**
* 字典信息
*/
@Provide()
@CoolController({
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
entity: DictInfoEntity,
service: DictInfoService,
listQueryOp: {
fieldEq: ['typeId'],
keyWordLikeFields: ['name'],
addOrderBy: {
createTime: 'ASC',
},
},
})
export class AdminDictInfoController extends BaseController {
@Inject()
dictInfoService: DictInfoService;
@Post('/data', { summary: '获得字典数据' })
async data(@Body('types') types: string[] = []) {
return this.ok(await this.dictInfoService.data(types));
}
@CoolTag(TagTypes.IGNORE_TOKEN)
@Get('/types', { summary: '获得所有字典类型' })
async types() {
return this.ok(await this.dictInfoService.types());
}
}
@@ -0,0 +1,18 @@
import { DictTypeEntity } from './../../entity/type';
import { Provide } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { DictTypeService } from '../../service/type';
/**
* 字典类型
*/
@Provide()
@CoolController({
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
entity: DictTypeEntity,
service: DictTypeService,
listQueryOp: {
keyWordLikeFields: ['name'],
},
})
export class AdminDictTypeController extends BaseController {}
@@ -0,0 +1,32 @@
import { Body, Get, Inject, Post, Provide } from '@midwayjs/core';
import {
CoolController,
BaseController,
CoolUrlTag,
TagTypes,
CoolTag,
} from '@cool-midway/core';
import { DictInfoService } from '../../service/info';
/**
* 字典信息
*/
@Provide()
@CoolController()
@CoolUrlTag()
export class AppDictInfoController extends BaseController {
@Inject()
dictInfoService: DictInfoService;
@CoolTag(TagTypes.IGNORE_TOKEN)
@Post('/data', { summary: '获得字典数据' })
async data(@Body('types') types: string[] = []) {
return this.ok(await this.dictInfoService.data(types));
}
@CoolTag(TagTypes.IGNORE_TOKEN)
@Get('/types', { summary: '获得所有字典类型' })
async types() {
return this.ok(await this.dictInfoService.types());
}
}
@@ -0,0 +1,88 @@
{
"dict_info": [
{
"id": 21,
"typeId": 19,
"name": "COOL",
"orderNum": 1,
"remark": null,
"parentId": null,
"value": "cool"
},
{
"id": 22,
"typeId": 19,
"name": "闪酷",
"orderNum": 2,
"remark": null,
"parentId": null,
"value": "https://show.cool-admin.com/api/public/uploads/20230308/c731b0cba84046268b10edbbcf36f948_315c243a448e1369fa145c5ea3f020da.gif"
},
{
"id": 23,
"typeId": 20,
"name": "法师",
"orderNum": 1,
"remark": null,
"parentId": null,
"value": "4"
},
{
"id": 24,
"typeId": 20,
"name": "战士",
"orderNum": 2,
"remark": null,
"parentId": null,
"value": "3"
},
{
"id": 25,
"typeId": 20,
"name": "坦克",
"orderNum": 3,
"remark": null,
"parentId": null,
"value": "2"
},
{
"id": 26,
"typeId": 20,
"name": "刺客",
"orderNum": 4,
"remark": null,
"parentId": null,
"value": "1"
},
{
"id": 27,
"typeId": 20,
"name": "射手",
"orderNum": 5,
"remark": null,
"parentId": null,
"value": "0"
},
{
"id": 30,
"typeId": 20,
"name": "幻影刺客",
"orderNum": 1,
"remark": null,
"parentId": 26,
"value": "5"
}
],
"dict_type": [
{
"id": 19,
"name": "品牌",
"key": "brand"
},
{
"id": 20,
"name": "职业",
"key": "occupation"
}
]
}
@@ -0,0 +1,26 @@
import { BaseEntity } from '../../base/entity/base';
import { Column, Entity } from 'typeorm';
/**
* 字典信息
*/
@Entity('dict_info')
export class DictInfoEntity extends BaseEntity {
@Column({ comment: '类型ID' })
typeId: number;
@Column({ comment: '名称' })
name: string;
@Column({ comment: '值', nullable: true })
value: string;
@Column({ comment: '排序', default: 0 })
orderNum: number;
@Column({ comment: '备注', nullable: true })
remark: string;
@Column({ comment: '父ID', default: null })
parentId: number;
}
@@ -0,0 +1,14 @@
import { BaseEntity } from '../../base/entity/base';
import { Column, Entity } from 'typeorm';
/**
* 字典类别
*/
@Entity('dict_type')
export class DictTypeEntity extends BaseEntity {
@Column({ comment: '名称' })
name: string;
@Column({ comment: '标识' })
key: string;
}
@@ -0,0 +1,146 @@
import { DictTypeEntity } from './../entity/type';
import { DictInfoEntity } from './../entity/info';
import { Config, Provide } from '@midwayjs/core';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository, In } from 'typeorm';
import * as _ from 'lodash';
/**
* 字典信息
*/
@Provide()
export class DictInfoService extends BaseService {
@InjectEntityModel(DictInfoEntity)
dictInfoEntity: Repository<DictInfoEntity>;
@InjectEntityModel(DictTypeEntity)
dictTypeEntity: Repository<DictTypeEntity>;
@Config('typeorm.dataSource.default.type')
ormType: string;
/**
* 获得字典数据
* @param types
*/
async data(types: string[]) {
const result = {};
let typeData = await this.dictTypeEntity.find();
if (!_.isEmpty(types)) {
typeData = await this.dictTypeEntity.findBy({ key: In(types) });
}
if (_.isEmpty(typeData)) {
return {};
}
const data = await this.dictInfoEntity
.createQueryBuilder('a')
.select([
'a.id',
'a.name',
'a.typeId',
'a.parentId',
'a.orderNum',
'a.value',
])
.where('a.typeId in(:...typeIds)', {
typeIds: typeData.map(e => {
return e.id;
}),
})
.orderBy('a.orderNum', 'ASC')
.addOrderBy('a.createTime', 'ASC')
.getMany();
for (const item of typeData) {
result[item.key] = _.filter(data, { typeId: item.id }).map(e => {
const value = e.value ? Number(e.value) : e.value;
return {
...e,
// @ts-ignore
value: isNaN(value) ? e.value : value,
};
});
}
return result;
}
/**
* 获得字典key
* @returns
*/
async types() {
return await this.dictTypeEntity.find();
}
/**
* 获得单个或多个字典值
* @param value 字典值或字典值数组
* @param key 字典类型
* @returns
*/
async getValues(value: string | string[], key: string) {
// 获取字典类型
const type = await this.dictTypeEntity.findOneBy({ key });
if (!type) {
return null; // 或者适当的错误处理
}
// 根据typeId获取所有相关的字典信息
const dictValues = await this.dictInfoEntity.find({
where: { typeId: type.id },
});
// 如果value是字符串,直接查找
if (typeof value === 'string') {
return this.findValueInDictValues(value, dictValues);
}
// 如果value是数组,遍历数组,对每个元素进行查找
return value.map(val => this.findValueInDictValues(val, dictValues));
}
/**
* 在字典值数组中查找指定的值
* @param value 要查找的值
* @param dictValues 字典值数组
* @returns
*/
findValueInDictValues(value: string, dictValues: any[]) {
let result = dictValues.find(dictValue => dictValue.value === value);
if (!result) {
result = dictValues.find(dictValue => dictValue.id === parseInt(value));
}
return result ? result.name : null; // 或者适当的错误处理
}
/**
* 修改之后
* @param data
* @param type
*/
async modifyAfter(data: any, type: 'delete' | 'update' | 'add') {
if (type === 'delete') {
for (const id of data) {
await this.delChildDict(id);
}
}
}
/**
* 删除子字典
* @param id
*/
private async delChildDict(id) {
const delDict = await this.dictInfoEntity.findBy({ parentId: id });
if (_.isEmpty(delDict)) {
return;
}
const delDictIds = delDict.map(e => {
return e.id;
});
await this.dictInfoEntity.delete(delDictIds);
for (const dictId of delDictIds) {
await this.delChildDict(dictId);
}
}
}
@@ -0,0 +1,25 @@
import { DictInfoEntity } from './../entity/info';
import { Provide } from '@midwayjs/core';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository, In } from 'typeorm';
/**
* 描述
*/
@Provide()
export class DictTypeService extends BaseService {
@InjectEntityModel(DictInfoEntity)
dictInfoEntity: Repository<DictInfoEntity>;
/**
* 删除
* @param ids
*/
async delete(ids) {
await super.delete(ids);
await this.dictInfoEntity.delete({
typeId: In(ids),
});
}
}