|
|
@ -1,136 +1,96 @@ |
|
|
|
<script lang="ts" setup> |
|
|
|
import { delSols, editSols, getSolsList, saveSols } from '@/apis/solution' |
|
|
|
import { useSolutionStore } from '@/stores/useSolutionStore' |
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus' |
|
|
|
import { onMounted, ref } from 'vue' |
|
|
|
import { delSols, getSolsList } from '@/apis/solution' |
|
|
|
import Edit from 'components/solution/Edit/index.vue' |
|
|
|
import { ElMessageBox } from 'element-plus' |
|
|
|
import { FtMessage } from 'libs/message' |
|
|
|
import { provide, ref, useTemplateRef } from 'vue' |
|
|
|
|
|
|
|
onMounted(() => { |
|
|
|
querySolutionList() |
|
|
|
}) |
|
|
|
const tableData = ref<Solution.SolutionItem[]>([]) |
|
|
|
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 currentData = ref<Solution.SolutionItem>() |
|
|
|
provide('currentData', currentData) |
|
|
|
const addSolution = () => { |
|
|
|
currentData.value = {} |
|
|
|
visible.value = true |
|
|
|
} |
|
|
|
|
|
|
|
const editInfo = ref() |
|
|
|
const editSolution = () => { |
|
|
|
if (selectedList.value.length === 1) { |
|
|
|
const editData = selectedList.value[0] |
|
|
|
editInfo.value = editData |
|
|
|
const editSolution = (data: Solution.SolutionItem[]) => { |
|
|
|
currentData.value = data[0] |
|
|
|
visible.value = true |
|
|
|
name.value = editData.name |
|
|
|
} |
|
|
|
else { |
|
|
|
ElMessage.warning('请选择一条要编辑的数据') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const delSolution = () => { |
|
|
|
if (!selectedList.value.length) { |
|
|
|
ElMessage.warning('请选择要删除的数据') |
|
|
|
return |
|
|
|
} |
|
|
|
const tableRef = useTemplateRef('tableRef') |
|
|
|
|
|
|
|
const delSolution = (data: Solution.SolutionItem[]) => { |
|
|
|
ElMessageBox.confirm( |
|
|
|
'确认删除选中的数据吗?', |
|
|
|
'确认提示', |
|
|
|
'提示', |
|
|
|
{ |
|
|
|
confirmButtonText: '确认', |
|
|
|
cancelButtonText: '取消', |
|
|
|
type: 'warning', |
|
|
|
}, |
|
|
|
).then(() => { |
|
|
|
const ids = selectedList.value.map(item => item.id) |
|
|
|
const ids = data.map(item => item.id) |
|
|
|
delSols(ids.join(',')).then(() => { |
|
|
|
ElMessage.success('删除成功') |
|
|
|
querySolutionList() |
|
|
|
FtMessage.success('删除成功') |
|
|
|
tableRef.value?.initData() |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
const onSelectionChange = (rows: Solution.SolutionItem[]) => { |
|
|
|
selectedList.value = rows |
|
|
|
} |
|
|
|
|
|
|
|
const onConfirm = () => { |
|
|
|
if (!name.value) { |
|
|
|
ElMessage.warning('请输入溶液名称') |
|
|
|
return |
|
|
|
} |
|
|
|
loading.value = true |
|
|
|
if (editInfo.value.id) { |
|
|
|
const params = { |
|
|
|
id: editInfo.value.id, |
|
|
|
name: name.value, |
|
|
|
} |
|
|
|
editSols(params).then(() => { |
|
|
|
ElMessage.success('编辑成功') |
|
|
|
visible.value = false |
|
|
|
name.value = '' |
|
|
|
querySolutionList() |
|
|
|
}) |
|
|
|
} |
|
|
|
else { |
|
|
|
const params = { |
|
|
|
name: name.value, |
|
|
|
} |
|
|
|
saveSols(params).then(() => { |
|
|
|
ElMessage.success('保存成功') |
|
|
|
const okHandle = () => { |
|
|
|
tableRef.value?.initData() |
|
|
|
visible.value = false |
|
|
|
name.value = '' |
|
|
|
querySolutionList() |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const closeDialog = () => { |
|
|
|
editInfo.value = {} |
|
|
|
visible.value = false |
|
|
|
} |
|
|
|
const columns = [ |
|
|
|
{ |
|
|
|
type: 'selection', |
|
|
|
}, |
|
|
|
{ |
|
|
|
type: 'index', |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '溶液名称', |
|
|
|
key: 'name', |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '创建时间', |
|
|
|
key: 'createTime', |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '更新时间', |
|
|
|
key: 'updateTime', |
|
|
|
}, |
|
|
|
] |
|
|
|
|
|
|
|
const btnList = [ |
|
|
|
{ |
|
|
|
name: '新增', |
|
|
|
type: 'primary', |
|
|
|
serverUrl: 'add', |
|
|
|
serverCondition: 0, |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: '编辑', |
|
|
|
type: 'primary', |
|
|
|
serverUrl: 'edit', |
|
|
|
serverCondition: 1, |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: '删除', |
|
|
|
type: 'danger', |
|
|
|
serverUrl: 'del', |
|
|
|
serverCondition: 2, |
|
|
|
}, |
|
|
|
] |
|
|
|
</script> |
|
|
|
|
|
|
|
<template> |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<FtButton type="primary" @click="addSolution"> |
|
|
|
添加溶液 |
|
|
|
</FtButton> |
|
|
|
<FtButton type="primary" @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="添加溶液" width="30%" :ok-handle="onConfirm" @cancel="closeDialog"> |
|
|
|
<div class="add-content"> |
|
|
|
<label>溶液名称:</label> |
|
|
|
<span><el-input v-model="name" placeholder="溶液名称" style="width:200px" /></span> |
|
|
|
</div> |
|
|
|
</FtDialog> |
|
|
|
<ft-table ref="tableRef" has-page has-header :columns="columns" :btn-list="btnList" :get-data-fn="getSolsList" @add="addSolution" @edit="editSolution" @del="delSolution" /> |
|
|
|
<Edit v-if="visible" @ok="okHandle" @cancel="visible = false" /> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
|
|
|
|