研发图纸文件管理系统-前端项目
he wei
2024-01-17 752d135e7d0d229002aed8f558a244ff58e949ca
src/pages/resourceManage/software/list.vue
@@ -14,7 +14,7 @@
            @refresh="onRefresh"
            @reset="onReset"
            :format-conditions="true"
            :scroll="{ x: 1920, y }"
            :scroll="{ x: 2020, y }"
            :pagination="{
              current: pageCurr,
              pageSize: pageSize,
@@ -28,7 +28,11 @@
              onChange: onPageChange,
              onShowSizeChange: onSizeChange,
            }"
            :rowClassName="rowClassFn"
          >
            <template slot="dataIndex" slot-scope="{ index }">
              {{ index + 1 }}
            </template>
            <template slot="title">
              <a-space>
                <span class="title">软件中心</span>
@@ -59,12 +63,43 @@
              </a-popover>
              <template v-if="canDownloadSoftware">
                <a-divider type="vertical"></a-divider>
                <a @click="download(record)">下载</a>
              </template>
              <template v-if="canUploadSoftware">
                <a
                  :disabled="!!record.soft.lockFlag && !isTester"
                  @click="download(record)"
                  >下载</a
                >
                <a-divider type="vertical"></a-divider>
                <a @click="updateDesc(record)">更新说明</a>
              </template>
              <a-popover title="" trigger="hover">
                <a-space class="btn-grp" direction="vertical" slot="content">
                  <a-button
                    v-if="canUploadSoftware"
                    :disabled="!!record.soft.lockFlag"
                    type="primary"
                    @click="updateDesc(record)"
                    >更新说明</a-button
                  >
                  <a-button
                    v-if="record.soft.lockFlag !== -1 ? canLock : isTester"
                    type="primary"
                    @click="lock(record)"
                    >{{ record.soft.lockFlag ? "解锁" : "锁定" }}</a-button
                  >
                  <a-button
                    v-if="canUploadSoftware"
                    type="primary"
                    @click="handleEmailShow(record)"
                    >邮件通知</a-button
                  >
                  <a-button
                    type="primary"
                    :disabled="!isTester"
                    @click="handleConfirmDelete(record)"
                    >删除</a-button
                  >
                </a-space>
                <a>更多</a>
              </a-popover>
            </template>
          </advance-table>
        </a-card>
@@ -75,25 +110,40 @@
      :visible="uploadShow"
      :footer="null"
      :width="760"
      title="上传软件"
      :title="onlyXls ? '更新发布说明' : '上传软件'"
      :destroyOnClose="true"
      :maskClosable="false"
      @cancel="uploadCancel"
    >
      <div class="">
        <a-row v-if="!onlyXls" type="flex" class="row">
          <a-col flex="6em" class="label">软件包</a-col>
          <a-col :flex="1">
            <a-upload
              class="upload"
              :before-upload="beforeUpload"
              @change="uploadChange"
              accept=".zip"
            >
              <a-button type="primary">选择软件</a-button>
            </a-upload>
          </a-col>
        </a-row>
        <template v-if="!onlyXls">
          <a-row type="flex" class="row">
            <a-col flex="6em" class="label">更新时间</a-col>
            <a-col :flex="1">
              <a-date-picker
                format="YYYY-MM-DD HH:mm:ss"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                :allowClear="false"
                :disabled-date="disabledDate"
                :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                v-model="versionTime"
              />
            </a-col>
          </a-row>
          <a-row type="flex" class="row">
            <a-col flex="6em" class="label">软件包</a-col>
            <a-col :flex="1">
              <a-upload
                class="upload"
                :before-upload="beforeUpload"
                @change="uploadChange"
                accept=".zip,.rar"
              >
                <a-button type="primary">选择软件</a-button>
              </a-upload>
            </a-col>
          </a-row>
        </template>
        <a-row type="flex" class="row">
          <a-col flex="6em" class="label">软件说明</a-col>
          <a-col :flex="1">
@@ -113,10 +163,56 @@
        </div>
        <div class="modal-footer">
          <a-button type="danger" @click="uploadCancel"> 取消 </a-button>
          <a-button v-if="!onlyXls" type="primary" @click="uploadSoftware"> 提交 </a-button>
          <a-button v-if="!onlyXls" type="primary" @click="uploadSoftware">
            提交
          </a-button>
          <a-button v-else type="primary" @click="applyModel"> 提交 </a-button>
        </div>
      </div>
    </a-modal>
    <pop
      :visible.sync="popVisible"
      :x="popPosition.x"
      :y="popPosition.y"
      :info="popInfo"
      :position="popPosition.dir"
    ></pop>
    <!-- 操作原因 -->
    <a-modal
      :visible="reasonVisible"
      :width="460"
      title="操作原因"
      :destroyOnClose="true"
      :maskClosable="false"
      @cancel="reasonCancel"
      @ok="reasonOk"
    >
      <a-form-model-item ref="name" label="操作原因">
        <a-input
          type="textarea"
          v-model="reason"
          placeHolder="请输入操作原因"
        />
      </a-form-model-item>
    </a-modal>
    <!-- 上传软件 -->
    <a-modal
      :visible="emailShow"
      :footer="null"
      :width="760"
      title="邮件发送"
      :destroyOnClose="true"
      :maskClosable="false"
      @cancel="emailCancel"
    >
      <email-card
        :visible.sync="emailShow"
        :users="userList"
        :title="emailInfo.title"
        :content="emailInfo.content"
        v-if="emailShow"
      ></email-card>
    </a-modal>
  </div>
