index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div class="__normal-page">
  3. <div class="__normal-content">
  4. <CusContent
  5. v-model:tableHead="tableHead"
  6. @handleReset="handleReset"
  7. @handleSearch="onSearch"
  8. >
  9. <template #fieldOut>
  10. <CusForm labelWidth="100px" @handleEnter="onSearch">
  11. <CusFormColumn
  12. label="操作人:"
  13. v-model:param="queryForm.operName"/>
  14. <CusFormColumn
  15. label="操作人单位:"
  16. link="select"
  17. v-model:param="queryForm.deptId"
  18. :options="$store.state.dictionary.deptList"/>
  19. <CusFormColumn
  20. label="操作模块:"
  21. link="select"
  22. v-model:param="queryForm.operModule"
  23. :options="$store.state.dictionary.operModuleList"/>
  24. <CusFormColumn
  25. label="操作类型:"
  26. link="select"
  27. v-model:param="queryForm.operType"
  28. :options="$store.state.dictionary.operTypeList"/>
  29. <!-- <CusFormColumn-->
  30. <!-- label="操作对象:"-->
  31. <!-- v-model:param="queryForm.shipId"/>-->
  32. <!-- <CusFormColumn-->
  33. <!-- label="操作详情:"-->
  34. <!-- v-model:param="queryForm.shipId"/>-->
  35. <CusFormColumn
  36. label="操作时间:"
  37. link="datetime"
  38. type="datetimerange"
  39. v-model:param="queryForm.operationDate"/>
  40. <CusSearchButtons
  41. @handleReset="handleReset"
  42. @handleSearch="onSearch"
  43. />
  44. </CusForm>
  45. </template>
  46. <template #buttons>
  47. <div class="__cus-button_submit __hover" @click="onExport">
  48. <SvgIcon name="export" size="16"/>导出
  49. </div>
  50. </template>
  51. <template #table>
  52. <CusTable
  53. v-loading="loading"
  54. ref="ref_cusTable"
  55. :tableData="queryResult.tableData"
  56. :tableHead="tableHead"
  57. :total="queryResult.total"
  58. :page="queryPage.pageNum"
  59. :pageSize="queryPage.pageSize"
  60. v-model:selected="selected"
  61. @handlePage="handlePage"
  62. >
  63. </CusTable>
  64. </template>
  65. </CusContent>
  66. </div>
  67. </div>
  68. </template>
  69. <script lang="ts">
  70. import {
  71. defineComponent,
  72. computed,
  73. onMounted,
  74. ref,
  75. reactive,
  76. watch,
  77. getCurrentInstance,
  78. ComponentInternalInstance,
  79. toRefs,
  80. nextTick
  81. } from 'vue'
  82. import {useStore} from 'vuex'
  83. import {useRouter, useRoute} from 'vue-router'
  84. import {getOperationLogList, operLogExport} from "@/api/modules/oper-log";
  85. import {getDeptList} from "@/api/modules/dept";
  86. import {ElMessage} from "element-plus";
  87. import {downLoadBlob} from "@/utils/downLoadUrl";
  88. export default defineComponent({
  89. name: '',
  90. components: {},
  91. setup(props, {emit}) {
  92. const store = useStore();
  93. const router = useRouter();
  94. const route = useRoute();
  95. const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties
  96. const state = reactive({
  97. // 加载中
  98. loading: false,
  99. // 查询分页参数
  100. queryPage: {
  101. pageNum: 1,
  102. pageSize: 10
  103. },
  104. // 查询结果
  105. queryResult: {
  106. total: 0,
  107. tableData: []
  108. },
  109. // 查询表单参数
  110. queryForm: <any>{},
  111. // 查询表单参数备份
  112. back_queryForm: {},
  113. // 表格表头
  114. tableHead: [
  115. {value: "p1", label: "操作人", show: true},
  116. {value: "p1", label: "操作人单位", show: true},
  117. {value: "p1", label: "设备IP", show: true},
  118. {value: "p1", label: "操作模块", show: true},
  119. {value: "p1", label: "操作类型", show: true},
  120. // {value: "p1", label: "操作对象", show: true},
  121. // {value: "p1", label: "操作详情", show: true},
  122. {value: "p1", label: "操作时间", show: true},
  123. ],
  124. selected: []
  125. });
  126. const ref_cusTable = ref()
  127. // 获取字典
  128. const initDictionary = () => {
  129. store.dispatch('dictionary/LOAD_DEPT')
  130. store.dispatch('dictionary/LOAD_DICT_LIST', 'oper_module')
  131. store.dispatch('dictionary/LOAD_DICT_LIST', 'oper_type')
  132. }
  133. // 查询分页参数改变处理方法
  134. const handlePage = ({page, pageSize}: any) => {
  135. state.queryPage.pageNum = page
  136. state.queryPage.pageSize = pageSize
  137. handleSearch(page, pageSize)
  138. }
  139. // 重置查询表单方法
  140. const handleReset = () => {
  141. state.queryForm = {}
  142. state.back_queryForm = JSON.parse(JSON.stringify(state.queryForm))
  143. handleSearch()
  144. }
  145. // 查询方法
  146. const handleSearch = (page = 1, pageSize = 10) => {
  147. // 添加分页参数
  148. const queryParams: any = {
  149. pageNum: page,
  150. pageSize: pageSize,
  151. }
  152. // 添加表单参数
  153. for (const [k, v] of Object.entries(state.back_queryForm)) {
  154. if (that.$util.isValue(v)) {
  155. if (k === 'operationDate') {
  156. queryParams['beginTime'] = v[0]
  157. queryParams['endTime'] = v[1]
  158. } else {
  159. queryParams[k] = v
  160. }
  161. }
  162. }
  163. state.loading = true
  164. that.$api.getOperationLogList(queryParams).then((res: any) => {
  165. if (res.code === 200) {
  166. state.queryResult.tableData = res.rows
  167. state.queryResult.total = res.total
  168. } else {
  169. ElMessage.error(res.message)
  170. }
  171. state.loading = false
  172. }).catch(() => {
  173. state.loading = false
  174. })
  175. }
  176. // 点击查询按钮后
  177. const onSearch = () => {
  178. ref_cusTable.value.resetFilter()
  179. state.back_queryForm = JSON.parse(JSON.stringify(state.queryForm))
  180. state.queryPage.pageNum = 1
  181. handleSearch()
  182. }
  183. const onExport = () => {
  184. const queryParams: any = {
  185. }
  186. if (state.selected.length > 0) {
  187. queryParams['ids'] = state.selected.map(v => v.id)
  188. } else {
  189. // 添加表单参数
  190. for (const [k, v] of Object.entries(state.back_queryForm)) {
  191. if (that.$util.isValue(v)) {
  192. if (k === 'operationDate') {
  193. queryParams['beginTime'] = v[0]
  194. queryParams['endTime'] = v[1]
  195. } else {
  196. queryParams[k] = v
  197. }
  198. }
  199. }
  200. }
  201. that.$api.operLogExport(queryParams).then(res => {
  202. downLoadBlob(res, '操作记录.xlsx')
  203. ElMessage.success('导出成功!')
  204. }).catch(() => {
  205. ElMessage.error('导出失败!')
  206. })
  207. }
  208. onMounted(() => {
  209. state.back_queryForm = JSON.parse(JSON.stringify(state.queryForm))
  210. initDictionary()
  211. handleSearch()
  212. })
  213. return {
  214. ref_cusTable,
  215. ...toRefs(state),
  216. handleSearch,
  217. handlePage,
  218. handleReset,
  219. onSearch,
  220. onExport
  221. }
  222. },
  223. })
  224. </script>
  225. <style scoped lang="scss">
  226. </style>