办学质量监测教学评价系统
shenrongliang
2025-06-13 11d86cc6c26bb4f709e407acadf4805c2024e79f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<script setup lang="ts">
import { ref,computed ,onMounted, watch} from 'vue';
import { NTabs ,NTabPane ,NInput,NSwitch ,NTooltip, NTag ,NButton, useMessage,NSelect, NImage, NSlider, useOsTheme} from "naive-ui";
import { SvgIcon } from '@/components/common';
import { mlog } from '@/api';
import { sunoFetch ,lyricsFetch, randStyle, FeedTask} from '@/api/suno';
import { t } from '@/locales';
import { homeStore, useAppStore } from '@/store';
import { SunoMedia } from '@/api/sunoStore';
import mcUploaderMp3 from './mcUploadMp3.vue'
import type { CSSProperties } from 'vue'
const st = ref({type:'custom',isLoading:false})
const exSuno= ref<SunoMedia>()
const des= ref( {
  "gpt_description_prompt": "",
  "make_instrumental": false,
  "mv": "chirp-v3-5",
  "prompt": ""
});
const cs= ref({
  "prompt": "",
  "mv": "chirp-v3-5",
  "title": "",
  "tags": "",
  "continue_at": 120,
  "continue_clip_id": ""
 
});
const OsTheme = useOsTheme()
const mvOption= [
{label: 'verion: v3.5',value: 'chirp-v3-5'}
,{label:'verion: v3',value: 'chirp-v3-0'}
 ]
 
const canPost = computed(() => {
   // return true; 
    if( st.value.isLoading ) return false;
    if( st.value.type=='custom'){
        return cs.value.tags && cs.value.title
    }
    if( st.value.type=='description' ){
        mlog('des: ', des.value.gpt_description_prompt , des.value.make_instrumental )
        return cs.value.title &&( des.value.gpt_description_prompt || des.value.make_instrumental)
    }
    return true
})
 
const ms = useMessage();
onMounted(() => {
    homeStore.setMyData({ms:ms})
});
//生成歌词
const generateLyrics= ()=>{
    //generate/lyrics
    let prompt = cs.value.prompt || cs.value.title;
    if (!prompt){
        ms.error(   t('suno.inputly') )
        return 
    }
    if(st.value.isLoading) {
         ms.info( t('suno.doingly'));
        return;
    }
    st.value.isLoading =true;
    ms.info( t('suno.doingly2') );
    sunoFetch(  '/generate/lyrics/' ,  {prompt}).then(async (r:any )=>{
        mlog('lyrics', r);
        let dz:any = await lyricsFetch( r.data );
         mlog('lyrics rz =>', dz );
        if(dz!=null){  
            cs.value.prompt= dz.data.data.text;
            cs.value.title= dz.data.data.title;
        }
        st.value.isLoading =false;
 
    }).catch(()=>  st.value.isLoading =false );
    if( !cs.value.tags ) cs.value.tags= randStyle()
}
 
// 生成歌曲
const generate= async ()=>{
    st.value.isLoading =false;
    let ids:string[]= ["0d435185-d440-42c8-982a-50205e1cf17d","43e095ba-5f08-4920-bb3d-89dd0defe0b7"];
    ids=["d359a0aa-adf1-4298-9074-005573d7cc84","12e3d62f-8fcc-497b-8365-194657582519"]
 
    if(st.value.type=='custom'){ 
        if(des.value.make_instrumental) cs.value.prompt='';
        if( cs.value.continue_clip_id!='' && exSuno.value?.metadata?.type=='upload' ){
            //chirp-v3-5-upload
            cs.value.mv='chirp-v3-5-upload'
        }
        let r:any= await sunoFetch(  '/generate' ,  cs.value ) 
        st.value.isLoading =false;
 
       ids=r.clips.map((r:any)=>r.id);
       mlog('ids ', ids );
       if( cs.value.mv='chirp-v3-5-upload' ) cs.value.mv='chirp-v3-5'
    }else{
        des.value.prompt=cs.value.title;
        let r:any= await sunoFetch(  '/generate/description-mode' ,  des.value )  
        st.value.isLoading =false; 
        ids=r.clips.map((r:any)=>r.id);
    }
    FeedTask(ids)
}
 
