Browse Source

优化请求和删除弹窗

ZaiZai 1 year ago
parent
commit
63f6bf5d7e

+ 1 - 1
package.json

@@ -18,7 +18,7 @@
         "dayjs": "^1.11.10",
         "echarts": "^5.5.0",
         "element-plus": "^2.6.1",
-        "hc-vue3-ui": "^3.4.6",
+        "hc-vue3-ui": "^3.4.7",
         "js-base64": "^3.7.7",
         "js-cookie": "^3.0.5",
         "js-fast-way": "^0.4.6",

+ 0 - 63
src/components/message/index.js

@@ -1,63 +0,0 @@
-import { h } from 'vue'
-import domView from './index.vue'
-
-//删除提醒
-export const delMessageV2 = (cbk) => {
-    window?.$messageBox({
-        center: true,
-        message: () => h(domView, {
-            type: 'delete',
-            title: '确认删除提醒',
-            text: '请谨慎考虑后,确认是否需要删除?',
-        }),
-        customClass: 'hc-message-view-box',
-        showCancelButton: true,
-        confirmButtonText: '确认删除',
-        cancelButtonText: '取消操作',
-        beforeClose: (action, instance, done) => {
-            if (cbk) {
-                cbk(action, instance, done)
-            } else {
-                done()
-            }
-        },
-    })
-}
-
-//请求异常
-export const apiErrorMessage = () => {
-    setTimeout(() => {
-        const doms = document.querySelector('.hc-message-view-box.warning')
-        if (doms) return
-        window?.$messageBox({
-            center: true,
-            message: () => h(domView, {
-                type: 'warning',
-                title: '服务器异常,请稍后重试',
-                text: '服务器异常了,如有需要,请联系管理员!',
-            }),
-            customClass: 'hc-message-view-box warning',
-            showCancelButton: false,
-            confirmButtonText: '关闭',
-        })
-    }, 1000)
-}
-
-//请求异常
-export const apiWarningMessage = () => {
-    setTimeout(() => {
-        const doms = document.querySelector('.hc-message-view-box.warning')
-        if (doms) return
-        window?.$messageBox({
-            center: true,
-            message: () => h(domView, {
-                type: 'warning',
-                title: '正在升级优化,请稍后重试',
-                text: '该功能正在升级优化,请联系管理员',
-            }),
-            customClass: 'hc-message-view-box warning',
-            showCancelButton: false,
-            confirmButtonText: '关闭',
-        })
-    }, 1000)
-}

+ 0 - 84
src/components/message/index.vue

@@ -1,84 +0,0 @@
-<template>
-    <div class="hc-message-box">
-        <div class="hc-lottie-box delete">
-            <HcLottie v-if="isType === 'delete'" type="delete" style="height: 200px" />
-            <HcLottie v-if="isType === 'warning'" type="warning" style="height: 140px" />
-        </div>
-        <div class="title">
-            {{ titles }}
-        </div>
-        <div class="text">
-            {{ text }}
-        </div>
-    </div>
-</template>
-
-<script setup>
-import { ref, watch } from 'vue'
-//参数
-const props = defineProps({
-    type: {
-        type: String,
-        default: 'warning',
-    },
-    title: {
-        type: String,
-        default: '',
-    },
-    text: {
-        type: String,
-        default: '',
-    },
-})
-
-//监听
-watch(() => [
-    props.type,
-    props.title,
-    props.text,
-], ([type, title, text]) => {
-    isType.value = type
-    titles.value = title
-    texts.value = text
-})
-
-//变量
-const isType = ref(props.type)
-const titles = ref(props.title)
-const texts = ref(props.text)
-</script>
-
-<style scoped lang="scss">
-.hc-message-box {
-    position: relative;
-    .hc-lottie-box {
-        position: relative;
-        height: 200px;
-        overflow: hidden;
-        display: flex;
-        align-items: center;
-        justify-content: center;
-    }
-    .title {
-        position: relative;
-        font-size: 20px;
-        color: #101010;
-        margin-bottom: 20px;
-    }
-    .text {
-        color: #878a99;
-        font-size: 14px;
-        margin-bottom: 10px;
-    }
-}
-
-//深色模式
-html.dark .hc-message-box {
-    .title {
-        color:white;
-    }
-    .text {
-        color:white;
-    }
-}
-</style>

+ 12 - 17
src/components/tree/hc-tree.vue