</template>
@@ -126,20 +222,50 @@
import checkPermit from "@/assets/js/tools/checkPermit";
import PERMITS from "@/assets/js/const/const_permits";
import DescRes from "./descRes";
import Pop from "./pop";
import offset from "@/assets/js/tools/offset";
import moment from "moment";
import { getUserList } from "../../permission/apis";
import { message, Modal } from "ant-design-vue";
import {
  getList,
  downLoadSoftware,
  excelParse,
  productSoftwareSubmit,
  applyModel
  applyModel,
  updateSoftwareLock,
  deleteSoftwareApi,
} from "./apis";
import { mapGetters } from "vuex";
import EmailCard from "../../components/emailCard";
import {
  searchDefaultMailUser,
  sendMail,
} from "../../components/emailCard/apis";
import { getRoleUser } from "@/pages/user/apis";
// TODO
// const tester = ["李桂华"];
export default {
  name: "",
  data() {
    return {
      mailList: [],
      tester: [],
      versionTime: moment().format("YYYY-MM-DD HH:mm:ss"),
      reasonVisible: false,
      reason: "",
      currentObj: null,
      popVisible: false,
      popPosition: {
        x: 0,
        y: 0,
        dir: "bottom",
      },
      popInfo: [],
      onlyXls: false,
      resData: [],
      file: null,
@@ -155,10 +281,53 @@
      conditions: {},
      columns: [
        {
          fixed: "left",
          title: "序号",
          dataIndex: "dataIndex",
          key: "dataIndex",
          align: "center",
          width: 60,
          noSearch: true,
          scopedSlots: { customRender: "dataIndex" },
        },
        {
          title: "状态",
          dataIndex: "soft.lockFlag",
          dataType: "select",
          align: "center",
          width: 140,
          visible: false,
          searchAble: true,
          noSearch: true,
          search: {
            default: 0,
            selectOptions: [
              {
                title: "全部",
                value: 11,
              },
              {
                title: "可用",
                value: 0,
              },
              {
                title: "不可用",
                value: 12,
              },
              {
                title: "待测试",
                value: -1,
              },
            ],
          },
          // customCell: this.customCell,
        },
        {
          title: "名称",
          dataIndex: "soft.fileName",
          align: "center",
          searchAble: true,
          customCell: this.customCell,
        },
        {
          title: "类型",
@@ -166,12 +335,14 @@
          align: "center",
          width: 180,
          noSearch: true,
          customCell: this.customCell,
        },
        {
          title: "版本",
          dataIndex: "soft.version",
          align: "center",
          noSearch: true,
          customCell: this.customCell,
        },
        {
          title: "负责人",
@@ -179,6 +350,7 @@
          align: "center",
          searchAble: true,
          width: 160,
          customCell: this.customCell,
        },
        {
          title: "适用机型号",
@@ -195,10 +367,25 @@
          visible: false,
        },
        {
          title: "板号",
          dataIndex: "soft.boardNumber",
          align: "center",
          searchAble: true,
          customCell: this.customCell,
        },
        {
          title: "升级说明",
          dataIndex: "soft.releaseNotes",
          align: "center",
          noSearch: true,
          customCell: this.customCell,
        },
        {
          title: "最后一次操作原因",
          dataIndex: "soft.localReason",
          align: "center",
          noSearch: true,
          customCell: this.customCell,
        },
        {
          title: "操作",
@@ -226,16 +413,36 @@
          noSearch: true,
        },
      ],
      emailShow: false,
      emailInfo: {
        title: "",
        content: "",
      },
      userList: [],
    };
  },
  components: {
    EmailCard,
    AdvanceTable,
    DescRes,
    Pop,
  },
  methods: {
    moment,
    rowClassFn(record) {
      let classList = [];
      if (record.soft.lockFlag == -1) {
        classList.push("locked");
      }
      return classList;
    },
    disabledDate(current) {
      // Can not select days before today and today
      return current > moment().endOf("day");
    },
    onSearch(conditions, searchOptions) {
      // console.log(conditions);
      // console.log(searchOptions);
      // console.log(searchOptions, "options");
      this.pageCurr = 1;
      this.conditions = conditions;
      this.searchData();
@@ -255,19 +462,29 @@
      this.searchData();
    },
    onReset(conditions) {
      // console.log(conditions, "reset");
      this.conditions = conditions;
      this.searchData();
    },
    searchData() {
      const { pageCurr, pageSize, conditions } = this;
      let params = {};
      if (undefined == conditions["soft.lockFlag"]) {
        conditions["soft.lockFlag"] = 11;
      }
      Object.keys(conditions).forEach((v) => {
        switch (v) {
          case "soft.lockFlag":
            params["lockFlag"] = conditions[v];
            break;
          case "soft.fileName":
            params[v] = conditions["fileName"];
            params["fileName"] = conditions[v];
            break;
          case "soft.owner":
            params[v] = conditions["owner"];
            params["owner"] = conditions[v];
            break;
          case "soft.boardNumber":
            params["boardNumber"] = conditions[v];
            break;
          default:
            params[v] = conditions[v];
@@ -299,6 +516,7 @@
    },
    download(obj) {
      const { id } = obj;
      let loading = this.$layer.loading();
      downLoadSoftware(id).then((res) => {
        // console.log(res, "===========");
        let { headers, data, status } = res;
@@ -314,9 +532,11 @@
          link.download = fileName;
          document.body.appendChild(link);
          link.click();
          this.$layer.close(loading);
          document.body.removeChild(link);
          window.URL.revokeObjectURL(url);
        } else {
          this.$layer.close(loading);
          this.$message.error("操作失败");
        }
      });
@@ -334,6 +554,7 @@
      this.file1 = null;
      this.resData = [];
      this.onlyXls = false;
      this.versionTime = moment().format("YYYY-MM-DD HH:mm:ss");
      this.uploadShow = true;
    },
    updateDesc() {
@@ -378,7 +599,7 @@
          list = data2;
          this.$message.success(msg);
        } else {
          this.$message.error(msg);
          this.$message.error("解析失败");
        }
        this.resData = list;
      });
@@ -399,11 +620,20 @@
        this.$message.error("软件说明文件解析异常");
        return false;
      }
      let info = this.resData[0];
      if (!info.boardNumber || !info.type) {
        this.$error({
          title: "系统提示",
          content: "缺少板号或软件类型,请输入板号和软件类型",
        });
        return false;
      }
      let loading = this.$layer.loading();
      const formData = new FormData();
      formData.append("file1", this.file);
      formData.append("file2", this.file1);
      formData.append("fontUpdateTime", this.versionTime);
      formData.append("softwareStr", JSON.stringify(this.resData));
      productSoftwareSubmit(formData)
        .then((res) => {
@@ -444,7 +674,7 @@
            this.$message.success(msg);
            this.searchData();
          } else {
            this.$message.error(msg);
            this.$message.error("解析失败");
          }
          this.$layer.close(loading);
        })