watch(()=>homeStore.myData.act, (n)=>{
    if(n=='suno.extend'){
        mlog("suno.extend", homeStore.myData.actData )
        const s= homeStore.myData.actData as SunoMedia
        exSuno.value= s 
        cs.value.continue_clip_id= s.id
        cs.value.continue_at= Math.ceil(s.metadata.duration/2) 
    }
});  
const appStore = useAppStore()
const isDark = computed(() => {
if (appStore.theme === 'auto')
    return OsTheme.value === 'dark'
else
    return appStore.theme === 'dark'
})
const railStyle = ({
        focused,
        checked
      }: {
        focused: boolean
        checked: boolean
      }) => {
        const style: CSSProperties = {}
        if (checked) {
          style.background = '#0084FF'
          if (focused) {
            // style.boxShadow = '0 0 0 2px #d0305040'
          }
        }
        // else {
        //   style.background = '#2080f0'
        //   if (focused) {
        //     style.boxShadow = '0 0 0 2px #2080f040'
        //   }
        // }
        return style
      }
</script>
<template>
<div class="p-2"> 
    <n-tabs type="line" animated  v-model:value="st.type">
        <!-- <n-tab-pane name="start" tab=""> 
 
        </n-tab-pane> -->
        <!-- <NText depth="3" class="text-center">{{ $t('suno.mic') }}</NText> -->
        <n-tab-pane name="description" :tab="$t('suno.description')">
            <div class="pt-1">
                <n-input :placeholder="$t('suno.titlepls')" v-model:value="cs.title">
                <template #prefix>
                     <span>{{$t('suno.title')}}:</span>
                </template>
                </n-input>
            </div>
            <div  class="pt-4 flex justify-between" style="margin-bottom: 10px">
                <div>{{$t('suno.desc')}}:</div>
                <div> 
                    <n-switch v-model:value="des.make_instrumental" size="small" :rail-style="isDark ? railStyle : ''">
                        <template #checked>
                         {{ $t('suno.noneedly') }}
                        </template>
                        <template #unchecked>
                         {{ $t('suno.noneedly') }}
                        </template>
                    </n-switch>
                </div>
            </div>
            <div  class="pt-1"> 
            <n-input v-model:value="des.gpt_description_prompt" :disabled="des.make_instrumental"
                :placeholder="$t('suno.descpls')"  type="textarea"  size="small"   
                :autosize="{ minRows: 3, maxRows: 12  }"  />
            </div>
            <div  class="pt-1">
                 <n-select v-model:value="des.mv" :options="mvOption" size="small" />
            </div>
        </n-tab-pane>
 
        <n-tab-pane name="custom" :tab="$t('suno.custom')">
            <div class="pt-1">
                <n-input :placeholder="$t('suno.titlepls')" v-model:value="cs.title">
                <template #prefix>
                     <span>{{$t('suno.title')}}:</span>
                </template>
                </n-input>
            </div>
             <div class="pt-4">
                <n-input :placeholder="$t('suno.stylepls')" v-model:value="cs.tags">
                    <template #prefix>
                        <span>{{$t('suno.style')}}:</span>
                    </template>
                    <template #suffix>
                        <n-tooltip placement="right" trigger="hover">
                            <template #trigger>
                                <div class="cursor-pointer" @click="cs.tags= randStyle()"><SvgIcon  icon="fa:random" class="w-4 h-4" /></div>
                            </template>
                            <div>{{$t('suno.rank')}}</div>
                            
                        </n-tooltip>
                    </template>
                </n-input>
            </div>
 
            <div  class="pt-4 flex justify-between" style="margin-bottom: 15px">
                <div>{{$t('suno.ly')}} :</div>
                <div> 
                    <n-switch v-model:value="des.make_instrumental" size="small" :rail-style="isDark ? railStyle : ''">
                        <template #checked>
                        {{ $t('suno.noneedly') }}
                        </template>
                        <template #unchecked>
                         {{ $t('suno.noneedly') }}
                        </template>
                    </n-switch>
                </div>
            </div>
            <div  class="pt-1"> 
                <n-input v-model:value="cs.prompt" :disabled="des.make_instrumental"
                :placeholder="$t('suno.lypls')" type="textarea"  size="small"   
                :autosize="{ minRows: 3, maxRows: 12  }"  />
            </div>
            <div  class="pt-1">
                <n-select v-model:value="cs.mv" :options="mvOption" size="small" />
            </div>
            <template v-if="cs.continue_clip_id && exSuno">
                <div  class="pt-5">
                    <div class="flex justify-between pb-3">
                        <div class="text-[12px]"> {{ $t('suno.extendAt') }} {{ cs.continue_at }}s</div>
                        <NTag  type="success" size="small" round  ><span class="cursor-pointer" @click="cs.continue_clip_id=''" >清除</span></NTag>
 
                    </div>
                    <n-slider v-model:value="cs.continue_at" :step="1" :max="Math.ceil( exSuno.metadata.duration)">
                        <template #thumb>
                            <div class="bg-[--n-fill-color] text-[9px]  border-[0px]  px-1 list-none rounded-md">{{ cs.continue_at }}s</div>
                        </template>
                    </n-slider>
                </div>
                <div  class="pt-1"  >
                    <div class="flex relative  justify-between items-start p-2 hover:dark:bg-black hover:bg-gray-200 border-b-[1px] border-gray-500/10 ">
                        <div class="w-[60px] h-[60px] relative  cursor-pointer" >
                            <n-image  lazy  width="100"  :src="exSuno.image_url" preview-disabled  >
                                <template #placeholder>
                                    <div class="w-full h-full justify-center items-center flex"  >
                                    <SvgIcon icon="line-md:downloading-loop" class="text-[40px] text-green-300"   ></SvgIcon>
                                    </div>
                                </template>
                            </n-image>
                        </div>
                        <div class="flex-1  pl-2"> 
                            <div class="flex justify-between line-clamp-1 w-full cursor-pointer"  >
                                <h3>{{exSuno.title}}</h3>
                                <!-- <div class="opacity-80"  >{{exSuno.metadata.tags}}</div> -->
                            </div>
                            <div class="opacity-60 line-clamp-1 w-full text-[12px] cursor-pointer"   v-if="exSuno.metadata && exSuno.metadata.prompt">
                            {{exSuno.metadata.prompt}}
                            </div>
                            <div class="opacity-60 line-clamp-1 w-full text-[12px] cursor-pointer"  v-else>
                            {{$t('suno.noly')}}
                            </div>
                            <div class="text-right text-[14px] flex justify-end items-center space-x-2  ">
                            
                                <div v-if="exSuno.status=='error'" class="text-[8px] flex items-center border-[1px] border-red-500/80 px-1 list-none rounded-md ">失败</div>
                                <template v-if="exSuno.metadata && exSuno.metadata.duration">
                                    <div class="text-[8px] flex items-center border-[1px] border-gray-500/30 px-1 list-none rounded-md" > {{exSuno.metadata.duration.toFixed(1)}}s</div>
                                </template>
                                <div class="text-[8px] flex items-center border-[1px] border-gray-500/30 px-1 list-none rounded-md" v-if="exSuno.major_model_version"> {{exSuno.major_model_version}}</div>
                            </div>
                        </div>
                    </div>
                </div>
            </template>
        </n-tab-pane>
    </n-tabs>
 
    <div class="pt-4">
        <div class="flex justify-between items-start">
            <NButton type="success" class="genner-button"  :bordered="false" style="border-radius: 8px" :disabled="!canPost" @click="generate()"><SvgIcon icon="ri:music-fill"  /> {{$t('suno.generate')}}</NButton> 
        </div>
        <div class="flex items-start" style="margin-top: 15px">
            <NTag type="info" round :bordered="false" v-if="st.type=='custom'" style="margin-right: 15px"  size="small"><span class="cursor-pointer" @click="generateLyrics()" >{{ $t('suno.generately') }}</span></NTag>
                  <!-- <NTag v-if="st.type=='custom'" type="info" size="small" round  ><span class="cursor-pointer" @click="generateLyrics()" >上传音频</span></NTag> -->
            <mcUploaderMp3 v-if="st.type=='custom'"/>
        </div>
        
       
    </div>
    <div style="color: #d84c10" v-if="st.type=='custom'" class="pt-4 text-[12px]" v-html="t('suno.info')"> </div>
 
</div>
 
</template>