music-sheet-kt.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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. NImage,
  13. NInput,
  14. NModal,
  15. NSelect,
  16. NSpace,
  17. NTag,
  18. useDialog,
  19. useMessage
  20. } from 'naive-ui'
  21. import Pagination from '@components/pagination'
  22. import TheTooltip from '@components/TheTooltip'
  23. import AddMusic from '@views/music-library/project-music-sheet/module/kt/addMusic'
  24. import UpdateMusic from '@views/music-library/project-music-sheet/module/kt/updateMusic'
  25. import {
  26. musicSheetApplicationExtendCategoryList,
  27. musicSheetApplicationExtendDel,
  28. musicSheetApplicationExtendStatus,
  29. musicSheetApplicationOwnerList,
  30. musicSheetPageByApplication,
  31. musicSheetRemove
  32. } from '@views/music-library/api'
  33. import { getMapValueByKey, getSelectDataFromObj } from '@/utils/objectUtil'
  34. import {appKey, musicSheetAudioType, musicSheetPaymentType, musicSheetSourceType, musicSheetType} from '@/utils/constant'
  35. import { sysApplicationPage } from '@views/menu-manage/api'
  36. import { musicSheetApplicationExtendSubjectList } from '@views/system-manage/api'
  37. import { filterTimes } from '@/utils/dateUtil'
  38. import deepClone from '@/utils/deep.clone'
  39. import { getOwnerName } from '@views/music-library/musicUtil'
  40. import MusicPreView from '@views/music-library/music-sheet/modal/musicPreView'
  41. export default defineComponent({
  42. name: 'project-music-sheet-KT',
  43. props: {
  44. appKey: {
  45. type: String,
  46. default: 'KT'
  47. }
  48. },
  49. setup(props) {
  50. const dialog = useDialog()
  51. const message = useMessage()
  52. const state = reactive({
  53. loading: false,
  54. appId: null as any,
  55. pagination: {
  56. page: 1,
  57. rows: 10,
  58. pageTotal: 0
  59. },
  60. searchForm: {
  61. keyword: null,
  62. musicSheetType: null, //曲目类型(SINGLE:单曲 CONCERT:合奏)
  63. subjectId: null, //声部ID
  64. subjectIds: null, //曲目声部ID集合
  65. musicCategoryIds: null, //曲目分类ID
  66. status: null, //曲目状态(0:停用,1:启用)
  67. sourceType: null, //来源类型/作者属性(PLATFORM: 平台; ORG: 机构; PERSON: 个人)
  68. paymentType: null, //收费类型(FREE:免费;VIP:会员;CHARGE:单曲收费)
  69. userId: null, //所属人
  70. musicCategoryId: null, //曲目分类ID
  71. times: null, // 上传时间
  72. // startTime: null, //上传时间(年月日)
  73. // endTime: null, //上传时间(年月日)
  74. audioType: null, //音频类型(HOMEMODE: 自制 COMMON: 普通)
  75. exquisiteFlag: null, //精品标志
  76. topFlag: null, //是否置顶(0:否;1:是)
  77. availableType: null, //可用途径 ORG 机构 PLATFORM 平台
  78. appAuditFlag: null, //是否审核版本
  79. detailFlag: null, //是否查询详情
  80. applicationId: null, //所属人项目ID
  81. extendApplicationId: null //所属人项目ID
  82. },
  83. subjectList: [],
  84. dataList: [] as any[],
  85. musicSheetCategories: [],
  86. showAddDialog: false,
  87. showEditDialog: false,
  88. userIdDisable: true,
  89. userIdData: [] as any,
  90. updateRow: {} as any, // 修改选择的行
  91. applicationId: null, //应用ID
  92. musicPreview: false,
  93. musicScore: null as any,
  94. useProjectData: [] as any // 适用项目行数据
  95. })
  96. onMounted(async () => {
  97. state.loading = true
  98. // 加载声部
  99. try {
  100. // 获取应用APP信息
  101. const appRes = await sysApplicationPage({ page: 1, rows: 1, appKey: props.appKey })
  102. const appTempList = appRes.data.rows || []
  103. if (!appTempList || appTempList.length == 0) {
  104. state.loading = false
  105. message.error('加载项目信息失败')
  106. return
  107. }
  108. state.appId = appTempList[0].id
  109. state.applicationId = appTempList[0].id
  110. const { data } = await musicSheetApplicationExtendSubjectList({
  111. applicationId: state.applicationId
  112. })
  113. const tempList = data || []
  114. tempList.forEach((item: any) => {
  115. item.label = item.subjectName
  116. item.value = item.subjectId
  117. })
  118. state.subjectList = tempList
  119. //加载曲目分类列表
  120. const categoryRes = await musicSheetApplicationExtendCategoryList({
  121. applicationIds: state.appId
  122. })
  123. if (categoryRes.data && categoryRes.data.length > 0) {
  124. state.musicSheetCategories = categoryRes.data[0].musicSheetCategories
  125. }
  126. } catch {}
  127. // 加载表格数据
  128. initUseAppList()
  129. getList()
  130. })
  131. const initUseAppList = async () => {
  132. try {
  133. const appKeys = Object.keys(appKey)
  134. const { data } = await sysApplicationPage({ page: 1, rows: 999 })
  135. const tempList = data.rows || []
  136. state.useProjectData = []
  137. const filter = tempList.filter((next: any) => {
  138. return appKeys.includes(next.appKey)
  139. })
  140. filter.forEach((item: any) => {
  141. state.useProjectData.push({
  142. ...item,
  143. label: item.appName,
  144. value: item.id
  145. })
  146. })
  147. } catch {}
  148. }
  149. const saveForm = ref()
  150. const onSearch = () => {
  151. saveForm.value?.submit()
  152. }
  153. const onBtnReset = () => {
  154. saveForm.value?.reset()
  155. }
  156. const onSubmit = () => {
  157. state.pagination.page = 1
  158. getList()
  159. }
  160. const checkedRowKeysRef = ref<DataTableRowKey[]>([])
  161. const handleCheck = (rowKeys: DataTableRowKey[]) => {
  162. checkedRowKeysRef.value = rowKeys
  163. }
  164. const getList = async () => {
  165. state.loading = true
  166. try {
  167. const sourceType = state.searchForm.sourceType
  168. const { data } = await musicSheetPageByApplication({
  169. ...state.pagination,
  170. ...state.searchForm,
  171. userId: sourceType && sourceType === 'PERSON' ? state.searchForm.userId : null,
  172. organizationRoleId: sourceType && sourceType === 'ORG' ? state.searchForm.userId : null,
  173. ...filterTimes(state.searchForm.times, ['startTime', 'endTime']),
  174. applicationId: state.applicationId
  175. })
  176. state.pagination.pageTotal = Number(data.total)
  177. state.dataList = data.rows || []
  178. } catch {}
  179. state.loading = false
  180. }
  181. const onChangeStatus = (row: any) => {
  182. const statusStr = row.status ? '停用' : '启用'
  183. dialog.warning({
  184. title: '提示',
  185. content: `是否${statusStr}?`,
  186. positiveText: '确定',
  187. negativeText: '取消',
  188. onPositiveClick: async () => {
  189. try {
  190. await musicSheetApplicationExtendStatus({
  191. ids: row.applicationExtendId,
  192. status: !row.status
  193. })
  194. getList()
  195. message.success(`${statusStr}成功`)
  196. } catch {}
  197. }
  198. })
  199. }
  200. const onBatchChangeStatus = (status: boolean) => {
  201. const length = checkedRowKeysRef.value.length
  202. if (length == 0) {
  203. message.warning('未选择数据')
  204. }
  205. const statusStr = !status ? '停用' : '启用'
  206. dialog.warning({
  207. title: '提示',
  208. content: `是否${statusStr}` + length + `条数据?`,
  209. positiveText: '确定',
  210. negativeText: '取消',
  211. onPositiveClick: async () => {
  212. try {
  213. await musicSheetApplicationExtendStatus({
  214. ids: checkedRowKeysRef.value.join(','),
  215. status: status
  216. })
  217. getList()
  218. message.success(`${statusStr}成功`)
  219. } catch {}
  220. }
  221. })
  222. }
  223. const updateUserIdData = async (sourceType: any) => {
  224. if (!state.searchForm.extendApplicationId) {
  225. return
  226. }
  227. state.userIdData = []
  228. state.searchForm.userId = null
  229. if (sourceType && sourceType !== 'PLATFORM') {
  230. const { data } = await musicSheetApplicationOwnerList({
  231. page: 1,
  232. rows: 9999,
  233. sourceType: sourceType,
  234. applicationId: state.searchForm.extendApplicationId
  235. })
  236. const temp = data.rows || []
  237. temp.forEach((next: any) => {
  238. state.userIdData.push({
  239. ...next,
  240. label: sourceType === 'PERSON' ? next.userName : next.organizationRole,
  241. value: sourceType === 'PERSON' ? next.userId : next.organizationRoleId
  242. })
  243. })
  244. }
  245. }
  246. const onRmove = (row: any): void => {
  247. dialog.warning({
  248. title: '提示',
  249. content: `删除曲目,是否继续?`,
  250. positiveText: '确定',
  251. negativeText: '取消',
  252. onPositiveClick: async () => {
  253. try {
  254. await musicSheetApplicationExtendDel(row.applicationExtendId)
  255. getList()
  256. message.success('删除成功')
  257. } catch {}
  258. }
  259. })
  260. }
  261. const columns = (): any => {
  262. return [
  263. {
  264. type: 'selection'
  265. },
  266. {
  267. title: '曲目名称',
  268. key: 'id',
  269. render: (row: any) => (
  270. <>
  271. <NDescriptions labelPlacement="left" column={1}>
  272. <NDescriptionsItem label="曲目名称">
  273. <TheTooltip content={row.name} />{' '}
  274. </NDescriptionsItem>
  275. <NDescriptionsItem label="曲目编号">
  276. <TheTooltip content={row.id} />{' '}
  277. </NDescriptionsItem>
  278. </NDescriptions>
  279. </>
  280. )
  281. },
  282. {
  283. title: '封面图',
  284. key: 'musicCover',
  285. render(row: any): JSX.Element {
  286. return <NImage width={60} height={60} src={row.musicCover} />
  287. }
  288. },
  289. {
  290. title: '曲目信息',
  291. key: 'musicSheetCategoriesName',
  292. render: (row: any) => (
  293. <>
  294. <NDescriptions labelPlacement="left" column={1}>
  295. <NDescriptionsItem label="曲目来源">
  296. {getMapValueByKey(row.sourceType, new Map(Object.entries(musicSheetSourceType)))}
  297. </NDescriptionsItem>
  298. <NDescriptionsItem label="多声轨渲染">
  299. {getMapValueByKey(row.musicSheetType, new Map(Object.entries(musicSheetType)))}
  300. </NDescriptionsItem>
  301. <NDescriptionsItem label="所属人">
  302. <TheTooltip content={getOwnerName(row.musicSheetExtend, row.sourceType)} />
  303. </NDescriptionsItem>
  304. <NDescriptionsItem label="可用声部">
  305. <TheTooltip content={row.subjectNames} />
  306. </NDescriptionsItem>
  307. </NDescriptions>
  308. </>
  309. )
  310. },
  311. {
  312. title: '伴奏类型',
  313. key: 'audioType',
  314. render: (row: any) => {
  315. return (
  316. <div>
  317. {getMapValueByKey(row.audioType, new Map(Object.entries(musicSheetAudioType)))}
  318. </div>
  319. )
  320. }
  321. },
  322. // {
  323. // title: '可用声部',
  324. // key: 'subjectNames',
  325. // render: (row: any) => {
  326. // return <TheTooltip content={row.subjectNames}/>
  327. // }
  328. // },
  329. {
  330. title: '乐谱教材',
  331. key: 'musicSheetCategoryName'
  332. },
  333. // {
  334. // title: '可用途径',
  335. // key: 'availableType',
  336. // render: (row: any) => {
  337. // return <div>{getMapValueByKey(row.availableType, new Map(Object.entries(musicSheetAvailableType)))}</div>
  338. // }
  339. // },
  340. {
  341. title: '收费方式',
  342. key: 'paymentType',
  343. render: (row: any) => {
  344. return <div>{getMapValueByKey(row.paymentType, new Map(Object.entries(musicSheetPaymentType)))}</div>
  345. }
  346. },
  347. {
  348. title: '上传人',
  349. minWidth: '150px',
  350. key: 'composer',
  351. render(row: any) {
  352. return (
  353. <NDescriptions labelPlacement="left" column={1}>
  354. <NDescriptionsItem label="上传人">{row.createByName}</NDescriptionsItem>
  355. <NDescriptionsItem label="上传时间">{row.createTime}</NDescriptionsItem>
  356. </NDescriptions>
  357. )
  358. }
  359. },
  360. {
  361. title: '状态',
  362. key: 'status',
  363. render(row: any) {
  364. return (
  365. <NTag type={row.status ? 'primary' : 'default'}>{row.status ? '启用' : '停用'}</NTag>
  366. )
  367. }
  368. },
  369. {
  370. title: '操作',
  371. key: 'operation',
  372. fixed: 'right',
  373. render(row: any) {
  374. return (
  375. <NSpace>
  376. <NButton
  377. type="primary"
  378. size="small"
  379. text
  380. onClick={() => {
  381. state.musicPreview = true
  382. state.musicScore = row
  383. }}
  384. >
  385. 预览
  386. </NButton>
  387. <NButton
  388. type="primary"
  389. size="small"
  390. text
  391. v-auth="musicSheetApplicationExtend/status1751235210464198657"
  392. onClick={() => onChangeStatus(row)}
  393. >
  394. {row.status ? '停用' : '启用'}
  395. </NButton>
  396. <NButton
  397. type="primary"
  398. size="small"
  399. text
  400. v-auth="musicSheetApplicationExtend/update1751230252163530754"
  401. onClick={() => {
  402. state.showEditDialog = true
  403. state.updateRow = row
  404. }}
  405. >
  406. 修改
  407. </NButton>
  408. <NButton
  409. type="primary"
  410. size="small"
  411. text
  412. disabled={!!row.status}
  413. onClick={() => onRmove(row)}
  414. v-auth="musicSheetApplicationExtend/del1770696070576254977"
  415. >
  416. 删除
  417. </NButton>
  418. </NSpace>
  419. )
  420. }
  421. }
  422. ]
  423. }
  424. return () => {
  425. return (
  426. <div class="system-menu-container">
  427. <SaveForm
  428. ref={saveForm}
  429. model={state.searchForm}
  430. onSubmit={onSubmit}
  431. saveKey="music-sheet-kt"
  432. onSetModel={(val: any) => (state.searchForm = val)}
  433. >
  434. <NFormItem label="关键词" path="keyword">
  435. <NInput
  436. placeholder="请输入曲目名称/编号"
  437. v-model:value={state.searchForm.keyword}
  438. clearable
  439. />
  440. </NFormItem>
  441. <NFormItem label="曲目来源" path="sourceType">
  442. <NSelect
  443. placeholder="请选择曲目来源"
  444. v-model:value={state.searchForm.sourceType}
  445. options={getSelectDataFromObj(musicSheetSourceType)}
  446. onUpdateValue={async (value: any) => {
  447. state.userIdData = []
  448. state.searchForm.userId = null
  449. if (value && value !== 'PLATFORM') {
  450. await updateUserIdData(value)
  451. state.userIdDisable = !state.searchForm.extendApplicationId
  452. } else {
  453. state.userIdDisable = true
  454. }
  455. }}
  456. clearable
  457. />
  458. </NFormItem>
  459. <NFormItem label="所属项目" path="applicationId">
  460. <NSelect
  461. placeholder="请选择所属项目"
  462. v-model:value={state.searchForm.extendApplicationId}
  463. options={state.useProjectData}
  464. clearable
  465. onUpdateValue={async (value: any) => {
  466. state.searchForm.extendApplicationId = value
  467. if (value) {
  468. await updateUserIdData(state.searchForm.sourceType)
  469. state.userIdDisable = !(
  470. state.searchForm.sourceType && state.searchForm.sourceType !== 'PLATFORM'
  471. )
  472. } else {
  473. state.searchForm.userId = null
  474. state.userIdDisable = true
  475. state.userIdData = []
  476. }
  477. }}
  478. />
  479. </NFormItem>
  480. <NFormItem label="所属人" path="userId">
  481. <NSelect
  482. filterable={true}
  483. placeholder="请选择所属人"
  484. disabled={state.userIdDisable}
  485. v-model:value={state.searchForm.userId}
  486. options={state.userIdData}
  487. clearable
  488. ></NSelect>
  489. </NFormItem>
  490. <NFormItem label="多声轨渲染" path="subjectType">
  491. <NSelect
  492. placeholder="请选择多声轨渲染"
  493. v-model:value={state.searchForm.musicSheetType}
  494. options={getSelectDataFromObj(musicSheetType)}
  495. clearable
  496. />
  497. </NFormItem>
  498. <NFormItem label="伴奏类型" path="audioType">
  499. <NSelect
  500. placeholder="请选择伴奏类型"
  501. v-model:value={state.searchForm.audioType}
  502. options={getSelectDataFromObj(musicSheetAudioType)}
  503. clearable
  504. />
  505. </NFormItem>
  506. <NFormItem label="可用声部" path="subjectId">
  507. <NSelect
  508. placeholder="请选择可用声部"
  509. v-model:value={state.searchForm.subjectId}
  510. options={state.subjectList}
  511. clearable
  512. />
  513. </NFormItem>
  514. <NFormItem label="乐谱教材" path="musicCategoryId">
  515. <NCascader
  516. valueField="id"
  517. labelField="name"
  518. children-field="children"
  519. placeholder="请选择乐谱教材"
  520. v-model:value={state.searchForm.musicCategoryId}
  521. options={state.musicSheetCategories}
  522. clearable
  523. />
  524. </NFormItem>
  525. {/*<NFormItem*/}
  526. {/* label="可用途径"*/}
  527. {/* path="availableType"*/}
  528. {/*>*/}
  529. {/* <NSelect*/}
  530. {/* placeholder="请选择可用途径"*/}
  531. {/* v-model:value={state.searchForm.availableType}*/}
  532. {/* options={getSelectDataFromObj(musicSheetAvailableType)}*/}
  533. {/* clearable*/}
  534. {/* >*/}
  535. {/* </NSelect>*/}
  536. {/*</NFormItem>*/}
  537. <NFormItem label="收费方式" path="paymentType">
  538. <NSelect
  539. v-model:value={state.searchForm.paymentType}
  540. placeholder="请选择收费方式"
  541. options={
  542. [
  543. {
  544. label: '免费',
  545. value: 'FREE'
  546. },
  547. {
  548. label: '会员',
  549. value: 'VIP'
  550. }
  551. ] as any
  552. }
  553. clearable
  554. />
  555. </NFormItem>
  556. <NFormItem label="状态" path="status">
  557. <NSelect
  558. v-model:value={state.searchForm.status}
  559. placeholder="请选择状态"
  560. options={
  561. [
  562. {
  563. label: '启用',
  564. value: true
  565. },
  566. {
  567. label: '停用',
  568. value: false
  569. }
  570. ] as any
  571. }
  572. clearable
  573. />
  574. </NFormItem>
  575. <NFormItem label="上传时间" path="authorFrom">
  576. <NDatePicker
  577. v-model:value={state.searchForm.times}
  578. type="daterange"
  579. clearable
  580. value-format="yyyy.MM.dd"
  581. startPlaceholder="开始时间"
  582. endPlaceholder="结束时间"
  583. />
  584. </NFormItem>
  585. <NFormItem>
  586. <NSpace>
  587. <NButton type="primary" onClick={onSearch}>
  588. 搜索
  589. </NButton>
  590. <NButton type="default" onClick={onBtnReset}>
  591. 重置
  592. </NButton>
  593. </NSpace>
  594. </NFormItem>
  595. </SaveForm>
  596. <div class={['section-container']}>
  597. <NSpace style={{ paddingBottom: '12px' }}>
  598. <NButton
  599. type="primary"
  600. v-auth="musicSheetApplicationExtend/saveBatch1751234344277508097"
  601. onClick={() => {
  602. state.showAddDialog = true
  603. }}
  604. >
  605. 添加曲目
  606. </NButton>
  607. <NButton
  608. disabled={checkedRowKeysRef.value.length == 0}
  609. v-auth="musicSheetApplicationExtend/status1751235210464198657"
  610. onClick={() => {
  611. onBatchChangeStatus(false)
  612. }}
  613. >
  614. 批量停用
  615. </NButton>
  616. <NButton
  617. disabled={checkedRowKeysRef.value.length == 0}
  618. v-auth="musicSheetApplicationExtend/status1751235210464198657"
  619. onClick={() => {
  620. onBatchChangeStatus(true)
  621. }}
  622. >
  623. 批量启用
  624. </NButton>
  625. </NSpace>
  626. <NDataTable
  627. loading={state.loading}
  628. columns={columns()}
  629. data={state.dataList}
  630. rowKey={(row: any) => row.applicationExtendId}
  631. onUpdateCheckedRowKeys={handleCheck}
  632. scrollX={'1400'}
  633. ></NDataTable>
  634. <Pagination
  635. v-model:page={state.pagination.page}
  636. v-model:pageSize={state.pagination.rows}
  637. v-model:pageTotal={state.pagination.pageTotal}
  638. onList={getList}
  639. sync
  640. saveKey="music-sheet-kt"
  641. ></Pagination>
  642. </div>
  643. <NModal
  644. v-model:show={state.showAddDialog}
  645. preset="dialog"
  646. showIcon={false}
  647. title={'添加曲目'}
  648. style={{ width: '1300px' }}
  649. >
  650. <AddMusic
  651. onClose={() => (state.showAddDialog = false)}
  652. onGetList={() => {
  653. state.pagination.page = 1
  654. getList()
  655. }}
  656. subjectList={state.subjectList}
  657. appId={state.appId}
  658. musicSheetCategories={state.musicSheetCategories}
  659. />
  660. </NModal>
  661. <NModal
  662. v-model:show={state.showEditDialog}
  663. preset="dialog"
  664. showIcon={false}
  665. title={'修改曲目'}
  666. style={{ width: '500px' }}
  667. >
  668. <UpdateMusic
  669. onClose={() => (state.showEditDialog = false)}
  670. onGetList={() => {
  671. state.pagination.page = 1
  672. getList()
  673. }}
  674. rowData={state.updateRow}
  675. appId={state.appId}
  676. musicSheetCategories={state.musicSheetCategories}
  677. />
  678. </NModal>
  679. <NModal
  680. blockScroll={true}
  681. v-model:show={state.musicPreview}
  682. preset="dialog"
  683. showIcon={false}
  684. title={'曲目预览'}
  685. style={{ width: 'auto' }}
  686. >
  687. <MusicPreView item={state.musicScore} />
  688. </NModal>
  689. </div>
  690. )
  691. }
  692. }
  693. })