tab3.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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
  13. :label="t('room.roomTitle')"
  14. name="roomTitle"
  15. style="width: 250px"
  16. >
  17. <a-input
  18. v-model:value="formState.roomTitle"
  19. :placeholder="t('room.roomTitle')"
  20. >
  21. </a-input>
  22. </a-form-item>
  23. <a-form-item
  24. :label="t('room.usingTime')"
  25. name="username"
  26. style="width: 350px"
  27. >
  28. <a-range-picker
  29. :show-time="{ format: 'HH:mm' }"
  30. format="YYYY-MM-DD HH:mm"
  31. style="width: 80%"
  32. v-model:value="formState.userTime"
  33. />
  34. </a-form-item>
  35. <a-form-item>
  36. <a-button type="primary" html-type="submit">
  37. {{ t('base.confirm') }}
  38. </a-button>
  39. </a-form-item>
  40. <a-form-item>
  41. <a-button type="primary" @click="exportList">
  42. {{ t('base.export') }}
  43. </a-button>
  44. </a-form-item>
  45. </a-form>
  46. </div>
  47. </a-col>
  48. </a-row>
  49. <a-row>
  50. <div class="container">
  51. <a-table
  52. align="center"
  53. :columns="columns"
  54. :data-source="msgList"
  55. :pagination="pagination"
  56. bordered
  57. >
  58. <template #bodyCell="{ column, text }">
  59. <template v-if="column.dataIndex === 'firstInRoomTime'">
  60. {{ dayjs(text).format('YYYY-MM-DD HH:mm') }}
  61. </template>
  62. <template v-if="column.dataIndex === 'lastOutRoomTime'">
  63. {{ dayjs(text).format('YYYY-MM-DD HH:mm') }}
  64. </template>
  65. <template v-if="column.dataIndex === 'texts'">
  66. {{
  67. text.join(';').length > 200
  68. ? text.join(';').substr(0, 200) + '...'
  69. : text.join(';')
  70. }}
  71. </template>
  72. </template>
  73. </a-table>
  74. </div>
  75. </a-row>
  76. </div>
  77. </template>
  78. <script lang="ts" setup>
  79. import { computed, onMounted, UnwrapRef, watch, unref, reactive } from 'vue'
  80. import { TableColumnProps } from 'ant-design-vue'
  81. import { useStatisticStore } from '@/store/modules/statistic'
  82. import dayjs from 'dayjs'
  83. import { useI18n } from '@/hook/useI18n'
  84. const { t } = useI18n()
  85. const statisticStore = useStatisticStore()
  86. const props = defineProps<{
  87. current: string
  88. }>()
  89. const msgList = computed(() => statisticStore.roomMsg.list)
  90. console.log('msgList', msgList)
  91. interface FormState {
  92. roomTitle: string
  93. userTime: string[]
  94. }
  95. const formState: UnwrapRef<FormState> = reactive({
  96. roomTitle: '',
  97. userTime: []
  98. })
  99. const columns: TableColumnProps[] = [
  100. {
  101. title: t('room.form.nickname'),
  102. dataIndex: 'nickName',
  103. width: 120
  104. },
  105. {
  106. title: t('room.form.phoneNumber'),
  107. // className: 'column-money',
  108. dataIndex: 'phoneNumber',
  109. width: 120
  110. },
  111. {
  112. title: t('room.roomTitle'),
  113. dataIndex: 'roomTitle',
  114. width: 120
  115. },
  116. {
  117. title: t('statistic.duration'),
  118. dataIndex: 'onlineTime',
  119. width: 120
  120. },
  121. {
  122. title: t('statistic.firstEnter'),
  123. dataIndex: 'firstInRoomTime',
  124. width: 160
  125. },
  126. {
  127. title: t('statistic.departure'),
  128. dataIndex: 'lastOutRoomTime',
  129. width: 160
  130. },
  131. {
  132. title: t('statistic.amount'),
  133. dataIndex: 'textCount',
  134. width: 80
  135. },
  136. {
  137. title: t('statistic.message'),
  138. dataIndex: 'texts',
  139. width: 140
  140. }
  141. ]
  142. const pagination = computed(() => {
  143. return {
  144. current: statisticStore.roomMsg.pageNum,
  145. total: statisticStore.roomMsg.total,
  146. pageSize: statisticStore.roomMsg.pageSize, //每页中显示10条数据
  147. showSizeChanger: true,
  148. onChange: (current: number, page: any) => {
  149. console.log('page', current, page)
  150. pagination.value.current = current
  151. pagination.value.pageSize = page
  152. fetchList()
  153. },
  154. pageSizeOptions: ['10', '20', '50', '100'], //每页中显示的数据
  155. showTotal: (total: string) => t('statistic.pageCount').replace('%N%', total) //分页中显示总的数据
  156. }
  157. })
  158. const fetchList = () => {
  159. try {
  160. console.log('formState-userTime', formState.userTime)
  161. statisticStore.fetchRoomMsglist({
  162. pageNum: pagination.value.current,
  163. pageSize: pagination.value.pageSize,
  164. // startTime: formState.userTime?.length ? formState.userTime[0] : '',
  165. // endTime: formState.userTime?.length ? formState.userTime[1] : '',
  166. timeList: formState.userTime
  167. ? formState.userTime.map(item => item.toString())
  168. : [],
  169. roomTitle: formState.roomTitle?.length ? formState.roomTitle : ''
  170. })
  171. } catch (error) {
  172. console.error('error', error)
  173. }
  174. }
  175. const exportList = () => {
  176. try {
  177. statisticStore.exportRoomMsgList({
  178. pageNum: pagination.value.current,
  179. pageSize: pagination.value.pageSize,
  180. // startTime: formState.userTime?.length ? formState.userTime[0] : '',
  181. // endTime: formState.userTime?.length ? formState.userTime[1] : '',
  182. timeList: formState.userTime
  183. ? formState.userTime.map(item => item.toString())
  184. : [],
  185. roomTitle: formState.roomTitle?.length ? formState.roomTitle : ''
  186. })
  187. } catch (error) {
  188. console.error('error', error)
  189. }
  190. }
  191. watch(
  192. () => props.current,
  193. val => {
  194. if (Number(unref(val)) === 3) {
  195. statisticStore.setRoomMsgPage()
  196. fetchList()
  197. } else {
  198. formState.roomTitle = ''
  199. formState.userTime = []
  200. }
  201. },
  202. {
  203. immediate: true
  204. }
  205. )
  206. const handleFinish = async () => {
  207. try {
  208. statisticStore.setRoomMsgPage()
  209. await fetchList()
  210. } catch (error) {
  211. console.error('error', error)
  212. }
  213. }
  214. const handleFinishFailed = () => {}
  215. </script>
  216. <style lang="less">
  217. .container {
  218. background-color: #fff;
  219. padding: 25px;
  220. width: 100%;
  221. margin-bottom: 25px;
  222. min-width: 875px;
  223. }
  224. </style>