@@ -184,6 +184,7 @@ import "../layout/AdaptationView.css";
184184import { useI18n } from " vue-i18n" ;
185185import showActionSheet from " ../popup/actionSheet.ts" ;
186186import Emitter from " ../services/eventEmitter.ts" ;
187+ import storageManager from " ../services/storage.ts" ;
187188
188189const comment = ref (" " );
189190const isLoading = ref (false );
@@ -193,7 +194,7 @@ const selectedTab = ref("Intro");
193194const route = useRoute ();
194195const { t } = useI18n ();
195196const returnImagePath = ref (
196- window .$getPath (" /@base/assets/library/Navigation-Return.png" ),
197+ window .$getPath (" /@base/assets/library/Navigation-Return.png" )
197198);
198199
199200const data = ref ({
@@ -232,7 +233,7 @@ const data = ref({
232233});
233234
234235let coverUrl = ref (
235- window .$getPath (" /@base/assets/messages/Experiment-Default.png" ),
236+ window .$getPath (" /@base/assets/messages/Experiment-Default.png" )
236237);
237238let avatarUrl = getUserUrl (data .value .User );
238239
@@ -264,7 +265,7 @@ async function handleEnter() {
264265 route .params .category as string ,
265266 route .params .id as string ,
266267 replyID ,
267- upDate ,
268+ upDate
268269 );
269270}
270271
@@ -284,26 +285,92 @@ function copy(text: string) {
284285}
285286
286287function copySubject() {
287- showActionSheet (
288- [
289- { label: t (" expeSummary.copyID" ) },
290- { label: t (" expeSummary.copyInternalLink" ) },
291- { label: t (" expeSummary.copyExternalLink" ) },
292- ],
293- (idx ) => {
294- if (idx === 0 ) {
295- copy (data .value .ID );
296- } else if (idx === 1 ) {
297- copy (
298- ` <${(route .params .category as string ).toLowerCase ()}=${route .params .id }>${data .value .Subject }</${(route .params .category as string ).toLowerCase ()}> ` ,
299- );
300- } else if (idx === 2 ) {
301- copy (
302- ` <external=${window .location .href }>${data .value .Subject }[web]</external> ` ,
303- );
304- }
305- },
306- );
288+ let list = [
289+ { label: t (" expeSummary.copyID" ) },
290+ { label: t (" expeSummary.copyInternalLink" ) },
291+ { label: t (" expeSummary.copyExternalLink" ) },
292+ ];
293+ if (data .value .User .ID === storageManager .getObj (" userInfo" )?.value ?.id ) {
294+ list .push ({ label: t (" expeSummary.changeCover" ) });
295+ }
296+ showActionSheet (list , (idx ) => {
297+ if (idx === 0 ) {
298+ copy (data .value .ID );
299+ } else if (idx === 1 ) {
300+ copy (
301+ ` <${(route .params .category as string ).toLowerCase ()}=${route .params .id }>${data .value .Subject }</${(route .params .category as string ).toLowerCase ()}> `
302+ );
303+ } else if (idx === 2 ) {
304+ copy (
305+ ` <external=${window .location .href }>${data .value .Subject }[web]</external> `
306+ );
307+ } else if (idx === 3 ) {
308+ try {
309+ // ask user to select an image
310+ const input = document .createElement (" input" );
311+ input .type = " file" ;
312+ input .accept = " image/*" ;
313+ input .onchange = async (e : any ) => {
314+ try {
315+ const file = e .target .files && e .target .files [0 ];
316+ if (! file ) return ;
317+ const summaryRes = await getData (` /Contents/GetSummary ` , {
318+ ContentID: route .params .id ,
319+ Category: route .params .category ,
320+ });
321+ const imageIndex = (summaryRes .Data .Image || 0 ) + 1 ;
322+ await getData (` /Contents/ConfirmExperiment ` , {
323+ Category: route .params .category ,
324+ SummaryID: route .params .id ,
325+ Image: imageIndex ,
326+ Extension: " .png" ,
327+ });
328+ const submitRes = await getData (` /Contents/SubmitExperiment ` , {
329+ Request: {
330+ FileSize: 0 - Math .abs (file .size ),
331+ Extension: " .jpg" ,
332+ },
333+ Summary: summaryRes .Data ,
334+ });
335+ try {
336+ const form = new FormData ();
337+ form .append (
338+ " authorization" ,
339+ submitRes .Data ?.Token ?.Authorization || " "
340+ );
341+ form .append (" policy" , submitRes .Data ?.Token ?.Policy || " " );
342+ form .append (" file" , file , " cover.jpg" );
343+ await fetch (" https://v0.api.upyun.com/qphysics" , {
344+ method: " POST" ,
345+ body: form ,
346+ });
347+ await getData (` /Contents/ConfirmExperiment ` , {
348+ Category: route .params .category ,
349+ SummaryID: route .params .id ,
350+ Image: imageIndex ,
351+ Extension: " .png" ,
352+ });
353+ } catch (upErr ) {
354+ Emitter .emit (" error" , " Failed to upload file" , 2 , upErr );
355+ return ;
356+ }
357+ Emitter .emit (" success" , " Cover changed successfully" , 2 );
358+ // refresh current cover (using existing utility function)
359+ setTimeout (async () => {
360+ const refreshed = await getData (` /Contents/GetSummary ` , {
361+ ContentID: route .params .id ,
362+ Category: route .params .category ,
363+ });
364+ coverUrl .value = getCoverUrl (refreshed .Data );
365+ }, 800 );
366+ } catch (err ) {
367+ Emitter .emit (" error" , " Failed to change cover, please try again later" , 2 , err );
368+ }
369+ };
370+ input .click ();
371+ } catch (error ) {}
372+ }
373+ });
307374}
308375
309376onActivated (() => {
0 commit comments