index.vue
6.94 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
225
226
227
228
229
230
231
232
<template>
<div class="app-container">
<el-card shadow="never">
<el-container style="height: 100%;">
<el-header style="height: max-content">
<!-- 列表操作 -->
<el-row :gutter="10" class="mb8" justify="end">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="Plus"
@click="btn_add()"
>{{ $t('advertisement.dialogTitleAdd') }}</el-button>
</el-col>
</el-row>
</el-header>
<el-main id="max-height">
<!-- 列表内容 -->
<el-table
v-loading="status.loading"
:data="list"
:max-height="windowSize.height - 70"
:header-cell-style="{textAlign:'center'}"
:cell-style="{textAlign:'center'}"
border
>
<el-table-column :label="$t('advertisement.tableAdName')" prop="name" />
<el-table-column :label="$t('advertisement.tableSortName')" prop="sort" />
<el-table-column :label="$t('advertisement.tablePhotoName')" >
<template #default="{ row }">
<el-image style="width: 100px; height: 100px" :src="row.ossUrl" />
</template>
</el-table-column>
<el-table-column :label="$t('advertisement.tableStateName')" prop="status">
<template #default="{ row }">
<dict-tag
:options="advert_state"
:value="row.status"
></dict-tag>
</template>
</el-table-column>
<el-table-column :label="$t('advertisement.tableControlsName')" class-name="small-padding fixed-width">
<template #default="{ row }">
<el-button
link
type="info"
@click="handleEdit(row)"
>{{ $t('advertisement.controlsEditName') }}</el-button>
<el-button
link
v-if="row.status == 1"
type="info"
@click="handleChangeStatus(row, 2)"
>{{ $t('advertisement.controlsDelistName') }}</el-button>
<el-button
link
v-if="row.status == 0 || row.status == 2"
type="info"
@click="handleChangeStatus(row, 1)"
>{{ $t('advertisement.controlsReleaseName') }}</el-button>
<el-button
link
type="info"
@click="handleDel(row)"
>{{ $t('advertisement.controlsDelName') }}</el-button>
</template>
</el-table-column>
</el-table>
<pagination v-show="total > 0"
:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="getList" />
</el-main>
</el-container>
<el-dialog :title="showForm.title" v-model="showForm.open" width="500px" append-to-body @close="closeDialog">
<el-form ref="formRefs" :model="showForm.form" :rules="rules">
<el-form-item :label="$t('advertisement.tableAdName')" label-width="80" prop="adName">
<el-input v-model="showForm.form.name" placeholder="请输入广告名称" />
</el-form-item>
<el-form-item :label="$t('advertisement.tablePhotoName')" label-width="80">
<imageUpload v-model="showForm.form.ossId" :limit='1' :fileType='["png", "jpg", "jpeg", "ico"]'/>
</el-form-item>
<el-form-item :label="$t('advertisement.tableSortName')" label-width="80">
<el-input-number v-model="showForm.form.sort" controls-position="right" :min="0" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<template v-if="!showForm.form?.id">
<el-button type="info" @click="submitForm(1)">{{ $t('advertisement.dialogSubmit') }}</el-button>
<el-button type="info" @click="submitForm(0)">{{ $t('advertisement.dialogSave') }}</el-button>
</template>
<el-button v-else type="info" @click="submitForm(null)">{{ $t('advertisement.dialogSave') }}</el-button>
<el-button @click="showForm.open = false">{{ $t('advertisement.dialogExit') }}</el-button>
</div>
</template>
</el-dialog>
</el-card>
</div>
</template>
<script setup name="ruleManager">
import { useTableHeight } from '@/hooks/useTableHeight'
// 导入api接口
import { getAdvertList, addAdvert, editAdvert, editAdvertStatus, delAdvert } from '@/api/legao/advertisement'
import { reactive, toRefs } from 'vue';
const { windowSize } = useTableHeight('max-height')
// 导入字典
const { proxy } = getCurrentInstance();
const { sys_yes_no, advert_state } = proxy.useDict("sys_yes_no", "advert_state");
const data = reactive({
status: {
loading: false,
unselected: true,
showForm: false,
showCodePart: false
},
queryParams: {
pageNum: 1,
pageSize: 10
},
total: 0,
list: [],
showForm: {
title: '',
open: false,
form: {
}
},
rules: [
{
adName: [{ required: true, message: "广告名称不能为空", trigger: "blur" }]
}
]
});
const { status, queryParams, total, list, showForm, rules } = toRefs(data)
//#region 初始化
btn_search()
//#endregion
// 获取列表数据
function getList () {
status.loading = true
getAdvertList(queryParams.value)
.then((res) => {
list.value = res.rows
total.value = res.total
})
.finally(() => {
status.loading = false
})
}
// 搜索
function btn_search () {
queryParams.value.pageNum = 1
getList()
}
// 单条编辑
function handleEdit (row) {
showForm.value.title = proxy.$t('advertisement.dialogTitleEdit')
showForm.value = {
...showForm.value,
open: true,
form: {...row}
}
}
function btn_add () {
showForm.value.title = proxy.$t('advertisement.dialogTitleAdd')
showForm.value = {
...showForm.value,
open: true
}
}
function handleDel(row) {
proxy.$modal.confirm(`是否删除广告名称:${row.name}的数据`).then(() => {
return delAdvert(row.id);
}).then(() => {
getList();
proxy.$modal.msgSuccess(res.msg);
}).finally(() => {
});
}
function handleChangeStatus(row, status) {
editAdvertStatus({
...row,
status
}).then(res => {
proxy.$modal.msgSuccess(res.msg);
getList()
showForm.value.open = false
})
}
function submitForm(type) {
const data = {
...showForm.value.form,
}
type && (data['status'] = type);
const fun = showForm.value.form?.id ? editAdvert : addAdvert
fun(data).then(res => {
// console.log(res);
proxy.$modal.msgSuccess(res.msg);
getList()
showForm.value.open = false
})
}
function closeDialog() {
showForm.value = {
...showForm.value,
form: {}
}
}
</script>