addMusic.tsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. import { defineComponent, h, onMounted, reactive, ref } from 'vue'
  2. import SaveForm from '@components/save-form'
  3. import {
  4. DataTableColumns,
  5. DataTableRowKey,
  6. NButton,
  7. NCascader,
  8. NDataTable,
  9. NFormItem,
  10. NIcon,
  11. NImage,
  12. NInput,
  13. NInputNumber,
  14. NSelect,
  15. NSpace,
  16. NStep,
  17. NSteps,
  18. useDialog,
  19. useMessage
  20. } from 'naive-ui'
  21. import Pagination from '@components/pagination'
  22. import { getMapValueByKey, getSelectDataFromObj } from '@/utils/objectUtil'
  23. import { musicSheetSourceType, musicSheetType } from '@/utils/constant'
  24. import {musicSheetApplicationExtendCategoryList, musicSheetApplicationExtendSaveBatch, musicSheetPage} from '@views/music-library/api'
  25. import deepClone from '@/utils/deep.clone'
  26. import { getOwnerName } from '@views/music-library/musicUtil'
  27. import TheTooltip from "@components/TheTooltip";
  28. export default defineComponent({
  29. name: 'gyt-addMusic',
  30. props: {
  31. appId: {
  32. type: String,
  33. required: true
  34. },
  35. subjectList: {
  36. type: Array,
  37. default: () => []
  38. },
  39. musicSheetCategories: {
  40. type: Array,
  41. default: () => []
  42. }
  43. },
  44. emits: ['close', 'getList'],
  45. setup(props, { slots, attrs, emit }) {
  46. const dialogs = useDialog()
  47. const message = useMessage()
  48. const state = reactive({
  49. loading: false,
  50. pagination: {
  51. page: 1,
  52. rows: 5,
  53. pageTotal: 0
  54. },
  55. stepPagination: {
  56. page: 1,
  57. rows: 5,
  58. pageTotal: 0
  59. },
  60. searchForm: {
  61. keyword: null,
  62. musicSheetType: null,
  63. subjectId: null,
  64. sourceType: null
  65. },
  66. subjectList: [] as any,
  67. showAdd: false,
  68. currentStep: 1,
  69. dataList: [],
  70. selectRowData: [] as any, // 选择的数据列表
  71. musicSheetCategories: [] as any,
  72. startSortNum: null as any, // 排序起始值
  73. projectMusicCategoryId: null as any // 曲目分类ID
  74. })
  75. onMounted(async () => {
  76. state.loading = true
  77. state.subjectList = props.subjectList
  78. // state.musicSheetCategories = props.musicSheetCategories
  79. //加载曲目分类列表
  80. try {
  81. const {data} = await musicSheetApplicationExtendCategoryList({
  82. applicationIds: props.appId
  83. })
  84. if (data && data.length > 0) {
  85. state.musicSheetCategories = data[0].musicSheetCategories
  86. }
  87. } catch {
  88. }
  89. await getList()
  90. })
  91. const getList = async () => {
  92. try {
  93. state.loading = true
  94. const { data } = await musicSheetPage({
  95. ...state.pagination,
  96. ...state.searchForm,
  97. addAppId: props.appId
  98. })
  99. state.pagination.pageTotal = Number(data.total)
  100. state.dataList = data.rows || []
  101. } catch {}
  102. state.loading = false
  103. }
  104. const saveForm = ref()
  105. const onSearch = () => {
  106. saveForm.value?.submit()
  107. }
  108. const onBtnReset = () => {
  109. saveForm.value?.reset()
  110. }
  111. const onSubmit = () => {
  112. state.pagination.page = 1
  113. getList()
  114. }
  115. const onSave = async () => {
  116. if (state.selectRowData.length == 0) {
  117. message.error('未选择曲目')
  118. return
  119. }
  120. const params = [] as any[]
  121. for (let i = 0; i < state.selectRowData.length; i++) {
  122. const item = state.selectRowData[i]
  123. if (!item.projectMusicCategoryId) {
  124. message.error('曲目分类不能为空')
  125. return
  126. }
  127. if (!item.sortNo || !item.projectMusicCategoryId) {
  128. message.error('排序号不能为空')
  129. return
  130. }
  131. params.push({
  132. ...item,
  133. musicSheetId: item.id,
  134. musicSheetCategoryId: item.projectMusicCategoryId,
  135. applicationId: props.appId,
  136. id: null
  137. })
  138. }
  139. const res = (await musicSheetApplicationExtendSaveBatch(params)) as any
  140. if (res && res.code == '200') {
  141. message.success(`添加成功`)
  142. emit('getList')
  143. emit('close')
  144. }
  145. }
  146. const columnsField = [
  147. {
  148. type: 'selection'
  149. },
  150. {
  151. title: '曲目编号',
  152. key: 'id'
  153. },
  154. {
  155. title: '封面图',
  156. key: 'titleImg',
  157. render(row: any) {
  158. return <NImage width={40} height={40} src={row.musicCover} />
  159. }
  160. },
  161. {
  162. title: '声部',
  163. key: 'subjectNames'
  164. },
  165. {
  166. title: '曲目名称',
  167. key: 'name'
  168. },
  169. {
  170. title: '音乐人',
  171. key: 'composer'
  172. },
  173. {
  174. title: '曲目类型',
  175. key: 'musicSheetType',
  176. render: (row: any) => {
  177. return (
  178. <div>
  179. {getMapValueByKey(row.musicSheetType, new Map(Object.entries(musicSheetType)))}
  180. </div>
  181. )
  182. }
  183. },
  184. {
  185. title: '作者属性',
  186. key: 'sourceType',
  187. render(row: any) {
  188. return getMapValueByKey(row.sourceType, new Map(Object.entries(musicSheetSourceType)))
  189. }
  190. },
  191. {
  192. title: '所属人',
  193. key: 'userName',
  194. render: (row: any) => {
  195. return <TheTooltip content={getOwnerName(row.musicSheetExtend, row.sourceType)} />
  196. }
  197. }
  198. ]
  199. const columns = (): any => {
  200. return columnsField
  201. }
  202. const stepColumns = (): DataTableColumns => {
  203. const field = deepClone(columnsField)
  204. field.splice(0, 1)
  205. field.push({
  206. title(column: any) {
  207. return (
  208. <NSpace>
  209. 曲目分类
  210. <NButton
  211. type="primary"
  212. size="small"
  213. text
  214. onClick={() => {
  215. dialogs.create({
  216. title: '请选择曲目分类',
  217. showIcon: false,
  218. content: () => {
  219. return h(
  220. 'div',
  221. {
  222. class: 'flex flex-col justify-center items-center text-14px'
  223. },
  224. [
  225. // icon
  226. h(NCascader, {
  227. onUpdateValue(v) {
  228. state.projectMusicCategoryId = v
  229. },
  230. valueField: 'id',
  231. labelField: 'name',
  232. childrenField: 'children',
  233. placeholderField: '请选择曲目分类',
  234. options: state.musicSheetCategories
  235. })
  236. ]
  237. )
  238. },
  239. positiveText: '确定',
  240. negativeText: '取消',
  241. onPositiveClick: () => {
  242. for (let i = 0; i < state.selectRowData.length; i++) {
  243. const item = state.selectRowData[i]
  244. item.projectMusicCategoryId = state.projectMusicCategoryId
  245. }
  246. }
  247. })
  248. }}
  249. >
  250. <NIcon size={15} style="padding-left: 5px;margin-top:4px">
  251. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
  252. <path d="M2 26h28v2H2z" fill="currentColor"></path>
  253. <path
  254. d="M25.4 9c.8-.8.8-2 0-2.8l-3.6-3.6c-.8-.8-2-.8-2.8 0l-15 15V24h6.4l15-15zm-5-5L24 7.6l-3 3L17.4 7l3-3zM6 22v-3.6l10-10l3.6 3.6l-10 10H6z"
  255. fill="currentColor"
  256. ></path>
  257. </svg>
  258. </NIcon>
  259. </NButton>
  260. </NSpace>
  261. )
  262. },
  263. key: 'projectMusicCategoryId',
  264. fixed: 'right',
  265. width: 200,
  266. render: (row: any) => {
  267. // })
  268. return (
  269. <NCascader
  270. valueField="id"
  271. labelField="name"
  272. children-field="children"
  273. placeholder="请选择曲目分类"
  274. value={row.projectMusicCategoryId}
  275. options={state.musicSheetCategories}
  276. onUpdateValue={(value: any) => {
  277. row.projectMusicCategoryId = value
  278. }}
  279. clearable
  280. />
  281. )
  282. }
  283. })
  284. field.push({
  285. title(column: any) {
  286. return (
  287. <NSpace>
  288. 排序
  289. <NButton
  290. type="primary"
  291. size="small"
  292. text
  293. onClick={() => {
  294. dialogs.create({
  295. title: '请输入排序起始值',
  296. showIcon: false,
  297. content: () => {
  298. return h(
  299. 'div',
  300. {
  301. class: 'flex flex-col justify-center items-center text-14px'
  302. },
  303. [
  304. // icon
  305. h(NInputNumber, {
  306. onUpdateValue(v) {
  307. state.startSortNum = v
  308. },
  309. min: 0,
  310. max: 9999
  311. })
  312. ]
  313. )
  314. },
  315. positiveText: '确定',
  316. negativeText: '取消',
  317. onPositiveClick: () => {
  318. if (state.startSortNum) {
  319. for (let i = 0; i < state.selectRowData.length; i++) {
  320. const item = state.selectRowData[i]
  321. item.sortNo = state.startSortNum + i
  322. }
  323. }
  324. }
  325. })
  326. }}
  327. >
  328. <NIcon size={15} style="padding-left: 5px;margin-top:4px">
  329. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
  330. <path d="M2 26h28v2H2z" fill="currentColor"></path>
  331. <path
  332. d="M25.4 9c.8-.8.8-2 0-2.8l-3.6-3.6c-.8-.8-2-.8-2.8 0l-15 15V24h6.4l15-15zm-5-5L24 7.6l-3 3L17.4 7l3-3zM6 22v-3.6l10-10l3.6 3.6l-10 10H6z"
  333. fill="currentColor"
  334. ></path>
  335. </svg>
  336. </NIcon>
  337. </NButton>
  338. </NSpace>
  339. )
  340. },
  341. key: 'sortNo',
  342. fixed: 'right',
  343. width: 150,
  344. render: (row: any) => {
  345. return h(NInputNumber, {
  346. value: row.sortNo,
  347. min: 0,
  348. max: 9999,
  349. onUpdateValue(value: any) {
  350. row.sortNo = value
  351. }
  352. })
  353. }
  354. })
  355. field.push({
  356. title: '操作',
  357. key: 'operation',
  358. fixed: 'right',
  359. render(row: any) {
  360. return (
  361. <NSpace>
  362. <NButton
  363. type="primary"
  364. size="small"
  365. text
  366. //v-auth="musicSheet/update1602302618558099458"
  367. onClick={() => {
  368. dialogs.warning({
  369. title: '警告',
  370. content: `是否删除该数据?`,
  371. positiveText: '确定',
  372. negativeText: '取消',
  373. onPositiveClick: async () => {
  374. try {
  375. const index = state.selectRowData.findIndex((item: any) => {
  376. if (item.id == row.id) {
  377. return true
  378. }
  379. })
  380. if (index > -1) {
  381. state.selectRowData.splice(index, 1)
  382. }
  383. const index1 = checkedRowKeysRef.value.findIndex((item: any) => {
  384. if (item == row.id) {
  385. return true
  386. }
  387. })
  388. if (index1 > -1) {
  389. checkedRowKeysRef.value.splice(index, 1)
  390. }
  391. } catch {}
  392. }
  393. })
  394. }}
  395. >
  396. 移除
  397. </NButton>
  398. </NSpace>
  399. )
  400. }
  401. })
  402. return field
  403. }
  404. const checkedRowKeysRef = ref<DataTableRowKey[]>([])
  405. const handleCheck = (rowKeys: DataTableRowKey[]) => {
  406. checkedRowKeysRef.value = rowKeys
  407. // 添加行更新值
  408. state.dataList.forEach((next: any) => {
  409. if (checkedRowKeysRef.value.includes(next.id)) {
  410. const find = state.selectRowData.find((row: any) => {
  411. return row.id === next.id
  412. })
  413. if (!find) {
  414. state.selectRowData.push(next)
  415. }
  416. }
  417. })
  418. // 去掉行更新值
  419. state.selectRowData = state.selectRowData.filter((next: any) => {
  420. return checkedRowKeysRef.value.includes(next.id)
  421. })
  422. }
  423. return () => {
  424. return (
  425. <div class="system-menu-container">
  426. <NSpace vertical size="medium">
  427. <NSteps
  428. current={state.currentStep}
  429. // onUpdateCurrent={()=>{
  430. // state.currentStep = val
  431. // }}
  432. style={'margin-bottom: 10px;margin-top: 10px'}
  433. >
  434. <NStep title="选择曲目" description=""></NStep>
  435. <NStep title="设置曲目信息" description=""></NStep>
  436. </NSteps>
  437. </NSpace>
  438. {state.currentStep === 1 && (
  439. <div class="system-menu-container">
  440. <SaveForm
  441. ref={saveForm}
  442. model={state.searchForm}
  443. onSubmit={onSubmit}
  444. // saveKey="cooleshow-edu-addMusic"
  445. onSetModel={(val: any) => (state.searchForm = val)}
  446. >
  447. <NFormItem label="关键词" path="keyword">
  448. <NInput
  449. v-model:value={state.searchForm.keyword}
  450. placeholder="请输入曲目名称/编号"
  451. clearable
  452. />
  453. </NFormItem>
  454. <NFormItem label="曲目类型" path="musicSheetType">
  455. <NSelect
  456. placeholder="请选择曲目类型"
  457. v-model:value={state.searchForm.musicSheetType}
  458. options={getSelectDataFromObj(musicSheetType)}
  459. clearable
  460. />
  461. </NFormItem>
  462. <NFormItem label="声部" path="musicSubject">
  463. <NSelect
  464. placeholder="请选择声部"
  465. v-model:value={state.searchForm.subjectId}
  466. options={state.subjectList}
  467. clearable
  468. />
  469. </NFormItem>
  470. <NFormItem label="曲目来源" path="sourceType">
  471. <NSelect
  472. placeholder="请选择曲目来源"
  473. v-model:value={state.searchForm.sourceType}
  474. options={getSelectDataFromObj(musicSheetSourceType)}
  475. // onUpdateValue={async (value: any) => {
  476. // }}
  477. clearable
  478. />
  479. </NFormItem>
  480. <NFormItem>
  481. <NSpace>
  482. <NButton type="primary" onClick={onSearch}>
  483. 搜索
  484. </NButton>
  485. <NButton type="default" onClick={onBtnReset}>
  486. 重置
  487. </NButton>
  488. </NSpace>
  489. </NFormItem>
  490. </SaveForm>
  491. <p style={{ paddingBottom: '12px' }}>
  492. 你选择了<span style={'color:red;padding:0 8px'}>{state.selectRowData.length}</span>
  493. 条曲目
  494. </p>
  495. <NDataTable
  496. loading={state.loading}
  497. columns={columns()}
  498. data={state.dataList}
  499. rowKey={(row: any) => row.id}
  500. onUpdateCheckedRowKeys={handleCheck}
  501. ></NDataTable>
  502. <Pagination
  503. v-model:page={state.pagination.page}
  504. v-model:pageSize={state.pagination.rows}
  505. v-model:pageTotal={state.pagination.pageTotal}
  506. onList={getList}
  507. sync
  508. // saveKey="cooleshow-edu-addMusic"
  509. ></Pagination>
  510. </div>
  511. )}
  512. {state.currentStep === 2 && (
  513. <div class="system-menu-container" style={'margin-top: 15px;'}>
  514. <NDataTable
  515. loading={state.loading}
  516. columns={stepColumns()}
  517. data={state.selectRowData}
  518. rowKey={(row: any) => row.id}
  519. maxHeight={500}
  520. ></NDataTable>
  521. </div>
  522. )}
  523. <NSpace justify="end" style={'margin-top:10px'}>
  524. <NButton
  525. type="default"
  526. onClick={() => {
  527. if (state.currentStep > 1) {
  528. state.currentStep = state.currentStep - 1
  529. } else {
  530. emit('close')
  531. }
  532. }}
  533. >
  534. {state.currentStep === 1 ? '取消' : '上一步'}
  535. </NButton>
  536. <NButton
  537. type="primary"
  538. onClick={() => {
  539. if (state.currentStep < 2) {
  540. if (state.selectRowData.length == 0) {
  541. message.warning('请选择曲目')
  542. return
  543. }
  544. state.currentStep = state.currentStep + 1
  545. } else {
  546. onSave()
  547. }
  548. }}
  549. // loading={btnLoading.value}
  550. // disabled={btnLoading.value}
  551. >
  552. {state.currentStep === 2 ? '确定' : '下一步'}
  553. </NButton>
  554. </NSpace>
  555. </div>
  556. )
  557. }
  558. }
  559. })