index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. <template #operModule-column-value="{ scope }">
  64. {{$store.state.dictionary.operModuleMap.get(scope.row.operModule)}}
  65. </template>
  66. <template #operType-column-value="{ scope }">
  67. {{$store.state.dictionary.operTypeMap.get(scope.row.operType)}}
  68. </template>
  69. </CusTable>
  70. </template>
  71. </CusContent>
  72. </div>
  73. </div>
  74. </template>
  75. <script lang="ts">
  76. import {
  77. defineComponent,
  78. computed,
  79. onMounted,
  80. ref,
  81. reactive,
  82. watch,
  83. getCurrentInstance,
  84. ComponentInternalInstance,
  85. toRefs,
  86. nextTick
  87. } from 'vue'
  88. import {useStore} from 'vuex'
  89. import {useRouter, useRoute} from 'vue-router'
  90. import {getOperationLogList, operLogExport} from "@/api/modules/oper-log";
  91. import {getDeptList} from "@/api/modules/dept";
  92. import {ElMessage} from "element-plus";
  93. import {downLoadBlob} from "@/utils/downLoadUrl";
  94. export default defineComponent({
  95. name: '',
  96. components: {},
  97. setup(props, {emit}) {
  98. const store = useStore();
  99. const router = useRouter();
  100. const route = useRoute();
  101. const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties
  102. const state = reactive({
  103. // 加载中
  104. loading: false,
  105. // 查询分页参数
  106. queryPage: {
  107. pageNum: 1,
  108. pageSize: 10
  109. },
  110. // 查询结果
  111. queryResult: {
  112. total: 0,
  113. tableData: []
  114. },
  115. // 查询表单参数
  116. queryForm: <any>{},
  117. // 查询表单参数备份
  118. back_queryForm: {},
  119. // 表格表头
  120. tableHead: [
  121. {value: "operName", label: "操作人", show: true},
  122. {value: "deptName", label: "操作人单位", show: true},
  123. {value: "operIp", label: "设备IP", show: true},
  124. {value: "operModule", label: "操作模块", show: true},
  125. {value: "operType", label: "操作类型", show: true},
  126. // {value: "p1", label: "操作对象", show: true},
  127. // {value: "p1", label: "操作详情", show: true},
  128. {value: "operTime", label: "操作时间", show: true},
  129. ],
  130. selected: []
  131. });
  132. const ref_cusTable = ref()
  133. // 获取字典
  134. const initDictionary = () => {
  135. store.dispatch('dictionary/LOAD_DEPT')
  136. store.dispatch('dictionary/LOAD_DICT_LIST', 'oper_module')
  137. store.dispatch('dictionary/LOAD_DICT_LIST', 'oper_type')
  138. }
  139. // 查询分页参数改变处理方法
  140. const handlePage = ({page, pageSize}: any) => {
  141. state.queryPage.pageNum = page
  142. state.queryPage.pageSize = pageSize
  143. handleSearch(page, pageSize)
  144. }
  145. // 重置查询表单方法
  146. const handleReset = () => {
  147. state.queryForm = {}
  148. state.back_queryForm = JSON.parse(JSON.stringify(state.queryForm))
  149. handleSearch()
  150. }
  151. // 查询方法
  152. const handleSearch = (page = 1, pageSize = 10) => {
  153. // 添加分页参数
  154. const queryParams: any = {
  155. pageNum: page,
  156. pageSize: pageSize,
  157. }
  158. // 添加表单参数
  159. for (const [k, v] of Object.entries(state.back_queryForm)) {
  160. if (that.$util.isValue(v)) {
  161. if (k === 'operationDate') {
  162. queryParams['beginTime'] = v[0]
  163. queryParams['endTime'] = v[1]
  164. } else {
  165. queryParams[k] = v
  166. }
  167. }
  168. }
  169. state.loading = true
  170. that.$api.getOperationLogList(queryParams).then((res: any) => {
  171. if (res.code === 200) {
  172. state.queryResult.tableData = res.rows
  173. state.queryResult.total = res.total
  174. } else {
  175. ElMessage.error(res.message)
  176. }
  177. state.loading = false
  178. }).catch(() => {
  179. state.loading = false
  180. })
  181. }
  182. // 点击查询按钮后
  183. const onSearch = () => {
  184. ref_cusTable.value.resetFilter()
  185. state.back_queryForm = JSON.parse(JSON.stringify(state.queryForm))
  186. state.queryPage.pageNum = 1
  187. handleSearch()
  188. }
  189. const onExport = () => {
  190. const queryParams: any = {
  191. }
  192. if (state.selected.length > 0) {
  193. queryParams['ids'] = state.selected.map(v => v.id)
  194. } else {
  195. // 添加表单参数
  196. for (const [k, v] of Object.entries(state.back_queryForm)) {
  197. if (that.$util.isValue(v)) {
  198. if (k === 'operationDate') {
  199. queryParams['beginTime'] = v[0]
  200. queryParams['endTime'] = v[1]
  201. } else {
  202. queryParams[k] = v
  203. }
  204. }
  205. }
  206. }
  207. that.$api.operLogExport(queryParams).then(res => {
  208. downLoadBlob(res, '操作记录.xlsx')
  209. ElMessage.success('导出成功!')
  210. }).catch(() => {
  211. ElMessage.error('导出失败!')
  212. })
  213. }
  214. onMounted(() => {
  215. state.back_queryForm = JSON.parse(JSON.stringify(state.queryForm))
  216. initDictionary()
  217. handleSearch()
  218. })
  219. return {
  220. ref_cusTable,
  221. ...toRefs(state),
  222. handleSearch,
  223. handlePage,
  224. handleReset,
  225. onSearch,
  226. onExport
  227. }
  228. },
  229. })
  230. </script>
  231. <style scoped lang="scss">
  232. </style>