提交 516c703f 编写于 作者: neko's avatar neko

初始化项目

上级 e244381d
流水线 #1163 已取消 ,包含阶段
# General
*.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
需要用到axios[^9.19.2]、dingtalk-jsapi[^2.9.14]、qs[^6.9.1]、typescript[^3.8.3]、rxjs[^6.5.2]</br>
需要用到webpack的import()动态加载模块。</br>
在babel.config.js中配置"retainLines": true,以便更加准确的再async中打断点;
```
module.exports = {
env: {
development: {
sourceMaps: true,
retainLines: true
}
},
presets: [
'@vue/cli-plugin-babel/preset'
]
}
```
\ No newline at end of file
// import moment from 'moment';
import { AppCommunicationsCenter } from './app-communications-center';
/**
* 应用消息发送工具
*
* @export
* @class AccSendUtil
*/
export class AccSendUtil {
/**
* 消息发送
*
* @protected
* @memberof AccSendUtil
*/
protected acc: AppCommunicationsCenter;
/**
* Creates an instance of AccSendUtil.
* @memberof AccSendUtil
*/
constructor(acc: AppCommunicationsCenter) {
this.acc = acc;
}
/**
* 指令-更新
*
* @param {*} data
* @memberof ControlBase
*/
public update(data: any): void {
this.acc.sendMessage({
type: 'COMMAND',
subtype: 'OBJECTUPDATED',
content: data
});
}
/**
* 指令-删除
*
* @param {*} data
* @memberof ControlBase
*/
public remove(data: any): void {
this.acc.sendMessage({
type: 'COMMAND',
subtype: 'OBJECTREMOVED',
content: data
});
}
/**
* 指令-新建
*
* @param {*} data
* @memberof ControlBase
*/
public create(data: any): void {
this.acc.sendMessage({
type: 'COMMAND',
subtype: 'OBJECTCREATED',
content: data
});
}
/**
* 向console区发送消息
*
* @param {string} message 消息内容
* @param {('success' | 'error' | 'warning' | 'info')} [type='info'] 消息类型
* @param {string} [subtype] 消息子类型用于分类
* @returns {void}
* @memberof AccSendUtil
*/
public console(message: string, type: 'success' | 'error' | 'warning' | 'info' = 'info', subtype?: string): void {
if (message) {
switch (type) {
case 'success':
return this.consoleSuccess(message, subtype);
case 'error':
return this.consoleError(message, subtype);
case 'warning':
return this.consoleWarning(message, subtype);
case 'info':
return this.consoleInfo(message, subtype);
}
}
}
/**
* 发送成功消息
*
* @protected
* @param {string} message
* @memberof AccSendUtil
*/
protected consoleSuccess(message: string, subtype?: string): void {
this.acc.sendMessage({
type: 'CONSOLE',
subtype,
content: `${this.getLocalDate()} \x1b[32m${message} \x1b[0m`
});
}
/**
* 发送错误消息
*
* @protected
* @param {string} message
* @memberof AccSendUtil
*/
protected consoleError(message: string, subtype?: string): void {
this.acc.sendMessage({
type: 'CONSOLE',
subtype,
content: `${this.getLocalDate()} \x1b[31m${message} \x1b[0m`
});
}
/**
* 发送警告消息
*
* @protected
* @param {string} message
* @memberof AccSendUtil
*/
protected consoleWarning(message: string, subtype?: string): void {
this.acc.sendMessage({
type: 'CONSOLE',
subtype,
content: `${this.getLocalDate()} \x1b[33m${message} \x1b[0m`
});
}
/**
* 发送消息
*
* @protected
* @param {string} message
* @memberof AccSendUtil
*/
protected consoleInfo(message: string, subtype?: string): void {
this.acc.sendMessage({
type: 'CONSOLE',
subtype,
content: message
});
}
/**
* 获取当前时间
*
* @protected
* @returns {string}
* @memberof AccSendUtil
*/
protected getLocalDate(): string {
// return moment().format('MM-DD HH:mm:ss');
return '';
}
}
\ No newline at end of file
// import mqtt, { MqttClient } from 'mqtt';
import { Util } from '../../utils';
import { AccCentralMessage } from './message/acc-central-message';
import { AccSystemMessage } from './message/acc-system-message';
import { AccCurrentMessage } from './message/acc-current-message';
import { AppMessage } from './interface';
import { AccSendUtil } from './acc-send-util';
/**
* App通讯中心
*
* @export
* @class CommunicationsCenter
*/
export class AppCommunicationsCenter {
/**
* 唯一实例
*
* @private
* @static
* @type {AppCommunicationsCenter}
* @memberof AppCommunicationsCenter
*/
private static readonly appCC: AppCommunicationsCenter = new AppCommunicationsCenter;
/**
* 应用中心消息
*
* @private
* @type {AccCentralMessage}
* @memberof AppCommunicationsCenter
*/
private $accCentralMessage: AccCentralMessage = new AccCentralMessage();
/**
* 发送消息工具
*
* @type {AccSendUtil}
* @memberof AppCommunicationsCenter
*/
public send: AccSendUtil = new AccSendUtil(this);
/**
* 应用中心级
*
* @readonly
* @type {AccCentralMessage}
* @memberof AppCommunicationsCenter
*/
public get central(): AccCentralMessage {
return this.$accCentralMessage;
}
/**
* 系统消息
*
* @private
* @type {AccSystemMessage}
* @memberof AppCommunicationsCenter
*/
private $accSystemMessage: AccSystemMessage = new AccSystemMessage();
/**
* 系统级
*
* @readonly
* @type {AccSystemMessage}
* @memberof AppCommunicationsCenter
*/
public get system(): AccSystemMessage {
return this.$accSystemMessage;
}
/**
* 当前页面消息
*
* @private
* @type {AccCurrentMessage}
* @memberof AppCommunicationsCenter
*/
private $accCurrentMessage: AccCurrentMessage = new AccCurrentMessage();
/**
* 页面级
*
* @readonly
* @type {AccCurrentMessage}
* @memberof AppCommunicationsCenter
*/
public get current(): AccCurrentMessage {
return this.$accCurrentMessage;
}
/**
* 订阅缓存
*
* @protected
* @type {Map<string, string[]>}
* @memberof AppCommunicationsCenter
*/
protected unsubscribeCache: Map<string, string[]> = new Map();
/**
* 连接选项
*
* @protected
* @memberof AppCommunicationsCenter
*/
protected options = {
// 超时时间
connectTimeout: 4000,
// 认证信息
clientId: 'ws-' + new Date().getTime(),
// username: 'emqx',
// password: 'emqx',
// 心跳时间
keepalive: 60,
clean: true,
}
/**
* 链接实例
*
* @protected
* @type {MqttClient}
* @memberof AppCommunicationsCenter
*/
// protected ws!: MqttClient;
/**
* 连接地址
*
* @protected
* @type {string}
* @memberof AppCommunicationsCenter
*/
protected url?: string;
/**
* 中心主题标识
*
* @protected
* @type {string}
* @memberof AppCommunicationsCenter
*/
protected psdcconsoleid?: string;
/**
* 系统主题标识
*
* @protected
* @type {string}
* @memberof AppCommunicationsCenter
*/
protected psdevslnsysid?: string;
/**
* 当前studio标识
*
* @protected
* @type {string}
* @memberof AppCommunicationsCenter
*/
protected psdsconsoleid?: string;
/**
* Creates an instance of AppCommunicationsCenter.
* @param {{ psdsconsoleurl: string, psdcconsoleid?: string, psdevslnsysid?: string, psdsconsoleid?: string }} [params]
* @param {*} [opt={}]
* @memberof AppCommunicationsCenter
*/
constructor(params?: { psdsconsoleurl?: string, psdcconsoleid?: string, psdevslnsysid?: string, psdsconsoleid?: string }, opt: any = {}) {
let me: any = this;
if (AppCommunicationsCenter.appCC) {
me = AppCommunicationsCenter.appCC;
}
// if (params) {
// me.url = params.psdsconsoleurl;
// me.psdcconsoleid = params.psdcconsoleid;
// me.psdevslnsysid = params.psdevslnsysid;
// me.psdsconsoleid = params.psdsconsoleid;
// if (me.psdsconsoleid) {
// me.options.clientId = me.psdsconsoleid;
// }
// Object.assign(me.options, opt);
// if (me.url) {
// if (me.ws) {
// me.ws.disconnecting()
// me.ws.disconnected();
// }
// me.ws = mqtt.connect(me.url, this.options);
// me.registerEvent();
// }
// }
return me;
}
/**
* 注册事件
*
* @protected
* @memberof AppCommunicationsCenter
*/
// protected registerEvent(): void {
// this.ws.on('connect', () => {
// // 订阅中心级
// if (this.psdcconsoleid) {
// this.ws.subscribe(this.psdcconsoleid, { qos: 1 }, (error: any) => {
// if (error) {
// console.error('Central 订阅失败', error);
// return;
// }
// });
// }
// // 订阅系统级
// if (this.psdevslnsysid) {
// this.ws.subscribe(this.psdevslnsysid, { qos: 1 }, (error: any) => {
// if (error) {
// console.error('System 订阅失败', error);
// return;
// }
// });
// }
// // 订阅当前级
// if (this.psdsconsoleid) {
// this.ws.subscribe(this.psdsconsoleid, { qos: 1 }, (error: any) => {
// if (error) {
// console.error('Current 订阅失败', error);
// return;
// }
// });
// }
// })
// this.ws.on('reconnect', (error: any) => {
// if (!error) {
// console.log('正在重连...');
// } else {
// console.warn('重连失败:', error);
// }
// })
// this.ws.on('error', (error: any) => {
// console.log('连接失败:', error)
// })
// this.ws.on('message', (topic: any, message: any) => {
// let ms: string = '';
// try {
// ms = message.toString('utf-8');
// const data: any = JSON.parse(ms);
// switch (topic) {
// case this.psdcconsoleid:
// this.next('Central', data);
// break;
// case this.psdevslnsysid:
// this.next('System', data);
// break;
// case this.psdsconsoleid:
// this.next('Current', data);
// break;
// }
// } catch (error) {
// console.warn('消息中心:websocket消息解析失败!');
// console.warn('消息内容:', ms);
// console.error(error);
// }
// });
// }
/**
* 取消订阅
*
* @param {string} key
* @memberof AccMessage
*/
public unsubscribe(key: string): void {
if (this.unsubscribeCache.has(key)) {
const arr: any = this.unsubscribeCache.get(key);
arr.forEach((str: string) => {
this.unsubscribe(str);
});
} else {
this.$accCentralMessage.unsubscribe(key);
this.$accSystemMessage.unsubscribe(key);
this.$accCurrentMessage.unsubscribe(key);
}
}
/**
* 取消本地模式订阅
*
* @param {string} key
* @memberof AccMessage
*/
public unsubscribeLocal(key: string): void {
if (this.unsubscribeCache.has(key)) {
const arr: any = this.unsubscribeCache.get(key);
arr.forEach((str: string) => {
this.unsubscribeLocal(str);
});
} else {
this.$accCentralMessage.unsubscribeLocal(key);
this.$accSystemMessage.unsubscribeLocal(key);
this.$accCurrentMessage.unsubscribeLocal(key);
}
}
/**
* 发送消息
*
* @param {('Central' | 'System' | 'Current')} type
* @param {AppMessage} data
* @memberof AppCommunicationsCenter
*/
public next(type: 'Central' | 'System' | 'Current', data: AppMessage) {
switch (type) {
case 'Central':
this.$accCentralMessage.next(data);
break;
case 'System':
this.$accSystemMessage.next(data);
break;
case 'Current':
this.$accCurrentMessage.next(data);
break;
}
}
/**
* 发送当前页面级消息
*
* @param {AppMessage} param
* @memberof AppCommunicationsCenter
*/
public sendMessage(param: AppMessage) {
const params: any = Util.deepCopy(param);
const data: any = params.content;
if ((!data.srfdename || Object.is(data.srfdename, '')) && data.srfdeid) {
data.srfdename = data.srfdeid;
}
this.$accCurrentMessage.nextLocal(params);
}
/**
* 订阅command
*
* @param {(content: any) => void} observer 回调函数
* @param {('update' | 'remove' | 'create')} [subtype] 更新类型
* @param {string} [deName] 实体名称
* @returns {string}
* @memberof AppCommunicationsCenter
*/
public command(observer: (content: any) => void, subtype?: 'update' | 'remove' | 'create' | 'all', deName?: string): string {
const arr: any[] = [];
if (Object.is(subtype, 'update')) {
arr.push(this.central.command.update.subscribe(observer, deName));
arr.push(this.system.command.update.subscribe(observer, deName));
arr.push(this.current.command.update.subscribe(observer, deName));
} else if (Object.is(subtype, 'remove')) {
arr.push(this.central.command.remove.subscribe(observer, deName));
arr.push(this.system.command.remove.subscribe(observer, deName));
arr.push(this.current.command.remove.subscribe(observer, deName));
} else if (Object.is(subtype, 'create')) {
arr.push(this.central.command.create.subscribe(observer, deName));
arr.push(this.system.command.create.subscribe(observer, deName));
arr.push(this.current.command.create.subscribe(observer, deName));
} else {
arr.push(this.central.command.subscribe(observer, deName));
arr.push(this.system.command.subscribe(observer, deName));
arr.push(this.current.command.subscribe(observer, deName));
}
const key: string = this.createUUID();
this.unsubscribeCache.set(key, arr);
return key;
}
/**
* 订阅command
*
* @param {(content: any) => void} observer 回调函数
* @param {('update' | 'remove' | 'create')} [subtype] 更新类型
* @param {string} [deName] 实体名称
* @returns {string}
* @memberof AppCommunicationsCenter
*/
public commandLocal(observer: (content: any) => void, subtype?: 'update' | 'remove' | 'create' | 'all', deName?: string): string {
const arr: any[] = [];
if (Object.is(subtype, 'update')) {
arr.push(this.current.command.update.subscribeLocal(observer, deName));
} else if (Object.is(subtype, 'remove')) {
arr.push(this.current.command.remove.subscribeLocal(observer, deName));
} else if (Object.is(subtype, 'create')) {
arr.push(this.current.command.create.subscribeLocal(observer, deName));
} else {
arr.push(this.current.command.subscribeLocal(observer, deName));
}
const key: string = this.createUUID();
this.unsubscribeCache.set(key, arr);
return key;
}
/**
* 订阅console
*
* @param {(content: any) => void} observer
* @returns {string}
* @memberof AppCommunicationsCenter
*/
public console(observer: (content: any) => void): string {
const arr: any[] = [];
arr.push(this.central.console.subscribe(observer));
arr.push(this.system.console.subscribe(observer));
arr.push(this.current.console.subscribe(observer));
const key: string = this.createUUID();
this.unsubscribeCache.set(key, arr);
return key;
}
/**
* 订阅console本地消息
*
* @param {(content: any) => void} observer
* @returns {string}
* @memberof AppCommunicationsCenter
*/
public consoleLocal(observer: (content: any) => void): string {
const key: string = this.createUUID();
this.unsubscribeCache.set(key, [this.current.console.subscribeLocal(observer)]);
return key;
}
/**
* 获取实例
*
* @static
* @returns
* @memberof AppCommunicationsCenter
*/
public static getInstance() {
return AppCommunicationsCenter.appCC;
}
/**
* 创建 UUID
*
* @returns {string}
* @memberof Util
*/
protected createUUID(): string {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}
}
\ No newline at end of file
/**
* 全局消息
*
* @export
* @interface AppMessage
*/
export interface AppMessage {
/**
* 消息类型
*
* @type {('CONSOLE' | 'COMMAND')}
* @memberof AppMessage
*/
type: 'CONSOLE' | 'COMMAND';
/**
* 消息子类型
*
* @type {('OBJECTUPDATED' | 'OBJECTREMOVED' | 'OBJECTCREATED' | string)}
* @memberof AppMessage
*/
subtype?: 'OBJECTUPDATED' | 'OBJECTREMOVED' | 'OBJECTCREATED' | string;
/**
* 消息内容
*
* @type {*}
* @memberof AppMessage
*/
content: any;
}
\ No newline at end of file
import { Subject, Subscription } from 'rxjs';
import { Util } from '../../../../utils';
/**
*
*
* @export
* @class MessageTypeBase
*/
export class MessageTypeBase {
/**
* 数据流发射器
*
* @protected
* @type {Subject<any>}
* @memberof MessageConsole
*/
protected subject: Subject<any> = new Subject();
/**
* 本地数据发射流
*
* @protected
* @type {Subject<any>}
* @memberof MessageTypeBase
*/
protected subjectLocal: Subject<any> = new Subject();
/**
* 事件订阅缓存(避免重复订阅)
*
* @protected
* @type {Map<string, Subject<any>>}
* @memberof MessageTypeBase
*/
protected subjectMap: Map<string, Subject<any>> = new Map();
/**
* 本地消息事件订阅缓存(避免重复订阅)
*
* @protected
* @type {Map<string, Subject<any>>}
* @memberof MessageTypeBase
*/
protected subjectLocalMap: Map<string, Subject<any>> = new Map();
/**
* 缓存
*
* @protected
* @type {Map<string, Subscription>}
* @memberof MessageConsole
*/
protected map: Map<string, Subscription> = new Map();
/**
* 本地缓存
*
* @protected
* @type {Map<string, Subscription>}
* @memberof MessageTypeBase
*/
protected mapLocal: Map<string, Subscription> = new Map();
/**
* 发送消息
*
* @param {*} message
* @param {string} [type]
* @memberof MessageTypeBase
*/
public next(message: any, type?: string): void {
if (type) {
if (this.subjectMap.has(type)) {
const sub: any = this.subjectMap.get(type);
sub.next(message.content);
}
} else {
this.subject.next(message.content);
}
}
/**
* 发送本地消息
*
* @param {*} message
* @param {string} [type]
* @memberof MessageTypeBase
*/
public nextLocal(message: any, type?: string): void {
if (type) {
if (this.subjectLocalMap.has(type)) {
const sub: any = this.subjectLocalMap.get(type);
sub.next(message.content);
}
} else {
this.subjectLocal.next(message.content);
}
}
/**
* 订阅消息
*
* @param {(content: any) => void} [observer]
* @param {string} [type]
* @returns {string}
* @memberof MessageTypeBase
*/
public subscribe(observer?: (content: any) => void, type?: string): string {
const key: string = Util.createUUID();
if (type) {
let sub: any;
if (this.subjectMap.has(type)) {
sub = this.subjectMap.get(type);
} else {
sub = new Subject();
this.subjectMap.set(type, sub);
}
this.map.set(key, sub.asObservable().subscribe(observer));
} else {
this.map.set(key, this.subject.asObservable().subscribe(observer));
}
return key;
}
/**
* 订阅本地消息
*
* @param {(content: any) => void} [observer]
* @param {string} [type]
* @returns {string}
* @memberof MessageTypeBase
*/
public subscribeLocal(observer?: (content: any) => void, type?: string): string {
const key: string = Util.createUUID();
if (type) {
let sub: any;
if (this.subjectLocalMap.has(type)) {
sub = this.subjectLocalMap.get(type);
} else {
sub = new Subject();
this.subjectLocalMap.set(type, sub);
}
this.mapLocal.set(key, sub.asObservable().subscribe(observer));
} else {
this.mapLocal.set(key, this.subjectLocal.asObservable().subscribe(observer));
}
return key;
}
/**
* 取消订阅
*
* @param {string} key
* @returns {void}
* @memberof MessageConsole
*/
public unsubscribe(key: string): void {
if (this.map.has(key)) {
const sub: any = this.map.get(key);
sub.unsubscribe();
}
}
/**
* 取消订阅本地消息
*
* @param {string} key
* @memberof MessageTypeBase
*/
public unsubscribeLocal(key: string): void {
if (this.mapLocal.has(key)) {
const sub: any = this.mapLocal.get(key);
sub.unsubscribe();
}
}
}
\ No newline at end of file
import { MessageTypeBase } from '../base/message-type-base';
/**
* 更新消息
*
* @export
* @class CommandCreate
* @extends {MessageTypeBase}
*/
export class CommandCreate extends MessageTypeBase {
}
\ No newline at end of file
import { MessageTypeBase } from '../base/message-type-base';
/**
* 更新消息
*
* @export
* @class CommandRemove
* @extends {MessageTypeBase}
*/
export class CommandRemove extends MessageTypeBase {
}
\ No newline at end of file
import { MessageTypeBase } from '../base/message-type-base';
/**
* 更新消息
*
* @export
* @class CommandUpdate
* @extends {MessageTypeBase}
*/
export class CommandUpdate extends MessageTypeBase {
}
\ No newline at end of file
import { MessageTypeBase } from './base/message-type-base';
import { CommandUpdate } from './command/command-update';
import { CommandCreate } from './command/command-create';
import { CommandRemove } from './command/command-remove';
import { AppMessage } from '../interface';
/**
* 命令消息
*
* @export
* @class MessageCommand
*/
export class MessageCommand extends MessageTypeBase {
/**
* 更新消息
*
* @protected
* @type {CommandUpdate}
* @memberof MessageCommand
*/
protected $update: CommandUpdate = new CommandUpdate();
/**
* 更新消息
*
* @readonly
* @type {CommandUpdate}
* @memberof MessageCommand
*/
public get update(): CommandUpdate {
return this.$update;
}
/**
* 新建消息
*
* @protected
* @type {CommandCreate}
* @memberof MessageCommand
*/
protected $create: CommandCreate = new CommandCreate();
/**
* 新建消息
*
* @readonly
* @type {CommandCreate}
* @memberof MessageCommand
*/
public get create(): CommandCreate {
return this.$create;
}
/**
* 删除消息
*
* @protected
* @type {CommandRemove}
* @memberof MessageCommand
*/
protected $remove: CommandRemove = new CommandRemove();
/**
* CommandRemove
*
* @readonly
* @type {CommandRemove}
* @memberof MessageCommand
*/
public get remove(): CommandRemove {
return this.$remove;
}
/**
* 发送消息
*
* @param {AppMessage} message
* @memberof MessageCommand
*/
public next(message: AppMessage): void {
if (message) {
const content: any = message.content;
const deName: string = content.srfdename;
if (content && deName && !Object.is(deName, '')) {
this.subNext(message, deName);
}
this.subNext(message);
super.next(message, deName);
}
}
/**
* 发送本地消息
*
* @param {AppMessage} message
* @memberof MessageCommand
*/
public nextLocal(message: AppMessage): void {
if (message) {
const content: any = message.content;
const deName: string = content.srfdename;
if (content && deName && !Object.is(deName, '')) {
this.subNextLocal(message, deName);
}
this.subNextLocal(message);
super.nextLocal(message, deName);
}
}
/**
* 根据子类别发送消息
*
* @param {AppMessage} message
* @param {string} [type]
* @memberof MessageCommand
*/
public subNext(message: AppMessage, type?: string): void {
if (Object.is(message.subtype, 'OBJECTUPDATED')) {
this.$update.next(message, type);
}
if (Object.is(message.subtype, 'OBJECTREMOVED')) {
this.$remove.next(message, type);
}
if (Object.is(message.subtype, 'OBJECTCREATED')) {
this.$create.next(message, type);
}
}
/**
* 根据子类别发送本地消息
*
* @param {AppMessage} message
* @param {string} [type]
* @memberof MessageCommand
*/
public subNextLocal(message: AppMessage, type?: string): void {
if (Object.is(message.subtype, 'OBJECTUPDATED')) {
this.$update.nextLocal(message, type);
}
if (Object.is(message.subtype, 'OBJECTREMOVED')) {
this.$remove.nextLocal(message, type);
}
if (Object.is(message.subtype, 'OBJECTCREATED')) {
this.$create.nextLocal(message, type);
}
}
/**
* 取消订阅
*
* @param {string} key
* @memberof MessageCommand
*/
public unsubscribe(key: string): void {
super.unsubscribe(key);
this.$create.unsubscribe(key);
this.$remove.unsubscribe(key);
this.$update.unsubscribe(key)
}
/**
* 取消本地订阅
*
* @param {string} key
* @memberof MessageCommand
*/
public unsubscribeLocal(key: string): void {
super.unsubscribeLocal(key);
this.$create.unsubscribeLocal(key);
this.$remove.unsubscribeLocal(key);
this.$update.unsubscribeLocal(key)
}
}
\ No newline at end of file
import { MessageTypeBase } from './base/message-type-base';
/**
* 控制台消息
*
* @export
* @class MessageConsole
*/
export class MessageConsole extends MessageTypeBase {
/**
* 发送消息
*
* @param {*} message
* @param {string} [type]
* @memberof MessageTypeBase
*/
public next(message: any, type?: string): void {
if (type) {
if (this.subjectMap.has(type)) {
const sub: any = this.subjectMap.get(type);
sub.next(message);
} else { }
} else {
this.subject.next(message);
}
}
/**
* 发送本地消息
*
* @param {*} message
* @param {string} [type]
* @memberof MessageConsole
*/
public nextLocal(message: any, type?: string): void {
if (type) {
if (this.subjectLocalMap.has(type)) {
const sub: any = this.subjectLocalMap.get(type);
sub.next(message);
} else { }
} else {
this.subjectLocal.next(message);
}
}
}
\ No newline at end of file
import { AccMessageBase } from './base/acc-message-base';
/**
*
*
* @export
* @class AccCentralMessage
* @extends {AccMessageBase}
*/
export class AccCentralMessage extends AccMessageBase {
}
\ No newline at end of file
import { AccMessageBase } from './base/acc-message-base';
/**
*
*
* @export
* @class AccCurrentMessage
* @extends {AccMessageBase}
*/
export class AccCurrentMessage extends AccMessageBase {
}
\ No newline at end of file
import { AccMessageBase } from './base/acc-message-base';
/**
*
*
* @export
* @class AccSystemMessage
* @extends {AccMessageBase}
*/
export class AccSystemMessage extends AccMessageBase {
}
\ No newline at end of file
import { Subject, Subscription } from 'rxjs';
import { Util } from '../../../../utils';
import { MessageConsole } from '../../message-type/message-console';
import { MessageCommand } from '../../message-type/message-command';
import { AppMessage } from '../../interface';
/**
* 应用中心消息
*
* @export
* @class AccMessageBase
*/
export class AccMessageBase {
/**
* 数据流发射器
*
* @protected
* @type {Subject<any>}
* @memberof MessageConsole
*/
protected subject: Subject<any> = new Subject();
/**
* 本地数据流发射器
*
* @protected
* @type {Subject<any>}
* @memberof AccMessageBase
*/
protected subjectLocal: Subject<any> = new Subject();
/**
* 订阅缓存
*
* @protected
* @type {Map<string, Subscription>}
* @memberof MessageConsole
*/
protected map: Map<string, Subscription> = new Map();
/**
* 本地订阅缓存
*
* @protected
* @type {Map<string, Subscription>}
* @memberof AccMessageBase
*/
protected mapLocal: Map<string, Subscription> = new Map();
/**
* console消息实例
*
* @protected
* @type {MessageConsole}
* @memberof AccMessageBase
*/
protected $messageConsole: MessageConsole = new MessageConsole();
/**
* console消息实例
*
* @readonly
* @type {MessageConsole}
* @memberof AccMessageBase
*/
public get console(): MessageConsole {
return this.$messageConsole;
}
/**
* command消息实例
*
* @protected
* @type {MessageCommand}
* @memberof AccMessageBase
*/
protected $messageCommand: MessageCommand = new MessageCommand();
/**
* MessageCommand
*
* @readonly
* @type {MessageCommand}
* @memberof AccMessageBase
*/
public get command(): MessageCommand {
return this.$messageCommand;
}
/**
* 发送消息数据
*
* @param {AppMessage} message
* @memberof AccMessageBase
*/
public next(message: AppMessage): void {
if (message) {
if (Object.is(message.type, 'CONSOLE')) {
this.$messageConsole.next(message);
}
if (Object.is(message.type, 'COMMAND')) {
this.$messageCommand.next(message);
}
this.subject.next(message);
}
}
/**
* 发送本地消息数据
*
* @param {AppMessage} message
* @memberof AccMessageBase
*/
public nextLocal(message: AppMessage): void {
if (message) {
if (Object.is(message.type, 'CONSOLE')) {
this.$messageConsole.nextLocal(message);
}
if (Object.is(message.type, 'COMMAND')) {
this.$messageCommand.nextLocal(message);
}
this.subjectLocal.next(message);
}
}
/**
* 订阅消息
*
* @param {(content: any) => void} [observer]
* @param {string} [type]
* @returns {string}
* @memberof MessageTypeBase
*/
public subscribe(observer?: (content: any) => void): string {
const key: string = Util.createUUID();
this.map.set(key, this.subject.asObservable().subscribe(observer));
return key;
}
/**
* 订阅本地消息
*
* @param {(content: any) => void} [observer]
* @returns {string}
* @memberof AccMessageBase
*/
public subscribeLocal(observer?: (content: any) => void): string {
const key: string = Util.createUUID();
this.mapLocal.set(key, this.subjectLocal.asObservable().subscribe(observer));
return key;
}
/**
* 取消订阅
*
* @param {string} key
* @returns {void}
* @memberof MessageConsole
*/
public unsubscribe(key: string): void {
this.$messageConsole.unsubscribe(key);
this.$messageCommand.unsubscribe(key);
if (this.map.has(key)) {
const sub: any = this.map.get(key);
sub.unsubscribe();
}
}
/**
* 取消订阅本地
*
* @param {string} key
* @memberof AccMessageBase
*/
public unsubscribeLocal(key: string): void {
this.$messageConsole.unsubscribeLocal(key);
this.$messageCommand.unsubscribeLocal(key);
if (this.mapLocal.has(key)) {
const sub: any = this.mapLocal.get(key);
sub.unsubscribe();
}
}
}
\ No newline at end of file
import { HttpResponse } from '../utils';
/**
* 代码表基类
*
* @export
* @class CodeListBase
*/
export class CodeListBase {
/**
* 代码表项主键标识
*
* @protected
* @type {string}
* @memberof CodeListBase
*/
protected idKey: string = '';
/**
* 代码表项值项标识
*
* @protected
* @type {string}
* @memberof CodeListBase
*/
protected valueKey: string = '';
/**
* 代码表项文本标识
*
* @protected
* @type {string}
* @memberof CodeListBase
*/
protected textKey: string = '';
/**
* 处理数据
*
* @protected
* @param {any[]} items
* @returns {any[]}
* @memberof CodeListBase
*/
protected doItems(items: any[]): any[] {
return items.map((item: any) => {
const data: any = {};
Object.assign(data, { id: item[this.idKey] });
Object.assign(data, { value: item[this.valueKey] });
Object.assign(data, { text: item[this.textKey] });
return data;
});;
}
/**
* 获取数据项
*
* @param {*} data
* @returns {Promise<any>}
* @memberof SysOperator
*/
public async getItems(data: any = {}): Promise<any> {
return new HttpResponse(200, []);
}
/**
* 根据实体名称获取service
*
* @protected
* @param {string} name
* @returns {Promise<any>}
* @memberof CodeListBase
*/
protected getService(name: string): Promise<any> {
return window.appEntityServiceConstructor.getService(name);
}
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
/**
* 应用菜单部件服务基类
*
* @export
* @class AppMenuServiceBase
* @extends {ControlServiceBase}
*/
export class AppMenuServiceBase extends ControlServiceBase {
}
\ No newline at end of file
import { MdServiceBase } from './md-service-base';
import { HttpResponse } from '../utils';
/**
* 日历部件服务基类
*
* @export
* @class CalendarServiceBase
* @extends {MdServiceBase}
*/
export class CalendarServiceBase extends MdServiceBase {
/**
* 事件配置集合
*
* @protected
* @type {any[]}
* @memberof CalendarServiceBase
*/
protected eventsConfig: any = {};
/**
* 加载实体数据集
*
* @protected
* @param {string} action
* @param {*} context
* @param {*} data
* @param {string} calendarItem
* @param {string} [serviceName]
* @returns {Promise<any[]>}
* @memberof CalendarServiceBase
*/
protected async loadDEDataSet(action: string, context: any, data: any, calendarItem: string, serviceName?: string): Promise<any[]> {
if (serviceName) {
const service: any = await this.getService(serviceName);
const response: HttpResponse = await service[action](context, data);
if (response.isError()) {
return Promise.reject(response);
}
return this.formatItem(response, calendarItem);
}
const response: HttpResponse = await this.service[action](context, data);
if (response.isError()) {
return Promise.reject(response);
}
return this.formatItem(response, calendarItem);
}
/**
* 格式化数据项
*
* @protected
* @param {*} response
* @param {string} type
* @returns {any[]}
* @memberof CalendarServiceBase
*/
protected formatItem(response: any, type: string): any[] {
if (response.data) {
response.data.forEach((item: any) => {
item.color = this.eventsConfig[type].color;
item.textColor = this.eventsConfig[type].textColor;
item.itemType = this.eventsConfig[type].itemType;
});
}
this.model.itemType = this.eventsConfig[type].itemType;
response = this.handleResponse(type, response);
return response.data.records;
}
/**
* 处理response
*
* @param {string} action
* @param {*} response
* @memberof CalendarServiceBase
*/
public handleResponse(action: string, response: any): any {
return new HttpResponse(response.status, this.handleResponseData(action, response.data));
}
}
\ No newline at end of file
import { MdServiceBase } from './md-service-base';
/**
* 表格部件服务基类
*
* @export
* @class ChartServiceBase
* @extends {ControlServiceBase}
*/
export class ChartServiceBase extends MdServiceBase {
}
\ No newline at end of file
import { appEntityServiceConstructor } from '@/app-core/service/app-entity-service-constructor';
import { Util, Http, Loading, HttpResponse } from '../utils';
import { CodeListService } from '@/app-core/service/app/code-list-service';
/**
* 部件服务基类
*
* @export
* @class ControlServiceBase
*/
export class ControlServiceBase {
/**
* 部件模型
*
* @protected
* @type {*}
* @memberof ControlServiceBase
*/
protected model: any = null;
/**
* 是否正在加载状态
*
* @protected
* @type {boolean}
* @memberof ControlServiceBase
*/
protected $isLoading: boolean = false;
public get isLoading(): boolean {
return this.$isLoading;
}
/**
* 应用实体名称
*
* @protected
* @type {string}
* @memberof ControlServiceBase
*/
protected appDEName: string = '';
/**
* 当前应用实体主键标识
*
* @protected
* @type {string}
* @memberof ControlServiceBase
*/
protected appDeKey: string = '';
/**
* 是否为从数据临时模式
*
* @protected
* @type {boolean}
* @memberof ControlServiceBase
*/
protected isTempMode: boolean = false;
/**
* 部件应用实体服务
*
* @protected
* @type {*}
* @memberof ControlServiceBase
*/
protected service: any;
/**
* 代码表服务
*
* @protected
* @type {CodeListService}
* @memberof ControlServiceBase
*/
protected codeListService: CodeListService = CodeListService.getInstance();
/**
* 请求服务对象
*
* @protected
* @type {Http}
* @memberof ControlServiceBase
*/
protected http: Http = Http.getInstance();
/**
* 获取实体服务
*
* @protected
* @param {string} entityName
* @returns {Promise<any>}
* @memberof ControlServiceBase
*/
protected getService(entityName: string): Promise<any> {
return appEntityServiceConstructor.getService(entityName);
}
/**
* 行为处理之前
*
* @protected
* @param {string} [action]
* @param {*} [context={}]
* @param {*} [data={}]
* @param {boolean} [isLoading=true]
* @returns {Promise<any>}
* @memberof ControlServiceBase
*/
protected async onBeforeAction(action?: string, context: any = {}, data: any = {}, isLoading: boolean = true): Promise<any> {
if (isLoading) {
this.showLoading();
}
if (!this.service) {
this.service = await this.getService(this.appDEName);
}
this.beforeAction(action, context, data);
}
/**
* 行为处理之前
*
* @protected
* @param {string} [action]
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<any>}
* @memberof ControlServiceBase
*/
protected async beforeAction(action?: string, context: any = {}, data: any = {}): Promise<any> { }
/**
* 行为处理之后
*
* @protected
* @param {string} [action]
* @param {*} [context={}]
* @param {*} [response]
* @returns {Promise<any>}
* @memberof ControlServiceBase
*/
protected async onAfterAction(action?: string, context: any = {}, response?: any): Promise<any> {
this.hiddenLoading();
this.afterAction(action, context, response);
}
/**
* 行为处理之后
*
* @protected
* @param {string} [action]
* @param {*} [context={}]
* @param {*} [response]
* @returns {Promise<any>}
* @memberof ControlServiceBase
*/
protected async afterAction(action?: string, context: any = {}, response?: any): Promise<any> { }
/**
* 添加数据
*
* @param {string} action
* @param {*} [context={}]
* @param {*} [data={}]
* @param {boolean} [isLoading]
* @returns {Promise<HttpResponse>}
* @memberof ControlServiceBase
*/
public async add(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data);
let response: HttpResponse;
if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data);
} else {
response = await this.service.Create(context, data);
}
if (!response.isError()) {
response = this.handleResponse(action, response);
}
await this.onAfterAction(action, context, response);
return response;
}
/**
* 删除数据
*
* @param {string} action
* @param {*} [context={}]
* @param {*} [data={}]
* @param {boolean} [isLoading]
* @returns {Promise<HttpResponse>}
* @memberof ControlServiceBase
*/
public async delete(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data);
let response: HttpResponse;
if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data);
} else {
response = await this.service.Remove(context, data);
}
if (!response.isError()) {
response = this.handleResponse(action, response);
}
await this.onAfterAction(action, context, response);
return response;
}
/**
* 修改数据
*
* @param {string} action
* @param {*} [context={}]
* @param {*} [data={}]
* @param {boolean} [isLoading]
* @returns {Promise<HttpResponse>}
* @memberof ControlServiceBase
*/
public async update(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data);
let response: HttpResponse;
if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data);
} else {
response = await this.service.Update(context, data);
}
if (!response.isError()) {
response = this.handleResponse(action, response);
}
await this.onAfterAction(action, context, response);
return response;
}
/**
* 查询数据
*
* @param {string} action
* @param {*} [context={}]
* @param {*} [data={}]
* @param {boolean} [isLoading]
* @returns {Promise<HttpResponse>}
* @memberof ControlServiceBase
*/
public async get(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data);
let response: HttpResponse;
if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data);
} else {
response = await this.service.Get(context, data);
}
if (!response.isError()) {
response = this.handleResponse(action, response);
}
await this.onAfterAction(action, context, response);
return response;
}
/**
* 加载草稿
*
* @param {string} action
* @param {*} [context={}]
* @param {*} [data={}]
* @param {boolean} [isLoading]
* @returns {Promise<HttpResponse>}
* @memberof ControlServiceBase
*/
public async loadDraft(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data);
//仿真主键数据
data[this.appDeKey] = Util.createUUID();
let response: HttpResponse;
if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data);
} else {
response = await this.service.GetDraft(context, data);
}
if (!response.isError()) {
response = this.handleResponse(action, response, true);
this.mergeDefaults(response);
}
await this.onAfterAction(action, context, response);
return response;
}
/**
* 前台逻辑
* @param {string} action
* @param {*} [context={}]
* @param {*} [data={}]
* @param {boolean} [isLoading]
* @returns {Promise<HttpResponse>}
* @memberof EditServiceBase
*/
public async frontLogic(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data);
let response: HttpResponse;
if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data);
} else {
response = new HttpResponse(200, null, { code: 100, message: `${action}前台逻辑未实现` });
}
if (!response.isError()) {
response = this.handleResponse(action, response, true);
}
await this.onAfterAction(action, context, response);
return response;
}
/**
* 处理请求数据
*
* @protected
* @param {string} action 行为
* @param {*} [context={}] 上下文参数
* @param {*} [data={}] 数据
* @returns {*}
* @memberof ControlServiceBase
*/
protected handleRequestData(action: string, context: any = {}, data: any = {}): any {
if (!this.model || !Util.isFunction(this.model.getDataItems)) {
return data;
}
if (context && context.srfsessionid) {
context.srfsessionkey = context.srfsessionid;
delete context.srfsessionid;
}
const dataItems: any[] = this.model.getDataItems();
const requestData: any = {};
dataItems.forEach((item: any) => {
if (item && item.dataType && Object.is(item.dataType, 'FONTKEY')) {
if (item && item.prop) {
requestData[item.prop] = context[item.name];
}
} else {
if (item && item.prop) {
requestData[item.prop] = data[item.name];
}
}
});
return requestData;
}
/**
* 处理response
*
* @param {string} action
* @param {*} response
* @memberof ControlService
*/
public handleResponse(action: string, response: any, isCreate: boolean = false): any {
return new HttpResponse(response.status, this.handleResponseData(action, response.data, isCreate))
}
/**
* 处理返回数据
*
* @param {string} action
* @param {*} response
* @memberof ControlService
*/
public handleResponseData(action: string, data: any = {}, isCreate?: boolean): any {
return data;
}
/**
* 只处理界面主键与应用实体主键之间的转化
*
* @param {*} data 传入数据
* @returns {*}
* @memberof ControlServiceBase
*/
public handleDataWithKey(data: any): any {
if (!this.model && Util.isFunction(this.model.getDataItems)) {
return data;
}
const dataItems: any[] = this.model.getDataItems();
dataItems.forEach((item: any) => {
if (item.dataType && Object.is(item.dataType, 'FONTKEY')) {
data[item.prop] = data[item.name];
delete data[item.name];
}
});
}
/**
* 合并配置的默认值
*
* @protected
* @param {*} [response={}]
* @memberof EditServiceBase
*/
protected mergeDefaults(response: any = {}): void { }
/**
* 开启加载动画
*
* @protected
* @returns {Promise<any>}
* @memberof ControlServiceBase
*/
protected async showLoading(): Promise<any> {
if (this.$isLoading === false) {
this.$isLoading = true;
Loading.show();
}
}
/**
* 结束加载动画
*
* @protected
* @returns {Promise<any>}
* @memberof ControlServiceBase
*/
protected async hiddenLoading(): Promise<any> {
if (this.$isLoading === true) {
Loading.hidden();
this.$isLoading = false;
}
}
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
/**
* 数据看板部件服务基类
*
* @export
* @class DashboardServiceBase
* @extends {ControlServiceBase}
*/
export class DashboardServiceBase extends ControlServiceBase {
}
\ No newline at end of file
import { Util, HttpResponse } from '../utils';
import { ControlServiceBase } from './control-service-base';
/**
* 数据视图部件服务基类
*
* @export
* @class DataViewServiceBase
* @extends {ControlServiceBase}
*/
export class DataViewServiceBase extends ControlServiceBase {
/**
* 查询数据
*
* @param {string} action
* @param {*} [context={}]
* @param {*} [data={}]
* @param {boolean} [isLoading]
* @returns {Promise<HttpResponse>}
* @memberof DataViewServiceBase
*/
public async search(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data);
let response: HttpResponse;
if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data);
} else {
response = await this.service.FetchDefault(context, data);
}
if (!response.isError()) {
response = this.handleResponse(action, response);
}
await this.onAfterAction(action, context, response);
return response;
}
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
/**
* 数据关系分页部件服务基类
*
* @export
* @class DrBarServiceBase
* @extends {ControlServiceBase}
*/
export class DrBarServiceBase extends ControlServiceBase {
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
/**
* 数据关系分页部件服务基类
*
* @export
* @class DrTabServiceBase
* @extends {ControlServiceBase}
*/
export class DrTabServiceBase extends ControlServiceBase {
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
import { HttpResponse, Util } from '../utils';
/**
* 表单部件服务基类
*
* @export
* @class FormServiceBase
* @extends {ControlServiceBase}
*/
export class FormServiceBase extends ControlServiceBase {
/**
* 处理数据
*
* @protected
* @param {HttpResponse} res
* @returns {Promise<any[]>}
* @memberof GridServiceBase
*/
protected async doItems(res: HttpResponse): Promise<any[]> {
if (res.status === 200) {
return [res.data];
}
return [];
}
/**
* 启动工作流
*
* @param {string} action
* @param {*} [context={}]
* @param {*} [data={}]
* @param {boolean} [isLoading]
* @returns {Promise<HttpResponse>}
* @memberof FormServiceBase
*/
public async wfstart(action: string, context: any = {}, data: any = {}, isLoading: boolean): Promise<HttpResponse> {
await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data);
let response: HttpResponse;
if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data);
} else {
response = await this.service.Create(context, data);
}
if (!response.isError()) {
response = this.handleResponse(action, response);
}
await this.onAfterAction(action, context, response);
return response;
}
/**
* 提交工作流
*
* @param {string} action
* @param {*} [context={}]
* @param {*} [data={}]
* @param {boolean} [isLoading]
* @returns {Promise<HttpResponse>}
* @memberof FormServiceBase
*/
public async wfsubmit(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data);
let response: HttpResponse;
if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data);
} else {
response = await this.service.Create(context, data);
}
if (!response.isError()) {
response = this.handleResponse(action, response);
}
await this.onAfterAction(action, context, response);
return response;
}
/**
* 处理返回数据
*
* @param {string} action
* @param {*} [data={}]
* @param {boolean} [isCreate]
* @returns {*}
* @memberof FormServiceBase
*/
public handleResponseData(action: string, data: any = {}, isCreate?: boolean): any {
if (!this.model || !Util.isFunction(this.model.getDataItems)) {
return data;
}
const item: any = {};
const dataItems: any[] = this.model.getDataItems();
dataItems.forEach(dataitem => {
let val = data.hasOwnProperty(dataitem.prop) ? data[dataitem.prop] : null;
if (!val) {
val = data.hasOwnProperty(dataitem.name) ? data[dataitem.name] : null;
}
if ((isCreate === undefined || isCreate === null) && Object.is(dataitem.dataType, 'GUID') && Object.is(dataitem.name, 'srfkey') && (val && !Object.is(val, ''))) {
isCreate = true;
}
item[dataitem.name] = val;
});
if (isCreate) {
if (!item.srfuf) {
Object.assign(item, { srfuf: '0' });
}
} else {
if (!item.srfuf) {
Object.assign(item, { srfuf: '1' });
}
}
Object.assign(data, item);
return data;
}
}
\ No newline at end of file
import { MdServiceBase } from './md-service-base';
/**
* 表格部件服务基类
*
* @export
* @class GridServiceBase
* @extends {ControlServiceBase}
*/
export class GridServiceBase extends MdServiceBase {
}
\ No newline at end of file
import { MdServiceBase } from './md-service-base';
/**
* 列表部件服务基类
*
* @export
* @class ListServiceBase
* @extends {ControlServiceBase}
*/
export class ListServiceBase extends MdServiceBase {
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
import { Util, HttpResponse } from '../utils';
/**
* 多数据部件服务基类
*
* @export
* @class MdServiceBase
* @extends {ControlServiceBase}
*/
export class MdServiceBase extends ControlServiceBase {
/**
* 查询数据
*
* @param {string} action
* @param {*} [context={}]
* @param {*} [data={}]
* @param {boolean} [isLoading]
* @returns {Promise<HttpResponse>}
* @memberof MdServiceBase
*/
public async search(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data);
let response: HttpResponse;
if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data);
} else {
response = await this.service.FetchDefault(context, data);
}
if (!response.isError()) {
response = this.handleResponse(action, response);
}
await this.onAfterAction(action, context, response);
return response;
}
/**
* 加载草稿
*
* @param {string} action
* @param {*} [context={}]
* @param {*} [data={}]
* @param {boolean} [isLoading]
* @returns {Promise<HttpResponse>}
* @memberof MdServiceBase
*/
public async loadDraft(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
const response: any = await super.loadDraft(action, context, data, isLoading);
// 处理返回数据,补充判断标识
if (response.data) {
Object.assign(response.data, { srfuf: '0' });
}
return response;
}
/**
* 处理response
*
* @param {string} action
* @param {*} response
* @memberof MdServiceBase
*/
public handleResponse(action: string, response: any): any {
const result = {};
if (response.status) {
Object.assign(result, { status: response.status });
}
if (response.headers) {
if (response.headers['x-page']) {
Object.assign(result, { page: Number(response.headers['x-page']) });
}
if (response.headers['x-per-page']) {
Object.assign(result, { size: Number(response.headers['x-per-page']) });
}
if (response.headers['x-total']) {
Object.assign(result, { total: Number(response.headers['x-total']) });
}
}
Object.assign(result, this.handleResponseData(action, response.data));
return new HttpResponse(response.status, result);
}
/**
* 处理数据
*
* @param {string} action 行为名称
* @param {*} [data]
* @returns
* @memberof MdServiceBase
*/
public handleResponseData(action: string, data: any) {
if (!this.model || !Util.isFunction(this.model.getDataItems)) {
return { records: data };
}
const result: any = {};
const dataItems: any[] = this.model.getDataItems();
const tempData: any = data;
if (!tempData) {
Object.assign(result, { records: tempData });
} else if (tempData instanceof Array) {
if (tempData.length > 0) {
tempData.forEach((item: any) => {
dataItems.forEach(dataitem => {
let val = item.hasOwnProperty(dataitem.prop) ? item[dataitem.prop] : null;
if (!val) {
val = item.hasOwnProperty(dataitem.name) ? item[dataitem.name] : null;
}
item[dataitem.name] = val;
});
});
Object.assign(result, { records: tempData });
} else {
Object.assign(result, { records: [] });
}
} else {
dataItems.forEach(dataitem => {
let val = tempData.hasOwnProperty(dataitem.prop) ? tempData[dataitem.prop] : null;
if (!val) {
val = tempData.hasOwnProperty(dataitem.name) ? tempData[dataitem.name] : null;
}
tempData[dataitem.name] = val;
});
Object.assign(result, { records: tempData });
}
return result;
}
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
/**
* 多编辑视图面板部件服务基类
*
* @export
* @class MultiEditViewPanelServiceBase
* @extends {ControlServiceBase}
*/
export class MultiEditViewPanelServiceBase extends ControlServiceBase {
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
/**
* 面板部件服务基类
*
* @export
* @class PanelServiceBase
* @extends {ControlServiceBase}
*/
export class PanelServiceBase extends ControlServiceBase {
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
/**
* 选择视图面板部件服务基类
*
* @export
* @class PickupViewPanelServiceBase
* @extends {ControlServiceBase}
*/
export class PickupViewPanelServiceBase extends ControlServiceBase {
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
/**
* 门户部件服务基类
*
* @export
* @class PortletServiceBase
* @extends {ControlServiceBase}
*/
export class PortletServiceBase extends ControlServiceBase {
}
\ No newline at end of file
import { FormServiceBase } from './form-service-base';
/**
* 搜索表单部件服务基类
*
* @export
* @class SearchFormServiceBase
* @extends {ControlServiceBase}
*/
export class SearchFormServiceBase extends FormServiceBase {
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
/**
* 分页导航部件服务基类
*
* @export
* @class TabExpServiceBase
* @extends {ControlServiceBase}
*/
export class TabExpServiceBase extends ControlServiceBase {
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
/**
*分页视图面板部件服务基类
*
* @export
* @class TabViewPanelServiceBase
* @extends {ControlServiceBase}
*/
export class TabViewPanelServiceBase extends ControlServiceBase {
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
/**
* 树视图导航栏部件服务基类
*
* @export
* @class TreeExpBarServiceBase
* @extends {ControlServiceBase}
*/
export class TreeExpBarServiceBase extends ControlServiceBase {
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
/**
* 树部件服务基类
*
* @export
* @class TreeViewServiceBase
* @extends {ControlServiceBase}
*/
export class TreeViewServiceBase extends ControlServiceBase {
/**
* 默认节点分隔符
*
* @protected
* @type {string}
* @memberof TreeViewServiceBase
*/
protected TREENODE_SEPARATOR: string = ';';
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
/**
* 流程导航栏部件服务基类
*
* @export
* @class WFExpBarServiceBase
* @extends {ControlServiceBase}
*/
export class WFExpBarServiceBase extends ControlServiceBase {
}
\ No newline at end of file
import { ControlServiceBase } from './control-service-base';
import { Util, HttpResponse } from '../utils';
/**
* 向导面板部件服务基类
*
* @export
* @class WizardPanelServiceBase
* @extends {ControlServiceBase}
*/
export class WizardPanelServiceBase extends ControlServiceBase {
/**
* 初始化向导
*
* @param {string} action
* @param {*} [context={}]
* @param {*} [data={}]
* @param {boolean} [isLoading]
* @returns {Promise<HttpResponse>}
* @memberof WizardPanelServiceBase
*/
public async init(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data);
let response: HttpResponse;
if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data);
} else {
response = await this.service.Create(context, data);
}
if (!response.isError()) {
response = this.handleResponse(action, response);
}
await this.onAfterAction(action, context, response);
return response;
}
/**
* 向导结束
*
* @param {string} action
* @param {*} [context={}]
* @param {*} [data={}]
* @param {boolean} [isLoading]
* @returns {Promise<HttpResponse>}
* @memberof WizardPanelServiceBase
*/
public async finish(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data);
let response: HttpResponse;
if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data);
} else {
response = await this.service.Update(context, data);
}
if (!response.isError()) {
response = this.handleResponse(action, response);
}
await this.onAfterAction(action, context, response);
return response;
}
}
\ No newline at end of file
/**
* 计数器服务基类
*
* @export
* @class CounterServiceBase
*/
export class CounterServiceBase {
/**
* 当前计数器数据对象
*
* @memberof CounterServiceBase
*/
public counterData: any = {};
/**
* 定时器实例
*
* @type {*}
* @memberof CounterServiceBase
*/
public timer: any;
/**
* Creates an instance of CounterServiceBase.
* @memberof CounterServiceBase
*/
constructor() {
this.initCounterData();
this.timer = setInterval(() => {
this.fetchCounterData();
}, 60000);
}
/**
* 初始化计数器
*
* @protected
* @memberof CounterServiceBase
*/
protected initCounterData(): void {
this.fetchCounterData();
}
/**
* 查询数据
*
* @protected
* @returns {Promise<any>}
* @memberof CounterServiceBase
*/
protected async fetchCounterData(): Promise<any> {
for (let i: number = 0; i < 10; i++) {
this.counterData['item' + i] = Math.floor(Math.random() * 10);
}
}
/**
* 刷新数据
*
* @protected
* @returns {Promise<any>}
* @memberof CounterServiceBase
*/
protected refreshData(): Promise<any> {
return this.fetchCounterData();
}
/**
* 定时器销毁
*
* @memberof CounterServiceBase
*/
public destroy(): void {
if (this.timer) {
clearInterval(this.timer);
}
}
}
\ No newline at end of file
// 导出实体服务类
export { DBService } from './service/db-service';
export { EntityLogicBase } from './service/entity-logic-base';
export { EntityServiceBase } from './service/entity-service-base';
export { IndexedDBService } from './service/indexeddb-service';
// 导出部件服务
export { ControlServiceBase } from './control-service/control-service-base';
export { FormServiceBase } from './control-service/form-service-base';
export { GridServiceBase } from './control-service/grid-service-base';
export { MdServiceBase } from './control-service/md-service-base';
export { SearchFormServiceBase } from './control-service/search-form-service-base';
export { AppMenuServiceBase } from './control-service/app-menu-service-base';
export { TabExpServiceBase } from './control-service/tab-exp-service-base';
export { DashboardServiceBase } from './control-service/dashboard-service-base';
export { MultiEditViewPanelServiceBase } from './control-service/multi-edit-view-panel-service-base';
export { TabViewPanelServiceBase } from './control-service/tab-view-panel-service-base';
export { ListServiceBase } from './control-service/list-service-base';
export { WFExpBarServiceBase } from './control-service/wf-exp-bar-service-base';
export { PortletServiceBase } from './control-service/portlef-service-base';
export { DrBarServiceBase } from './control-service/dr-bar-service-base';
export { DrTabServiceBase } from './control-service/dr-tab-service-base';
export { TreeExpBarServiceBase } from './control-service/tree-exp-bar-service-base';
export { TreeViewServiceBase } from './control-service/tree-view-service-base';
export { DataViewServiceBase } from './control-service/data-view-service-base';
export { PickupViewPanelServiceBase } from './control-service/pickup-view-panel-service-base';
export { WizardPanelServiceBase } from './control-service/wizard-panel-service-base';
export { CalendarServiceBase } from './control-service/calendar-service-base';
export { ChartServiceBase } from './control-service/chart-service-base';
// 导出界面行为服务类
export { UILogicBase } from './ui-service/ui-logic-base';
export { WFUIActionBase } from './wf-ui-service/wf-ui-action-base';
// 导出代码表服务基类
export { CodeListBase } from './code-list/code-list-base';
// 导出计数器服务基类
export { CounterServiceBase } from './counter/counter-service-base';
// 导出第三方服务
export { ThirdPartyService } from './third-party-service/ThirdPartyService';
// 导入服务
import { appEntityServiceConstructor } from '@/app-core/service/app-entity-service-constructor';
import { counterServiceConstructor } from '@/app-core/counter/counter-service-constructor';
import { AppCommunicationsCenter } from './app-service/message-center/app-communications-center';
// 全局挂载应用实体服务构造器
window['appEntityServiceConstructor'] = appEntityServiceConstructor;
// 全局挂载计数器服务构造器
window['counterServiceConstructor'] = counterServiceConstructor;
// 全局挂载应用通讯中心
window['acc'] = AppCommunicationsCenter.getInstance();
/**
* 注册组件
*/
export const iBizCore = {
install(v: any, opt: any) {
}
};
\ No newline at end of file
import { IndexedDBService } from './indexeddb-service';
/**
* 数据对象基类 前端应用实体存储主键,统一为srfSessionKey
*
* @export
* @class DBService
*/
export class DBService {
/**
* 数据库实例
*
* @protected
* @type {IDBDatabase}
* @memberof DBService
*/
protected db!: IDBDatabase;
/**
* 实体名称
*
* @protected
* @type {string}
* @memberof DBService
*/
protected entityName: string = '';
/**
* 主键标识
*
* @protected
* @type {string}
* @memberof DBService
*/
protected primaryKey: string = 'srfsessionkey';
/**
* Creates an instance of DBService.
* @param {string} entityName
* @memberof DBService
*/
constructor(entityName: string) {
this.entityName = entityName;
this.init();
}
/**
* 初始化
*
* @protected
* @memberof DBService
*/
protected init(): void {
if (IndexedDBService.getInstance().getDB()) {
this.db = IndexedDBService.getInstance().getDB();
} else {
setTimeout(() => this.init(), 10);
}
}
/**
* 新增数据
*
* @param {*} params
* @returns {Promise<boolean>}
* @memberof DBService
*/
public create(params: any): Promise<boolean> {
return new Promise((resolve) => {
try {
const t = this.getTransaction();
const store = this.getStore(t);
store.add(params);
t.oncomplete = (e) => resolve(params);
t.onerror = () => resolve(false);
} catch (error) {
console.error(error);
}
});
}
/**
* 更新数据
*
* @param {*} data
* @returns {Promise<boolean>}
* @memberof DBService
*/
public update(data: any): Promise<boolean> {
return new Promise(async (resolve) => {
try {
const t = this.getTransaction();
const store = this.getStore(t);
const item: any = await this.get(data[this.primaryKey], t, store);
if (item) {
Object.assign(item, data);
}
store.put(item);
t.oncomplete = () => resolve(true);
t.onerror = () => resolve(false);
} catch (error) {
console.error(error);
}
});
}
/**
* 获取数据
*
* @param {string} val
* @returns {Promise<any>}
* @memberof DBService
*/
public get(val: string, t: IDBTransaction = this.getTransaction(), store: IDBObjectStore = this.getStore(t)): Promise<any> {
return new Promise((resolve) => {
try {
// const index = store.index(this.primaryKey);
// request = index.get(val);
const request = store.get(val);
request.onsuccess = (e: any) => resolve(e.target.result);
request.onerror = (e: any) => resolve(e.target.result);
} catch (error) {
console.error(error);
}
});
}
/**
* 根据索引查询数据
*
* @param {string} val 索引属性值
* @param {string} indexName 索引属性
* @param {IDBTransaction} [t=this.getTransaction()]
* @param {IDBObjectStore} [store=this.getStore(t)]
* @returns {Promise<any>}
* @memberof DBService
*/
public getByIndex(val: string, indexName: string, t: IDBTransaction = this.getTransaction(), store: IDBObjectStore = this.getStore(t)): Promise<any> {
return new Promise((resolve) => {
try {
const index = store.index(indexName);
const request = index.get(val);
request.onsuccess = (e: any) => {
const item: any = e.target.result;
resolve(item.data);
}
request.onerror = (e: any) => resolve(e.target.result);
} catch (error) {
console.error(error);
}
});
}
/**
* 删除数据
*
* @param {string} val
* @param {IDBTransaction} [t=this.getTransaction()]
* @param {IDBObjectStore} [store=this.getStore(t)]
* @returns {Promise<boolean>}
* @memberof DBService
*/
public remove(val: string, t: IDBTransaction = this.getTransaction(), store: IDBObjectStore = this.getStore(t)): Promise<boolean> {
return new Promise((resolve) => {
try {
store.delete(val);
t.oncomplete = () => resolve(true);
t.onerror = () => resolve(false);
} catch (error) {
console.error(error);
}
});
}
/**
* 设置数据
*
* @param {*} params
* @returns {Promise<boolean>}
* @memberof DBService
*/
public async set(data: any): Promise<boolean> {
try {
const t = this.getTransaction();
const store = this.getStore(t);
const result: any = await this.get(data[this.primaryKey], t, store);
if (result) {
await this.remove(data[this.primaryKey], t, store);
return this.create(data);
}
return this.create(data);
} catch (error) {
console.error(error);
return false;
}
}
/**
* 获取对应事务存储对象
*
* @protected
* @param {IDBTransaction} transaction
* @returns {IDBObjectStore}
* @memberof DBService
*/
protected getStore(transaction: IDBTransaction): IDBObjectStore {
return transaction.objectStore(this.entityName);
}
/**
* 获取事务
*
* @protected
* @returns {IDBTransaction}
* @memberof DBService
*/
protected getTransaction(): IDBTransaction {
return this.db.transaction(this.entityName, 'readwrite');
}
}
\ No newline at end of file
/**
* 实体逻辑处理基类
*
* @export
* @class EntityLogicBase
*/
export class EntityLogicBase {
/**
* 获取其他实体服务
*
* @protected
* @param {string} name 实体名称
* @returns {Promise<any>}
* @memberof EntityLogicBase
*/
protected getService(name: string): Promise<any> {
return window.appEntityServiceConstructor.getService(name);
}
}
\ No newline at end of file
import { Http, Util, HttpResponse } from '../utils';
import { DBService } from './db-service';
/**
* 实体服务基类
*
* @export
* @class EntityServiceBase
*/
export class EntityServiceBase {
/**
* 实体本地数据库
*
* @protected
* @type {DBService}
* @memberof EntityServiceBase
*/
protected db: DBService;
/**
* http请求工具实例
*
* @protected
* @type {Http}
* @memberof EntityServiceBase
*/
protected http: Http = Http.getInstance();
/**
* 所有从实体
*
* @protected
* @type {*}
* @memberof EntityServiceBase
*/
protected allMinorAppEntity: any = {};
/**
* 当前实体主键标识
*
* @protected
* @type {(string)}
* @memberof EntityServiceBase
*/
protected readonly key: string = '';
/**
* 当前实体名称
*
* @protected
* @type {(string)}
* @memberof EntityServiceBase
*/
protected readonly dePath: string = '';
/**
* 实体名称
*
* @protected
* @type {string}
* @memberof EntityServiceBase
*/
protected readonly deName: string;
/**
* 当前实体主信息标识
*
* @protected
* @type {(string)}
* @memberof EntityServiceBase
*/
protected readonly text: string = '';
/**
* 请求根路径
*
* @protected
* @type {string}
* @memberof EntityServiceBase
*/
protected readonly rootUrl: string = '';
/**
* Creates an instance of EntityServiceBase.
* @param {string} deName
* @memberof EntityServiceBase
*/
constructor(deName: string) {
this.deName = deName;
this.db = new DBService(deName);
}
/**
* 设置从实体本地缓存
*
* @protected
* @param {*} [context={}]
* @param {*} [data]
* @returns {Promise<void>}
* @memberof EntityServiceBase
*/
protected async setMinorLocalCache(context: any = {}, data: any): Promise<void> {
if (data) {
for (const key in this.allMinorAppEntity) {
if (data.hasOwnProperty(key) && this.allMinorAppEntity.hasOwnProperty(key)) {
const config: any = this.allMinorAppEntity[key];
await this.setLocalCache(context, data[key], config.name);
}
}
}
}
/**
* 设置本地缓存
*
* @protected
* @param {*} [context={}]
* @param {*} data
* @param {string} [entityName] 指定实体
* @returns {Promise<boolean>}
* @memberof EntityServiceBase
*/
protected async setLocalCache(context: any = {}, data: any, entityName?: string): Promise<boolean> {
if (data) {
if (entityName) {
const service: EntityServiceBase = await this.getService(entityName);
if (service) {
return service.setLocalCache(context, data);
}
} else {
data = Util.deepCopy(data);
return this.db.set({ srfsessionkey: context.srfsessionkey, data });
}
}
return false;
}
/**
* 获取所有从实体本地缓存数据
*
* @protected
* @param {*} [context={}]
* @returns {Promise<any>}
* @memberof EntityServiceBase
*/
protected async getMinorLocalCache(context: any = {}): Promise<any> {
const data: any = {};
for (const key in this.allMinorAppEntity) {
if (this.allMinorAppEntity.hasOwnProperty(key)) {
const config: any = this.allMinorAppEntity[key];
const results: any[] = await this.getLocalCache(context, config.name);
if (results) {
results.forEach((item: any) => {
if (item.srfuf == 0) {
delete item[this.key];
}
});
}
data[key] = results || [];
}
}
return data;
}
/**
* 获取本地缓存数据
*
* @protected
* @param {*} [context={}]
* @param {string} [entityName] 指定实体
* @returns {Promise<any>}
* @memberof EntityServiceBase
*/
protected async getLocalCache(context: any = {}, entityName?: string): Promise<any> {
if (entityName) {
const service: EntityServiceBase = await this.getService(entityName);
if (service) {
return service.getLocalCache(context);
}
} else {
const item: any = await this.db.get(context.srfsessionkey);
if (item) {
return item.data;
}
}
}
/**
* 删除本地缓存
*
* @protected
* @param {*} [context={}]
* @returns {Promise<boolean>}
* @memberof EntityServiceBase
*/
protected async removeLocalCache(context: any = {}, entityName?: string): Promise<boolean> {
if (entityName) {
const service: EntityServiceBase = await this.getService(entityName);
if (service) {
return service.removeLocalCache(context);
}
} else {
return this.db.remove(context.srfsessionkey);
}
return false;
}
/**
* Select接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async Select(context: any = {}, data: any = {}): Promise<HttpResponse> {
return new HttpResponse(500, null, { code: 100, message: '预置实体行为「Select」未实现' });
}
/**
* SelectTemp接口方法(暂未支持)
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async SelectTemp(context: any = {}, data: any = {}): Promise<HttpResponse> {
if (context.srfsessionkey) {
const result: any[] = await this.getLocalCache(context) || [];
if (result) {
return new HttpResponse(200, result);
}
}
return new HttpResponse(500, null, { code: 5001 });
}
/**
* CreateTemp接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async CreateTemp(context: any = {}, data: any = {}): Promise<HttpResponse> {
if (data && context.srfsessionkey) {
const result: any[] = await this.getLocalCache(context) || [];
data.srfuf = 0;
result.push(data);
if (await this.setLocalCache(context, result)) {
return new HttpResponse(200, data);
}
}
return new HttpResponse(500, null, { code: 5003 });
}
/**
* GetTemp接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async GetTemp(context: any = {}, data: any = {}): Promise<HttpResponse> {
if (context.srfsessionkey) {
const result: any[] = await this.getLocalCache(context) || [];
const self: any = result.find((item: any) => Object.is(item[this.key], context[this.deName]));
if (self) {
return new HttpResponse(200, self);
}
}
return new HttpResponse(500, null, { code: 5001 });
}
/**
* UpdateTemp接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async UpdateTemp(context: any = {}, data: any = {}): Promise<HttpResponse> {
if (context.srfsessionkey) {
const result: any[] = await this.getLocalCache(context) || [];
const num: number = result.findIndex((item: any) => Object.is(item[this.key], data[this.key]));
if (num !== -1) {
result[num] = data;
if (await this.setLocalCache(context, result)) {
return new HttpResponse(200, data);
}
}
}
return new HttpResponse(500, null, { code: 5004 });
}
/**
* RemoveTemp接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async RemoveTemp(context: any = {}, data: any = {}): Promise<HttpResponse> {
if (context.srfsessionkey) {
const result: any[] = await this.getLocalCache(context) || [];
const str: string = context[this.deName];
if (str && !Object.is(str, '')) {
const keys: string[] = str.split(';');
keys.forEach((key: string) => {
const num: number = result.findIndex((item: any) => item[this.key] == key);
if (num !== -1) {
result.splice(num, 1);
}
});
if (await this.setLocalCache(context, result)) {
return new HttpResponse(200, data);
}
}
}
return new HttpResponse(500, null, { code: 5005 });
}
/**
* UpdateTempMajor接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async UpdateTempMajor(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.Update(context, data);
}
/**
* CreateTempMajor接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async CreateTempMajor(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.Create(context, data);
}
/**
* RemoveTempMajor接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async RemoveTempMajor(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.Remove(context, data);
}
/**
* GetDraftTempMajor接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async GetDraftTempMajor(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.GetDraft(context, data);
}
/**
* GetTempMajor接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async GetTempMajor(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.Get(context, data);
}
/**
* FetchTempDefault接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async FetchTempDefault(context: any = {}, data: any = {}): Promise<HttpResponse> {
return new HttpResponse(500, null, { code: 100, message: '预置实体行为「FetchTempDefault」未实现' });
}
/**
* GetDraftTemp接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async GetDraftTemp(context: any = {}, data: any = {}): Promise<HttpResponse> {
const tempData = { srfsessionkey: data.srfsessionkey };
Object.defineProperty(tempData, this.key, {
enumerable: true,
value: data[this.key]
});
Object.assign(data, tempData);
return new HttpResponse(200, data);
}
/**
* Update接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async Update(context: any = {}, data: any = {}): Promise<HttpResponse> {
return new HttpResponse(500, null, { code: 100, message: '预置实体行为「Update」未实现' });
}
/**
* Save接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async Save(context: any = {}, data: any = {}): Promise<HttpResponse> {
return new HttpResponse(500, null, { code: 100, message: '预置实体行为「Save」未实现' });
}
/**
* CheckKey接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async CheckKey(context: any = {}, data: any = {}): Promise<HttpResponse> {
if (context.srfsessionkey) {
const result = await this.getLocalCache(context)
if (result) {
return new HttpResponse(200, true);
}
}
return new HttpResponse(200, false);
}
/**
* GetDraft接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async GetDraft(context: any = {}, data: any = {}): Promise<HttpResponse> {
return new HttpResponse(500, null, { code: 100, message: '预置实体行为「GetDraft」未实现' });
}
/**
* Remove接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async Remove(context: any = {}, data: any = {}): Promise<HttpResponse> {
return new HttpResponse(500, null, { code: 100, message: '预置实体行为「Remove」未实现' });
}
/**
* Get接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async Get(context: any = {}, data: any = {}): Promise<HttpResponse> {
return new HttpResponse(500, null, { code: 100, message: '预置实体行为「Get」未实现' });
}
/**
* Create接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async Create(context: any = {}, data: any = {}): Promise<HttpResponse> {
return new HttpResponse(500, null, { code: 100, message: '预置实体行为「Create」未实现' });
}
/**
* FetchDefault接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async FetchDefault(context: any = {}, data: any = {}): Promise<HttpResponse> {
return new HttpResponse(500, null, { code: 100, message: '预置实体行为「FetchDefault」未实现' });
}
/**
* FilterUpdate接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async FilterUpdate(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.Update(context, data);
}
/**
* FilterSearch接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async FilterSearch(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.FetchDefault(context, data);
}
/**
* FilterGet接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async FilterGet(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.Get(context, data);
}
/**
* FilterCreate接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async FilterCreate(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.Create(context, data);
}
/**
* FilterGetDraft接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async FilterGetDraft(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.GetDraft(context, data);
}
/**
* FilterRemove接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async FilterRemove(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.Remove(context, data);
}
/**
* FilterFetch接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async FilterFetch(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.FetchDefault(context, data);
}
/**
* WFStart接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async WFStart(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.http.post(`/${this.dePath}/wfstart`, { wfdata: data });
}
/**
* WFClose接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async WFClose(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.http.post(`/${this.dePath}/${context[this.key]}/wfclose`, data);
}
/**
* WFMarkRead接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async WFMarkRead(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.http.post(`/${this.dePath}/${context[this.key]}/wfmarkread`, data);
}
/**
* WFGoto接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async WFGoto(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.http.post(`/${this.dePath}/${context[this.key]}/wfgoto`, data);
}
/**
* WFRollback接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async WFRollback(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.http.post(`/${this.dePath}/${context[this.key]}/wfrollback`, data);
}
/**
* WFRestart接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async WFRestart(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.http.post(`/${this.dePath}/${context[this.key]}/wfrestart`, data);
}
/**
* WFReassign接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async WFReassign(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.http.post(`/${this.dePath}/${context[this.key]}/wfreassign`, data);
}
/**
* WFSubmit接口方法
*
* @param {*} [context={}]
* @param {*} [data={}]
* @returns {Promise<HttpResponse>}
* @memberof EntityServiceBase
*/
public async WFSubmit(context: any = {}, data: any = {}): Promise<HttpResponse> {
return this.http.post(`/${this.dePath}/${context[this.key]}/wfsubmit`, data);
}
/**
* 获取其他实体服务
*
* @protected
* @param {string} name 实体名称
* @returns {Promise<any>}
* @memberof EntityServiceBase
*/
protected getService(name: string): Promise<any> {
return window.appEntityServiceConstructor.getService(name);
}
}
\ No newline at end of file
/**
* IndexedDB数据库服务基类
*
* @export
* @class IndexedDBServiceBase
*/
export class IndexedDBServiceBase {
/**
* indexedDB实例
*
* @protected
* @memberof IndexedDBServiceBase
*/
protected iDB!: IDBOpenDBRequest;
/**
* 数据库实例
*
* @protected
* @type {IDBDatabase}
* @memberof IndexedDBServiceBase
*/
protected db!: IDBDatabase;
/**
* 数据库名称
*
* @protected
* @type {string}
* @memberof IndexedDBServiceBase
*/
protected dbName: string = 'AppDatabase';
/**
* 实体配置
*
* @protected
* @type {{ name: string, keyPath: string, indexNames: string[] }[]}
* @memberof IndexedDBServiceBase
*/
protected entityConfigs: { name: string, keyPath: string, indexNames?: string[] }[] = [];
/**
* Creates an instance of IndexedDBServiceBase.
* @memberof IndexedDBServiceBase
*/
protected constructor(version: string) {
this.entityConfigInit();
if (new RegExp(/-[1-9]{1}-/).test(version)) {
version = version.substring(0, 5) + '0' + version.substring(5, version.length);
}
const data = new Date(version);
this.iDB = window.indexedDB.open(this.dbName, data.getTime());
this.iDB.onsuccess = () => this.openSuccess();
this.iDB.onerror = (e: any) => this.openError(e);
this.iDB.onupgradeneeded = (e: any) => {
this.upgradeneeded(e);
}
}
/**
* 实体配置初始化
*
* @protected
* @memberof IndexedDBServiceBase
*/
protected entityConfigInit(): void { }
/**
* 数据库打开成功
*
* @protected
* @param {Event} e
* @memberof IndexedDBServiceBase
*/
protected openSuccess(): void {
this.db = this.iDB.result;
}
/**
* 数据库打开失败
*
* @protected
* @param {Event} e
* @memberof IndexedDBServiceBase
*/
protected openError(e: Event): void {
console.error('indexedDB打开失败', e);
}
/**
* 数据库升级成功
*
* @protected
* @param {Event} e
* @memberof IndexedDBServiceBase
*/
protected upgradeneeded(e: any): void {
const db: IDBDatabase = e.target.result;
this.createObjectStore(db);
}
/**
* 创建表
*
* @protected
* @param {IDBDatabase} db
* @memberof IndexedDBServiceBase
*/
protected createObjectStore(db: IDBDatabase): void {
this.entityConfigs.forEach((item) => {
if (!db.objectStoreNames.contains(item.name)) {
const store = db.createObjectStore(item.name, { keyPath: item.keyPath });
this.createIndex(store);
}
});
}
/**
* 建立索引
*
* @protected
* @param {IDBObjectStore} store
* @memberof IndexedDBServiceBase
*/
protected createIndex(store: IDBObjectStore): void { }
/**
* 删除数据库
*
* @memberof IndexedDBServiceBase
*/
public deleteDB(): void {
indexedDB.deleteDatabase(this.dbName);
}
/**
* 关闭数据库
*
* @memberof IndexedDBServiceBase
*/
public closeDB(): void {
this.db.close();
}
/**
* 获取数据库实例
*
* @returns {IDBDatabase}
* @memberof IndexedDBServiceBase
*/
public getDB(): IDBDatabase {
return this.db;
}
}
\ No newline at end of file
/**
* 应用实体服务
*
* @export
* @class ServiceConstructorBase
*/
export class ServiceConstructorBase {
/**
* 所有实体服务
*
* @protected
* @type {*}
* @memberof ServiceConstructorBase
*/
protected allService: Map<string, () => Promise<any>> = new Map();
/**
* 已加载服务缓存
*
* @protected
* @type {Map<string, any>}
* @memberof ServiceConstructorBase
*/
protected serviceCache: Map<string, any> = new Map();
/**
* Creates an instance of ServiceConstructorBase.
* @memberof ServiceConstructorBase
*/
constructor() {
this.init();
}
/**
* 初始化
*
* @protected
* @memberof ServiceConstructorBase
*/
protected init(): void { }
/**
* 加载服务实体
*
* @protected
* @param {string} serviceName
* @returns {Promise<any>}
* @memberof ServiceConstructorBase
*/
protected async loadService(serviceName: string): Promise<any> {
const service = this.allService.get(serviceName);
if (service) {
return await service();
}
}
/**
* 获取应用实体服务
*
* @param {string} name
* @returns {Promise<any>}
* @memberof ServiceConstructorBase
*/
public async getService(name: string): Promise<any> {
if (this.serviceCache.has(name)) {
return this.serviceCache.get(name);
}
const entityService: any = await this.loadService(name);
if (entityService && entityService.default) {
const instance: any = new entityService.default();
this.serviceCache.set(name, instance);
return instance;
}
}
/**
* 销毁已激活的服务
*
* @param {string} name 服务存储名称
* @memberof ServiceConstructorBase
*/
public destroyService(name: string): void {
if (name && this.allService.has(name)) {
const item: any = this.allService.get(name);
if (item && item.destroy) {
item.destroy();
}
this.allService.delete(name);
}
}
}
\ No newline at end of file
import axios from 'axios';
import * as dd from 'dingtalk-jsapi';
/**
* 钉钉服务
*
* @export
* @class DingTalkService
*/
export class DingTalkService {
/**
* 唯一实例
*
* @private
* @static
* @memberof DingTalkService
*/
private static readonly instance = new DingTalkService();
/**
* 用户信息缓存key
*
* @private
* @type {string}
* @memberof DingTalkService
*/
private readonly infoName: string = "UserInfo";
/**
* 企业corpId
*
* @private
* @type {string}
* @memberof WeChatService
*/
private readonly appId: string = "dingf89eefecd565b89cbc961a6cb783455b";
/**
* 钉钉sdk
*
* @memberof DingTalkService
*/
public readonly dd = dd;
/**
* 钉钉是否已经初始化
*
* @private
* @type {boolean}
* @memberof DingTalkService
*/
private $isInit: boolean = false;
/**
* 是否已经初始化
*
* @type {boolean}
* @memberof DingTalkService
*/
public get isInit(): boolean {
return this.$isInit;
}
/**
* Creates an instance of DingTalkService.
* @memberof DingTalkService
*/
private constructor() {
if (DingTalkService.instance) {
return DingTalkService.instance;
}
const info: string = window.navigator.userAgent.toUpperCase();
if (info.indexOf('DINGTALK') !== -1) {
dd.ready(() => {
this.$isInit = true;
});
dd.error((err: any) => {
alert(`dd加载错误:${JSON.stringify(err)}`);
});
}
}
/**
* 钉钉登录
*
* @returns {Promise<any>} 返回用户信息
* @memberof DingTalkService
*/
public async login(): Promise<any> {
const data = await this.getUserInfo();
if (!data || !data.value || Object.is(data.value, '')) {
// 获取临时登录授权码
const res: { code: string } = await dd.runtime.permission.requestAuthCode({ corpId: this.appId });
if (res && res.code) {
const userInfo = await this.get(`./dingtalk/login?code=${res.code}`);
dd.util.domainStorage.setItem({ name: this.infoName, value: userInfo });
data.value = userInfo;
}
}
return data.value;
}
/**
* 清楚登录用户信息
*
* @memberof DingTalkService
*/
public clearUserInfo(): void {
dd.util.domainStorage.removeItem({ name: this.infoName });
}
/**
* 获取用户信息
*
* @returns {Promise<any>}
* @memberof DingTalkService
*/
public getUserInfo(): Promise<any> {
return dd.util.domainStorage.getItem({ name: this.infoName });
}
/**
* 请求(需要替换为项目)
*
* @private
* @param {string} url
* @returns {Promise<any>}
* @memberof DingTalkService
*/
private async get(url: string): Promise<any> {
return new Promise((resolve) => {
axios.get(url).then((response: any) => {
resolve(response.data);
}).catch((error: any) => {
console.log('请求异常');
});
})
}
/**
* 获取实例
*
* @static
* @returns {DingTalkService}
* @memberof DingTalkService
*/
public static getInstance(): DingTalkService {
return DingTalkService.instance;
}
}
import { DingTalkService } from './DingTalkService';
import { WeChatService } from './WeChatService';
/**
* 第三方服务
*
* @export
* @class ThirdPartyService
*/
export class ThirdPartyService {
/**
* 唯一实例
*
* @private
* @static
* @type {ThirdPartyService}
* @memberof ThirdPartyService
*/
private static readonly instance: ThirdPartyService = new ThirdPartyService();
/**
* 当前搭载平台
*
* @protected
* @type {('WeChat' | 'DingTalk' | null)}
* @memberof ThirdPartyService
*/
protected platform: 'WeChat' | 'DingTalk' | null = null;
/**
* 钉钉服务
*
* @type {DingTalkService}
* @memberof ThirdPartyService
*/
public dd: DingTalkService = DingTalkService.getInstance();
/**
* 企业微信服务
*
* @type {WeChatService}
* @memberof ThirdPartyService
*/
public weChat: WeChatService = WeChatService.getInstance();
/**
* 是否已经初始化
*
* @readonly
* @type {boolean}
* @memberof ThirdPartyService
*/
public get isInit(): boolean {
return this.dd.isInit || this.weChat.isInit;
}
/**
* Creates an instance of ThirdPartyService.
* @memberof ThirdPartyService
*/
private constructor() {
if (ThirdPartyService.instance) {
return ThirdPartyService.instance;
}
const info: string = window.navigator.userAgent.toUpperCase();
if (info.indexOf('DINGTALK') !== -1) {
this.platform = 'DingTalk';
} else if (info.indexOf('WXWORK') !== -1) {
this.platform = 'WeChat';
}
}
/**
* 登录
*
* @returns {Promise<any>}
* @memberof ThirdPartyService
*/
public async login(): Promise<any> {
if (this.isDingTalk()) {
return this.dd.login();
} else if (this.isWeChat()) {
return this.weChat.login();
}
}
/**
* 清楚登录用户信息
*
* @memberof WeChatService
*/
public clearUserInfo(): void {
if (this.isDingTalk()) {
this.dd.clearUserInfo();
} else if (this.isWeChat()) {
this.weChat.clearUserInfo();
}
}
/**
* 获取用户信息
*
* @returns {*}
* @memberof WeChatService
*/
public async getUserInfo(): Promise<any> {
if (this.isDingTalk()) {
return this.dd.getUserInfo();
} else if (this.isWeChat()) {
return this.weChat.getUserInfo();
}
}
/**
* 是否为钉钉平台
*
* @returns {boolean}
* @memberof ThirdPartyService
*/
public isDingTalk(): boolean {
return Object.is(this.platform, 'DingTalk');
}
/**
* 是否为微信平台
*
* @returns {boolean}
* @memberof ThirdPartyService
*/
public isWeChat():boolean {
return Object.is(this.platform, 'WeChat');
}
/**
* 获取实例
*
* @static
* @returns {ThirdPartyService}
* @memberof ThirdPartyService
*/
public static getInstance(): ThirdPartyService {
return ThirdPartyService.instance;
}
}
\ No newline at end of file
import axios from 'axios';
/**
* 惬意微信服务
*
* @export
* @class WeChatService
*/
export class WeChatService {
/**
* 唯一实例
*
* @private
* @static
* @type {WeChatService}
* @memberof WeChatService
*/
private static readonly instance: WeChatService = new WeChatService();
/**
* 用户信息缓存key
*
* @private
* @type {string}
* @memberof WeChatService
*/
private readonly infoName: string = "UserInfo";
/**
* 企业corpId
*
* @private
* @type {string}
* @memberof WeChatService
*/
private readonly appId: string = "ww41b9cbca11ed5dbb";
/**
* 微信SDK
*
* @protected
* @type {*}
* @memberof WeChatService
*/
protected wx: any = null;
/**
* 是否初始化
*
* @protected
* @type {boolean}
* @memberof WeChatService
*/
protected $isInit: boolean = false;
public get isInit(): boolean {
return this.$isInit;
}
/**
* Creates an instance of WeChatService.
* @memberof WeChatService
*/
private constructor() {
if (WeChatService.instance) {
return WeChatService.instance;
}
this.init();
}
/**
* 初始化
*
* @protected
* @returns {Promise<void>}
* @memberof WeChatService
*/
protected async init(): Promise<void> {
const info: string = window.navigator.userAgent.toUpperCase();
if (info.indexOf('WXWORK') !== -1) {
// 企业微信js-sdk相关,暂未用到注释
// const win: any = window;
// this.wx = win.wx;
// if (this.wx) {
// const data: any = await this.get('./wechat/config?url=' + encodeURIComponent(window.location.origin));
// if (data) {
// const config = {
// beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
// debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
// appId: data.appid, // 必填,企业微信的corpID
// timestamp: data.timestamp, // 必填,生成签名的时间戳
// nonceStr: data.nonceStr, // 必填,生成签名的随机串
// signature: data.signature,// 必填,签名,见 附录-JS-SDK使用权限签名算法
// jsApiList: [] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
// }
// this.wx.config(config);
// this.wx.ready(() => {
// this.$isInit = true;
// alert('微信初始化成功');
// });
// this.wx.error((res: any) => {
// // alert('微信信息初始化失败!---' + JSON.stringify(res));
// });
// }
// }
this.$isInit = true;
}
}
/**
* 登录
*
* @returns {Promise<any>}
* @memberof WeChatService
*/
public async login(): Promise<any> {
let userInfo = this.getUserInfo();
if (!userInfo) {
const code = this.getQueryValue1('code');
if (code && !Object.is(code, '')) {
const res = await this.get(`./wechat/login?code=${code}`);
if (res) {
window.localStorage.setItem(this.infoName, res);
userInfo = res;
}
} else {
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.appId}&redirect_uri=${encodeURIComponent(window.location.href)}&response_type=code&scope=snsapi_base&state==#wechat_redirect`;
}
}
return userInfo;
}
/**
* 清楚登录用户信息
*
* @memberof WeChatService
*/
public clearUserInfo(): void {
window.localStorage.removeItem(this.infoName);
}
/**
* 获取用户信息
*
* @returns {*}
* @memberof WeChatService
*/
public getUserInfo(): any {
return window.localStorage.getItem(this.infoName);
}
/**
* 获取url参数
*
* @private
* @param {string} queryName
* @returns
* @memberof WeChatService
*/
private getQueryValue1(queryName: string) {
var reg = new RegExp("(^|&)" + queryName + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return decodeURI(r[2]);
} else {
return null;
}
}
/**
* 请求(需要替换为项目)
*
* @private
* @param {string} url
* @returns {Promise<any>}
* @memberof DingTalkService
*/
private async get(url: string): Promise<any> {
return new Promise((resolve) => {
axios.get(url).then((response: any) => {
resolve(response.data);
}).catch((error: any) => {
console.log('请求异常');
});
})
}
/**
* 获取实例
*
* @static
* @returns {WeChatService}
* @memberof WeChatService
*/
public static getInstance(): WeChatService {
return WeChatService.instance;
}
}
\ No newline at end of file
import { AppEntityServiceConstructor } from '@/app-core/service/app-entity-service-constructor';
import { CounterServiceConstructor } from '@/app-core/counter/counter-service-constructor';
import { AppCommunicationsCenter } from '../app-service/message-center/app-communications-center';
declare global {
interface Window {
appEntityServiceConstructor: AppEntityServiceConstructor,
counterServiceConstructor: CounterServiceConstructor,
acc: AppCommunicationsCenter
}
}
\ No newline at end of file
/**
* 界面逻辑处理服务基类
*
* @export
* @class UILogicBase
*/
export class UILogicBase {
}
\ No newline at end of file
import Vue from 'vue';
const isServer = Vue.prototype.$isServer;
/* istanbul ignore next */
export const on = (function() {
if (!isServer && document.addEventListener) {
return function(element: any, event: any, handler: any) {
if (element && event && handler) {
element.addEventListener(event, handler, false);
}
};
} else {
return function(element: any, event: any, handler: any) {
if (element && event && handler) {
element.attachEvent('on' + event, handler);
}
};
}
})();
/* istanbul ignore next */
export const off = (function() {
if (!isServer && document.removeEventListener) {
return function(element: any, event: any, handler: any) {
if (element && event) {
element.removeEventListener(event, handler, false);
}
};
} else {
return function(element: any, event: any, handler: any) {
if (element && event) {
element.detachEvent('on' + event, handler);
}
};
}
})();
/* istanbul ignore next */
export function hasClass(el: Element | HTMLElement, cls: string) {
if (!el || !cls) return false;
if (cls.indexOf(' ') !== -1) throw new Error('className should not contain space.');
if (el.classList) {
return el.classList.contains(cls);
} else {
return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1;
}
}
/* istanbul ignore next */
export function addClass(el: Element | HTMLElement, cls: string) {
if (!el) return;
let curClass = el.className;
const classes = (cls || '').split(' ');
for (let i = 0, j = classes.length; i < j; i++) {
const clsName = classes[i];
if (!clsName) continue;
if (el.classList) {
el.classList.add(clsName);
} else {
if (!hasClass(el, clsName)) {
curClass += ' ' + clsName;
}
}
}
if (!el.classList) {
el.className = curClass;
}
}
/* istanbul ignore next */
export function removeClass(el: Element | HTMLElement, cls: string) {
if (!el || !cls) return;
const classes = cls.split(' ');
let curClass = ' ' + el.className + ' ';
for (let i = 0, j = classes.length; i < j; i++) {
const clsName = classes[i];
if (!clsName) continue;
if (el.classList) {
el.classList.remove(clsName);
} else {
if (hasClass(el, clsName)) {
curClass = curClass.replace(' ' + clsName + ' ', ' ');
}
}
}
if (!el.classList) {
el.className = trim(curClass);
}
}
/* istanbul ignore next */
const trim = function(str: string) {
return (str || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, '');
};
\ No newline at end of file
/**
* Http请求状态文本信息
*/
export const StatusMessage = {
200: '服务器成功返回请求的数据。',
201: '新建或修改数据成功。',
202: '一个请求已经进入后台排队(异步任务)。',
204: '删除数据成功。',
400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
401: '用户没有权限(令牌、用户名、密码错误)。',
403: '用户得到授权,但是访问是被禁止的。',
404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
406: '请求的格式不可得。',
410: '请求的资源被永久删除,且不会再得到的。',
422: '当创建一个对象时,发生一个验证错误。',
500: '服务器发生错误,请检查服务器。',
502: '网关错误。',
503: '服务不可用,服务器暂时过载或维护。',
504: '网关超时。',
};
/**
* 请求错误状态码文本
*/
export const ErrorMessage = {
100: '未知',
101: '请求发生错误',
5001: '数据不存在',
5002: '数据已存在,无法重复创建',
5003: '新建失败',
5004: '数据不存在,无法保存',
5005: '数据删除失败'
};
\ No newline at end of file
import { StatusMessage, ErrorMessage } from "./http-constant";
/**
* Http请求返回
*
* @export
* @class HttpResponse
*/
export class HttpResponse {
/**
* 状态
*
* @type {(200 | 201 | 202 | 204 | 400 | 401 | 403 | 404 | 406 | 410 | 422 | 500 | 502 | 503 | 504)}
* @memberof HttpResponse
*/
public readonly status: 200 | 201 | 202 | 204 | 400 | 401 | 403 | 404 | 406 | 410 | 422 | 500 | 502 | 503 | 504;
/**
* 请求头
*
* @type {*}
* @memberof HttpResponse
*/
public readonly headers: any;
/**
* 状态码对应文本消息
*
* @protected
* @static
* @memberof HttpResponse
*/
protected static readonly statusMessage: any = StatusMessage;
/**
* 数据
*
* @type {*}
* @memberof HttpResponse
*/
public readonly data?: any;
/**
* 错误内容
*
* @type {{ code: HttpResponse['$errorCode'], message?: string }}
* @memberof HttpResponse
*/
public readonly error?: { code: HttpResponse['$errorCode'], message?: string } | null = null;
/**
* 错误码
*
* @protected
* @type {(-1 | 100 | 101 | 5001 | 5002 | 5003 | 5004 | 5005)} 100为通用错误码,需自定义错误消息内容。101为http请求通用错误码。
* @memberof HttpResponse
*/
protected $errorCode: -1 | 100 | 101 | 5001 | 5002 | 5003 | 5004 | 5005 = -1;
/**
* 错误状态码对应信息
*
* @protected
* @static
* @memberof HttpResponse
*/
protected static readonly errorMessage: any = ErrorMessage;
/**
* Creates an instance of HttpResponse.
* @param {HttpResponse['status']} status
* @param {HttpResponse['data']} [data=null]
* @param {HttpResponse['error']} [error=null]
* @param {*} [headers]
* @memberof HttpResponse
*/
constructor(status: HttpResponse['status'], data: HttpResponse['data'] = null, error: HttpResponse['error'] = null, headers?: any) {
this.status = status;
this.data = data;
this.error = error;
if (!this.error && this.status !== 200 && this.status !== 201 && this.status !== 204) {
this.error = { code: 101 };
}
if (this.error && !this.error.message) {
if (this.error.code === 101) {
this.error.message = HttpResponse.getStatusMessage(this.status);
} else {
this.error.message = HttpResponse.getErrorMessage(this.error.code);
}
}
this.headers = headers;
}
/**
* 获取状态码文本值
*
* @param {HttpResponse['$status']} status
* @returns {string}
* @memberof HttpResponse
*/
public static getStatusMessage(status: HttpResponse['status']): string {
return this.statusMessage[status];
}
/**
* 获取错误码文本值
*
* @param {HttpResponse['$errorCode']} code
* @returns {string}
* @memberof HttpResponse
*/
public static getErrorMessage(code: HttpResponse['$errorCode']): string {
return this.errorMessage[code];
}
/**
* 是否错误
*
* @returns {boolean}
* @memberof HttpResponse
*/
public isError(): boolean {
return this.error ? true : false;
}
}
\ No newline at end of file
import axios, { AxiosResponse } from 'axios';
import qs from 'qs';
import { HttpResponse } from './http-response';
import { Util } from '../util/util';
/**
* Http net 对象
* 调用 getInstance() 获取实例
*
* @class Http
*/
export class Http {
/**
* 唯一实例
*
* @private
* @static
* @type {Http}
* @memberof Http
*/
private static readonly instance: Http = new Http();
/**
* Creates an instance of Http.
* 私有构造,拒绝通过 new 创建对象
*
* @memberof Http
*/
constructor() {
if (Http.instance) {
return Http.instance;
}
}
/**
* 获取
*
* @param {string} url
* @param {*} [params]
* @returns {Promise<any>}
* @memberof Http
*/
public get(url: string, params?: any): Promise<any> {
if (params) {
params = this.handleRequestData(params);
if ((Object.keys(params)).length > 0) {
let tempParam: any = {};
let sort: any = null;
Object.keys(params).forEach((item: any) => {
if (params[item] || Object.is(params[item], 0)) {
if (Object.is(item, 'sort')) {
sort = params[item];
} else {
tempParam[item] = params[item];
}
}
})
url += `?${qs.stringify(tempParam)}`;
if (sort) {
url += '&sort=' + sort;
}
}
}
return new Promise((resolve: any, reject: any) => {
axios.get(url).then((response: AxiosResponse) => {
resolve(this.handelResponseResult(response));
}).catch((response: AxiosResponse) => {
reject(this.handelResponseResult(response));
});
});
}
/**
* 删除
*
* @param {string} url
* @returns {Promise<any>}
* @memberof Http
*/
public delete(url: string): Promise<any> {
return new Promise((resolve: any, reject: any) => {
axios.delete(url).then((response: AxiosResponse) => {
resolve(this.handelResponseResult(response));
}).catch((response: AxiosResponse) => {
reject(this.handelResponseResult(response));
});
});
}
/**
*
*
* @param {string} url
* @returns {Promise<any>}
* @memberof Http
*/
public head(url: string): Promise<any> {
return new Promise((resolve: any, reject: any) => {
axios.head(url).then((response: AxiosResponse) => {
resolve(this.handelResponseResult(response));
}).catch((response: AxiosResponse) => {
reject(this.handelResponseResult(response));
});
});
}
/**
*
*
* @param {string} url
* @returns {Promise<any>}
* @memberof Http
*/
public options(url: string): Promise<any> {
return new Promise((resolve: any, reject: any) => {
axios.options(url).then((response: AxiosResponse) => {
resolve(this.handelResponseResult(response));
}).catch((response: AxiosResponse) => {
reject(this.handelResponseResult(response));
});
});
}
/**
* post请求
*
* @param {string} url
* @param {*} [data]
* @returns {Promise<any>}
* @memberof Http
*/
public post(url: string, data?: any): Promise<any> {
if (data) {
data = this.handleRequestData(data);
}
return new Promise((resolve: any, reject: any) => {
axios.post(url,
data,
{ headers: { 'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json' } }
).then((response: AxiosResponse) => {
resolve(this.handelResponseResult(response));
}).catch((response: AxiosResponse) => {
reject(this.handelResponseResult(response));
});
});
}
/**
* 修改数据
*
* @param {string} url
* @param {*} data
* @returns {Promise<any>}
* @memberof Http
*/
public put(url: string, data: any): Promise<any> {
if (data) {
data = this.handleRequestData(data);
}
return new Promise((resolve: any, reject: any) => {
axios.put(url, data).then((response: AxiosResponse) => {
resolve(this.handelResponseResult(response));
}).catch((response: AxiosResponse) => {
reject(this.handelResponseResult(response));
});
});
}
/**
* 修改数据
*
* @param {string} url
* @param {*} data
* @returns {Promise<any>}
* @memberof Http
*/
public patch(url: string, data: any): Promise<any> {
if (data) {
data = this.handleRequestData(data);
}
return new Promise((resolve: any, reject: any) => {
axios.patch(url, data).then((response: AxiosResponse) => {
resolve(this.handelResponseResult(response));
}).catch((response: AxiosResponse) => {
reject(this.handelResponseResult(response));
});
});
}
/**
* 处理响应结果
*
* @private
* @param {*} response
* @memberof Http
*/
private handelResponseResult(response: any): HttpResponse {
if (response) {
if (response.status === 200) {
return new HttpResponse(200, response.data, undefined, response.headers);
}
return new HttpResponse(response.status, response.data, { code: 101, message: HttpResponse.getStatusMessage(response.status) }, response.headers)
}
return new HttpResponse(500, null, { code: 100, message: '请求发生异常,无返回结果!' }, response.headers);
}
/**
* 处理请求数据
*
* @private
* @param data
* @memberof Http
*/
private handleRequestData(data: any) {
data = Util.deepCopy(data);
if (data.srfsessionkey) {
delete data.srfsessionkey;
}
if (data.srfsessionid) {
delete data.srfsessionid;
}
return data;
}
/**
* 获取 Http 单例对象
*
* @static
* @returns {Http}
* @memberof Http
*/
public static getInstance(): Http {
return this.instance;
}
}
\ No newline at end of file
export { Util } from './util/util';
export { Verify } from './verify/verify';
export { XMLWriter } from './xml-writer/xml-writer';
export { Http } from './http/http';
export { Loading } from './loading/loading';
export { HttpResponse } from './http/http-response';
\ No newline at end of file
/**
* 全局加载动画工具类
*
* @export
* @class Loading
*/
export class Loading {
/**
* 加载个数计数
*
* @protected
* @type {number}
* @memberof DragDesignBase
*/
protected static loadingCount: number = 0;
/**
* 显示加载动画
*
* @static
* @param {string} [message='加载中']
* @memberof Loading
*/
public static show(message: string = '加载中'): void {
if (this.loadingCount === 0) {
console.warn('需自行实现加载动画开启功能');
}
this.loadingCount++;
}
/**
* 隐藏加载动画
*
* @memberof DragDesignBase
*/
public static hidden(): void {
this.loadingCount--;
if (this.loadingCount < 0) {
this.loadingCount = 0;
}
if (this.loadingCount === 0) {
setTimeout(() => {
console.warn('需自行实现加载动画关闭功能');
}, 50);
}
}
}
\ No newline at end of file
/**
* 平台工具类
*
* @export
* @class Util
*/
export class Util {
/**
* 创建 UUID
*
* @static
* @returns {string}
* @memberof Util
*/
public static createUUID(): string {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}
/**
* 创建序列号
*
* @static
* @returns {number}
* @memberof Util
*/
public static createSerialNumber(): number {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000);
}
return s4();
}
/**
* 判断是否为一个函数
*
* @static
* @param {*} func
* @returns {boolean}
* @memberof Util
*/
public static isFunction(func: any): boolean {
return (Object.is(this.typeOf(func), 'function') || Object.is(this.typeOf(func), 'asyncFunction'));
}
/**
*
*
* @static
* @param {*} [o={}]
* @memberof Util
*/
public static processResult(o: any = {}): void {
if (o.url != null && o.url !== '') {
window.location.href = o.url;
}
if (o.code != null && o.code !== '') {
eval(o.code);
}
if (o.downloadurl != null && o.downloadurl !== '') {
const downloadurl = this.parseURL2(o.downloadurl, '');
this.download(downloadurl);
}
}
/**
* 下载文件
*
* @static
* @param {string} url
* @memberof Util
*/
public static download(url: string): void {
window.open(url, '_blank');
}
/**
*
*
* @static
* @param {any} url
* @param {any} params
* @returns {string}
* @memberof Util
*/
public static parseURL2(url: string, params: any): string {
let tmpURL;
if (url.indexOf('../../') !== -1) {
tmpURL = url.substring(url.indexOf('../../') + 6, url.length);
} else if (url.indexOf('/') === 0) {
tmpURL = url.substring(url.indexOf('/') + 1, url.length);
} else {
tmpURL = url;
}
if (params) {
return tmpURL + (url.indexOf('?') === -1 ? '?' : '&');
} else {
return tmpURL;
}
}
/**
* 是否是数字
*
* @param {*} num
* @returns {boolean}
* @memberof Util
*/
public static isNumberNaN(num: any): boolean {
return Number.isNaN(num) || num !== num;
}
/**
* 是否未定义
*
* @static
* @param {*} value
* @returns {boolean}
* @memberof Util
*/
public static isUndefined(value: any): boolean {
return typeof value === 'undefined';
}
/**
* 是否为空
*
* @static
* @param {*} value
* @returns {boolean}
* @memberof Util
*/
public static isEmpty(value: any): boolean {
return this.isUndefined(value) || Object.is(value, '') || value === null || value !== value;
}
/**
* 转换为矩阵参数
*
* @static
* @param {*} obj
* @returns {*}
* @memberof Util
*/
public static formatMatrixStringify(obj: any): any {
let str: string = '';
if (obj && !(obj instanceof Array) && (obj instanceof Object)) {
const keys: string[] = Object.keys(obj);
keys.forEach((key: string) => {
if (!obj[key]) {
return;
}
if (!Object.is(str, '')) {
str += ';';
}
str += `${key}=${obj[key]}`;
});
}
return Object.is(str, '') ? undefined : str;
}
/**
* 准备路由参数
*
* @static
* @param {*} { route: route, sourceNode: sourceNode, targetNode: targetNode, data: data }
* @returns {*}
* @memberof Util
*/
public static prepareRouteParmas({ route: route, sourceNode: sourceNode, targetNode: targetNode, data: data }: any): any {
const params: any = {};
if (!sourceNode || (sourceNode && Object.is(sourceNode, ''))) {
return params;
}
if (!targetNode || (targetNode && Object.is(targetNode, ''))) {
return params;
}
const indexName = route.matched[0].name;
Object.assign(params, { [indexName]: route.params[indexName] });
Object.assign(params, { [targetNode]: this.formatMatrixStringify(data) });
return params;
}
/**
* 获取当前值类型
*
* @static
* @param {*} obj
* @returns
* @memberof Util
*/
public static typeOf(obj: any): string {
const toString = Object.prototype.toString;
const map: any = {
'[object Boolean]': 'boolean',
'[object Number]': 'number',
'[object String]': 'string',
'[object Function]': 'function',
'[object AsyncFunction]': 'asyncFunction',
'[object Array]': 'array',
'[object Date]': 'date',
'[object RegExp]': 'regExp',
'[object Undefined]': 'undefined',
'[object Null]': 'null',
'[object Object]': 'object'
};
return map[toString.call(obj)];
}
/**
* 深拷贝(deepCopy)
*
* @static
* @param {*} data
* @returns {*}
* @memberof Util
*/
public static deepCopy(data: any): any {
const t = this.typeOf(data);
let o: any;
if (t === 'array') {
o = [];
} else if (t === 'object') {
o = {};
} else {
return data;
}
if (t === 'array') {
for (let i = 0; i < data.length; i++) {
o.push(this.deepCopy(data[i]));
}
} else if (t === 'object') {
for (let i in data) {
o[i] = this.deepCopy(data[i]);
}
}
return o;
}
/**
* 名称格式化
*
* @static
* @param {string} name
* @returns {string}
* @memberof Util
*/
public static srfFilePath2(name: string): string {
if (!name || (name && Object.is(name, ''))) {
throw new Error('名称异常');
}
name = name.replace(/[_]/g, '-');
let state: number = 0;
let _str = '';
const uPattern = /^[A-Z]{1}$/;
const str1 = name.substring(0, 1);
const str2 = name.substring(1)
state = uPattern.test(str1) ? 1 : 0;
_str = `${_str}${str1.toLowerCase()}`;
for (let chr of str2) {
if (uPattern.test(chr)) {
if (state === 1) {
_str = `${_str}${chr.toLowerCase()}`;
} else {
_str = `${_str}-${chr.toLowerCase()}`;
}
state = 1
} else {
_str = `${_str}${chr.toLowerCase()}`;
state = 0
}
}
_str = _str.replace(/---/g, '-').replace(/--/g, '-');
return _str;
}
}
\ No newline at end of file
import { Util } from '../util/util';
/**
* 校验对象
*
* @export
* @class Verify
*/
export class Verify {
/**
* 错误提示信息
*
* @static
* @type {string}
* @memberof Verify
*/
public static errorInfo: string = '';
/**
* 值比较
*
* @static
* @param {*} value
* @param {*} value2
* @returns {number}
* @memberof Verify
*/
public static compare(value: any, value2: any): number {
let result: any;
if (!Object.is(value, '') && !Object.is(value2, '') && !isNaN(value) && !isNaN(value2)) {
result = this.compareNumber(parseFloat(value), parseFloat(value2));
} else if (this.isParseDate(value) && this.isParseDate(value2)) {
result = this.compareDate((new Date(value)).getTime(), (new Date(value2)).getTime());
} else if (value && (typeof (value) === 'boolean' || value instanceof Boolean)) {
result = this.compareBoolean(value, value2);
} else if (value && (typeof (value) === 'string' || value instanceof String)) {
result = this.compareString(value, value2);
}
return result;
}
/**
* 字符串比较
*
* @static
* @param {*} value
* @param {*} value2
* @returns {number}
* @memberof Verify
*/
public static compareString(value: any, value2: any): number {
return value.localeCompare(value2);
}
/**
* boolean 值比较
*
* @static
* @param {*} value
* @param {*} value2
* @returns {number}
* @memberof Verify
*/
public static compareBoolean(value: any, value2: any): number {
if (value === value2) {
return 0;
} else {
return -1;
}
}
/**
* 时间值比较(毫秒数)
*
* @static
* @param {number} value
* @param {number} value2
* @returns {number}
* @memberof Verify
*/
public static compareDate(value: number, value2: number): number {
if (value > value2) {
return 1;
} else if (value < value2) {
return -1;
} else {
return 0;
}
}
/**
* 是否是时间
*
* @static
* @param {string} value
* @returns {boolean}
* @memberof Verify
*/
public static isParseDate(value: string): boolean {
const time = new Date(value);
if (isNaN(time.getTime())) {
return false;
}
return true;
}
/**
* 数值比较
*
* @static
* @param {number} value
* @param {number} value2
* @returns {number}
* @memberof Verify
*/
public static compareNumber(value: number, value2: number): number {
if (value > value2) {
return 1;
} else if (value < value2) {
return -1;
} else {
return 0;
}
}
/**
* 文本包含
*
* @static
* @param {*} value
* @param {*} value2
* @returns {boolean}
* @memberof Verify
*/
public static contains(value: any, value2: any): boolean {
if (value && value2) {
// 定义一数组
let arr = new Array();
arr = value2.split(',');
// 定义正则表达式的连接符
const S = String.fromCharCode(2);
const reg = new RegExp(S + value + S);
return (reg.test(S + arr.join(S) + S));
}
return false;
}
/**
* 比较值
*
* @static
* @param {*} value
* @param {*} op
* @param {*} value2
* @returns {boolean}
* @memberof Verify
*/
public static testCond(value: any, op: any, value2: any): boolean {
// 等于操作
if (Object.is(op, 'EQ')) {
const _value = `${value}`;
return _value === value2;
}
// 大于操作
if (Object.is(op, 'GT')) {
const result: number = this.compare(value, value2);
if (result !== undefined && result > 0) {
return true;
} else {
return false;
}
}
// 大于等于操作
if (Object.is(op, 'GTANDEQ')) {
const result: number = this.compare(value, value2);
if (result !== undefined && result >= 0) {
return true;
} else {
return false;
}
}
// 值包含在给定的范围中
if (Object.is(op, 'IN')) {
return this.contains(value, value2);
}
// 不为空判断操作
if (Object.is(op, 'ISNOTNULL')) {
return (value != null && value !== '');
}
// 为空判断操作
if (Object.is(op, 'ISNULL')) {
return (value == null || value === '');
}
// 文本左包含
if (Object.is(op, 'LEFTLIKE')) {
return (value && value2 && (value.toUpperCase().indexOf(value2.toUpperCase()) === 0));
}
// 文本包含
if (Object.is(op, 'LIKE')) {
return (value && value2 && (value.toUpperCase().indexOf(value2.toUpperCase()) !== -1));
}
// 小于操作
if (Object.is(op, 'LT')) {
const result: number = this.compare(value, value2);
if (result !== undefined && result < 0) {
return true;
} else {
return false;
}
}
// 小于等于操作
if (Object.is(op, 'LTANDEQ')) {
const result: number = this.compare(value, value2);
if (result !== undefined && result <= 0) {
return true;
} else {
return false;
}
}
// 不等于操作
if (Object.is(op, 'NOTEQ')) {
const _value = `${value}`;
return _value !== value2;
}
// 值不包含在给定的范围中
if (Object.is(op, 'NOTIN')) {
return !this.contains(value, value2);
}
// 文本右包含
if (Object.is(op, 'RIGHTLIKE')) {
if (!(value && value2)) {
return false;
}
const nPos = value.toUpperCase().indexOf(value2.toUpperCase());
if (nPos === -1) {
return false;
}
return nPos + value2.length === value.length;
}
// 空判断
if (Object.is(op, 'TESTNULL')) {
}
// 自定义包含
if (Object.is(op, 'USERLIKE')) {
}
return false;
}
/**
* 检查属性常规条件
*
* @static
* @param {*} value 属性值
* @param {string} op 检测条件
* @param {*} value2 预定义值
* @param {string} errorInfo 错误信息
* @param {string} paramType 参数类型
* @param {*} form 表单对象
* @param {boolean} primaryModel 是否必须条件
* @returns {boolean}
* @memberof Verify
*/
public static checkFieldSimpleRule(value: any, op: string, value2: any, errorInfo: string, paramType: string, form: any, primaryModel: boolean): boolean {
if (Object.is(paramType, 'CURTIME')) {
value2 = `${new Date()}`;
}
if (Object.is(paramType, 'ENTITYFIELD')) {
value2 = value2 ? value2.toLowerCase() : '';
const _value2Field = form.findFormItem(value2);
if (!_value2Field) {
this.errorInfo = `表单项${value2}未配置`;
return true;
}
value2 = _value2Field.getValue();
}
if (Util.isEmpty(errorInfo)) {
errorInfo = '内容必须符合值规则';
}
this.errorInfo = errorInfo;
const result = this.testCond(value, op, value2);
if (!result) {
if (primaryModel) {
throw new Error(this.errorInfo);
}
}
return !result;
}
/**
* 检查属性字符长度规则
*
* @static
* @param {*} viewValue
* @param {number} minLength
* @param {boolean} indexOfMin
* @param {number} maxLength
* @param {boolean} indexOfMax
* @param {string} errorInfo
* @param {boolean} primaryModel
* @returns {boolean}
* @memberof Verify
*/
public static checkFieldStringLengthRule(viewValue: string, minLength: number, indexOfMin: boolean, maxLength: number, indexOfMax: boolean, errorInfo: string, primaryModel: boolean): boolean {
if (Util.isEmpty(errorInfo)) {
this.errorInfo = '内容长度必须符合范围规则';
} else {
this.errorInfo = errorInfo;
}
const isEmpty = Util.isEmpty(viewValue);
if (isEmpty) {
if (primaryModel) {
throw new Error('值为空');
}
this.errorInfo = '值为空';
return true;
}
const viewValueLength: number = viewValue.length;
// 小于等于
if (minLength !== null) {
if (indexOfMin) {
if (viewValueLength < minLength) {
if (primaryModel) {
throw new Error(this.errorInfo);
}
return true;
}
} else {
if (viewValueLength <= minLength) {
if (primaryModel) {
throw new Error(this.errorInfo);
}
return true;
}
}
}
// 大于等于
if (maxLength !== null) {
if (indexOfMax) {
if (viewValueLength > maxLength) {
if (primaryModel) {
throw new Error(this.errorInfo);
}
return true;
}
} else {
if (viewValueLength >= maxLength) {
if (primaryModel) {
throw new Error(this.errorInfo);
}
return true;
}
}
}
this.errorInfo = '';
return false;
}
/**
* 检查属性值正则式规则
*
* @static
* @param {string} viewValue 属性值
* @param {*} strReg 验证正则
* @param {string} errorInfo 错误信息
* @param {boolean} primaryModel 是否关键条件
* @returns {boolean}
* @memberof Verify
*/
public static checkFieldRegExRule(viewValue: string, strReg: any, errorInfo: string, primaryModel: boolean): boolean {
if (Util.isEmpty(errorInfo)) {
this.errorInfo = '值必须符合正则规则';
} else {
this.errorInfo = errorInfo;
}
const isEmpty = Util.isEmpty(viewValue);
if (isEmpty) {
if (primaryModel) {
throw new Error('值为空');
}
this.errorInfo = '值为空';
return true;
}
const regExp = new RegExp(strReg);
if (!regExp.test(viewValue)) {
if (primaryModel) {
throw new Error(this.errorInfo);
}
return true;
}
this.errorInfo = '';
return false;
}
/**
* 检查属性值范围规则
*
* @static
* @param {string} viewValue 属性值
* @param {*} minNumber 最小数值
* @param {boolean} indexOfMin 是否包含最小数值
* @param {*} maxNumber 最大数值
* @param {boolean} indexOfMax 是否包含最大数值
* @param {string} errorInfo 错误信息
* @param {boolean} primaryModel 是否关键条件
* @returns {boolean}
* @memberof Verify
*/
public static checkFieldValueRangeRule(viewValue: string, minNumber: any, indexOfMin: boolean, maxNumber: any, indexOfMax: boolean, errorInfo: string, primaryModel: boolean): boolean {
if (Util.isEmpty(errorInfo)) {
this.errorInfo = '值必须符合值范围规则';
} else {
this.errorInfo = errorInfo;
}
const isEmpty = Util.isEmpty(viewValue);
if (isEmpty) {
if (primaryModel) {
throw new Error('值为空');
}
this.errorInfo = '值为空';
return true;
}
const valueFormat = this.checkFieldRegExRule(viewValue, /^-?\d*\.?\d+$/, '', primaryModel);
if (valueFormat) {
return true;
} else {
this.errorInfo = errorInfo;
}
const data = Number.parseFloat(viewValue);
// 小于等于
if (minNumber !== null) {
if (indexOfMin) {
if (data < minNumber) {
if (primaryModel) {
throw new Error(this.errorInfo);
}
return true;
}
} else {
if (data <= minNumber) {
if (primaryModel) {
throw new Error(this.errorInfo);
}
return true;
}
}
}
// //大于等于
if (maxNumber != null) {
if (indexOfMax) {
if (data > maxNumber) {
if (primaryModel) {
throw new Error(this.errorInfo);
}
return true;
}
} else {
if (data >= maxNumber) {
if (primaryModel) {
throw new Error(this.errorInfo);
}
return true;
}
}
}
this.errorInfo = '';
return false;
}
/**
* 检查属性值系统值范围规则 暂时支持正则表达式
*
* @static
* @param {string} viewValue 属性值
* @param {*} strReg 正则
* @param {string} errorInfo 错误信息
* @param {boolean} primaryModel 是否关键条件
* @returns {boolean}
* @memberof Verify
*/
public static checkFieldSysValueRule(viewValue: string, strReg: any, errorInfo: string, primaryModel: boolean): boolean {
return this.checkFieldRegExRule(viewValue, strReg, errorInfo, primaryModel);
}
}
\ No newline at end of file
/**
* xml工具类
*
* @export
* @class XMLWriter
*/
export class XMLWriter {
public XML: any[] = [];
public nodes: any[] = [];
public State = '';
/**
*
*
* @param {any} Str
* @returns
* @memberof XMLWriter
*/
public formatXML(Str: any) {
if (Str) {
return Str.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '&#xA;').replace(/\r/g, '&#xD;');
}
return '';
}
/**
*
*
* @param {any} Name
* @returns
* @memberof XMLWriter
*/
public beginNode(Name: any) {
if (!Name) {
return;
}
if (this.State === 'beg') {
this.XML.push('>');
}
this.State = 'beg';
this.nodes.push(Name);
this.XML.push('<' + Name);
}
/**
*
*
* @memberof XMLWriter
*/
public endNode() {
if (this.State === 'beg') {
this.XML.push('/>');
this.nodes.pop();
} else if (this.nodes.length > 0) {
this.XML.push('</' + this.nodes.pop() + '>');
}
this.State = '';
}
/**
*
*
* @param {any} Name
* @param {any} Value
* @returns
* @memberof XMLWriter
*/
public attrib(Name: any, Value: any) {
if (this.State !== 'beg' || !Name) {
return;
}
this.XML.push(' ' + Name + '="' + this.formatXML(Value) + '"');
}
/**
*
*
* @param {any} Value
* @memberof XMLWriter
*/
public writeString(Value: any) {
if (this.State === 'beg') {
this.XML.push('>');
}
this.XML.push(this.formatXML(Value));
this.State = '';
}
/**
*
*
* @param {any} Name
* @param {any} Value
* @returns
* @memberof XMLWriter
*/
public node(Name: any, Value: any) {
if (!Name) {
return;
}
if (this.State === 'beg') {
this.XML.push('>');
}
this.XML.push((Value === '' || !Value) ? '<' + Name + '/>' : '<' + Name + '>' + this.formatXML(Value) + '</' + Name + '>');
this.State = '';
}
/**
*
*
* @memberof XMLWriter
*/
public close() {
while (this.nodes.length > 0) {
this.endNode();
}
this.State = 'closed';
}
/**
*
*
* @returns
* @memberof XMLWriter
*/
public toString() { return this.XML.join(''); }
}
\ No newline at end of file
/**
* 工作流界面行为服务基类
*
* @export
* @class WFUIActionBase
*/
export class WFUIActionBase {
}
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册