修正自定义题目无法删除的bug

This commit is contained in:
zhl 2021-06-01 11:01:01 +08:00
parent 5e7a24af26
commit df06dd5501
4 changed files with 35 additions and 15 deletions

View File

@ -14,6 +14,7 @@ export interface IQuestionData {
quality: number quality: number
withNext: boolean withNext: boolean
shop?: string shop?: string
status?: number
} }
export const defaultQuestionData: IQuestionData = { export const defaultQuestionData: IQuestionData = {

View File

@ -34,10 +34,11 @@ export const importQuestions = (shop: string, data: any) =>
data data
}) })
export const deleteShopQuestion = (shop: string, id: string) => export const deleteShopQuestion = (shop: string, ids: string[]) =>
request({ request({
url: `/api/${shop}/puzzle/${id}/delete`, url: `/api/${shop}/puzzle/delete`,
method: 'post' method: 'post',
data: { ids }
}) })
export const getShopCategory = (shop: string) => export const getShopCategory = (shop: string) =>

View File

@ -302,7 +302,7 @@ export default class extends Vue {
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}) })
await deleteShopQuestion(this.postForm.shop!, this.postForm._id!) await deleteShopQuestion(this.postForm.shop!, [this.postForm._id!])
this.loading = false this.loading = false
EventBus.$emit(EVENT_SHOP_PUZZLES_UPDATE, {}) EventBus.$emit(EVENT_SHOP_PUZZLES_UPDATE, {})
this.$store.dispatch('delView', this.$route) this.$store.dispatch('delView', this.$route)

View File

@ -157,7 +157,13 @@
<el-tag v-for="item in row.groups" :key="item">{{ item }}</el-tag> <el-tag v-for="item in row.groups" :key="item">{{ item }}</el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column
label="状态"
>
<template slot-scope="{row}">
<span>{{ puzzleStatus(row.status) }}</span>
</template>
</el-table-column>
<el-table-column <el-table-column
align="center" align="center"
width="180" width="180"
@ -282,6 +288,17 @@ export default class extends Vue {
return formatQType(val) return formatQType(val)
} }
private puzzleStatus(val: number) {
switch (val) {
case 1:
return '已审核'
case -1:
return '内容敏感'
default:
return '未审核'
}
}
async created() { async created() {
if (UserModule.level === 1) { if (UserModule.level === 1) {
await this.getRemoteDeptList() await this.getRemoteDeptList()
@ -322,7 +339,7 @@ export default class extends Vue {
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}) })
await deleteShopQuestion(this.listQuery.shop, row._id) await deleteShopQuestion(this.listQuery.shop, [row._id])
this.list.splice($index, 1) this.list.splice($index, 1)
this.$message({ this.$message({
type: 'success', type: 'success',
@ -419,25 +436,26 @@ export default class extends Vue {
private async handleRemoveAll() { private async handleRemoveAll() {
try { try {
if (this.multipleSelection.length === 0) {
return
}
const str = this.multipleSelection.length > 0 ? '确定删除选中的题目' : '确定删除所有题目' const str = this.multipleSelection.length > 0 ? '确定删除选中的题目' : '确定删除所有题目'
await this.$confirm(str, 'Warning', { await this.$confirm(str, 'Warning', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}) })
if (this.multipleSelection.length > 0) { const ids: string[] = []
for (const s of this.multipleSelection) { for (const s of this.multipleSelection) {
this.questions.splice(this.questions.indexOf(s), 1) ids.push(s._id)
}
(this.$refs.question_table as any).clearSelection()
} else {
this.questions.length = 0
} }
this.sliceData() const { data } = await deleteShopQuestion(this.listQuery.shop, ids);
(this.$refs.question_table as any).clearSelection()
this.$message({ this.$message({
type: 'success', type: 'success',
message: 'Deleted!' message: `删除成功, 本次删除${data.n}条记录`
}) })
await this.getList()
} catch (err) { } catch (err) {
console.log(err) console.log(err)
} }