index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <div class="h-full flex">
  3. <div class="p-5 w-60 pr-0">
  4. <div class="bg-white w-full h-full shadow-md rounded-md flex flex-col const-left">
  5. <el-table ref="dictionaryTableRef" :data="dictionaryTableData" border highlight-current-row
  6. @current-change="dictionaryHandleCurrentChange" style="width: 100%;height: 100%;">
  7. <el-table-column prop="name" label="字典编码" align="center" />
  8. </el-table>
  9. </div>
  10. </div>
  11. <div class="flex-1 p-5 overflow-auto">
  12. <div class="bg-white w-full h-full shadow-md rounded-md flex flex-col">
  13. <div class="tableHeader">
  14. <div>字典编码-{{ currentRow?.name }}</div>
  15. <el-button type="primary" @click="showDialogFormVisible()" :disabled="!currentRow.id">新增参数</el-button>
  16. </div>
  17. <div class="flex-1 p-3">
  18. <el-table ref="dictionaryTableRef" :data="tableData" v-loading="AllLoading.tableDataLoading" border
  19. style="width: 100%;height: 100%;">
  20. <el-table-column type="selection" width="55" />
  21. <el-table-column prop="name" label="字典名称" align="center" />
  22. <el-table-column prop="seq" label="排序" align="center" />
  23. <el-table-column label="操作" width="100px">
  24. <template #default="{ row, $index }">
  25. <dv class="operation">
  26. <el-icon @click="deteleItem(row)">
  27. <Delete color="red" />
  28. </el-icon>
  29. </dv>
  30. </template>
  31. </el-table-column>
  32. </el-table>
  33. </div>
  34. </div>
  35. </div>
  36. <!-- 弹窗 -->
  37. <el-dialog title="新增参数" v-model="AllVisible.dialogFormVisible" width="500" align-center
  38. :before-close="handleClose">
  39. <div>
  40. <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
  41. <el-form-item label="字典名称" prop="name">
  42. <el-input v-model="form.name" placeholder="请输入字典名称"></el-input>
  43. </el-form-item>
  44. <el-form-item label="排序" prop="seq">
  45. <el-input-number v-model="form.seq" :step="2" placeholder="请输入排序" controls-position="right" style="width: 100%;" />
  46. </el-form-item>
  47. </el-form>
  48. </div>
  49. <template #footer>
  50. <div slot="footer" class="dialog-footer">
  51. <el-button type="primary" @click="submitForm(formRef, false)" v-loading="AllLoading.dialogFormLoading">保
  52. 存</el-button>
  53. <el-button type="primary" @click="submitForm(formRef, true)"
  54. v-loading="AllLoading.dialogFormLoading">保存并新增</el-button>
  55. </div>
  56. </template>
  57. </el-dialog>
  58. </div>
  59. </template>
  60. <script lang="ts" setup>
  61. import { ref, reactive, onMounted, inject } from 'vue';
  62. import { Delete } from '@element-plus/icons-vue'
  63. import { FormInstance, FormRules, ElMessageBox, ElTable } from 'element-plus'
  64. import { GETLISTBYCODE, GETTYPE, UNDATELIST, DELETELIST } from './api'
  65. import { post, get } from "@/utils/request";
  66. import { getFromValue, resetFromValue } from '@/utils/tools'
  67. type dictionaryTab = {
  68. id: string | number
  69. name: string
  70. }
  71. interface RuleForm {
  72. name: string,
  73. seq: any
  74. id: string | number,
  75. code: string
  76. }
  77. const globalPopup = inject<GlobalPopup>('globalPopup')
  78. const dictionaryTableRef = ref<InstanceType<typeof ElTable>>()
  79. const currentRow: any = ref({})
  80. const dictionaryTableData = ref<dictionaryTab[]>([])
  81. const tableData = ref<any[]>([])
  82. const formRef = ref<FormInstance>()
  83. const form = reactive<RuleForm>({
  84. id: '',
  85. code: '',
  86. name: '',
  87. seq: ''
  88. })
  89. const rules = reactive<FormRules<RuleForm>>({
  90. name: [{ required: true, message: '请输入字典名称', trigger: 'change' }],
  91. seq: [{ required: true, message: '请输入排序', trigger: 'change' }]
  92. })
  93. const AllLoading = reactive({
  94. tableDataLoading: false,
  95. dialogFormLoading: false
  96. })
  97. const AllVisible = reactive({
  98. dialogFormVisible: false
  99. })
  100. function deteleItem(data: any) {
  101. ElMessageBox.confirm(
  102. `确定删除【${data.name}】字典吗?`, '',
  103. {
  104. confirmButtonText: '确定',
  105. cancelButtonText: '取消',
  106. type: 'warning',
  107. }
  108. )
  109. .then(() => {
  110. post(DELETELIST, { id: data.id, code: data.code }).then(res => {
  111. if (res.code != 'ok') {
  112. globalPopup?.showError(res.msg)
  113. return
  114. }
  115. globalPopup?.showSuccess('删除成功')
  116. getTableList()
  117. })
  118. })
  119. }
  120. function showDialogFormVisible() {
  121. let newForm = resetFromValue(form)
  122. newForm.code = currentRow.value.id
  123. Object.assign(form, newForm)
  124. AllVisible.dialogFormVisible = true
  125. console.log(form)
  126. }
  127. async function submitForm(formEl: FormInstance | undefined, flag: boolean) {
  128. if (!formEl) return
  129. await formEl.validate((valid) => {
  130. if (valid) {
  131. updateList(getFromValue(form), flag)
  132. }
  133. })
  134. }
  135. function updateList(data: any, flag: boolean) {
  136. AllLoading.dialogFormLoading = true
  137. post(UNDATELIST, { ...data }).then((_res) => {
  138. let newForm = resetFromValue(form)
  139. newForm.code = currentRow.value.id
  140. Object.assign(form, newForm)
  141. globalPopup?.showSuccess ('保存成功')
  142. getTableList()
  143. AllLoading.dialogFormLoading = false
  144. AllVisible.dialogFormVisible = flag
  145. }).catch((_err) => {
  146. AllLoading.dialogFormLoading = false
  147. })
  148. }
  149. function getDataType() {
  150. post(GETTYPE, {}).then((res) => {
  151. dictionaryTableData.value = res.data
  152. dictionarySetCurrent(dictionaryTableData.value[0])
  153. })
  154. }
  155. function getTableList() {
  156. const { id } = currentRow.value
  157. get(GETLISTBYCODE, { code: id }).then((res) => {
  158. tableData.value = res.data
  159. })
  160. }
  161. function handleClose(done: any) {
  162. done()
  163. }
  164. function dictionaryHandleCurrentChange(val: any) {
  165. currentRow.value = val;
  166. getTableList()
  167. }
  168. function dictionarySetCurrent(row?: dictionaryTab) {
  169. dictionaryTableRef.value!.setCurrentRow(row)
  170. }
  171. onMounted(() => {
  172. getDataType()
  173. });
  174. </script>
  175. <style lang="scss" scoped>
  176. $borderColor : #F4F4F4;
  177. $titleBack : #FBFBFB;
  178. $themeColor : #075985;
  179. .const-left {
  180. .const-leftTile {
  181. text-align: center;
  182. background: $titleBack;
  183. padding: 0.85rem 0;
  184. }
  185. .const-leftItem {
  186. width: 100%;
  187. text-align: center;
  188. padding: 0.85rem 0;
  189. cursor: pointer;
  190. }
  191. .ons {
  192. background: $themeColor;
  193. color: #fff;
  194. }
  195. .border-bottom {
  196. border-bottom: 1px solid $borderColor;
  197. }
  198. }
  199. .tableHeader {
  200. display: flex;
  201. width: 100%;
  202. justify-content: space-between;
  203. align-items: center;
  204. padding: 10px;
  205. background-color: #F5F7FA;
  206. }
  207. </style>