无人机管理后台前端(已迁走)
shuishen
2025-04-29 ef9ad4a0ae1c8229a9fbd503fba655e81ce07770
src/views/system/dept.vue
@@ -227,15 +227,15 @@
            emitPath: false,  // 只返回最后选中的值
            checkStrictly: true,  // 可以选择任意一级
            multiple: false,  // 确保只能单选
            expandTrigger: 'hover' // 鼠标悬停时展开子菜单
              expandTrigger: 'hover', // 鼠标悬停时展开子菜单
           },
           dataType: 'string', // 使用字符串类型
           rules: [
            {
              required: true,
              message: '请选择行政区划',
              trigger: 'change'
            }
                trigger: 'change',
              },
           ],
           change: ({ value }) => {
            if (!value) {
@@ -258,33 +258,33 @@
            let list = [];
            let callback = () => {
              resolve(
               (list || []).map((ele) => ({
                  (list || []).map(ele => ({
                 ...ele,
                 value: ele.value, // 保持原始值类型(字符串)
                 leaf: level >= 2 // 县级为最后一级
                    leaf: level >= 2, // 县级为最后一级
               }))
              );
            };
            
            if (level === 0) {
              getLazyTree('000000000000').then((res) => {
                getLazyTree('000000000000').then(res => {
               list = res.data.data;
               callback();
              });
            } else if (level === 1) {
              getLazyTree(node.value).then((res) => {
                getLazyTree(node.value).then(res => {
               list = res.data.data;
               callback();
              });
            } else if (level === 2) {
              getLazyTree(node.value).then((res) => {
                getLazyTree(node.value).then(res => {
               list = res.data.data;
               callback();
              });
            } else {
              callback();
            }
           }
            },
         },
         {
           label: '备注',
@@ -316,7 +316,7 @@
     },
     ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(',');
@@ -324,7 +324,7 @@
   },
   methods: {
     initData() {
      getDeptTree().then((res) => {
      getDeptTree().then(res => {
        const column = this.findObject(this.option.column, 'parentId');
        column.dicData = res.data.data;
      });
@@ -365,7 +365,7 @@
      console.log('Row data before submit:', row);
      
      add(row).then(
        (res) => {
        res => {
         console.log('Save response:', res.data);
         const data = res.data.data;
         row.id = data.id;
@@ -373,12 +373,12 @@
         row.tenantId = data.tenantId;
         this.$message({
           type: 'success',
           message: '操作成功!'
            message: '操作成功!',
         });
         this.onLoad(this.page);
         done(row);
        },
        (error) => {
        error => {
         console.log('Save error:', error);
         this.loading = false;
         loading();
@@ -395,13 +395,14 @@
      // 提交时只使用县级代码
      const submitData = {
        ...row,
        areaCode: row.areaCode.split(',').pop() // 取最后一个代码(县级)
        areaCode: row.areaCode.split(',').pop(), // 取最后一个代码(县级)
      };
      
      console.log('Row data before submit:', row);
      
      update(submitData).then(
        (res) => {
      update(submitData)
        .then(
          res => {
         console.log('Update response:', res.data);
         this.$message({
           type: 'success',
@@ -410,12 +411,13 @@
         this.onLoad(this.page);
         done(row);
        },
        (error) => {
          error => {
         console.log('Update error:', error);
         this.loading = false;
         loading();
        }
      ).catch((error) => {
        )
        .catch(error => {
        console.log('Update promise rejected:', error);
        this.loading = false;
      });
@@ -482,23 +484,31 @@
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
     },
    // 修改 beforeOpen 方法
     beforeOpen(done, type) {
      if (['add', 'edit'].includes(type)) {
        this.initData();
      }
      if (['edit', 'view'].includes(type)) {
        getDept(this.form.id).then((res) => {
         const areaCode = res.data.data.areaCode;
         const areaName = res.data.data.areaName;
        getDept(this.form.id).then(res => {
          const data = res.data.data;
          const areaCode = data.areaCode;
          const areaName = data.areaName;
         
         // 生成完整的行政区划代码
          // 生成完整的行政区划代码(考虑不同级别)
         const fullAreaCode = this.getFullAreaCode(areaCode);
         
         this.form = Object.assign({}, res.data.data, {
          this.form = Object.assign({}, data, {
           hasChildren: this.form.hasChildren,
           // 使用完整的行政区划代码
           areaCode: fullAreaCode,
           areaName: areaName || '',
          });
          // 调试输出
          console.log('回显数据:', {
            originalAreaCode: areaCode,
            fullAreaCode: fullAreaCode,
            areaName: areaName,
         });
        });
      } else if (type === 'add') {
@@ -530,7 +540,8 @@
      this.loading = true;
      console.log('onLoad triggered with page:', page, 'params:', params);
      console.log('Current parentId:', this.parentId, 'query:', this.query);
      getLazyList(this.parentId, Object.assign(params, this.query)).then((res) => {
      getLazyList(this.parentId, Object.assign(params, this.query))
        .then(res => {
        console.log('onLoad response:', res.data);
        // 处理 areaCode,确保是单一字符串
        const data = (res.data.data || []).map(item => {
@@ -540,14 +551,15 @@
           // 保存完整的行政区划代码
           areaCode: fullAreaCode,
           // 使用原始的县级代码作为实际值
           originalAreaCode: item.areaCode
              originalAreaCode: item.areaCode,
         };
        });
        this.data = data;
        this.loading = false;
        this.selectionClear();
        console.log('Table data after onLoad:', this.data);
      }).catch((error) => {
        })
        .catch(error => {
        console.log('onLoad error:', error);
        this.loading = false;
        this.data = this.data; // 保留当前数据
@@ -555,17 +567,34 @@
      });
     },
     treeLoad(tree, treeNode, resolve) {
      getChildLazyTree({ parentId: tree.id }).then((res) => {
      getChildLazyTree({ parentId: tree.id }).then(res => {
        resolve(res.data.data);
      });
     },
     // 新增:获取完整的行政区划代码
     getFullAreaCode(countyCode) {
      if (!countyCode) return '';
      // 县级代码是12位,省级代码取前2位,市级代码取前4位
      const provinceCode = countyCode.substring(0, 2) + '0000000000';
      const cityCode = countyCode.substring(0, 4) + '00000000';
      return `${provinceCode},${cityCode},${countyCode}`;
    // 修改 getFullAreaCode 方法
    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}`;
      }
     },
   },
  };