第11节:创建新增/编辑组件

摘要:正常禁用取消保存import{ref,reactive}from'vue'import{useFormData}from'@/utils/form-data.js'//是否显

正常禁用取消保存import { ref, reactive } from 'vue'import { useFormData } from '@/utils/form-data.js'//是否显示弹窗const show = defineModel('show')//是否是编辑(用户名不允许修改)const isUpdate = defineModel('isUpdate')//编辑时的用户数据const rowData = defineModel('rowData')//弹窗标题const dialogTitle = defineModel('dialogTitle')//表单对象const formRef = ref(null)//表单const { form, resetFields, assignFields } = useFormData({userId: void 0,username: '',password: '',phone: '',sex: void 0,status: void 0,});//验证规则const rules = reactive({username: [{required: true,message: '请输入名称',type: 'string',trigger: 'blur'}],phone: [{required: true,message: '请输入手机号码',type: 'string',trigger: 'blur'}],});//性别选项const selectOpt = [{ value: 1, label: '男' },{ value: 2, label: '女' },{ value: 3, label: '保密' }]//保存const save = => {//console.log(form)formRef.value?.validate?.((valid) => {if (!valid) {return false;}//验证通过后提交保存//todo...});}//重置取消const close = => {//表单项的验证提示清除formRef.value?.clearValidate?.;show.value = false;} 新增删除保密正常禁用{{ row.createTime }}编辑删除import { reactive, onMounted, ref } from 'vue'import { Delete, Plus } from '@element-plus/icons-vue'import UserSearch from './components/user-search.vue'import { pageUser } from '@/api/user/index.js'import { ElMessage } from 'element-plus'import UserSave from './components/user-save.vue'//是否显示弹窗const show = ref(false)//是否是编辑const isUpdate = ref(false)//编辑时的用户数据const rowData = ref(null)//弹窗标题const dialogTitle = ref('')//表单属性const tableData = reactive({page: 1, //当前默认页total: 0, //模拟,总记录数pageSize: 10, //每页记录数list: , //用户数据列表});//新增文件const add = => {show.value = trueisUpdate.value = falserowData.value = nulldialogTitle.value = '新增用户'};//编辑文章const edit = (row) => {show.value = trueisUpdate.value = truerowData.value = rowdialogTitle.value = '编辑用户'}//Dom挂载后获取数据onMounted( => {getUserList})//重新加载const reload = (form) => {getUserList(form)};//获取分页数据const getUserList = (objData) => {pageUser({ page: tableData.page, pageSize: tableData.pageSize, ...objData}).then((res) => {//console.log(res)tableData.total = res.total;tableData.list = res.list;}).catch((e) => {return e && ElMessage.error(e.message)})};//跳转导航const currentChange = (pageNum) => {tableData.page = pageNumgetUserList}.left-6 {margin-left: 6px;}.table-footer {padding-top: 10px;box-sizing: border-box;display: flex;align-items: center;}.pagination {margin: 0 auto;flex-wrap: wrap;justify-content: center;}.el-table__header {background-color: #f0f0f0;}

来源:文轩教育

相关推荐