index.vue
5.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
<script setup lang="ts">
import { reactive, ref, onMounted, getCurrentInstance } from "vue";
import { columnList, columnStatus, columnSort } from "@/api/property/column";
import Pagination from "@/components/Pagination/index.vue";
import { ElMessageBox } from "element-plus";
import { types } from "./config";
import { globalFilters, enumArray } from "@/utils/tool";
interface Form {
page: number;
pageSize: number;
}
interface Params {
total: number;
query: Form;
}
interface Data {
loading: boolean;
list: any[];
types: any[];
params: Params;
}
let instance: ComponentInternalInstance | null = getCurrentInstance();
let data: Data = reactive({
list: [],
types: types,
loading: false,
params: {
total: 0,
query: {
page: 1,
pageSize: 10,
},
},
});
/**
* 列表
*/
const getList = async () => {
data.loading = true;
try {
const res = await columnList(data.params.query);
data.list = res?.data?.data?.list;
data.params.total = res?.data?.data?.total;
} catch (e) {
console.log(e);
} finally {
data.loading = false;
}
};
/**
* 修改
* @param {object} obj 要操作的数据对象
* @param {string} type 操作类型 => 排序sort 修改状态status 删除delete
*/
const handleUpdate = async (obj: any, type: string) => {
let res: any;
try {
switch (type) {
case "delete":
return ElMessageBox.confirm("确认删除吗?", "警告", {
confirmButtonText: "确认",
cancelButtonText: "取消",
type: "warning",
})
.then(async () => {
res = await columnStatus({ id: obj.id, status: 2 });
if (res?.data) {
instance?.proxy?.$message.success("操作成功");
getList();
} else {
instance?.proxy?.$message.error("操作失败");
}
})
.catch((error) => {
console.log("取消");
});
break;
case "sort":
res = await columnSort({ id: obj.id, sort: obj.sort });
break;
case "status":
res = await columnStatus({
id: obj.id,
status: obj.status ? 0 : 1,
});
break;
}
if (res?.data) {
instance?.proxy?.$message.success("操作成功");
getList();
} else {
instance?.proxy?.$message.error("操作失败");
}
} catch (e) {
console.log(e);
}
};
/**
* 状态值
* @enum {number}
*/
enum statusEnum {
"隐藏" = 0,
"显示",
"删除",
}
onMounted(() => {
getList();
});
</script>
<template>
<div class="page-container">
<h1>栏目列表</h1>
<el-row style="padding-bottom: 20px">
<el-form :inline="true" label-width="70px">
<el-form-item>
<el-button type="primary"
><router-link
:to="{ path: '/column/edit', query: { dataType: 'add' } }"
>创建栏目</router-link
></el-button
>
</el-form-item>
</el-form>
</el-row>
<el-table
:data="data.list"
style="width: 100%"
border
v-loading="data.loading"
row-key="id"
:indent="30"
:tree-props="{ children: 'contentColumnList' }"
align="center"
element-loading-text="拼命加载中"
>
<el-table-column prop="id" label="ID" align="center"></el-table-column>
<el-table-column
prop="columnName"
label="栏目名称"
align="center"
></el-table-column>
<el-table-column prop="type" label="栏目类型" align="center">
<template #default="scope">
{{
scope.row.type
? globalFilters(~~scope.row.type, data.types)
: scope.row.type
}}
</template>
</el-table-column>
<el-table-column prop="columnImg" label="缩略图" align="center">
<template #default="scope">
<el-image
:src="
scope.row.columnImg
? scope.row.columnImg
: instance?.proxy?.$defaultImage
"
fit="contain"
lazy
style="height: 100px"
></el-image>
</template>
</el-table-column>
<el-table-column prop="sort" label="排序" align="center">
<template #default="scope">
<el-input-number
v-model="scope.row.sort"
placeholder="请填写排序值"
:min="0"
:max="100"
@change="handleUpdate(scope.row, 'sort')"
/>
</template>
</el-table-column>
<el-table-column prop="status" label="状态" align="center">
<template #default="scope">
{{ statusEnum[scope.row.status] }}
</template>
</el-table-column>
<el-table-column label="操作" align="center">
<template #default="scope">
<el-button type="text">
<router-link
:to="{
path: '/column/edit',
query: { ...scope.row, ...{ dataType: 'edit' } },
}"
>编辑</router-link
>
</el-button>
<el-button type="text" v-show="!scope.row.parentColumnId">
<!-- 栏目一共可以有两层 -->
<router-link
:to="{
path: '/column/edit',
query: { dataType: 'subColumn', parentColumnId: scope.row.id },
}"
>子栏目</router-link
>
</el-button>
<el-button type="text" @click="handleUpdate(scope.row, 'status')">{{
scope.row.status ? "隐藏" : "显示"
}}</el-button>
<el-button type="text" @click="handleUpdate(scope.row, 'delete')"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<Pagination
:total="data.params.total"
v-model:currentPage="data.params.query.page"
v-model:pageSize="data.params.query.pageSize"
@pageChange="getList"
></Pagination>
</div>
</template>