10 changed files with 358 additions and 178 deletions
-
0src/apis/container.ts
-
9src/apis/solution.ts
-
8src/router/routes.ts
-
14src/stores/useSolutionStore.ts
-
13src/types/solution.d.ts
-
0src/views/container/index.vue
-
13src/views/container/liquidItem.vue
-
139src/views/solution/index.vue
@ -0,0 +1,9 @@ |
|||||
|
import http from 'libs/http' |
||||
|
|
||||
|
export const getSolsList = (): Promise<any> => http.get(`/sols/list`) |
||||
|
|
||||
|
export const saveSols = (params: { name: string }): Promise<any> => http.post(`/sols`, params) |
||||
|
|
||||
|
export const editSols = (params: { id: number, name: string }): Promise<any> => http.put(`/sols`, params) |
||||
|
|
||||
|
export const delSols = (ids: string): Promise<any> => http.delete(`/sols/${ids}`) |
@ -0,0 +1,14 @@ |
|||||
|
import { defineStore } from 'pinia' |
||||
|
import { ref } from 'vue' |
||||
|
|
||||
|
export const useSolutionStore = defineStore('solution', () => { |
||||
|
const solutionList = ref<Solution.SolutionItem[]>([]) |
||||
|
|
||||
|
const updateSolution = (list: Solution.SolutionItem[]) => { |
||||
|
solutionList.value = list |
||||
|
} |
||||
|
return { |
||||
|
solutionList, |
||||
|
updateSolution, |
||||
|
} |
||||
|
}) |
@ -0,0 +1,13 @@ |
|||||
|
declare namespace Solution { |
||||
|
interface SolutionItem { |
||||
|
id?: number |
||||
|
name: string |
||||
|
updateTime?: string |
||||
|
createTime?: string |
||||
|
} |
||||
|
|
||||
|
interface SolutionItemList { |
||||
|
list: SolutionItem[] |
||||
|
total: number |
||||
|
} |
||||
|
} |
@ -0,0 +1,139 @@ |
|||||
|
<script lang="ts" setup> |
||||
|
import { delSols, getSolsList, saveSols } from '@/apis/solution' |
||||
|
import { useSolutionStore } from '@/stores/useSolutionStore' |
||||
|
import { ElMessage, ElMessageBox } from 'element-plus' |
||||
|
import { onMounted, ref } from 'vue' |
||||
|
|
||||
|
onMounted(() => { |
||||
|
querySolutionList() |
||||
|
}) |
||||
|
const tableData = ref([]) |
||||
|
const visible = ref(false) |
||||
|
const name = ref('') |
||||
|
const loading = ref(false) |
||||
|
const selectedList = ref<Solution.SolutionItem[]>([]) |
||||
|
const solutionStore = useSolutionStore() |
||||
|
const querySolutionList = () => { |
||||
|
getSolsList().then((res) => { |
||||
|
if (res && res.list) { |
||||
|
tableData.value = res.list |
||||
|
// 保存至store |
||||
|
solutionStore.updateSolution(res.list) |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
const addSolution = () => { |
||||
|
visible.value = true |
||||
|
} |
||||
|
|
||||
|
const editSolution = () => { |
||||
|
visible.value = true |
||||
|
} |
||||
|
|
||||
|
const delSolution = () => { |
||||
|
if (!selectedList.value.length) { |
||||
|
ElMessage.warning('请选择要编辑的数据') |
||||
|
return |
||||
|
} |
||||
|
ElMessageBox.confirm( |
||||
|
'确认删除选中的数据吗?', |
||||
|
'确认提示', |
||||
|
{ |
||||
|
confirmButtonText: '确认', |
||||
|
cancelButtonText: '取消', |
||||
|
type: 'warning', |
||||
|
}, |
||||
|
).then(() => { |
||||
|
const ids = selectedList.value.map(item => item.id) |
||||
|
delSols(ids.join(',')).then(() => { |
||||
|
ElMessage.success('删除成功') |
||||
|
querySolutionList() |
||||
|
}) |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
const onSelectionChange = (rows: Solution.SolutionItem[]) => { |
||||
|
console.log('rows===', rows) |
||||
|
selectedList.value = rows |
||||
|
} |
||||
|
|
||||
|
const onConfirm = () => { |
||||
|
if (!name.value) { |
||||
|
ElMessage.warning('请输入溶液名称') |
||||
|
return |
||||
|
} |
||||
|
loading.value = true |
||||
|
const params = { |
||||
|
name: name.value, |
||||
|
} |
||||
|
saveSols(params).then(() => { |
||||
|
ElMessage.success('保存成功') |
||||
|
visible.value = false |
||||
|
name.value = '' |
||||
|
querySolutionList() |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
const closeDialog = () => { |
||||
|
visible.value = false |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<template> |
||||
|
<div> |
||||
|
<div> |
||||
|
<FtButton @click="addSolution"> |
||||
|
添加溶液 |
||||
|
</FtButton> |
||||
|
<FtButton @click="editSolution"> |
||||
|
编辑溶液 |
||||
|
</FtButton> |
||||
|
<FtButton @click="delSolution"> |
||||
|
删除溶液 |
||||
|
</FtButton> |
||||
|
</div> |
||||
|
<div> |
||||
|
<el-table :data="tableData" stripe style="width: 100%" @selection-change="onSelectionChange"> |
||||
|
<el-table-column type="selection" width="55" /> |
||||
|
<el-table-column type="index" width="50" /> |
||||
|
<el-table-column prop="name" label="溶液名称" /> |
||||
|
<el-table-column prop="createTime" label="创建时间" /> |
||||
|
<el-table-column prop="updateTime" label="更新时间" /> |
||||
|
</el-table> |
||||
|
</div> |
||||
|
<FtDialog v-model="visible" title="添加溶液" style="width:35vw; height:30vh"> |
||||
|
<div class="add-content"> |
||||
|
<label>溶液名称:</label> |
||||
|
<span><el-input v-model="name" style="width:200px" /></span> |
||||
|
</div> |
||||
|
<template #footer> |
||||
|
<div class="footer"> |
||||
|
<FtButton @click="closeDialog"> |
||||
|
取消 |
||||
|
</FtButton> |
||||
|
<FtButton :click-handle="onConfirm"> |
||||
|
确定 |
||||
|
</FtButton> |
||||
|
</div> |
||||
|
</template> |
||||
|
</FtDialog> |
||||
|
</div> |
||||
|
</template> |
||||
|
|
||||
|
<style scoped> |
||||
|
.add-content{ |
||||
|
height: 50px; |
||||
|
display: flex; |
||||
|
align-items: center; |
||||
|
} |
||||
|
.footer{ |
||||
|
display: flex; |
||||
|
justify-content: center; |
||||
|
align-items: center; |
||||
|
height: 4rem; |
||||
|
} |
||||
|
.craft-tag{ |
||||
|
display: flex; |
||||
|
} |
||||
|
</style> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue