xm-operation-log-list.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <div>
  3. <a-col :span="10" style="z-index: 100">
  4. <a-form-model v-bind="{ wrapperCol: { span: 24 } }">
  5. <a-form-model-item>
  6. <AuditGroupPicker
  7. v-model="unit"
  8. :single="true"
  9. :read-only="false"
  10. :root-node="rootNode"
  11. @chang="chang"
  12. />
  13. </a-form-model-item>
  14. </a-form-model>
  15. </a-col>
  16. <a-col :span="5" style="z-index: 100">
  17. <a-form-model v-bind="{ wrapperCol: { span: 24 } }">
  18. <a-form-model-item>
  19. <SdUserPicker
  20. v-model="user"
  21. :single="true"
  22. :read-only="false"
  23. :root-node="userPickerRoot"
  24. @chang="chang"
  25. />
  26. </a-form-model-item>
  27. </a-form-model>
  28. </a-col>
  29. <a-col :span="20" style="z-index: 100">
  30. <a-form-model v-bind="{ wrapperCol: { span: 24 } }">
  31. <a-form-model-item>
  32. 日志时间:
  33. <a-date-picker
  34. v-model="startDate"
  35. :default-value="startDate"
  36. placeholder="开始时间"
  37. @change="dateChange"
  38. />
  39. ~
  40. <a-date-picker
  41. v-model="endDate"
  42. :default-value="endDate"
  43. placeholder="结束时间"
  44. @change="dateChange"
  45. />
  46. {{ tip }}
  47. &nbsp;&nbsp;&nbsp;&nbsp;
  48. <a-button @click="changDate('day', -7)">近七天</a-button>
  49. <a-button @click="changDate('month', -1)">近一个月</a-button>
  50. <a-button @click="changDate('month', -3)">近三个月</a-button>
  51. <a-button @click="exportData">导出数据</a-button>
  52. </a-form-model-item>
  53. </a-form-model>
  54. </a-col>
  55. <sd-data-table
  56. ref="dataTable"
  57. :columns="columns"
  58. :data-url="'api/xcoa-mobile/v1/operation-log/all-list'"
  59. :process-req="processReq"
  60. :process-res="processRes"
  61. :defultpagination-pagesize="10"
  62. :row-key="'id'"
  63. :change-param="changeParam"
  64. >
  65. </sd-data-table>
  66. </div>
  67. </template>
  68. <script>
  69. import components from './_import-components/xm-operation-log-list-import'
  70. import AuditGroupPicker from '../../components/picker/audit-group-picker.vue'
  71. import SdUserPicker from '@/common/components/sd-user-picker.vue'
  72. import { getUserInfo } from '@/common/store-mixin'
  73. import axios from '@/common/services/axios-instance'
  74. import moment from 'moment'
  75. import download from '@/common/services/download'
  76. import { Modal } from 'ant-design-vue'
  77. export default {
  78. name: 'XmOperatorLogList',
  79. metaInfo: {
  80. title: '用户操作日志列表',
  81. },
  82. components: { ...components, AuditGroupPicker, SdUserPicker },
  83. // components,
  84. data() {
  85. return {
  86. startDate: '',
  87. endDate: '',
  88. tip: '',
  89. unit: [],
  90. user: [],
  91. rootNode: {},
  92. data: [],
  93. columns: [],
  94. }
  95. },
  96. computed: {
  97. userPickerRoot() {
  98. return this.unit.length > 0 ? this.unit[0] : this.rootNode
  99. },
  100. },
  101. mounted() {
  102. this.columns.push({ title: '姓名', dataIndex: 'userName', width: '120px' })
  103. this.columns.push({ title: '公司', dataIndex: 'parentCompanyName' })
  104. this.columns.push({ title: '操作时间', dataIndex: 'time' })
  105. this.columns.push({ title: '操作模块', dataIndex: 'menuName' })
  106. this.columns.push({ title: '使用时长', dataIndex: 'holderDesc' })
  107. this.initAuditUnit()
  108. },
  109. methods: {
  110. exportData() {
  111. const param = {}
  112. this.changeParam(param)
  113. console.log(param)
  114. axios({
  115. url: 'api/xcoa-mobile/v1/operation-log/export-list',
  116. data: param,
  117. method: 'post',
  118. responseType: 'blob',
  119. }).then((res) => {
  120. if (res.status === 200) {
  121. console.log(res)
  122. const url = URL.createObjectURL(res.data)
  123. const filename = '模块操作日志.xlsx'
  124. download(url, decodeURI(filename))
  125. } else {
  126. Modal.warning({
  127. title: '提示',
  128. content: '导出报错,请联系管理员!',
  129. })
  130. return false
  131. }
  132. })
  133. },
  134. changeParam(param) {
  135. console.log(param)
  136. param.startDateRange = this.startDate
  137. param.endDateRange = this.endDate
  138. if (this.unit.length !== 0) {
  139. param.unitCode = this.unit[0].code
  140. param.unitId = this.unit[0].id
  141. }
  142. if (this.user.length !== 0) {
  143. param.account = this.user[0].code
  144. }
  145. },
  146. chang() {
  147. this.$refs.dataTable.refresh()
  148. },
  149. dateChange(data) {
  150. this.$refs.dataTable.refresh()
  151. this.tip = ''
  152. },
  153. changDate(type, amount) {
  154. if (type === 'day') {
  155. const d1 = new Date()
  156. d1.setDate(d1.getDate() + amount)
  157. this.startDate = moment(d1.getTime()).format('YYYY-MM-DD')
  158. this.endDate = moment(new Date().getTime()).format('YYYY-MM-DD')
  159. this.tip = '近' + Math.abs(amount) + '天'
  160. }
  161. if (type === 'month') {
  162. const d2 = new Date()
  163. d2.setMonth(d2.getMonth() + amount)
  164. this.startDate = moment(d2.getTime()).format('YYYY-MM-DD')
  165. this.endDate = moment(new Date().getTime()).format('YYYY-MM-DD')
  166. this.tip = '近' + Math.abs(amount) + '个月'
  167. }
  168. this.$refs.dataTable.refresh()
  169. },
  170. processRes(res) {
  171. console.log(res)
  172. const data1 = []
  173. if (res.data.length > 0) {
  174. const localOffset = new Date().getTimezoneOffset() * 60000 // 本地时区偏移量(以毫秒为单位)
  175. res.data.forEach((item) => {
  176. item.time = moment(item.time).format('YYYY-MM-DD hh:mm:ss')
  177. item.holderDesc = item.holderDesc ? item.holderDesc : '-'
  178. data1.push(item)
  179. })
  180. }
  181. return { data: data1, total: res.totalSize }
  182. },
  183. processReq(req) {
  184. if (req.data.pageSize === undefined) {
  185. req.data.pageSize = 10
  186. }
  187. return req
  188. },
  189. initAuditUnit() {
  190. const userInfo = getUserInfo()
  191. console.log(userInfo)
  192. const params = {}
  193. axios({
  194. url: 'api/xcoa-mobile/v1/iamorg/getCurrentUserGroup',
  195. method: 'get',
  196. }).then((res) => {
  197. params.orgId = res.data.id
  198. axios({
  199. url: 'api/xcoa-mobile/v1/iamorg/findIamOrg',
  200. method: 'post',
  201. params,
  202. }).then((res) => {
  203. const groupInfo = res.data
  204. const deptCode = groupInfo.orgId
  205. const deptName = res.data.orgName
  206. this.rootNode = { code: deptCode, name: deptName, id: res.data.id }
  207. this.unit = [this.rootNode]
  208. this.changDate('day', -7)
  209. })
  210. })
  211. },
  212. },
  213. }
  214. </script>
  215. <style module lang="scss">
  216. @use '@/common/design' as *;
  217. </style>