UNPKG

ed-frame-vue

Version:

easydata 基础组件

134 lines (128 loc) 3.45 kB
import { getVarType } from "../../utils/utils"; import useTable from "./useTable" import {initControls, TempType} from "../../api/easyData"; export default { mixins: [useTable], data(){ return { initLoading: false, controlInfos: [], controlProps: {}, dataSource: {}, } }, props: { /** * 数据源名称 * @default '' */ dataSourceName: {type: String, default: ''}, /** * 视图ID,用于显示不同视图 * @default 'default' */ viewId: {type: String, default: 'default'}, /** * 业务请求参数,仅模板使用 * @default {} */ bizParams: {type: Object, default: () => {}}, /** * 表单数据默认值,新增接口提交数据会自动带上 * @default {} */ formData: {type: [Array, Object], default: () => {}}, /** * 额外请求参数,仅模板使用 * @default {} */ extraParams: {type: Object, default: () => {}}, /** * 数据源传递 * @default [] */ passModuleIds: {type: Array, default: () => []}, /** * 模块属性 模块使用自定义属性 * @default {} */ moduleProp: { type: Object, default: () => { return { showAddBtn: false, showAction: false } } } }, methods:{ /** * 初始化表单模板数据 * @returns {Promise<void>} */ initControls() { return new Promise(async (resolve, reject) => { this.initLoading = true try { const result = await initControls(this.dataSourceName, this.viewId) const {data: {controlInfos, controlPropsMap, dataSource}} = result; this.controlInfos = this.getControlInfo(controlInfos) this.controlProps = controlPropsMap this.dataSource = dataSource resolve({ dataSource: dataSource, controlProps: controlPropsMap, controlInfos: controlInfos }) }catch (e) { reject(e) } this.initLoading = false }) }, /** * @name getControlInfo * @param controlInfos * @returns {*} * @description 获取表单控件属性 */ getControlInfo(controlInfos) { this.$emit('editControlInfos', controlInfos) return controlInfos }, /** * 获取当前模板类型 * @returns */ getType(){ return TempType.save }, /** 获取指定二级模块数据,或者所有需要的二级模块数据 */ getPassModuleData(moduleId = this.passModuleIds) { if(moduleId && this._tempV) { if(getVarType(moduleId) === 'string') { return this._tempV.getFormData(moduleId) } else if (getVarType(moduleId) === 'array' && moduleId.length > 0) { let PromiseAll = [] moduleId.map(item=>{ PromiseAll.push(this._tempV.getFormData(item)) }) return new Promise((resolve, reject) => { Promise.all(PromiseAll).then(data => { resolve(data) }).catch(err => { console.log(err) reject(false) }) }) } } return new Promise((resolve, reject) => {resolve({})}) }, // 检测对象中是否包含指定字段 hasObject(thisArg, ...argArray){ return Object.prototype.hasOwnProperty.call(thisArg, ...argArray) }, } }