| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- import { updateClassName } from '../util/reuse-methods'
- import _ from 'lodash'
- export const generateDialogMixin = {
- props: ['config', 'models', 'rules', 'element', 'remote', 'blanks', 'edit', 'remoteOption', 'platform', 'preview', 'containerKey', 'dataSourceValue', 'eventFunction', 'printRead', 'group', 'fieldNode'],
- data () {
- return {
- visible: this.element.options.visible,
- displayFields: {},
- dialogModel: this.models[this.element.model] ?? {},
- dialogDisabled: {}
- }
- },
- emits: ['update:models'],
- inject: ['generateComponentInstance', 'deleteComponentInstance', 'getFormComponent', 'onFormHide', 'onFormDisplay'],
- created () {
- this._generateModel(this.element.list)
- },
- mounted () {
- this.generateComponentInstance && this.generateComponentInstance(this.element.model, this.$refs[`generate-dialog-${this.element.model}`].$parent)
- },
- beforeUnmount () {
- this.deleteComponentInstance && this.deleteComponentInstance(this.element.model)
- },
- provide () {
- return {
- 'setDialogData': this.setDialogData
- }
- },
- methods: {
- setDialogData (value, field) {
- this.dialogModel[field] = value
- },
- _generateModel (genList) {
- for (let i = 0; i < genList.length; i++) {
- if (genList[i].type == 'grid') {
- this.displayFields[genList[i].model] = !genList[i].options.hidden
- genList[i].columns.forEach(item => {
- this._generateModel(item.list)
- })
- } else if (genList[i].type === 'tabs') {
- genList[i].tabs.forEach(item => {
- this._generateModel(item.list)
- })
- this.displayFields[genList[i].model] = !genList[i].options.hidden
- } else if (genList[i].type === 'collapse') {
- genList[i].tabs.forEach(item => {
- this._generateModel(item.list)
- })
- this.displayFields[genList[i].model] = !genList[i].options.hidden
- } else if (genList[i].type === 'report') {
- genList[i].rows.forEach(row => {
- row.columns.forEach(column => {
- this._generateModel(column.list)
- })
- })
- this.displayFields[genList[i].model] = !genList[i].options.hidden
- } else if (genList[i].type === 'inline') {
- this._generateModel(genList[i].list)
- this.displayFields[genList[i].model] = !genList[i].options.hidden
- } else if (genList[i].type === 'card') {
- this._generateModel(genList[i].list)
- this.displayFields[genList[i].model] = !genList[i].options.hidden
- } else {
- if (genList[i].type == 'blank') {
- this.dialogModel[genList[i].model] = genList[i].options.defaultType === 'String' ? '' : (genList[i].options.defaultType === 'Object' ? {} : [])
- } else {
- this.dialogModel[genList[i].model] = this.models[this.element.model][genList[i].model] ?? _.cloneDeep(genList[i].options.defaultValue)
- }
- this.displayFields[genList[i].model] = !genList[i].options.hidden
- this.dialogDisabled[genList[i].model] = !genList[i].options.disabled
- }
- }
- },
- open () {
- this.visible = true
- },
- close () {
- this.visible = false
- },
- hide (fields) {
- if (typeof fields === 'string') {
- fields = [fields]
- }
- fields.forEach(field => {
- this.onFormHide(`${this.fieldNode}.${field}`)
- })
- },
- display (fields) {
- if (typeof fields === 'string') {
- fields = [fields]
- }
- fields.forEach(field => {
- this.onFormDisplay(`${this.fieldNode}.${field}`)
- })
- },
- disabled (fields, disabled) {
- if (typeof fields === 'string') {
- fields = [fields]
- }
- this._setDisabled(this.element.list, fields, disabled)
- },
- handleCancel () {
- if (this.element && this.element.events && this.element.events.onCancel) {
- let funcKey = this.element.events.onCancel
- this.eventFunction[funcKey]({
- field: this.element.model,
- currentRef: this
- })
- }
- },
- handleConfirm () {
- if (this.element && this.element.events && this.element.events.onConfirm) {
- let funcKey = this.element.events.onConfirm
- this.eventFunction[funcKey]({
- field: this.element.model,
- currentRef: this
- })
- }
- },
- confirmLoading (status) {
- this.element.options.confirmLoading = status
- },
- setOptions (fields, options) {
- if (typeof fields === 'string') {
- fields = [fields]
- }
- this._setOptions(this.element.list, fields, options)
- },
- setData (value) {
- return new Promise((resolve) => {
- this.$nextTick(() => {
- Object.keys(value).forEach(item => {
- this.dialogModel[item] = value[item]
- })
- resolve()
- })
- })
- },
- getValues () {
- return this.dialogModel
- },
- getValue (fieldName) {
- return this.dialogModel[fieldName]
- },
- addClassName (fields, className) {
- if (typeof fields === 'string') {
- fields = [fields]
- }
- fields.forEach(item => {
- updateClassName(this.element.list, item.split('.'), className, 'add')
- })
- },
- removeClassName (fields, className) {
- if (typeof fields === 'string') {
- fields = [fields]
- }
- fields.forEach(item => {
- updateClassName(this.element.list, item.split('.'), className, 'remove')
- })
- },
- _setDisabled (genList, fields, disabled) {
- for (let i = 0; i < genList.length; i++) {
- if (genList[i].type === 'grid') {
- genList[i].columns.forEach(item => {
- this._setDisabled(item.list, fields, disabled)
- })
- } else if (genList[i].type === 'tabs') {
- genList[i].tabs.forEach(item => {
- this._setDisabled(item.list, fields, disabled)
- })
- } else if (genList[i].type === 'collapse') {
- genList[i].tabs.forEach(item => {
- this._setDisabled(item.list, fields, disabled)
- })
- } else if (genList[i].type === 'report') {
- genList[i].rows.forEach(row => {
- row.columns.forEach(column => {
- this._setDisabled(column.list, fields, disabled)
- })
- })
- } else if (genList[i].type === 'inline') {
- this._setDisabled(genList[i].list, fields, disabled)
- } else if (genList[i].type === 'card') {
- this._setDisabled(genList[i].list, fields, disabled)
- } else {
- if (fields.indexOf(genList[i].model) >= 0) {
- genList[i].options.disabled = disabled
- }
- }
- }
- },
- _setOptions (genList, fields, opts) {
- for (let i = 0; i < genList.length; i++) {
- if (genList[i].type === 'grid') {
- genList[i].columns.forEach(item => {
- this._setOptions(item.list, fields, opts)
- })
- } else if (genList[i].type === 'tabs') {
- genList[i].tabs.forEach(item => {
- this._setOptions(item.list, fields, opts)
- })
- } else if (genList[i].type === 'collapse') {
- genList[i].tabs.forEach(item => {
- this._setOptions(item.list, fields, opts)
- })
- } else if (genList[i].type === 'report') {
- genList[i].rows.forEach(row => {
- row.columns.forEach(column => {
- this._setOptions(column.list, fields, opts)
- })
- })
- } else if (genList[i].type === 'inline') {
- this._setOptions(genList[i].list, fields, opts)
- } else if (genList[i].type === 'card') {
- this._setOptions(genList[i].list, fields, opts)
- }
- if (fields.indexOf(genList[i].model) >= 0) {
- Object.keys(opts).forEach(key => {
- genList[i].options[key] = opts[key]
- })
- }
- }
- },
- _getAllRuleFields () {
- let realFields = []
- Object.keys(this.dialogModel).forEach((v) => {
- if (Array.isArray(this.dialogModel[v])) {
- const currentArray = this.dialogModel[v]
- currentArray.forEach((o, i) => {
- Object.keys(o).forEach((key) => {
- realFields.push(`${this.element.model}.${v}.${i}.${key}`)
- })
- })
- } else {
- realFields.push(`${this.element.model}.${v}`)
- }
- })
- return realFields
- },
- },
- watch: {
- dialogModel: {
- deep: true,
- handler (val) {
- this.$emit('update:models', {
- ...this.models,
- [this.element.model]: val
- })
- }
- },
- models: {
- deep: true,
- handler (val) {
- this.dialogModel = this.models[this.element.model]
- }
- }
- }
- }
|