import SaveForm from '@/components/save-form'
import Pagination from '@/components/pagination'
import {
DataTableRowKey,
NButton,
NCascader,
NDataTable,
NDescriptions,
NDescriptionsItem,
NDropdown,
NFormItem,
NIcon,
NImage,
NInput,
NInputNumber,
NModal,
NSelect,
NSpace,
NTag,
NTooltip,
useDialog,
useMessage
} from 'naive-ui'
import { defineComponent, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
import {
musicSheetApplicationOwnerList,
musicSheetPage,
musicSheetRemove,
musicSheetImg,
musicSheetStatusList,
musicTagPage,
musicSheetCategoriesQueryTree
} from '../../api'
import MusicOperation from '../modal/music-operationV2'
import { subjectPage } from '@/views/system-manage/api'
import MusicPreView from '../modal/musicPreViewCbs'
import UseProject from '@views/music-library/music-sheet/modal/use-project'
import { filterAudioPlayType, getMapValueByKey } from '@/utils/filters'
import { appKey, musicSheetSourceType } from '@/utils/constant'
import { getSelectDataFromObj } from '@/utils/objectUtil'
import { sysApplicationPage } from '@views/menu-manage/api'
import { getOwnerName, copyText } from '@views/music-library/musicUtil'
import styles from './music-list.module.less'
import MusicCreateImg from '../modal/music-create-img'
import TheTooltip from '@components/TheTooltip'
import { HelpCircleOutline } from '@vicons/ionicons5'
import { musicalInstrumentPage } from '@views/system-manage/subject-manage/api'
import MusiceBeatTime from '../modal/musiceBeatTime'
import MusicPlatform from '../modal/music-platform'
import { audioPlayTypeArray } from '@/utils/searchArray'
export default defineComponent({
name: 'music-list',
props: ['searchId', 'musicCategoryId'],
setup(props, { emit }) {
const dialog = useDialog()
const message = useMessage()
const state = reactive({
loading: false,
pagination: {
page: 1,
rows: 10,
pageTotal: 0
},
searchForm: {
keyword: null,
isScoreRender: null,
subjectId: null, //声部ID
sourceType: null, //来源类型/作者属性(PLATFORM: 平台; ORG: 机构; PERSON: 个人
composer: null, //作曲人/音乐人
userId: null, //所属人
applicationId: null, //所属人项目ID
useAppId: [] as any, //适用项目ID
status: null, //曲目状态(0:停用,1:启用)
appAuditFlag: null, //是否审核版本
categoriesId: null, //是否审核版本
musicCategoryId: null, //曲目分类
musicalInstrumentId: null, // 乐器ID
dataCorrect: null, // 数据修复
generateFirst: null, // 妙级课需要针对生成节拍器音频(暂时不用)
audioPlayTypes: null, // 场景
generateMetronomeAudio: null // 是否生成节拍器音频
},
dataList: [] as any,
subjectList: [] as any,
instrumentList: [] as any,
tagList: [] as any,
visiableMusic: false,
musicOperation: 'add',
musicData: {} as any,
musicSheetCategories: [] as any,
musicPreview: false,
musicPreviewScoreType: 'staff', // 预览谱面类型
musicScore: null as any,
showUseProject: false, // 适用项目
useProjectData: [] as any, // 适用项目行数据
showUseProjectId: null as any, // 适用项目行数据
detailReadonly: false, // 新增、修改、详情是否可编辑
userIdDisable: true, // 所属人
userIdData: [] as any, // 所属人数据列表
productOpen: false,
beatTimeOpen: false,
productItem: {} as any
})
const columns = (): any => {
return [
{
type: 'selection'
},
{
title: '曲目名称',
minWidth: '200px',
key: 'id',
render(row: any) {
return (
{
copyText(message, row.id)
}}
>
)
}
},
{
title: '封面图',
key: 'titleImg',
render(row: any): JSX.Element {
return
}
},
{
title: '曲目信息',
minWidth: '200px',
key: 'composer',
render(row: any) {
return (
{row.composer}
{row.isScoreRender ? '支持' : '不支持'}
{/**/}
{/* */}
{/**/}
)
}
},
{
title: '作者属性',
key: 'sourceType',
minWidth: '120px',
render(row: any) {
return (
{getMapValueByKey(row.sourceType, new Map(Object.entries(musicSheetSourceType)))}
{getOwnerName(row.musicSheetExtend, row.sourceType)}
)
}
},
{
title: '适用项目',
key: 'projectName',
render(row: any) {
return (
{
state.showUseProject = true
state.showUseProjectId = row.id
}}
>
{/* state.showUseProject = true}>显示适用项目 */}
)
}
},
{
title: '更新信息',
minWidth: '250px',
key: 'updateBy',
render(row: any) {
return (
{row.updateByName}
{row.updateTime}
)
}
},
{
title: '场景',
key: 'audioPlayTypes',
render(row: any) {
return (
{row.audioPlayTypeArray.map((item: any) => (
{filterAudioPlayType(item)}
))}
)
}
},
{
title: '审核版本',
minWidth: '100px',
key: 'appAuditFlag',
render(row: any) {
return
{row.appAuditFlag ? '是' : '否'}
}
},
{
title: '状态',
minWidth: '50px',
key: 'status',
render(row: any) {
return (
{row.status ? '启用' : '停用'}
)
}
},
{
title: '操作',
key: 'operation',
fixed: 'right',
width: '300px',
render(row: any) {
return (
{
state.musicPreview = true
state.musicScore = row
state.musicPreviewScoreType = key
}}
>
e.stopPropagation()}
>
预览
{
state.visiableMusic = true
state.musicOperation = 'preview'
state.musicData = row
state.detailReadonly = true
}}
>
查看
{
state.visiableMusic = true
state.musicOperation = 'edit'
state.musicData = row
state.detailReadonly = true
}}
>
修改
onChangeStatus(row)}
>
{row.status ? '停用' : '启用'}
{
state.productOpen = true
state.productItem = row
// handleAutoProduct(row)
}}
>
生成图片
{/* { row.isMixBeat &&
{
state.productItem = row
state.beatTimeOpen = true
}}
>
生成节拍器音频
} */}
onRmove(row)}
v-auth="musicSheet/remove1753457445635645442"
>
删除
)
}
}
]
}
const checkedRowKeysRef = ref([])
const handleCheck = (rowKeys: DataTableRowKey[]) => {
checkedRowKeysRef.value = rowKeys
}
const onChangeStatus = (row: any) => {
const statusStr = row.status ? '停用' : '启用'
dialog.warning({
title: '提示',
content: `是否${statusStr}?`,
positiveText: '确定',
negativeText: '取消',
onPositiveClick: async () => {
try {
await musicSheetStatusList({
ids: new Array(row.id),
status: !row.status
})
getList()
message.success(`${statusStr}成功`)
} catch {}
}
})
}
const onBatchChangeStatus = (status: boolean) => {
const length = checkedRowKeysRef.value.length
if (length == 0) {
message.warning('未选择数据')
}
const statusStr = !status ? '停用' : '启用'
dialog.warning({
title: '提示',
content: `是否${statusStr}` + length + `条数据?`,
positiveText: '确定',
negativeText: '取消',
onPositiveClick: async () => {
try {
await musicSheetStatusList({
ids: checkedRowKeysRef.value,
status: status
})
getList()
message.success(`${statusStr}成功`)
} catch {}
}
})
}
const updateUserIdData = async (sourceType: any) => {
if (!state.searchForm.applicationId) {
return
}
state.userIdData = []
state.searchForm.userId = null
if (sourceType && sourceType !== 'PLATFORM') {
const { data } = await musicSheetApplicationOwnerList({
page: 1,
rows: 9999,
sourceType: sourceType,
applicationId: state.searchForm.applicationId
})
const temp = data.rows || []
temp.forEach((next: any) => {
state.userIdData.push({
...next,
label: sourceType === 'PERSON' ? next.userName : next.organizationRole,
value: sourceType === 'PERSON' ? next.userId : next.organizationRoleId
})
})
}
}
const onRmove = (row: any): void => {
dialog.warning({
title: '提示',
content: `删除"${row.name}",是否继续?`,
positiveText: '确定',
negativeText: '取消',
onPositiveClick: async () => {
try {
await musicSheetRemove({ id: row.id })
getList()
message.success('删除成功')
} catch {}
}
})
}
const getList = async () => {
try {
state.loading = true
const sourceType = state.searchForm.sourceType
const userId = state.searchForm.userId
const audioPlayTypes = state.searchForm.audioPlayTypes
const { generateFirst, musicCategoryId, ...res } = state.searchForm
let search = {
...res,
useAppId: state.searchForm.useAppId
? state.searchForm.useAppId.join(',')
: state.searchForm.useAppId,
audioPlayTypes: [] as any,
musicCategoryId: musicCategoryId || generateFirst,
} as any
if (audioPlayTypes) {
if (audioPlayTypes === 'PLAY_SING') {
search.audioPlayTypes = ['PLAY', 'SING']
} else {
search.audioPlayTypes = [audioPlayTypes]
}
}
if (sourceType) {
if (sourceType == 'ORG') {
search.organizationRoleId = userId
search.userId = null
}
}
const { data } = await musicSheetPage({ ...state.pagination, ...search })
state.pagination.pageTotal = Number(data.total)
const result = data.rows || []
// 初始化场景
result.forEach((item: any) => {
item.audioPlayTypeArray = item.audioPlayTypes ? item.audioPlayTypes.split(',') : []
})
state.dataList = result
} catch {}
state.loading = false
}
// 获取标签
const getTagList = async () => {
try {
const { data } = await musicTagPage({ page: 1, rows: 999 })
const tempList = data.rows || []
tempList.forEach((item: any) => {
item.label = item.name
item.value = item.id
})
state.tagList = tempList
} catch {}
}
// 获取分类
const getMusicSheetCategorieList = async () => {
try {
const { data } = await musicSheetCategoriesQueryTree({})
// state.musicSheetCategories = filterPointCategory(data, 'musicSheetCategoriesList')
state.musicSheetCategories = data || []
clearEmptyMusicCategory(state.musicSheetCategories)
} catch (e) {}
}
const clearEmptyMusicCategory = (data: any) => {
for (let i = 0; i < data.length; i++) {
if (data[i].musicSheetCategoriesList.length < 1) {
data[i].musicSheetCategoriesList = null
} else {
clearEmptyMusicCategory(data[i].musicSheetCategoriesList)
}
}
}
// 获取声部
const initSubjectList = async () => {
try {
const { data } = await subjectPage({ page: 1, rows: 999 })
const tempList = data.rows || []
tempList.forEach((item: any) => {
item.label = item.name
item.value = item.id + ''
})
state.subjectList = tempList
} catch {}
}
const initInstrumentList = async () => {
try {
const { data } = await musicalInstrumentPage({ page: 1, rows: 999 })
const tempList = data.rows || []
tempList.forEach((item: any) => {
item.label = item.name
item.value = item.id + ''
})
state.instrumentList = tempList
} catch {}
}
// app列表
const initUseAppList = async () => {
try {
const appKeys = Object.keys(appKey)
const { data } = await sysApplicationPage({ page: 1, rows: 999, hiddenFlag: true })
const tempList = data.rows || []
state.useProjectData = []
const filter = tempList.filter((next: any) => {
return appKeys.includes(next.appKey)
})
filter.forEach((item: any) => {
state.useProjectData.push({
...item,
label: item.appName,
value: item.id
})
})
} catch {}
}
const saveForm = ref()
const onSubmit = () => {
state.pagination.page = 1
getList()
}
watch(
() => props.searchId,
(val) => {
console.log(val, 'searchId')
}
)
const onSearch = () => {
checkedRowKeysRef.value = []
saveForm.value?.submit()
}
const onBtnReset = () => {
saveForm.value?.reset()
}
onMounted(async () => {
state.loading = true
// getTagList()
if (props.searchId) {
state.searchForm.categoriesId = props.searchId || null
}
if (props.musicCategoryId) {
state.searchForm.musicCategoryId = props.musicCategoryId || null
}
initSubjectList()
initInstrumentList()
initUseAppList()
getMusicSheetCategorieList()
getList()
})
return () => (
)
}
})