music-sheet-kt.tsx 22 KB

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