无人机管理后台前端(已迁走)
张含笑
2025-07-29 d5d2bd2ae7959f2c525642290bcfd8459a06cfdb
Merge remote-tracking branch 'origin/dev' into dev
1 files modified
98 ■■■■■ changed files
src/views/device/addDevice.vue 98 ●●●●● patch | view | raw | blame | history
src/views/device/addDevice.vue
@@ -194,6 +194,64 @@
                        format: 'YYYY-MM-DD HH:mm:ss',
                    },
                    {
                        label: '行政区划',
                        prop: 'area_code',
                        type: 'cascader',
                        labelWidth: 130,
                        hide: true,
                        editDisplay: true,
                        viewDisplay: false,
                        props: {
                        label: 'title',
                        value: 'value',
                        emitPath: false,
                        checkStrictly: true,
                        multiple: false,
                        expandTrigger: 'hover',
                        },
                        dataType: 'string',
                        rules: [
                        {
                            required: true,
                            message: '请选择行政区划',
                            trigger: 'change',
                        },
                        ],
                        lazy: true,
                        lazyLoad (node, resolve) {
                        let level = node.level
                        let list = []
                        let callback = () => {
                            resolve(
                            (list || []).map(ele => ({
                                ...ele,
                                value: ele.value,
                                leaf: level >= 2,
                            }))
                            )
                        }
                        if (level === 0) {
                            getLazyTree('000000000000').then(res => {
                            list = res.data.data
                            callback()
                            })
                        } else if (level === 1) {
                            getLazyTree(node.value).then(res => {
                            list = res.data.data
                            callback()
                            })
                        } else if (level === 2) {
                            getLazyTree(node.value).then(res => {
                            list = res.data.data
                            callback()
                            })
                        } else {
                            callback()
                        }
                        },
                    },
                ],
            },
@@ -258,6 +316,14 @@
        },
        rowSave (row, done, loading) {
            let areaCode = row.area_code
            if (Array.isArray(areaCode)) {
                areaCode = areaCode[areaCode.length - 1]
            } else if (typeof areaCode === 'string' && areaCode.includes(',')) {
                const codes = areaCode.split(',')
                areaCode = codes[codes.length - 1]
            }
            row.area_code = areaCode || null
            add(row).then(
                () => {
                    this.onLoad(this.page)
@@ -274,7 +340,11 @@
            )
        },
        rowUpdate (row, index, done, loading) {
            update(row).then(
            const submitData = {
                ...row,
                area_code: row.area_code.split(',').pop(),
            }
            update(submitData).then(
                () => {
                    this.onLoad(this.page)
                    this.$message({
@@ -345,10 +415,32 @@
                    this.$refs.crud.toggleSelection()
                })
        },
        async getFullAreaCode (areaCode) {
            if (!areaCode) return ''
            const code = areaCode.toString()
            if (code.includes(',')) return code
            if (code.endsWith('0000000000')) {
                return code
            } else if (code.endsWith('00000000') && !code.endsWith('0000000000')) {
                const provinceCode = code.substring(0, 2) + '0000000000'
                return `${provinceCode},${code}`
            } else {
                const provinceCode = code.substring(0, 2) + '0000000000'
                const cityCode = code.substring(0, 4) + '00000000'
                return `${provinceCode},${cityCode},${code}`
            }
        },
        beforeOpen (done, type) {
            if (['edit', 'view'].includes(type)) {
                getDetail(this.form.id).then(res => {
                    this.form = res.data.data
                getDetail(this.form.id).then(async res => {
                    const data = res.data.data
                     this.form = {
                        ...data,
                        area_code: await this.getFullAreaCode(data.area_code),
                     }
                })
            }
            done()