患者1.2

This commit is contained in:
zoujiandong
2024-01-10 08:57:23 +08:00
parent 49c01e8922
commit 5d865d1bbb
339 changed files with 23720 additions and 267 deletions
@@ -0,0 +1,10 @@
/**
* 装饰器:阻止函数重复调用
* @export
* @param {Object} options 入参
* @param {Function} options.fn 函数
* @param {Object} options.context 上下文对象
* @param {String} options.name 函数名
* @returns {Function} 封装后的函数
*/
export declare function avoidRepeatedCall(): (target: any, name: string, descriptor: any) => any;
@@ -0,0 +1,49 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.avoidRepeatedCall = void 0;
const index_1 = require("../../const/index");
/**
* 装饰器:阻止函数重复调用
* @export
* @param {Object} options 入参
* @param {Function} options.fn 函数
* @param {Object} options.context 上下文对象
* @param {String} options.name 函数名
* @returns {Function} 封装后的函数
*/
function avoidRepeatedCall() {
return function (target, name, descriptor) {
const oldFn = descriptor.value;
const isCallingSet = new Set();
descriptor.value = function (...args) {
return __awaiter(this, void 0, void 0, function* () {
if (isCallingSet.has(this)) {
console.warn((`${index_1.NAME.PREFIX}previous ${name}() is ongoing, please avoid repeated calls`));
// throw new Error(`previous ${name}() is ongoing, please avoid repeated calls`);
return;
}
try {
isCallingSet.add(this);
const result = yield oldFn.apply(this, args);
isCallingSet.delete(this);
return result;
}
catch (error) {
isCallingSet.delete(this);
throw error;
}
});
};
return descriptor;
};
}
exports.avoidRepeatedCall = avoidRepeatedCall;
+4
View File
@@ -0,0 +1,4 @@
import { avoidRepeatedCall } from './avoidRepeatedCall';
import { paramValidate } from './validateParams';
import { VALIDATE_PARAMS } from './validateConfig';
export { VALIDATE_PARAMS, paramValidate, avoidRepeatedCall, };
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.avoidRepeatedCall = exports.paramValidate = exports.VALIDATE_PARAMS = void 0;
const avoidRepeatedCall_1 = require("./avoidRepeatedCall");
Object.defineProperty(exports, "avoidRepeatedCall", { enumerable: true, get: function () { return avoidRepeatedCall_1.avoidRepeatedCall; } });
const validateParams_1 = require("./validateParams");
Object.defineProperty(exports, "paramValidate", { enumerable: true, get: function () { return validateParams_1.paramValidate; } });
const validateConfig_1 = require("./validateConfig");
Object.defineProperty(exports, "VALIDATE_PARAMS", { enumerable: true, get: function () { return validateConfig_1.VALIDATE_PARAMS; } });
@@ -0,0 +1,173 @@
import { VideoResolution, VideoDisplayMode } from "../../const/index";
export declare const VALIDATE_PARAMS: {
init: {
SDKAppID: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
userID: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
userSig: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
tim: {
required: boolean;
rules: any[];
};
};
call: {
userID: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
type: {
required: boolean;
rules: any[];
range: number[];
allowEmpty: boolean;
};
roomID: {
required: boolean;
rules: any[];
range: string;
allowEmpty: boolean;
};
userData: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
timeout: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
};
groupCall: {
userIDList: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
type: {
required: boolean;
rules: any[];
range: number[];
allowEmpty: boolean;
};
groupID: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
roomID: {
required: boolean;
rules: any[];
range: string;
allowEmpty: boolean;
};
timeout: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
userData: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
offlinePushInfo: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
};
joinInGroupCall: {
type: {
required: boolean;
rules: any[];
range: number[];
allowEmpty: boolean;
};
groupID: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
roomID: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
};
inviteUser: {
userIDList: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
};
setSelfInfo: {
nickName: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
avatar: {
required: boolean;
rules: any[];
allowEmpty: boolean;
};
};
enableFloatWindow: {
key: string;
required: boolean;
rules: any[];
allowEmpty: boolean;
}[];
enableAIVoice: {
key: string;
required: boolean;
rules: any[];
allowEmpty: boolean;
}[];
enableMuteMode: {
key: string;
required: boolean;
rules: any[];
allowEmpty: boolean;
}[];
setCallingBell: {
key: string;
required: boolean;
rules: any[];
allowEmpty: boolean;
}[];
setLanguage: {
key: string;
required: boolean;
rules: any[];
allowEmpty: boolean;
}[];
setVideoDisplayMode: {
key: string;
required: boolean;
rules: any[];
range: VideoDisplayMode[];
allowEmpty: boolean;
}[];
setVideoResolution: {
key: string;
required: boolean;
rules: any[];
range: VideoResolution[];
allowEmpty: boolean;
}[];
};
@@ -0,0 +1,190 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VALIDATE_PARAMS = void 0;
const index_1 = require("../../const/index");
exports.VALIDATE_PARAMS = {
init: {
SDKAppID: {
required: true,
rules: [index_1.NAME.NUMBER],
allowEmpty: false,
},
userID: {
required: true,
rules: [index_1.NAME.STRING],
allowEmpty: false,
},
userSig: {
required: true,
rules: [index_1.NAME.STRING],
allowEmpty: false,
},
tim: {
required: false,
rules: [index_1.NAME.OBJECT],
},
},
call: {
userID: {
required: true,
rules: [index_1.NAME.STRING],
allowEmpty: false
},
type: {
required: true,
rules: [index_1.NAME.NUMBER],
range: [1, 2],
allowEmpty: false
},
roomID: {
required: false,
rules: [index_1.NAME.NUMBER],
range: `1~${index_1.MAX_NUMBER_ROOM_ID}`,
allowEmpty: false,
},
userData: {
required: false,
rules: [index_1.NAME.STRING],
allowEmpty: false,
},
timeout: {
required: false,
rules: [index_1.NAME.NUMBER],
allowEmpty: false
}
},
groupCall: {
userIDList: {
required: true,
rules: [index_1.NAME.ARRAY],
allowEmpty: false
},
type: {
required: true,
rules: [index_1.NAME.NUMBER],
range: [1, 2],
allowEmpty: false
},
groupID: {
required: true,
rules: [index_1.NAME.STRING],
allowEmpty: false
},
roomID: {
required: false,
rules: [index_1.NAME.NUMBER],
range: `1~${index_1.MAX_NUMBER_ROOM_ID}`,
allowEmpty: false
},
timeout: {
required: false,
rules: [index_1.NAME.NUMBER],
allowEmpty: false
},
userData: {
required: false,
rules: [index_1.NAME.STRING],
allowEmpty: false,
},
offlinePushInfo: {
required: false,
rules: [index_1.NAME.OBJECT],
allowEmpty: false,
},
},
joinInGroupCall: {
type: {
required: true,
rules: [index_1.NAME.NUMBER],
range: [1, 2],
allowEmpty: false
},
groupID: {
required: true,
rules: [index_1.NAME.STRING],
allowEmpty: false
},
roomID: {
required: true,
rules: [index_1.NAME.NUMBER],
allowEmpty: false,
},
},
inviteUser: {
userIDList: {
required: true,
rules: [index_1.NAME.ARRAY],
allowEmpty: false
},
},
setSelfInfo: {
nickName: {
required: false,
rules: [index_1.NAME.STRING],
allowEmpty: false,
},
avatar: {
required: false,
rules: [index_1.NAME.STRING],
allowEmpty: false,
}
},
enableFloatWindow: [
{
key: "enable",
required: false,
rules: [index_1.NAME.BOOLEAN],
allowEmpty: false,
}
],
enableAIVoice: [
{
key: "enable",
required: true,
rules: [index_1.NAME.BOOLEAN],
allowEmpty: false,
}
],
enableMuteMode: [
{
key: "enable",
required: true,
rules: [index_1.NAME.BOOLEAN],
allowEmpty: false,
}
],
setCallingBell: [
{
key: "filePath",
required: false,
rules: [index_1.NAME.STRING],
allowEmpty: true,
}
],
setLanguage: [
{
key: "language",
required: true,
rules: [index_1.NAME.STRING],
allowEmpty: false
}
],
setVideoDisplayMode: [
{
key: "displayMode",
required: true,
rules: [index_1.NAME.STRING],
range: [index_1.VideoDisplayMode.CONTAIN, index_1.VideoDisplayMode.COVER, index_1.VideoDisplayMode.FILL],
allowEmpty: false
}
],
setVideoResolution: [
{
key: "resolution",
required: true,
rules: [index_1.NAME.STRING],
range: [index_1.VideoResolution.RESOLUTION_1080P, index_1.VideoResolution.RESOLUTION_480P, index_1.VideoResolution.RESOLUTION_720P],
allowEmpty: false
}
]
};
@@ -0,0 +1 @@
export declare function paramValidate(config: any): (target: any, propertyName: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
@@ -0,0 +1,86 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.paramValidate = void 0;
const common_utils_1 = require("../common-utils");
const index_1 = require("../../const/index");
const PREFIX = index_1.NAME.PREFIX + "API";
function paramValidate(config) {
return function (target, propertyName, descriptor) {
let method = descriptor.value;
descriptor.value = function (...args) {
doValidate.call(this, config, args, propertyName);
return method.apply(this, args);
};
return descriptor;
};
}
exports.paramValidate = paramValidate;
function doValidate(config, args, name) {
try {
// 兼容 init 方法中: SDKAppID sdkAppID 两种写法的参数校验判断
if (!args[0].SDKAppID) {
config = (0, common_utils_1.modifyObjectKey)(config, "SDKAppID", "sdkAppID");
}
if ((0, common_utils_1.isArray)(config)) {
for (let i = 0; i < config.length; i++) {
check.call(this, Object.assign(Object.assign({}, config[i]), { value: args[i], name }));
}
}
else {
for (const key in config) {
if (config.hasOwnProperty(key)) {
check.call(this, Object.assign(Object.assign({}, config[key]), { value: args[0][key], name,
key }));
}
}
}
}
catch (error) {
console.error(error);
throw error;
}
}
function check({ required, rules, range, value, allowEmpty, name, key }) {
// 用户没传指定参数
if ((0, common_utils_1.isUndefined)(value)) {
// 检查必填参数, 若配置是必填则报错
if (required) {
throw new Error(`${PREFIX}<${name}>: ${key} is required.`);
}
else {
return;
}
}
// 判断参数类型是否正确
const result = rules.some((item) => item === (0, common_utils_1.getType)(value));
let type = '';
if (!result) {
for (let i = 0; i < rules.length; i++) {
let str = rules[i];
str = str.replace(str[0], str[0].toUpperCase());
type += `${str}/`;
}
type = type.substring(0, type.length - 1);
throw new Error(`${PREFIX}<${name}>: ${key} must be ${type}, current ${key} is ${typeof value}.`);
}
// 不允许传空值, 例如: '', ' '
if (allowEmpty === false) {
const isEmptyString = (0, common_utils_1.isString)(value) && value.trim() === '';
if (isEmptyString) {
throw new Error(`${PREFIX}<${name}>: ${key} is blank.`);
}
}
// 判断是否符合限制条件
if ((0, common_utils_1.isArray)(range)) {
if (range && range.indexOf(value) === -1) {
throw new Error(`${PREFIX}<${name}>: ${key} error, only be ${range}, current ${key} is ${value}.`);
}
}
// 取值范围, 前闭后闭
if ((0, common_utils_1.isString)(range) && range.indexOf('~') !== -1) {
const valueList = range.split('~');
if (value < +valueList[0] || value > +valueList[1] || ((0, common_utils_1.isNumber)(value) && Number.isNaN(value))) {
throw new Error(`${PREFIX}<${name}>: ${key} error, only be ${range}, current ${key} is ${value}.`);
}
}
}