提交 e96ca706 编写于 作者: tony001's avatar tony001

update:更新core内容

上级 299622d4
import { IContext, IParam } from '@core';
import { Ref } from 'vue';
import { deepCopy } from '../../utils';
export * from './ui-base';
/**
* 为源响应式对象上的某个属性新创建一个单向的Ref,类似于vue的toRef但区别在于,修改返回的Ref,不会影响源响应对象的该属性。而源响应对象上的属性值变化会响应式影响到返回的Ref
*
* @param object 源响应对象,可以是ref对象,也可以是reactive对象
* @param key 响应对象上的属性的key值
*
* ```ts
* const object = ref({foo: 1});
* // 或者 const object = reactive({foo: 1})
* const foo = toOneWayRef(object, 'foo');
* foo.value = 2;
* console.log(object.foo) // 1
* console.log(foo.value) // 2
* object.foo = 3
* console.log(object.foo) // 3
* console.log(foo.value) // 3
* ```
* ps:如果要维持props的父对于props修改的响应性,props必须是Ref
* ```ts
* const father = reactive({ props: { foo: 1 }})
* const props = toRef(father,'props');
* const foo = toOneWayRef(props, 'foo');
* const foo1 = toOneWayRef(props.value,'foo')
* father.props = {foo: 3}
* console.log(father.props.foo) // 3
* console.log(foo.value) // 3
* console.log(foo1.value) // 1
* ```
*
*/
export function toOneWayRef<T extends object, K extends keyof T>(object: Ref<T> | T, key: K): Ref<T[K]>{
// 创建空的Ref
const propertyRef: Ref<T[K]> = ref({}) as any;
// 用watch来监听源响应对象的key属性,并建立单向响应
watch(
() => isRef(object) ? (object.value as T)[key] : object[key],
(newVal: any, oldVal: any) => {
// 用immediate来初始化最初的值,用deepCopy来切断与源值的关联
propertyRef.value = deepCopy(newVal) as T[K];
},
{
immediate: true,
deep: true,
},
);
return propertyRef;
}
/**
* @description 使用上下文参数逻辑块
* @export
* @param {Record<any, any>} props
*/
export function useContextParams(props: Record<any, any>) {
const { contextProp, viewParamsProp } = toRefs(props);
// 维护上下文并监控其变化
const context: Ref<IContext> = ref({});
watch(
contextProp,
(newVal: any, oldVal: any) => {
context.value = deepCopy(newVal || {});
},
{
immediate: true,
deep: true,
}
);
// 维护视图参数并监控其变化
const viewParams: Ref<IParam> = ref({});
watch(
viewParamsProp,
(newVal: any, oldVal: any) => {
viewParams.value = deepCopy(newVal || {});
},
{
immediate: true,
deep: true,
}
);
return { context, viewParams };
}
/**
* @description 值规则校验
* @export
* @param {Record<any, any>} props
*/
export async function verifyRules(_rule: any, value: any, condition: any) {
//常规规则
if (Object.is(condition.Type, 'SIMPLE')) {
//todo
// 数值范围
} else if (Object.is(condition.Type, 'VALUERANGE2')) {
if (!value) {
return;
}
if (!Number.isInteger(value)) {
return Promise.reject('请输入数值!');
} else {
if (condition.includeMinValue && Object.is(value,condition.minValue)) {
return Promise.resolve();
} else if (condition.includeMaxValue && Object.is(value,condition.maxValue)) {
return Promise.resolve();
} else if (value > condition.minValue && value < condition.maxValue) {
return Promise.resolve();
}
}
// 正则式
} else if (Object.is(condition.Type, 'REGEX')) {
// 长度
} else if (Object.is(condition.Type, 'STRINGLENGTH')) {
// 系统值规则
} else if (Object.is(condition.Type, 'SYSVALUERULE')) {
}
}
\ No newline at end of file
import { Ref } from 'vue';
import { IContext, IParam } from '@core';
import { deepCopy } from '../../utils';
/**
* @description 界面基类
* @export
* @class UIBase
*/
export class UIBase {
/**
* 为源响应式对象上的某个属性新创建一个单向的Ref,类似于vue的toRef但区别在于,修改返回的Ref,不会影响源响应对象的该属性。而源响应对象上的属性值变化会响应式影响到返回的Ref
*
* @param object 源响应对象,可以是ref对象,也可以是reactive对象
* @param key 响应对象上的属性的key值
*
* ```ts
* const object = ref({foo: 1});
* // 或者 const object = reactive({foo: 1})
* const foo = toOneWayRef(object, 'foo');
* foo.value = 2;
* console.log(object.foo) // 1
* console.log(foo.value) // 2
* object.foo = 3
* console.log(object.foo) // 3
* console.log(foo.value) // 3
* ```
* ps:如果要维持props的父对于props修改的响应性,props必须是Ref
* ```ts
* const father = reactive({ props: { foo: 1 }})
* const props = toRef(father,'props');
* const foo = toOneWayRef(props, 'foo');
* const foo1 = toOneWayRef(props.value,'foo')
* father.props = {foo: 3}
* console.log(father.props.foo) // 3
* console.log(foo.value) // 3
* console.log(foo1.value) // 1
* ```
*
*/
public static toOneWayRef<T extends object, K extends keyof T>(object: Ref<T> | T, key: K): Ref<T[K]> {
// 创建空的Ref
const propertyRef: Ref<T[K]> = ref({}) as any;
// 用watch来监听源响应对象的key属性,并建立单向响应
watch(
() => isRef(object) ? (object.value as T)[key] : object[key],
(newVal: any, oldVal: any) => {
// 用immediate来初始化最初的值,用deepCopy来切断与源值的关联
propertyRef.value = deepCopy(newVal) as T[K];
},
{
immediate: true,
deep: true,
},
);
return propertyRef;
}
/**
* @description 使用上下文参数逻辑块
* @export
* @param {Record<any, any>} props
*/
public static useContextParams(props: Record<any, any>) {
const { contextProp, viewParamsProp } = toRefs(props);
// 维护上下文并监控其变化
const context: Ref<IContext> = ref({});
watch(
contextProp,
(newVal: any, oldVal: any) => {
context.value = deepCopy(newVal || {});
},
{
immediate: true,
deep: true,
}
);
// 维护视图参数并监控其变化
const viewParams: Ref<IParam> = ref({});
watch(
viewParamsProp,
(newVal: any, oldVal: any) => {
viewParams.value = deepCopy(newVal || {});
},
{
immediate: true,
deep: true,
}
);
return { context, viewParams };
}
}
\ No newline at end of file
import { toRefs } from 'vue';
import { UIUtil, IParam, useContextParams } from '@core';
import { UIUtil, IParam, UIBase } from '@core';
/**
* @description 部件基类
* @export
......@@ -15,7 +15,7 @@ export class EditorBase {
*/
public handleEditorNavParams(props: Record<string, any>) {
const { localContext, localParam, data } = toRefs(props);
const { context, viewParams } = useContextParams(props);
const { context, viewParams } = UIBase.useContextParams(props);
const navParams = {
navContext: context.value,
navViewParam: viewParams.value,
......
import { Ref } from 'vue';
import { useRoute } from 'vue-router';
import { ViewPropsBase, ViewStateBase, toOneWayRef, IParam } from '@core';
import { ViewPropsBase, ViewStateBase, UIBase, IParam } from '@core';
/**
* @description 视图基类
......@@ -74,8 +74,8 @@ export class ViewBase {
* @memberof ViewBase
*/
public useViewContextParams(props: ViewPropsBase) {
const context = toOneWayRef(props, 'context');
const viewParams = toOneWayRef(props, 'viewParams');
const context = UIBase.toOneWayRef(props, 'context');
const viewParams = UIBase.toOneWayRef(props, 'viewParams');
// 导航视图参数处理
this.handleViewContextParams(props, context, viewParams);
watch(context, (newVal: any, oldVal: any) => {
......
import { ControlPropsBase, ControlStateBase, toOneWayRef } from '@core';
import { ControlPropsBase, ControlStateBase, UIBase } from '@core';
import { RouteLocationNormalizedLoaded, Router, useRoute, useRouter } from 'vue-router';
/**
......@@ -64,8 +64,8 @@ export class ControlBase {
* @memberof ControlBase
*/
public useControlContextParams(props: ControlPropsBase) {
const context = toOneWayRef(props, 'context');
const viewParams = toOneWayRef(props, 'viewParams');
const context = UIBase.toOneWayRef(props, 'context');
const viewParams = UIBase.toOneWayRef(props, 'viewParams');
// 把Ref赋值到State上进行解包
this.controlState.context = context;
......
export * from './control-service'
export * from './entity'
export * from './ui-service/ui-service-base'
\ No newline at end of file
export * from './entity-service'
export * from './ui-service'
\ No newline at end of file
export { UIServiceBase } from './ui-service-base';
\ No newline at end of file
......@@ -93,4 +93,38 @@ export class UIUtil {
}
return _data;
}
/**
* @description 值规则校验
* @export
* @param {Record<any, any>} props
*/
public static async verifyRules(_rule: any, value: any, condition: any) {
//常规规则
if (Object.is(condition.Type, 'SIMPLE')) {
//todo
// 数值范围
} else if (Object.is(condition.Type, 'VALUERANGE2')) {
if (!value) {
return;
}
if (!Number.isInteger(value)) {
return Promise.reject('请输入数值!');
} else {
if (condition.includeMinValue && Object.is(value, condition.minValue)) {
return Promise.resolve();
} else if (condition.includeMaxValue && Object.is(value, condition.maxValue)) {
return Promise.resolve();
} else if (value > condition.minValue && value < condition.maxValue) {
return Promise.resolve();
}
}
// 正则式
} else if (Object.is(condition.Type, 'REGEX')) {
// 长度
} else if (Object.is(condition.Type, 'STRINGLENGTH')) {
// 系统值规则
} else if (Object.is(condition.Type, 'SYSVALUERULE')) {
}
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册