【新增】试卷任务前端
This commit is contained in:
@@ -113,6 +113,11 @@ export enum DICT_TYPE {
|
||||
TERMINAL = 'terminal', // 终端
|
||||
DATE_INTERVAL = 'date_interval', // 数据间隔
|
||||
|
||||
|
||||
TASK_TYPE="task_type",//试卷任务模式
|
||||
SYS_STATUS="sys_common_status_other",//通用状态
|
||||
EXAM_QUE_DIFF="exam_que_difficulty",//题型难度
|
||||
SYS_YES_NO="sys_yes_no",
|
||||
// ========== SYSTEM 模块 ==========
|
||||
SYSTEM_USER_SEX = 'system_user_sex',
|
||||
SYSTEM_MENU_TYPE = 'system_menu_type',
|
||||
|
55
src/utils/use-form-data.js
Normal file
55
src/utils/use-form-data.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import { reactive } from 'vue';
|
||||
import { cloneDeep, set as setValue } from 'lodash-es';
|
||||
|
||||
/**
|
||||
* 表单数据hook
|
||||
* @param initValue 初始值
|
||||
*/
|
||||
export function useFormData(init) {
|
||||
let initValue = init == null ? {} : cloneDeep(init);
|
||||
/** 表单数据 */
|
||||
const form = reactive(init == null ? {} : { ...init });
|
||||
|
||||
/** 重置为初始值 */
|
||||
const resetFields = (field, excludes) => {
|
||||
const keys = Object.keys(form);
|
||||
if (typeof field === 'string' && field) {
|
||||
if (keys.includes(field)) {
|
||||
form[field] = cloneDeep(initValue[field]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
keys.forEach((key) => {
|
||||
if (!excludes || !excludes.includes(key)) {
|
||||
form[key] = cloneDeep(initValue[key]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/** 赋值不改变字段 */
|
||||
const assignFields = (data, excludes) => {
|
||||
if (excludes === true) {
|
||||
initValue = data == null ? {} : cloneDeep(data);
|
||||
}
|
||||
Object.keys(form).forEach((key) => {
|
||||
if (!excludes || excludes === true || !excludes.includes(key)) {
|
||||
form[key] = data?.[key];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/** 赋值某字段 */
|
||||
const setFieldValue = (field, value) => {
|
||||
//form[field] = value;
|
||||
setValue(form, field, value);
|
||||
};
|
||||
|
||||
const result = [form, resetFields, assignFields, setFieldValue];
|
||||
// 支持对象解构以兼容旧版
|
||||
Object.assign(result, {
|
||||
form,
|
||||
resetFields,
|
||||
assignFields
|
||||
});
|
||||
return result;
|
||||
}
|
Reference in New Issue
Block a user