AIWriting.vue 238 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598
  1. <template>
  2. <div class="chat-container">
  3. <!-- 最左侧边栏 -->
  4. <Sidebar />
  5. <!-- 中间历史记录区域 -->
  6. <div class="history-sidebar">
  7. <div class="history-header">
  8. <span class="section-title">历史记录</span>
  9. <img
  10. src="@/assets/Chat/2.png"
  11. alt="新建任务"
  12. class="new-chat-btn"
  13. :class="{ 'disabled': isPolishing }"
  14. @click="createNewChat"
  15. />
  16. </div>
  17. <div class="history-list">
  18. <!-- 历史记录加载状态 -->
  19. <div v-if="isLoadingHistory && historyTotal === 0" class="history-loading">
  20. <div class="loading-spinner"></div>
  21. <div class="loading-text">正在加载历史记录...</div>
  22. </div>
  23. <!-- 有历史记录时显示 -->
  24. <div
  25. v-else-if="historyTotal > 0"
  26. v-for="(item, index) in historyData"
  27. :key="item.id"
  28. :class="['history-item', { active: item.isActive }]"
  29. @click="item.isActive ? null : (isGenerating || isPolishing ? null : handleHistoryItem(item))"
  30. :style="{ cursor: item.isActive || isPolishing ? 'default' : 'pointer' }"
  31. >
  32. <div class="history-content">
  33. <div class="history-title">{{ item.title }}</div>
  34. <div class="history-time">{{ item.time }}</div>
  35. </div>
  36. <div
  37. class="delete-btn"
  38. @click.stop="deleteHistoryItem(item, index)"
  39. :class="{ 'always-visible': item.isActive }"
  40. >
  41. <img src="/src/assets/AIWriting/8.png" alt="删除" class="delete-icon" />
  42. </div>
  43. </div>
  44. <!-- 无历史记录时显示空状态 -->
  45. <div v-else class="empty-history">
  46. <img src="@/assets/Chat/22.png" alt="暂无数据" class="empty-icon">
  47. <div class="empty-text">暂无数据</div>
  48. </div>
  49. </div>
  50. </div>
  51. <!-- 右侧工作区域 -->
  52. <div class="main-work">
  53. <!-- 头部 -->
  54. <div class="work-header">
  55. <h2>AI写作</h2>
  56. </div>
  57. <!-- 工作内容区域 -->
  58. <div class="work-content">
  59. <!-- 主界面:AI写作工作区 -->
  60. <div v-if="currentView === 'main'" class="ai-writing-card">
  61. <!-- 文档生成区域 -->
  62. <div class="document-generation">
  63. <h3>帮我写作</h3>
  64. <p class="subtitle">智能生成办公文档,提升办公效能,高效创作</p>
  65. <div class="input-area">
  66. <div class="template-input-container"
  67. contenteditable="true"
  68. @input="handleTemplateInput"
  69. @copy="handleCopy"
  70. placeholder="请在这里输入您的写作要求..."></div>
  71. <div class="input-actions">
  72. <div class="left-actions">
  73. <button class="attachment-btn" @click="triggerFileUpload" :disabled="isSending">
  74. <img src="@/assets/AIWriting/4.png" alt="附件" class="action-icon" />
  75. </button>
  76. <!-- 文件预览区域 - 显示在输入框右边 -->
  77. <div v-if="selectedFile" class="file-preview-inline">
  78. <div class="file-info-inline">
  79. <img v-if="selectedFile.icon && typeof selectedFile.icon === 'string' && selectedFile.icon.includes('.png')" :src="selectedFile.icon" alt="文档图标" class="file-icon-inline-img">
  80. <span v-else class="file-icon-inline">{{ selectedFile.icon }}</span>
  81. <span class="file-name-inline">{{ selectedFile.name }}</span>
  82. <button class="remove-file-inline" @click="removeSelectedFile">
  83. <span class="remove-icon">×</span>
  84. </button>
  85. </div>
  86. </div>
  87. </div>
  88. <div class="right-actions">
  89. <button class="voice-btn" @click="handleVoiceClick" :disabled="isSending" :class="{ 'recording': isListening }">
  90. <div class="icon-container">
  91. <img src="@/assets/Chat/18.png" alt="语音" class="action-icon" />
  92. <div v-if="isListening" class="recording-indicator"></div>
  93. </div>
  94. </button>
  95. <div class="divider"></div>
  96. <button class="send-btn" @click="sendAIWritingRequest" :disabled="isGenerating || isSending">
  97. <img
  98. :src="hasInputContent ? sendIconFilled : sendIconEmpty"
  99. alt="发送"
  100. class="action-icon"
  101. />
  102. <span v-if="isGenerating" class="generating-text">生成中...</span>
  103. </button>
  104. </div>
  105. </div>
  106. </div>
  107. <p class="hint-text">提示:请输入关键字,AI将根据关键字生成文档</p>
  108. </div>
  109. <!-- 文档模板区域 -->
  110. <div class="document-templates">
  111. <div class="template-tabs">
  112. <div
  113. v-for="tab in tabs"
  114. :key="tab.key"
  115. :class="['tab-item', { active: activeTab === tab.key }]"
  116. @click="switchTab(tab.key)"
  117. >
  118. {{ tab.name }}
  119. </div>
  120. </div>
  121. <div class="template-cards">
  122. <div
  123. v-for="template in filteredTemplates"
  124. :key="template.id"
  125. class="template-card"
  126. >
  127. <img
  128. :src="template.image"
  129. :alt="template.name"
  130. class="template-image"
  131. />
  132. <button
  133. :class="['use-template-btn', template.buttonClass]"
  134. @click="useTemplate(template.name)"
  135. >
  136. 使用此模板
  137. </button>
  138. </div>
  139. </div>
  140. </div>
  141. </div>
  142. <!-- 步骤三:富文本编辑器 -->
  143. <div v-if="currentView === 'editor'" class="editor-view">
  144. <!-- 全屏Loading遮罩 -->
  145. <div v-if="isGenerating" class="editor-full-loading">
  146. <div class="loading-spinner"></div>
  147. <div class="loading-text">正在生成文档,请稍候...</div>
  148. </div>
  149. <!-- 历史记录切换Loading遮罩 -->
  150. <div v-if="isLoadingHistoryItem" class="editor-full-loading">
  151. <div class="loading-spinner"></div>
  152. <div class="loading-text">正在加载历史记录,请稍候...</div>
  153. </div>
  154. <div class="editor-header">
  155. <div class="editor-title">
  156. <h3>文档编辑</h3>
  157. <p class="editor-subtitle" v-if="!isGenerating">AI已为您生成内容,您可以直接编辑和完善</p>
  158. <p class="editor-subtitle" v-else>AI正在生成内容,请稍候...</p>
  159. </div>
  160. <div class="editor-actions">
  161. <!-- <button class="back-btn" @click="backToMain">
  162. <img src="@/assets/Chat/2.png" alt="返回" class="action-icon" />
  163. 返回
  164. </button> -->
  165. <button class="save-btn" @click="saveDocument" :disabled="isPolishing">
  166. <!-- <img src="@/assets/Chat/16.png" alt="保存" class="action-icon" /> -->
  167. 保存文档
  168. </button>
  169. <button class="download-btn" @click="downloadDocument" :disabled="isPolishing">
  170. <img src="@/assets/Exam/13.png" alt="下载Word" class="download-icon" />
  171. </button>
  172. </div>
  173. </div>
  174. <div class="editor-content">
  175. <div class="rich-editor-container" :class="{ 'polishing': isPolishing }">
  176. <!-- 编辑器 -->
  177. <div>
  178. <Toolbar
  179. class="rich-editor-toolbar"
  180. :editor="editorRef"
  181. :defaultConfig="toolbarConfig"
  182. :mode="mode"
  183. />
  184. <Editor
  185. style="height: calc(100vh - 280px); overflow-y: auto;"
  186. v-model="editorContent"
  187. :defaultConfig="editorConfig"
  188. :mode="mode"
  189. @onCreated="handleCreated"
  190. @onChange="handleChange"
  191. />
  192. </div>
  193. </div>
  194. </div>
  195. <!-- AI扩写输入框 -->
  196. <div
  197. v-if="showPolishInput && selectedText.trim()"
  198. class="ai-polish-input"
  199. :style="{
  200. left: polishInputPosition.x + 'px',
  201. top: polishInputPosition.y + 'px'
  202. }"
  203. @click.stop
  204. >
  205. <div class="polish-input-container">
  206. <div class="input-wrapper">
  207. <input
  208. type="text"
  209. v-model="polishCustomPrompt"
  210. placeholder="请输入要求(可选)"
  211. class="polish-input-field"
  212. :disabled="isPolishing"
  213. @keyup.enter="handlePolishText"
  214. @click.stop="handlePolishInputClick"
  215. @focus="handlePolishInputFocus"
  216. @blur="handlePolishInputBlur"
  217. maxlength="200"
  218. />
  219. <div class="char-counter">{{ polishCustomPrompt.length }}/200</div>
  220. </div>
  221. <div class="button-group">
  222. <button
  223. class="polish-send-btn"
  224. @click.stop="handlePolishText"
  225. :disabled="isPolishing"
  226. >
  227. {{ isPolishing && polishingType === 'polish' ? '正在扩写' : 'AI扩写' }}
  228. </button>
  229. <button
  230. class="polish-send-btn continue-btn"
  231. @click.stop="handleContinueText"
  232. :disabled="isPolishing"
  233. >
  234. {{ isPolishing && polishingType === 'continue' ? '正在续写' : 'AI续写' }}
  235. </button>
  236. </div>
  237. </div>
  238. </div>
  239. </div>
  240. <!-- 详情页:聊天对话和文档内容 -->
  241. <div v-if="currentView === 'detail'" class="detail-view">
  242. <!-- 历史记录切换Loading遮罩 -->
  243. <div v-if="isLoadingHistoryItem" class="detail-loading">
  244. <div class="loading-spinner"></div>
  245. <div class="loading-text">正在加载历史记录,请稍候...</div>
  246. </div>
  247. <!-- 主要内容区域:动态布局 -->
  248. <div class="main-content1" :class="{ 'with-document': showDocumentPreview }">
  249. <!-- 左侧:聊天对话区域 -->
  250. <div class="left-column">
  251. <div class="chat-area">
  252. <!-- 显示对话历史 -->
  253. <div
  254. v-for="(message, index) in selectedHistoryItem?.messages"
  255. :key="index"
  256. :class="['message-item', message.type]"
  257. >
  258. <!-- 用户消息 -->
  259. <div v-if="message.type === 'user'" class="user-message">
  260. <div class="message-content">
  261. <!-- 文件显示 -->
  262. <div v-if="message.file" class="message-file">
  263. <div class="file-display">
  264. <div class="file-icon">{{ message.file.icon }}</div>
  265. <div class="file-details">
  266. <div class="file-name">{{ message.file.name }}</div>
  267. <div class="file-size">{{ formatFileSize(message.file.size) }}</div>
  268. </div>
  269. </div>
  270. </div>
  271. <!-- 文本内容 -->
  272. <div v-if="message.content" class="message-text">{{ message.content }}</div>
  273. </div>
  274. <!-- <div class="message-time">{{ message.time }}</div> -->
  275. <!-- 用户消息的操作按钮 -->
  276. <div class="action-buttons">
  277. <button class="action-btn copy-btn" @click="copyUserMessage(message)">
  278. <img
  279. src="@/assets/AIWriting/5.png"
  280. alt="复制"
  281. class="action-icon"
  282. />
  283. 复制
  284. </button>
  285. <button class="action-btn edit-btn" @click="editUserMessage(message)">
  286. <img
  287. src="@/assets/AIWriting/6.png"
  288. alt="编辑"
  289. class="action-icon"
  290. />
  291. 编辑
  292. </button>
  293. </div>
  294. </div>
  295. <!-- AI消息 -->
  296. <div v-else-if="message.type === 'ai'" class="ai-message">
  297. <div class="ai-avatar">
  298. <img
  299. src="@/assets/AIWriting/15.png"
  300. alt="AI头像"
  301. class="avatar-img"
  302. />
  303. </div>
  304. <div class="message-content">
  305. <!-- 开头文字 -->
  306. <div v-if="message.parsedContent?.openingText" class="opening-text" v-html="filterInternalTags(message.parsedContent.openingText)">
  307. </div>
  308. <!-- 文档信息卡片 - 可点击显示预览 -->
  309. <div
  310. v-if="message.parsedContent?.hasDocument"
  311. class="document-info clickable"
  312. @click="toggleDocumentPreview(message.parsedContent)"
  313. >
  314. <div class="doc-icon">
  315. <img
  316. src="@/assets/AIWriting/14.png"
  317. alt="文档图标"
  318. class="info-icon"
  319. />
  320. </div>
  321. <div class="doc-details">
  322. <div class="doc-title">
  323. {{ message.parsedContent?.documentTitle || selectedHistoryItem?.documentContent?.title || "文档标题" }}
  324. </div>
  325. <div class="doc-time">创建时间: {{ getMessageTime(message) }}</div>
  326. </div>
  327. </div>
  328. <!-- 结尾文字 -->
  329. <div v-if="message.parsedContent?.closingText" class="closing-text" v-html="filterInternalTags(message.parsedContent.closingText)">
  330. </div>
  331. <!-- 操作按钮区域 -->
  332. <div class="action-buttons">
  333. <div class="left-actions">
  334. <button class="action-btn copy-btn" @click="copyAIMessage(message)">
  335. <img
  336. src="@/assets/AIWriting/5.png"
  337. alt="复制"
  338. class="action-icon"
  339. />
  340. 复制
  341. </button>
  342. <button class="action-btn regenerate-btn" @click="regenerateResponse(index)" :disabled="isGenerating">
  343. <img
  344. src="@/assets/AIWriting/7.png"
  345. alt="重新生成"
  346. class="action-icon"
  347. />
  348. 重新生成
  349. </button>
  350. <button class="action-btn delete-btn" @click="handleDeleteClick(index)">
  351. <img
  352. src="@/assets/AIWriting/8.png"
  353. alt="删除"
  354. class="action-icon"
  355. />
  356. 删除
  357. </button>
  358. <button class="action-btn voice-btn" @click="handleVoiceRead(message)">
  359. <img
  360. src="@/assets/AIWriting/9.png"
  361. alt="语音朗读"
  362. class="action-icon"
  363. />
  364. {{ isSpeaking(message.id) ? '停止朗读' : '语音朗读' }}
  365. </button>
  366. </div>
  367. <div class="right-actions">
  368. <button
  369. class="action-btn thumbs-up-btn"
  370. :class="{ active: message.userFeedback === 'like' }"
  371. @click="handleThumbsUp(message)"
  372. >
  373. <img src="@/assets/AIWriting/10.png" alt="点赞" class="action-icon">
  374. </button>
  375. <button
  376. class="action-btn thumbs-down-btn"
  377. :class="{ active: message.userFeedback === 'dislike' }"
  378. @click="handleThumbsDown(message)"
  379. >
  380. <img src="@/assets/AIWriting/11.png" alt="踩" class="action-icon">
  381. </button>
  382. </div>
  383. </div>
  384. </div>
  385. </div>
  386. </div>
  387. <!-- 生成中状态 -->
  388. <div v-if="isGenerating" class="message-item generating">
  389. <div class="ai-avatar">
  390. <img
  391. src="@/assets/AIWriting/15.png"
  392. alt="AI头像"
  393. class="avatar-img"
  394. />
  395. </div>
  396. <div class="message-content">
  397. <span class="generating-text">AI正在思考中...</span>
  398. <div class="loading-dots">
  399. <span></span>
  400. <span></span>
  401. <span></span>
  402. </div>
  403. </div>
  404. </div>
  405. </div>
  406. <!-- 输入框区域 - 固定在底部 -->
  407. <div class="input-section">
  408. <!-- 文件预览区域 - 放在输入框上方 -->
  409. <div v-if="selectedFile" class="file-preview-section">
  410. <div class="file-preview">
  411. <div class="file-icon">
  412. <img v-if="selectedFile.icon && typeof selectedFile.icon === 'string' && selectedFile.icon.includes('.png')" :src="selectedFile.icon" alt="文档图标" class="file-icon-img">
  413. <span v-else>{{ selectedFile.icon }}</span>
  414. </div>
  415. <div class="file-info">
  416. <div class="file-name">{{ selectedFile.name }}</div>
  417. <div class="file-size">{{ formatFileSize(selectedFile.size) }}</div>
  418. </div>
  419. <button class="remove-file-btn" @click="removeSelectedFile">
  420. <span class="remove-icon">×</span>
  421. </button>
  422. </div>
  423. </div>
  424. <div class="input-container">
  425. <button class="attachment-btn" @click="triggerFileUpload" :disabled="isGenerating">
  426. <img src="@/assets/Chat/9.png" alt="上传文件" class="action-icon" />
  427. </button>
  428. <input
  429. v-model="detailInputText"
  430. type="text"
  431. placeholder="请在此处发送消息 (Enter键也可发送)"
  432. class="message-input"
  433. @keydown.enter="sendDetailMessage"
  434. @input="handleDetailInput"
  435. maxlength="2000"
  436. :disabled="isGenerating"
  437. />
  438. <button class="voice-btn" @click="handleVoiceClick" :disabled="isGenerating" :class="{ 'recording': isListening }">
  439. <div class="icon-container">
  440. <img src="@/assets/Chat/18.png" alt="语音" class="action-icon" />
  441. <div v-if="isListening" class="recording-indicator"></div>
  442. </div>
  443. </button>
  444. <div class="divider"></div>
  445. <button class="send-btn" @click="sendDetailMessage" :disabled="isGenerating || !detailInputText.trim()">
  446. <img
  447. :src="detailInputText.trim() && !isGenerating ? sendIconFilled : sendIconEmpty"
  448. class="action-icon"
  449. alt="发送"
  450. />
  451. </button>
  452. </div>
  453. </div>
  454. </div>
  455. <!-- 右侧:文档内容区域 - 动态显示 -->
  456. <div v-if="showDocumentPreview" class="right-column">
  457. <div class="document-header">
  458. <h3 class="doc-title">
  459. <!-- {{ selectedDocument?.documentTitle || selectedHistoryItem?.documentContent?.title || "文档标题" }} -->
  460. 文件详情
  461. </h3>
  462. <div class="doc-actions">
  463. <button class="action-btn" @click="copyDocumentContent">
  464. <img src="@/assets/AIWriting/12.png" alt="复制" class="action-icon" />
  465. 复制
  466. </button>
  467. <button class="action-btn" @click="downloadDocumentAsWord">
  468. <img src="@/assets/AIWriting/13.png" alt="下载" class="action-icon" />
  469. 下载
  470. </button>
  471. <button class="action-btn close-btn" @click="closeDocumentPreview">
  472. <img src="@/assets/AIWriting/16.png" alt="关闭" class="action-icon" />
  473. </button>
  474. </div>
  475. </div>
  476. <div class="document-body">
  477. <div
  478. v-if="selectedDocument?.documentContent"
  479. v-for="section in selectedDocument.documentContent.sections"
  480. :key="`selected-${section.title}`"
  481. class="doc-section"
  482. >
  483. <div class="section-content" v-html="formatDocumentContent(section.content)"></div>
  484. </div>
  485. <!-- 如果没有选中文档,显示历史记录中的文档 -->
  486. <div
  487. v-else-if="selectedHistoryItem?.documentContent"
  488. v-for="section in selectedHistoryItem.documentContent.sections"
  489. :key="`history-${section.title}`"
  490. class="doc-section"
  491. >
  492. <div class="section-content" v-html="formatDocumentContent(section.content)"></div>
  493. </div>
  494. <!-- 如果都没有,尝试从AI消息中获取文档内容 -->
  495. <div
  496. v-else-if="getDocumentContentFromMessages()"
  497. v-for="section in getDocumentContentFromMessages().sections"
  498. :key="`message-${section.title}`"
  499. class="doc-section"
  500. >
  501. <div class="section-content" v-html="formatDocumentContent(section.content)"></div>
  502. </div>
  503. </div>
  504. </div>
  505. </div>
  506. </div>
  507. </div>
  508. </div>
  509. <!-- 删除确认弹窗 -->
  510. <DeleteConfirmModal
  511. :visible="showDeleteModal"
  512. :title="deleteConfirmTitle"
  513. :message="deleteConfirmMessage"
  514. @confirm="confirmDelete"
  515. @cancel="cancelDelete"
  516. @close="cancelDelete"
  517. />
  518. <!-- 隐藏的文件输入框 -->
  519. <input
  520. ref="fileInput"
  521. type="file"
  522. accept=".docx"
  523. style="display: none"
  524. @change="handleFileSelect"
  525. />
  526. </div>
  527. </template>
  528. <script setup>
  529. import { ref, computed, nextTick, onMounted, onBeforeUnmount, watch, reactive } from "vue";
  530. import Sidebar from "@/components/Sidebar.vue";
  531. import DeleteConfirmModal from "@/components/DeleteConfirmModal.vue";
  532. import { apis } from "@/request/apis.js";
  533. import { ElMessage } from 'element-plus';
  534. // 导入语音识别组件
  535. import { useSpeechRecognition } from '@/composables/useSpeechRecognition';
  536. // 导入发送按钮图标
  537. import sendIconEmpty from "@/assets/Chat/15.png";
  538. import sendIconFilled from "@/assets/Chat/16.png";
  539. import wordDocIcon from "@/assets/Chat/26.png";
  540. // 导入 wangeditor
  541. import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
  542. import '@wangeditor/editor/dist/css/style.css'
  543. // wangeditor 可以直接处理 HTML,无需 Markdown 转换
  544. // 响应式数据
  545. const messageText = ref("");
  546. const inputText = ref("");
  547. const purposeText = ref("项目进展总结"); // 目的字段的默认值
  548. const contentText = ref("工作内容、成果、风险卡点及解决方案"); // 内容字段的默认值
  549. const templateContent = ref(""); // 整个模板输入框的文本内容
  550. const activeTab = ref("all");
  551. const currentView = ref("main"); // 当前视图:main-主界面,detail-详情页,editor-富文本编辑器
  552. const selectedHistoryItem = ref(null); // 选中的历史记录项
  553. const detailInputText = ref(""); // 详情页输入框文本
  554. const showDocumentPreview = ref(false); // 控制是否显示文档预览
  555. // 富文本编辑器相关状态
  556. const editorContent = ref(""); // 富文本编辑器内容
  557. const isEditorReady = ref(false); // 编辑器是否准备就绪
  558. const richEditor = ref(null); // 富文本编辑器 DOM 引用
  559. // wangeditor 编辑器内置撤销重做功能
  560. // wangeditor 编辑器引用
  561. const editorRef = ref(null);
  562. const mode = 'default'; // 或 'simple'
  563. // 添加文本选择事件监听
  564. onMounted(() => {
  565. // 监听全局文本选择事件
  566. document.addEventListener('selectionchange', handleSelectionChange);
  567. // 监听鼠标移动事件
  568. document.addEventListener('mousemove', handleMouseMove);
  569. // 监听鼠标按下事件
  570. document.addEventListener('mousedown', handleMouseDown);
  571. // 监听鼠标松开事件
  572. document.addEventListener('mouseup', handleMouseUp);
  573. // 监听滚动事件,滚动时隐藏润色输入框和高亮框
  574. document.addEventListener('scroll', handleScroll, true);
  575. // 监听键盘事件,退格键时隐藏润色输入框
  576. document.addEventListener('keydown', handleKeyDown);
  577. // 监听输入法事件,支持中文输入
  578. document.addEventListener('compositionstart', handleCompositionStart);
  579. document.addEventListener('compositionupdate', handleCompositionUpdate);
  580. document.addEventListener('compositionend', handleCompositionEnd);
  581. });
  582. onBeforeUnmount(() => {
  583. // 清理事件监听
  584. document.removeEventListener('selectionchange', handleSelectionChange);
  585. document.removeEventListener('mousemove', handleMouseMove);
  586. document.removeEventListener('mousedown', handleMouseDown);
  587. document.removeEventListener('mouseup', handleMouseUp);
  588. document.removeEventListener('scroll', handleScroll, true);
  589. document.removeEventListener('keydown', handleKeyDown);
  590. document.removeEventListener('compositionstart', handleCompositionStart);
  591. document.removeEventListener('compositionupdate', handleCompositionUpdate);
  592. document.removeEventListener('compositionend', handleCompositionEnd);
  593. });
  594. // wangeditor 工具栏配置
  595. const toolbarConfig = {
  596. excludeKeys: [
  597. 'group-video',
  598. 'group-more-style',
  599. 'fullScreen',
  600. 'emotion', // 表情
  601. 'insertLink', // 插入链接
  602. 'insertImage', // 插入图片
  603. 'uploadImage', // 上传图片
  604. 'insertTable', // 插入表格
  605. 'codeBlock', // 插入代码块
  606. 'divider', // 分割线
  607. 'undo', // 撤销
  608. 'redo' // 重做
  609. ]
  610. };
  611. // wangeditor 编辑器配置
  612. const editorConfig = {
  613. placeholder: '请输入内容...',
  614. readOnly: false,
  615. autoFocus: false,
  616. scroll: true,
  617. // 禁用所有弹出菜单
  618. hoverbarKeys: {
  619. text: {
  620. menuKeys: []
  621. },
  622. link: {
  623. menuKeys: []
  624. },
  625. image: {
  626. menuKeys: []
  627. },
  628. table: {
  629. menuKeys: []
  630. },
  631. video: {
  632. menuKeys: []
  633. }
  634. },
  635. // 禁用右键菜单
  636. MENU_CONF: {
  637. // 配置颜色
  638. color: {
  639. colors: ['#000000', '#333333', '#666666', '#999999', '#cccccc', '#ffffff', '#ff0000', '#00ff00', '#0000ff']
  640. },
  641. // 配置字体
  642. fontFamily: {
  643. fontFamilyList: ['黑体', '楷体', '仿宋', '微软雅黑', 'Arial', 'Tahoma', 'Verdana']
  644. },
  645. // 配置字号
  646. fontSize: {
  647. fontSizeList: ['12px', '13px', '14px', '15px', '16px', '19px', '22px', '24px', '32px', '48px']
  648. },
  649. // 禁用图片上传
  650. uploadImage: {
  651. server: '', // 空字符串禁用上传
  652. allowedFileTypes: [], // 不允许任何文件类型
  653. maxFileSize: 0, // 最大文件大小为0,禁用上传
  654. maxNumberOfFiles: 0, // 最大文件数量为0,禁用上传
  655. fieldName: '', // 空字段名
  656. meta: {},
  657. metaWithUrl: false,
  658. withCredentials: false,
  659. timeout: 0,
  660. headers: {},
  661. customInsert: () => {}, // 空函数,禁用自定义插入
  662. customBrowseAndUpload: () => {}, // 空函数,禁用浏览和上传
  663. customUpload: () => {} // 空函数,禁用自定义上传
  664. }
  665. }
  666. };
  667. // 删除相关状态
  668. const showDeleteModal = ref(false); // 控制是否显示删除确认弹窗
  669. const deleteTargetItem = ref(null); // 要删除的目标项
  670. const deleteType = ref(''); // 删除类型:'history' 或 'message'
  671. // AI写作相关状态
  672. const isGenerating = ref(false); // 是否正在生成
  673. const aiResponse = ref(""); // AI回复内容
  674. const showAIResponse = ref(false); // 是否显示AI回复
  675. const isLoadingHistory = ref(false); // 是否正在加载历史记录
  676. const isLoadingHistoryItem = ref(false); // 是否正在加载历史记录项
  677. // AI扩写相关状态
  678. const showPolishInput = ref(false); // 是否显示AI扩写输入框
  679. const selectedText = ref(""); // 选中的文本
  680. const polishInputPosition = ref({ x: 0, y: 0 }); // 扩写输入框位置
  681. const isPolishing = ref(false); // 是否正在扩写/续写
  682. const polishingType = ref(''); // 当前操作类型:'polish'(扩写)或 'continue'(续写)
  683. const mousePosition = ref({ x: 0, y: 0 }); // 鼠标位置
  684. const isMouseDown = ref(false); // 鼠标是否按下
  685. const savedSelection = ref(null); // 保存的选区信息
  686. const polishCustomPrompt = ref(""); // 用户自定义扩写/续写提示词
  687. const showCustomHighlight = ref(false); // 是否显示自定义高亮
  688. const customHighlightElement = ref(null); // 自定义高亮元素
  689. const isLoadingHistoryContent = ref(false); // 是否正在加载历史记录内容(用于防止弹窗误显示)
  690. // 文件上传相关状态
  691. const fileInput = ref(null);
  692. const selectedFile = ref(null);
  693. const isUploadingFile = ref(false);
  694. const isSending = ref(false); // 控制发送状态
  695. const fileContent = ref('') // 存储文件内容
  696. // ===== 已删除:getUserId - 不再需要,改用token =====
  697. // import { getUserId } from '@/utils/userManager.js'
  698. // 文件处理配置
  699. const fileConfig = reactive({
  700. maxSize: 20 * 1024 * 1024, // 20MB
  701. allowedTypes: ['.docx'] // 只允许.docx格式的Word文档
  702. })
  703. // 语音功能相关状态
  704. const speakingMessageId = ref(null); // 记录正在朗读的消息ID
  705. // 语音功能
  706. const {
  707. isSupported: speechSupported,
  708. isListening,
  709. isSpeaking: speechIsSpeaking,
  710. transcript,
  711. error: speechError,
  712. startListening,
  713. stopListening,
  714. speakText,
  715. stopSpeaking
  716. } = useSpeechRecognition();
  717. ;
  718. // 防抖定时器
  719. let debounceTimer = null;
  720. // 详情页输入防抖定时器
  721. let detailInputDebounceTimer = null;
  722. // 格式检测防抖定时器
  723. let formatDetectionTimer = null;
  724. //对话id
  725. const ai_conversation_id = ref(0)
  726. //业务类型
  727. const business_type = ref(2)
  728. // 计算属性:获取完整的输入文本
  729. const fullInputText = computed(() => {
  730. // 直接返回用户输入的内容,如果没有输入则返回空字符串
  731. return templateContent.value || "";
  732. });
  733. // 计算属性:判断是否有输入内容
  734. const hasInputContent = computed(() => {
  735. // 检查是否有用户输入的内容,包括默认模板文字
  736. const userInput = templateContent.value.trim();
  737. // 只要有内容就认为有输入,包括默认模板文字
  738. return userInput.length > 0;
  739. });
  740. // 历史记录数据
  741. const historyData = ref([])
  742. const historyTotal = ref(0) // 历史记录总数
  743. // 获取历史记录列表
  744. const getHistoryRecordList = async () => {
  745. try {
  746. console.log('📋 开始获取AI写作历史记录列表...')
  747. isLoadingHistory.value = true
  748. const startTime = performance.now()
  749. const response = await apis.getHistoryRecord({
  750. // ===== 已删除:user_id - 后端从token解析 =====
  751. ai_conversation_id: 0, // 0表示获取对话列表
  752. business_type: 2 // AI写作类型
  753. })
  754. const endTime = performance.now()
  755. console.log(`📋 AI写作历史记录API调用耗时: ${(endTime - startTime).toFixed(2)}ms`)
  756. console.log('📋 AI写作历史记录列表响应:', response)
  757. if (response.statusCode === 200) {
  758. // 设置历史记录总数
  759. historyTotal.value = response.total || 0
  760. // 转换后端数据为前端格式
  761. historyData.value = response.data.map(conversation => ({
  762. id: conversation.id,
  763. title: generateConversationTitle(conversation.content),
  764. time: formatTime(conversation.updated_at),
  765. businessType: conversation.business_type,
  766. isActive: false,
  767. // 保存原始数据用于后续查询
  768. rawData: conversation
  769. }))
  770. console.log(`✅ AI写作历史记录列表已设置: ${historyData.value.length}条记录,总数: ${historyTotal.value}`)
  771. } else {
  772. console.error('❌ 获取AI写作历史记录列表失败:', response.statusCode)
  773. }
  774. } catch (error) {
  775. console.error('❌ 获取AI写作历史记录列表失败:', error)
  776. } finally {
  777. isLoadingHistory.value = false
  778. }
  779. }
  780. // 获取指定对话的详细消息
  781. const getConversationMessages = async (conversationId) => {
  782. try {
  783. console.log('开始获取AI写作对话消息,conversationId:', conversationId)
  784. const response = await apis.getHistoryRecord({
  785. // ===== 已删除:user_id - 后端从token解析 =====
  786. ai_conversation_id: conversationId,
  787. business_type: 2 // AI写作类型
  788. })
  789. console.log('AI写作对话消息响应:', response)
  790. console.log('响应数据结构:', {
  791. statusCode: response.statusCode,
  792. data: response.data,
  793. dataType: Array.isArray(response.data) ? 'array' : typeof response.data,
  794. dataLength: Array.isArray(response.data) ? response.data.length : 'N/A'
  795. })
  796. if (response.statusCode === 200) {
  797. // 检查数据是否存在
  798. if (!response.data || !Array.isArray(response.data)) {
  799. console.error('响应数据格式错误:', response.data)
  800. return false
  801. }
  802. // 转换后端消息数据为前端格式
  803. const messages = response.data.map(message => {
  804. const userFeedback = convertUserFeedback(message.user_feedback)
  805. console.log(`消息 ${message.id} 的反馈状态:`, {
  806. raw: message.user_feedback,
  807. converted: userFeedback
  808. })
  809. // 对于AI消息,需要解析文档结构
  810. let parsedContent = null
  811. if (message.type === 'ai') {
  812. try {
  813. parsedContent = parseAIResponse(message.content)
  814. // 如果解析后没有文档结构,确保至少显示AI的回复内容
  815. if (!parsedContent.hasDocument && !parsedContent.openingText && !parsedContent.closingText) {
  816. parsedContent = {
  817. hasDocument: false,
  818. documentContent: null,
  819. openingText: message.content, // 将整个回复作为开头文本显示
  820. documentText: "",
  821. closingText: ""
  822. }
  823. }
  824. } catch (error) {
  825. console.error('解析AI回复失败:', error)
  826. parsedContent = {
  827. hasDocument: false,
  828. documentContent: null,
  829. openingText: message.content, // 将整个回复作为开头文本显示
  830. documentText: "",
  831. closingText: ""
  832. }
  833. }
  834. }
  835. // 如果是用户消息且包含文件标签,提取文件信息
  836. let file = null
  837. let userContent = message.content
  838. if (message.type === 'user' && message.content.includes('</filesize>')) {
  839. // 提取文件信息
  840. const filenameMatch = message.content.match(/<filename>(.*?)<\/filename>/)
  841. const filesizeMatch = message.content.match(/<filesize>(.*?)<\/filesize>/)
  842. const wordMatch = message.content.match(/<word>(.*?)<\/word>/s)
  843. if (filenameMatch && filesizeMatch) {
  844. const filename = filenameMatch[1]
  845. const filesize = parseInt(filesizeMatch[1])
  846. const fileContent = wordMatch ? wordMatch[1].trim() : ''
  847. // 创建文件对象
  848. file = {
  849. name: filename,
  850. size: filesize,
  851. type: filename.endsWith('.docx') ? '.docx' : filename.endsWith('.doc') ? '.doc' : '.docx',
  852. icon: getFileIcon(filename.endsWith('.docx') ? '.docx' : filename.endsWith('.doc') ? '.doc' : '.docx'),
  853. content: fileContent
  854. }
  855. // 提取用户实际说的话(</filesize>标签后的内容)
  856. const userMessageMatch = message.content.split('</filesize>')[1]
  857. userContent = userMessageMatch ? userMessageMatch.trim() : ''
  858. }
  859. }
  860. const messageObj = {
  861. type: message.type, // 'user' 或 'ai'
  862. content: userContent, // 使用提取的用户消息
  863. displayContent: message.type === 'ai' ? message.content : userContent,
  864. file: file, // 添加文件对象
  865. isTyping: false,
  866. id: message.id,
  867. userFeedback: userFeedback,
  868. parsedContent: parsedContent, // 添加解析后的内容
  869. created_at: message.created_at, // 添加创建时间字段
  870. isFromBackend: true, // 标记这是从后端获取的消息
  871. // 保存原始数据
  872. rawData: message
  873. };
  874. return messageObj;
  875. })
  876. // 设置聊天消息
  877. selectedHistoryItem.value.messages = messages
  878. console.log('AI写作对话消息已设置:', selectedHistoryItem.value.messages)
  879. console.log('消息数量:', messages.length)
  880. console.log('currentView状态:', currentView.value)
  881. // 更新对话ID
  882. ai_conversation_id.value = conversationId
  883. // 从AI消息中提取文档内容,设置到历史记录项上
  884. const aiMessage = messages.find(msg => msg.type === 'ai' && msg.parsedContent?.hasDocument);
  885. if (aiMessage && aiMessage.parsedContent) {
  886. selectedHistoryItem.value.documentContent = aiMessage.parsedContent.documentContent;
  887. selectedHistoryItem.value.hasDocument = aiMessage.parsedContent.hasDocument;
  888. }
  889. return true
  890. } else {
  891. console.error('获取AI写作对话消息失败:', response.statusCode)
  892. return false
  893. }
  894. } catch (error) {
  895. console.error('获取AI写作对话消息失败:', error)
  896. return false
  897. }
  898. }
  899. // 生成对话标题(从内容中提取)
  900. const generateConversationTitle = (content) => {
  901. if (!content) return '未知对话'
  902. // 检查是否包含文件标签格式
  903. if (content.includes('</filesize>')) {
  904. // 提取</filesize>标签后面的内容
  905. const userMessage = content.split('</filesize>')[1]
  906. if (userMessage && userMessage.trim()) {
  907. // 清理多余的空格和换行
  908. const cleanMessage = userMessage.replace(/\s+/g, ' ').trim()
  909. // 提取第一句话作为标题
  910. const firstSentence = cleanMessage.split(/[。!?\n]/)[0]
  911. // 限制标题长度
  912. if (firstSentence.length > 30) {
  913. return firstSentence.substring(0, 30) + '...'
  914. }
  915. return firstSentence || '新对话'
  916. }
  917. }
  918. // 如果没有文件标签,使用原来的方法
  919. let cleanContent = content.replace(/<[^>]*>/g, '')
  920. cleanContent = cleanContent.replace(/\s+/g, ' ').trim()
  921. // 提取第一句话作为标题
  922. const firstSentence = cleanContent.split(/[。!?\n]/)[0]
  923. // 限制标题长度
  924. if (firstSentence.length > 30) {
  925. return firstSentence.substring(0, 30) + '...'
  926. }
  927. return firstSentence || '新对话'
  928. }
  929. // 格式化时间
  930. const formatTime = (timestamp) => {
  931. if (!timestamp) return '未知时间'
  932. // 处理时间戳
  933. let date
  934. if (typeof timestamp === 'string') {
  935. // 如果是ISO字符串格式,直接创建Date对象
  936. date = new Date(timestamp)
  937. } else {
  938. // 如果是数字时间戳
  939. let timestampMs = timestamp
  940. if (timestamp.toString().length === 10) {
  941. timestampMs = timestamp * 1000
  942. } else if (timestamp.toString().length === 11) {
  943. timestampMs = timestamp * 1000
  944. } else if (timestamp.toString().length === 13) {
  945. // 13位时间戳,直接使用
  946. } else {
  947. timestampMs = timestamp * 1000
  948. }
  949. date = new Date(timestampMs)
  950. }
  951. const now = new Date()
  952. // 获取今天的开始时间(0点0分0秒)
  953. const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate())
  954. // 获取昨天的开始时间
  955. const yesterdayStart = new Date(todayStart.getTime() - 24 * 60 * 60 * 1000)
  956. // 今天的对话(日期相同)
  957. if (date >= todayStart) {
  958. return date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
  959. }
  960. // 昨天的对话(日期是昨天)
  961. if (date >= yesterdayStart && date < todayStart) {
  962. return '昨天 ' + date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
  963. }
  964. // 更早的对话:显示为 "8月30日 15:30" 格式
  965. const month = date.getMonth() + 1 // getMonth() 返回 0-11
  966. const day = date.getDate()
  967. const time = date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
  968. return `${month}月${day}日 ${time}`
  969. }
  970. // 根据消息来源显示时间
  971. const getMessageTime = (message) => {
  972. // 如果是从后端获取的消息且有created_at字段,使用formatTime格式化
  973. if (message.isFromBackend && message.created_at) {
  974. return formatTime(message.created_at)
  975. }
  976. // 否则使用原来的time字段(新创建的消息)
  977. return message.time || '未知时间'
  978. }
  979. // 转换用户反馈状态
  980. const convertUserFeedback = (feedback) => {
  981. console.log('转换用户反馈状态:', feedback, '类型:', typeof feedback)
  982. switch (parseInt(feedback)) {
  983. case 2: return 'like' // 满意(赞)
  984. case 3: return 'dislike' // 不满意(踩)
  985. case 0:
  986. default: return null // 无反馈
  987. }
  988. }
  989. // 转换前端反馈状态为后端格式
  990. const convertFeedbackToBackend = (feedback) => {
  991. switch (feedback) {
  992. case 'like': return 2 // 满意(赞)
  993. case 'dislike': return 3 // 不满意(踩)
  994. default: return 0 // 无反馈
  995. }
  996. }
  997. // 删除确认消息
  998. const deleteConfirmMessage = computed(() => {
  999. if (deleteType.value === 'history') {
  1000. const title = deleteTargetItem.value?.item?.title || ''
  1001. return `确定要删除历史记录"${title}"吗?删除后将无法恢复。`
  1002. } else if (deleteType.value === 'message') {
  1003. return '确定要删除这条消息吗?删除后将无法恢复。'
  1004. }
  1005. return '确定要删除吗?删除后将无法恢复。'
  1006. })
  1007. // 删除确认标题
  1008. const deleteConfirmTitle = computed(() => {
  1009. if (deleteType.value === 'history') {
  1010. return '删除历史记录'
  1011. } else if (deleteType.value === 'message') {
  1012. return '删除消息'
  1013. }
  1014. return '删除确认'
  1015. })
  1016. // 删除历史记录
  1017. const deleteHistoryItem = (historyItem, index) => {
  1018. console.log('准备删除历史记录:', historyItem)
  1019. // 设置要删除的项目并显示确认弹窗
  1020. deleteTargetItem.value = { item: historyItem, index: index }
  1021. deleteType.value = 'history'
  1022. showDeleteModal.value = true
  1023. }
  1024. // 删除相关方法
  1025. const handleDeleteClick = (messageIndex) => {
  1026. console.log('点击删除按钮,消息索引:', messageIndex)
  1027. // 检查是否只剩一句AI回复和一句用户发言
  1028. if (selectedHistoryItem.value?.messages?.length === 2) {
  1029. ElMessage.warning('第一句话无法删除')
  1030. return
  1031. }
  1032. // 设置删除类型和要删除的消息索引
  1033. deleteType.value = 'message'
  1034. deleteTargetItem.value = { messageIndex: messageIndex }
  1035. showDeleteModal.value = true
  1036. }
  1037. // 统一的确认删除函数
  1038. const confirmDelete = async () => {
  1039. if (!deleteTargetItem.value) return
  1040. if (deleteType.value === 'history') {
  1041. await confirmDeleteHistory()
  1042. } else if (deleteType.value === 'message') {
  1043. await confirmDeleteMessage()
  1044. }
  1045. }
  1046. // 确认删除历史记录
  1047. const confirmDeleteHistory = async () => {
  1048. const { item: historyItem, index } = deleteTargetItem.value
  1049. try {
  1050. // 调用删除接口
  1051. const response = await apis.deleteHistoryRecord({
  1052. ai_conversation_id: historyItem.id
  1053. })
  1054. if (response.statusCode === 200) {
  1055. // 删除成功,从列表中移除
  1056. historyData.value.splice(index, 1)
  1057. // 如果删除的是当前激活的历史记录,需要清空聊天界面并调用新建任务
  1058. if (historyItem.isActive) {
  1059. await createNewChat()
  1060. }
  1061. console.log('历史记录删除成功')
  1062. ElMessage.success('删除成功')
  1063. } else {
  1064. console.error('删除历史记录失败:', response.msg)
  1065. ElMessage.error(response.msg || '删除失败')
  1066. }
  1067. } catch (error) {
  1068. console.error('删除历史记录失败:', error)
  1069. ElMessage.error('删除失败,请稍后重试')
  1070. } finally {
  1071. // 关闭弹窗并清除目标项
  1072. showDeleteModal.value = false
  1073. deleteTargetItem.value = null
  1074. deleteType.value = ''
  1075. }
  1076. }
  1077. // 确认删除消息
  1078. const confirmDeleteMessage = async () => {
  1079. const { messageIndex } = deleteTargetItem.value
  1080. try {
  1081. const aiMessage = selectedHistoryItem.value?.messages?.[messageIndex]
  1082. console.log('aiMessage:', aiMessage)
  1083. // 检查是否有id(统一使用id字段)
  1084. if (aiMessage && aiMessage.id) {
  1085. console.log('准备调用后端删除接口,id:', aiMessage.id)
  1086. try {
  1087. // 调用后端删除接口
  1088. const response = await apis.deleteConversation({
  1089. ai_message_id: aiMessage.id
  1090. })
  1091. console.log('后端删除接口响应:', response)
  1092. if (response.statusCode === 200) {
  1093. // 后端删除成功,从前端数组中删除AI消息和对应的用户消息
  1094. // 删除AI消息
  1095. selectedHistoryItem.value.messages.splice(messageIndex, 1)
  1096. // 删除对应的用户消息(前一条)
  1097. if (messageIndex > 0) {
  1098. selectedHistoryItem.value.messages.splice(messageIndex - 1, 1)
  1099. }
  1100. // 如果正在预览文档,关闭预览
  1101. if (showDocumentPreview.value) {
  1102. showDocumentPreview.value = false
  1103. selectedDocument.value = null
  1104. console.log('删除对话时关闭文档预览')
  1105. }
  1106. console.log('删除成功')
  1107. ElMessage.success('删除成功')
  1108. } else {
  1109. console.error('删除失败:', response.msg)
  1110. ElMessage.error('删除失败,请稍后重试')
  1111. }
  1112. } catch (error) {
  1113. console.error('删除接口调用失败:', error)
  1114. ElMessage.error('删除失败,请稍后重试')
  1115. }
  1116. } else {
  1117. console.log('没有id,仅从前端删除')
  1118. // 没有id的情况,仅从前端删除
  1119. selectedHistoryItem.value.messages.splice(messageIndex, 1)
  1120. // 如果正在预览文档,关闭预览
  1121. if (showDocumentPreview.value) {
  1122. showDocumentPreview.value = false
  1123. selectedDocument.value = null
  1124. console.log('删除对话时关闭文档预览')
  1125. }
  1126. ElMessage.success('删除成功')
  1127. }
  1128. } catch (error) {
  1129. console.error('删除消息失败:', error)
  1130. ElMessage.error('删除失败,请稍后重试')
  1131. } finally {
  1132. // 关闭弹窗并清除目标项
  1133. showDeleteModal.value = false
  1134. deleteTargetItem.value = null
  1135. deleteType.value = ''
  1136. }
  1137. }
  1138. // 取消删除
  1139. const cancelDelete = () => {
  1140. showDeleteModal.value = false
  1141. deleteTargetItem.value = null
  1142. deleteType.value = ''
  1143. }
  1144. // 从用户输入内容生成标题
  1145. const generateTitleFromContent = (content) => {
  1146. if (!content || !content.trim()) return 'AI写作任务'
  1147. // 清理HTML标签
  1148. const cleanContent = content.replace(/<[^>]*>/g, '')
  1149. // 提取第一句话作为标题
  1150. const firstSentence = cleanContent.split(/[。!?\n]/)[0]
  1151. // 限制标题长度
  1152. if (firstSentence.length > 30) {
  1153. return firstSentence.substring(0, 30) + '...'
  1154. }
  1155. return firstSentence || 'AI写作任务'
  1156. }
  1157. // 后端返回的是HTML格式,无需Markdown转换
  1158. // 模板标签配置
  1159. const tabs = [
  1160. { key: "all", name: "全部" },
  1161. { key: "announcement", name: "公告" },
  1162. { key: "notification", name: "通知" },
  1163. { key: "summary", name: "总结报告" },
  1164. { key: "meeting", name: "会议纪要" },
  1165. { key: "speech", name: "决定" },
  1166. ];
  1167. import announcementIcon from '@/assets/AIWriting/3.png'
  1168. import notificationIcon from '@/assets/AIWriting/2.png'
  1169. import summaryIcon from '@/assets/AIWriting/1.png'
  1170. import meetingIcon from '@/assets/AIWriting/18.png'
  1171. import speechIcon from '@/assets/AIWriting/19.png'
  1172. // 模板数据配置
  1173. const templates = [
  1174. {
  1175. id: 1,
  1176. name: "公告模板",
  1177. image: announcementIcon,
  1178. category: "announcement",
  1179. buttonClass: "announcement-btn"
  1180. },
  1181. {
  1182. id: 2,
  1183. name: "通知模板",
  1184. image: notificationIcon,
  1185. category: "notification",
  1186. buttonClass: "notification-btn"
  1187. },
  1188. {
  1189. id: 3,
  1190. name: "工作汇报模板",
  1191. image: summaryIcon,
  1192. category: "summary",
  1193. buttonClass: "report-btn"
  1194. },
  1195. {
  1196. id: 4,
  1197. name: "会议纪要模版",
  1198. image: meetingIcon,
  1199. category: "meeting",
  1200. buttonClass: "announcement-btn"
  1201. },
  1202. {
  1203. id: 5,
  1204. name: "决定模版",
  1205. image: speechIcon,
  1206. category: "speech",
  1207. buttonClass: "notification-btn"
  1208. }
  1209. ];
  1210. // 根据当前选中的标签筛选模板
  1211. const filteredTemplates = computed(() => {
  1212. if (activeTab.value === "all") {
  1213. return templates;
  1214. }
  1215. return templates.filter(template => template.category === activeTab.value);
  1216. });
  1217. // 方法
  1218. const createNewChat = async () => {
  1219. console.log("创建新AI写作任务");
  1220. // 如果正在生成或扩写/续写,不允许新建
  1221. if (isGenerating.value || isPolishing.value) {
  1222. return
  1223. }
  1224. // 隐藏AI扩写输入框
  1225. hidePolishInput();
  1226. // 停止当前朗读
  1227. if (speakingMessageId.value) {
  1228. try { window.speechSynthesis && window.speechSynthesis.cancel(); } catch (e) {}
  1229. speakingMessageId.value = null;
  1230. }
  1231. // 重置所有状态
  1232. ai_conversation_id.value = 0
  1233. selectedHistoryItem.value = null;
  1234. currentView.value = "main";
  1235. showDocumentPreview.value = false;
  1236. selectedDocument.value = null;
  1237. detailInputText.value = "";
  1238. // 重置输入框内容为默认模板
  1239. const inputElement = document.querySelector('.template-input-container');
  1240. if (inputElement) {
  1241. const defaultTemplate = "<span class=\"editable-highlight\" contenteditable=\"true\">总结主题:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">总结时间:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">主要内容:</span>\n\n请帮我生成一份正式的总结报告,要求格式规范、语言严谨,具体参考以上内容,按照标准工作总结格式生成全文,包含\"工作总结、问题不足、未来计划\"三部分的完整报告。";
  1242. inputElement.innerHTML = defaultTemplate;
  1243. templateContent.value = defaultTemplate.replace(/<[^>]*>/g, '');
  1244. // 为高亮元素添加样式
  1245. nextTick(() => {
  1246. const highlights = inputElement.querySelectorAll('.editable-highlight');
  1247. highlights.forEach(highlight => {
  1248. highlight.style.backgroundColor = '#3E7BFA10';
  1249. highlight.style.color = '#3E7BFA';
  1250. highlight.style.padding = '4px 8px';
  1251. highlight.style.borderRadius = '6px';
  1252. highlight.style.fontWeight = '500';
  1253. highlight.style.cursor = 'text';
  1254. highlight.style.border = '1px solid transparent';
  1255. highlight.style.display = 'inline-block';
  1256. highlight.style.minWidth = '20px';
  1257. });
  1258. });
  1259. }
  1260. // 清除所有历史记录的选中状态
  1261. historyData.value.forEach((item) => {
  1262. item.isActive = false;
  1263. });
  1264. // 刷新历史记录列表
  1265. await getHistoryRecordList();
  1266. };
  1267. // 点击历史记录
  1268. const handleHistoryItem = async (historyItem) => {
  1269. console.log("点击历史记录:", historyItem);
  1270. // 如果正在生成,不允许切换
  1271. if (isGenerating.value) {
  1272. return
  1273. }
  1274. // 隐藏AI扩写输入框
  1275. hidePolishInput();
  1276. // 设置加载标志,防止选择事件触发弹窗
  1277. isLoadingHistoryContent.value = true;
  1278. // 显示loading
  1279. isLoadingHistoryItem.value = true;
  1280. try {
  1281. // 停止当前朗读
  1282. if (speakingMessageId.value) {
  1283. try { window.speechSynthesis && window.speechSynthesis.cancel(); } catch (e) {}
  1284. speakingMessageId.value = null;
  1285. }
  1286. selectedHistoryItem.value = historyItem;
  1287. // 重置文档预览状态,确保界面恢复全屏
  1288. showDocumentPreview.value = false;
  1289. selectedDocument.value = null;
  1290. // 更新数据层的active状态
  1291. historyData.value.forEach((item) => {
  1292. item.isActive = item.id === historyItem.id;
  1293. });
  1294. // 获取该对话的详细消息
  1295. const success = await getConversationMessages(historyItem.id)
  1296. if (success) {
  1297. console.log('AI写作历史对话加载成功,直接进入富文本编辑器')
  1298. // 获取AI回复内容
  1299. const aiMessage = selectedHistoryItem.value.messages.find(msg => msg.type === 'ai');
  1300. if (aiMessage) {
  1301. // 直接使用AI消息内容,无需解析
  1302. // 直接使用AI消息的content,无需解析
  1303. console.log('AI消息内容长度:', aiMessage.content.length);
  1304. console.log('AI消息内容预览:', aiMessage.content.substring(0, 200) + '...');
  1305. // 格式化内容并进入富文本编辑器
  1306. const formattedContent = formatContentForEditor(aiMessage.content);
  1307. enterEditor(formattedContent);
  1308. } else {
  1309. // 如果没有AI消息,显示用户消息
  1310. const userMessage = selectedHistoryItem.value.messages.find(msg => msg.type === 'user');
  1311. if (userMessage) {
  1312. const formattedContent = formatContentForEditor(userMessage.content);
  1313. enterEditor(formattedContent);
  1314. } else {
  1315. // 如果都没有,显示默认内容
  1316. enterEditor("<p>暂无内容</p>");
  1317. }
  1318. }
  1319. } else {
  1320. console.error('加载历史对话失败')
  1321. ElMessage.error('加载历史对话失败,请稍后重试');
  1322. }
  1323. } catch (error) {
  1324. console.error('加载AI写作历史对话失败:', error)
  1325. ElMessage.error('加载历史对话时发生错误,请稍后重试');
  1326. } finally {
  1327. // 隐藏loading
  1328. isLoadingHistoryItem.value = false;
  1329. // 延迟重置加载标志,确保编辑器内容已完全加载并且选择事件已处理
  1330. setTimeout(() => {
  1331. isLoadingHistoryContent.value = false;
  1332. console.log("历史记录内容加载完成,允许显示扩写弹窗");
  1333. }, 500); // 延迟500ms,确保所有选择事件已处理完毕
  1334. }
  1335. };
  1336. // 返回主界面
  1337. const backToMain = () => {
  1338. currentView.value = "main";
  1339. ai_conversation_id.value = 0
  1340. selectedHistoryItem.value = null;
  1341. showDocumentPreview.value = false; // 关闭文档预览
  1342. selectedDocument.value = null; // 重置选中文档
  1343. // 重置所有历史记录的active状态
  1344. historyData.value.forEach((item) => {
  1345. item.isActive = false;
  1346. });
  1347. // 隐藏AI扩写输入框
  1348. hidePolishInput();
  1349. // 重置加载标志
  1350. isLoadingHistoryContent.value = false;
  1351. // 移除选择变化监听
  1352. removeSelectionListener();
  1353. };
  1354. // wangeditor 编辑器内置格式检测功能
  1355. // wangeditor 编辑器事件处理
  1356. const handleCreated = (editor) => {
  1357. editorRef.value = editor;
  1358. console.log('wangeditor 编辑器创建完成');
  1359. };
  1360. const handleChange = (editor) => {
  1361. // 获取编辑器内容但不立即更新 editorContent.value
  1362. const currentEditorContent = editor.getHtml();
  1363. // 调试日志:检查内容变化
  1364. console.log("wangeditor内容变化 - 新内容长度:", currentEditorContent.length);
  1365. console.log("wangeditor内容变化 - 新内容预览:", currentEditorContent.substring(0, 200) + '...');
  1366. // 只有在用户主动编辑时才更新 editorContent.value
  1367. // 避免在程序设置内容时被覆盖
  1368. if (isEditorReady.value) {
  1369. editorContent.value = currentEditorContent;
  1370. }
  1371. };
  1372. // 不再需要自定义粘贴处理,wangeditor 会自动处理
  1373. const handleEditorKeydown = (event) => {
  1374. // 处理快捷键
  1375. if (event.ctrlKey || event.metaKey) {
  1376. switch (event.key) {
  1377. case 'z':
  1378. event.preventDefault();
  1379. if (event.shiftKey) {
  1380. redoEditor(); // Ctrl+Shift+Z 重做
  1381. } else {
  1382. undoEditor(); // Ctrl+Z 撤销
  1383. }
  1384. break;
  1385. case 'y':
  1386. event.preventDefault();
  1387. redoEditor(); // Ctrl+Y 重做
  1388. break;
  1389. case 'b':
  1390. event.preventDefault();
  1391. execCommand('bold');
  1392. break;
  1393. case 'i':
  1394. event.preventDefault();
  1395. execCommand('italic');
  1396. break;
  1397. case 'u':
  1398. event.preventDefault();
  1399. execCommand('underline');
  1400. break;
  1401. case 's':
  1402. event.preventDefault();
  1403. saveDocument();
  1404. break;
  1405. }
  1406. }
  1407. // 检测当前格式
  1408. setTimeout(() => {
  1409. detectCurrentFormat();
  1410. }, 0);
  1411. };
  1412. // 处理编辑器点击事件
  1413. const handleEditorClick = () => {
  1414. // 立即检测格式(点击时不需要防抖)
  1415. detectCurrentFormat();
  1416. };
  1417. // 处理编辑器选择变化
  1418. const handleEditorSelectionChange = () => {
  1419. // 使用防抖来减少格式检测的频率
  1420. if (formatDetectionTimer) {
  1421. clearTimeout(formatDetectionTimer);
  1422. }
  1423. formatDetectionTimer = setTimeout(() => {
  1424. detectCurrentFormat();
  1425. }, 100); // 100ms 防抖延迟,比输入事件更快响应
  1426. };
  1427. // 添加全局选择变化监听
  1428. const addSelectionListener = () => {
  1429. document.addEventListener('selectionchange', handleEditorSelectionChange);
  1430. };
  1431. // 移除全局选择变化监听
  1432. const removeSelectionListener = () => {
  1433. document.removeEventListener('selectionchange', handleEditorSelectionChange);
  1434. };
  1435. // wangeditor 编辑器内置撤销重做功能
  1436. // 保存光标位置
  1437. const saveCursorPosition = () => {
  1438. const selection = window.getSelection();
  1439. if (selection.rangeCount > 0) {
  1440. const range = selection.getRangeAt(0);
  1441. return {
  1442. startContainer: range.startContainer,
  1443. startOffset: range.startOffset,
  1444. endContainer: range.endContainer,
  1445. endOffset: range.endOffset
  1446. };
  1447. }
  1448. return null;
  1449. };
  1450. // 恢复光标位置
  1451. const restoreCursorPosition = (savedPosition) => {
  1452. if (!savedPosition) return;
  1453. try {
  1454. const selection = window.getSelection();
  1455. const range = document.createRange();
  1456. range.setStart(savedPosition.startContainer, savedPosition.startOffset);
  1457. range.setEnd(savedPosition.endContainer, savedPosition.endOffset);
  1458. selection.removeAllRanges();
  1459. selection.addRange(range);
  1460. } catch (error) {
  1461. console.log('恢复光标位置失败:', error);
  1462. }
  1463. };
  1464. // wangeditor 编辑器内置所有格式化功能
  1465. // wangeditor 编辑器内置链接和图片功能
  1466. // wangeditor 编辑器内置字体和字号功能
  1467. const saveDocument = async (options = {}) => {
  1468. const { silent = false } = options
  1469. // 如果正在扩写/续写,不允许保存
  1470. if (isPolishing.value) {
  1471. return;
  1472. }
  1473. try {
  1474. // 获取当前编辑器内容
  1475. let content = '';
  1476. if (editorRef.value) {
  1477. try {
  1478. // 强制刷新编辑器内容,确保获取最新内容
  1479. content = editorRef.value.getHtml();
  1480. console.log("保存文档 - 从wangeditor获取内容,长度:", content.length);
  1481. console.log("保存文档 - 内容预览:", content.substring(0, 200) + '...');
  1482. } catch (error) {
  1483. console.log("从wangeditor获取内容失败,使用editorContent:", error);
  1484. content = editorContent.value || '';
  1485. }
  1486. } else {
  1487. content = editorContent.value || '';
  1488. console.log("保存文档 - 从editorContent获取内容,长度:", content.length);
  1489. }
  1490. if (!content || content.trim() === '') {
  1491. ElMessage.warning("没有内容可保存");
  1492. return;
  1493. }
  1494. console.log("保存文档内容长度:", content.length);
  1495. // 获取当前对话ID
  1496. const currentConversationId = selectedHistoryItem.value?.id;
  1497. if (!currentConversationId) {
  1498. ElMessage.error("无法获取对话ID,请重新选择历史记录");
  1499. return;
  1500. }
  1501. // 调用保存接口
  1502. const response = await apis.saveEditDocument({
  1503. ai_conversation_id: currentConversationId,
  1504. content: content
  1505. });
  1506. if (response && response.data && response.statusCode === 200) {
  1507. if (!silent) {
  1508. ElMessage.success("文档保存成功");
  1509. }
  1510. console.log("文档保存成功,返回内容:", response.data.data);
  1511. } else {
  1512. ElMessage.error("文档保存失败,请重试");
  1513. console.error("保存失败:", response);
  1514. }
  1515. } catch (error) {
  1516. console.error("保存文档失败:", error);
  1517. ElMessage.error("保存文档失败,请检查网络连接");
  1518. }
  1519. };
  1520. // 下载文档功能
  1521. const downloadDocument = async () => {
  1522. // 如果正在扩写/续写,不允许下载
  1523. if (isPolishing.value) {
  1524. return;
  1525. }
  1526. try {
  1527. console.log("开始下载文档...");
  1528. // 先保存文档到数据库(静默,不提示成功)
  1529. await saveDocument({ silent: true });
  1530. // 尝试多种方式获取编辑器内容
  1531. let content = '';
  1532. // 方式1: 从DOM获取
  1533. const editorTextContainer = document.querySelector('.w-e-text');
  1534. if (editorTextContainer) {
  1535. content = editorTextContainer.innerHTML;
  1536. console.log("从DOM获取内容长度:", content.length);
  1537. }
  1538. // 方式2: 从editorContent获取
  1539. if (!content && editorContent.value) {
  1540. content = editorContent.value;
  1541. console.log("从editorContent获取内容长度:", content.length);
  1542. }
  1543. // 方式3: 从wangeditor实例获取
  1544. if (!content && editorRef.value) {
  1545. try {
  1546. content = editorRef.value.getHtml();
  1547. console.log("从wangeditor实例获取内容长度:", content.length);
  1548. } catch (error) {
  1549. console.log("从wangeditor实例获取失败:", error);
  1550. }
  1551. }
  1552. console.log("最终下载内容长度:", content.length);
  1553. console.log("最终下载内容预览:", content.substring(0, 200));
  1554. if (!content || content.trim() === '') {
  1555. ElMessage.warning("没有可下载的内容");
  1556. return;
  1557. }
  1558. // 获取当前文档标题
  1559. const documentTitle = getCurrentDocumentTitle();
  1560. // 生成文件名(优先使用文档标题)
  1561. let filename;
  1562. if (documentTitle && documentTitle !== 'AI生成文档') {
  1563. // 清理标题中的特殊字符,确保文件名合法
  1564. const cleanTitle = documentTitle.replace(/[<>:"/\\|?*]/g, '').trim();
  1565. filename = `${cleanTitle}.docx`;
  1566. } else {
  1567. // 如果没有有效标题,使用时间戳
  1568. const now = new Date();
  1569. const timestamp = now.toISOString().slice(0, 19).replace(/[-:]/g, '').replace('T', '_');
  1570. filename = `AI生成文档_${timestamp}.docx`;
  1571. }
  1572. // 生成无水印的Word文档(HTML方式)
  1573. await generateWordWithoutWatermark(content, documentTitle, filename);
  1574. } catch (error) {
  1575. console.error("下载Word文档失败:", error);
  1576. ElMessage.error("下载Word文档失败,请重试");
  1577. }
  1578. };
  1579. // 进入富文本编辑器
  1580. const enterEditor = (content) => {
  1581. currentView.value = "editor";
  1582. console.log("进入富文本编辑器,内容长度:", content.length);
  1583. console.log("进入富文本编辑器,内容预览:", content.substring(0, 200) + '...');
  1584. // 使用 nextTick 确保 DOM 更新后再设置内容
  1585. nextTick(() => {
  1586. // 先设置内容
  1587. editorContent.value = content;
  1588. // 延迟设置编辑器内容,确保编辑器已初始化
  1589. setTimeout(() => {
  1590. if (editorRef.value) {
  1591. try {
  1592. // 直接设置 HTML 内容到 wangeditor
  1593. editorRef.value.setHtml(content);
  1594. console.log("wangeditor 内容设置完成");
  1595. // 设置完成后才标记编辑器为就绪
  1596. isEditorReady.value = true;
  1597. // 重置生成状态
  1598. isGenerating.value = false;
  1599. } catch (error) {
  1600. console.error("设置 wangeditor 内容失败:", error);
  1601. // 如果setHtml失败,尝试重新初始化编辑器
  1602. try {
  1603. console.log("尝试重新初始化编辑器...");
  1604. // 清空编辑器内容
  1605. editorRef.value.clear();
  1606. // 重新设置内容
  1607. editorRef.value.setHtml(content);
  1608. console.log("重新初始化编辑器成功");
  1609. isEditorReady.value = true;
  1610. isGenerating.value = false;
  1611. } catch (retryError) {
  1612. console.error("重新初始化编辑器也失败:", retryError);
  1613. // 最后的降级方案:直接设置editorContent
  1614. editorContent.value = content;
  1615. isEditorReady.value = true;
  1616. isGenerating.value = false;
  1617. }
  1618. }
  1619. } else {
  1620. console.log("editorRef.value 不存在,等待编辑器初始化");
  1621. // 如果编辑器还没初始化,再等一会
  1622. setTimeout(() => {
  1623. if (editorRef.value) {
  1624. try {
  1625. editorRef.value.setHtml(content);
  1626. console.log("延迟设置 wangeditor 内容完成");
  1627. // 设置完成后才标记编辑器为就绪
  1628. isEditorReady.value = true;
  1629. // 重置生成状态
  1630. isGenerating.value = false;
  1631. } catch (error) {
  1632. console.error("延迟设置 wangeditor 内容失败:", error);
  1633. // 如果延迟设置也失败,尝试重新初始化编辑器
  1634. try {
  1635. console.log("延迟设置失败,尝试重新初始化编辑器...");
  1636. editorRef.value.clear();
  1637. editorRef.value.setHtml(content);
  1638. console.log("延迟重新初始化编辑器成功");
  1639. isEditorReady.value = true;
  1640. isGenerating.value = false;
  1641. } catch (retryError) {
  1642. console.error("延迟重新初始化编辑器也失败:", retryError);
  1643. // 最后的降级方案:直接设置editorContent
  1644. editorContent.value = content;
  1645. isEditorReady.value = true;
  1646. isGenerating.value = false;
  1647. }
  1648. }
  1649. }
  1650. }, 500);
  1651. }
  1652. }, 100);
  1653. });
  1654. };
  1655. // 处理鼠标移动
  1656. const handleMouseMove = (event) => {
  1657. // 检查是否在AI扩写输入框上移动
  1658. if (event.target.closest('.ai-polish-input')) {
  1659. return; // 如果在扩写输入框上移动,不处理
  1660. }
  1661. // 只有在鼠标按下时才更新位置,避免按钮位置一直变化
  1662. if (isMouseDown.value) {
  1663. mousePosition.value = {
  1664. x: event.clientX,
  1665. y: event.clientY
  1666. };
  1667. }
  1668. };
  1669. // 处理鼠标按下
  1670. const handleMouseDown = (event) => {
  1671. // 如果正在扩写/续写,禁用文本选择
  1672. if (isPolishing.value) {
  1673. event.preventDefault();
  1674. return;
  1675. }
  1676. // 检查是否点击的是AI扩写输入框
  1677. if (event.target.closest('.ai-polish-input')) {
  1678. return; // 如果点击的是扩写输入框,不处理,保持显示
  1679. }
  1680. // 如果点击的是工具栏,隐藏AI扩写输入框
  1681. if (event.target.closest('.w-e-toolbar') || event.target.closest('.w-e-bar')) {
  1682. hidePolishInput();
  1683. return;
  1684. }
  1685. isMouseDown.value = true;
  1686. // 记录鼠标按下时的位置
  1687. mousePosition.value = {
  1688. x: event.clientX,
  1689. y: event.clientY
  1690. };
  1691. // 只有在点击编辑器内容区域且不在扩写输入框内时才隐藏输入框
  1692. if ((event.target.closest('.w-e-text-container') || event.target.closest('.rich-editor-container'))
  1693. && !event.target.closest('.ai-polish-input')) {
  1694. hidePolishInput();
  1695. }
  1696. };
  1697. // 处理鼠标松开
  1698. const handleMouseUp = () => {
  1699. // 如果正在扩写/续写,不处理鼠标松开事件
  1700. if (isPolishing.value) {
  1701. return;
  1702. }
  1703. isMouseDown.value = false;
  1704. // 鼠标松开后检查是否有选中文本
  1705. setTimeout(() => {
  1706. checkSelectionAndShowButton();
  1707. }, 50); // 延迟50ms确保选择完成
  1708. };
  1709. // 检查选择并显示按钮
  1710. const checkSelectionAndShowButton = () => {
  1711. console.log("=== checkSelectionAndShowButton 被调用 ===");
  1712. // 如果正在加载历史记录内容,不处理选择
  1713. if (isLoadingHistoryContent.value) {
  1714. console.log("正在加载历史记录内容,跳过选择处理");
  1715. return;
  1716. }
  1717. // 如果正在扩写/续写,不处理选择
  1718. if (isPolishing.value) {
  1719. console.log("正在扩写/续写中,跳过选择处理");
  1720. return;
  1721. }
  1722. // 如果扩写输入框正在显示,不处理选择
  1723. if (showPolishInput.value) {
  1724. console.log("扩写输入框正在显示,跳过选择处理");
  1725. return;
  1726. }
  1727. try {
  1728. const selection = window.getSelection();
  1729. console.log("当前选择:", selection ? selection.toString() : "无选择");
  1730. if (selection && selection.toString().trim().length > 0) {
  1731. console.log("检测到选中文本");
  1732. const selectedTextContent = selection.toString().trim();
  1733. selectedText.value = selectedTextContent;
  1734. // 使用鼠标最后位置作为输入框位置,并考虑屏幕边界
  1735. const polishBoxWidth = 400; // 扩写框最大宽度
  1736. const polishBoxHeight = 60; // 扩写框高度(估算)
  1737. const margin = 10; // 边距
  1738. // 获取当前视口尺寸
  1739. const viewportWidth = window.innerWidth;
  1740. const viewportHeight = window.innerHeight;
  1741. let x = mousePosition.value.x + margin; // 默认在鼠标右侧
  1742. let y = mousePosition.value.y - 80; // 默认在鼠标上方
  1743. // 检查右边界 - 如果右侧空间不够,改为左侧
  1744. if (x + polishBoxWidth > viewportWidth) {
  1745. x = mousePosition.value.x - polishBoxWidth - margin;
  1746. }
  1747. // 检查左边界 - 如果左侧也不够,贴左边
  1748. if (x < margin) {
  1749. x = margin;
  1750. }
  1751. // 检查上边界 - 如果上方空间不够,改为下方
  1752. if (y < margin) {
  1753. y = mousePosition.value.y + margin;
  1754. }
  1755. // 检查下边界 - 如果下方也不够,贴底边
  1756. if (y + polishBoxHeight > viewportHeight - margin) {
  1757. y = viewportHeight - polishBoxHeight - margin;
  1758. }
  1759. // 最终边界检查,确保不会超出屏幕
  1760. x = Math.max(margin, Math.min(x, viewportWidth - polishBoxWidth - margin));
  1761. y = Math.max(margin, Math.min(y, viewportHeight - polishBoxHeight - margin));
  1762. polishInputPosition.value = { x, y };
  1763. showPolishInput.value = true;
  1764. console.log("选中文本:", selectedTextContent);
  1765. console.log("鼠标位置:", mousePosition.value);
  1766. console.log("视口尺寸:", { width: viewportWidth, height: viewportHeight });
  1767. console.log("扩写框位置:", polishInputPosition.value);
  1768. // 保存选区信息,包括HTML结构用于精确匹配
  1769. if (selection && selection.rangeCount > 0) {
  1770. try {
  1771. const range = selection.getRangeAt(0);
  1772. // 确保选区在编辑器内
  1773. const editorContainer = editorRef.value?.getEditableContainer?.();
  1774. if (editorContainer && editorContainer.contains(range.commonAncestorContainer)) {
  1775. // 创建临时容器来获取选中内容的HTML
  1776. const tempDiv = document.createElement('div');
  1777. tempDiv.appendChild(range.cloneContents());
  1778. const selectedHtml = tempDiv.innerHTML;
  1779. // 获取选中文本的纯文本内容(移除所有HTML标签)
  1780. const selectedPlainText = tempDiv.textContent || tempDiv.innerText || '';
  1781. // 检测是否为多格式文本
  1782. const isMultiFormat = selectedHtml.includes('<strong>') ||
  1783. selectedHtml.includes('<em>') ||
  1784. selectedHtml.includes('<b>') ||
  1785. selectedHtml.includes('<i>') ||
  1786. selectedHtml.includes('<span') ||
  1787. selectedHtml.includes('<h1>') ||
  1788. selectedHtml.includes('<h2>') ||
  1789. selectedHtml.includes('<h3>') ||
  1790. selectedHtml.includes('<h4>') ||
  1791. selectedHtml.includes('<h5>') ||
  1792. selectedHtml.includes('<h6>') ||
  1793. selectedHtml.includes('<u>') ||
  1794. selectedHtml.includes('<s>');
  1795. savedSelection.value = {
  1796. text: selectedTextContent,
  1797. html: selectedHtml,
  1798. plainText: selectedPlainText, // 保存纯文本内容
  1799. isMultiFormat: isMultiFormat, // 标记是否为多格式文本
  1800. range: range.cloneRange(),
  1801. // 保存更多选区信息用于多格式文本
  1802. startContainer: range.startContainer,
  1803. endContainer: range.endContainer,
  1804. startOffset: range.startOffset,
  1805. endOffset: range.endOffset,
  1806. // 保存完整的HTML内容用于精确匹配
  1807. fullHtml: editorRef.value.getHtml()
  1808. };
  1809. console.log("已保存选区信息:", {
  1810. text: selectedTextContent,
  1811. html: selectedHtml,
  1812. plainText: selectedPlainText,
  1813. isMultiFormat: isMultiFormat,
  1814. startContainer: range.startContainer,
  1815. endContainer: range.endContainer,
  1816. startOffset: range.startOffset,
  1817. endOffset: range.endOffset
  1818. });
  1819. // 不显示自定义高亮框,保留浏览器原生选区高亮
  1820. // 这样用户可以直接通过退格键删除选中的文本
  1821. } else {
  1822. console.log("选区不在编辑器内,清除保存的选区");
  1823. savedSelection.value = null;
  1824. }
  1825. } catch (error) {
  1826. console.error("保存选区失败:", error);
  1827. savedSelection.value = null;
  1828. }
  1829. }
  1830. // 不自动聚焦到扩写输入框,避免选区丢失
  1831. // 用户需要时可以手动点击输入框进行输入
  1832. } else {
  1833. console.log("没有选中文本,隐藏输入框");
  1834. hidePolishInput();
  1835. }
  1836. } catch (error) {
  1837. console.error("处理文本选择失败:", error);
  1838. hidePolishInput();
  1839. }
  1840. };
  1841. // 处理滚动事件
  1842. const handleScroll = (event) => {
  1843. // 如果扩写输入框正在显示
  1844. if (showPolishInput.value) {
  1845. // 检查是否在编辑器容器内滚动
  1846. const isInEditor = event.target.closest('.w-e-text-container') ||
  1847. event.target.closest('.rich-editor-container') ||
  1848. event.target.closest('.w-e-text-placeholder') ||
  1849. event.target.closest('.w-e-content');
  1850. // 如果在编辑器内滚动
  1851. if (isInEditor) {
  1852. // 如果正在扩写/续写过程中,禁用滚动
  1853. if (isPolishing.value) {
  1854. console.log("扩写/续写过程中,禁用编辑器滚动");
  1855. event.preventDefault();
  1856. event.stopPropagation();
  1857. return;
  1858. }
  1859. // 扩写/续写完成后允许滚动,但隐藏扩写输入框
  1860. console.log("检测到编辑器内滚动,隐藏扩写输入框");
  1861. hidePolishInput();
  1862. } else {
  1863. console.log("检测到页面滚动,但不隐藏扩写输入框");
  1864. }
  1865. }
  1866. };
  1867. // 处理键盘事件
  1868. const handleKeyDown = (event) => {
  1869. // 如果扩写输入框正在显示
  1870. if (showPolishInput.value) {
  1871. // 检查是否在扩写输入框内(更精确的检查)
  1872. const isInPolishInput = event.target.closest('.ai-polish-input') ||
  1873. event.target.classList.contains('polish-input-field') ||
  1874. event.target.classList.contains('polish-input-container') ||
  1875. event.target.classList.contains('input-wrapper');
  1876. // 如果在扩写输入框内,不处理任何键盘事件
  1877. if (isInPolishInput) {
  1878. console.log("在扩写输入框内,不处理键盘事件");
  1879. return;
  1880. }
  1881. // 检查是否在编辑器内
  1882. const isInEditor = event.target.closest('.w-e-text-container') ||
  1883. event.target.closest('.rich-editor-container') ||
  1884. event.target.closest('.w-e-text-placeholder');
  1885. // 只有在编辑器内才处理键盘事件
  1886. if (isInEditor) {
  1887. // 在编辑器内按退格键、删除键
  1888. if (event.key === 'Backspace' || event.key === 'Delete') {
  1889. console.log("检测到退格/删除键,隐藏扩写输入框");
  1890. hidePolishInput();
  1891. }
  1892. // 在编辑器内输入文字(字母、数字、中文等)
  1893. else if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
  1894. console.log("检测到文字输入,隐藏扩写输入框");
  1895. hidePolishInput();
  1896. }
  1897. // 在编辑器内按空格键
  1898. else if (event.key === ' ') {
  1899. console.log("检测到空格键,隐藏扩写输入框");
  1900. hidePolishInput();
  1901. }
  1902. // 在编辑器内按Enter键
  1903. else if (event.key === 'Enter') {
  1904. console.log("检测到Enter键,隐藏扩写输入框");
  1905. hidePolishInput();
  1906. }
  1907. }
  1908. }
  1909. };
  1910. // 处理输入法开始事件
  1911. const handleCompositionStart = (event) => {
  1912. if (showPolishInput.value) {
  1913. // 检查是否在扩写输入框内(更精确的检查)
  1914. const isInPolishInput = event.target.closest('.ai-polish-input') ||
  1915. event.target.classList.contains('polish-input-field') ||
  1916. event.target.classList.contains('polish-input-container') ||
  1917. event.target.classList.contains('input-wrapper');
  1918. // 如果在扩写输入框内,不处理
  1919. if (isInPolishInput) {
  1920. console.log("在扩写输入框内,不处理输入法事件");
  1921. return;
  1922. }
  1923. // 检查是否在编辑器内
  1924. const isInEditor = event.target.closest('.w-e-text-container') ||
  1925. event.target.closest('.rich-editor-container') ||
  1926. event.target.closest('.w-e-text-placeholder');
  1927. // 在编辑器内开始输入法输入时隐藏扩写输入框
  1928. if (isInEditor) {
  1929. console.log("检测到输入法开始,隐藏扩写输入框");
  1930. hidePolishInput();
  1931. }
  1932. }
  1933. };
  1934. // 处理输入法更新事件
  1935. const handleCompositionUpdate = (event) => {
  1936. if (showPolishInput.value) {
  1937. // 检查是否在扩写输入框内(更精确的检查)
  1938. const isInPolishInput = event.target.closest('.ai-polish-input') ||
  1939. event.target.classList.contains('polish-input-field') ||
  1940. event.target.classList.contains('polish-input-container') ||
  1941. event.target.classList.contains('input-wrapper');
  1942. // 如果在扩写输入框内,不处理
  1943. if (isInPolishInput) {
  1944. console.log("在扩写输入框内,不处理输入法事件");
  1945. return;
  1946. }
  1947. // 检查是否在编辑器内
  1948. const isInEditor = event.target.closest('.w-e-text-container') ||
  1949. event.target.closest('.rich-editor-container') ||
  1950. event.target.closest('.w-e-text-placeholder');
  1951. // 在编辑器内输入法更新时隐藏扩写输入框
  1952. if (isInEditor) {
  1953. console.log("检测到输入法更新,隐藏扩写输入框");
  1954. hidePolishInput();
  1955. }
  1956. }
  1957. };
  1958. // 处理输入法结束事件
  1959. const handleCompositionEnd = (event) => {
  1960. if (showPolishInput.value) {
  1961. // 检查是否在扩写输入框内(更精确的检查)
  1962. const isInPolishInput = event.target.closest('.ai-polish-input') ||
  1963. event.target.classList.contains('polish-input-field') ||
  1964. event.target.classList.contains('polish-input-container') ||
  1965. event.target.classList.contains('input-wrapper');
  1966. // 如果在扩写输入框内,不处理
  1967. if (isInPolishInput) {
  1968. console.log("在扩写输入框内,不处理输入法事件");
  1969. return;
  1970. }
  1971. // 检查是否在编辑器内
  1972. const isInEditor = event.target.closest('.w-e-text-container') ||
  1973. event.target.closest('.rich-editor-container') ||
  1974. event.target.closest('.w-e-text-placeholder');
  1975. // 在编辑器内输入法结束时隐藏扩写输入框
  1976. if (isInEditor) {
  1977. console.log("检测到输入法结束,隐藏扩写输入框");
  1978. hidePolishInput();
  1979. }
  1980. }
  1981. };
  1982. // 处理文本选择变化
  1983. const handleSelectionChange = () => {
  1984. console.log("=== handleSelectionChange 被调用 ===");
  1985. // 如果正在润色,不处理选择变化
  1986. if (isPolishing.value) {
  1987. console.log("正在润色中,跳过选择变化处理");
  1988. return;
  1989. }
  1990. // 如果润色输入框正在显示,不处理选择变化
  1991. if (showPolishInput.value) {
  1992. console.log("润色输入框正在显示,跳过选择变化处理");
  1993. return;
  1994. }
  1995. // 只有在鼠标松开后才处理选择变化
  1996. if (!isMouseDown.value) {
  1997. console.log("鼠标已松开,调用 checkSelectionAndShowButton");
  1998. checkSelectionAndShowButton();
  1999. } else {
  2000. console.log("鼠标仍按下,等待松开");
  2001. }
  2002. };
  2003. // 处理扩写输入框点击事件
  2004. const handlePolishInputClick = (event) => {
  2005. // 允许输入框正常聚焦,但阻止事件冒泡
  2006. event.stopPropagation();
  2007. // 点击输入框时,显示自定义高亮而不是恢复原生选区
  2008. showCustomHighlight.value = true;
  2009. createCustomHighlight();
  2010. };
  2011. // 处理扩写输入框聚焦事件
  2012. const handlePolishInputFocus = (event) => {
  2013. // 输入框聚焦时,显示自定义高亮
  2014. showCustomHighlight.value = true;
  2015. createCustomHighlight();
  2016. };
  2017. // 处理扩写输入框失焦事件
  2018. const handlePolishInputBlur = (event) => {
  2019. // 输入框失焦时,隐藏自定义高亮,恢复原生选区
  2020. showCustomHighlight.value = false;
  2021. removeCustomHighlight();
  2022. // 恢复原生选区
  2023. setTimeout(() => {
  2024. if (savedSelection.value && savedSelection.value.range) {
  2025. try {
  2026. const selection = window.getSelection();
  2027. if (selection) {
  2028. // 清除当前选区
  2029. selection.removeAllRanges();
  2030. // 恢复保存的选区
  2031. selection.addRange(savedSelection.value.range);
  2032. console.log("输入框失焦时恢复选区成功");
  2033. }
  2034. } catch (error) {
  2035. console.error("恢复选区失败:", error);
  2036. }
  2037. }
  2038. }, 10);
  2039. };
  2040. // 创建自定义高亮
  2041. const createCustomHighlight = () => {
  2042. if (!savedSelection.value || !savedSelection.value.range) {
  2043. return;
  2044. }
  2045. try {
  2046. const range = savedSelection.value.range;
  2047. const rects = range.getClientRects(); // 使用 getClientRects() 获取多个矩形
  2048. // 移除之前的高亮元素
  2049. removeCustomHighlight();
  2050. // 如果没有矩形或矩形为空,则使用 getBoundingClientRect() 作为备选
  2051. if (!rects || rects.length === 0) {
  2052. const rect = range.getBoundingClientRect();
  2053. if (rect.width === 0 || rect.height === 0) {
  2054. console.log("选区矩形为空,跳过高亮创建");
  2055. return;
  2056. }
  2057. // 创建单个高亮元素
  2058. const highlightElement = document.createElement('div');
  2059. highlightElement.className = 'custom-selection-highlight';
  2060. highlightElement.style.cssText = `
  2061. position: fixed;
  2062. left: ${rect.left}px;
  2063. top: ${rect.top}px;
  2064. width: ${rect.width}px;
  2065. height: ${rect.height}px;
  2066. background-color: rgba(59, 130, 246, 0.2);
  2067. border: 1px solid rgba(59, 130, 246, 0.5);
  2068. border-radius: 2px;
  2069. pointer-events: none;
  2070. z-index: 998;
  2071. transition: all 0.2s ease;
  2072. `;
  2073. document.body.appendChild(highlightElement);
  2074. customHighlightElement.value = [highlightElement];
  2075. console.log("自定义高亮创建成功(单个矩形)");
  2076. return;
  2077. }
  2078. // 为每个矩形创建高亮元素(多行选择)
  2079. const highlightElements = [];
  2080. for (let i = 0; i < rects.length; i++) {
  2081. const rect = rects[i];
  2082. // 跳过宽度或高度为0的矩形
  2083. if (rect.width === 0 || rect.height === 0) {
  2084. continue;
  2085. }
  2086. const highlightElement = document.createElement('div');
  2087. highlightElement.className = 'custom-selection-highlight';
  2088. highlightElement.style.cssText = `
  2089. position: fixed;
  2090. left: ${rect.left}px;
  2091. top: ${rect.top}px;
  2092. width: ${rect.width}px;
  2093. height: ${rect.height}px;
  2094. background-color: rgba(59, 130, 246, 0.2);
  2095. border: 1px solid rgba(59, 130, 246, 0.5);
  2096. border-radius: 2px;
  2097. pointer-events: none;
  2098. z-index: 998;
  2099. transition: all 0.2s ease;
  2100. `;
  2101. document.body.appendChild(highlightElement);
  2102. highlightElements.push(highlightElement);
  2103. }
  2104. // 保存所有高亮元素的引用
  2105. customHighlightElement.value = highlightElements;
  2106. console.log(`自定义高亮创建成功(${highlightElements.length}个矩形)`);
  2107. } catch (error) {
  2108. console.error("创建自定义高亮失败:", error);
  2109. }
  2110. };
  2111. // 移除自定义高亮
  2112. const removeCustomHighlight = () => {
  2113. if (customHighlightElement.value) {
  2114. try {
  2115. // 处理多个高亮元素(数组)
  2116. if (Array.isArray(customHighlightElement.value)) {
  2117. customHighlightElement.value.forEach(element => {
  2118. try {
  2119. if (element && element.parentNode) {
  2120. document.body.removeChild(element);
  2121. }
  2122. } catch (e) {
  2123. console.error("移除单个高亮元素失败:", e);
  2124. }
  2125. });
  2126. console.log(`自定义高亮移除成功(${customHighlightElement.value.length}个矩形)`);
  2127. } else {
  2128. // 处理单个高亮元素(向后兼容)
  2129. if (customHighlightElement.value.parentNode) {
  2130. document.body.removeChild(customHighlightElement.value);
  2131. }
  2132. console.log("自定义高亮移除成功");
  2133. }
  2134. customHighlightElement.value = null;
  2135. } catch (error) {
  2136. console.error("移除自定义高亮失败:", error);
  2137. }
  2138. }
  2139. };
  2140. // 隐藏扩写输入框和高亮框
  2141. const hidePolishInput = () => {
  2142. showPolishInput.value = false;
  2143. selectedText.value = "";
  2144. polishCustomPrompt.value = "";
  2145. polishingType.value = ''; // 重置操作类型
  2146. showCustomHighlight.value = false;
  2147. removeCustomHighlight();
  2148. savedSelection.value = null; // 清除保存的选区
  2149. };
  2150. // 处理AI扩写
  2151. const handlePolishText = async () => {
  2152. if (!selectedText.value.trim() || isPolishing.value) {
  2153. return;
  2154. }
  2155. try {
  2156. isPolishing.value = true;
  2157. polishingType.value = 'polish'; // 设置为扩写类型
  2158. // 构建扩写提示词
  2159. let polishPrompt = `请对以下文本进行扩写,要求:
  2160. 1. 保持原文的核心意思和逻辑结构
  2161. 2. 提升语言的流畅性和专业性
  2162. 3. 优化表达方式,使其更加准确和生动
  2163. 4. 保持原文的语调和风格
  2164. 5. 只返回扩写后的文本,不要添加任何解释或说明`;
  2165. // 如果用户有自定义要求,使用用户的要求
  2166. if (polishCustomPrompt.value.trim()) {
  2167. polishPrompt = `请根据以下要求对文本进行处理:${polishCustomPrompt.value.trim()}
  2168. 要求:
  2169. 1. 保持原文的核心意思和逻辑结构
  2170. 2. 只返回处理后的文本,不要添加任何解释或说明`;
  2171. }
  2172. polishPrompt += `\n\n原文:\n${selectedText.value}`;
  2173. // 调用AI扩写接口
  2174. const response = await apis.reProduceSingleQuestion({
  2175. message: polishPrompt
  2176. });
  2177. if (response && response.data && response.data.reply) {
  2178. const polishedText = response.data.reply.trim();
  2179. // 使用保存的选区信息或当前选区进行扩写
  2180. if (editorRef.value) {
  2181. try {
  2182. let currentSelection = null;
  2183. let selectedText = "";
  2184. // 优先使用当前选区
  2185. const selection = window.getSelection();
  2186. if (selection && selection.toString().trim()) {
  2187. currentSelection = selection;
  2188. selectedText = selection.toString();
  2189. console.log("使用当前选区:", selectedText);
  2190. }
  2191. // 如果当前选区为空,使用保存的选区信息
  2192. else if (savedSelection.value && savedSelection.value.text) {
  2193. selectedText = savedSelection.value.text;
  2194. console.log("使用保存的选区:", selectedText);
  2195. }
  2196. if (selectedText) {
  2197. // 检查是否为多格式文本
  2198. // if (savedSelection.value && savedSelection.value.isMultiFormat) {
  2199. // console.log("检测到多格式文本,不建议进行润色");
  2200. // ElMessage.warning("不建议选取多字体进行润色,会造成后续文字结构变化");
  2201. // return;
  2202. // }
  2203. // 如果有保存的选区,优先使用wangeditor的API进行精确替换
  2204. if (savedSelection.value && savedSelection.value.range) {
  2205. try {
  2206. // 使用wangeditor的API而不是直接操作DOM,避免与Slate状态冲突
  2207. const editor = editorRef.value;
  2208. // 先尝试使用wangeditor的选区恢复API
  2209. if (editor.restoreSelection && typeof editor.restoreSelection === 'function') {
  2210. editor.restoreSelection(savedSelection.value.range);
  2211. // 使用wangeditor的insertText方法,它会自动处理Slate状态同步
  2212. editor.insertText(polishedText);
  2213. console.log("扩写完成,通过wangeditor restoreSelection + insertText API");
  2214. ElMessage.success("文本扩写完成");
  2215. return;
  2216. } else {
  2217. // 如果restoreSelection不可用,使用字符串替换策略
  2218. throw new Error("wangeditor restoreSelection API不可用");
  2219. }
  2220. } catch (insertError) {
  2221. console.error("使用wangeditor API替换失败,尝试字符串替换:", insertError);
  2222. }
  2223. }
  2224. // 如果有当前选区,使用wangeditor的insertText方法
  2225. if (currentSelection) {
  2226. try {
  2227. // 获取当前选区
  2228. const range = currentSelection.getRangeAt(0);
  2229. // 检查选区是否在编辑器内
  2230. const editorElement = editorRef.value.getEditableContainer();
  2231. if (editorElement && editorElement.contains(range.commonAncestorContainer)) {
  2232. // 使用wangeditor的insertText方法替换选中内容
  2233. editorRef.value.insertText(polishedText);
  2234. console.log("扩写完成,通过wangeditor insertText API");
  2235. // 清除选择
  2236. currentSelection.removeAllRanges();
  2237. return;
  2238. } else {
  2239. throw new Error("选区不在编辑器内");
  2240. }
  2241. } catch (insertError) {
  2242. console.log("insertText失败,尝试字符串替换:", insertError);
  2243. }
  2244. }
  2245. // 降级方案:使用字符串替换
  2246. const currentHtml = editorRef.value.getHtml();
  2247. console.log("扩写前内容长度:", currentHtml.length);
  2248. let newHtml = currentHtml;
  2249. let replaced = false;
  2250. // 添加调试信息
  2251. console.log("扩写调试信息:", {
  2252. selectedText: selectedText,
  2253. currentHtmlLength: currentHtml.length,
  2254. savedSelection: savedSelection.value,
  2255. hasCurrentSelection: !!currentSelection
  2256. });
  2257. // 尝试多种替换策略
  2258. // 策略1:使用保存的HTML结构进行精确替换(适用于多格式文本)
  2259. // 为了处理HTML实体编码问题,这里需要对selectedText进行HTML解码再进行比较
  2260. const decodedSelectedHtml = savedSelection.value?.html ? new DOMParser().parseFromString(savedSelection.value.html, 'text/html').documentElement.textContent : '';
  2261. if (savedSelection.value && savedSelection.value.html && (currentHtml.includes(savedSelection.value.html) || currentHtml.includes(decodedSelectedHtml))) {
  2262. if (currentHtml.includes(savedSelection.value.html)) {
  2263. newHtml = currentHtml.replace(savedSelection.value.html, polishedText);
  2264. replaced = true;
  2265. console.log("策略1成功:通过保存的HTML结构替换");
  2266. } else if (currentHtml.includes(decodedSelectedHtml)) {
  2267. newHtml = currentHtml.replace(decodedSelectedHtml, polishedText);
  2268. replaced = true;
  2269. console.log("策略1成功:通过解码后的HTML结构替换");
  2270. }
  2271. }
  2272. // 策略1.5:使用保存的纯文本进行替换(适用于多格式文本)
  2273. else if (savedSelection.value && savedSelection.value.plainText && currentHtml.includes(savedSelection.value.plainText)) {
  2274. newHtml = currentHtml.replace(savedSelection.value.plainText, polishedText);
  2275. replaced = true;
  2276. console.log("策略1.5成功:通过保存的纯文本替换");
  2277. }
  2278. // 策略2:直接字符串替换
  2279. else if (currentHtml.includes(selectedText)) {
  2280. newHtml = currentHtml.replace(selectedText, polishedText);
  2281. replaced = true;
  2282. console.log("策略2成功:直接字符串替换");
  2283. }
  2284. // 策略3:HTML实体替换
  2285. else {
  2286. const htmlEntities = selectedText
  2287. .replace(/&/g, '&amp;')
  2288. .replace(/</g, '&lt;')
  2289. .replace(/>/g, '&gt;')
  2290. .replace(/"/g, '&quot;')
  2291. .replace(/'/g, '&#39;');
  2292. console.log("策略3尝试:HTML实体替换", {
  2293. htmlEntities: htmlEntities,
  2294. includes: currentHtml.includes(htmlEntities)
  2295. });
  2296. if (currentHtml.includes(htmlEntities)) {
  2297. newHtml = currentHtml.replace(htmlEntities, polishedText);
  2298. replaced = true;
  2299. console.log("策略3成功:HTML实体替换");
  2300. } else {
  2301. // 策略4:正则表达式匹配
  2302. const regex = new RegExp(`>[^<]*${selectedText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[^<]*<`, 'g');
  2303. const match = currentHtml.match(regex);
  2304. console.log("策略4尝试:正则表达式匹配", {
  2305. regex: regex,
  2306. match: match
  2307. });
  2308. if (match) {
  2309. newHtml = currentHtml.replace(match[0], match[0].replace(selectedText, polishedText));
  2310. replaced = true;
  2311. console.log("策略4成功:正则表达式替换");
  2312. }
  2313. // 策略5:尝试模糊匹配(移除HTML标签后匹配)
  2314. else {
  2315. // 清理文本,移除HTML标签进行模糊匹配
  2316. const cleanText = selectedText.replace(/<[^>]*>/g, '').trim();
  2317. const cleanCurrentHtml = currentHtml.replace(/<[^>]*>/g, '');
  2318. console.log("策略5尝试:模糊匹配", {
  2319. cleanText: cleanText,
  2320. cleanCurrentHtml: cleanCurrentHtml.substring(0, 200) + '...',
  2321. includes: cleanCurrentHtml.includes(cleanText)
  2322. });
  2323. if (cleanCurrentHtml.includes(cleanText)) {
  2324. // 找到包含选中文本的HTML片段进行替换
  2325. const regex = new RegExp(`[^>]*${cleanText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[^<]*`, 'g');
  2326. const match = currentHtml.match(regex);
  2327. if (match) {
  2328. newHtml = currentHtml.replace(match[0], match[0].replace(cleanText, polishedText));
  2329. replaced = true;
  2330. console.log("策略5成功:通过模糊匹配替换");
  2331. }
  2332. }
  2333. }
  2334. }
  2335. }
  2336. if (replaced) {
  2337. // 设置新的内容到编辑器,并确保wangeditor状态同步
  2338. try {
  2339. editorRef.value.setHtml(newHtml);
  2340. // 强制刷新编辑器状态,避免Slate状态不同步
  2341. setTimeout(() => {
  2342. try {
  2343. // 触发编辑器内容变化事件,确保内部状态更新
  2344. const editorElement = editorRef.value.getEditableContainer();
  2345. if (editorElement) {
  2346. // 触发input事件,让wangeditor知道内容已变化
  2347. const inputEvent = new Event('input', { bubbles: true });
  2348. editorElement.dispatchEvent(inputEvent);
  2349. }
  2350. } catch (syncError) {
  2351. console.log("编辑器状态同步失败:", syncError);
  2352. }
  2353. }, 10);
  2354. console.log("润色后内容长度:", newHtml.length);
  2355. console.log("润色完成,通过字符串替换");
  2356. console.log("润色后内容预览:", newHtml.substring(0, 200) + '...');
  2357. } catch (setHtmlError) {
  2358. console.error("设置编辑器内容失败:", setHtmlError);
  2359. ElMessage.error("润色失败,请重试");
  2360. return;
  2361. }
  2362. } else {
  2363. console.log("所有替换策略都失败,未找到匹配的文本");
  2364. ElMessage.warning("未找到选中的文本,请重新选择");
  2365. return;
  2366. }
  2367. } else {
  2368. console.log("没有找到选中的文本");
  2369. ElMessage.warning("请先选择要润色的文本");
  2370. return;
  2371. }
  2372. } catch (error) {
  2373. console.error("润色失败:", error);
  2374. ElMessage.error("润色失败,请重试");
  2375. return;
  2376. }
  2377. }
  2378. ElMessage.success("文本润色完成");
  2379. console.log("文本润色完成");
  2380. } else {
  2381. ElMessage.error("润色失败,请重试");
  2382. }
  2383. } catch (error) {
  2384. console.error("AI润色失败:", error);
  2385. ElMessage.error("润色失败,请检查网络连接");
  2386. } finally {
  2387. isPolishing.value = false;
  2388. polishingType.value = ''; // 重置操作类型
  2389. hidePolishInput();
  2390. }
  2391. };
  2392. // 处理AI续写
  2393. const handleContinueText = async () => {
  2394. if (!selectedText.value.trim() || isPolishing.value) {
  2395. return;
  2396. }
  2397. try {
  2398. isPolishing.value = true;
  2399. polishingType.value = 'continue'; // 设置为续写类型
  2400. // 构建续写提示词
  2401. let continuePrompt = `请对以下文本进行续写,要求:
  2402. 1. 保持原文的语调和风格
  2403. 2. 在原文基础上自然延续,【重要】绝对不要重复原文内容
  2404. 3. 续写的内容应该与原文逻辑连贯
  2405. 4. 增加新的内容,使文章更加完整
  2406. 5. 【重要】只返回续写的内容,不要包含原文,不要添加任何解释或说明
  2407. 6. 【重要】直接开始续写新内容,不要重复原文的最后几个字
  2408. 7. 如果AI无法理解或续写,请返回"无法续写"`;
  2409. // 如果用户有自定义要求,使用用户的要求
  2410. if (polishCustomPrompt.value.trim()) {
  2411. continuePrompt = `请根据以下要求对文本进行续写:${polishCustomPrompt.value.trim()}
  2412. 要求:
  2413. 1. 保持原文的语调和风格
  2414. 2. 【重要】只返回续写的内容,不要包含原文,不要添加任何解释或说明
  2415. 3. 【重要】直接开始续写新内容,不要重复原文
  2416. 4. 如果AI无法理解或续写,请返回"无法续写"`;
  2417. }
  2418. continuePrompt += `\n\n原文:\n${selectedText.value}\n\n请直接开始续写,不要重复原文:`;
  2419. // 调用AI续写接口
  2420. const response = await apis.reProduceSingleQuestion({
  2421. message: continuePrompt
  2422. });
  2423. if (response && response.data && response.data.reply) {
  2424. let continuedText = response.data.reply.trim();
  2425. console.log("AI返回的原始续写内容:", continuedText);
  2426. console.log("原文:", selectedText.value);
  2427. // 处理AI幻觉:如果返回的内容包含原文,则提取续写部分
  2428. if (continuedText.includes(selectedText.value)) {
  2429. console.log("AI返回内容包含原文,开始提取纯续写部分");
  2430. // 找到原文在续写内容中的位置
  2431. const originalTextIndex = continuedText.indexOf(selectedText.value);
  2432. if (originalTextIndex !== -1) {
  2433. // 提取原文后面的部分作为续写内容
  2434. continuedText = continuedText.substring(originalTextIndex + selectedText.value.length).trim();
  2435. console.log("提取后的纯续写内容:", continuedText);
  2436. }
  2437. } else {
  2438. console.log("AI返回内容不包含原文,直接使用");
  2439. }
  2440. // 额外处理:移除可能的常见前缀(如"续写:"、"续写内容:"等)
  2441. const prefixPatterns = [
  2442. /^续写[::]/,
  2443. /^续写内容[::]/,
  2444. /^续写部分[::]/,
  2445. /^以下是续写[::]/,
  2446. /^以下是续写内容[::]/
  2447. ];
  2448. for (const pattern of prefixPatterns) {
  2449. if (pattern.test(continuedText)) {
  2450. continuedText = continuedText.replace(pattern, '').trim();
  2451. console.log("移除前缀后的续写内容:", continuedText);
  2452. break;
  2453. }
  2454. }
  2455. // 如果续写内容为空或包含"无法续写",则提示用户
  2456. if (!continuedText || continuedText === "无法续写" || continuedText.length < 2) {
  2457. ElMessage.warning("AI无法续写此内容,请尝试其他文本或调整要求");
  2458. return;
  2459. }
  2460. console.log("最终使用的续写内容:", continuedText);
  2461. // 使用光标位置插入法:直接在选区末尾插入续写内容
  2462. if (editorRef.value) {
  2463. try {
  2464. console.log("续写调试信息:", {
  2465. selectedText: selectedText.value,
  2466. continuedText: continuedText,
  2467. hasSavedRange: !!savedSelection.value?.range,
  2468. savedSelection: savedSelection.value
  2469. });
  2470. // 策略1:使用保存的Range,在选区末尾插入内容
  2471. if (savedSelection.value && savedSelection.value.range) {
  2472. try {
  2473. const range = savedSelection.value.range;
  2474. const editorElement = editorRef.value.getEditableContainer();
  2475. // 确保Range在编辑器内
  2476. if (editorElement && editorElement.contains(range.endContainer)) {
  2477. // 创建一个新Range,定位到原选区的末尾
  2478. const newRange = document.createRange();
  2479. newRange.setStart(range.endContainer, range.endOffset);
  2480. newRange.setEnd(range.endContainer, range.endOffset);
  2481. // 在末尾位置插入一个文本节点
  2482. const textNode = document.createTextNode(continuedText);
  2483. newRange.insertNode(textNode);
  2484. // 移动光标到插入内容的末尾
  2485. newRange.setStartAfter(textNode);
  2486. newRange.collapse(true);
  2487. // 更新编辑器选区
  2488. const selection = window.getSelection();
  2489. if (selection) {
  2490. selection.removeAllRanges();
  2491. selection.addRange(newRange);
  2492. }
  2493. // 触发编辑器内容变化事件
  2494. setTimeout(() => {
  2495. try {
  2496. const inputEvent = new Event('input', { bubbles: true });
  2497. editorElement.dispatchEvent(inputEvent);
  2498. } catch (e) {
  2499. console.log("触发input事件失败:", e);
  2500. }
  2501. }, 10);
  2502. console.log("续写成功:通过Range在选区末尾插入文本节点");
  2503. ElMessage.success("文本续写完成");
  2504. return;
  2505. } else {
  2506. console.log("Range不在编辑器内,尝试其他策略");
  2507. }
  2508. } catch (rangeError) {
  2509. console.error("使用Range插入失败:", rangeError);
  2510. }
  2511. }
  2512. // 策略2:使用HTML结构匹配(作为备选方案)
  2513. const currentHtml = editorRef.value.getHtml();
  2514. let newHtml = currentHtml;
  2515. let replaced = false;
  2516. // 如果有保存的HTML结构,直接在其后添加续写内容
  2517. if (savedSelection.value && savedSelection.value.html && currentHtml.includes(savedSelection.value.html)) {
  2518. const htmlWithContinue = savedSelection.value.html + continuedText;
  2519. newHtml = currentHtml.replace(savedSelection.value.html, htmlWithContinue);
  2520. replaced = true;
  2521. console.log("续写成功:通过HTML结构匹配添加续写");
  2522. }
  2523. // 如果有保存的纯文本,进行文本匹配
  2524. else if (savedSelection.value && savedSelection.value.plainText && currentHtml.includes(savedSelection.value.plainText)) {
  2525. const textWithContinue = savedSelection.value.plainText + continuedText;
  2526. newHtml = currentHtml.replace(savedSelection.value.plainText, textWithContinue);
  2527. replaced = true;
  2528. console.log("续写成功:通过纯文本匹配添加续写");
  2529. }
  2530. // 直接使用选中的文本进行匹配
  2531. else if (currentHtml.includes(selectedText.value)) {
  2532. const textWithContinue = selectedText.value + continuedText;
  2533. newHtml = currentHtml.replace(selectedText.value, textWithContinue);
  2534. replaced = true;
  2535. console.log("续写成功:通过直接文本匹配添加续写");
  2536. }
  2537. if (replaced) {
  2538. editorRef.value.setHtml(newHtml);
  2539. // 强制刷新编辑器状态
  2540. setTimeout(() => {
  2541. try {
  2542. const editorElement = editorRef.value.getEditableContainer();
  2543. if (editorElement) {
  2544. const inputEvent = new Event('input', { bubbles: true });
  2545. editorElement.dispatchEvent(inputEvent);
  2546. }
  2547. } catch (syncError) {
  2548. console.log("编辑器状态同步失败:", syncError);
  2549. }
  2550. }, 10);
  2551. console.log("续写完成");
  2552. ElMessage.success("文本续写完成");
  2553. } else {
  2554. console.error("所有策略都失败了");
  2555. console.log("续写失败调试信息:", {
  2556. selectedText: selectedText.value,
  2557. savedSelectionHtml: savedSelection.value?.html,
  2558. savedSelectionPlainText: savedSelection.value?.plainText,
  2559. currentHtmlPreview: currentHtml.substring(0, 500)
  2560. });
  2561. ElMessage.error("续写失败,无法找到选中的文本");
  2562. }
  2563. } catch (error) {
  2564. console.error("续写过程中发生错误:", error);
  2565. ElMessage.error("续写失败,请重试");
  2566. }
  2567. } else {
  2568. console.error("编辑器引用不存在");
  2569. ElMessage.error("续写失败,编辑器未初始化");
  2570. }
  2571. } else {
  2572. ElMessage.error("续写失败,请重试");
  2573. }
  2574. } catch (error) {
  2575. console.error("AI续写失败:", error);
  2576. ElMessage.error("续写失败,请检查网络连接");
  2577. } finally {
  2578. isPolishing.value = false;
  2579. polishingType.value = ''; // 重置操作类型
  2580. hidePolishInput();
  2581. }
  2582. };
  2583. // 格式化内容为富文本编辑器格式 - 简化版本,直接使用 wangeditor
  2584. const formatContentForEditor = (content) => {
  2585. if (!content) return "";
  2586. console.log('formatContentForEditor 输入内容:', content);
  2587. console.log('formatContentForEditor 输入内容长度:', content.length);
  2588. console.log('formatContentForEditor 输入内容预览:', content.substring(0, 200) + '...');
  2589. // 检测是否为 HTML 格式
  2590. const isHTML = /<[^>]+>/.test(content);
  2591. console.log('检测到HTML格式:', isHTML);
  2592. if (isHTML) {
  2593. console.log('直接使用后端返回的HTML内容,无需转换');
  2594. // 直接返回后端生成的HTML内容,wangeditor 可以直接处理
  2595. return content;
  2596. }
  2597. // 如果不是 HTML,按普通文本处理
  2598. console.log('按普通文本处理');
  2599. return formatPlainText(content);
  2600. };
  2601. // 普通文本格式化函数
  2602. const formatPlainText = (content) => {
  2603. console.log('开始普通文本处理,内容长度:', content.length);
  2604. // 先处理换行符,保持原始结构
  2605. let formatted = content
  2606. .replace(/\n\n\n+/g, '\n\n') // 多个连续换行合并为双换行
  2607. .replace(/\n\n/g, '</p><p>') // 双换行转换为段落
  2608. .replace(/\n/g, '<br>'); // 单换行转换为换行符
  2609. // 包装在段落标签中
  2610. if (formatted.trim()) {
  2611. formatted = '<p>' + formatted + '</p>';
  2612. }
  2613. // 处理标题格式
  2614. formatted = formatted
  2615. .replace(/<p>(第[一二三四五六七八九十\d]+章[^<]*)<\/p>/g, '<h2>$1</h2>')
  2616. .replace(/<p>(\d+\.\d+[^<]*)<\/p>/g, '<h3>$1</h3>')
  2617. .replace(/<p>(\d+\.\d+\.\d+[^<]*)<\/p>/g, '<h4>$1</h4>')
  2618. .replace(/<p>(一、[^<]*)<\/p>/g, '<h3>$1</h3>')
  2619. .replace(/<p>(二、[^<]*)<\/p>/g, '<h3>$1</h3>')
  2620. .replace(/<p>(三、[^<]*)<\/p>/g, '<h3>$1</h3>')
  2621. .replace(/<p>(四、[^<]*)<\/p>/g, '<h3>$1</h3>')
  2622. .replace(/<p>(五、[^<]*)<\/p>/g, '<h3>$1</h3>');
  2623. // 清理空段落
  2624. formatted = formatted.replace(/<p><\/p>/g, '');
  2625. formatted = formatted.replace(/<p>\s*<\/p>/g, '');
  2626. console.log('普通文本处理后内容长度:', formatted.length);
  2627. console.log('普通文本处理后内容预览:', formatted.substring(0, 200) + '...');
  2628. return formatted;
  2629. };
  2630. // 专门处理包含"-"符号的文本,避免被误认为Markdown列表
  2631. const formatTextWithDashes = (content) => {
  2632. console.log('开始处理包含"-"符号的文本,内容长度:', content.length);
  2633. // 先转义所有"-"符号,避免被marked误认为列表
  2634. let processedContent = content.replace(/^- /gm, '\\- '); // 转义行首的"- "
  2635. // 然后进行普通文本处理
  2636. return formatPlainText(processedContent);
  2637. };
  2638. // wangeditor 可以直接处理 HTML,无需额外转换
  2639. // 切换标签
  2640. const switchTab = (tabKey) => {
  2641. activeTab.value = tabKey;
  2642. console.log("切换到标签:", tabKey);
  2643. };
  2644. // 使用模板
  2645. const useTemplate = (templateName) => {
  2646. console.log("使用模板:", templateName);
  2647. // 根据模板名称填充对应的模板内容
  2648. let content = "";
  2649. switch (templateName) {
  2650. case "通知模板":
  2651. content = "<span class=\"editable-highlight\" contenteditable=\"true\">通知主题:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">通知对象:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">具体事项:</span>\n\n请帮我生成一份正式的通知,要求格式规范、语言严谨,具体参考以上内容,按照标准公文格式生成完整通知,包括文号、标题、正文、落款等所有要素。";
  2652. break;
  2653. case "公告模板":
  2654. content = "<span class=\"editable-highlight\" contenteditable=\"true\">公告主题:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">发文单位:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">核心内容:</span>\n\n请帮我生成一份正式的公告,要求格式规范、语言严谨,具体参考以上内容,按照标准公告格式生成全文,包括标题、正文、落款等所有要素。";
  2655. break;
  2656. case "会议纪要模版":
  2657. content = "<span class=\"editable-highlight\" contenteditable=\"true\">会议主题:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">会议时间:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">主要议题:</span>\n\n请帮我生成一份正式的会议纪要,要求格式规范、语言严谨,具体参考以上内容,按照标准会议纪要格式生成全文,包含标题、导语、议定事项和落款。";
  2658. break;
  2659. case "决定模版":
  2660. content = "<span class=\"editable-highlight\" contenteditable=\"true\">决定主题:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">决定依据:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">决定内容:</span>\n\n请帮我生成一份正式的决定,要求格式规范、语言严谨,具体参考以上内容,按照标准决定公文格式生成完整文件。";
  2661. break;
  2662. case "工作汇报模板":
  2663. content = "<span class=\"editable-highlight\" contenteditable=\"true\">总结主题:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">总结时间:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">主要内容:</span>\n\n请帮我生成一份正式的总结报告,要求格式规范、语言严谨,具体参考以上内容,按照标准工作总结格式生成全文,包含\"工作总结、问题不足、未来计划\"三部分的完整报告。";
  2664. break;
  2665. default:
  2666. content = "<span class=\"editable-highlight\" contenteditable=\"true\">公告主题:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">发文单位:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">核心内容:</span>\n\n请帮我生成一份正式的公告,要求格式规范、语言严谨,具体参考以上内容,按照标准公告格式生成全文,包括标题、正文、落款等所有要素。";
  2667. }
  2668. // 将模板内容填充到输入框中
  2669. const inputElement = document.querySelector('.template-input-container');
  2670. if (inputElement) {
  2671. // 使用更安全的方式设置HTML内容
  2672. inputElement.innerHTML = content;
  2673. // 同时更新templateContent.value,确保发送时使用正确的模板内容
  2674. templateContent.value = content.replace(/<[^>]*>/g, ''); // 移除HTML标签,保留纯文本
  2675. // 确保所有editable-highlight元素都有正确的样式
  2676. const highlights = inputElement.querySelectorAll('.editable-highlight');
  2677. highlights.forEach(highlight => {
  2678. highlight.style.backgroundColor = '#3E7BFA10';
  2679. highlight.style.color = '#3E7BFA';
  2680. highlight.style.padding = '4px 8px';
  2681. highlight.style.borderRadius = '6px';
  2682. highlight.style.fontWeight = '500';
  2683. highlight.style.cursor = 'text';
  2684. highlight.style.border = '1px solid transparent';
  2685. highlight.style.display = 'inline-block';
  2686. highlight.style.minWidth = '20px';
  2687. });
  2688. inputElement.focus();
  2689. // 将光标移动到末尾
  2690. const range = document.createRange();
  2691. const selection = window.getSelection();
  2692. range.selectNodeContents(inputElement);
  2693. range.collapse(false);
  2694. selection.removeAllRanges();
  2695. selection.addRange(range);
  2696. console.log('模板已应用,templateContent更新为:', templateContent.value);
  2697. }
  2698. };
  2699. // 当前选中的文档信息
  2700. const selectedDocument = ref(null);
  2701. // 切换文档预览状态
  2702. const toggleDocumentPreview = (documentInfo) => {
  2703. // 如果点击的是当前已选中的文档,则关闭预览
  2704. if (selectedDocument.value && selectedDocument.value === documentInfo) {
  2705. showDocumentPreview.value = false;
  2706. selectedDocument.value = null;
  2707. } else {
  2708. // 否则显示新选中的文档
  2709. selectedDocument.value = documentInfo;
  2710. showDocumentPreview.value = true;
  2711. }
  2712. console.log("切换文档预览状态:", showDocumentPreview.value, "选中文档:", selectedDocument.value);
  2713. };
  2714. // 关闭文档预览
  2715. const closeDocumentPreview = () => {
  2716. showDocumentPreview.value = false;
  2717. selectedDocument.value = null;
  2718. console.log("关闭文档预览");
  2719. };
  2720. // 发送AI写作请求
  2721. const sendAIWritingRequest = async () => {
  2722. if (!hasInputContent.value) {
  2723. console.log("请输入内容");
  2724. return;
  2725. }
  2726. // 保存文件引用,因为后面需要传递给AI
  2727. const currentFile = selectedFile.value;
  2728. // 直接进入富文本编辑器并显示loading
  2729. currentView.value = 'editor';
  2730. isGenerating.value = true;
  2731. // 重置文档预览状态,确保界面恢复全屏
  2732. showDocumentPreview.value = false;
  2733. selectedDocument.value = null;
  2734. // 注意:不要在这里清空文件,因为后面创建消息时还需要使用
  2735. // 如果是新对话,清除所有历史记录的选中状态
  2736. if (historyData.value.length === 0 || !historyData.value.some(item => item.isActive)) {
  2737. historyData.value.forEach((item) => {
  2738. item.isActive = false;
  2739. });
  2740. console.log('新对话开始,清除所有历史记录的选中状态');
  2741. }
  2742. // 创建临时的历史记录项用于显示用户消息
  2743. const tempHistoryItem = {
  2744. id: Date.now(),
  2745. title: generateTitleFromContent(fullInputText.value),
  2746. time: new Date().toLocaleString('zh-CN', {
  2747. hour: '2-digit',
  2748. minute: '2-digit'
  2749. }),
  2750. isActive: false,
  2751. hasDocument: false,
  2752. documentContent: null,
  2753. aiResponse: "",
  2754. userMessage: fullInputText.value,
  2755. file: currentFile, // 使用保存的文件引用
  2756. messages: [
  2757. {
  2758. type: 'user',
  2759. content: fullInputText.value,
  2760. file: currentFile, // 使用保存的文件引用
  2761. time: new Date().toLocaleString('zh-CN', {
  2762. hour: '2-digit',
  2763. minute: '2-digit'
  2764. }),
  2765. id: Date.now(),
  2766. isFromBackend: false // 标记这是新创建的消息
  2767. }
  2768. ]
  2769. };
  2770. console.log("创建临时历史记录项,文件信息:", currentFile);
  2771. // 设置选中的历史记录项,这样用户消息就能显示出来
  2772. selectedHistoryItem.value = tempHistoryItem;
  2773. // 现在可以清空选中的文件了,因为已经保存到消息中
  2774. if (selectedFile.value) {
  2775. removeSelectedFile();
  2776. }
  2777. console.log("发送AI写作请求:");
  2778. console.log("完整文本:", fullInputText.value);
  2779. console.log("目的:", purposeText.value);
  2780. console.log("内容:", contentText.value);
  2781. console.log("额外:", templateContent.value);
  2782. // 在详情页中调用AI
  2783. await callAIInDetail(tempHistoryItem, null, fullInputText.value, currentFile);
  2784. };
  2785. // 智能提示词生成
  2786. const generateSmartPrompt = () => {
  2787. // 不做意图判断,让AI自己判断用户需求,但要求按照固定格式
  2788. return `请根据用户的需求进行回复。
  2789. 如果用户需要文档,请严格按照以下格式回复:
  2790. <OPENING_START>
  2791. 以下是为您准备的文档,包含相关内容:
  2792. </OPENING_END>
  2793. <DOCUMENT_START>
  2794. [在这里生成完整的Word文档内容,必须包含:
  2795. 1. 文档标题(使用#标记)
  2796. 2. 多个章节(使用##标记)
  2797. 3. 详细内容(使用Markdown格式,支持大小标题、换行、列表、加粗、斜体等富文本效果)
  2798. 4. 确保内容完整,不要中途停止]
  2799. </DOCUMENT_END>
  2800. <CLOSING_START>
  2801. 以上文档采用专业的格式编写,符合办公文档要求。如需调整内容或格式,请告诉我具体需求。
  2802. </CLOSING_END>
  2803. 如果是普通问题,请直接回答,不要使用上述格式。
  2804. 重要提醒:
  2805. 1. 如果生成文档,必须包含三个标签区域:<OPENING_START>开头文本</OPENING_END>、<DOCUMENT_START>文档内容</DOCUMENT_END>、<CLOSING_START>结尾文本</CLOSING_END>
  2806. 2. 确保每个区域都完整,特别是结尾部分不能缺失
  2807. 3. 标签必须严格按照上述格式,不能有任何变化
  2808. 4. 文档内容中不要使用emoji表情符号
  2809. 5. 如果用户明确要求生成文档、报告、通知、方案等办公文档,必须使用上述格式
  2810. 6. 标签名称区分大小写,必须完全匹配
  2811. 示例正确格式:
  2812. <OPENING_START>
  2813. 以下是为您准备的文档,包含相关内容:
  2814. </OPENING_END>
  2815. <DOCUMENT_START>
  2816. # 文档标题
  2817. ## 第一章 概述
  2818. 详细内容...
  2819. ## 第二章 具体内容
  2820. 详细内容...
  2821. </DOCUMENT_END>
  2822. <CLOSING_START>
  2823. 以上文档采用专业的格式编写,符合办公文档要求。如需调整内容或格式,请告诉我具体需求。
  2824. </CLOSING_END>`;
  2825. };
  2826. // 处理模板输入框的input事件
  2827. const handleTemplateInput = (event) => {
  2828. // 清除之前的定时器
  2829. if (debounceTimer) {
  2830. clearTimeout(debounceTimer);
  2831. }
  2832. // 设置防抖延迟
  2833. debounceTimer = setTimeout(async () => {
  2834. // 使用nextTick确保DOM更新完成
  2835. await nextTick();
  2836. // 获取可编辑区域的纯文本内容,不包含HTML标签
  2837. const text = event.target.innerText || event.target.textContent || '';
  2838. // 更新模板内容
  2839. templateContent.value = text;
  2840. // 如果文本为空,确保光标在开头
  2841. if (!text.trim()) {
  2842. await nextTick();
  2843. // 将光标移动到开头
  2844. const selection = window.getSelection();
  2845. const range = document.createRange();
  2846. // 确保有子节点
  2847. if (event.target.firstChild) {
  2848. range.setStart(event.target.firstChild, 0);
  2849. } else {
  2850. // 如果没有子节点,直接设置到容器
  2851. range.setStart(event.target, 0);
  2852. }
  2853. range.collapse(true);
  2854. selection.removeAllRanges();
  2855. selection.addRange(range);
  2856. // 聚焦到输入框
  2857. event.target.focus();
  2858. }
  2859. }, 200); // 防抖延迟200ms
  2860. };
  2861. // 处理复制事件
  2862. const handleCopy = (event) => {
  2863. // 获取复制的内容
  2864. const copiedText = event.target.innerText || event.target.textContent;
  2865. // 将复制的内容设置到剪贴板
  2866. event.clipboardData.setData('text/plain', copiedText);
  2867. // 阻止默认的浏览器复制行为
  2868. event.preventDefault();
  2869. console.log("复制成功:", copiedText);
  2870. };
  2871. // 文件处理工具函数
  2872. const validateFile = (file) => {
  2873. // 检查文件大小
  2874. if (file.size > fileConfig.maxSize) {
  2875. throw new Error('文件大小不能超过20MB')
  2876. }
  2877. // 检查文件类型
  2878. const fileExtension = '.' + file.name.split('.').pop().toLowerCase()
  2879. if (!fileConfig.allowedTypes.includes(fileExtension)) {
  2880. throw new Error('只支持.docx格式的Word文档。如果是.doc格式,请先另存为.docx格式。')
  2881. }
  2882. return fileExtension
  2883. }
  2884. // 读取Word文件内容
  2885. const readWordFile = async (file) => {
  2886. try {
  2887. console.log('开始读取Word文件:', file.name, '文件大小:', file.size)
  2888. // 检查文件是否为空
  2889. if (file.size === 0) {
  2890. throw new Error('Word文件为空')
  2891. }
  2892. // 使用mammoth.js库读取Word文档
  2893. console.log('正在导入mammoth库...')
  2894. const mammoth = await import('mammoth')
  2895. console.log('mammoth库导入成功')
  2896. // 将文件转换为ArrayBuffer
  2897. const arrayBuffer = await file.arrayBuffer()
  2898. console.log('文件转换为ArrayBuffer成功,大小:', arrayBuffer.byteLength)
  2899. // 提取文本内容
  2900. console.log('开始提取文本内容...')
  2901. const result = await mammoth.extractRawText({ arrayBuffer })
  2902. console.log('Word文件读取完成,内容长度:', result.value.length)
  2903. return result.value
  2904. } catch (error) {
  2905. console.error('Word文件读取失败,详细错误:', error)
  2906. console.error('错误堆栈:', error.stack)
  2907. // 提供更具体的错误信息
  2908. if (error.message.includes('Invalid file format')) {
  2909. throw new Error('Word文件格式无效或已损坏')
  2910. } else if (error.message.includes('File is empty')) {
  2911. throw new Error('Word文件为空')
  2912. } else {
  2913. throw new Error(`Word文件读取失败: ${error.message}`)
  2914. }
  2915. }
  2916. }
  2917. // 处理文件标签格式的回显
  2918. const processFileDisplay = (text, file) => {
  2919. if (!file) {
  2920. // 如果没有文件对象,尝试从文本中提取文件信息
  2921. return processFileDisplayFromText(text)
  2922. }
  2923. // 查找文件标签并替换为显示格式
  2924. const fileDisplay = `
  2925. 📄 文件信息:
  2926. 文件名:${file.name}
  2927. 文件大小:${formatFileSize(file.size)}
  2928. 文件类型:${file.type}
  2929. 📝 文件内容:
  2930. ${file.content}
  2931. ---
  2932. `
  2933. // 替换文件标签为显示格式
  2934. let processedText = text
  2935. .replace(/<word>.*?<\/word>/gs, fileDisplay)
  2936. .replace(/<filename>.*?<\/filename>/g, '')
  2937. .replace(/<filesize>.*?<\/filesize>/g, '')
  2938. return processedText
  2939. }
  2940. // 从文本中提取文件信息并转换为显示格式
  2941. const processFileDisplayFromText = (text) => {
  2942. // 提取文件名
  2943. const filenameMatch = text.match(/<filename>(.*?)<\/filename>/)
  2944. const filename = filenameMatch ? filenameMatch[1] : '未知文件'
  2945. // 提取文件大小
  2946. const filesizeMatch = text.match(/<filesize>(.*?)<\/filesize>/)
  2947. const filesize = filesizeMatch ? parseInt(filesizeMatch[1]) : 0
  2948. // 提取文件内容
  2949. const wordMatch = text.match(/<word>(.*?)<\/word>/s)
  2950. const fileContent = wordMatch ? wordMatch[1].trim() : '无内容'
  2951. // 创建文件显示格式
  2952. const fileDisplay = `
  2953. 📄 文件信息:
  2954. 文件名:${filename}
  2955. 文件大小:${formatFileSize(filesize)}
  2956. 文件类型:${filename.endsWith('.docx') ? '.docx' : filename.endsWith('.doc') ? '.doc' : '未知'}
  2957. 📝 文件内容:
  2958. ${fileContent}
  2959. ---
  2960. `
  2961. // 替换文件标签为显示格式
  2962. let processedText = text
  2963. .replace(/<word>.*?<\/word>/gs, fileDisplay)
  2964. .replace(/<filename>.*?<\/filename>/g, '')
  2965. .replace(/<filesize>.*?<\/filesize>/g, '')
  2966. return processedText
  2967. }
  2968. // 文件上传相关方法
  2969. const triggerFileUpload = () => {
  2970. if (selectedFile.value) {
  2971. ElMessage.warning('只能上传一个文件,请先删除当前文件');
  2972. return;
  2973. }
  2974. fileInput.value?.click();
  2975. };
  2976. const handleFileSelect = async (event) => {
  2977. const file = event.target.files[0];
  2978. if (!file) return;
  2979. try {
  2980. // 验证文件
  2981. const fileExtension = validateFile(file)
  2982. isUploadingFile.value = true;
  2983. console.log('开始读取文件内容:', file.name);
  2984. // 只处理Word文档
  2985. const extractedContent = await readWordFile(file)
  2986. // 创建文件信息对象
  2987. selectedFile.value = {
  2988. file,
  2989. name: file.name,
  2990. size: file.size,
  2991. type: fileExtension,
  2992. icon: getFileIcon(fileExtension),
  2993. content: extractedContent // 存储提取的内容
  2994. }
  2995. // 显示提取的内容长度
  2996. const contentLength = extractedContent.length
  2997. console.log('文件内容提取完成,字符数:', contentLength)
  2998. ElMessage.success(`文件读取成功`)
  2999. } catch (error) {
  3000. console.error('文件读取失败:', error)
  3001. ElMessage.error(error.message || '文件读取失败,请重试')
  3002. } finally {
  3003. isUploadingFile.value = false;
  3004. event.target.value = '';
  3005. }
  3006. };
  3007. const removeSelectedFile = () => {
  3008. if (selectedFile.value) {
  3009. selectedFile.value = null;
  3010. }
  3011. };
  3012. // 获取文件图标
  3013. const getFileIcon = (fileType) => {
  3014. switch (fileType) {
  3015. case '.doc':
  3016. case '.docx':
  3017. return wordDocIcon;
  3018. default:
  3019. return '📎';
  3020. }
  3021. };
  3022. // 语音输入相关方法
  3023. const handleVoiceClick = () => {
  3024. console.log('点击语音按钮');
  3025. if (isListening.value) {
  3026. // 如果正在录音,则停止
  3027. stopVoiceInput();
  3028. } else {
  3029. // 开始语音输入
  3030. startVoiceInput();
  3031. }
  3032. };
  3033. const startVoiceInput = () => {
  3034. console.log('开始语音输入');
  3035. // 开始语音识别
  3036. const success = startListening();
  3037. if (!success) {
  3038. ElMessage.error('语音识别启动失败,请检查麦克风权限');
  3039. }
  3040. };
  3041. const stopVoiceInput = () => {
  3042. console.log('停止语音输入');
  3043. stopListening();
  3044. // 语音识别完成后,将结果填入输入框
  3045. if (transcript.value.trim()) {
  3046. // 根据当前视图决定填入哪个输入框
  3047. if (currentView.value === 'detail') {
  3048. // 如果在详情页,填入详情页输入框
  3049. detailInputText.value = transcript.value;
  3050. } else {
  3051. // 如果在主页面,填入主页面输入框
  3052. const inputElement = document.querySelector('.template-input-container');
  3053. if (inputElement) {
  3054. inputElement.textContent = transcript.value;
  3055. templateContent.value = transcript.value;
  3056. }
  3057. }
  3058. }
  3059. };
  3060. // 详情页输入处理方法
  3061. const handleDetailInput = (event) => {
  3062. // 清除之前的防抖定时器
  3063. if (detailInputDebounceTimer) {
  3064. clearTimeout(detailInputDebounceTimer);
  3065. }
  3066. // 设置防抖延迟
  3067. detailInputDebounceTimer = setTimeout(() => {
  3068. const currentValue = event.target.value;
  3069. // 检查是否有重复字符(连续超过3个相同字符)
  3070. const duplicatePattern = /(.)\1{3,}/g;
  3071. if (duplicatePattern.test(currentValue)) {
  3072. // 移除重复字符,只保留最多3个连续相同字符
  3073. const cleanedValue = currentValue.replace(duplicatePattern, (match, char) => char.repeat(3));
  3074. detailInputText.value = cleanedValue;
  3075. ElMessage.warning('检测到重复字符,已自动清理');
  3076. return;
  3077. }
  3078. // 长度限制
  3079. if (currentValue.length > 2000) {
  3080. detailInputText.value = currentValue.substring(0, 2000);
  3081. ElMessage.warning('消息长度不能超过2000字');
  3082. }
  3083. }, 100); // 防抖延迟100ms
  3084. };
  3085. // 复制功能
  3086. const copyToClipboard = async (text) => {
  3087. try {
  3088. await navigator.clipboard.writeText(text);
  3089. ElMessage.success('复制成功');
  3090. } catch (err) {
  3091. // 降级方案:使用传统复制方法
  3092. const textArea = document.createElement('textarea');
  3093. textArea.value = text;
  3094. document.body.appendChild(textArea);
  3095. textArea.select();
  3096. document.execCommand('copy');
  3097. document.body.removeChild(textArea);
  3098. ElMessage.success('复制成功');
  3099. }
  3100. };
  3101. // 复制文档内容
  3102. const copyDocumentContent = () => {
  3103. // 优先从documentContent获取,如果没有则从AI消息的parsedContent获取
  3104. let documentContent = selectedHistoryItem.value?.documentContent;
  3105. if (!documentContent) {
  3106. // 尝试从AI消息中获取文档内容
  3107. const aiMessage = selectedHistoryItem.value?.messages?.find(msg => msg.type === 'ai' && msg.parsedContent?.hasDocument);
  3108. if (aiMessage && aiMessage.parsedContent) {
  3109. documentContent = aiMessage.parsedContent.documentContent;
  3110. }
  3111. }
  3112. if (!documentContent) {
  3113. ElMessage.warning('没有可复制的文档内容');
  3114. return;
  3115. }
  3116. try {
  3117. // 构建完整的文档内容
  3118. let fullContent = '';
  3119. // 添加标题
  3120. if (documentContent.title) {
  3121. fullContent += `${documentContent.title}\n\n`;
  3122. }
  3123. // 添加各个章节内容
  3124. if (documentContent.sections) {
  3125. documentContent.sections.forEach((section, index) => {
  3126. fullContent += `${section.title}\n`;
  3127. // 清理HTML标签,只保留纯文本
  3128. const cleanContent = section.content.replace(/<[^>]*>/g, '');
  3129. fullContent += `${cleanContent}\n\n`;
  3130. });
  3131. }
  3132. // 去除markdown格式符号
  3133. fullContent = removeMarkdownFormatting(fullContent);
  3134. // 复制到剪贴板
  3135. copyToClipboard(fullContent.trim());
  3136. } catch (error) {
  3137. console.error('复制文档内容失败:', error);
  3138. ElMessage.error('复制失败,请重试');
  3139. }
  3140. };
  3141. // 下载文档为Word格式(使用改进的HTML方法)
  3142. const downloadDocumentAsWord = async () => {
  3143. // 优先从documentContent获取,如果没有则从AI消息的parsedContent获取
  3144. let documentContent = selectedHistoryItem.value?.documentContent;
  3145. if (!documentContent) {
  3146. // 尝试从AI消息中获取文档内容
  3147. const aiMessage = selectedHistoryItem.value?.messages?.find(msg => msg.type === 'ai' && msg.parsedContent?.hasDocument);
  3148. if (aiMessage && aiMessage.parsedContent) {
  3149. documentContent = aiMessage.parsedContent.documentContent;
  3150. }
  3151. }
  3152. if (!documentContent) {
  3153. ElMessage.warning('没有可下载的文档内容');
  3154. return;
  3155. }
  3156. try {
  3157. // 创建改进的HTML格式Word文档
  3158. const wordContent = createImprovedWordContent(documentContent);
  3159. // 创建Blob对象 - 使用Word兼容的MIME类型
  3160. const blob = new Blob([wordContent], {
  3161. type: 'application/msword'
  3162. });
  3163. // 使用file-saver下载
  3164. const { saveAs } = await import('file-saver');
  3165. const fileName = documentContent.title || 'AI生成的文档';
  3166. saveAs(blob, `${fileName}.doc`);
  3167. ElMessage.success('下载成功');
  3168. } catch (error) {
  3169. console.error('下载文档失败:', error);
  3170. ElMessage.error('下载失败,请重试');
  3171. }
  3172. };
  3173. // 创建改进的HTML格式Word文档内容
  3174. const createImprovedWordContent = (documentContent) => {
  3175. // 创建HTML格式的文档内容,兼容Microsoft Office Word
  3176. let htmlContent = `<!DOCTYPE html>
  3177. <html xmlns:o="urn:schemas-microsoft-com:office:office"
  3178. xmlns:w="urn:schemas-microsoft-com:office:word"
  3179. xmlns="http://www.w3.org/TR/REC-html40">
  3180. <head>
  3181. <meta charset="utf-8">
  3182. <meta name="ProgId" content="Word.Document">
  3183. <meta name="Generator" content="Microsoft Word 15">
  3184. <meta name="Originator" content="Microsoft Word 15">
  3185. <title>${documentContent.title || 'AI生成的文档'}</title>
  3186. <!--[if gte mso 9]>
  3187. <xml>
  3188. <w:WordDocument>
  3189. <w:View>Print</w:View>
  3190. <w:Zoom>100</w:Zoom>
  3191. <w:DoNotOptimizeForBrowser/>
  3192. <w:ValidateAgainstSchemas/>
  3193. <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  3194. <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  3195. <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  3196. <w:Compatibility>
  3197. <w:BreakWrappedTables/>
  3198. <w:SnapToGridInCell/>
  3199. <w:WrapTextWithPunct/>
  3200. <w:UseAsianBreakRules/>
  3201. <w:DontGrowAutofit/>
  3202. </w:Compatibility>
  3203. </w:WordDocument>
  3204. </xml>
  3205. <![endif]-->
  3206. <style>
  3207. @page {
  3208. size: 21cm 29.7cm;
  3209. margin: 2.5cm 2cm 2.5cm 2cm;
  3210. }
  3211. body {
  3212. font-family: "Microsoft YaHei", "宋体", Arial, sans-serif;
  3213. font-size: 14px;
  3214. line-height: 1.6;
  3215. margin: 24px;
  3216. color: #000;
  3217. }
  3218. .header {
  3219. text-align: center;
  3220. margin-bottom: 1.5cm;
  3221. page-break-after: avoid;
  3222. }
  3223. .doc-title {
  3224. font-size: 18pt;
  3225. font-weight: bold;
  3226. margin-bottom: 0.8cm;
  3227. color: #000;
  3228. }
  3229. .section {
  3230. margin-bottom: 1rem;
  3231. page-break-inside: avoid;
  3232. }
  3233. .section-title {
  3234. font-size: 14pt;
  3235. font-weight: bold;
  3236. margin-bottom: 0.5rem;
  3237. color: #000;
  3238. page-break-after: avoid;
  3239. }
  3240. .content {
  3241. margin-bottom: 0.5rem;
  3242. text-align: justify;
  3243. }
  3244. h1 {
  3245. font-size: 16pt;
  3246. font-weight: bold;
  3247. margin: 1rem 0 0.5rem 0;
  3248. color: #000;
  3249. page-break-after: avoid;
  3250. letter-spacing: normal;
  3251. word-spacing: normal;
  3252. }
  3253. h2 {
  3254. font-size: 14pt;
  3255. font-weight: bold;
  3256. margin: 0.8rem 0 0.4rem 0;
  3257. color: #000;
  3258. page-break-after: avoid;
  3259. letter-spacing: normal;
  3260. word-spacing: normal;
  3261. }
  3262. h3 {
  3263. font-size: 12pt;
  3264. font-weight: bold;
  3265. margin: 0.6rem 0 0.3rem 0;
  3266. color: #000;
  3267. page-break-after: avoid;
  3268. letter-spacing: normal;
  3269. word-spacing: normal;
  3270. }
  3271. h4 {
  3272. font-size: 12pt;
  3273. font-weight: bold;
  3274. margin: 0.5rem 0 0.3rem 0;
  3275. color: #000;
  3276. page-break-after: avoid;
  3277. letter-spacing: normal;
  3278. word-spacing: normal;
  3279. }
  3280. strong { font-weight: bold; }
  3281. em { font-style: italic; }
  3282. p {
  3283. margin: 0.5rem 0;
  3284. text-align: justify;
  3285. orphans: 2;
  3286. widows: 2;
  3287. letter-spacing: normal;
  3288. word-spacing: normal;
  3289. }
  3290. .list-item {
  3291. margin: 0.25rem 0;
  3292. text-align: justify;
  3293. }
  3294. table {
  3295. border-collapse: collapse;
  3296. width: 100%;
  3297. margin: 1rem 0;
  3298. page-break-inside: avoid;
  3299. }
  3300. td, th {
  3301. border: 1px solid #000;
  3302. padding: 0.3cm;
  3303. text-align: left;
  3304. font-size: 11pt;
  3305. }
  3306. th {
  3307. background-color: #f0f0f0;
  3308. font-weight: bold;
  3309. }
  3310. ul, ol {
  3311. margin: 0.5rem 0;
  3312. padding-left: 1cm;
  3313. }
  3314. li {
  3315. margin: 0.25rem 0;
  3316. text-align: justify;
  3317. letter-spacing: normal;
  3318. word-spacing: normal;
  3319. }
  3320. </style>
  3321. </head>
  3322. <body>
  3323. <div class='header'>
  3324. <div class='doc-title'>${documentContent.title || 'AI生成的文档'}</div>
  3325. </div>
  3326. `;
  3327. // 添加各个章节内容
  3328. if (documentContent.sections) {
  3329. documentContent.sections.forEach((section, index) => {
  3330. htmlContent += `
  3331. <div class='section'>
  3332. <div class='section-title'>${section.title}</div>
  3333. <div class='content'>
  3334. ${formatContentForImprovedWord(section.content)}
  3335. </div>
  3336. </div>
  3337. `;
  3338. });
  3339. }
  3340. htmlContent += '</body></html>';
  3341. return htmlContent;
  3342. };
  3343. // 格式化内容为改进的Word格式
  3344. const formatContentForImprovedWord = (content) => {
  3345. if (!content) return '';
  3346. let formattedContent = content;
  3347. // 后端返回的是HTML格式,无需Markdown转换
  3348. // 后端返回的是HTML格式,无需Markdown转换
  3349. // 将连续的列表项包装在ul或ol标签中
  3350. formattedContent = formattedContent.replace(/(<li>.*<\/li>)/gs, (match) => {
  3351. const hasNumbers = /^\d+\./.test(content);
  3352. const listTag = hasNumbers ? 'ol' : 'ul';
  3353. return `<${listTag}>${match}</${listTag}>`;
  3354. });
  3355. // 处理段落
  3356. formattedContent = formattedContent.replace(/\n\n/g, '</p><p>');
  3357. formattedContent = formattedContent.replace(/\n/g, '<br>');
  3358. // 包装在段落标签中
  3359. if (formattedContent.trim() && !formattedContent.startsWith('<')) {
  3360. formattedContent = `<p>${formattedContent}</p>`;
  3361. }
  3362. return formattedContent;
  3363. };
  3364. // 创建docx文档内容
  3365. const createDocxContent = async (documentContent) => {
  3366. const { Paragraph, TextRun, HeadingLevel, AlignmentType } = await import('docx');
  3367. const children = [];
  3368. // 添加文档标题
  3369. if (documentContent.title) {
  3370. children.push(
  3371. new Paragraph({
  3372. children: [
  3373. new TextRun({
  3374. text: documentContent.title,
  3375. bold: true,
  3376. size: 32, // 18pt
  3377. }),
  3378. ],
  3379. alignment: AlignmentType.CENTER,
  3380. spacing: {
  3381. after: 400, // 0.5cm
  3382. },
  3383. })
  3384. );
  3385. }
  3386. // 添加各个章节
  3387. if (documentContent.sections) {
  3388. for (let index = 0; index < documentContent.sections.length; index++) {
  3389. const section = documentContent.sections[index];
  3390. // 添加章节标题
  3391. children.push(
  3392. new Paragraph({
  3393. children: [
  3394. new TextRun({
  3395. text: section.title,
  3396. bold: true,
  3397. size: 28, // 14pt
  3398. }),
  3399. ],
  3400. heading: HeadingLevel.HEADING_2,
  3401. spacing: {
  3402. before: 400, // 0.5cm
  3403. after: 200, // 0.25cm
  3404. },
  3405. })
  3406. );
  3407. // 添加章节内容
  3408. if (section.content) {
  3409. const formattedContent = await formatContentForDocx(section.content);
  3410. children.push(...formattedContent);
  3411. }
  3412. }
  3413. }
  3414. return children;
  3415. };
  3416. // 格式化内容为docx格式
  3417. const formatContentForDocx = async (content) => {
  3418. const { Paragraph, TextRun, HeadingLevel } = await import('docx');
  3419. if (!content) return [];
  3420. const children = [];
  3421. const lines = content.split('\n');
  3422. for (let i = 0; i < lines.length; i++) {
  3423. const line = lines[i].trim();
  3424. if (!line) {
  3425. // 空行
  3426. children.push(
  3427. new Paragraph({
  3428. children: [new TextRun({ text: '' })],
  3429. spacing: { after: 200 },
  3430. })
  3431. );
  3432. continue;
  3433. }
  3434. // 检查是否是标题
  3435. if (line.startsWith('# ')) {
  3436. children.push(
  3437. new Paragraph({
  3438. children: [
  3439. new TextRun({
  3440. text: line.substring(2),
  3441. bold: true,
  3442. size: 32,
  3443. }),
  3444. ],
  3445. heading: HeadingLevel.HEADING_1,
  3446. spacing: { before: 400, after: 200 },
  3447. })
  3448. );
  3449. } else if (line.startsWith('## ')) {
  3450. children.push(
  3451. new Paragraph({
  3452. children: [
  3453. new TextRun({
  3454. text: line.substring(3),
  3455. bold: true,
  3456. size: 28,
  3457. }),
  3458. ],
  3459. heading: HeadingLevel.HEADING_2,
  3460. spacing: { before: 300, after: 200 },
  3461. })
  3462. );
  3463. } else if (line.startsWith('### ')) {
  3464. children.push(
  3465. new Paragraph({
  3466. children: [
  3467. new TextRun({
  3468. text: line.substring(4),
  3469. bold: true,
  3470. size: 24,
  3471. }),
  3472. ],
  3473. heading: HeadingLevel.HEADING_3,
  3474. spacing: { before: 200, after: 200 },
  3475. })
  3476. );
  3477. } else if (line.startsWith('- ') || /^\d+\. /.test(line)) {
  3478. // 列表项
  3479. children.push(
  3480. new Paragraph({
  3481. children: [
  3482. new TextRun({
  3483. text: line,
  3484. size: 24,
  3485. }),
  3486. ],
  3487. spacing: { before: 100, after: 100 },
  3488. })
  3489. );
  3490. } else {
  3491. // 普通段落
  3492. const textRuns = parseTextRunsSync(line);
  3493. children.push(
  3494. new Paragraph({
  3495. children: textRuns,
  3496. spacing: { before: 200, after: 200 },
  3497. })
  3498. );
  3499. }
  3500. }
  3501. return children;
  3502. };
  3503. // 解析文本运行(处理加粗、斜体等)- 同步版本
  3504. const parseTextRunsSync = (text) => {
  3505. // 简化版本,直接返回普通文本
  3506. return [{
  3507. text: text.replace(/\*\*(.*?)\*\*/g, '$1'), // 移除加粗标记
  3508. size: 24,
  3509. }];
  3510. };
  3511. // 创建Word文档内容(HTML格式)
  3512. const createWordContent = (documentContent) => {
  3513. // 创建HTML格式的文档内容,符合A4纸张格式
  3514. let htmlContent = `
  3515. <html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>
  3516. <head>
  3517. <meta charset='utf-8'>
  3518. <title>${documentContent.title || 'AI生成的文档'}</title>
  3519. <!--[if gte mso 9]>
  3520. <xml>
  3521. <w:WordDocument>
  3522. <w:View>Print</w:View>
  3523. <w:Zoom>90</w:Zoom>
  3524. <w:DoNotOptimizeForBrowser/>
  3525. </w:WordDocument>
  3526. </xml>
  3527. <![endif]-->
  3528. <style>
  3529. @page {
  3530. size: 21cm 29.7cm;
  3531. margin: 2.5cm 2cm 2.5cm 2cm;
  3532. }
  3533. body {
  3534. font-family: "Microsoft YaHei", "宋体", Arial, sans-serif;
  3535. font-size: 14px;
  3536. line-height: 1.6;
  3537. margin: 24px;
  3538. color: #000;
  3539. }
  3540. .header {
  3541. text-align: center;
  3542. margin-bottom: 1.5cm;
  3543. page-break-after: avoid;
  3544. }
  3545. .doc-title {
  3546. font-size: 18pt;
  3547. font-weight: bold;
  3548. margin-bottom: 0.8cm;
  3549. color: #000;
  3550. }
  3551. .section {
  3552. margin-bottom: 1rem;
  3553. page-break-inside: avoid;
  3554. }
  3555. .section-title {
  3556. font-size: 14pt;
  3557. font-weight: bold;
  3558. margin-bottom: 0.5rem;
  3559. color: #000;
  3560. page-break-after: avoid;
  3561. }
  3562. .content {
  3563. margin-bottom: 0.5rem;
  3564. text-align: justify;
  3565. }
  3566. h1 {
  3567. font-size: 16pt;
  3568. font-weight: bold;
  3569. margin: 1rem 0 0.5rem 0;
  3570. color: #000;
  3571. page-break-after: avoid;
  3572. letter-spacing: normal;
  3573. word-spacing: normal;
  3574. }
  3575. h2 {
  3576. font-size: 14pt;
  3577. font-weight: bold;
  3578. margin: 0.8rem 0 0.4rem 0;
  3579. color: #000;
  3580. page-break-after: avoid;
  3581. letter-spacing: normal;
  3582. word-spacing: normal;
  3583. }
  3584. h3 {
  3585. font-size: 12pt;
  3586. font-weight: bold;
  3587. margin: 0.6rem 0 0.3rem 0;
  3588. color: #000;
  3589. page-break-after: avoid;
  3590. letter-spacing: normal;
  3591. word-spacing: normal;
  3592. }
  3593. h4 {
  3594. font-size: 12pt;
  3595. font-weight: bold;
  3596. margin: 0.5rem 0 0.3rem 0;
  3597. color: #000;
  3598. page-break-after: avoid;
  3599. letter-spacing: normal;
  3600. word-spacing: normal;
  3601. }
  3602. strong { font-weight: bold; }
  3603. em { font-style: italic; }
  3604. p {
  3605. margin: 0.5rem 0;
  3606. text-align: justify;
  3607. orphans: 2;
  3608. widows: 2;
  3609. letter-spacing: normal;
  3610. word-spacing: normal;
  3611. }
  3612. .list-item {
  3613. margin: 0.25rem 0;
  3614. text-align: justify;
  3615. }
  3616. table {
  3617. border-collapse: collapse;
  3618. width: 100%;
  3619. margin: 1rem 0;
  3620. page-break-inside: avoid;
  3621. }
  3622. td, th {
  3623. border: 1px solid #000;
  3624. padding: 0.3cm;
  3625. text-align: left;
  3626. font-size: 11pt;
  3627. }
  3628. th {
  3629. background-color: #f0f0f0;
  3630. font-weight: bold;
  3631. }
  3632. ul, ol {
  3633. margin: 0.5rem 0;
  3634. padding-left: 1cm;
  3635. }
  3636. li {
  3637. margin: 0.25rem 0;
  3638. text-align: justify;
  3639. letter-spacing: normal;
  3640. word-spacing: normal;
  3641. }
  3642. </style>
  3643. </head>
  3644. <body>
  3645. <div class='header'>
  3646. <div class='doc-title'>${documentContent.title || 'AI生成的文档'}</div>
  3647. </div>
  3648. `;
  3649. // 添加各个章节内容
  3650. if (documentContent.sections) {
  3651. documentContent.sections.forEach((section, index) => {
  3652. htmlContent += `
  3653. <div class='section'>
  3654. <div class='section-title'>${section.title}</div>
  3655. <div class='content'>
  3656. ${formatContentForWord(section.content)}
  3657. </div>
  3658. </div>
  3659. `;
  3660. });
  3661. }
  3662. htmlContent += '</body></html>';
  3663. return htmlContent;
  3664. };
  3665. // 格式化内容为Word格式(A4纸张优化)
  3666. const formatContentForWord = (content) => {
  3667. if (!content) return '';
  3668. let formattedContent = content;
  3669. // 后端返回的是HTML格式,无需Markdown转换
  3670. // 后端返回的是HTML格式,无需Markdown转换
  3671. // 将连续的列表项包装在ul或ol标签中
  3672. formattedContent = formattedContent.replace(/(<li>.*<\/li>)/gs, (match) => {
  3673. // 检查是否是有序列表(包含数字)
  3674. const hasNumbers = /^\d+\./.test(content);
  3675. const listTag = hasNumbers ? 'ol' : 'ul';
  3676. return `<${listTag}>${match}</${listTag}>`;
  3677. });
  3678. // 处理段落 - 将双换行符转换为段落
  3679. formattedContent = formattedContent.replace(/\n\n/g, '</p><p>');
  3680. // 处理单换行符
  3681. formattedContent = formattedContent.replace(/\n/g, '<br>');
  3682. // 包装在段落标签中
  3683. if (formattedContent.trim() && !formattedContent.startsWith('<')) {
  3684. formattedContent = `<p>${formattedContent}</p>`;
  3685. }
  3686. return formattedContent;
  3687. };
  3688. // 去除markdown格式符号的工具函数
  3689. const removeMarkdownFormatting = (text) => {
  3690. if (!text) return '';
  3691. return text
  3692. // 去除标题符号 (# ## ### #### ##### ######)
  3693. .replace(/^#{1,6}\s+/gm, '')
  3694. // 去除粗体符号 (**text** 或 __text__)
  3695. .replace(/\*\*(.*?)\*\*/g, '$1')
  3696. .replace(/__(.*?)__/g, '$1')
  3697. // 去除斜体符号 (*text* 或 _text_)
  3698. .replace(/\*(.*?)\*/g, '$1')
  3699. .replace(/_(.*?)_/g, '$1')
  3700. // 去除删除线符号 (~~text~~)
  3701. .replace(/~~(.*?)~~/g, '$1')
  3702. // 去除代码块符号 (```code```)
  3703. .replace(/```[\s\S]*?```/g, '')
  3704. // 去除行内代码符号 (`code`)
  3705. .replace(/`([^`]+)`/g, '$1')
  3706. // 去除链接符号 ([text](url))
  3707. .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
  3708. // 去除图片符号 (![alt](url))
  3709. .replace(/!\[([^\]]*)\]\([^)]+\)/g, '$1')
  3710. // 去除引用符号 (> text)
  3711. .replace(/^>\s*/gm, '')
  3712. // 去除列表符号 (- * + 或 1. 2. 3.)
  3713. .replace(/^[\s]*[-*+]\s+/gm, '')
  3714. .replace(/^[\s]*\d+\.\s+/gm, '')
  3715. // 去除表格符号 (| 分隔符)
  3716. .replace(/\|/g, ' ')
  3717. // 去除水平分割线 (--- 或 ***)
  3718. .replace(/^[-*]{3,}$/gm, '')
  3719. // 清理多余的空行
  3720. .replace(/\n\s*\n\s*\n/g, '\n\n')
  3721. .trim();
  3722. };
  3723. // 消息操作方法
  3724. const copyUserMessage = (message) => {
  3725. let textToCopy = message.content || '';
  3726. // 去除文件标签,只保留用户实际输入的内容
  3727. if (textToCopy.includes('<filename>') && textToCopy.includes('<filesize>')) {
  3728. // 提取用户实际输入的部分(在文件标签之后的内容)
  3729. const parts = textToCopy.split('</filesize>');
  3730. if (parts.length > 1) {
  3731. textToCopy = parts[1].trim();
  3732. } else {
  3733. // 如果没有找到结束标签,尝试其他方式提取
  3734. textToCopy = textToCopy.replace(/<word>.*?<\/word>/s, '').replace(/<filename>.*?<\/filename>/g, '').replace(/<filesize>.*?<\/filesize>/g, '').trim();
  3735. }
  3736. }
  3737. // 去除markdown格式符号
  3738. textToCopy = removeMarkdownFormatting(textToCopy);
  3739. copyToClipboard(textToCopy);
  3740. };
  3741. const copyAIMessage = (message) => {
  3742. let textToCopy = message.content || '';
  3743. // 过滤掉AI写作的内部标签
  3744. textToCopy = textToCopy
  3745. .replace(/<OPENING_START>/g, '')
  3746. .replace(/<\/OPENING_END>/g, '')
  3747. .replace(/<DOCUMENT_START>/g, '')
  3748. .replace(/<\/DOCUMENT_END>/g, '')
  3749. .replace(/<CLOSING_START>/g, '')
  3750. .replace(/<\/CLOSING_START>/g, '') // 处理可能的错误标签格式
  3751. .replace(/<\/CLOSING_END>/g, '')
  3752. .replace(/<\/DOCUMENT_START>/g, '') // 处理错误的</DOCUMENT_START>标签
  3753. .replace(/<CLOSING_END>/g, '') // 处理可能的错误标签格式
  3754. .trim();
  3755. // 去除markdown格式符号
  3756. textToCopy = removeMarkdownFormatting(textToCopy);
  3757. copyToClipboard(textToCopy);
  3758. };
  3759. const editUserMessage = (message) => {
  3760. console.log('编辑用户消息:', message.content);
  3761. detailInputText.value = message.content;
  3762. // 恢复文件信息
  3763. if (message.file) {
  3764. selectedFile.value = message.file;
  3765. console.log('恢复文件信息:', message.file.name);
  3766. }
  3767. // 聚焦到输入框
  3768. const inputElement = document.querySelector('.message-input');
  3769. if (inputElement) {
  3770. inputElement.focus();
  3771. inputElement.setSelectionRange(inputElement.value.length, inputElement.value.length);
  3772. }
  3773. };
  3774. const regenerateResponse = async (messageIndex) => {
  3775. console.log('重新生成回复,消息索引:', messageIndex);
  3776. // 找到对应的用户消息
  3777. if (messageIndex > 0) {
  3778. const userMessage = selectedHistoryItem.value.messages[messageIndex - 1];
  3779. if (userMessage && userMessage.type === 'user') {
  3780. console.log('重新发送用户消息:', userMessage.content);
  3781. // 恢复消息文本和文件信息
  3782. detailInputText.value = userMessage.content;
  3783. // 恢复文件信息
  3784. if (userMessage.file) {
  3785. selectedFile.value = userMessage.file;
  3786. console.log('重新生成时恢复文件信息:', userMessage.file.name);
  3787. }
  3788. await sendDetailMessage();
  3789. }
  3790. }
  3791. };
  3792. // 语音朗读相关方法
  3793. const handleVoiceRead = (message) => {
  3794. if (speakingMessageId.value === message.id) {
  3795. // 如果正在朗读这条消息,则停止
  3796. try { window.speechSynthesis && window.speechSynthesis.cancel(); } catch (e) {}
  3797. speakingMessageId.value = null;
  3798. } else {
  3799. // 如果朗读其他消息,先停止当前朗读
  3800. if (speakingMessageId.value) {
  3801. try { window.speechSynthesis && window.speechSynthesis.cancel(); } catch (e) {}
  3802. }
  3803. // 开始朗读新消息 - 使用过滤后的内容,移除内部标签但保留文档内容
  3804. let textToRead = '';
  3805. if (message.parsedContent) {
  3806. // 如果有解析后的内容,组合所有可见文本部分
  3807. const parts = [];
  3808. if (message.parsedContent.openingText) {
  3809. parts.push(filterInternalTags(message.parsedContent.openingText));
  3810. }
  3811. // 添加文档内容(如果有的话)
  3812. if (message.parsedContent.documentText) {
  3813. parts.push(filterInternalTags(message.parsedContent.documentText));
  3814. }
  3815. if (message.parsedContent.closingText) {
  3816. parts.push(filterInternalTags(message.parsedContent.closingText));
  3817. }
  3818. textToRead = parts.join(' ');
  3819. } else {
  3820. // 如果没有解析后的内容,直接过滤原始内容
  3821. textToRead = filterInternalTags(message.content || '');
  3822. }
  3823. // 进一步清理HTML标签和Markdown标签,确保只朗读纯文本
  3824. textToRead = textToRead
  3825. .replace(/<[^>]*>/g, '') // 移除HTML标签
  3826. .trim();
  3827. // 清理Markdown标签
  3828. textToRead = cleanMarkdownForSpeech(textToRead);
  3829. if (textToRead) {
  3830. // 创建自定义的语音合成实例,以便监听完成事件
  3831. const utterance = new SpeechSynthesisUtterance(textToRead);
  3832. utterance.lang = 'zh-CN';
  3833. utterance.rate = 0.9;
  3834. utterance.pitch = 1;
  3835. utterance.volume = 1;
  3836. // 监听语音合成完成事件
  3837. utterance.onend = () => {
  3838. speakingMessageId.value = null;
  3839. };
  3840. utterance.onerror = () => {
  3841. speakingMessageId.value = null;
  3842. };
  3843. // 开始朗读
  3844. window.speechSynthesis.speak(utterance);
  3845. speakingMessageId.value = message.id;
  3846. }
  3847. }
  3848. };
  3849. // 检查消息是否正在朗读
  3850. const isSpeaking = (messageId) => {
  3851. return speakingMessageId.value === messageId;
  3852. };
  3853. // 点赞和点踩功能
  3854. const handleThumbsUp = async (message) => {
  3855. console.log('点赞消息:', message.id);
  3856. // 如果已经点赞,则取消点赞
  3857. if (message.userFeedback === 'like') {
  3858. message.userFeedback = null;
  3859. } else {
  3860. // 设置点赞,取消点踩
  3861. message.userFeedback = 'like';
  3862. }
  3863. // 强制触发Vue响应式更新
  3864. selectedHistoryItem.value.messages = [...selectedHistoryItem.value.messages]
  3865. // 同步反馈到后端
  3866. await syncFeedbackToBackend(message);
  3867. };
  3868. const handleThumbsDown = async (message) => {
  3869. console.log('点踩消息:', message.id);
  3870. // 如果已经点踩,则取消点踩
  3871. if (message.userFeedback === 'dislike') {
  3872. message.userFeedback = null;
  3873. } else {
  3874. // 设置点踩,取消点赞
  3875. message.userFeedback = 'dislike';
  3876. }
  3877. // 强制触发Vue响应式更新
  3878. selectedHistoryItem.value.messages = [...selectedHistoryItem.value.messages]
  3879. // 同步反馈到后端
  3880. await syncFeedbackToBackend(message);
  3881. };
  3882. // 同步用户反馈到后端
  3883. const syncFeedbackToBackend = async (message) => {
  3884. try {
  3885. if (!message.rawData || !message.rawData.id) {
  3886. console.warn('消息缺少原始数据,无法同步反馈')
  3887. return
  3888. }
  3889. const feedback = convertFeedbackToBackend(message.userFeedback)
  3890. console.log('同步反馈到后端:', {
  3891. messageId: message.rawData.id,
  3892. feedback: feedback
  3893. })
  3894. // 调用后端点赞点踩接口
  3895. const response = await apis.likeAndDislike({
  3896. id: message.rawData.id,
  3897. user_feedback: feedback
  3898. })
  3899. if (response.statusCode === 200) {
  3900. console.log('反馈同步成功')
  3901. ElMessage.success('反馈提交成功')
  3902. } else {
  3903. console.error('反馈同步失败:', response.msg)
  3904. ElMessage.error('反馈提交失败,请稍后重试')
  3905. }
  3906. } catch (error) {
  3907. console.error('同步反馈失败:', error)
  3908. ElMessage.error('反馈同步失败,请稍后重试')
  3909. }
  3910. }
  3911. // 格式化文件大小
  3912. const formatFileSize = (bytes) => {
  3913. if (bytes === 0) return '0 B';
  3914. const k = 1024;
  3915. const sizes = ['B', 'KB', 'MB', 'GB'];
  3916. const i = Math.floor(Math.log(bytes) / Math.log(k));
  3917. return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
  3918. };
  3919. watch(transcript, (newVal) => {
  3920. if (!newVal || isListening.value) return
  3921. if (currentView.value === 'detail') {
  3922. detailInputText.value = newVal
  3923. } else {
  3924. const inputElement = document.querySelector('.template-input-container')
  3925. if (inputElement) {
  3926. inputElement.textContent = newVal
  3927. }
  3928. templateContent.value = newVal
  3929. }
  3930. })
  3931. // 监听语音识别错误
  3932. watch(speechError, (newVal) => {
  3933. if (newVal) {
  3934. console.error('语音识别错误:', newVal);
  3935. ElMessage.error(newVal);
  3936. }
  3937. });
  3938. // 组件挂载后初始化
  3939. onMounted(async () => {
  3940. await nextTick();
  3941. // 初始化输入框的默认模板内容
  3942. const inputElement = document.querySelector('.template-input-container');
  3943. if (inputElement) {
  3944. const defaultTemplate = "<span class=\"editable-highlight\" contenteditable=\"true\">总结主题:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">总结时间:</span>\n<span class=\"editable-highlight\" contenteditable=\"true\">主要内容:</span>\n\n请帮我生成一份正式的总结报告,要求格式规范、语言严谨,具体参考以上内容,按照标准工作总结格式生成全文,包含\"工作总结、问题不足、未来计划\"三部分的完整报告。";
  3945. inputElement.innerHTML = defaultTemplate;
  3946. templateContent.value = defaultTemplate.replace(/<[^>]*>/g, '');
  3947. // 为高亮元素添加样式
  3948. await nextTick();
  3949. const highlights = inputElement.querySelectorAll('.editable-highlight');
  3950. highlights.forEach(highlight => {
  3951. highlight.style.backgroundColor = '#3E7BFA10';
  3952. highlight.style.color = '#3E7BFA';
  3953. highlight.style.padding = '4px 8px';
  3954. highlight.style.borderRadius = '6px';
  3955. highlight.style.fontWeight = '500';
  3956. highlight.style.cursor = 'text';
  3957. highlight.style.border = '1px solid transparent';
  3958. highlight.style.display = 'inline-block';
  3959. highlight.style.minWidth = '20px';
  3960. });
  3961. }
  3962. // 获取历史记录列表
  3963. await getHistoryRecordList();
  3964. });
  3965. // 组件销毁前清理
  3966. onBeforeUnmount(() => {
  3967. // 停止当前朗读
  3968. if (speakingMessageId.value) {
  3969. try { window.speechSynthesis && window.speechSynthesis.cancel(); } catch (e) {}
  3970. speakingMessageId.value = null;
  3971. }
  3972. });
  3973. // 在详情页中调用AI
  3974. const callAIInDetail = async (historyItem, smartPrompt, currentUserMessage = null, file = null) => {
  3975. try {
  3976. // 设置生成状态
  3977. isGenerating.value = true;
  3978. // 构建发送给DeepSeek的消息
  3979. // 如果有当前用户消息,使用当前消息;否则使用历史记录中的第一条消息
  3980. const userMessageToSend = currentUserMessage || (historyItem ? historyItem.userMessage : '');
  3981. // 构建发送给AI的消息
  3982. let messageToSend = userMessageToSend;
  3983. // 如果有文件,使用标签格式
  3984. if (file && file.content) {
  3985. messageToSend = `<word>${file.content}</word><filename>${file.name}</filename><filesize>${file.size}</filesize>${userMessageToSend}`;
  3986. }
  3987. // 不再拼接提示词,直接使用用户消息
  3988. // 调用DeepSeek API
  3989. const response = await apis.sendDeepseekMessage({
  3990. // ===== 已删除:user_id - 后端从token解析 =====
  3991. ai_conversation_id: ai_conversation_id.value,
  3992. message: messageToSend,
  3993. business_type: 2 // AI写作类型
  3994. });
  3995. console.log('DeepSeek API响应:', response);
  3996. if (response.statusCode === 200) {
  3997. const aiReply = response.data.reply;
  3998. // 更新对话ID
  3999. ai_conversation_id.value = response.data.ai_conversation_id;
  4000. // 简化解析逻辑,不做复杂的段落分析
  4001. // 直接使用AI回复内容,无需解析
  4002. // 更新历史记录(如果存在)
  4003. if (historyItem) {
  4004. historyItem.aiResponse = aiReply;
  4005. historyItem.hasDocument = true; // 简化:直接标记为有文档
  4006. historyItem.documentContent = {
  4007. title: "AI生成的文档",
  4008. sections: [
  4009. {
  4010. title: "文档内容",
  4011. content: aiReply
  4012. }
  4013. ]
  4014. };
  4015. // 添加AI消息到对话历史
  4016. const aiMessage = {
  4017. type: 'ai',
  4018. content: aiReply,
  4019. time: new Date().toLocaleString('zh-CN', {
  4020. hour: '2-digit',
  4021. minute: '2-digit'
  4022. }),
  4023. parsedContent: {
  4024. hasDocument: true,
  4025. documentContent: {
  4026. title: "AI生成的文档",
  4027. sections: [
  4028. {
  4029. title: "文档内容",
  4030. content: aiReply
  4031. }
  4032. ]
  4033. },
  4034. openingText: "",
  4035. documentText: aiReply,
  4036. closingText: "",
  4037. documentTitle: "AI生成的文档"
  4038. },
  4039. id: response.data.ai_message_id || Date.now() + 1, // 优先使用后端返回的ai_message_id,否则使用前端生成的ID
  4040. userFeedback: null, // 用户反馈状态:null, 'like', 'dislike'
  4041. isFromBackend: false // 标记这是新创建的AI消息
  4042. };
  4043. historyItem.messages.push(aiMessage);
  4044. // 如果是临时历史记录项,更新selectedHistoryItem
  4045. if (selectedHistoryItem.value && selectedHistoryItem.value.id === historyItem.id) {
  4046. selectedHistoryItem.value = historyItem;
  4047. }
  4048. }
  4049. // 自动滚动到最新位置
  4050. scrollToBottom();
  4051. // AI回复完成后,获取最新的历史记录
  4052. await getHistoryRecordList();
  4053. // 如果是新对话,将最新的历史记录设为激活状态
  4054. if (ai_conversation_id.value > 0) {
  4055. historyData.value.forEach((item) => {
  4056. item.isActive = item.id === ai_conversation_id.value;
  4057. });
  4058. console.log('设置最新历史记录为激活状态,conversationId:', ai_conversation_id.value);
  4059. }
  4060. console.log("AI写作完成,准备进入富文本编辑器");
  4061. // 直接进入富文本编辑器,显示AI生成的内容
  4062. console.log('AI回复内容长度:', aiReply.length);
  4063. console.log('AI回复内容预览:', aiReply.substring(0, 200) + '...');
  4064. // 格式化内容为HTML
  4065. const formattedContent = formatContentForEditor(aiReply);
  4066. enterEditor(formattedContent);
  4067. } else {
  4068. console.error("DeepSeek API调用失败:", response);
  4069. alert("AI写作失败,请重试");
  4070. }
  4071. } catch (error) {
  4072. console.error("调用AI时出错:", error);
  4073. alert("调用AI失败,请检查网络连接");
  4074. } finally {
  4075. // 重置生成状态
  4076. isGenerating.value = false;
  4077. }
  4078. };
  4079. // 智能分析AI回复的段落结构
  4080. const parseAIResponse = (aiReply) => {
  4081. // 分析文档生成回复的结构 - 优先使用三个标签识别,兼容旧格式
  4082. let openingText = "";
  4083. let documentText = "";
  4084. let closingText = "";
  4085. let documentTitle = "AI生成的文档"; // 默认标题
  4086. // 优先查找三个标签格式
  4087. const openingStartTag = '<OPENING_START>';
  4088. const openingEndTag = '</OPENING_END>';
  4089. const docStartTag = '<DOCUMENT_START>';
  4090. const docEndTag = '</DOCUMENT_END>';
  4091. const closingStartTag = '<CLOSING_START>';
  4092. const closingEndTag = '</CLOSING_END>';
  4093. if (aiReply.includes(openingStartTag) && aiReply.includes(docStartTag) && aiReply.includes(closingStartTag)) {
  4094. // 使用三个标签格式
  4095. try {
  4096. console.log('检测到三个标签格式,开始解析');
  4097. // 提取开头文本
  4098. const openingStart = aiReply.indexOf(openingStartTag) + openingStartTag.length;
  4099. const openingEnd = aiReply.indexOf(openingEndTag);
  4100. if (openingStart < openingEnd) {
  4101. openingText = aiReply.substring(openingStart, openingEnd).trim();
  4102. console.log('提取的开头文本:', openingText);
  4103. } else {
  4104. console.warn('开头标签格式不正确');
  4105. }
  4106. // 提取文档内容
  4107. const docStart = aiReply.indexOf(docStartTag) + docStartTag.length;
  4108. let docEnd = aiReply.indexOf(docEndTag);
  4109. // 如果没有找到正确的结束标签,尝试查找错误的结束标签
  4110. if (docEnd === -1) {
  4111. docEnd = aiReply.indexOf('</DOCUMENT_START>');
  4112. if (docEnd !== -1) {
  4113. console.log('检测到错误的文档结束标签:</DOCUMENT_START>');
  4114. }
  4115. }
  4116. if (docStart < docEnd && docEnd !== -1) {
  4117. documentText = aiReply.substring(docStart, docEnd).trim();
  4118. console.log('提取的文档内容长度:', documentText.length);
  4119. console.log('提取的文档内容预览:', documentText.substring(0, 200) + '...');
  4120. // 尝试从文档内容中提取标题
  4121. const titleMatch = documentText.match(/^#\s+(.+)$/m);
  4122. if (titleMatch) {
  4123. documentTitle = titleMatch[1].trim();
  4124. console.log('从Markdown提取的标题:', documentTitle);
  4125. } else {
  4126. // 如果没有Markdown标题,尝试从第一行提取
  4127. const lines = documentText.split('\n');
  4128. if (lines.length > 0 && lines[0].trim()) {
  4129. documentTitle = lines[0].trim();
  4130. console.log('从第一行提取的标题:', documentTitle);
  4131. }
  4132. }
  4133. } else {
  4134. console.warn('文档标签格式不正确');
  4135. }
  4136. // 提取结尾文本
  4137. const closingStart = aiReply.indexOf(closingStartTag) + closingStartTag.length;
  4138. const closingEnd = aiReply.indexOf(closingEndTag);
  4139. if (closingStart < closingEnd) {
  4140. closingText = aiReply.substring(closingStart, closingEnd).trim();
  4141. console.log('提取的结尾文本:', closingText);
  4142. } else {
  4143. // 尝试从文档结束标签后提取结尾文本
  4144. let afterDocEnd = aiReply.indexOf(docEndTag) + docEndTag.length;
  4145. // 如果没有找到正确的结束标签,尝试查找错误的结束标签
  4146. if (afterDocEnd === docEndTag.length - 1) {
  4147. afterDocEnd = aiReply.indexOf('</DOCUMENT_START>') + '</DOCUMENT_START>'.length;
  4148. }
  4149. const remainingText = aiReply.substring(afterDocEnd).trim();
  4150. if (remainingText) {
  4151. closingText = remainingText;
  4152. console.log('从文档结束后提取的结尾文本:', closingText);
  4153. } else {
  4154. console.warn('结尾标签格式不正确');
  4155. }
  4156. }
  4157. // 验证解析结果
  4158. if (!openingText || !documentText || !closingText) {
  4159. console.warn('标签解析不完整:', { openingText: !!openingText, documentText: !!documentText, closingText: !!closingText });
  4160. }
  4161. } catch (error) {
  4162. console.error('解析三个标签格式失败:', error);
  4163. }
  4164. } else if (aiReply.includes(docStartTag) && aiReply.includes(docEndTag)) {
  4165. // 兼容只有文档标签的格式
  4166. const startIndex = aiReply.indexOf(docStartTag) + docStartTag.length;
  4167. const endIndex = aiReply.indexOf(docEndTag);
  4168. if (startIndex < endIndex) {
  4169. documentText = aiReply.substring(startIndex, endIndex).trim();
  4170. // 尝试从文档内容中提取标题
  4171. const titleMatch = documentText.match(/^#\s+(.+)$/m);
  4172. if (titleMatch) {
  4173. documentTitle = titleMatch[1].trim();
  4174. } else {
  4175. // 如果没有Markdown标题,尝试从第一行提取
  4176. const lines = documentText.split('\n');
  4177. if (lines.length > 0 && lines[0].trim()) {
  4178. documentTitle = lines[0].trim();
  4179. }
  4180. }
  4181. }
  4182. // 设置开头和结尾文本(不包含标签)
  4183. const beforeDoc = aiReply.substring(0, aiReply.indexOf(docStartTag)).trim();
  4184. const afterDoc = aiReply.substring(aiReply.indexOf(docEndTag) + docEndTag.length).trim();
  4185. openingText = beforeDoc;
  4186. closingText = afterDoc;
  4187. } else if (aiReply.includes('<DOCUMENT_START>') && aiReply.includes('</DOCUMENT_START>')) {
  4188. // 特殊情况:处理后端返回<DOCUMENT_START>和</DOCUMENT_START>的错误情况
  4189. console.log('检测到错误的文档标签格式:<DOCUMENT_START>和</DOCUMENT_START>');
  4190. const startIndex = aiReply.indexOf('<DOCUMENT_START>') + '<DOCUMENT_START>'.length;
  4191. const endIndex = aiReply.indexOf('</DOCUMENT_START>');
  4192. if (startIndex < endIndex) {
  4193. documentText = aiReply.substring(startIndex, endIndex).trim();
  4194. // 尝试从文档内容中提取标题
  4195. const titleMatch = documentText.match(/^#\s+(.+)$/m);
  4196. if (titleMatch) {
  4197. documentTitle = titleMatch[1].trim();
  4198. } else {
  4199. // 如果没有Markdown标题,尝试从第一行提取
  4200. const lines = documentText.split('\n');
  4201. if (lines.length > 0 && lines[0].trim()) {
  4202. documentTitle = lines[0].trim();
  4203. }
  4204. }
  4205. }
  4206. // 设置开头和结尾文本(不包含标签)
  4207. const beforeDoc = aiReply.substring(0, aiReply.indexOf('<DOCUMENT_START>')).trim();
  4208. const afterDoc = aiReply.substring(aiReply.indexOf('</DOCUMENT_START>') + '</DOCUMENT_START>'.length).trim();
  4209. openingText = beforeDoc;
  4210. closingText = afterDoc;
  4211. } else {
  4212. // 兼容旧的格式:使用"以下"和"以上"识别
  4213. const lines = aiReply.split('\n').filter(line => line.trim());
  4214. // 查找"以下"开头的段落
  4215. const openingIndex = lines.findIndex(line => line.includes('以下'));
  4216. if (openingIndex !== -1) {
  4217. openingText = lines[openingIndex];
  4218. }
  4219. // 查找"以上"开头的段落
  4220. const closingIndex = lines.findIndex(line => line.includes('以上'));
  4221. if (closingIndex !== -1) {
  4222. closingText = lines[closingIndex];
  4223. }
  4224. // 中间部分就是文档内容
  4225. if (openingIndex !== -1 && closingIndex !== -1) {
  4226. // 提取中间部分(不包括开头和结尾行)
  4227. const startIndex = openingIndex + 1;
  4228. const endIndex = closingIndex;
  4229. if (startIndex < endIndex) {
  4230. documentText = lines.slice(startIndex, endIndex).join('\n');
  4231. // 尝试从文档内容中提取标题
  4232. const titleMatch = documentText.match(/^#\s+(.+)$/m);
  4233. if (titleMatch) {
  4234. documentTitle = titleMatch[1].trim();
  4235. } else {
  4236. // 如果没有Markdown标题,尝试从第一行提取
  4237. const firstLine = documentText.split('\n')[0];
  4238. if (firstLine && firstLine.trim()) {
  4239. documentTitle = firstLine.trim();
  4240. }
  4241. }
  4242. }
  4243. } else if (openingIndex !== -1) {
  4244. // 只有开头,没有结尾
  4245. const startIndex = openingIndex + 1;
  4246. documentText = lines.slice(startIndex).join('\n');
  4247. // 尝试提取标题
  4248. const titleMatch = documentText.match(/^#\s+(.+)$/m);
  4249. if (titleMatch) {
  4250. documentTitle = titleMatch[1].trim();
  4251. }
  4252. } else if (closingIndex !== -1) {
  4253. // 只有结尾,没有开头
  4254. documentText = lines.slice(0, closingIndex).join('\n');
  4255. // 尝试提取标题
  4256. const titleMatch = documentText.match(/^#\s+(.+)$/m);
  4257. if (titleMatch) {
  4258. documentTitle = titleMatch[1].trim();
  4259. }
  4260. }
  4261. }
  4262. // 如果没有检测到标准文档结构,检查是否为HTML格式
  4263. if (!openingText && !closingText && !documentText) {
  4264. // 检测是否为HTML格式
  4265. const isHTML = /<[^>]+>/.test(aiReply);
  4266. if (isHTML) {
  4267. // 如果是HTML格式,将其作为文档内容
  4268. console.log('检测到HTML格式,将其作为文档内容');
  4269. return {
  4270. hasDocument: true,
  4271. documentContent: {
  4272. title: "AI生成的文档",
  4273. sections: [
  4274. {
  4275. title: "文档内容",
  4276. content: aiReply
  4277. }
  4278. ]
  4279. },
  4280. openingText: "",
  4281. documentText: aiReply,
  4282. closingText: "",
  4283. documentTitle: "AI生成的文档"
  4284. };
  4285. } else {
  4286. // 如果不是HTML格式,将整个回复作为开头文本
  4287. return {
  4288. hasDocument: false,
  4289. documentContent: null,
  4290. openingText: aiReply, // 将整个回复作为开头文本
  4291. documentText: "",
  4292. closingText: "",
  4293. documentTitle: "AI回复"
  4294. };
  4295. }
  4296. }
  4297. const result = {
  4298. hasDocument: documentText.trim().length > 0,
  4299. documentContent: documentText.trim() ? {
  4300. title: documentTitle,
  4301. sections: [
  4302. {
  4303. title: "文档内容",
  4304. content: documentText.trim()
  4305. }
  4306. ]
  4307. } : null,
  4308. openingText: openingText.trim(),
  4309. documentText: documentText.trim(),
  4310. closingText: closingText.trim(),
  4311. documentTitle: documentTitle // 添加文档标题
  4312. };
  4313. // 调试日志:输出解析结果
  4314. console.log('parseAIResponse 解析结果:', {
  4315. hasDocument: result.hasDocument,
  4316. documentTextLength: result.documentText.length,
  4317. openingTextLength: result.openingText.length,
  4318. closingTextLength: result.closingText.length,
  4319. documentTitle: result.documentTitle
  4320. });
  4321. return result;
  4322. };
  4323. // 从AI消息中获取文档内容的辅助函数
  4324. const getDocumentContentFromMessages = () => {
  4325. if (!selectedHistoryItem.value?.messages) return null;
  4326. const aiMessage = selectedHistoryItem.value.messages.find(msg => msg.type === 'ai' && msg.parsedContent?.hasDocument);
  4327. if (aiMessage && aiMessage.parsedContent) {
  4328. return aiMessage.parsedContent.documentContent;
  4329. }
  4330. return null;
  4331. };
  4332. // 获取当前文档标题的辅助函数
  4333. const getCurrentDocumentTitle = () => {
  4334. // 从富文本编辑器中提取标题
  4335. let content = '';
  4336. // 方式1: 从DOM获取
  4337. const editorTextContainer = document.querySelector('.w-e-text');
  4338. if (editorTextContainer) {
  4339. content = editorTextContainer.innerHTML;
  4340. }
  4341. // 方式2: 从editorContent获取
  4342. if (!content && editorContent.value) {
  4343. content = editorContent.value;
  4344. }
  4345. // 方式3: 从wangeditor实例获取
  4346. if (!content && editorRef.value) {
  4347. try {
  4348. content = editorRef.value.getHtml();
  4349. } catch (error) {
  4350. console.log("从wangeditor实例获取失败:", error);
  4351. }
  4352. }
  4353. if (content) {
  4354. // 尝试从HTML内容中提取标题
  4355. // 查找第一个h1标签
  4356. const h1Match = content.match(/<h1[^>]*>(.*?)<\/h1>/i);
  4357. if (h1Match) {
  4358. const title = h1Match[1].replace(/<[^>]*>/g, '').trim();
  4359. if (title) {
  4360. return title;
  4361. }
  4362. }
  4363. // 查找第一个h2标签
  4364. const h2Match = content.match(/<h2[^>]*>(.*?)<\/h2>/i);
  4365. if (h2Match) {
  4366. const title = h2Match[1].replace(/<[^>]*>/g, '').trim();
  4367. if (title) {
  4368. return title;
  4369. }
  4370. }
  4371. // 查找第一个h3标签
  4372. const h3Match = content.match(/<h3[^>]*>(.*?)<\/h3>/i);
  4373. if (h3Match) {
  4374. const title = h3Match[1].replace(/<[^>]*>/g, '').trim();
  4375. if (title) {
  4376. return title;
  4377. }
  4378. }
  4379. // 如果没有标题标签,尝试从第一段文本中提取
  4380. const firstParagraph = content.match(/<p[^>]*>(.*?)<\/p>/i);
  4381. if (firstParagraph) {
  4382. const text = firstParagraph[1].replace(/<[^>]*>/g, '').trim();
  4383. // 如果第一段文本较短且看起来像标题,则使用它
  4384. if (text && text.length <= 50 && !text.includes('。') && !text.includes(',')) {
  4385. return text;
  4386. }
  4387. }
  4388. }
  4389. // 如果都没有找到合适的标题,返回默认值
  4390. return 'AI生成文档';
  4391. };
  4392. // 获取水印文本的辅助函数
  4393. const getWatermarkText = () => {
  4394. // 可以从以下来源获取水印文本:
  4395. // 1. 用户设置
  4396. // 2. 系统配置
  4397. // 3. 文档类型
  4398. // 4. 默认值
  4399. // 这里可以根据实际需求进行配置
  4400. const watermarkConfig = {
  4401. default: '机密文档',
  4402. // 可以根据文档类型设置不同的水印
  4403. types: {
  4404. '工作总结': '内部文档',
  4405. '会议纪要': '机密',
  4406. '通知': '正式文档',
  4407. '公告': '公开文档'
  4408. }
  4409. };
  4410. // 获取当前文档标题
  4411. const documentTitle = getCurrentDocumentTitle();
  4412. // 根据文档标题判断类型
  4413. for (const [type, watermark] of Object.entries(watermarkConfig.types)) {
  4414. if (documentTitle.includes(type)) {
  4415. return watermark;
  4416. }
  4417. }
  4418. // 返回默认水印
  4419. return watermarkConfig.default;
  4420. };
  4421. // 使用HTML生成带真正可见水印的Word文档
  4422. const generateWordWithWatermark = async (content, documentTitle, watermarkText, filename) => {
  4423. // 为保持兼容,保留函数但改为调用无水印实现
  4424. try {
  4425. await generateWordWithoutWatermark(content, documentTitle, filename)
  4426. } catch (error) {
  4427. console.error('生成Word文档失败:', error);
  4428. ElMessage.error("生成Word文档失败,请重试");
  4429. }
  4430. };
  4431. // 回退方案:使用HTML生成带水印的Word文档
  4432. const generateWordWithHTMLWatermark = async (content, documentTitle, watermarkText, filename) => {
  4433. // 保留旧接口但移除水印与成功提示
  4434. await generateWordWithoutWatermark(content, documentTitle, filename)
  4435. };
  4436. // 无水印的Word(HTML)生成与下载
  4437. const generateWordWithoutWatermark = async (content, documentTitle, filename) => {
  4438. try {
  4439. const html = createHTMLWithoutWatermark(content, documentTitle)
  4440. const blob = new Blob([html], { type: 'application/msword;charset=utf-8' })
  4441. const url = URL.createObjectURL(blob)
  4442. const link = document.createElement('a')
  4443. link.href = url
  4444. link.download = filename.replace('.docx', '.doc')
  4445. document.body.appendChild(link)
  4446. link.click()
  4447. document.body.removeChild(link)
  4448. URL.revokeObjectURL(url)
  4449. ElMessage.success("Word文档下载成功")
  4450. } catch (error) {
  4451. console.error('生成无水印Word文档失败:', error)
  4452. ElMessage.error("生成Word文档失败,请重试")
  4453. }
  4454. }
  4455. // 创建带有真正可见水印的HTML文档
  4456. const createHTMLWithTrueWatermark = (content, documentTitle, watermarkText) => {
  4457. // 兼容旧函数签名,移除水印,仅输出纯文档
  4458. return createHTMLWithoutWatermark(content, documentTitle)
  4459. };
  4460. const createHTMLWithoutWatermark = (content, documentTitle) => {
  4461. return `<!DOCTYPE html>
  4462. <html xmlns:o="urn:schemas-microsoft-com:office:office"
  4463. xmlns:w="urn:schemas-microsoft-com:office:word"
  4464. xmlns="http://www.w3.org/TR/REC-html40">
  4465. <head>
  4466. <meta charset="UTF-8">
  4467. <meta name="ProgId" content="Word.Document">
  4468. <meta name="Generator" content="Microsoft Word 15">
  4469. <meta name="Originator" content="Microsoft Word 15">
  4470. <title>${documentTitle || 'AI生成文档'}</title>
  4471. <style>
  4472. @page { size: 21cm 29.7cm; margin: 2.54cm 3.18cm 2.54cm 3.18cm; }
  4473. body { font-family: "宋体", "SimSun", serif; font-size: 12pt; line-height: 1.5; color: #000; }
  4474. h1 { font-size: 18pt; font-weight: bold; text-align: center; margin: 24pt 0 18pt 0; }
  4475. h2 { font-size: 16pt; font-weight: bold; margin: 18pt 0 12pt 0; }
  4476. h3 { font-size: 14pt; font-weight: bold; margin: 12pt 0 6pt 0; }
  4477. p { margin: 0 0 6pt 0; text-align: justify; text-indent: 2em; }
  4478. table { border-collapse: collapse; width: 100%; margin: 12pt 0; }
  4479. td, th { border: 1px solid #000; padding: 6pt; }
  4480. </style>
  4481. <!--[if gte mso 9]>
  4482. <xml>
  4483. <w:WordDocument>
  4484. <w:View>Print</w:View>
  4485. <w:Zoom>100</w:Zoom>
  4486. <w:DoNotOptimizeForBrowser/>
  4487. </w:WordDocument>
  4488. </xml>
  4489. <![endif]-->
  4490. </head>
  4491. <body>
  4492. ${content}
  4493. </body>
  4494. </html>`
  4495. }
  4496. // 过滤内部标签,只显示纯文本内容
  4497. const filterInternalTags = (text) => {
  4498. if (!text) return text;
  4499. console.log('过滤前的文本:', text);
  4500. // 移除所有内部标签(包括可能的变体)
  4501. let filteredText = text
  4502. .replace(/<OPENING_START>/g, '')
  4503. .replace(/<\/OPENING_END>/g, '')
  4504. .replace(/<DOCUMENT_START>/g, '')
  4505. .replace(/<\/DOCUMENT_END>/g, '')
  4506. .replace(/<CLOSING_START>/g, '')
  4507. .replace(/<\/CLOSING_START>/g, '') // 处理可能的错误标签格式
  4508. .replace(/<\/CLOSING_END>/g, '')
  4509. .replace(/<\/DOCUMENT_START>/g, '') // 处理错误的</DOCUMENT_START>标签
  4510. .replace(/<CLOSING_END>/g, '') // 处理可能的错误标签格式
  4511. .trim();
  4512. console.log('过滤后的文本:', filteredText);
  4513. return filteredText;
  4514. };
  4515. // 清理Markdown标签,用于语音朗读
  4516. const cleanMarkdownForSpeech = (text) => {
  4517. if (!text) return text;
  4518. let cleanText = text
  4519. // 移除Markdown标题标记
  4520. .replace(/^#{1,6}\s+/gm, '') // 移除 # ## ### 等标题标记
  4521. // 移除粗体和斜体标记
  4522. .replace(/\*\*([^*]+)\*\*/g, '$1') // 移除 **粗体**
  4523. .replace(/\*([^*]+)\*/g, '$1') // 移除 *斜体*
  4524. .replace(/__([^_]+)__/g, '$1') // 移除 __粗体__
  4525. .replace(/_([^_]+)_/g, '$1') // 移除 _斜体_
  4526. // 移除链接标记
  4527. .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') // 移除 [文本](链接)
  4528. // 移除代码块标记
  4529. .replace(/```[\s\S]*?```/g, '') // 移除 ```代码块```
  4530. .replace(/`([^`]+)`/g, '$1') // 移除 `行内代码`
  4531. // 移除列表标记
  4532. .replace(/^[\s]*[-*+]\s+/gm, '') // 移除无序列表标记
  4533. .replace(/^[\s]*\d+\.\s+/gm, '') // 移除有序列表标记
  4534. // 移除引用标记
  4535. .replace(/^>\s*/gm, '') // 移除 > 引用标记
  4536. // 移除水平线
  4537. .replace(/^[-*_]{3,}$/gm, '') // 移除 --- 或 *** 或 ___
  4538. // 移除表格标记
  4539. .replace(/\|/g, ' ') // 移除表格分隔符
  4540. .replace(/^[\s]*[-:]+[\s-:]*$/gm, '') // 移除表格分隔行
  4541. // 清理多余的空格和换行
  4542. .replace(/\n\s*\n/g, '\n') // 合并多个空行
  4543. .replace(/\s+/g, ' ') // 合并多个空格
  4544. .trim();
  4545. return cleanText;
  4546. };
  4547. // 格式化文档内容,处理Markdown链接和换行
  4548. const formatDocumentContent = (content) => {
  4549. if (!content) return '';
  4550. let formattedContent = content;
  4551. // 后端返回的是HTML格式,无需Markdown转换
  4552. // 后端返回的是HTML格式,无需Markdown转换
  4553. // 过滤emoji表情符号
  4554. formattedContent = formattedContent.replace(/[\u{1F600}-\u{1F64F}]|[\u{1F300}-\u{1F5FF}]|[\u{1F680}-\u{1F6FF}]|[\u{1F1E0}-\u{1F1FF}]|[\u{2600}-\u{26FF}]|[\u{2700}-\u{27BF}]/gu, '');
  4555. // 包装在p标签中,但减少多余的段落
  4556. if (formattedContent.trim()) {
  4557. formattedContent = `<p>${formattedContent}</p>`;
  4558. }
  4559. return formattedContent;
  4560. };
  4561. // 发送详情页消息
  4562. const sendDetailMessage = () => {
  4563. if (!detailInputText.value.trim() || isGenerating.value) {
  4564. return;
  4565. }
  4566. // 保存文件引用,因为后面需要传递给AI
  4567. const currentFile = selectedFile.value;
  4568. const newMessage = {
  4569. type: 'user',
  4570. content: detailInputText.value,
  4571. file: currentFile, // 添加文件信息
  4572. time: new Date().toLocaleString('zh-CN', {
  4573. hour: '2-digit',
  4574. minute: '2-digit'
  4575. }),
  4576. id: Date.now(), // 添加唯一ID
  4577. isFromBackend: false // 标记这是新创建的消息
  4578. };
  4579. selectedHistoryItem.value.messages.push(newMessage);
  4580. detailInputText.value = '';
  4581. // 注意:不关闭文档预览,让用户在预览状态下正常聊天
  4582. // 清空选中的文件
  4583. if (selectedFile.value) {
  4584. removeSelectedFile();
  4585. }
  4586. // 自动滚动到最新位置
  4587. scrollToBottom();
  4588. // 直接进入富文本编辑器并显示loading
  4589. currentView.value = "editor";
  4590. isGenerating.value = true;
  4591. // 在详情页中调用AI - 传递当前用户输入的消息
  4592. callAIInDetail(selectedHistoryItem.value, null, newMessage.content, currentFile);
  4593. };
  4594. // 自动滚动到最新位置
  4595. const scrollToBottom = () => {
  4596. nextTick(() => {
  4597. const chatArea = document.querySelector('.chat-area');
  4598. if (chatArea) {
  4599. chatArea.scrollTop = chatArea.scrollHeight;
  4600. }
  4601. });
  4602. };
  4603. // 监听消息变化,自动滚动
  4604. const watchMessages = () => {
  4605. if (selectedHistoryItem.value?.messages) {
  4606. scrollToBottom();
  4607. }
  4608. };
  4609. // 使用watch监听消息数组变化
  4610. watch(selectedHistoryItem, (newVal) => {
  4611. watchMessages();
  4612. });
  4613. // 为详情页生成智能提示词
  4614. const generateSmartPromptForDetail = (userMessage) => {
  4615. // 不做意图判断,让AI自己判断,但要求按照固定格式
  4616. return `请根据用户的问题或需求进行回复。
  4617. 如果用户需要文档,请严格按照以下格式回复:
  4618. <OPENING_START>
  4619. 以下是为您准备的文档,包含相关内容:
  4620. </OPENING_END>
  4621. <DOCUMENT_START>
  4622. [在这里生成完整的Word文档内容,必须包含:
  4623. 1. 文档标题(使用#标记)
  4624. 2. 多个章节(使用##标记)
  4625. 3. 详细内容(使用Markdown格式,支持大小标题、换行、列表、加粗、斜体等富文本效果)
  4626. 4. 确保内容完整,不要中途停止]
  4627. </DOCUMENT_END>
  4628. <CLOSING_START>
  4629. 以上文档采用专业的格式编写,符合办公文档要求。如需调整内容或格式,请告诉我具体需求。
  4630. </CLOSING_END>
  4631. 如果是普通问题,请直接回答,不要使用上述格式。
  4632. 重要提醒:
  4633. 1. 如果生成文档,必须包含三个标签区域:<OPENING_START>开头文本</OPENING_END>、<DOCUMENT_START>文档内容</DOCUMENT_END>、<CLOSING_START>结尾文本</CLOSING_END>
  4634. 2. 确保每个区域都完整,特别是结尾部分不能缺失
  4635. 3. 标签必须严格按照上述格式,不能有任何变化
  4636. 4. 文档内容中不要使用emoji表情符号
  4637. 5. 如果用户明确要求生成文档、报告、通知、方案等办公文档,必须使用上述格式
  4638. 6. 标签名称区分大小写,必须完全匹配
  4639. 示例正确格式:
  4640. <OPENING_START>
  4641. 以下是为您准备的文档,包含相关内容:
  4642. </OPENING_END>
  4643. <DOCUMENT_START>
  4644. # 文档标题
  4645. ## 第一章 概述
  4646. 详细内容...
  4647. ## 第二章 具体内容
  4648. 详细内容...
  4649. </DOCUMENT_END>
  4650. <CLOSING_START>
  4651. 以上文档采用专业的格式编写,符合办公文档要求。如需调整内容或格式,请告诉我具体需求。
  4652. </CLOSING_END>`;
  4653. };
  4654. </script>
  4655. <style lang="less" scoped>
  4656. // 删除图标样式
  4657. .delete-icon {
  4658. width: 16px;
  4659. height: 16px;
  4660. }
  4661. .chat-container {
  4662. display: flex;
  4663. height: 100vh;
  4664. font-family: "Alibaba PuHuiTi 3.0", sans-serif;
  4665. }
  4666. /* 工作内容区域 */
  4667. .work-content {
  4668. flex: 1;
  4669. padding: 22px;
  4670. overflow-y: auto;
  4671. display: flex;
  4672. flex-direction: column;
  4673. align-items: center;
  4674. // max-width: 1528px; /* 设置最小宽度,确保内容完整显示 */
  4675. /* 隐藏滚动条样式 */
  4676. &::-webkit-scrollbar {
  4677. width: 0;
  4678. background: transparent;
  4679. }
  4680. &::-webkit-scrollbar-track {
  4681. background: transparent;
  4682. }
  4683. &::-webkit-scrollbar-thumb {
  4684. background: transparent;
  4685. }
  4686. .ai-writing-card {
  4687. background: white;
  4688. width: 100%;
  4689. min-height: 720px; /* 最小高度 */
  4690. max-height: calc(100vh); /* 最大高度,防止超出容器 */
  4691. height: calc(100vh); /* 自适应高度 */
  4692. padding: 25px 236px 35px 272px;
  4693. border-radius: 16px;
  4694. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  4695. max-width: 1528px;
  4696. display: flex;
  4697. flex-direction: column;
  4698. .document-generation {
  4699. margin-bottom: 38px; /* 减少底部间距 */
  4700. text-align: center;
  4701. flex-shrink: 0; /* 防止被压缩 */
  4702. h3 {
  4703. font-size: 30px;
  4704. font-weight: 600;
  4705. color: #1e3d59;
  4706. // margin: 0 0 16px 0;
  4707. }
  4708. .subtitle {
  4709. font-size: 20px;
  4710. color: #b2b2b2;
  4711. margin: 0 0 13px 0;
  4712. line-height: 1.5;
  4713. }
  4714. .input-area {
  4715. border: 2px solid #3e7bfa;
  4716. border-radius: 12px;
  4717. padding: 24px 24px 0 24px;
  4718. height: 205px;
  4719. margin-bottom: 15px;
  4720. .template-input-container {
  4721. text-align: left;
  4722. display: block; /* 改为block布局,避免flex对齐问题 */
  4723. // margin-bottom: 10px;
  4724. height: 120px; /* 固定高度,不再使用min-height */
  4725. border-radius: 8px; /* 大输入框的圆角 */
  4726. background-color: #fff; /* 大输入框的背景色 */
  4727. transition: border-color 0.3s ease;
  4728. cursor: text; /* 显示文本输入光标 */
  4729. outline: none; /* 移除默认轮廓 */
  4730. // padding: 16px; /* 恢复内边距 */
  4731. font-size: 18px;
  4732. line-height: 1.6;
  4733. color: #000;
  4734. overflow-y: auto; /* 添加垂直滚动条 */
  4735. white-space: pre-line; /* 保留换行符,确保每个关键信息独占一行 */
  4736. resize: none; /* 禁止手动调整大小 */
  4737. &:focus-within {
  4738. border-color: #3e7bfa; /* 当内部输入框聚焦时,大框也高亮 */
  4739. }
  4740. &:focus {
  4741. border-color: #3e7bfa; /* 当整个容器聚焦时高亮 */
  4742. }
  4743. /* 支持文本输入 */
  4744. &:empty:before {
  4745. content: attr(placeholder);
  4746. color: #9ca3af;
  4747. pointer-events: none;
  4748. }
  4749. /* 自定义滚动条样式 */
  4750. &::-webkit-scrollbar {
  4751. width: 6px;
  4752. }
  4753. &::-webkit-scrollbar-track {
  4754. background: #f1f1f1;
  4755. border-radius: 3px;
  4756. }
  4757. &::-webkit-scrollbar-thumb {
  4758. background: #c1c1c1;
  4759. border-radius: 3px;
  4760. }
  4761. &::-webkit-scrollbar-thumb:hover {
  4762. background: #a8a8a8;
  4763. }
  4764. .editable-highlight {
  4765. background-color: #3E7BFA10; /* 特殊背景色 */
  4766. color: #3E7BFA; /* 特殊字体颜色 */
  4767. padding: 4px 8px;
  4768. border-radius: 6px;
  4769. font-weight: 500;
  4770. cursor: text;
  4771. transition: all 0.3s ease;
  4772. border: 1px solid transparent;
  4773. display: inline-block; /* 确保正确对齐 */
  4774. min-width: 20px; /* 最小宽度,防止完全消失 */
  4775. &:hover {
  4776. background-color: #3E7BFA20;
  4777. border-color: #3E7BFA30;
  4778. }
  4779. &:focus {
  4780. background-color: #3E7BFA20;
  4781. border-color: #3E7BFA;
  4782. outline: none;
  4783. }
  4784. }
  4785. }
  4786. .text-input {
  4787. width: 100%;
  4788. min-height: 120px;
  4789. border: none;
  4790. outline: none;
  4791. resize: none;
  4792. font-size: 18px;
  4793. line-height: 1.6;
  4794. color: #000000;
  4795. font-family: inherit;
  4796. &::placeholder {
  4797. color: #9ca3af;
  4798. }
  4799. }
  4800. .input-actions {
  4801. display: flex;
  4802. justify-content: space-between;
  4803. align-items: center;
  4804. // margin-top: 16px;
  4805. .left-actions {
  4806. display: flex;
  4807. align-items: center;
  4808. gap: 12px;
  4809. .attachment-btn {
  4810. background: none;
  4811. border: none;
  4812. cursor: pointer;
  4813. padding: 8px;
  4814. border-radius: 6px;
  4815. transition: background-color 0.3s ease;
  4816. // &:hover {
  4817. // background-color: #F3F4F6;
  4818. // }
  4819. .action-icon {
  4820. width: 40px;
  4821. height: 40px;
  4822. }
  4823. }
  4824. // 文件预览样式 - 显示在输入框右边
  4825. .file-preview-inline {
  4826. display: flex;
  4827. align-items: center;
  4828. background: rgba(255, 255, 255, 0.9);
  4829. border: 1px solid #E5E7EB;
  4830. border-radius: 8px;
  4831. padding: 6px 10px;
  4832. margin-bottom: 5px;
  4833. // margin-left: 8px;
  4834. max-width: 200px;
  4835. .file-info-inline {
  4836. display: flex;
  4837. align-items: center;
  4838. gap: 6px;
  4839. .file-icon-inline {
  4840. font-size: 16px;
  4841. flex-shrink: 0;
  4842. }
  4843. .file-icon-inline-img {
  4844. width: 16px;
  4845. height: 16px;
  4846. object-fit: contain;
  4847. flex-shrink: 0;
  4848. }
  4849. .file-name-inline {
  4850. font-size: 12px;
  4851. color: #374151;
  4852. overflow: hidden;
  4853. text-overflow: ellipsis;
  4854. white-space: nowrap;
  4855. max-width: 120px;
  4856. }
  4857. .remove-file-inline {
  4858. width: 16px;
  4859. height: 16px;
  4860. border: none;
  4861. background: rgba(239, 68, 68, 0.1);
  4862. color: #DC2626;
  4863. border-radius: 50%;
  4864. cursor: pointer;
  4865. display: flex;
  4866. align-items: center;
  4867. justify-content: center;
  4868. transition: all 0.2s ease;
  4869. flex-shrink: 0;
  4870. &:hover {
  4871. background: rgba(239, 68, 68, 0.2);
  4872. transform: scale(1.1);
  4873. }
  4874. .remove-icon {
  4875. font-size: 12px;
  4876. font-weight: bold;
  4877. }
  4878. }
  4879. }
  4880. }
  4881. }
  4882. .right-actions {
  4883. display: flex;
  4884. gap: 12px;
  4885. align-items: center;
  4886. .voice-btn {
  4887. background: none;
  4888. border: none;
  4889. cursor: pointer;
  4890. // padding: 8px;
  4891. border-radius: 6px;
  4892. transition: all 0.3s ease;
  4893. position: relative;
  4894. &:hover {
  4895. background-color: #f3f4f6;
  4896. }
  4897. &.recording {
  4898. background: rgba(239, 68, 68, 0.1);
  4899. animation: pulse 1.5s ease-in-out infinite;
  4900. }
  4901. .icon-container {
  4902. position: relative;
  4903. display: flex;
  4904. align-items: center;
  4905. justify-content: center;
  4906. }
  4907. .recording-indicator {
  4908. position: absolute;
  4909. top: -2px;
  4910. right: -2px;
  4911. width: 8px;
  4912. height: 8px;
  4913. background: #ef4444;
  4914. border-radius: 50%;
  4915. animation: blink 1s ease-in-out infinite;
  4916. }
  4917. .action-icon {
  4918. width: 20px;
  4919. height: 20px;
  4920. }
  4921. }
  4922. .divider {
  4923. width: 1px;
  4924. height: 31px;
  4925. background: #d6d5de;
  4926. }
  4927. .send-btn {
  4928. background: none;
  4929. border: none;
  4930. padding: 0;
  4931. cursor: pointer;
  4932. position: relative; /* 为生成中文字定位 */
  4933. &:disabled {
  4934. cursor: not-allowed;
  4935. opacity: 0.6;
  4936. }
  4937. .action-icon {
  4938. width: 90px;
  4939. height: 40px;
  4940. }
  4941. .generating-text {
  4942. position: absolute;
  4943. top: 50%;
  4944. left: 50%;
  4945. transform: translate(-50%, -50%);
  4946. font-size: 12px;
  4947. color: #666;
  4948. white-space: nowrap;
  4949. }
  4950. }
  4951. }
  4952. }
  4953. }
  4954. .hint-text {
  4955. font-size: 14px;
  4956. color: #6b7280;
  4957. margin: 0;
  4958. text-align: start;
  4959. }
  4960. }
  4961. .document-templates {
  4962. flex: 1; /* 允许弹性增长 */
  4963. display: flex;
  4964. flex-direction: column;
  4965. min-height: 0; /* 允许收缩 */
  4966. .template-tabs {
  4967. display: flex;
  4968. gap: 40px;
  4969. margin-bottom: 24px;
  4970. border-bottom: 1px solid #e5e7eb;
  4971. flex-shrink: 0; /* 防止被压缩 */
  4972. .tab-item {
  4973. padding: 10px 0;
  4974. font-size: 16px;
  4975. font-weight: 500;
  4976. color: #4b5563;
  4977. cursor: pointer;
  4978. transition: all 0.3s ease;
  4979. border-bottom: 3px solid transparent;
  4980. width: 95px;
  4981. // height: 52px;
  4982. text-align: center;
  4983. &:hover {
  4984. color: #2563eb;
  4985. }
  4986. &.active {
  4987. color: #2563eb;
  4988. border-bottom-color: #2563eb;
  4989. }
  4990. }
  4991. }
  4992. .template-cards {
  4993. display: flex;
  4994. flex-direction: column;
  4995. gap: 18px;
  4996. flex: 1; /* 占满剩余空间 */
  4997. min-height: 0; /* 允许收缩 */
  4998. overflow-y: auto;
  4999. /* 隐藏滚动条 */
  5000. &::-webkit-scrollbar {
  5001. display: none;
  5002. }
  5003. /* Firefox隐藏滚动条 */
  5004. scrollbar-width: none;
  5005. /* IE隐藏滚动条 */
  5006. -ms-overflow-style: none;
  5007. .template-card {
  5008. position: relative;
  5009. border-radius: 12px;
  5010. background: #fafafa;
  5011. // overflow: hidden;
  5012. .template-image {
  5013. width: 100%;
  5014. height: auto;
  5015. object-fit: contain;
  5016. display: block;
  5017. }
  5018. .use-template-btn {
  5019. position: absolute;
  5020. right: 39px;
  5021. bottom: 51px;
  5022. padding: 8px 16px;
  5023. border: none;
  5024. border-radius: 9999px;
  5025. font-size: 14px;
  5026. font-weight: 500;
  5027. cursor: pointer;
  5028. transition: all 0.3s ease;
  5029. z-index: 10;
  5030. &.announcement-btn {
  5031. background: rgba(29, 78, 216, 0.1);
  5032. color: #1d4ed8;
  5033. border: 1px solid #1d4ed8;
  5034. &:hover {
  5035. background: rgba(29, 78, 216, 0.2);
  5036. }
  5037. }
  5038. &.notification-btn {
  5039. background: rgba(126, 34, 206, 0.1);
  5040. color: #7e22ce;
  5041. border: 1px solid #7e22ce;
  5042. &:hover {
  5043. background: rgba(126, 34, 206, 0.2);
  5044. }
  5045. }
  5046. &.report-btn {
  5047. background: rgba(194, 65, 12, 0.1);
  5048. color: #c2410c;
  5049. border: 1px solid #c2410c;
  5050. &:hover {
  5051. background: rgba(194, 65, 12, 0.2);
  5052. }
  5053. }
  5054. }
  5055. }
  5056. }
  5057. }
  5058. }
  5059. }
  5060. /* 固定布局,支持横向滚动 */
  5061. .chat-container {
  5062. min-width: 1428px; /* 设置最小宽度,确保内容完整显示 */
  5063. }
  5064. .work-content {
  5065. min-width: 1428px; /* 工作内容区域最小宽度 */
  5066. overflow-x: auto; /* 横向滚动条 */
  5067. }
  5068. .ai-writing-card {
  5069. min-width: 1428px; /* AI写作卡片最小宽度 */
  5070. }
  5071. /* 详情页样式 */
  5072. .detail-view {
  5073. position: relative;
  5074. width: 100%;
  5075. max-width: 1528px;
  5076. background: white;
  5077. border-radius: 16px;
  5078. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  5079. overflow: hidden;
  5080. min-width: 1428px;
  5081. min-height: 800px; /* 最小高度 */
  5082. max-height: calc(100vh - 96px); /* 最大高度,防止超出视窗 */
  5083. height: calc(100vh - 128px); /* 自适应高度 */
  5084. display: flex;
  5085. flex-direction: column;
  5086. transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); // 整体过渡动画
  5087. .main-content1 {
  5088. display: flex;
  5089. flex-direction: row;
  5090. padding: 22px 32px;
  5091. gap: 32px;
  5092. flex: 1;
  5093. position: relative; // 为动画定位
  5094. transition: gap 0.4s cubic-bezier(0.4, 0, 0.2, 1); // gap变化动画
  5095. height: 100%; // 确保占满高度
  5096. overflow: hidden; // 防止内容溢出
  5097. // 默认状态:聊天区域占一半宽度,居中显示
  5098. &:not(.with-document) {
  5099. gap: 0; // 没有分栏时,gap为0
  5100. justify-content: center; // 让内容居中显示
  5101. .left-column {
  5102. width: 50%; // 占一半宽度
  5103. margin: 0; // 移除margin居中,保持与有右侧区域时相同的布局
  5104. padding: 0 32px 0 0; // 与有文档时的padding保持一致,只有右边距
  5105. display: flex;
  5106. flex-direction: column;
  5107. align-items: center;
  5108. transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); // 平滑过渡
  5109. transform: translateX(0); // 确保在中心位置
  5110. height: 100%; // 确保占满高度
  5111. }
  5112. }
  5113. // 显示文档预览时:聊天区域向左滑动
  5114. &.with-document {
  5115. gap: 0; // 减少gap,让左右两列更贴近
  5116. .left-column {
  5117. width: 50%; // 保持一半宽度
  5118. padding: 0 32px 0 0;
  5119. align-items: flex-start;
  5120. transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); // 平滑过渡
  5121. transform: translateX(0); // 确保在左侧位置
  5122. height: 100%; // 确保占满高度
  5123. }
  5124. }
  5125. .left-column {
  5126. display: flex;
  5127. flex-direction: column;
  5128. height: 100%; /* 占满整个高度 */
  5129. width: 100%; /* 确保宽度 */
  5130. transition: none; /* 移除过渡动画,提高响应速度 */
  5131. .chat-area {
  5132. flex: 1; /* 占据剩余空间 */
  5133. overflow-y: auto; /* 允许垂直滚动 */
  5134. padding: 20px 0;
  5135. margin-bottom: 0; /* 移除底部边距 */
  5136. min-height: 0; /* 允许收缩 */
  5137. width: 100%;
  5138. max-height: calc(100vh - 320px); /* 设置最大高度,留出输入框空间 */
  5139. transition: none;
  5140. .message-item {
  5141. margin-bottom: 20px;
  5142. width: 100%;
  5143. &.user {
  5144. .user-message {
  5145. display: flex;
  5146. flex-direction: column;
  5147. align-items: flex-end;
  5148. gap: 8px;
  5149. width: 100%;
  5150. .message-content {
  5151. background: #004bff20;
  5152. color: #000;
  5153. padding: 16px;
  5154. border-radius: 8px 0px 8px 8px;
  5155. font-size: 16px;
  5156. line-height: 1.6;
  5157. max-width: 70%;
  5158. min-width: 0;
  5159. text-align: left;
  5160. word-wrap: break-word;
  5161. overflow-wrap: break-word;
  5162. .message-file {
  5163. margin-bottom: 12px;
  5164. .file-display {
  5165. display: flex;
  5166. align-items: center;
  5167. background: rgba(255, 255, 255, 0.8);
  5168. border: 1px solid #E5E7EB;
  5169. border-radius: 12px;
  5170. padding: 16px;
  5171. max-width: 400px;
  5172. .file-icon {
  5173. font-size: 32px;
  5174. margin-right: 16px;
  5175. width: 48px;
  5176. text-align: center;
  5177. .file-icon-img {
  5178. width: 32px;
  5179. height: 32px;
  5180. object-fit: contain;
  5181. }
  5182. }
  5183. .file-details {
  5184. flex: 1;
  5185. .file-name {
  5186. font-size: 14px;
  5187. font-weight: 500;
  5188. color: #374151;
  5189. margin-bottom: 4px;
  5190. overflow: hidden;
  5191. text-overflow: ellipsis;
  5192. white-space: nowrap;
  5193. max-width: 200px;
  5194. }
  5195. .file-size {
  5196. font-size: 12px;
  5197. color: #6B7280;
  5198. }
  5199. }
  5200. }
  5201. }
  5202. .message-text {
  5203. // margin-top: 8px;
  5204. word-wrap: break-word;
  5205. word-break: break-all;
  5206. overflow-wrap: break-word;
  5207. white-space: pre-wrap;
  5208. max-width: 100%;
  5209. }
  5210. }
  5211. .message-time {
  5212. font-size: 12px;
  5213. color: #6b7280;
  5214. margin-top: 4px;
  5215. text-align: right;
  5216. }
  5217. .action-buttons {
  5218. display: flex;
  5219. // margin-top: 128px;
  5220. align-items: center;
  5221. flex-wrap: wrap;
  5222. // gap: 128px;
  5223. justify-content: flex-end;
  5224. .action-btn {
  5225. background: none;
  5226. color: #6b7280;
  5227. border: none;
  5228. border-radius: 6px;
  5229. padding: 6px 5px;
  5230. font-size: 14px;
  5231. cursor: pointer;
  5232. transition: all 0.3s ease;
  5233. display: flex;
  5234. align-items: center;
  5235. gap: 4px;
  5236. white-space: nowrap;
  5237. &:hover {
  5238. background: #f3f4f6;
  5239. }
  5240. .action-icon {
  5241. width: 16px;
  5242. height: 16px;
  5243. }
  5244. }
  5245. }
  5246. }
  5247. }
  5248. &.ai {
  5249. .ai-message {
  5250. display: flex;
  5251. align-items: flex-start;
  5252. gap: 12px;
  5253. width: 100%;
  5254. .ai-avatar {
  5255. flex-shrink: 0;
  5256. .avatar-img {
  5257. width: 40px;
  5258. height: 40px;
  5259. border-radius: 8px;
  5260. background: #3e7bfa;
  5261. display: flex;
  5262. align-items: center;
  5263. justify-content: center;
  5264. color: white;
  5265. font-weight: bold;
  5266. font-size: 16px;
  5267. }
  5268. }
  5269. .message-content {
  5270. background: #fff;
  5271. border: 1px solid #e2e8f0;
  5272. color: #000;
  5273. padding: 16px 20px;
  5274. border-radius: 0px 8px 8px 8px;
  5275. font-size: 16px;
  5276. line-height: 1.6;
  5277. max-width: 70%;
  5278. flex: 1;
  5279. // 表格样式
  5280. table {
  5281. border-collapse: collapse;
  5282. width: 100%;
  5283. margin: 16px 0;
  5284. border: 1px solid #ddd;
  5285. }
  5286. td, th {
  5287. border: 1px solid #ddd;
  5288. padding: 8px 12px;
  5289. text-align: left;
  5290. }
  5291. th {
  5292. background-color: #f8f9fa;
  5293. font-weight: bold;
  5294. }
  5295. tr:nth-child(even) {
  5296. background-color: #f8f9fa;
  5297. }
  5298. .opening-text {
  5299. margin-bottom: 16px;
  5300. color: #374151;
  5301. }
  5302. .closing-text {
  5303. margin-top: 16px;
  5304. color: #374151;
  5305. }
  5306. .document-info {
  5307. display: flex;
  5308. align-items: center;
  5309. gap: 12px;
  5310. padding: 12px 16px;
  5311. background: white;
  5312. border-radius: 8px;
  5313. margin: 16px 0;
  5314. border: 1px solid #e5e7eb;
  5315. cursor: pointer;
  5316. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  5317. background-color: #e5e5e550;
  5318. &:hover {
  5319. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  5320. border-color: #3e7bfa;
  5321. transform: translateY(-2px);
  5322. background-color: #f8fafc;
  5323. }
  5324. .info-icon {
  5325. width: 24px;
  5326. height: 24px;
  5327. flex-shrink: 0;
  5328. }
  5329. .doc-details {
  5330. flex: 1;
  5331. .doc-title {
  5332. font-size: 16px;
  5333. font-weight: 600;
  5334. color: #000;
  5335. margin-bottom: 4px;
  5336. }
  5337. .doc-time {
  5338. font-size: 12px;
  5339. color: #6b7280;
  5340. }
  5341. }
  5342. }
  5343. .action-buttons {
  5344. display: flex;
  5345. justify-content: space-between;
  5346. margin-top: 16px;
  5347. border-top: 1px solid #e5e7eb;
  5348. padding-top: 6px;
  5349. align-items: center;
  5350. flex-wrap: wrap;
  5351. // gap: 128px;
  5352. .left-actions {
  5353. display: flex;
  5354. gap: 8px;
  5355. flex-wrap: wrap;
  5356. }
  5357. .right-actions {
  5358. display: flex;
  5359. gap: 8px;
  5360. }
  5361. .action-btn {
  5362. background: none;
  5363. color: #6b7280;
  5364. border: none;
  5365. border-radius: 6px;
  5366. padding: 6px 5px;
  5367. font-size: 14px;
  5368. cursor: pointer;
  5369. transition: all 0.3s ease;
  5370. display: flex;
  5371. align-items: center;
  5372. gap: 4px;
  5373. white-space: nowrap;
  5374. &:hover:not(:disabled) {
  5375. background-color: #f3f4f6;
  5376. }
  5377. &:disabled {
  5378. cursor: not-allowed;
  5379. opacity: 0.6;
  5380. }
  5381. .action-icon {
  5382. width: 16px;
  5383. height: 16px;
  5384. }
  5385. // 点赞和点踩按钮的特殊样式
  5386. &.thumbs-up-btn {
  5387. transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  5388. &:hover:not(:disabled) {
  5389. color: #059669;
  5390. transform: scale(1.1);
  5391. background-color: rgba(5, 150, 105, 0.1);
  5392. }
  5393. &.active {
  5394. color: #059669;
  5395. transform: scale(1.2);
  5396. .action-icon {
  5397. filter: brightness(0) saturate(100%) invert(27%) sepia(51%) saturate(2878%) hue-rotate(142deg) brightness(104%) contrast(97%) !important;
  5398. }
  5399. }
  5400. &:active {
  5401. transform: scale(0.9);
  5402. transition: all 0.1s ease;
  5403. }
  5404. }
  5405. &.thumbs-down-btn {
  5406. transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  5407. &:hover:not(:disabled) {
  5408. color: #dc2626;
  5409. transform: scale(1.1);
  5410. background-color: rgba(220, 38, 38, 0.1);
  5411. }
  5412. &.active {
  5413. color: #dc2626;
  5414. transform: scale(1.2);
  5415. .action-icon {
  5416. filter: brightness(0) saturate(100%) invert(27%) sepia(51%) saturate(2878%) hue-rotate(0deg) brightness(104%) contrast(97%) !important;
  5417. }
  5418. }
  5419. &:active {
  5420. transform: scale(0.9);
  5421. transition: all 0.1s ease;
  5422. }
  5423. }
  5424. }
  5425. .feedback-icon {
  5426. width: 16px;
  5427. height: 16px;
  5428. cursor: pointer;
  5429. transition: opacity 0.3s ease;
  5430. margin: 0 5px;
  5431. &:hover {
  5432. opacity: 0.7;
  5433. }
  5434. }
  5435. }
  5436. }
  5437. }
  5438. }
  5439. &.generating {
  5440. display: flex;
  5441. align-items: flex-start;
  5442. gap: 12px;
  5443. width: 100%;
  5444. .ai-avatar {
  5445. flex-shrink: 0;
  5446. .avatar-img {
  5447. width: 40px;
  5448. height: 40px;
  5449. border-radius: 8px;
  5450. background: #3e7bfa;
  5451. display: flex;
  5452. align-items: center;
  5453. justify-content: center;
  5454. color: white;
  5455. font-weight: bold;
  5456. font-size: 16px;
  5457. }
  5458. }
  5459. .message-content {
  5460. background: #fff;
  5461. border: 1px solid #e2e8f0;
  5462. color: #000;
  5463. padding: 12px 16px;
  5464. border-radius: 12px;
  5465. font-size: 16px;
  5466. line-height: 1.6;
  5467. max-width: fit-content;
  5468. min-width: 120px;
  5469. display: flex;
  5470. align-items: center;
  5471. gap: 12px;
  5472. .generating-text {
  5473. color: #6b7280;
  5474. font-size: 14px;
  5475. white-space: nowrap;
  5476. }
  5477. .loading-dots {
  5478. display: flex;
  5479. gap: 4px;
  5480. span {
  5481. width: 6px;
  5482. height: 6px;
  5483. background: #3e7bfa;
  5484. border-radius: 50%;
  5485. animation: loading 1.4s infinite ease-in-out;
  5486. &:nth-child(1) { animation-delay: -0.32s; }
  5487. &:nth-child(2) { animation-delay: -0.16s; }
  5488. &:nth-child(3) { animation-delay: 0s; }
  5489. }
  5490. }
  5491. }
  5492. }
  5493. }
  5494. @keyframes loading {
  5495. 0%, 80%, 100% {
  5496. transform: scale(0);
  5497. opacity: 0.5;
  5498. }
  5499. 40% {
  5500. transform: scale(1);
  5501. opacity: 1;
  5502. }
  5503. }
  5504. /* 自定义滚动条样式 */
  5505. &::-webkit-scrollbar {
  5506. width: 0; /* 隐藏滚动条 */
  5507. }
  5508. &::-webkit-scrollbar-track {
  5509. display: none; /* 隐藏滚动条轨道 */
  5510. }
  5511. &::-webkit-scrollbar-thumb {
  5512. display: none; /* 隐藏滚动条滑块 */
  5513. }
  5514. &::-webkit-scrollbar-thumb:hover {
  5515. display: none; /* 隐藏滚动条滑块悬停状态 */
  5516. }
  5517. }
  5518. // 输入框区域样式
  5519. .input-section {
  5520. background: white;
  5521. display: flex;
  5522. flex-direction: column;
  5523. align-items: center;
  5524. width: 100%;
  5525. position: sticky; /* 固定在底部 */
  5526. bottom: 0;
  5527. padding-top: 32px; /* 增加上方间距 */
  5528. // padding: 320px 0;
  5529. // border-top: 16px solid #e5e7eb;
  5530. z-index: 10;
  5531. transition: none; /* 移除过渡动画,提高响应速度 */
  5532. will-change: transform; /* 优化渲染性能 */
  5533. // 文件预览区域样式
  5534. .file-preview-section {
  5535. margin-bottom: 12px;
  5536. width: 100%;
  5537. max-width: 780px;
  5538. .file-preview {
  5539. position: relative;
  5540. display: flex;
  5541. align-items: center;
  5542. background: rgba(255, 255, 255, 0.9);
  5543. border: 1px solid #E5E7EB;
  5544. border-radius: 12px;
  5545. padding: 12px;
  5546. max-width: 400px;
  5547. .file-icon {
  5548. font-size: 32px;
  5549. margin-right: 12px;
  5550. width: 48px;
  5551. text-align: center;
  5552. .file-icon-img {
  5553. width: 32px;
  5554. height: 32px;
  5555. object-fit: contain;
  5556. }
  5557. }
  5558. .file-info {
  5559. flex: 1;
  5560. .file-name {
  5561. font-size: 14px;
  5562. font-weight: 500;
  5563. color: #374151;
  5564. margin-bottom: 4px;
  5565. overflow: hidden;
  5566. text-overflow: ellipsis;
  5567. white-space: nowrap;
  5568. max-width: 200px;
  5569. }
  5570. .file-size {
  5571. font-size: 12px;
  5572. color: #6B7280;
  5573. }
  5574. }
  5575. .remove-file-btn {
  5576. width: 24px;
  5577. height: 24px;
  5578. border: none;
  5579. background: rgba(239, 68, 68, 0.1);
  5580. color: #DC2626;
  5581. border-radius: 50%;
  5582. cursor: pointer;
  5583. display: flex;
  5584. align-items: center;
  5585. justify-content: center;
  5586. transition: all 0.2s ease;
  5587. &:hover {
  5588. background: rgba(239, 68, 68, 0.2);
  5589. transform: scale(1.1);
  5590. }
  5591. .remove-icon {
  5592. font-size: 16px;
  5593. font-weight: bold;
  5594. }
  5595. }
  5596. }
  5597. }
  5598. .input-container {
  5599. width: 100%;
  5600. max-width: 780px; // 固定最大宽度
  5601. display: flex;
  5602. align-items: center;
  5603. gap: 12px;
  5604. border: 1px solid #3e7bfa;
  5605. border-radius: 16px;
  5606. padding: 12px 16px;
  5607. background: white;
  5608. .attachment-btn,
  5609. .voice-btn {
  5610. background: none;
  5611. border: none;
  5612. cursor: pointer;
  5613. padding: 8px 8px 4px 8px;
  5614. border-radius: 6px;
  5615. transition: all 0.3s ease;
  5616. position: relative;
  5617. &:hover:not(:disabled) {
  5618. background-color: #f3f4f6;
  5619. }
  5620. &.recording {
  5621. background: rgba(239, 68, 68, 0.1);
  5622. animation: pulse 1.5s ease-in-out infinite;
  5623. }
  5624. .icon-container {
  5625. position: relative;
  5626. display: flex;
  5627. align-items: center;
  5628. justify-content: center;
  5629. }
  5630. .recording-indicator {
  5631. position: absolute;
  5632. top: -2px;
  5633. right: -2px;
  5634. width: 8px;
  5635. height: 8px;
  5636. background: #ef4444;
  5637. border-radius: 50%;
  5638. animation: blink 1s ease-in-out infinite;
  5639. }
  5640. &:disabled {
  5641. cursor: not-allowed;
  5642. opacity: 0.6;
  5643. }
  5644. .action-icon {
  5645. width: 20px;
  5646. height: 20px;
  5647. object-fit: contain;
  5648. }
  5649. }
  5650. .message-input {
  5651. flex: 1;
  5652. border: none;
  5653. outline: none;
  5654. font-size: 16px;
  5655. color: #374151;
  5656. background: transparent;
  5657. min-width: 0;
  5658. &::placeholder {
  5659. color: #9ca3af;
  5660. }
  5661. &:disabled {
  5662. cursor: not-allowed;
  5663. opacity: 0.6;
  5664. background-color: #f9fafb;
  5665. }
  5666. }
  5667. .divider {
  5668. width: 1px;
  5669. height: 31px;
  5670. background: #d6d5de;
  5671. }
  5672. .send-btn {
  5673. background: none;
  5674. border: none;
  5675. cursor: pointer;
  5676. padding: 0;
  5677. border-radius: 6px;
  5678. transition: background-color 0.3s ease;
  5679. min-width: 90px; /* 确保最小宽度 */
  5680. height: 40px; /* 确保高度 */
  5681. display: flex;
  5682. align-items: center;
  5683. justify-content: center;
  5684. &:disabled {
  5685. cursor: not-allowed;
  5686. opacity: 0.6;
  5687. }
  5688. &:hover:not(:disabled) {
  5689. background-color: #f3f4f6;
  5690. }
  5691. .action-icon {
  5692. width: 90px;
  5693. height: 40px;
  5694. object-fit: contain; /* 确保图标不被压缩 */
  5695. }
  5696. }
  5697. }
  5698. }
  5699. }
  5700. .right-column {
  5701. width: 50%; // 改为50%,与左侧列相等
  5702. padding-left: 31px; // 减少左边距,让分隔线更贴近
  5703. border-left: 1px solid #e5e7eb;
  5704. display: flex;
  5705. flex-direction: column;
  5706. transform: translateX(100%); // 初始状态:向右偏移隐藏
  5707. opacity: 0; // 初始状态:透明
  5708. transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); // 平滑过渡
  5709. .document-header {
  5710. display: flex;
  5711. justify-content: space-between;
  5712. align-items: center;
  5713. margin-bottom: 16px;
  5714. padding-bottom: 16px;
  5715. // border-bottom: 1px solid #e5e7eb;
  5716. transform: translateY(20px); // 初始状态:向下偏移
  5717. opacity: 0; // 初始状态:透明
  5718. transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1) 0.1s; // 延迟动画
  5719. .doc-title {
  5720. font-size: 22px;
  5721. font-weight: 600;
  5722. color: #1f2937;
  5723. margin: 0;
  5724. }
  5725. .doc-actions {
  5726. display: flex;
  5727. gap: 10px;
  5728. align-items: center;
  5729. .action-btn {
  5730. background: none;
  5731. border: none;
  5732. color: #6b7280;
  5733. font-size: 14px;
  5734. cursor: pointer;
  5735. padding: 8px;
  5736. border-radius: 6px;
  5737. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); // 统一缓动函数
  5738. display: flex;
  5739. align-items: center;
  5740. gap: 6px;
  5741. &:hover {
  5742. background: #f3f4f6;
  5743. color: #374151;
  5744. transform: translateY(-1px); // 悬停时轻微上移
  5745. }
  5746. .action-icon {
  5747. width: 16px;
  5748. height: 16px;
  5749. }
  5750. }
  5751. .close-btn {
  5752. background: none;
  5753. border: none;
  5754. color: #6b7280;
  5755. font-size: 14px;
  5756. cursor: pointer;
  5757. padding: 8px;
  5758. border-radius: 6px;
  5759. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); // 统一缓动函数
  5760. display: flex;
  5761. align-items: center;
  5762. gap: 6px;
  5763. &:hover {
  5764. background: #f3f4f6;
  5765. color: #374151;
  5766. transform: translateY(-1px); // 悬停时轻微上移
  5767. }
  5768. }
  5769. }
  5770. }
  5771. .document-body {
  5772. transform: translateY(20px); // 初始状态:向下偏移
  5773. opacity: 0; // 初始状态:透明
  5774. transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1) 0.2s; // 延迟动画
  5775. max-height: calc(100vh - 300px); // 设置最大高度
  5776. overflow-y: auto; // 添加垂直滚动条
  5777. .doc-section {
  5778. margin-bottom: 16px; // 减少section之间的间距
  5779. .section-content {
  5780. font-size: 16px;
  5781. line-height: 1.6;
  5782. color: #374151;
  5783. margin: 0;
  5784. text-align: justify;
  5785. padding-right: 16px; // 添加右边距,让文字和滚动条之间有间距
  5786. // 调整富文本元素的间距
  5787. h1, h2, h3 {
  5788. margin: 16px 0 8px 0; // 标题的上下间距
  5789. font-weight: 600;
  5790. color: #1f2937;
  5791. }
  5792. h1 {
  5793. font-size: 20px;
  5794. }
  5795. h2 {
  5796. font-size: 18px;
  5797. }
  5798. h3 {
  5799. font-size: 16px;
  5800. }
  5801. p {
  5802. margin: 8px 0; // 段落间距
  5803. }
  5804. li {
  5805. margin: 4px 0; // 列表项间距
  5806. }
  5807. .list-item {
  5808. margin: 4px 0; // 列表项间距
  5809. padding-left: 8px; // 轻微缩进
  5810. }
  5811. ul, ol {
  5812. margin: 8px 0;
  5813. padding-left: 20px;
  5814. }
  5815. }
  5816. }
  5817. /* 自定义滚动条样式 */
  5818. &::-webkit-scrollbar {
  5819. width: 6px;
  5820. }
  5821. &::-webkit-scrollbar-track {
  5822. background: #f1f1f1;
  5823. border-radius: 3px;
  5824. }
  5825. &::-webkit-scrollbar-thumb {
  5826. background: #c1c1c1;
  5827. border-radius: 3px;
  5828. }
  5829. &::-webkit-scrollbar-thumb:hover {
  5830. background: #a8a8a8;
  5831. }
  5832. }
  5833. }
  5834. // 当显示文档预览时,右侧列显示
  5835. &.with-document {
  5836. .right-column {
  5837. transform: translateX(0);
  5838. opacity: 1;
  5839. .document-header,
  5840. .document-body {
  5841. transform: translateY(0);
  5842. opacity: 1;
  5843. }
  5844. }
  5845. }
  5846. }
  5847. .history-card {
  5848. display: flex;
  5849. align-items: center;
  5850. gap: 16px;
  5851. padding: 20px 32px;
  5852. background: #f9fafb;
  5853. border-top: 1px solid #e5e7eb;
  5854. border-bottom: 1px solid #e5e7eb;
  5855. .card-icon {
  5856. .doc-icon {
  5857. width: 48px;
  5858. height: 48px;
  5859. }
  5860. }
  5861. .card-content {
  5862. .card-title {
  5863. font-size: 18px;
  5864. font-weight: 600;
  5865. color: #1f2937;
  5866. margin-bottom: 4px;
  5867. }
  5868. .card-time {
  5869. font-size: 14px;
  5870. color: #6b7280;
  5871. }
  5872. }
  5873. }
  5874. .follow-up-text {
  5875. padding: 24px 32px;
  5876. font-size: 16px;
  5877. color: #374151;
  5878. line-height: 1.6;
  5879. background: white;
  5880. }
  5881. }
  5882. /* 中间历史记录栏 */
  5883. .history-sidebar {
  5884. width: 280px;
  5885. background: #e8f0ff;
  5886. display: flex;
  5887. flex-direction: column;
  5888. }
  5889. /* 中间历史记录栏样式 */
  5890. .history-sidebar {
  5891. padding: 24px 16px 0 16px;
  5892. .history-header {
  5893. background: transparent;
  5894. .section-title {
  5895. font-size: 16px;
  5896. font-weight: 600;
  5897. color: #2c3e50;
  5898. }
  5899. .new-chat-btn {
  5900. width: 248px;
  5901. height: 40px;
  5902. cursor: pointer;
  5903. transition: opacity 0.3s ease;
  5904. object-fit: contain;
  5905. display: block;
  5906. margin-top: 16px;
  5907. margin-bottom: 16px;
  5908. &:hover {
  5909. opacity: 0.8;
  5910. }
  5911. &.disabled {
  5912. cursor: not-allowed;
  5913. opacity: 0.6;
  5914. &:hover {
  5915. opacity: 0.6;
  5916. }
  5917. }
  5918. }
  5919. }
  5920. .history-list {
  5921. flex: 1;
  5922. overflow-y: auto;
  5923. width: 248px;
  5924. height: 64px;
  5925. /* 隐藏滚动条 */
  5926. &::-webkit-scrollbar {
  5927. display: none;
  5928. }
  5929. -ms-overflow-style: none; /* IE and Edge */
  5930. scrollbar-width: none; /* Firefox */
  5931. .history-item {
  5932. background: white;
  5933. border-radius: 8px;
  5934. padding: 15px;
  5935. margin-bottom: 8px;
  5936. cursor: pointer;
  5937. transition: all 0.3s ease;
  5938. border-left: 3px solid transparent;
  5939. box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  5940. display: flex;
  5941. align-items: center;
  5942. justify-content: space-between;
  5943. position: relative;
  5944. &:hover {
  5945. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  5946. .delete-btn {
  5947. opacity: 1;
  5948. visibility: visible;
  5949. }
  5950. }
  5951. &.active {
  5952. border-left-color: #3e7bfa;
  5953. box-shadow: 0 2px 8px rgba(62, 123, 250, 0.2);
  5954. cursor: default;
  5955. opacity: 0.8;
  5956. &:hover {
  5957. transform: none;
  5958. box-shadow: 0 2px 8px rgba(62, 123, 250, 0.2);
  5959. }
  5960. }
  5961. .history-content {
  5962. flex: 1;
  5963. min-width: 0; // 允许内容收缩
  5964. }
  5965. .history-title {
  5966. font-size: 14px;
  5967. line-height: 1.4;
  5968. margin-bottom: 6px;
  5969. color: #2c3e50;
  5970. overflow: hidden;
  5971. text-overflow: ellipsis;
  5972. white-space: nowrap;
  5973. }
  5974. .history-time {
  5975. font-size: 12px;
  5976. color: #7c8db5;
  5977. }
  5978. .delete-btn {
  5979. opacity: 0;
  5980. visibility: hidden;
  5981. transition: all 0.2s ease;
  5982. cursor: pointer;
  5983. padding: 4px;
  5984. border-radius: 4px;
  5985. color: #7c8db5;
  5986. display: flex;
  5987. align-items: center;
  5988. justify-content: center;
  5989. margin-left: 8px;
  5990. flex-shrink: 0;
  5991. &:hover {
  5992. color: #ff4757;
  5993. background-color: rgba(255, 71, 87, 0.1);
  5994. }
  5995. &.always-visible {
  5996. opacity: 1;
  5997. visibility: visible;
  5998. }
  5999. }
  6000. }
  6001. .empty-history {
  6002. display: flex;
  6003. flex-direction: column;
  6004. align-items: center;
  6005. justify-content: center;
  6006. margin-top: 236px;
  6007. .empty-icon {
  6008. width: 147px;
  6009. height: 148px;
  6010. object-fit: contain;
  6011. margin-bottom: 16px;
  6012. }
  6013. .empty-text {
  6014. font-size: 16px;
  6015. color: #9C9FA7;
  6016. text-align: center;
  6017. }
  6018. }
  6019. }
  6020. }
  6021. /* 主工作区域 */
  6022. .main-work {
  6023. flex: 1;
  6024. background: #ebf3ff;
  6025. display: flex;
  6026. flex-direction: column;
  6027. }
  6028. /* 富文本编辑器样式 */
  6029. .editor-view {
  6030. position: relative;
  6031. width: 100%;
  6032. max-width: 1528px;
  6033. background: white;
  6034. border-radius: 12px;
  6035. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  6036. display: flex;
  6037. flex-direction: column;
  6038. // height: calc(100vh - 40px);
  6039. // margin: -20px;
  6040. // overflow: hidden;
  6041. }
  6042. .editor-header {
  6043. display: flex;
  6044. justify-content: space-between;
  6045. align-items: center;
  6046. padding: 24px 32px;
  6047. border-bottom: 1px solid #e5e7eb;
  6048. background: #f9fafb;
  6049. }
  6050. .editor-title h3 {
  6051. margin: 0;
  6052. font-size: 24px;
  6053. font-weight: 600;
  6054. color: #1f2937;
  6055. }
  6056. .editor-subtitle {
  6057. margin: 4px 0 0 0;
  6058. font-size: 14px;
  6059. color: #6b7280;
  6060. }
  6061. .editor-actions {
  6062. display: flex;
  6063. gap: 12px;
  6064. }
  6065. .back-btn, .save-btn, .download-btn {
  6066. display: flex;
  6067. align-items: center;
  6068. gap: 8px;
  6069. padding: 7px 20px;
  6070. border: none;
  6071. border-radius: 8px;
  6072. font-size: 14px;
  6073. font-weight: 500;
  6074. cursor: pointer;
  6075. transition: all 0.2s ease;
  6076. }
  6077. .back-btn {
  6078. background: #f3f4f6;
  6079. color: #374151;
  6080. }
  6081. .back-btn:hover {
  6082. background: #e5e7eb;
  6083. }
  6084. .save-btn {
  6085. background: #3b82f6;
  6086. color: white;
  6087. }
  6088. .save-btn:hover {
  6089. background: #2563eb;
  6090. }
  6091. .download-btn {
  6092. border: none;
  6093. background: transparent;
  6094. cursor: pointer;
  6095. transition: opacity 0.3s ease;
  6096. padding: 0;
  6097. }
  6098. .download-btn:hover {
  6099. opacity: 0.8;
  6100. }
  6101. .download-icon {
  6102. width: 107px;
  6103. height: 34px;
  6104. }
  6105. .action-icon {
  6106. width: 16px;
  6107. height: 16px;
  6108. }
  6109. .editor-content {
  6110. flex: 1;
  6111. display: flex;
  6112. flex-direction: column;
  6113. overflow: auto;
  6114. // background: red;
  6115. min-height: 0;
  6116. padding-bottom: 10px;
  6117. }
  6118. /* 富文本工具栏样式 */
  6119. .editor-toolbar {
  6120. display: flex;
  6121. align-items: center;
  6122. padding: 12px 16px;
  6123. background: #f8f9fa;
  6124. border-bottom: 1px solid #e5e7eb;
  6125. gap: 8px;
  6126. flex-wrap: wrap;
  6127. }
  6128. .toolbar-group {
  6129. display: flex;
  6130. align-items: center;
  6131. gap: 4px;
  6132. }
  6133. .toolbar-divider {
  6134. width: 1px;
  6135. height: 24px;
  6136. background: #d1d5db;
  6137. margin: 0 8px;
  6138. }
  6139. .toolbar-btn {
  6140. display: flex;
  6141. align-items: center;
  6142. justify-content: center;
  6143. width: 32px;
  6144. height: 32px;
  6145. border: 1px solid #d1d5db;
  6146. background: white;
  6147. border-radius: 4px;
  6148. cursor: pointer;
  6149. font-size: 14px;
  6150. font-weight: 500;
  6151. color: #374151;
  6152. transition: all 0.2s ease;
  6153. }
  6154. .toolbar-btn:hover {
  6155. background: #f3f4f6;
  6156. border-color: #9ca3af;
  6157. }
  6158. .toolbar-btn:active {
  6159. background: #e5e7eb;
  6160. transform: translateY(1px);
  6161. }
  6162. .toolbar-btn:disabled {
  6163. background: #f9fafb;
  6164. color: #9ca3af;
  6165. cursor: not-allowed;
  6166. opacity: 0.6;
  6167. }
  6168. .toolbar-btn:disabled:hover {
  6169. background: #f9fafb;
  6170. border-color: #d1d5db;
  6171. transform: none;
  6172. }
  6173. .toolbar-btn strong {
  6174. font-weight: bold;
  6175. }
  6176. .toolbar-btn em {
  6177. font-style: italic;
  6178. }
  6179. .toolbar-btn u {
  6180. text-decoration: underline;
  6181. }
  6182. .font-size-select, .font-family-select {
  6183. height: 32px;
  6184. padding: 4px 8px;
  6185. border: 1px solid #d1d5db;
  6186. background: white;
  6187. border-radius: 4px;
  6188. font-size: 14px;
  6189. color: #374151;
  6190. cursor: pointer;
  6191. transition: all 0.2s ease;
  6192. min-width: 80px;
  6193. }
  6194. .font-size-select:hover, .font-family-select:hover {
  6195. border-color: #9ca3af;
  6196. }
  6197. .font-size-select:focus, .font-family-select:focus {
  6198. outline: none;
  6199. border-color: #3b82f6;
  6200. box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  6201. }
  6202. .rich-editor-container {
  6203. flex: 1;
  6204. padding: 0px 32px 20px 32px;
  6205. overflow: hidden;
  6206. background: white;
  6207. border-radius: 8px;
  6208. display: flex;
  6209. flex-direction: column;
  6210. min-height: 0;
  6211. }
  6212. /* 富文本编辑器工具栏样式 */
  6213. .rich-editor-toolbar {
  6214. border-bottom: 1px solid #ccc;
  6215. }
  6216. /* wangeditor 编辑器基础样式 */
  6217. .rich-editor-container .w-e-scroll {
  6218. border: 1px solid #e5e7eb !important;
  6219. border-radius: 8px !important;
  6220. font-size: 16px;
  6221. line-height: 1.6;
  6222. background: white !important;
  6223. }
  6224. /* 禁用wangeditor自带的弹出菜单 */
  6225. .rich-editor-container .w-e-hover-bar {
  6226. display: none !important;
  6227. }
  6228. .rich-editor-container .w-e-menu-tooltip {
  6229. display: none !important;
  6230. }
  6231. .rich-editor-container .w-e-menu {
  6232. display: none !important;
  6233. }
  6234. .rich-editor-container .w-e-menu-panel {
  6235. display: none !important;
  6236. }
  6237. .rich-editor-container .w-e-menu-item {
  6238. display: none !important;
  6239. }
  6240. /* 禁用右键菜单 */
  6241. .rich-editor-container .w-e-text-container {
  6242. -webkit-user-select: text !important;
  6243. -moz-user-select: text !important;
  6244. -ms-user-select: text !important;
  6245. user-select: text !important;
  6246. }
  6247. .rich-editor-container .w-e-text-container * {
  6248. -webkit-user-select: text !important;
  6249. -moz-user-select: text !important;
  6250. -ms-user-select: text !important;
  6251. user-select: text !important;
  6252. }
  6253. /* 润色时禁用文本选择 */
  6254. .rich-editor-container.polishing .w-e-text-container {
  6255. -webkit-user-select: none !important;
  6256. -moz-user-select: none !important;
  6257. -ms-user-select: none !important;
  6258. user-select: none !important;
  6259. pointer-events: none !important;
  6260. }
  6261. .rich-editor-container.polishing .w-e-text-container * {
  6262. -webkit-user-select: none !important;
  6263. -moz-user-select: none !important;
  6264. -ms-user-select: none !important;
  6265. user-select: none !important;
  6266. pointer-events: none !important;
  6267. }
  6268. .rich-editor-container .w-e-toolbar {
  6269. border: 1px solid #e5e7eb !important;
  6270. border-bottom: none !important;
  6271. border-radius: 8px 8px 0 0 !important;
  6272. padding: 12px 0 !important;
  6273. background: white !important;
  6274. }
  6275. .rich-editor {
  6276. min-height: 100%;
  6277. padding: 24px;
  6278. border: 1px solid #e5e7eb;
  6279. border-radius: 8px;
  6280. background: white;
  6281. font-size: 16px;
  6282. line-height: 1.6;
  6283. color: #1f2937;
  6284. outline: none;
  6285. transition: border-color 0.2s ease;
  6286. }
  6287. .rich-editor:focus {
  6288. border-color: #3b82f6;
  6289. box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  6290. }
  6291. .rich-editor h2 {
  6292. font-size: 24px;
  6293. font-weight: 600;
  6294. color: #1f2937;
  6295. margin: 24px 0 16px 0;
  6296. padding-bottom: 8px;
  6297. border-bottom: 2px solid #e5e7eb;
  6298. }
  6299. .rich-editor h3 {
  6300. font-size: 20px;
  6301. font-weight: 600;
  6302. color: #374151;
  6303. margin: 20px 0 12px 0;
  6304. }
  6305. .rich-editor h4 {
  6306. font-size: 18px;
  6307. font-weight: 600;
  6308. color: #4b5563;
  6309. margin: 16px 0 8px 0;
  6310. }
  6311. .rich-editor p {
  6312. margin: 12px 0;
  6313. text-align: justify;
  6314. }
  6315. .rich-editor ul, .rich-editor ol {
  6316. margin: 12px 0;
  6317. padding-left: 24px;
  6318. }
  6319. .rich-editor li {
  6320. margin: 4px 0;
  6321. }
  6322. .rich-editor blockquote {
  6323. margin: 16px 0;
  6324. padding: 16px 20px;
  6325. background: #f9fafb;
  6326. border-left: 4px solid #3b82f6;
  6327. border-radius: 0 8px 8px 0;
  6328. font-style: italic;
  6329. color: #4b5563;
  6330. }
  6331. /* 工作头部 */
  6332. .work-header {
  6333. background: transparent;
  6334. padding: 30px 0px 0px 18px;
  6335. h2 {
  6336. margin: 0;
  6337. font-size: 20px;
  6338. font-weight: 600;
  6339. color: #2c3e50;
  6340. }
  6341. }
  6342. /* 响应式设计 */
  6343. /* @media (max-width: 16384px) {
  6344. .history-sidebar {
  6345. width: 4000px;
  6346. }
  6347. }
  6348. @media (max-width: 14400px) {
  6349. .history-sidebar {
  6350. width: 3840px;
  6351. }
  6352. }
  6353. @media (max-width: 12288px) {
  6354. .chat-container {
  6355. flex-direction: column;
  6356. }
  6357. .history-sidebar {
  6358. width: 100%;
  6359. height: 3200px;
  6360. order: 2;
  6361. .history-list {
  6362. .history-item {
  6363. padding: 160px 320px;
  6364. .history-title {
  6365. font-size: 208px;
  6366. }
  6367. }
  6368. }
  6369. }
  6370. .main-work {
  6371. order: 1;
  6372. }
  6373. .work-content {
  6374. padding: 320px 256px;
  6375. }
  6376. } */
  6377. /* 点赞和点踩按钮的图标颜色变化 */
  6378. .thumbs-up-btn.active .action-icon {
  6379. /* 绿色图标 */
  6380. filter: brightness(0) saturate(100%) invert(27%) sepia(51%) saturate(2878%) hue-rotate(142deg) brightness(104%) contrast(97%) !important;
  6381. }
  6382. .thumbs-down-btn.active .action-icon {
  6383. /* 红色图标 */
  6384. filter: brightness(0) saturate(100%) invert(27%) sepia(51%) saturate(2878%) hue-rotate(0deg) brightness(104%) contrast(97%) !important;
  6385. }
  6386. /* 历史记录加载状态样式 */
  6387. .history-loading {
  6388. display: flex;
  6389. flex-direction: column;
  6390. align-items: center;
  6391. justify-content: center;
  6392. padding: 40px 20px;
  6393. min-height: 200px;
  6394. }
  6395. .history-loading .loading-spinner {
  6396. width: 32px;
  6397. height: 32px;
  6398. border: 3px solid #f3f3f3;
  6399. border-top: 3px solid #409eff;
  6400. border-radius: 50%;
  6401. animation: spin 1s linear infinite;
  6402. margin: 0 auto 16px auto;
  6403. }
  6404. .history-loading .loading-text {
  6405. color: #6B7280;
  6406. font-size: 14px;
  6407. margin: 0;
  6408. font-weight: 400;
  6409. }
  6410. /* 编辑器全屏加载状态样式 */
  6411. .editor-full-loading {
  6412. position: absolute;
  6413. top: 0;
  6414. left: 0;
  6415. right: 0;
  6416. bottom: 0;
  6417. display: flex;
  6418. flex-direction: column;
  6419. align-items: center;
  6420. justify-content: center;
  6421. background: rgba(255, 255, 255, 0.95);
  6422. backdrop-filter: blur(4px);
  6423. z-index: 1000;
  6424. border-radius: 12px;
  6425. }
  6426. .editor-full-loading .loading-spinner {
  6427. width: 48px;
  6428. height: 48px;
  6429. border: 4px solid #f3f3f3;
  6430. border-top: 4px solid #3b82f6;
  6431. border-radius: 50%;
  6432. animation: spin 1s linear infinite;
  6433. margin: 0 auto 24px auto;
  6434. }
  6435. .editor-full-loading .loading-text {
  6436. color: #374151;
  6437. font-size: 18px;
  6438. margin: 0;
  6439. font-weight: 500;
  6440. }
  6441. @keyframes spin {
  6442. 0% { transform: rotate(0deg); }
  6443. 100% { transform: rotate(360deg); }
  6444. }
  6445. /* 详情页加载状态样式 */
  6446. .detail-loading {
  6447. position: absolute;
  6448. top: 0;
  6449. left: 0;
  6450. right: 0;
  6451. bottom: 0;
  6452. display: flex;
  6453. flex-direction: column;
  6454. align-items: center;
  6455. justify-content: center;
  6456. background: rgba(255, 255, 255, 0.95);
  6457. backdrop-filter: blur(4px);
  6458. z-index: 1000;
  6459. border-radius: 16px;
  6460. }
  6461. .detail-loading .loading-spinner {
  6462. width: 48px;
  6463. height: 48px;
  6464. border: 4px solid #f3f3f3;
  6465. border-top: 4px solid #3b82f6;
  6466. border-radius: 50%;
  6467. animation: spin 1s linear infinite;
  6468. margin: 0 auto 24px auto;
  6469. }
  6470. .detail-loading .loading-text {
  6471. color: #374151;
  6472. font-size: 18px;
  6473. margin: 0;
  6474. font-weight: 500;
  6475. }
  6476. /* AI润色输入框样式 */
  6477. .ai-polish-input {
  6478. position: fixed;
  6479. z-index: 999;
  6480. background: white;
  6481. border-radius: 8px;
  6482. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  6483. transition: all 0.2s ease;
  6484. user-select: none;
  6485. min-width: 300px;
  6486. max-width: 400px;
  6487. }
  6488. .polish-input-container {
  6489. display: flex;
  6490. align-items: center;
  6491. padding: 8px;
  6492. gap: 8px;
  6493. }
  6494. .button-group {
  6495. display: flex;
  6496. align-items: center;
  6497. gap: 6px;
  6498. }
  6499. .input-wrapper {
  6500. flex: 1;
  6501. position: relative;
  6502. }
  6503. .polish-input-field {
  6504. width: 100%;
  6505. border: 1px solid #e5e7eb;
  6506. border-radius: 6px;
  6507. padding: 8px 60px 8px 12px;
  6508. font-size: 14px;
  6509. outline: none;
  6510. transition: border-color 0.2s ease;
  6511. box-sizing: border-box;
  6512. }
  6513. .char-counter {
  6514. position: absolute;
  6515. right: 12px;
  6516. top: 50%;
  6517. transform: translateY(-50%);
  6518. font-size: 12px;
  6519. color: #6b7280;
  6520. pointer-events: none;
  6521. }
  6522. .polish-input-field:focus {
  6523. border-color: #3b82f6;
  6524. box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  6525. }
  6526. .polish-input-field:disabled {
  6527. background-color: #f9fafb;
  6528. color: #6b7280;
  6529. cursor: not-allowed;
  6530. }
  6531. .polish-send-btn {
  6532. background: #3b82f6;
  6533. color: white;
  6534. border: none;
  6535. cursor: pointer;
  6536. padding: 8px 16px;
  6537. border-radius: 6px;
  6538. font-size: 14px;
  6539. font-weight: 500;
  6540. transition: all 0.2s ease;
  6541. min-width: 80px;
  6542. }
  6543. .polish-send-btn:hover:not(:disabled) {
  6544. background-color: #2563eb;
  6545. }
  6546. .polish-send-btn:disabled {
  6547. cursor: not-allowed;
  6548. opacity: 0.6;
  6549. background-color: #9ca3af;
  6550. }
  6551. .continue-btn {
  6552. background: #10b981;
  6553. }
  6554. .continue-btn:hover:not(:disabled) {
  6555. background-color: #059669;
  6556. }
  6557. .polish-loading {
  6558. display: flex;
  6559. align-items: center;
  6560. justify-content: center;
  6561. gap: 8px;
  6562. }
  6563. .polish-loading .loading-spinner {
  6564. width: 16px;
  6565. height: 16px;
  6566. border: 2px solid rgba(255, 255, 255, 0.3);
  6567. border-top: 2px solid white;
  6568. border-radius: 50%;
  6569. animation: spin 1s linear infinite;
  6570. }
  6571. @keyframes pulse {
  6572. 0%, 100% {
  6573. transform: scale(1);
  6574. opacity: 1;
  6575. }
  6576. 50% {
  6577. transform: scale(1.05);
  6578. opacity: 0.8;
  6579. }
  6580. }
  6581. @keyframes blink {
  6582. 0%, 50% {
  6583. opacity: 1;
  6584. }
  6585. 51%, 100% {
  6586. opacity: 0.3;
  6587. }
  6588. }
  6589. /* 响应式设计 */
  6590. </style>