Skip to content

Commit 6db9e99

Browse files
author
piexlmax
committed
setup版本代码优化
1 parent 95627e9 commit 6db9e99

File tree

11 files changed

+80
-41
lines changed

11 files changed

+80
-41
lines changed

server/resource/template/web/form.vue.tpl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
find{{.StructName}}
5050
} from '@/api/{{.PackageName}}'
5151
52+
// 自动获取字典
5253
import { getDictFunc } from '@/utils/format'
5354
import { useRoute, useRouter } from "vue-router"
5455
import { ElMessage } from 'element-plus'
@@ -78,6 +79,8 @@ const formData = ref({
7879
{{- end }}
7980
{{- end }}
8081
})
82+
83+
// 初始化方法
8184
const init = async () => {
8285
// 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
8386
if (route.query.id) {
@@ -95,8 +98,8 @@ const init = async () => {
9598
}
9699
97100
init()
98-
99-
const save = async() => {
101+
// 保存按钮
102+
const save = async() => {
100103
let res
101104
switch (type.value) {
102105
case 'create':
@@ -115,7 +118,9 @@ init()
115118
message: '创建/更改成功'
116119
})
117120
}
118-
}
121+
}
122+
123+
// 返回按钮
119124
const back = () => {
120125
router.go(-1)
121126
}

