maven
2025-08-08 f139849fb65e7264d173bc46f45d70409e559504
src/views/collaborativeApproval/approvalProcess/components/approvalDia.vue
@@ -102,6 +102,10 @@
              <div v-if="!activity.isShen" class="node-reason">
                <span>审批意见:</span>{{ activity.approveNodeReason }}
              </div>
              <div v-if="!activity.isShen" class="node-reason">
                <span>签名:</span>
                        <img :src="activity.urlTem" class="signImg" alt="" v-if="activity.urlTem"/>
              </div>
              <div v-else-if="activity.isShen">
                <el-form-item
                  :prop="'activities.' + index + '.approveNodeReason'"
@@ -117,16 +121,33 @@
      <template #footer v-if="operationType === 'approval'">
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm(2)">不通过</el-button>
          <el-button type="primary" @click="submitForm(1)">通过</el-button>
          <el-button type="primary" @click="openSignatureDialog(1)">通过</el-button>
          <el-button @click="closeDia">取消</el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 电子签名弹窗(vue3-signature-pad) -->
    <el-dialog v-model="signatureDialogVisible" title="电子签名" width="600px" append-to-body>
         <vueEsign
            ref="esign"
            class="mySign"
            :width="800"
            :height="300"
            :isCrop="isCrop"
            :lineWidth="lineWidth"
            :lineColor="lineColor"
         />
      <div style="margin-top:10px;">
        <el-button @click="clearSignature">清除</el-button>
        <el-button type="primary" @click="confirmSignature">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script setup>
import {getCurrentInstance, reactive, ref, toRefs} from "vue";
import { getCurrentInstance, reactive, ref, toRefs } from "vue";
import vueEsign from "vue-esign";
import {
   approveProcessDetails,
   getDept,
@@ -135,6 +156,7 @@
import useUserStore from "@/store/modules/user.js";
import {userListNoPageByTenantId} from "@/api/system/user.js";
import { WarningFilled, Edit, Check, MoreFilled } from '@element-plus/icons-vue'
import { getToken } from "@/utils/auth";
const emit = defineEmits(['close'])
const { proxy } = getCurrentInstance()
@@ -156,6 +178,22 @@
   },
});
const { form } = toRefs(data);
const signatureDialogVisible = ref(false);
const signatureImg = ref('');
let submitStatus = null; // 临时存储通过/不通过状态
const isCrop = ref("");
const esign = ref(null);
const lineWidth = ref(0);
const lineColor = ref("#000000");
// 上传配置
const upload = reactive({
  // 上传的地址
  url: import.meta.env.VITE_APP_BASE_API + "/file/upload",
  // 设置上传的请求头部
  headers: { Authorization: "Bearer " + getToken() },
});
// 节点标题
const getNodeTitle = (index, len) => {
  if (index === len - 1) return '结束';
@@ -190,6 +228,11 @@
    activities.value = res.data
    // 增加isApproval字段
    activities.value.forEach(item => {
         if (item.url.includes('word')) {
            item.urlTem = item.url.replaceAll('word', 'img')
         } else {
            item.urlTem = item.url
         }
      if (item.approveNodeStatus === 2) {
        item.isApproval = '已驳回';
      } else if (item.approveNodeStatus === 1) {
@@ -205,17 +248,84 @@
      productOptions.value = res.data;
   });
};
// 打开签名弹窗
const openSignatureDialog = (status) => {
  submitStatus = status;
  signatureDialogVisible.value = true;
};
// 清除签名
const clearSignature = () => {
   esign.value.reset();
};
// 确认签名
const confirmSignature = () => {
   esign.value.generate().then((res) => {
      console.log(res);
      // 将base64转换为二进制
      const base64Data = res.split(',')[1]; // 移除data:image/png;base64,前缀
      const binaryString = atob(base64Data);
      const bytes = new Uint8Array(binaryString.length);
      for (let i = 0; i < binaryString.length; i++) {
         bytes[i] = binaryString.charCodeAt(i);
      }
      signatureImg.value = bytes;
      // 创建文件对象用于上传
      const blob = new Blob([bytes], { type: 'image/png' });
      const file = new File([blob], 'signature.png', { type: 'image/png' });
      // 创建FormData
      const formData = new FormData();
      formData.append('file', file);
      // 上传签名图片
      fetch(upload.url, {
         method: 'POST',
         headers: upload.headers,
         body: formData
      })
      .then(response => response.json())
      .then(data => {
         if (data.code === 200) {
            console.log('data---', data)
            let tempFileIds = [];
            tempFileIds.push(data.data.tempId);
            signatureDialogVisible.value = false;
            clearSignature();
            // 只有通过时才传递签名文件ID
            if (submitStatus === 1) {
               submitForm(submitStatus, tempFileIds);
            } else {
               submitForm(submitStatus);
            }
         } else {
            proxy.$modal.msgError("签名图片上传失败:" + data.msg);
         }
      })
      .catch(error => {
         console.error('上传失败:', error);
         proxy.$modal.msgError("签名图片上传失败");
      });
   }).catch((err) => {
      console.log(err);
      proxy.$modal.msgWarning("请先签名!");
   })
};
// 提交审批
const submitForm = (status) => {
const submitForm = (status, tempFileIds) => {
  const filteredActivities = activities.value.filter(activity => activity.isShen);
  filteredActivities[0].approveNodeStatus = status
  filteredActivities[0].approveNodeStatus = status;
  // 只有通过时才需要签名
  if (status === 1 && tempFileIds) {
    filteredActivities[0].tempFileIds = tempFileIds;
  }
  // 判断是否为最后一步
  const isLast = activities.value.findIndex(a => a.isShen) === activities.value.length-1;
  updateApproveNode({ ...filteredActivities[0], isLast }).then(() => {
    proxy.$modal.msgSuccess("提交成功");
    closeDia();
  })
}
  });
};
// 关闭弹框
const closeDia = () => {
  proxy.resetForm("formRef");
@@ -253,4 +363,9 @@
   height: 30px;
   border-radius: 50px;
}
.signImg {
   cursor: pointer;
   width: 200px;
   height: 60px;
}
</style>