index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <el-card shadow="never" class="page">
  3. <el-form :model="tableData.param" ref="queryRef" inline>
  4. <el-form-item label="" prop="ipaddr">
  5. <el-input v-model="tableData.param.ipaddr" placeholder="登录IP" clearable style="width: 150px" @keyup.enter="dataList" />
  6. </el-form-item>
  7. <el-form-item label="" prop="loginLocation">
  8. <el-input v-model="tableData.param.loginLocation" placeholder="登录地点" clearable style="width: 150px" @keyup.enter="dataList" />
  9. </el-form-item>
  10. <el-form-item label="" prop="status">
  11. <el-select v-model="tableData.param.status" placeholder="状态" style="width: 75px">
  12. <el-option label="全部" :value="-1" />
  13. <el-option label="成功" :value="1" />
  14. <el-option label="失败" :value="0" />
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item label="" prop="dateRange">
  18. <el-date-picker v-model="tableData.param.dateRange" style="width: 220px" value-format="YYYY-MM-DD" type="daterange" range-separator="-" start-placeholder="登录时间" end-placeholder="结束时间"></el-date-picker>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button type="primary" @click="dataList">
  22. <el-icon>
  23. <ele-Search />
  24. </el-icon>
  25. 查询
  26. </el-button>
  27. <!-- <el-button @click="resetQuery(queryRef)">
  28. <el-icon>
  29. <ele-Refresh />
  30. </el-icon>
  31. 重置
  32. </el-button> -->
  33. <el-button type="info" @click="onRowDel(null)" v-auth="'del'">
  34. <el-icon>
  35. <ele-Delete />
  36. </el-icon>
  37. 删除日志
  38. </el-button>
  39. <el-button type="primary" @click="onRowExport()">
  40. <el-icon>
  41. <ele-Download />
  42. </el-icon>
  43. 导出日志
  44. </el-button>
  45. </el-form-item>
  46. </el-form>
  47. <el-table :data="tableData.data" style="width: 100%" @selection-change="handleSelectionChange" v-loading="tableData.loading">
  48. <el-table-column type="selection" width="50" align="center" />
  49. <el-table-column label="编号" align="center" width="90" prop="infoId" />
  50. <el-table-column label="登录名称" align="center" prop="loginName" />
  51. <el-table-column label="登录地址" align="center" prop="ipaddr" width="145" show-overflow-tooltip />
  52. <el-table-column label="登录地点" v-col="'loginLocation'" align="center" prop="loginLocation" show-overflow-tooltip />
  53. <el-table-column label="浏览器" align="center" prop="browser" />
  54. <el-table-column label="操作系统" show-overflow-tooltip align="center" prop="os" />
  55. <el-table-column label="登录状态" v-col="'status'" align="center" prop="status" width="90">
  56. <template #default="scope">
  57. <el-tag type="success" size="small" v-if="scope.row.status === 1">成功</el-tag>
  58. <el-tag type="info" size="small" v-else>失败</el-tag>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="操作信息" v-col="'msg'" show-overflow-tooltip prop="msg" align="center" />
  62. <el-table-column label="登录日期" v-col="'loginTime'" align="center" prop="loginTime" width="160" />
  63. <el-table-column label="登录模块" v-col="'module'" align="center" show-overflow-tooltip prop="module" width="120"></el-table-column>
  64. </el-table>
  65. <pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="dataList" />
  66. </el-card>
  67. </template>
  68. <script lang="ts">
  69. import { toRefs, reactive, onMounted, ref, defineComponent, getCurrentInstance } from 'vue';
  70. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  71. import api from '/@/api/system';
  72. import downloadFile from '/@/utils/download';
  73. // 定义接口来定义对象的类型
  74. interface TableDataRow {
  75. infoId: number;
  76. loginName: string;
  77. ipaddr: string;
  78. loginLocation: string;
  79. browser: string;
  80. os: string;
  81. status: number;
  82. msg: string;
  83. loginTime: string;
  84. module: string;
  85. }
  86. interface TableDataState {
  87. ids: number[];
  88. tableData: {
  89. data: Array<TableDataRow>;
  90. total: number;
  91. loading: boolean;
  92. param: {
  93. pageNum: number;
  94. pageSize: number;
  95. dateRange: string[];
  96. status: number;
  97. ipaddr: string;
  98. loginLocation: string;
  99. userName: string;
  100. };
  101. };
  102. }
  103. export default defineComponent({
  104. name: 'apiV1SystemLoginLogList',
  105. setup() {
  106. const { proxy } = getCurrentInstance() as any;
  107. const queryRef = ref();
  108. const { admin_login_status } = proxy.useDict('admin_login_status');
  109. const state = reactive<TableDataState>({
  110. ids: [],
  111. tableData: {
  112. data: [],
  113. total: 0,
  114. loading: false,
  115. param: {
  116. pageNum: 1,
  117. pageSize: 20,
  118. dateRange: [],
  119. status: -1,
  120. ipaddr: '',
  121. loginLocation: '',
  122. userName: '',
  123. },
  124. },
  125. });
  126. // 初始化表格数据
  127. const initTableData = () => {
  128. dataList();
  129. };
  130. const dataList = () => {
  131. state.tableData.loading = true;
  132. api.log
  133. .getList(state.tableData.param)
  134. .then((res: any) => {
  135. state.tableData.data = res.list;
  136. state.tableData.total = res.total;
  137. })
  138. .finally(() => {
  139. state.tableData.loading = false;
  140. });
  141. };
  142. // 删除日志
  143. const onRowDel = (row: TableDataRow) => {
  144. let msg = '你确定要删除所选数据?';
  145. let ids: number[] = [];
  146. if (row) {
  147. msg = `此操作将永久删除:“${row.loginName}”,是否继续?`;
  148. ids = [row.infoId];
  149. } else {
  150. ids = state.ids;
  151. }
  152. if (ids.length === 0) {
  153. ElMessage.error('请选择要删除的数据。');
  154. return;
  155. }
  156. ElMessageBox.confirm(msg, '提示', {
  157. confirmButtonText: '确认',
  158. cancelButtonText: '取消',
  159. type: 'warning',
  160. beforeClose: (action, instance, done) => {
  161. if (action === 'confirm') {
  162. instance.confirmButtonLoading = true;
  163. instance.confirmButtonText = '删除中';
  164. api.log.del(ids).then(() => {
  165. ElMessage.success('删除成功');
  166. dataList();
  167. done();
  168. });
  169. } else {
  170. done();
  171. }
  172. },
  173. }).catch(() => { });
  174. };
  175. // 导出日志
  176. const onRowExport = () => {
  177. api.log.export({
  178. ...state.tableData.param,
  179. // pageSize: state.tableData.total
  180. }).then((res: any) => downloadFile(res))
  181. };
  182. // 清空日志
  183. const onRowClear = () => {
  184. ElMessageBox.confirm('你确定要删除所选数据?', '提示', {
  185. confirmButtonText: '确认',
  186. cancelButtonText: '取消',
  187. type: 'warning',
  188. })
  189. .then(() => {
  190. api.log.clearLog().then(() => {
  191. ElMessage.success('清除成功');
  192. dataList();
  193. });
  194. })
  195. .catch(() => { });
  196. };
  197. // 页面加载时
  198. onMounted(() => {
  199. initTableData();
  200. });
  201. /** 重置按钮操作 */
  202. const resetQuery = (formEl: FormInstance | undefined) => {
  203. if (!formEl) return;
  204. formEl.resetFields();
  205. dataList();
  206. };
  207. // 多选框选中数据
  208. const handleSelectionChange = (selection: TableDataRow[]) => {
  209. state.ids = selection.map((item) => item.infoId);
  210. };
  211. return {
  212. queryRef,
  213. onRowDel,
  214. onRowExport,
  215. dataList,
  216. resetQuery,
  217. handleSelectionChange,
  218. onRowClear,
  219. admin_login_status,
  220. ...toRefs(state),
  221. };
  222. },
  223. });
  224. </script>