无人机管理后台前端(已迁走)
shuishen
2025-05-19 2dfc8dc4bcd3d3cd4aed1b6054e073e140eba9c8
src/views/device/components/devicePerShare.vue
@@ -9,6 +9,7 @@
      @row-del="rowDel"
      v-model="form"
      :permission="permissionList"
      @row-save="rowSave"
      @row-update="rowUpdate"
      :before-open="beforeOpen"
      @search-change="searchChange"
@@ -17,80 +18,23 @@
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
       @on-load="onLoad"
    >
      <template #menu-left>
        <el-button type="primary" icon="el-icon-plus" plain @click="openFirmwareUpload"
          >固件上传
        </el-button>
      </template>
    </avue-crud>
    <el-dialog title="固件上传" append-to-body v-model="firmwareUploadBox" width="40%" height="60%">
      <el-form
        ref="form"
        :model="importForm"
        v-loading="loadingForm"
        label-width="80px"
        style="width: 80%; margin-left: 10%"
        :rules="rules"
      >
        <el-form-item label="设备名称" prop="device_name">
          <el-input v-model="importForm.device_name" clearable></el-input>
        </el-form-item>
        <!-- 上传 -->
        <el-form-item label="固件文件" label-width="80px" prop="file">
          <el-upload
            class="upload-demo"
            action="#"
            ref="uploadFirmware"
            :limit="1"
            :auto-upload="false"
            :multiple="false"
            :before-upload="beforeUploadFile"
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text" style="height: 50px"><em>点击上传</em></div>
          </el-upload>
        </el-form-item>
        <el-form-item label="是否可用" prop="status">
          <el-select v-model="importForm.status" placeholder="请选择" clearable>
            <el-option label="是" value="1"></el-option>
            <el-option label="否" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="说明" label-width="80px" prop="release_note">
          <el-input type="textarea" v-model="importForm.release_note" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onConfirm">确定</el-button>
          <el-button @click="onCancel">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </basic-container>
