push-record.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import {defineComponent, onMounted, reactive, ref} from 'vue'
  2. import SaveForm from '@components/save-form'
  3. import {DataTableRowKey, NButton, NDataTable, NDatePicker, NFormItem, NInput, NSelect, NSpace, useDialog, useMessage} from 'naive-ui'
  4. import Pagination from '@components/pagination'
  5. import {getMapValueByKey, getSelectDataFromObj} from '@/utils/objectUtil'
  6. import {clientType, messageSenderFunctionModule} from '@/utils/constant'
  7. import {getTimes} from "@/utils/dateUtil";
  8. import {sysMessageConfigPage, sysMessagePage} from "@views/message/api";
  9. export default defineComponent({
  10. name: 'push-record',
  11. props: {
  12. appKey: {
  13. type: String,
  14. required: true
  15. }
  16. },
  17. setup(props) {
  18. const dialog = useDialog()
  19. const message = useMessage()
  20. const state = reactive({
  21. loading: false,
  22. appId: null as any,
  23. pagination: {
  24. page: 1,
  25. rows: 10,
  26. pageTotal: 0
  27. },
  28. searchForm: {
  29. title: null, //消息名称
  30. clientId: null, //客户端
  31. model: null, // 功能模块
  32. sendTime: null // 发送时间
  33. },
  34. dataList: []
  35. })
  36. onMounted(async () => {
  37. getList()
  38. })
  39. const saveForm = ref()
  40. const onSearch = () => {
  41. saveForm.value?.submit()
  42. }
  43. const onBtnReset = () => {
  44. saveForm.value?.reset()
  45. }
  46. const onSubmit = () => {
  47. state.pagination.page = 1
  48. getList()
  49. }
  50. const checkedRowKeysRef = ref<DataTableRowKey[]>([])
  51. const handleCheck = (rowKeys: DataTableRowKey[]) => {
  52. checkedRowKeysRef.value = rowKeys
  53. }
  54. const getList = async () => {
  55. try {
  56. state.loading = true
  57. const {data} = await sysMessagePage({
  58. ...state.pagination,
  59. title: state.searchForm.title,
  60. clientId: state.searchForm.clientId,
  61. model: state.searchForm.model,
  62. appKey: props.appKey,
  63. sendMode:'PUSH',
  64. ...getTimes(state.searchForm.sendTime, ['sendTimeStart', 'sendTimeEnd']),
  65. })
  66. state.pagination.pageTotal = Number(data.total)
  67. state.dataList = data.rows || []
  68. } catch {
  69. }
  70. state.loading = false
  71. }
  72. const columns = (): any => {
  73. return [
  74. {
  75. title: '消息名称',
  76. key: 'description'
  77. },
  78. {
  79. title: '发送时间',
  80. key: 'sendTime'
  81. },
  82. {
  83. title: '发送平台',
  84. key: 'senderName'
  85. },
  86. {
  87. title: '姓名',
  88. key: 'username'
  89. },
  90. {
  91. title: '消息名称',
  92. key: 'title'
  93. },
  94. {
  95. title: '发送对象',
  96. key: 'clientId',
  97. render: (row: any) => {
  98. return (
  99. <div>
  100. {getMapValueByKey(row.clientId, new Map(Object.entries(clientType)))}
  101. </div>
  102. )
  103. }
  104. },
  105. {
  106. title: '功能模块',
  107. key: 'group',
  108. render: (row: any) => {
  109. return (
  110. <div>
  111. {getMapValueByKey(row.group, new Map(Object.entries(messageSenderFunctionModule)))}
  112. </div>
  113. )
  114. }
  115. },
  116. {
  117. title: '触发条件',
  118. key: 'triggerCondition'
  119. },
  120. {
  121. title: '推送标题',
  122. key: 'title'
  123. },
  124. {
  125. title: '推送内容',
  126. key: 'content'
  127. },
  128. ]
  129. }
  130. return () => {
  131. return (
  132. <div class="system-menu-container">
  133. <SaveForm
  134. ref={saveForm}
  135. model={state.searchForm}
  136. onSubmit={onSubmit}
  137. saveKey="push-record"
  138. onSetModel={(val: any) => (state.searchForm = val)}
  139. >
  140. <NFormItem label="消息名称" path="title">
  141. <NInput
  142. placeholder="请输入消息名称"
  143. v-model:value={state.searchForm.title}
  144. clearable
  145. />
  146. </NFormItem>
  147. <NFormItem label="发送对象" path="clientId">
  148. <NSelect
  149. placeholder="全部发送对象"
  150. v-model:value={state.searchForm.clientId}
  151. options={getSelectDataFromObj(clientType)}
  152. clearable
  153. />
  154. </NFormItem>
  155. <NFormItem label="功能模块" path="model">
  156. <NSelect
  157. filterable
  158. placeholder="全部功能模块"
  159. v-model:value={state.searchForm.model}
  160. options={getSelectDataFromObj(messageSenderFunctionModule)}
  161. clearable
  162. ></NSelect>
  163. </NFormItem>
  164. <NFormItem label="发送时间" path="sendTime">
  165. <NDatePicker
  166. v-model:value={state.searchForm.sendTime}
  167. type="daterange"
  168. clearable
  169. value-format="yyyy.MM.dd"
  170. startPlaceholder="开始时间"
  171. endPlaceholder="结束时间"
  172. />
  173. </NFormItem>
  174. <NFormItem>
  175. <NSpace>
  176. <NButton type="primary" onClick={onSearch}>
  177. 搜索
  178. </NButton>
  179. <NButton type="default" onClick={onBtnReset}>
  180. 重置
  181. </NButton>
  182. </NSpace>
  183. </NFormItem>
  184. </SaveForm>
  185. <div class={['section-container']}>
  186. <NDataTable
  187. loading={state.loading}
  188. columns={columns()}
  189. data={state.dataList}
  190. rowKey={(row: any) => row.id}
  191. scrollX={'1400'}
  192. ></NDataTable>
  193. <Pagination
  194. v-model:page={state.pagination.page}
  195. v-model:pageSize={state.pagination.rows}
  196. v-model:pageTotal={state.pagination.pageTotal}
  197. onList={getList}
  198. sync
  199. saveKey="push-record"
  200. ></Pagination>
  201. </div>
  202. </div>
  203. )
  204. }
  205. }
  206. })