@@ -58,7 +58,7 @@ import { getArchiveTreeLazyTree, initTree } from '~api/other'
 import { getArrValue, getObjValue, isArrItem, isNullES } from 'js-fast-way'
 import EditNodeDialog from '~src/components/dialog/EditNodeDialog.vue'
 import SortNodeDialog from '~src/components/dialog/SortNodeDialog.vue'
-import { delMessageV2 } from '~com/message/index.js'
+import { HcDelMsg } from 'hc-vue3-ui'
 import initialgApi from '~api/initial/initial'
 
 //参数
@@ -492,22 +492,17 @@ const sortDialogHide = ()=>{
 
 
 //删除节点
-const delNodeMoadl = (node)=>{
-    delMessageV2(async (action, instance, done) => {
-            if (action === 'confirm') {
-                instance.confirmButtonLoading = true
-                const { code } = await remove({
-                    id:node.data.id,
-                })
-                if (code === 200) {
-                    window.$message?.success('删除成功')
-                    ElTreeRef.value.remove(node)
-                }
-                instance.confirmButtonLoading = false
-                done()
-            } else {
-                done()
-            }
+const delNodeMoadl = (node) => {
+    HcDelMsg({}, async (instance, resolve) => {
+        instance.confirmButtonLoading = true
+        instance.confirmButtonText = '删除中...'
+        const { code } = await remove({ id: node.data.id })
+        if (code === 200) {
+            window.$message?.success('删除成功')
+            ElTreeRef.value.remove(node)
+        }
+        resolve() //关闭弹窗的回调
+        instance.confirmButtonLoading = false
     })
 }
 

+ 0 - 108
src/global/components/echarts/echarts.vue

@@ -1,108 +0,0 @@
-<template>
-    <div class="hc-echarts-box">
-        <div ref="echart" class="hc-echarts" :style="`width : ${chart?.clientWidth}px`" />
-    </div>
-</template>
-
-<script setup>
-import * as echarts from 'echarts'
-import { getObjValue } from 'js-fast-way'
-import { onMounted, onUnmounted, ref, watch } from 'vue'
-const props = defineProps({
-    option: {
-        type: Object,
-        default: () => ({}),
-    },
-    dark: {
-        type: Boolean,
-        default: false,
-    },
-})
-
-defineOptions({
-    name: 'HcCharts',
-})
-
-//初始变量
-let chart = null
-const echart = ref(null)
-const options = ref(getObjValue(props.option))
-
-//深度监听
-watch(() => [
-    props.option,
-], ([option]) => {
-    options.value = getObjValue(option)
-    setOptions(options.value)
-}, { deep: true })
-
-//初始化图表
-const initChart = () => {
-    chart = echarts.init(echart.value, props.dark ? 'dark' : 'light')
-    setOptions(options.value)
-}
-
-//监听浏览器窗口变化
-const windowResize = () => {
-    window.addEventListener('resize', resizeEvent)
-}
-
-const resizeEvent = () => {
-    window.requestAnimationFrame(() => {
-        chart.resize()
-    })
-}
-
-//设置图表
-const setOptions = (option) => {
-    chart?.setOption(option)
-}
-
-//渲染完成
-onMounted(() => {
-    initChart()
-    windowResize()
-    setTimeout(() => {
-        chart?.resize()
-    }, 500)
-})
-
-//被卸载
-onUnmounted(() => {
-    window.removeEventListener('resize', resizeEvent)
-    chart.dispose()
-    chart = null
-})
-
-const getWidth = () => {
-    return chart?.getWidth()
-}
-
-const onResize = () => {
-    chart?.resize()
-}
-
-// 暴露出去
-defineExpose({
-    onResize,
-    getWidth,
-})
-</script>
-
-<style lang="scss" scoped>
-.hc-echarts-box {
-    display: block;
-    height: 100%;
-    overflow: hidden;
-    position: relative;
-    .hc-echarts {
-        position: absolute;
-        bottom: 0;
-        left: 0;
-        right: 0;
-        z-index: 2;
-        width: 100%;
-        height: 100%;
-    }
-}
-</style>

+ 0 - 2
src/global/components/index.js

@@ -4,7 +4,6 @@ import HcReportModal from './hc-report-modal/index.vue'
 import HcReportExperts from './hc-report-experts/index.vue'
 import HcTasksUser from './hc-tasks-user/index.vue'
 import HcBorderNeon from './hc-border-neon/index.vue'
-import HcCharts from './echarts/echarts.vue'
 import HcPdfs from './hc-pdfs/pdfs.vue'
 
 //注册全局组件
@@ -15,6 +14,5 @@ export const setupComponents = (App) => {
     App.component('HcReportExperts', HcReportExperts)
     App.component('HcTasksUser', HcTasksUser)
     App.component('HcBorderNeon', HcBorderNeon)
-    App.component('HcCharts', HcCharts)
     App.component('HcPdfs', HcPdfs)
 }

+ 26 - 32
src/views/file/collection.vue

@@ -416,7 +416,7 @@ import HcTree from '~src/components/tree/hc-tree.vue'
 import HcReport from './components/HcReport.vue'
 import notableform from '~src/assets/view/notableform.svg'
 import { rowsToId } from '~uti/tools'
-import { delMessageV2 } from '~com/message/index.js'
+import { HcDelMsg } from 'hc-vue3-ui'
 import archiveFileApi from '~api/archiveFile/archiveFile'
 import tasksFlowApi from '~api/tasks/flow'
 import { arrKeySort, arrToId, deepClone, getArrValue, getObjVal } from 'js-fast-way'
@@ -891,22 +891,19 @@ const sortingDelData = (row, index) => {
     //过滤掉当前选择的文件
     checkList.value = checkList.value.filter(e => e.tableindex !== index)
     if (row.boxNumber) {
-        delMessageV2(async (action, instance, done) => {
-            if (action === 'confirm') {
-                instance.confirmButtonLoading = true
-                    const { error, code } = await archiveFileApi.removeAllocation({
-                        boxName: row.boxName,
-                        boxNumber:row.boxNumber,
-                    })
-                    if (!error && code === 200) {
-                        window.$message?.success('删除成功!')
-                        sortingClick()
-                    }
-                instance.confirmButtonLoading = false
-                done()
-            } else {
-                done()
+        HcDelMsg({}, async (instance, resolve) => {
+            instance.confirmButtonLoading = true
+            instance.confirmButtonText = '删除中...'
+            const { error, code } = await archiveFileApi.removeAllocation({
+                boxName: row.boxName,
+                boxNumber:row.boxNumber,
+            })
+            if (!error && code === 200) {
+                window.$message?.success('删除成功!')
+                sortingClick()
             }
+            resolve() //关闭弹窗的回调
+            instance.confirmButtonLoading = false
         })
     }
 }
@@ -1012,7 +1009,7 @@ const sortingModalClose = () => {
 }
 
 //删除
-const delModalClick = async () => {
+const delModalClick = () => {
     const rows = tableCheckedKeys.value
     //待审批,已审批都不能删除
     const result = rows.some(({ isApprovalValue }) => {
@@ -1025,22 +1022,19 @@ const delModalClick = async () => {
     if (rows.length <= 0) {
         window.$message?.error('请选择需要删除的数据')
     } else {
-        delMessageV2(async (action, instance, done) => {
-            if (action === 'confirm') {
-                instance.confirmButtonLoading = true
-                const keys = arrToId(rows)
-                const { error, code } = await archiveFileApi.removeFile({
-                    ids: keys,
-                })
-                if (!error && code === 200) {
-                    window.$message?.success('删除成功!')
-                    searchClick()
-                }
-                instance.confirmButtonLoading = false
-                done()
-            } else {
-                done()
+        HcDelMsg({}, async (instance, resolve) => {
+            instance.confirmButtonLoading = true
+            instance.confirmButtonText = '删除中...'
+            const keys = arrToId(rows)
+            const { error, code } = await archiveFileApi.removeFile({
+                ids: keys,
+            })
+            if (!error && code === 200) {
+                window.$message?.success('删除成功!')
+                searchClick()
             }
+            resolve() //关闭弹窗的回调
+            instance.confirmButtonLoading = false
         })
     }
 }

+ 15 - 23
src/views/file/records.vue

@@ -18,7 +18,7 @@
                     <el-button hc-btn type="warning" :disabled="tableCheckedKeys.length <= 0" @click="batchEditClick">编辑</el-button>
                 </HcTooltip>
                 <HcTooltip keys="file_records_btn_del">
-                    <el-button hc-btn type="danger" :disabled="tableCheckedKeys.length <= 0" @click="delModalClick">删除</el-button>
+                    <el-button v-del-com:[delModalClick] hc-btn type="danger" :disabled="tableCheckedKeys.length <= 0">删除</el-button>
                 </HcTooltip>
             </template>
             <template #extra>
@@ -270,7 +270,7 @@ import { nextTick, onMounted, ref, watch } from 'vue'
 import { useAppStore } from '~src/store'
 import HcTree from '~src/components/tree/hc-tree.vue'
 import { rowsToId } from '~uti/tools'
-import { delMessageV2 } from '~com/message/index.js'
+import { HcDelMsg } from 'hc-vue3-ui'
 import { getHeader } from 'hc-vue3-ui'
 import archiveFileApi from '~api/archiveFile/archiveFileAuto.js'
 import { getStoreValue, setStoreValue } from '~src/utils/storage'
@@ -722,28 +722,20 @@ const sortingModalClose = () => {
 }
 
 //删除
-const delModalClick = () => {
-    delMessageV2(async (action, instance, done) => {
-            if (action === 'confirm') {
-                instance.confirmButtonLoading = true
-                let ids = []
-                tableCheckedKeys.value.forEach((element)=>{
-                    ids.push(element.id)
-                })
-                const { error, code, data } = await archiveFileApi.remove({
-                    ids:ids.join(','),
-                })
-                //处理数据
-                if (!error && code === 200) {
-                    window.$message?.success('操作成功')
-                    getTableData()
-                }
-                instance.confirmButtonLoading = false
-                done()
-            } else {
-                done()
-            }
+const delModalClick = async (_, resolve) => {
+    let ids = []
+    tableCheckedKeys.value.forEach((element)=>{
+        ids.push(element.id)
     })
+    const { error, code } = await archiveFileApi.remove({
+        ids: ids.join(','),
+    })
+    //处理数据
+    if (!error && code === 200) {
+        window.$message?.success('操作成功')
+        getTableData()
+    }
+    resolve()
 }
 
 

+ 5 - 13
src/views/tasks/flow.vue

@@ -21,7 +21,7 @@
                         <el-button plain size="small" type="primary" @click="handleTableEdit(row)">编辑</el-button>
                     </HcTooltip>
                     <HcTooltip keys="tasks_flow_del">
-                        <el-button plain size="small" type="danger" @click="handleTableDel(row)">删除</el-button>
+                        <el-button v-del-com:[handleTableDel]="row" plain size="small" type="danger">删除</el-button>
                     </HcTooltip>
                 </template>
             </HcTable>
@@ -60,7 +60,7 @@ import { onMounted, ref } from 'vue'
 import { useAppStore } from '~src/store'
 import { getArrValue, getObjValue } from 'js-fast-way'
 import tasksFlowApi from '~api/tasks/flow'
-import { delMessageV2 } from '~com/message/index.js'
+import { HcDelMsg } from 'hc-vue3-ui'
 //变量
 const useAppState = useAppStore()
 const projectId = ref(useAppState.getProjectId)
@@ -197,17 +197,9 @@ const saveFormClick = async () => {
 }
 
 //删除
-const handleTableDel = (row) => {
-    delMessageV2(async (action, instance, done) => {
-            if (action === 'confirm') {
-                instance.confirmButtonLoading = true
-                removeFixedFlowData(row)
-                instance.confirmButtonLoading = false
-                done()
-            } else {
-                done()
-            }
-    })
+const handleTableDel = async ({ item }, resolve) => {
+    await removeFixedFlowData(item)
+    resolve()
 }
 
 //确认删除

+ 7 - 10
src/views/tasks/message-data.vue

@@ -64,7 +64,7 @@ import { useRoute, useRouter } from 'vue-router'
 import messageApi from '~api/tasks/message'
 import { arrToId, getArrValue } from 'js-fast-way'
 import website from '~src/config/index'
-import { delMessageV2 } from '~com/message/index.js'
+import { HcDelMsg } from 'hc-vue3-ui'
 
 //消息数量
 const props = defineProps(
@@ -233,15 +233,12 @@ const tableContent = (row) => {
 const delClick = () => {
     const rows = tableCheckedKeys.value
     if (rows.length > 0) {
-        delMessageV2(async (action, instance, done) => {
-            if (action === 'confirm') {
-                instance.confirmButtonLoading = true
-                removeData(rows)
-                instance.confirmButtonLoading = false
-                done()
-            } else {
-                done()
-            }
+        HcDelMsg({}, async (instance, resolve) => {
+            instance.confirmButtonLoading = true
+            instance.confirmButtonText = '删除中...'
+            await removeData(rows)
+            resolve() //关闭弹窗的回调
+            instance.confirmButtonLoading = false
         })
     } else {
         window.$message?.warning('请先勾选要删除的消息')

+ 20 - 30
src/views/transfer/components/examination/table-opinion.vue

@@ -14,7 +14,7 @@
             <el-button v-else type="primary" size="small" @click="editClick(row)">
                 编辑
             </el-button>
-            <el-button type="danger" size="small" :loading="delLoading" @click="delClick(row)">
+            <el-button v-del-com:[delClick]="row" type="danger" size="small" :loading="delLoading">
                 删除
             </el-button>
         </template>
@@ -25,7 +25,7 @@
 import { onMounted, ref, watch } from 'vue'
 import { getArrValue } from 'js-fast-way'
 import initialgApi from '~api/initial/initial'
-import { delMessageV2 } from '~com/message/index.js'
+import { HcDelMsg } from 'hc-vue3-ui'
 
 //参数
 const props = defineProps({
@@ -81,7 +81,7 @@ const getTableData = async () => {
             ...searchLogForm.value,
             projectId: projectId.value,
             conclusionId:currentId.value,
-     
+
         })
         tableLoading.value = false
         if (!error && code === 200) {
@@ -91,7 +91,7 @@ const getTableData = async () => {
             tableData.value = []
             searchLogForm.value.total = 0
         }
-    
+
 
 }
 const tableLoading = ref(false)
@@ -117,7 +117,7 @@ const saveClick = async (row) => {
     submitLoading.value = false
     if (!error && code === 200) {
         window.$message.success(msg)
-       
+
         getTableData()
 
     } else {
@@ -127,31 +127,21 @@ const saveClick = async (row) => {
 
 //删除('抽检意见传空')
 const delLoading = ref(false)
-const delClick = async (row) => {
-    delMessageV2(async (action, instance, done) => {
-        if (action === 'confirm') {
-            instance.confirmButtonLoading = true
-            delLoading.value = true
-            const { error, code, data, msg } = await initialgApi.saveInspect({
-            ...row,
-            opinion:'',
-
-            })
-            delLoading.value = false
-            if (!error && code === 200) {
-                window.$message.success(msg)
-            
-                getTableData()
-
-            } else {
-                row.opinion = ''
-            }
-            instance.confirmButtonLoading = false
-            done()
-        } else {
-            done()
-        }
-     })
+const delClick = async ({ item }, resolve) => {
+    delLoading.value = true
+    const { error, code, msg } = await initialgApi.saveInspect({
+        ...item,
+        opinion:'',
+    })
+    delLoading.value = false
+    if (!error && code === 200) {
+        window.$message.success(msg)
+        resolve()
+        getTableData()
+    } else {
+        resolve()
+        item.opinion = ''
+    }
 }
 </script>
 

+ 4 - 4
yarn.lock

@@ -1371,10 +1371,10 @@ hasown@^2.0.0:
   dependencies:
     function-bind "^1.1.2"
 
-hc-vue3-ui@^3.4.6:
-  version "3.4.6"
-  resolved "http://39.108.216.210:9000/hc-vue3-ui/-/hc-vue3-ui-3.4.6.tgz#d590df95852ece36a94553a08c7290ef3dc19145"
-  integrity sha512-usCu5o5AIkSVoSvQdMt7Eu8lzbNlu4xi9toDUVjLmgU5Hdqo1ACfOWiXoupRaepAM4usavXWqhX4JCPFYa3F6Q==
+hc-vue3-ui@^3.4.7:
+  version "3.4.7"
+  resolved "http://39.108.216.210:9000/hc-vue3-ui/-/hc-vue3-ui-3.4.7.tgz#1955dc75684030a87dd79b7611d1e545ae6a2f99"
+  integrity sha512-lBOkk9tWt1Kw8YxMlAnOIaD10YfdCzjlDdboNUZdwhIxorFxFkyp1XDS1lBl/GaryyZRmUed4lFmnBUYvVxy8Q==
   dependencies:
     axios "^1.6.7"
     dayjs "^1.11.10"