mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2024-11-01 22:20:30 +08:00
完善参数配置,支持字符串、富文本、文件
This commit is contained in:
parent
96aaba5ae6
commit
614738f6b1
@ -11,7 +11,7 @@ import * as localTask from '@midwayjs/task';
|
||||
import * as cool from '@cool-midway/core';
|
||||
import * as cloud from '@cool-midway/cloud';
|
||||
import * as file from '@cool-midway/file';
|
||||
// import * as sms from '@cool-midway/sms';
|
||||
import * as sms from '@cool-midway/sms';
|
||||
// import * as rpc from '@cool-midway/rpc';
|
||||
// import * as task from '@cool-midway/task';
|
||||
// import * as pay from '@cool-midway/pay';
|
||||
@ -48,7 +48,7 @@ import * as file from '@cool-midway/file';
|
||||
// 物联网开发,如MQTT支持等
|
||||
// iot,
|
||||
// 短信
|
||||
// sms
|
||||
sms,
|
||||
{
|
||||
component: info,
|
||||
enabledEnvironment: ['local'],
|
||||
|
@ -6,8 +6,8 @@ import { Column, Index, Entity } from 'typeorm';
|
||||
*/
|
||||
@Entity('base_sys_param')
|
||||
export class BaseSysParamEntity extends BaseEntity {
|
||||
@Index()
|
||||
@Column({ comment: '键位' })
|
||||
@Index({ unique: true })
|
||||
@Column({ comment: '键' })
|
||||
keyName: string;
|
||||
|
||||
@Column({ comment: '名称' })
|
||||
@ -17,7 +17,7 @@ export class BaseSysParamEntity extends BaseEntity {
|
||||
data: string;
|
||||
|
||||
@Column({
|
||||
comment: '数据类型 0:字符串 1:数组 2:键值对',
|
||||
comment: '数据类型 0-字符串 1-富文本 2-文件 ',
|
||||
default: 0,
|
||||
type: 'tinyint',
|
||||
})
|
||||
|
@ -307,24 +307,24 @@ CREATE TABLE `base_sys_param` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT 'ID',
|
||||
`createTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间',
|
||||
`updateTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT '更新时间',
|
||||
`keyName` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '键位',
|
||||
`keyName` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '键',
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '名称',
|
||||
`data` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '数据',
|
||||
`dataType` tinyint NOT NULL DEFAULT '0' COMMENT '数据类型 0:字符串 1:数组 2:键值对',
|
||||
`remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '备注',
|
||||
`dataType` tinyint NOT NULL DEFAULT 0 COMMENT '数据类型 0-字符串 1-富文本 2-文件 ',
|
||||
`remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `IDX_cf19b5e52d8c71caa9c4534454` (`keyName`) USING BTREE,
|
||||
KEY `IDX_7bcb57371b481d8e2d66ddeaea` (`createTime`) USING BTREE,
|
||||
KEY `IDX_479122e3bf464112f7a7253dac` (`updateTime`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
UNIQUE INDEX `IDX_cf19b5e52d8c71caa9c4534454`(`keyName` ASC) USING BTREE,
|
||||
INDEX `IDX_7bcb57371b481d8e2d66ddeaea`(`createTime` ASC) USING BTREE,
|
||||
INDEX `IDX_479122e3bf464112f7a7253dac`(`updateTime` ASC) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of base_sys_param
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO `base_sys_param` VALUES (1, '2021-02-26 13:53:05.000000', '2021-03-03 17:50:04.000000', 'text', '富文本参数', '<p><strong class=\"ql-size-huge\">111xxxxx2222<span class=\"ql-cursor\"></span></strong></p>', 0, NULL);
|
||||
INSERT INTO `base_sys_param` VALUES (2, '2021-02-26 13:53:18.000000', '2023-03-06 12:18:12.329000', 'json', 'JSON参数', '{\n \"code\": 111233\n}', 0, NULL);
|
||||
COMMIT;
|
||||
INSERT INTO `base_sys_param` VALUES (1, '2021-02-26 13:53:05.000000', '2023-05-31 10:43:23.312000', 'rich', '富文本参数', '<h3><strong>这是一个富文本</strong></h3><p>xxx</p><p>xxxxxxxxxx</p><p><br></p>', 1, NULL);
|
||||
INSERT INTO `base_sys_param` VALUES (2, '2021-02-26 13:53:18.000000', '2023-05-30 18:46:28.282000', 'json', 'JSON参数', '{\n \"code\": 111233\n}', 0, NULL);
|
||||
INSERT INTO `base_sys_param` VALUES (6, '2023-05-30 18:48:25.371000', '2023-05-31 10:44:25.612000', 'file', '文件', '', 2, NULL);
|
||||
INSERT INTO `base_sys_param` VALUES (8, '2023-05-31 10:07:53.295000', '2023-05-31 10:46:27.960000', 'text', '测试', '这是一段字符串', 0, NULL);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for base_sys_role
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Inject, Provide } from '@midwayjs/decorator';
|
||||
import { BaseService } from '@cool-midway/core';
|
||||
import { BaseService, CoolCommException } from '@cool-midway/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Not, Repository } from 'typeorm';
|
||||
import { BaseSysParamEntity } from '../../entity/sys/param';
|
||||
import { CacheManager } from '@midwayjs/cache';
|
||||
|
||||
@ -24,17 +24,23 @@ export class BaseSysParamService extends BaseService {
|
||||
let result: any = await this.cacheManager.get(`param:${key}`);
|
||||
if (!result) {
|
||||
result = await this.baseSysParamEntity.findOneBy({ keyName: key });
|
||||
this.cacheManager.set(`param:${key}`, result);
|
||||
}
|
||||
if (result) {
|
||||
if (typeof result == 'string') {
|
||||
result = JSON.parse(result);
|
||||
}
|
||||
if (result.dataType !== 0) {
|
||||
if (result.dataType == 0) {
|
||||
try {
|
||||
return JSON.parse(result.data);
|
||||
} else {
|
||||
} catch (error) {
|
||||
return result.data;
|
||||
}
|
||||
}
|
||||
if (result.dataType == 1) {
|
||||
return result.data;
|
||||
}
|
||||
if (result.dataType == 2) {
|
||||
return result.data.split(',');
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -54,16 +60,31 @@ export class BaseSysParamService extends BaseService {
|
||||
return html;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加或者修改
|
||||
* @param param
|
||||
*/
|
||||
async addOrUpdate(param: any): Promise<void> {
|
||||
const find = {
|
||||
keyName: param.keyName,
|
||||
};
|
||||
if (param.id) {
|
||||
find['id'] = Not(param.id);
|
||||
}
|
||||
const check = await this.baseSysParamEntity.findOneBy(find);
|
||||
if (check) {
|
||||
throw new CoolCommException('存在相同的keyName');
|
||||
}
|
||||
await super.addOrUpdate(param);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新初始化缓存
|
||||
*/
|
||||
async modifyAfter() {
|
||||
const params = await this.baseSysParamEntity.find();
|
||||
for (const param of params) {
|
||||
await this.cacheManager.set(
|
||||
`param:${param.keyName}`,
|
||||
JSON.stringify(param)
|
||||
);
|
||||
await this.cacheManager.set(`param:${param.keyName}`, param);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user