server/resource/template/web/table.vue.tpl

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,12 @@ import {
140140
get{{.StructName}}List
141141
} from '@/api/{{.PackageName}}'
142142
143+
// 全量引入格式化工具 请按需保留
143144
import { getDictFunc, formatDate, formatBoolean, filterDict } from '@/utils/format'
144145
import { ElMessage, ElMessageBox } from 'element-plus'
145146
import { ref } from 'vue'
146147
147-
const dialogFormVisible = ref(false)
148-
const type = ref('')
149-
const deleteVisible = ref(false)
150-
const multipleSelection = ref([])
148+
// 自动化生成的字典(可能为空)以及字段
151149
{{- range $index, $element := .DictTypes}}
152150
const {{ $element }}Options = ref([])
153151
{{- end }}
@@ -171,17 +169,19 @@ const formData = ref({
171169
{{- end }}
172170
})
173171
172+
// =========== 表格控制部分 ===========
174173
const page = ref(1)
175174
const total = ref(0)
176175
const pageSize = ref(10)
177176
const tableData = ref([])
178177
const searchInfo = ref({})
179178
179+
// 重置
180180
const onReset = () => {
181181
searchInfo.value = {}
182182
}
183-
// 搜索
184183
184+
// 搜索
185185
const onSubmit = () => {
186186
page.value = 1
187187
pageSize.value = 10
@@ -198,6 +198,7 @@ const handleSizeChange = (val) => {
198198
getTableData()
199199
}
200200
201+
// 修改页面容量
201202
const handleCurrentChange = (val) => {
202203
page.value = val
203204
getTableData()
@@ -216,18 +217,27 @@ const getTableData = async() => {
216217
217218
getTableData()
218219
220+
// ============== 表格控制部分结束 ===============
221+
222+
// 获取需要的字典 可能为空 按需保留
219223
const setOptions = async () =>{
220224
{{- range $index, $element := .DictTypes }}
221225
{{ $element }}Options.value = await getDictFunc('{{$element}}')
222226
{{- end }}
223227
}
224228
229+
// 获取需要的字典 可能为空 按需保留
225230
setOptions()
226231
232+
233+
// 多选数据
234+
const multipleSelection = ref([])
235+
// 多选
227236
const handleSelectionChange = (val) => {
228237
multipleSelection.value = val
229238
}
230239
240+
// 删除行
231241
const deleteRow = (row) => {
232242
ElMessageBox.confirm('确定要删除吗?', '提示', {
233243
confirmButtonText: '确定',
@@ -237,7 +247,13 @@ const deleteRow = (row) => {
237247
delete{{.StructName}}Func(row)
238248
})
239249
}
240-
const onDelete = async() => {
250+
251+
252+
// 批量删除控制标记
253+
const deleteVisible = ref(false)
254+
255+
// 多选删除
256+
const onDelete = async() => {
241257
const ids = []
242258
if (multipleSelection.value.length === 0) {
243259
ElMessage({
@@ -263,6 +279,11 @@ const deleteRow = (row) => {
263279
getTableData()
264280
}
265281
}
282+
283+
// 行为控制标记(弹窗内部需要增还是改)
284+
const type = ref('')
285+
286+
// 更新行
266287
const update{{.StructName}}Func = async(row) => {
267288
const res = await find{{.StructName}}({ ID: row.ID })
268289
type.value = 'update'
@@ -271,6 +292,33 @@ const update{{.StructName}}Func = async(row) => {
271292
dialogFormVisible.value = true
272293
}
273294
}
295+
296+
297+
// 删除行
298+
const delete{{.StructName}}Func = async (row) => {
299+
const res = await delete{{.StructName}}({ ID: row.ID })
300+
if (res.code === 0) {
301+
ElMessage({
302+
type: 'success',
303+
message: '删除成功'
304+
})
305+
if (tableData.value.length === 1 && page.value > 1) {
306+
page.value--
307+
}
308+
getTableData()
309+
}
310+
}
311+
312+
// 弹窗控制标记
313+
const dialogFormVisible = ref(false)
314+
315+
// 打开弹窗
316+
const openDialog = () => {
317+
type.value = 'create'
318+
dialogFormVisible.value = true
319+
}
320+
321+
// 关闭弹窗
274322
const closeDialog = () => {
275323
dialogFormVisible.value = false
276324
formData.value = {
@@ -293,19 +341,7 @@ const closeDialog = () => {
293341
{{- end }}
294342
}
295343
}
296-
const delete{{.StructName}}Func = async (row) => {
297-
const res = await delete{{.StructName}}({ ID: row.ID })
298-
if (res.code === 0) {
299-
ElMessage({
300-
type: 'success',
301-
message: '删除成功'
302-
})
303-
if (tableData.value.length === 1 && page.value > 1) {
304-
page.value--
305-
}
306-
getTableData()
307-
}
308-
}
344+
// 弹窗确定
309345
const enterDialog = async () => {
310346
let res
311347
switch (type.value) {
@@ -328,10 +364,6 @@ const enterDialog = async () => {
328364
getTableData()
329365
}
330366
}
331-
const openDialog = () => {
332-
type.value = 'create'
333-
dialogFormVisible.value = true
334-
}
335367
</script>
336368

337369
<style>

web/src/components/upload/image.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ const props = defineProps({
3737
}
3838
})
3939
40-
4140
const path = ref(import.meta.env.VITE_BASE_API)
4241
const token = computed(()=>store.getters['user/token'])
43-
const showImageUrl = computed(()=>(props.imageUrl && props.imageUrl.slice(0, 4) !== 'http') ? path.value + props.imageUrl : props.imageUrl)
4442
4543
const beforeImageUpload = (file) => {
4644
const isJPG = file.type === 'image/jpeg'

web/src/view/about/index.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ export default {
116116
<script setup>
117117
import { ref } from 'vue'
118118
import { Commits, Members } from '@/api/github'
119-
const members = ref([])
120-
const dataTimeline = ref([])
121119
const page = ref(0)
122120
123121
const loadMore = () => {
124122
page.value++
125123
loadCommits()
126124
}
125+
126+
const dataTimeline = ref([])
127127
const loadCommits = () => {
128128
Commits(page.value).then(({ data }) => {
129129
data.forEach((element) => {
@@ -138,6 +138,8 @@ const loadCommits = () => {
138138
})
139139
})
140140
}
141+
142+
const members = ref([])
141143
const loadMembers = () => {
142144
Members().then(({ data }) => {
143145
members.value = data

web/src/view/example/customer/customer.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ import { ref } from 'vue'
8181
import { ElMessage } from 'element-plus'
8282
import { formatDate } from '@/utils/format'
8383
84-
const dialogFormVisible = ref(false)
85-
const type = ref('')
8684
const form = ref({
8785
customerName: '',
8886
customerPhoneData: ''
@@ -117,6 +115,8 @@ const getTableData = async() => {
117115
118116
getTableData()
119117
118+
const dialogFormVisible = ref(false)
119+
const type = ref('')
120120
const updateCustomer = async(row) => {
121121
const res = await getExaCustomer({ ID: row.ID })
122122
type.value = 'update'

web/src/view/example/upload/upload.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ const store = useStore()
8282
const path = ref(import.meta.env.VITE_BASE_API)
8383
const token = computed(() => store.getters['user/token'])
8484
85-
const fullscreenLoading = ref(false)
8685
const imageUrl = ref('')
8786
8887
const page = ref(1)
@@ -139,6 +138,8 @@ const deleteFileFunc = async(row) => {
139138
})
140139
})
141140
}
141+
142+
const fullscreenLoading = ref(false)
142143
const checkFile = (file) => {
143144
fullscreenLoading.value = true
144145
const isJPG = file.type === 'image/jpeg'

web/src/view/superAdmin/api/api.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ const handleCurrentChange = (val) => {
222222
// 排序
223223
const sortChange = ({ prop, order }) => {
224224
if (prop) {
225+
if (prop === 'ID') {
226+
prop = 'id'
227+
}
225228
searchInfo.value.orderKey = toSQLLine(prop)
226229
searchInfo.value.desc = order === 'descending'
227230
}

web/src/view/superAdmin/dictionary/sysDictionary.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,6 @@ import { formatBoolean, formatDate } from '@/utils/format'
217217
218218
const router = useRouter()
219219
220-
const dialogFormVisible = ref(false)
221-
const type = ref('')
222220
const formData = ref({
223221
name: null,
224222
type: null,
@@ -306,6 +304,8 @@ const toDetile = (row) => {
306304
})
307305
}
308306
307+
const dialogFormVisible = ref(false)
308+
const type = ref('')
309309
const updateSysDictionaryFunc = async(row) => {
310310
const res = await findSysDictionary({ ID: row.ID })
311311
type.value = 'update'

web/src/view/superAdmin/dictionary/sysDictionaryDetail.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ import { ElMessage } from 'element-plus'
133133
import { formatBoolean, formatDate } from '@/utils/format'
134134
const route = useRoute()
135135
136-
const dialogFormVisible = ref(false)
137-
const type = ref('')
138136
const formData = ref({
139137
label: null,
140138
value: null,
@@ -212,6 +210,8 @@ const getTableData = async() => {
212210
213211
getTableData()
214212
213+
const type = ref('')
214+
const dialogFormVisible = ref(false)
215215
const updateSysDictionaryDetailFunc = async(row) => {
216216
const res = await findSysDictionaryDetail({ ID: row.ID })
217217
type.value = 'update'

web/src/view/superAdmin/operation/sysOperationRecord.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,10 @@ const getTableData = async() => {
173173
}
174174
}
175175
176-
const deleteVisible = ref(false)
177-
const multipleSelection = ref([])
178-
179176
getTableData()
180177
178+
const deleteVisible = ref(false)
179+
const multipleSelection = ref([])
181180
const handleSelectionChange = (val) => {
182181
multipleSelection.value = val
183182
}

0 commit comments

Comments
 (0)