index.vue 7.4 KB

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