music-sheet-kt.tsx 20 KB

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