index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div class="system-dic-container">
  3. <el-card shadow="hover">
  4. <div class="system-user-search mb15">
  5. <el-form :model="tableData.param" ref="queryRef" :inline="true" label-width="68px">
  6. <el-form-item label="创建时间" prop="dateRange">
  7. <el-date-picker
  8. v-model="tableData.param.dateRange"
  9. size="default"
  10. style="width: 240px"
  11. value-format="YYYY-MM-DD"
  12. type="daterange"
  13. range-separator="-"
  14. start-placeholder="开始日期"
  15. end-placeholder="结束日期"
  16. ></el-date-picker>
  17. </el-form-item>
  18. <el-form-item>
  19. <el-button size="default" type="primary" class="ml10" @click="typeList">
  20. <el-icon>
  21. <ele-Search />
  22. </el-icon>
  23. 查询
  24. </el-button>
  25. <el-button size="default" @click="resetQuery(queryRef)">
  26. <el-icon>
  27. <ele-Refresh />
  28. </el-icon>
  29. 重置
  30. </el-button>
  31. <el-button size="default" type="danger" class="ml10" @click="onRowDel(null)" v-auth="'del'">
  32. <el-icon>
  33. <ele-Delete />
  34. </el-icon>
  35. 删除
  36. </el-button>
  37. </el-form-item>
  38. </el-form>
  39. </div>
  40. <el-table :data="tableData.data" style="width: 100%" @selection-change="handleSelectionChange" v-loading="tableData.loading">
  41. <el-table-column type="selection" width="55" align="center" />
  42. <el-table-column label="ID" align="center" prop="id" width="60" v-col="'ID'" />
  43. <el-table-column label="标题" prop="title" :show-overflow-tooltip="true" v-col="'title'" />
  44. <el-table-column prop="status" label="发送状态" width="100" align="center" v-col="'status'">
  45. <template #default="scope">
  46. <el-tag type="success" size="small" v-if="scope.row.status">发送成功</el-tag>
  47. <el-tag type="info" size="small" v-else>发送失败</el-tag>
  48. </template>
  49. </el-table-column>
  50. <el-table-column prop="sendTime" label="发送时间" align="center" width="180" v-col="'createdAt'"></el-table-column>
  51. <el-table-column label="操作" width="150" align="center" fixed="right" v-col="'handle'">
  52. <template #default="scope">
  53. <el-button size="small" text type="primary" @click="onOpenDetailDic(scope.row)" v-auth="'detail'">详情</el-button>
  54. </template>
  55. </el-table-column>
  56. </el-table>
  57. <pagination
  58. v-show="tableData.total > 0"
  59. :total="tableData.total"
  60. v-model:page="tableData.param.pageNum"
  61. v-model:limit="tableData.param.pageSize"
  62. @pagination="typeList"
  63. />
  64. </el-card>
  65. <EditDic ref="editDicRef" @dataList="typeList" />
  66. <DetailDic ref="detailRef" @dataList="typeList" />
  67. </div>
  68. </template>
  69. <script lang="ts">
  70. import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
  71. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  72. import api from '/@/api/notice';
  73. import DetailDic from './component/detail.vue';
  74. // 定义接口来定义对象的类型
  75. interface TableDataRow {
  76. id: number;
  77. name: string;
  78. deviceType: string;
  79. status: number;
  80. desc: string;
  81. createBy: string;
  82. }
  83. interface TableDataState {
  84. ids: number[];
  85. tableData: {
  86. data: Array<TableDataRow>;
  87. total: number;
  88. loading: boolean;
  89. param: {
  90. pageNum: number;
  91. pageSize: number;
  92. dateRange: string[];
  93. };
  94. };
  95. }
  96. export default defineComponent({
  97. name: 'log',
  98. components: { DetailDic },
  99. setup() {
  100. const addDicRef = ref();
  101. const editDicRef = ref();
  102. const detailRef = ref();
  103. const queryRef = ref();
  104. const state = reactive<TableDataState>({
  105. ids: [],
  106. tableData: {
  107. data: [],
  108. total: 0,
  109. loading: false,
  110. param: {
  111. pageNum: 1,
  112. pageSize: 10,
  113. status: '',
  114. dateRange: [],
  115. },
  116. },
  117. });
  118. // 初始化表格数据
  119. const initTableData = () => {
  120. typeList();
  121. };
  122. const typeList = () => {
  123. state.tableData.loading = true;
  124. api.log
  125. .getList(state.tableData.param)
  126. .then((res: any) => {
  127. state.tableData.data = res.list;
  128. state.tableData.total = res.Total;
  129. })
  130. .finally(() => (state.tableData.loading = false));
  131. };
  132. //打开详情页
  133. const onOpenDetailDic = (row: TableDataRow) => {
  134. detailRef.value.openDialog(row);
  135. };
  136. // 打开新增产品弹窗
  137. const onOpenAddDic = () => {
  138. editDicRef.value.openDialog();
  139. };
  140. // 打开修改产品弹窗
  141. const onOpenEditDic = (row: TableDataRow) => {
  142. editDicRef.value.openDialog(row);
  143. };
  144. // 页面加载时
  145. onMounted(() => {
  146. initTableData();
  147. });
  148. /** 重置按钮操作 */
  149. const resetQuery = (formEl: FormInstance | undefined) => {
  150. if (!formEl) return;
  151. formEl.resetFields();
  152. typeList();
  153. };
  154. // 多选框选中数据
  155. const handleSelectionChange = (selection: TableDataRow[]) => {
  156. state.ids = selection.map((item) => item.id);
  157. };
  158. const onRowDel = (row: TableDataRow) => {
  159. let msg = '你确定要删除所选数据?';
  160. let ids: number[] = [];
  161. if (row) {
  162. msg = `此操作将永久删除产品:“${row.name}”,是否继续?`;
  163. ids = [row.id];
  164. } else {
  165. ids = state.ids;
  166. }
  167. if (ids.length === 0) {
  168. ElMessage.error('请选择要删除的数据。');
  169. return;
  170. }
  171. ElMessageBox.confirm(msg, '提示', {
  172. confirmButtonText: '确认',
  173. cancelButtonText: '取消',
  174. type: 'warning',
  175. })
  176. .then(() => {
  177. api.log.delete(ids).then(() => {
  178. ElMessage.success('删除成功');
  179. typeList();
  180. });
  181. })
  182. .catch(() => { });
  183. };
  184. return {
  185. onRowDel,
  186. addDicRef,
  187. editDicRef,
  188. queryRef,
  189. detailRef,
  190. onOpenDetailDic,
  191. onOpenAddDic,
  192. onOpenEditDic,
  193. typeList,
  194. resetQuery,
  195. handleSelectionChange,
  196. ...toRefs(state),
  197. };
  198. },
  199. });
  200. </script>