message-template-list.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. import {defineComponent, onMounted, reactive, ref} from 'vue'
  2. import SaveForm from '@components/save-form'
  3. import {
  4. DataTableRowKey,
  5. NButton,
  6. NCascader,
  7. NDataTable,
  8. NDatePicker,
  9. NDescriptions,
  10. NDescriptionsItem,
  11. NFormItem,
  12. NIcon,
  13. NImage,
  14. NInput,
  15. NModal,
  16. NSelect,
  17. NSpace,
  18. NTag,
  19. NTooltip,
  20. useDialog,
  21. useMessage
  22. } from 'naive-ui'
  23. import Pagination from '@components/pagination'
  24. import TheTooltip from '@components/TheTooltip'
  25. import AddMusic from '@views/music-library/project-music-sheet/module/gym/addMusic'
  26. import {getMapValueByKey, getSelectDataFromObj} from '@/utils/objectUtil'
  27. import {
  28. appKey, clientType, messageSenderFunctionModule, messageSenderMode,
  29. musicSheetAudioType,
  30. musicSheetPaymentType,
  31. musicSheetSourceType,
  32. musicSheetType
  33. } from '@/utils/constant'
  34. import {
  35. musicSheetApplicationExtendCategoryList,
  36. musicSheetApplicationExtendDel,
  37. musicSheetApplicationExtendStatus,
  38. musicSheetApplicationOwnerList,
  39. musicSheetPageByApplication,
  40. musicSheetStatusList, sysMessageConfigPage
  41. } from '@views/music-library/api'
  42. import UpdateMusic from '@views/music-library/project-music-sheet/module/gym/updateMusic'
  43. import {subjectPage, sysApplicationPage} from '@views/system-manage/api'
  44. import {filterTimes} from '@/utils/dateUtil'
  45. import deepClone from '@/utils/deep.clone'
  46. import {getOwnerName} from '@views/music-library/musicUtil'
  47. import MusicPreView from '@views/music-library/music-sheet/modal/musicPreView'
  48. import {HelpCircleOutline} from '@vicons/ionicons5'
  49. export default defineComponent({
  50. name: 'message-template-list',
  51. props: {
  52. appKey: {
  53. type: String,
  54. default: 'kT'
  55. }
  56. },
  57. setup(props) {
  58. const dialog = useDialog()
  59. const message = useMessage()
  60. const state = reactive({
  61. loading: false,
  62. appId: null as any,
  63. pagination: {
  64. page: 1,
  65. rows: 10,
  66. pageTotal: 0
  67. },
  68. searchForm: {
  69. description: null, //消息名称
  70. sendMode: null, // 消息类型
  71. clientId: null, //客户端
  72. model: null,
  73. status: null
  74. },
  75. subjectList: [],
  76. dataList: [] as any[],
  77. musicSheetCategories: [],
  78. showAddDialog: false,
  79. showEditDialog: false,
  80. userIdDisable: true,
  81. userIdData: [] as any,
  82. updateRow: {} as any, // 修改选择的行
  83. applicationId: null, //应用ID
  84. musicPreview: false,
  85. musicScore: null as any,
  86. useProjectData: [] as any // 适用项目行数据
  87. })
  88. onMounted(async () => {
  89. state.loading = true
  90. // 获取应用APP信息
  91. try {
  92. const {data} = await sysApplicationPage({page: 1, rows: 1, appKey: props.appKey})
  93. const tempList = data.rows || []
  94. if (!tempList || tempList.length == 0) {
  95. state.loading = false
  96. message.error('加载项目信息失败')
  97. return
  98. }
  99. state.appId = tempList[0].id
  100. state.applicationId = tempList[0].id
  101. } catch {
  102. }
  103. // 加载声部
  104. try {
  105. const {data} = await subjectPage({page: 1, rows: 999})
  106. const tempList = data.rows || []
  107. tempList.forEach((item: any) => {
  108. item.label = item.name
  109. item.value = item.id + ''
  110. })
  111. state.subjectList = tempList
  112. } catch {
  113. }
  114. //加载曲目分类列表
  115. try {
  116. const {data} = await musicSheetApplicationExtendCategoryList({
  117. applicationIds: state.appId
  118. })
  119. if (data && data.length > 0) {
  120. state.musicSheetCategories = data[0].musicSheetCategories
  121. }
  122. } catch {
  123. }
  124. // 加载表格数据
  125. initUseAppList()
  126. getList()
  127. })
  128. const initUseAppList = async () => {
  129. try {
  130. const appKeys = Object.keys(appKey)
  131. const {data} = await sysApplicationPage({page: 1, rows: 999})
  132. const tempList = data.rows || []
  133. state.useProjectData = []
  134. const filter = tempList.filter((next: any) => {
  135. return appKeys.includes(next.appKey)
  136. })
  137. filter.forEach((item: any) => {
  138. state.useProjectData.push({
  139. ...item,
  140. label: item.appName,
  141. value: item.id
  142. })
  143. })
  144. } catch {
  145. }
  146. }
  147. const saveForm = ref()
  148. const onSearch = () => {
  149. saveForm.value?.submit()
  150. }
  151. const onBtnReset = () => {
  152. saveForm.value?.reset()
  153. }
  154. const onSubmit = () => {
  155. state.pagination.page = 1
  156. getList()
  157. }
  158. const checkedRowKeysRef = ref<DataTableRowKey[]>([])
  159. const handleCheck = (rowKeys: DataTableRowKey[]) => {
  160. checkedRowKeysRef.value = rowKeys
  161. }
  162. const getList = async () => {
  163. try {
  164. state.loading = true
  165. const {data} = await sysMessageConfigPage({
  166. ...state.pagination,
  167. ...state.searchForm,
  168. appKey: props.appKey,
  169. })
  170. state.pagination.pageTotal = Number(data.total)
  171. state.dataList = data.rows || []
  172. } catch {
  173. }
  174. state.loading = false
  175. }
  176. const onChangeStatus = (row: any) => {
  177. const statusStr = row.status ? '停用' : '启用'
  178. dialog.warning({
  179. title: '提示',
  180. content: `是否${statusStr}?`,
  181. positiveText: '确定',
  182. negativeText: '取消',
  183. onPositiveClick: async () => {
  184. try {
  185. await musicSheetApplicationExtendStatus({
  186. ids: row.applicationExtendId,
  187. status: !row.status
  188. })
  189. getList()
  190. message.success(`${statusStr}成功`)
  191. } catch {
  192. }
  193. }
  194. })
  195. }
  196. const columns = (): any => {
  197. return [
  198. {
  199. title: '消息名称',
  200. key: 'description'
  201. },
  202. {
  203. title: '详细类型',
  204. key: 'sendMode',
  205. render: (row: any) => {
  206. return (
  207. <div>
  208. {getMapValueByKey(row.sendMode, new Map(Object.entries(messageSenderMode)))}
  209. </div>
  210. )
  211. }
  212. },
  213. {
  214. title: '客户端',
  215. key: 'clientId',
  216. render: (row: any) => {
  217. return (
  218. <div>
  219. {getMapValueByKey(row.clientId, new Map(Object.entries(clientType)))}
  220. </div>
  221. )
  222. }
  223. },
  224. {
  225. title: '功能模块',
  226. key: 'messageType'
  227. },
  228. {
  229. title: '触发条件',
  230. key: 'triggerCondition'
  231. },
  232. {
  233. title: '消息模板',
  234. key: 'content'
  235. },
  236. {
  237. title: '示例',
  238. key: 'contentExample'
  239. },
  240. {
  241. title: '更新人',
  242. key: 'operatorName'
  243. },
  244. {
  245. title: '更新时间',
  246. key: 'updateTime'
  247. },
  248. {
  249. title: '状态',
  250. key: 'status',
  251. render(row: any) {
  252. return (
  253. <NTag type={row.status ? 'primary' : 'default'}>{row.status ? '启用' : '停用'}</NTag>
  254. )
  255. }
  256. },
  257. {
  258. title: '操作',
  259. key: 'operation',
  260. fixed: 'right',
  261. render(row: any) {
  262. return (
  263. <NSpace>
  264. <NButton
  265. type="primary"
  266. size="small"
  267. text
  268. // v-auth="musicSheetApplicationExtend/status1751235150422736897"
  269. onClick={() => onChangeStatus(row)}
  270. >
  271. {row.status ? '停用' : '启用'}
  272. </NButton>
  273. </NSpace>
  274. )
  275. }
  276. }
  277. ]
  278. }
  279. return () => {
  280. return (
  281. <div class="system-menu-container">
  282. <SaveForm
  283. ref={saveForm}
  284. model={state.searchForm}
  285. onSubmit={onSubmit}
  286. saveKey="message-template"
  287. onSetModel={(val: any) => (state.searchForm = val)}
  288. >
  289. <NFormItem label="短信名称" path="description">
  290. <NInput
  291. placeholder="请输入短信名称"
  292. v-model:value={state.searchForm.description}
  293. clearable
  294. />
  295. </NFormItem>
  296. <NFormItem label="短信类型" path="sendMode">
  297. <NSelect
  298. placeholder="全部类型"
  299. v-model:value={state.searchForm.sendMode}
  300. options={getSelectDataFromObj(messageSenderMode)}
  301. clearable
  302. />
  303. </NFormItem>
  304. <NFormItem label="客户端" path="clientId">
  305. <NSelect
  306. placeholder="请选择所属项目"
  307. v-model:value={state.searchForm.clientId}
  308. options={getSelectDataFromObj(clientType)}
  309. clearable
  310. />
  311. </NFormItem>
  312. <NFormItem label="功能模块" path="model">
  313. <NSelect
  314. filterable
  315. placeholder="全部功能模块"
  316. options={getSelectDataFromObj(messageSenderFunctionModule)}
  317. clearable
  318. ></NSelect>
  319. </NFormItem>
  320. <NFormItem label="状态" path="status">
  321. <NSelect
  322. v-model:value={state.searchForm.status}
  323. placeholder="请选择状态"
  324. options={
  325. [
  326. {
  327. label: '启用',
  328. value: true
  329. },
  330. {
  331. label: '停用',
  332. value: false
  333. }
  334. ] as any
  335. }
  336. clearable
  337. />
  338. </NFormItem>
  339. <NFormItem>
  340. <NSpace>
  341. <NButton type="primary" onClick={onSearch}>
  342. 搜索
  343. </NButton>
  344. <NButton type="default" onClick={onBtnReset}>
  345. 重置
  346. </NButton>
  347. </NSpace>
  348. </NFormItem>
  349. </SaveForm>
  350. <div class={['section-container']}>
  351. <NDataTable
  352. loading={state.loading}
  353. columns={columns()}
  354. data={state.dataList}
  355. rowKey={(row: any) => row.applicationExtendId}
  356. // onUpdateCheckedRowKeys={handleCheck}
  357. scrollX={'1400'}
  358. ></NDataTable>
  359. <Pagination
  360. v-model:page={state.pagination.page}
  361. v-model:pageSize={state.pagination.rows}
  362. v-model:pageTotal={state.pagination.pageTotal}
  363. onList={getList}
  364. sync
  365. saveKey="message-template"
  366. ></Pagination>
  367. </div>
  368. </div>
  369. )
  370. }
  371. }
  372. })