123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441 |
- <script lang="ts" setup>
- import type { BasicForm } from '@/types/form'
- import { ElInput } from 'element-plus'
- const request = function ({ pageNo }: any) {
- return new Promise(resolve => {
- setTimeout(() => {
- const data = {
- list: [
- { name: '张三' + pageNo, sex: '男', id: '' + pageNo + 1 },
- { name: '李四' + pageNo, sex: '女', id: '' + pageNo + 2 },
- { name: '王五' + pageNo, sex: '男', id: '' + pageNo + 3 },
- { name: '赵六' + pageNo, sex: '女', id: '' + pageNo + 4 },
- { name: '张三' + pageNo, sex: '男', id: '' + pageNo + 5 }
- ],
- total: 10
- }
- resolve(data)
- }, 1500)
- })
- }
- const formData = reactive<any>({})
- const formConfig = reactive<BasicForm>({
- span: 12,
- props: {
- labelPosition: 'right'
- },
- formItems: [
- {
- label: '',
- value: '',
- name: '',
- type: 'form-title',
- span: 24,
- notFormItem: true,
- props: {
- title: '基础表单',
- type: 'success',
- color: '#0366d6'
- }
- },
- {
- label: '用户名',
- value: '',
- name: 'name',
- type: 'input',
- rules: [{ required: true, message: '请输入用户名', trigger: 'blur' }]
- },
- {
- label: '密码',
- value: '',
- name: 'password',
- type: 'custom',
- slots: [
- {
- name: 'default',
- alias: 'password'
- }
- ],
- rules: [{ required: true, message: '请输入密码', trigger: 'blur' }]
- },
- {
- label: '区域',
- value: [],
- name: 'area',
- type: 'area',
- props: {
- props: {
- multiple: true
- }
- }
- },
- {
- label: '下拉表格',
- value: '',
- name: 'tableSelect',
- type: 'tableSelect',
- props: {
- tableConfig: {
- column: [
- {
- title: '#',
- type: 'seq',
- width: 45,
- align: 'center'
- },
- {
- title: '姓名',
- field: 'name',
- align: 'center'
- },
- {
- title: '性别',
- align: 'center',
- slot: 'sex'
- }
- ],
- /* 实际开发应传入接口方法 */
- request: request,
- pageSize: 5
- }
- }
- },
- {
- label: '手机号',
- value: '',
- name: 'phone',
- type: 'input',
- rules: [
- // {
- // validator: validator.mobile
- // }
- ]
- },
- {
- label: '开关',
- value: true,
- name: 'ss',
- type: 'switch',
- props: {}
- },
- {
- label: '',
- value: '',
- name: '',
- type: 'button',
- notFormItem: true,
- props: {
- buttonName: '按钮'
- }
- },
- {
- label: '',
- value: '',
- name: '',
- type: 'alert',
- notFormItem: true,
- props: {
- title: 'alert',
- type: 'warning'
- }
- },
- {
- label: '字典',
- value: '',
- name: 'field1',
- type: 'dict',
- props: {
- type: 'task_from',
- multiple: true
- }
- },
- {
- label: '字段名',
- value: '',
- name: 'field2',
- type: 'input',
- slots: [
- {
- name: 'prepend',
- alias: 'prepend1'
- },
- {
- name: 'append',
- alias: 'append1'
- }
- ]
- },
- {
- label: '字段名',
- value: '',
- name: 'field3',
- type: 'cascader',
- props: {
- options: [
- {
- value: 'guide',
- label: 'Guide',
- children: [
- {
- value: 'disciplines',
- label: 'Disciplines',
- children: [
- {
- value: 'consistency',
- label: 'Consistency'
- },
- {
- value: 'feedback',
- label: 'Feedback'
- },
- {
- value: 'efficiency',
- label: 'Efficiency'
- },
- {
- value: 'controllability',
- label: 'Controllability'
- }
- ]
- },
- {
- value: 'navigation',
- label: 'Navigation',
- children: [
- {
- value: 'side nav',
- label: 'Side Navigation'
- },
- {
- value: 'top nav',
- label: 'Top Navigation'
- }
- ]
- }
- ]
- },
- {
- value: 'resource',
- label: 'Resource',
- children: [
- {
- value: 'axure',
- label: 'Axure Components'
- },
- {
- value: 'sketch',
- label: 'Sketch Templates'
- },
- {
- value: 'docs',
- label: 'Design Documentation'
- }
- ]
- }
- ]
- },
- slots: [
- {
- name: 'default',
- alias: 'cDefault'
- }
- ],
- events: {
- change() {
- formData.name = 'c'
- formConfig.formItems[1].hidden = true
- }
- }
- },
- {
- label: '树选择',
- value: '',
- name: 'tree',
- type: 'tree-select',
- props: {
- data: [
- {
- value: '1',
- label: 'Level one 1',
- children: [
- {
- value: '1-1',
- label: 'Level two 1-1',
- children: [
- {
- value: '1-1-1',
- label: 'Level three 1-1-1'
- }
- ]
- }
- ]
- },
- {
- value: '2',
- label: 'Level one 2',
- children: [
- {
- value: '2-1',
- label: 'Level two 2-1',
- children: [
- {
- value: '2-1-1',
- label: 'Level three 2-1-1'
- }
- ]
- },
- {
- value: '2-2',
- label: 'Level two 2-2',
- children: [
- {
- value: '2-2-1',
- label: 'Level three 2-2-1'
- }
- ]
- }
- ]
- }
- ]
- }
- },
- {
- label: '图片',
- value: '',
- name: 'image',
- type: 'image-upload',
- slots: [
- {
- name: 'tip',
- alias: 'tip'
- }
- ]
- },
- {
- label: '文件',
- value: 'erp/prod/temp/1702626281947.png,erp/prod/temp/1702626287319.png',
- name: 'file',
- type: 'file-upload',
- slots: [
- {
- name: 'default',
- alias: 'file'
- }
- ]
- },
- {
- label: '可编辑标签',
- value: 'f,ghh',
- name: 'tag',
- type: 'edit-tag'
- },
- {
- label: '自定义',
- value: '',
- name: 'custom',
- type: 'custom',
- notFormItem: true,
- slots: [
- {
- name: 'default',
- alias: 'customDefault'
- }
- ]
- }
- ]
- })
- const create = (data: any) => {
- console.log(data)
- }
- const update = (data: any) => {
- console.log(data)
- }
- const proFormRef = ref<any>()
- const handleSave = () => {
- proFormRef.value.submit()
- }
- const inputValue = ref('')
- const dynamicTags = ref(['Tag 1', 'Tag 2', 'Tag 3'])
- const inputVisible = ref(false)
- const InputRef = ref<InstanceType<typeof ElInput>>()
- const handleClose = (tag: string) => {
- dynamicTags.value.splice(dynamicTags.value.indexOf(tag), 1)
- }
- const showInput = () => {
- inputVisible.value = true
- nextTick(() => {
- InputRef.value!.input!.focus()
- })
- }
- const handleInputConfirm = () => {
- if (inputValue.value) {
- dynamicTags.value.push(inputValue.value)
- }
- inputVisible.value = false
- inputValue.value = ''
- }
- </script>
- <template>
- <div class="h-full bg-white p-16px pt-20px overflow-auto">
- <form-title type="primary" class="py-10px mb-4">
- <template #default> 标题 </template>
- </form-title>
- <pro-form :formConfig="formConfig" :formData="formData" :create="create" :update="update" ref="proFormRef">
- <template #prepend1> test1 </template>
- <template #append1> test1 </template>
- <template #cDefault="{ node, data }">
- <span>{{ data.label }}</span>
- <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
- </template>
- <template #file>
- <el-button type="primary">上传文件</el-button>
- </template>
- <template #tip>
- <div><el-text>请上传750*450px 的图片</el-text></div>
- </template>
- <template #password>
- <el-input type="password" name="password" v-model="formData.password" placeholder="请输入密码"></el-input>
- <el-text type="info">密码需包含大写字母、小写字母、数字</el-text>
- </template>
- <template #customDefault>
- <el-space wrap>
- <el-tag
- v-for="tag in dynamicTags"
- :key="tag"
- size="small"
- closable
- :disable-transitions="false"
- @close="handleClose(tag)"
- >
- {{ tag }}
- </el-tag>
- <el-input
- v-if="inputVisible"
- ref="InputRef"
- v-model="inputValue"
- class="ml-1 w-20"
- size="small"
- @keyup.enter="handleInputConfirm"
- @blur="handleInputConfirm"
- />
- <el-button v-else class="button-new-tag ml-1" size="small" @click="showInput"> + New Tag </el-button>
- </el-space>
- </template>
- </pro-form>
- <div class="text-center">
- <el-button type="primary" @click="handleSave">保存</el-button>
- </div>
- </div>
- </template>
- <style lang="scss" scoped></style>
|