| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- <template>
- <component
- {% if component_type == 1 %}
- is="a-modal"
- {% else %}
- is="a-drawer"
- {% endif %}
- {% if is_full == 2 %}
- {% if component_type == 1 %}
- :fullscreen="true"
- {% else %}
- width="100%"
- {% endif %}
- {% else %}
- :width="tool.getDevice() === 'mobile' ? '100%' : '{{form_width}}px'"
- {% endif %}
- v-model:visible="visible"
- :title="title"
- :mask-closable="false"
- :ok-loading="loading"
- @cancel="close"
- @before-ok="submit">
- <!-- 表单信息 start -->
- <a-form ref="formRef" :model="formData" :rules="rules" :auto-label-width="true">
- {% for column in columns %}
- {% if column.is_insert == 2 %}
- {% if column.view_type == 'input' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <a-input v-model="formData.{{column.column_name}}" placeholder="请输入{{column.column_comment}}" />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'password' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <a-input-password v-model="formData.{{column.column_name}}" placeholder="请输入{{column.column_comment}}" />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'textarea' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <a-textarea v-model="formData.{{column.column_name}}" placeholder="请输入{{column.column_comment}}" />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'inputNumber' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <a-input-number v-model="formData.{{column.column_name}}" placeholder="请输入{{column.column_comment}}" />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'inputTag' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <a-input-tag v-model="formData.{{column.column_name}}" placeholder="请输入{{column.column_comment}}" allow-clear />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'switch' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <sa-switch v-model="formData.{{column.column_name}}" />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'slider' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <a-slider v-model="formData.{{column.column_name}}" placeholder="请输入{{column.column_comment}}" />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'select' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <a-select v-model="formData.{{column.column_name}}" :options="[]" placeholder="请选择{{column.column_comment}}" allow-clear />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'saSelect' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <sa-select v-model="formData.{{column.column_name}}" dict="{{column.dict_type}}" placeholder="请选择{{column.column_comment}}" allow-clear />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'treeSelect' and column.column_name == options.tree_parent_id %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <a-tree-select
- v-model="formData.{{column.column_name}}"
- :data="treeData"
- :field-names="{ key: '{{options.tree_id}}', title: '{{options.tree_name}}', icon: 'customIcon' }"
- placeholder="请选择{{column.column_comment}}"
- allow-clear />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'treeSelect' and column.column_name != options.tree_parent_id %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <a-tree-select v-model="formData.{{column.column_name}}" :data="[]" placeholder="请选择{{column.column_comment}}" allow-clear />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'radio' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <sa-radio v-model="formData.{{column.column_name}}" dict="{{column.dict_type}}" />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'checkbox' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <sa-checkbox v-model="formData.{{column.column_name}}" dict="{{column.dict_type}}" />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'date' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <a-date-picker v-model="formData.{{column.column_name}}" :show-time="{{column.options.showTime|bool}}" mode="{{column.options.mode}}" placeholder="请选择{{column.column_comment}}" />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'time' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <a-time-picker v-model="formData.{{column.column_name}}" placeholder="请选择{{column.column_comment}}" />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'rate' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <a-rate v-model="formData.{{column.column_name}}" />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'cascader' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <a-cascader v-model="formData.{{column.column_name}}" :options="[]" placeholder="请选择{{column.column_comment}}" allow-clear />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'userSelect' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <sa-user v-model="formData.{{column.column_name}}" :isEcho="true" />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'cityLinkage' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <ma-cityLinkage v-model="formData.{{column.column_name}}" type="${type}" mode="${mode}" />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'uploadImage' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <sa-upload-image v-model="formData.{{column.column_name}}" :limit="{{column.options.limit|formatNumber}}" :multiple="{{column.options.multiple|bool}}" />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'uploadFile' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <sa-upload-file v-model="formData.{{column.column_name}}" :limit="{{column.options.limit|formatNumber}}" :multiple="{{column.options.multiple|bool}}" />
- </a-form-item>
- {% endif %}
- {% if column.view_type == 'wangEditor' %}
- <a-form-item label="{{column.column_comment}}" field="{{column.column_name}}">
- <ma-wangEditor v-model="formData.{{column.column_name}}" :height="{{column.options.height}}" />
- </a-form-item>
- {% endif %}
- {% endif %}
- {% endfor %}
- </a-form>
- <!-- 表单信息 end -->
- </component>
- </template>
- <script setup>
- import { ref, reactive, computed } from 'vue'
- import tool from '@/utils/tool'
- import { Message, Modal } from '@arco-design/web-vue'
- {% if package_name == '' %}
- import api from '../api/{{business_name}}'
- {% else %}
- import api from '../../api/{{package_name}}/{{business_name}}'
- {% endif %}
- const emit = defineEmits(['success'])
- // 引用定义
- const visible = ref(false)
- const loading = ref(false)
- const formRef = ref()
- const mode = ref('')
- {% if tpl_category == 'tree' %}
- const treeData = ref([])
- {% endif %}
- let title = computed(() => {
- return '{{menu_name}}' + (mode.value == 'add' ? '-新增' : '-编辑')
- })
- // 表单初始值
- const initialFormData = {
- {% for column in columns %}
- {% if column.is_pk == 2 %}
- {{column.column_name}}: null,
- {% elseif column.is_insert == 2 %}
- {% if column.column_type == 'int' or column.column_type == 'smallint' or column.column_type == 'tinyint' %}
- {{column.column_name}}: {{column.default_value | parseNumber}},
- {% elseif column.view_type == 'inputTag' %}
- {{column.column_name}}: [],
- {% else %}
- {{column.column_name}}: '{{column.default_value}}',
- {% endif %}
- {% endif %}
- {% endfor %}
- }
- // 表单信息
- const formData = reactive({ ...initialFormData })
- // 验证规则
- const rules = {
- {% for column in columns %}
- {% if column.is_required == 2 and column.is_pk == 1 %}
- {{column.column_name}}: [{ required: true, message: '{{column.column_comment}}必需填写' }],
- {% endif %}
- {% endfor %}
- }
- // 打开弹框
- const open = async (type = 'add') => {
- mode.value = type
- // 重置表单数据
- Object.assign(formData, initialFormData)
- formRef.value.clearValidate()
- visible.value = true
- await initPage()
- }
- // 初始化页面数据
- {% if tpl_category == 'single' %}
- const initPage = async () => {}
- {% else %}
- const initPage = async () => {
- const resp = await api.getPageList()
- treeData.value = resp.data
- }
- {% endif %}
- // 设置数据
- const setFormData = async (data) => {
- for (const key in formData) {
- if (data[key] != null && data[key] != undefined) {
- formData[key] = data[key]
- }
- }
- }
- // 数据保存
- const submit = async (done) => {
- const validate = await formRef.value?.validate()
- if (!validate) {
- loading.value = true
- let data = { ...formData }
- let result = {}
- if (mode.value === 'add') {
- // 添加数据
- data.{{pk}} = undefined
- result = await api.save(data)
- } else {
- // 修改数据
- result = await api.update(data.{{pk}}, data)
- }
- if (result.code === 200) {
- Message.success('操作成功')
- emit('success')
- done(true)
- }
- // 防止连续点击提交
- setTimeout(() => {
- loading.value = false
- }, 500)
- }
- done(false)
- }
- // 关闭弹窗
- const close = () => (visible.value = false)
- defineExpose({ open, setFormData })
- </script>
|