| | |
| | | </template> |
| | | |
| | | <script> |
| | | import { listByRole } from './service'; |
| | | |
| | | export default { |
| | | name: "AddDialog", |
| | | props: { |
| | |
| | | photoList: [], |
| | | spectrumList: [], |
| | | defaultImageUrl: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg', // 默认图片地址 |
| | | userOptions: [ |
| | | { value: '1', label: '用户1' }, |
| | | { value: '2', label: '用户2' }, |
| | | { value: '3', label: '用户3' }, |
| | | { value: '4', label: '用户4' }, |
| | | { value: '5', label: '用户5' } |
| | | ] |
| | | userOptions: [] |
| | | }; |
| | | }, |
| | | computed: { |
| | |
| | | }, |
| | | }, |
| | | methods: { |
| | | getUserOptions() { |
| | | listByRole().then(res => { |
| | | if (res) { |
| | | this.userOptions = res.map(user => ({ |
| | | value: user.userId, |
| | | label: user.nickName || user.userName |
| | | })); |
| | | } else { |
| | | this.$message.error('获取用户列表失败'); |
| | | } |
| | | }).catch(err => { |
| | | console.error('获取用户列表失败', err); |
| | | }); |
| | | }, |
| | | checkEditPermission(header) { |
| | | if (!header.role || !Array.isArray(header.role)) { |
| | | return true; |
| | |
| | | photos: this.photoList, |
| | | spectrums: this.spectrumList, |
| | | }; |
| | | |
| | | // 为用户类型字段添加用户完整信息 |
| | | if (this.headerList && this.headerList.length) { |
| | | this.headerList.forEach(header => { |
| | | if (header.type === 'user' && Array.isArray(submitData[header.name])) { |
| | | // 为每个用户类型字段添加userInfo属性,包含用户完整信息 |
| | | submitData[`${header.name}_userInfo`] = submitData[header.name].map(userId => { |
| | | const userInfo = this.userOptions.find(user => user.value === userId); |
| | | return userInfo ? userInfo : { value: userId, label: userId }; |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | console.log(submitData,'修改的数据') |
| | | this.$emit("success", submitData); |
| | | this.handleClose(); |
| | | } else { |
| | |
| | | // 同时更新form中对应的字段值以通过表单验证 |
| | | const imageHeader = this.headerList.find(h => h.type === 'image'); |
| | | if (imageHeader && imageHeader.name) { |
| | | this.$set(this.form, imageHeader.name, '默认图片'); |
| | | // 保存图片URL,这样在表格中可以直接使用 |
| | | this.$set(this.form, imageHeader.name, this.defaultImageUrl); |
| | | console.log('设置图片字段:', imageHeader.name, this.defaultImageUrl); |
| | | } |
| | | |
| | | this.$refs.form.validateField("spectrums"); |
| | |
| | | |
| | | }, |
| | | mounted() { |
| | | // 获取用户列表数据 |
| | | this.getUserOptions(); |
| | | }, |
| | | }; |
| | | </script> |