HtDeleteButton.vue
5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<template>
<el-popconfirm
title="确定删除吗?"
@onConfirm="handleDelete"
@confirm="handleDelete"
confirm-button-text="确认"
cancel-button-text="取消"
trigger="hover"
class="ht-delete-button"
>
<el-button
slot="reference"
v-if="!row"
:type="type"
:disabled="disabled"
icon="icon-application-delete"
v-loading.fullscreen.lock="fullscreenLoading"
>
<slot></slot>
</el-button>
<el-dropdown-item
icon="el-icon-delete"
:command="{row: row, command: 'delete'}"
slot="reference"
v-if="row"
:type="type"
v-loading.fullscreen.lock="fullscreenLoading"
>
<slot></slot>
</el-dropdown-item>
</el-popconfirm>
</template>
<script>
import req from '@/request.js'
import {mapState} from 'vuex'
export default {
name: 'ht-delete-button',
props: {
type: {
type: String,
default: '',
},
requestMethod: {
type: String,
default: 'DELETE',
},
url: {
type: String,
required: true,
},
pk: {
type: String,
default: 'id',
},
parameter: {
type: String,
default: 'ids',
},
pureData: {
type: Boolean,
default: false,
},
htTable: {
type: Object,
},
row: {
type: Object,
},
ignoreTenant: {
type: Boolean,
default: false,
},
alertMessage: {
type: Boolean,
default: true,
},
deleteList: {
type: Array,
default: () => [],
},
disabled: {
type: Boolean,
default: false,
},
isLayout: {
type: Boolean,
default: false,
},
successMessage: {
type: String,
},
checkRight: {
type: Boolean,
default: false,
},
name: {
type: String,
default: 'name',
},
},
data() {
return {
fullscreenLoading: false,
elTable: null,
}
},
computed: {
...mapState('tenant', ['tenantId']),
...mapState('login', ['currentUser']),
},
mounted() {},
methods: {
handleDelete() {
let ids = []
let notRightNames = []
if (this.row) {
ids.push(this.row[this.pk])
} else if (this.deleteList.length || this.htTable) {
let data = this.deleteList
if (!data || !data.length) {
this.elTable = this.htTable
if (this.htTable.$refs && this.htTable.$refs.htTable) {
this.elTable = this.htTable.$refs.htTable
}
data = this.elTable.selection
}
for (let item of data) {
if (
!this.ignoreTenant &&
!this.tenantId &&
item.tenantId &&
this.currentUser.userAttrs &&
this.currentUser.userAttrs.tenantId !== item.tenantId
) {
this.$message.error('不能删除平台的公共数据')
return
}
if (this.checkRight) {
if (this.$checkRight(item,'4')) {
ids.push(item[this.pk])
}else{
notRightNames.push(item[this.name])
}
}else{
ids.push(item[this.pk])
}
}
if (notRightNames.length > 0) {
this.$message.error('以下数据无权限删除,已跳过:['+notRightNames.join(',')+']')
if (notRightNames.length == data.length) {
return
}
}
}
if (ids.length === 0) {
this.$message.error('请至少选择一条数据')
return
}
if (!this.isLayout) {
this.deleteSelectData(ids)
return
}
const hasPublish = this.elTable.selection.filter(
(item) => item.pubMenuCount
)
if (hasPublish && hasPublish.length > 0) {
this.$confirm(
'该栏目已发布为菜单,删除后将无法使用菜单,是否删除该布局?',
'提示',
{
type: 'warning',
}
)
.then(() => {
this.deleteSelectData(ids)
})
.catch(() => {})
} else {
this.deleteSelectData(ids)
}
},
async deleteSelectData(ids) {
let params = {},
data = null
params[this.parameter] = ids.join(',')
// 如果是纯文本作为参数,则直接传递文本作为参数
if (this.pureData) {
params = null
data = ids.join(',')
}
this.fullscreenLoading = true
let response = await req
.request({
params: params,
data: data,
url: this.url,
method: this.requestMethod,
})
.finally(() => {
this.fullscreenLoading = false
this.htTable.load()
})
if (response.data && response.data.state) {
this.$emit('after-delete', response.data.message)
if (this.alertMessage) {
this.$message({
message: this.successMessage || response.data.message || '操作成功',
showClose: true,
type: 'success',
})
}
}
},
},
}
</script>