index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div class="table-box">
  3. <div class="card table-main">
  4. <!-- 表格头部 操作按钮 -->
  5. <div class="table-header">
  6. <div class="header-button-lf">
  7. <el-form :model="queryParams" label-width="auto" :inline="true">
  8. <el-form-item label="角色名称:">
  9. <el-input v-model="queryParams.name" style="width: 200px" placeholder="请输入角色名称" clearable />
  10. </el-form-item>
  11. <el-form-item>
  12. <el-button type="primary" @click="handleQuery"> 查询 </el-button>
  13. <el-button style="margin-left: 10px" @click="resetQuery"> 重置 </el-button>
  14. <el-button style="margin-left: 10px" type="primary" plain @click="handleAdd"> 新增 </el-button>
  15. </el-form-item>
  16. </el-form>
  17. </div>
  18. </div>
  19. <!-- 表格主体 -->
  20. <el-table stripe ref="tableRef" :border="true" :data="processTableData" size="small">
  21. <el-table-column align="left" label="序号" width="80px" :show-overflow-tooltip="true">
  22. <template #default="scope">
  23. {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
  24. </template>
  25. </el-table-column>
  26. <template v-for="item in columns" :key="item">
  27. <el-table-column v-bind="item" :align="item.align ?? 'left'" :reserve-selection="item.type == 'selection'" :show-overflow-tooltip="true">
  28. <template #default="scope">
  29. <template v-if="item.prop === 'operation'">
  30. <el-tooltip
  31. class="box-item"
  32. effect="dark"
  33. content="编辑"
  34. placement="top"
  35. >
  36. <el-button type="primary" link @click="handleUpdate">
  37. <img class="operation-img" src="@/assets/images/edit.png">
  38. </el-button>
  39. </el-tooltip>
  40. <el-tooltip
  41. class="box-item"
  42. effect="dark"
  43. content="删除"
  44. placement="top"
  45. >
  46. <el-button type="primary" link @click="handleDelete(scope.row)">
  47. <img class="operation-img" src="@/assets/images/delete.png">
  48. </el-button>
  49. </el-tooltip>
  50. </template>
  51. </template>
  52. </el-table-column>
  53. </template>
  54. <!-- 无数据 -->
  55. <template #empty>
  56. <div class="table-empty">
  57. <slot name="empty">
  58. <img src="@/assets/images/notData.png" alt="notData" />
  59. <div>暂无数据</div>
  60. </slot>
  61. </div>
  62. </template>
  63. </el-table>
  64. <!-- 分页组件 -->
  65. <Pagination :pageable="pageable" :handle-size-change="handleSizeChange" :handle-current-change="handleCurrentChange" />
  66. </div>
  67. <!-- 添加或修改对话框 -->
  68. <el-dialog :title="dialog.title" v-model="dialog.visible" width="800px" append-to-body>
  69. <el-form ref="formRef" :model="roleForm" :rules="rules" label-width="120px">
  70. <el-form-item label="角色名称" prop="roleName">
  71. <el-input v-model="roleForm.roleName" placeholder="请输入角色名称" />
  72. </el-form-item>
  73. </el-form>
  74. <template #footer>
  75. <div class="dialog-footer">
  76. <el-button @click="cancel">取 消</el-button>
  77. <el-button type="primary" @click="submitForm">确 定</el-button>
  78. </div>
  79. </template>
  80. </el-dialog>
  81. </div>
  82. </template>
  83. <script setup lang="ts" name="useProTable">
  84. import Pagination from "@/components/ProTable/components/Pagination.vue";
  85. import { ref, reactive } from "vue";
  86. import { ColumnProps } from "@/components/ProTable/interface";
  87. import { ElMessageBox } from 'element-plus'
  88. const pageable = ref<any>({
  89. pageNum: 1,
  90. pageSize: 20,
  91. total: 1
  92. });
  93. const queryParams = ref({
  94. name: '',
  95. pageNum: 1,
  96. pageSize: 20,
  97. total: 2
  98. });
  99. // 查询功能
  100. const handleQuery = () => {
  101. queryParams.value.pageNum = 1;
  102. };
  103. //搜索功能
  104. const resetQuery = () => {
  105. queryParams.value.pageNum = 1;
  106. };
  107. /**
  108. * @description 每页条数改变
  109. * @param {Number} val 当前条数
  110. * @return void
  111. * */
  112. const handleSizeChange = (val: number) => {
  113. console.log(val);
  114. };
  115. /**
  116. * @description 当前页改变
  117. * @param {Number} val 当前页
  118. * @return void
  119. * */
  120. const handleCurrentChange = (val: number) => {
  121. console.log(val);
  122. };
  123. const processTableData = ref([
  124. {
  125. id: "681913747276782417",
  126. a: "观察员",
  127. }
  128. ]);
  129. // 表格配置项
  130. const columns = reactive<ColumnProps[]>([
  131. { prop: "a", label: "角色名称" },
  132. { prop: "operation", label: "操作", width:150,align: 'center' }
  133. ]);
  134. const dialog = reactive<any>({
  135. visible: false,
  136. title: ''
  137. });
  138. const formRef = ref<any>();
  139. const rules = ref<any>(
  140. {
  141. roleName: [{ required: true, message: "角色名称不能为空", trigger: "blur" }],
  142. }
  143. );
  144. const initFormData = ref<any>(
  145. {
  146. roleName: "",
  147. }
  148. );
  149. const roleForm = ref<any>({...initFormData});
  150. /** 新增按钮操作 */
  151. const handleAdd = () => {
  152. reset();
  153. dialog.visible = true;
  154. dialog.title = "新增";
  155. }
  156. /** 修改按钮操作 */
  157. const handleUpdate = async (row?: any) => {
  158. reset();
  159. dialog.visible = true;
  160. dialog.title = "编辑";
  161. }
  162. /** 取消按钮 */
  163. const cancel = () => {
  164. reset();
  165. dialog.visible = false;
  166. }
  167. /** 表单重置 */
  168. const reset = () => {
  169. roleForm.value = { ...initFormData };
  170. formRef.value?.resetFields();
  171. }
  172. /** 提交按钮 */
  173. const submitForm = () => {
  174. formRef.value?.validate(async (valid: boolean) => {
  175. if (valid) {
  176. dialog.visible = false;
  177. }
  178. });
  179. }
  180. /** 删除按钮操作 */
  181. const handleDelete = async (row?: any) => {
  182. ElMessageBox.confirm('是否确认删除岗位编号为"' + row.b + '"的数据项?', {
  183. confirmButtonText: '删除',
  184. cancelButtonText: '取消',
  185. type: 'warning',
  186. title:'删除数据',
  187. draggable: true
  188. })
  189. .then(() => {
  190. })
  191. .catch(() => {
  192. })
  193. }
  194. </script>