</template>
<script>
import { getDeviceFirmwareList, deleteFirmware, updateFirmware, upload } from '@/api/device/device';
import { getList, remove, add, update } from '@/api/device/devicePerShare';
import { getDeptTreeByNotItself } from '@/api/system/dept';
import { mapGetters } from 'vuex';
export default {
  data() {
    return {
      loadingForm:false,
      file: '',
      rules: {
        device_name: [{ required: true, message: '请输入设备名称', trigger: 'blur' }],
        status: [{ required: true, message: '请选择', trigger: 'change' }],
        release_note:[{ required: true, message: '请输入版本说明', trigger: 'blur' }],
      },
      importForm: {},
      firmwareUploadBox: false,
      deptId: '',
      deviceSn: '',
      form: {},
      query: {},
      workspaceId: '',
      deviceName: '',
      loading: true,
      page: {
        pageSize: 10,
@@ -98,155 +42,98 @@
        total: 0,
      },
      selectionList: [],
      deptTreeData: [],
      option: {
        lazy: true,
        tree: true,
        height: 'atuo',
        height: 'auto',
        calcHeight: 32,
        dialogWidth: 950,
        dialogWidth: 750,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        viewBtn: true,
        addBtn: false,
        addBtn: true,
        selection: true,
        excelBtn: false,
        dialogClickModal: false,
        grid: false,
        column: [
          {
            label: '设备名称',
            prop: 'device_name',
            editDisabled: true,
            // search: true,
            // searchSpan: 5,
            label: '授权单位',
            prop: 'deptId',
            labelWidth: 130,
            addDisplay: false,
            editDisabled: true,
            type: 'tree',
            dicData: [],
            props: {
              label: 'name',
              value: 'id',
            },
            span: 24,
            row: true,
            hide: true,
            editDisplay: false,
            viewDisplay: false,
            rules: [
              {
                required: true,
                message: '请输入设备型号',
                message: '请输入授权单位',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '固件文件名称',
            prop: 'file_name',
            label: '授权单位',
            prop: 'deptName',
            labelWidth: 130,
            addDisplay: false,
            editDisabled: true,
            search: true,
            searchSpan: 8,
            searchLabelWidth: 120,
            editDisabled: true,
            searchSpan: 6,
            span: 24,
            row: true,
            rules: [
              {
                required: true,
                message: '请输入固件文件名称',
                message: '请输入授权单位',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '文件大小',
            prop: 'file_size',
            addDisplay: false,
            editDisabled: true,
            hide:true,
            label: '授权功能',
            prop: 'devicePerMenuId',
            labelWidth: 130,
            rules: [
              {
                required: false,
                message: '请输入文件大小',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '固件版本',
            prop: 'firmware_version',
            labelWidth: 130,
            width: 100,
            editDisabled: true,
            type: 'tree',
            dicUrl: '/blade-system/manage/api/v1/devicePerMenu/selectDeviceList',
            props: {
              label: 'name',
              value: 'id',
            },
            multiple: true,
            dataType: 'string',
            span: 24,
            row: true,
            rules: [
              {
                required: true,
                message: '请输入固件版本',
                message: '请输入授权功能',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '上传时间',
            prop: 'create_time',
            label: '授权时间',
            prop: 'createTime',
            type: 'date',
            addDisplay: false,
            editDisplay: false,
            labelWidth: 130,
            span: 24,
            row: true,
            width: 160,
            format: 'YYYY-MM-DD HH:mm:ss',
            // valueFormat: 'YYYY-MM-DD HH:mm:ss',
            startPlaceholder: '任务开始时间',
            rules: [
              {
                required: true,
                message: '请输入在线时间',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '是否可用',
            prop: 'status',
            addDisplay: false,
            labelWidth: 130,
            type: 'select',
            width: 100,
            dicData: [
              {
                label: '可用',
                value: true,
              },
              {
                label: '不可用',
                value: false,
              },
            ],
            rules: [
              {
                required: true,
                message: '请输入在线状态',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '上传状态',
            prop: 'upload_status',
            addDisplay: false,
            editDisplay: false,
            labelWidth: 130,
            type: 'select',
            width: 100,
            dicData: [
              {
                label: '上传中或者上传失败',
                value: 1,
              },
              {
                label: '上传成功',
                value: 2,
              },
            ],
            rules: [
              {
                required: true,
                message: '请输入在线状态',
                trigger: 'blur',
              },
            ],
          },
        ],
      },
@@ -272,60 +159,46 @@
    },
  },
  methods: {
    //自定义上传方法,使用上传组件的submit()后才会触发以获取文件实体
    beforeUploadFile(param) {
      this.file = param;
      return false;
    init(data) {
      this.deptId = data.dept_id;
      this.deviceSn = data.device_sn;
      this.getDeptTreeInfo();
      this.getLoadPage(this.page);
    },
    // 确定按钮
    onConfirm() {
      var that = this;
      this.$refs.form.validate(valid => {
        if (valid) {
          this.$refs.uploadFirmware.submit();
          const formDatas = new FormData();
          formDatas.append('file', that.file);
          formDatas.append('deviceName', that.importForm.device_name);
          formDatas.append('releaseNote', that.importForm.release_note);
          formDatas.append('status', that.importForm.status);
          this.loadingForm = true;
          // 提交
          upload(this.workspaceId, formDatas).then(res => {
            this.loadingForm = false;
            this.firmwareUploadBox = false;
            that.importForm = {}
            this.onLoad(this.page);
            this.$message({
              type: 'success',
              message: '操作成功!',
            });
          });
        } else {
          console.log('error submit!!');
          return false;
        }
    getDeptTreeInfo() {
      getDeptTreeByNotItself(this.deptId, this.deviceSn).then(res => {
        const column = this.findObject(this.option.column, 'deptId');
        this.deptTreeData = res.data.data;
        column.dicData = res.data.data;
      });
    },
    onCancel(){
        this.firmwareUploadBox = false;
        this.file = ''
    },
    //打卡固件上传页面
    openFirmwareUpload() {
      this.firmwareUploadBox = true;
      this.importForm['device_name'] = this.deviceName;
    },
    // 初始化数据
    init(data) {
      this.workspaceId = data.workspace_id;
      // this.workspaceId = '4a574d68-4ad3-48f7-9f16-3edbcd8056e1';
      this.deviceName = data.device_name;
      this.onLoad(this.page);
    rowSave(row, done, loading) {
      // 添加毫秒级时间戳
      row['createTime'] = Date.now();
      row['deviceSn'] = this.deviceSn;
      add(row).then(
        () => {
          this.initFlag = false;
          this.getLoadPage(this.page);
          this.getDeptTreeInfo();
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          done();
        },
        error => {
          window.console.log(error);
          loading();
        }
      );
    },
    rowUpdate(row, index, done, loading) {
        updateFirmware(row).then(
      row['device_sn'] = this.deviceSn;
      update(row).then(
        () => {
          this.onLoad(this.page);
          this.getLoadPage(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
@@ -345,10 +218,11 @@
        type: 'warning',
      })
        .then(() => {
          return deleteFirmware(row.id);
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.getDeptTreeInfo();
          this.getLoadPage(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
@@ -357,12 +231,12 @@
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
      this.getLoadPage(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      this.getLoadPage(this.page, params);
      done();
    },
    selectionChange(list) {
@@ -386,7 +260,7 @@
          return remove(this.ids);
        })
        .then(() => {
          this.onLoad(this.page);
          this.getLoadPage(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
@@ -399,22 +273,28 @@
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.getLoadPage(this.page, this.query); // 添加数据刷新
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.page.currentPage = 1; // 每页条数改变时,重置到第一页
      this.getLoadPage(this.page, this.query); // 添加数据刷新
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
      this.getLoadPage(this.page, this.query);
    },
    onLoad(page, params = {}) {
      params['device_name'] = this.deviceName;
    getLoadPage(page, params = {}) {
      params['deviceSn'] = this.deviceSn;
      this.loading = true;
      getDeviceFirmwareList(page.currentPage, page.pageSize, params).then(res => {
      getList(page.currentPage, page.pageSize, params).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      }).catch(err => {
        console.error('加载数据失败:', err);
        this.loading = false;
      });
    },
  },
@@ -428,6 +308,5 @@
}
.firmware_status:hover {
  cursor: pointer;
  /* color: aqua; */
}
</style>
</style>