@@ -452,6 +682,205 @@
          this.$layer.close(loading);
          console.log(error);
        });
    },
    cellMouseenter(e, obj) {
      // console.log("enter", e, obj);
      const wraper = this.$refs.wraper;
      const { clientHeight, clientWidth } = wraper;
      const { target, clientX, clientY } = e;
      let { left: x, top: y } = offset(wraper);
      x = clientX - x;
      y = clientY - y;
      // 如果clientHeight 小于380 * 2 则左右布局
      let dir = "bottom";
      if (clientHeight < 380 * 2) {
        if (x + 420 + 18 > clientWidth) {
          dir = "left";
        } else {
          dir = "right";
        }
        if (y < 180) {
          y = 180;
        } else if (y > clientHeight - 378) {
          y = clientHeight / 2;
        }
      } else {
        if (y + 18 + 360 > clientHeight) {
          // y = clientHeight - 378;
          dir = "top";
        } else {
          dir = "bottom";
        }
        if (x < 300) {
          x = 300;
        }
        if (x + 300 > clientWidth) {
          x = clientWidth - 300;
        }
      }
      this.popPosition.x = x;
      this.popPosition.y = y;
      this.popPosition.dir = dir;
      this.popInfo = obj.links;
      this.popVisible = true;
    },
    cellMouseleave(e, obj) {
      // console.log("leave", obj);
      this.popVisible = false;
    },
    customCell(record) {
      return {
        on: {
          mouseenter: (e) => this.cellMouseenter(e, record),
          mouseleave: (e) => this.cellMouseleave(e, record),
        },
      };
    },
    reasonCancel() {
      this.reasonVisible = false;
    },
    reasonOk() {
      let {
        soft: { fileUrl, lockFlag },
      } = this.currentObj;
      // 多传一个当前状态
      let lockFlagNow = lockFlag;
      lockFlag = !lockFlag * 1;
      let params = {
        fileUrl,
        localReason: this.reason,
        lockFlag,
        lockFlagNow,
      };
      updateSoftwareLock(params).then((res) => {
        const { code, data } = res.data;
        if (code && data) {
          this.$message.success("操作成功");
          this.reasonVisible = false;
          // 如果是测试人员解锁确认 则自动发送邮件
          if (lockFlagNow == -1 && this.isTester) {
            this.sendEmail();
          }
          this.searchData();
        } else {
          this.$message.error("操作失败");
        }
      });
    },
    sendEmail() {
      let { title, content } = this.handleEmailShow(this.currentObj, true);
      let params = { mailList: this.mailList, title, content };
      sendMail(params);
    },
    lock(record) {
      this.reason = "";
      this.currentObj = record;
      this.reasonVisible = true;
    },
    handleEmailShow(record, get) {
      this.emailInfo.title =
        "[软件发布记录]" +
        record.soft.fileName +
        " 版本号:" +
        record.soft.version;
      let { soft, links } = record;
      let content = [];
      content.push("软件基本信息");
      content.push("文件名称: " + soft.fileName);
      content.push("板号: " + soft.boardNumber);
      content.push("软件类型: " + soft.type);
      content.push("软件版本: " + soft.version);
      content.push("软件基于版本: " + soft.basedVersion);
      content.push("软件负责人: " + soft.owner);
      content.push("归档日期: " + soft.filingDate);
      content.push("软件类型: " + soft.type);
      content.push("软件适用机型");
      links.forEach((v) => {
        content.push(
          "物料编码: " + v.applyMaterialCode + " 规格型号: " + v.applyModel
        );
      });
      content.push("发布说明: " + soft.releaseNotes);
      this.emailInfo.content = content.join("\n");
      if (get) {
        return {
          title: this.emailInfo.title,
          content: content.join("\n"),
        };
      }
      this.emailShow = true;
    },
    emailCancel() {
      this.emailShow = false;
    },
    searchAllUserList() {
      getUserList()
        .then((res) => {
          let rs = res.data;
          if (rs.code && rs.data) {
            this.userList = rs.data2;
            this.searchDefaultMailUser();
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    searchDefaultMailUser() {
      // 软件 type为1
      let type = 1;
      searchDefaultMailUser(type).then((res) => {
        let rs = res.data;
        let data = [];
        if (rs.code === 1) {
          data = rs.data.map((item) => {
            return item.user;
          });
        }
        this.mailList = this.userList
          .filter((o) => data.includes(o.name) && o.mail)
          .map((item) => {
            return item.mail;
          });
      });
    },
    getRoleUser() {
      getRoleUser(0)
        .then((res) => {
          let { code, data, data2 } = res.data;
          let list = [];
          if (code && data) {
            // console.log(data);
            list = data2.map((v) => v.name);
          }
          this.tester = list;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    handleConfirmDelete(obj) {
      Modal.confirm({
        content: () => "删除当前软件,删除后无法恢复,请注意!!!",
        onOk: async () => {
          try {
            const res = await deleteSoftwareApi(
              obj.soft.fileName,
              obj.soft.version
            );
            const rs = res.data;
            if (rs.code === 1 && rs.data) {
              this.$message.success("删除成功。");
            } else {
              this.$message.error("删除失败!!!");
            }
            this.searchData();
          } catch (e) {
            this.$message.error("删除失败,请联系开发人员!!!");
            console.log(e);
          }
        },
      });
    },
  },
  watch: {
@@ -489,7 +918,7 @@
    },
  },
  computed: {
    ...mapGetters("account", ["permits"]),
    ...mapGetters("account", ["permits", "user"]),
    ...mapGetters("setting", ["affixed"]),
    canUploadSoftware() {
      return checkPermit(PERMITS.uploadSoftware, this.permits);
@@ -497,9 +926,17 @@
    canDownloadSoftware() {
      return checkPermit(PERMITS.downloadSoftware, this.permits);
    },
    canLock() {
      return checkPermit(PERMITS.lockOther, this.permits);
    },
    isTester() {
      return this.tester.some((v) => v == this.user.name);
    },
  },
  mounted() {
    this.getRoleUser();
    this.searchData();
    this.searchAllUserList();
    window.addEventListener("resize", this.resize);
  },
  destroyed() {
@@ -564,4 +1001,14 @@
  overflow-y: auto;
  margin-bottom: 10px;
}
</style>
.btn-grp button {
  width: 6.4em;
}
/deep/.locked > td {
  background: #fec54b;
}
/deep/.locked.locked.locked.ant-table-row-hover > td,
/deep/.locked.locked.locked:hover > td {
  background: #fcd583;
}
</style>