fix: 修复非管理权限下的导出和状态改变

This commit is contained in:
wangdan-fit2cloud 2024-12-10 16:06:01 +08:00
parent adad526a4f
commit 8d9a14a15f
3 changed files with 49 additions and 35 deletions

View File

@ -225,8 +225,9 @@ export const exportExcel: (
params: any, params: any,
loading?: NProgress | Ref<boolean> loading?: NProgress | Ref<boolean>
) => { ) => {
return promise(request({ url: url, method: 'get', params, responseType: 'blob' }), loading) return promise(request({ url: url, method: 'get', params, responseType: 'blob' }), loading).then(
.then((res: any) => { (res: any) => {
console.log(res)
if (res) { if (res) {
const blob = new Blob([res], { const blob = new Blob([res], {
type: 'application/vnd.ms-excel' type: 'application/vnd.ms-excel'
@ -239,8 +240,8 @@ export const exportExcel: (
window.URL.revokeObjectURL(link.href) window.URL.revokeObjectURL(link.href)
} }
return true return true
}) }
.catch((e) => {}) )
} }
export const exportExcelPost: ( export const exportExcelPost: (
@ -265,22 +266,20 @@ export const exportExcelPost: (
responseType: 'blob' responseType: 'blob'
}), }),
loading loading
) ).then((res: any) => {
.then((res: any) => { if (res) {
if (res) { const blob = new Blob([res], {
const blob = new Blob([res], { type: 'application/vnd.ms-excel'
type: 'application/vnd.ms-excel' })
}) const link = document.createElement('a')
const link = document.createElement('a') link.href = window.URL.createObjectURL(blob)
link.href = window.URL.createObjectURL(blob) link.download = fileName
link.download = fileName link.click()
link.click() // 释放内存
// 释放内存 window.URL.revokeObjectURL(link.href)
window.URL.revokeObjectURL(link.href) }
} return true
return true })
})
.catch((e) => {})
} }
export const download: ( export const download: (

View File

@ -187,9 +187,10 @@
<template #default="{ row }"> <template #default="{ row }">
<div @click.stop> <div @click.stop>
<el-switch <el-switch
:loading="loading"
size="small" size="small"
v-model="row.is_active" v-model="row.is_active"
@change="changeState($event, row)" :before-change="() => changeState(row)"
/> />
</div> </div>
</template> </template>
@ -678,18 +679,24 @@ function deleteDocument(row: any) {
更新名称或状态 更新名称或状态
*/ */
function updateData(documentId: string, data: any, msg: string) { function updateData(documentId: string, data: any, msg: string) {
documentApi.putDocument(id, documentId, data, loading).then((res) => { documentApi
const index = documentData.value.findIndex((v) => v.id === documentId) .putDocument(id, documentId, data, loading)
documentData.value.splice(index, 1, res.data) .then((res) => {
MsgSuccess(msg) const index = documentData.value.findIndex((v) => v.id === documentId)
}) documentData.value.splice(index, 1, res.data)
MsgSuccess(msg)
return true
})
.catch(() => {
return false
})
} }
function changeState(bool: Boolean, row: any) { function changeState(row: any) {
const obj = { const obj = {
is_active: bool is_active: !row.is_active
} }
const str = bool ? '启用成功' : '禁用成功' const str = !row.is_active ? '启用成功' : '禁用成功'
currentMouseId.value && updateData(row.id, obj, str) currentMouseId.value && updateData(row.id, obj, str)
} }

View File

@ -104,8 +104,9 @@
> >
<div class="active-button" @click.stop> <div class="active-button" @click.stop>
<el-switch <el-switch
:loading="loading"
v-model="item.is_active" v-model="item.is_active"
@change="changeState($event, item)" :before-change="() => changeState(item)"
size="small" size="small"
/> />
</div> </div>
@ -162,7 +163,6 @@
<ParagraphDialog ref="ParagraphDialogRef" :title="title" @refresh="refresh" /> <ParagraphDialog ref="ParagraphDialogRef" :title="title" @refresh="refresh" />
<SelectDocumentDialog ref="SelectDocumentDialogRef" @refresh="refreshMigrateParagraph" /> <SelectDocumentDialog ref="SelectDocumentDialogRef" @refresh="refreshMigrateParagraph" />
<GenerateRelatedDialog ref="GenerateRelatedDialogRef" @refresh="refresh" /> <GenerateRelatedDialog ref="GenerateRelatedDialogRef" @refresh="refresh" />
</LayoutContainer> </LayoutContainer>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@ -258,11 +258,20 @@ function searchHandle() {
getParagraphList() getParagraphList()
} }
function changeState(bool: Boolean, row: any) { function changeState(row: any) {
const obj = { const obj = {
is_active: bool is_active: !row.is_active
} }
paragraph.asyncPutParagraph(id, documentId, row.id, obj, changeStateloading).then((res) => {}) paragraph
.asyncPutParagraph(id, documentId, row.id, obj, changeStateloading)
.then((res) => {
const index = paragraphDetail.value.findIndex((v) => v.id === row.id)
paragraphDetail.value[index].is_active = !paragraphDetail.value[index].is_active
return true
})
.catch(() => {
return false
})
} }
function deleteParagraph(row: any) { function deleteParagraph(row: any) {
@ -328,7 +337,6 @@ function refresh(data: any) {
} }
} }
const GenerateRelatedDialogRef = ref() const GenerateRelatedDialogRef = ref()
function openGenerateDialog(row?: any) { function openGenerateDialog(row?: any) {
const arr: string[] = [] const arr: string[] = []