tab3.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div>
  3. <a-row>
  4. <a-col :span="24">
  5. <div class="container search-container">
  6. <a-form
  7. layout="inline"
  8. :model="formState"
  9. @finish="handleFinish"
  10. @finishFailed="handleFinishFailed"
  11. >
  12. <a-form-item label="房间名称" name="roomTitle">
  13. <a-input
  14. v-model:value="formState.roomTitle"
  15. placeholder="房间名称"
  16. >
  17. </a-input>
  18. </a-form-item>
  19. <a-form-item label="使用时间" name="username">
  20. <a-range-picker
  21. :show-time="{ format: 'HH:mm' }"
  22. format="YYYY-MM-DD HH:mm"
  23. style="width: 80%"
  24. v-model:value="formState.userTime"
  25. />
  26. </a-form-item>
  27. <a-form-item>
  28. <a-button type="primary" html-type="submit"> 确定 </a-button>
  29. </a-form-item>
  30. </a-form>
  31. </div>
  32. </a-col>
  33. </a-row>
  34. <a-row>
  35. <div class="container">
  36. <a-table
  37. align="center"
  38. :columns="columns"
  39. :data-source="msgList"
  40. :pagination="pagination"
  41. bordered
  42. >
  43. <template #bodyCell="{ column, text }">
  44. <template v-if="column.dataIndex === 'firstInRoomTime'">
  45. {{ dayjs(text).format('YYYY-MM-DD HH:mm') }}
  46. </template>
  47. <template v-if="column.dataIndex === 'lastOutRoomTime'">
  48. {{ dayjs(text).format('YYYY-MM-DD HH:mm') }}
  49. </template>
  50. <template v-if="column.dataIndex === 'texts'">
  51. {{ text.join(';') }}
  52. </template>
  53. </template>
  54. </a-table>
  55. </div>
  56. </a-row>
  57. </div>
  58. </template>
  59. <script lang="ts" setup>
  60. import { computed, onMounted, UnwrapRef, reactive } from 'vue'
  61. import { TableColumnProps } from 'ant-design-vue'
  62. import { useStatisticStore } from '@/store/modules/statistic'
  63. import dayjs from 'dayjs'
  64. const statisticStore = useStatisticStore()
  65. const msgList = computed(() => statisticStore.roomMsg.list)
  66. const pagination = reactive({
  67. current: 1,
  68. total: statisticStore.roomMsg.total,
  69. pageSize: 20, //每页中显示10条数据
  70. showSizeChanger: true,
  71. pageSizeOptions: ['10', '20', '50', '100'], //每页中显示的数据
  72. showTotal: (total: string) => `共有 ${total} 条数据` //分页中显示总的数据
  73. })
  74. console.log('msgList', msgList)
  75. interface FormState {
  76. roomTitle: string
  77. userTime: string[]
  78. }
  79. const formState: UnwrapRef<FormState> = reactive({
  80. roomTitle: '',
  81. userTime: []
  82. })
  83. const columns: TableColumnProps[] = [
  84. {
  85. title: '昵称',
  86. dataIndex: 'nickName'
  87. },
  88. {
  89. title: '手机号',
  90. // className: 'column-money',
  91. dataIndex: 'phoneNumber'
  92. },
  93. {
  94. title: '房间名称',
  95. dataIndex: 'roomTitle'
  96. },
  97. {
  98. title: '时长/分',
  99. dataIndex: 'onlineTime',
  100. width: 120
  101. },
  102. {
  103. title: '初次进入房间',
  104. dataIndex: 'firstInRoomTime',
  105. width: 200
  106. },
  107. {
  108. title: '最后离开房间',
  109. dataIndex: 'lastOutRoomTime',
  110. width: 200
  111. },
  112. {
  113. title: '数量',
  114. dataIndex: 'textCount',
  115. width: 80
  116. },
  117. {
  118. title: '留言内容',
  119. dataIndex: 'texts',
  120. width: 140
  121. }
  122. ]
  123. onMounted(async () => {
  124. await statisticStore.fetchRoomMsglist({
  125. pageNum: 1,
  126. pageSize: 20,
  127. startTime: '',
  128. endTime: ''
  129. })
  130. })
  131. const handleFinish = () => {
  132. try {
  133. statisticStore.fetchRoomMsglist({
  134. startTime: formState.userTime ? formState.userTime[0] : '',
  135. endTime: formState.userTime ? formState.userTime[1] : '',
  136. pageNum: 1,
  137. pageSize: 20,
  138. roomTitle: formState.roomTitle
  139. })
  140. } catch (error) {
  141. console.error('error', error)
  142. }
  143. }
  144. const handleFinishFailed = () => {}
  145. </script>
  146. <style lang="less">
  147. .container {
  148. background-color: #fff;
  149. padding: 25px;
  150. width: 100%;
  151. margin-bottom: 25px;
  152. }
  153. </style>