ss-components.js 383 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074
  1. import { ssIcon, commonIcon } from "./icon-config.js";
  2. import * as IndexComponents from "./ss-index-components.js";
  3. import * as EchartComponents from "./ss-echarts-compnents.js";
  4. import {
  5. isNum,
  6. toStyleStr,
  7. buildThumbUrl,
  8. openServiceDialog,
  9. pickSearchParams,
  10. } from "./tools.js"; // 功能说明:组件内统一构建缩略图URL、打开服务弹窗,减少 JSP 层字段转换 by xu 20260122
  11. import { EVEN_VAR } from "./EventBus.js";
  12. // import * as elements from "../lib/element-plus.js";
  13. (function () {
  14. const {
  15. createApp,
  16. ref,
  17. reactive,
  18. watch,
  19. onMounted,
  20. onBeforeUnmount,
  21. h,
  22. computed,
  23. resolveComponent,
  24. watchEffect,
  25. nextTick,
  26. onVnodeMounted,
  27. Teleport,
  28. inject,
  29. provide,
  30. } = Vue;
  31. // 弹窗默认遮罩z-index
  32. let currentZIndex = 100;
  33. // 目前已存在的弹窗
  34. const topWindow = window.top;
  35. topWindow.dialogInstances = topWindow.dialogInstances || [];
  36. // 新建弹窗
  37. function createSsDialogInstance(setting, callbackEvent) {
  38. currentZIndex += 10; // 动态提升 z-index
  39. const container = document.createElement("div");
  40. document.body.appendChild(container);
  41. const app = Vue.createApp({
  42. render() {
  43. return h(SsDialog, {
  44. ...setting,
  45. zIndex: currentZIndex,
  46. onClose() {
  47. document.body.removeChild(container); // 仅移除弹窗容器
  48. const index = topWindow.dialogInstances.indexOf(app);
  49. if (index > -1) {
  50. topWindow.dialogInstances.splice(index, 1); // 移除实例
  51. }
  52. // 关闭后的回调
  53. if (callbackEvent && typeof callbackEvent === "function") {
  54. callbackEvent();
  55. }
  56. app.unmount(); // 仅卸载弹窗实例
  57. if (container.parentNode) {
  58. container.parentNode.removeChild(container); // 确保移除容器
  59. }
  60. },
  61. });
  62. },
  63. });
  64. topWindow.dialogInstances.push({ app, callbackEvent, container });
  65. app.component("ss-mark", SsMark); // 注册 ss-mark 组件
  66. app.component("ss-icon", SsIcon);
  67. app.component("ss-full-style-header", SsFullStyleHeader); // 注册 ss-full-style-header 组件
  68. app.mount(container);
  69. }
  70. // ss-breadcrumb 一级菜单页面面包屑
  71. const SsBreadcrumb = {
  72. name: "SsBreadcrumb",
  73. props: {
  74. level: {
  75. type: Object,
  76. default: null,
  77. },
  78. },
  79. setup(props) {
  80. const currentMenu = ref(null);
  81. const folderPath = ref([]);
  82. const eventBus = window.parent.sharedEventBus;
  83. // 监听页面变化
  84. onMounted(() => {
  85. // 获取初始页面
  86. currentMenu.value = eventBus.getState(EVEN_VAR.currentPage);
  87. folderPath.value = eventBus.getState("folderPath") || [];
  88. // 订阅页面变化
  89. eventBus.subscribe(EVEN_VAR.currentPage, (page) => {
  90. currentMenu.value = page;
  91. });
  92. eventBus.subscribe("folderPath", (path) => {
  93. folderPath.value = path || [];
  94. });
  95. });
  96. // 修改点击处理函数
  97. const handlePathClick = (index) => {
  98. if (props.level?.onBack) {
  99. // 截取到点击的位置,后面的路径会被销毁
  100. const newPath = folderPath.value.slice(0, index + 1);
  101. eventBus.publish("folderPath", newPath);
  102. // 返回到对应层级
  103. const targetFolder = newPath[newPath.length - 1]?.folder || null;
  104. props.level.onBack(targetFolder);
  105. }
  106. };
  107. const SsCommonIcon = resolveComponent("SsCommonIcon");
  108. return () =>
  109. h("div", { class: "bread-crumb" }, [
  110. currentMenu.value &&
  111. h(
  112. "div",
  113. {
  114. onClick: () => {
  115. if (props.level?.onBack) {
  116. eventBus.publish("folderPath", []);
  117. props.level.onBack(null); // 返回到根目录
  118. } else {
  119. eventBus.publish(EVEN_VAR.currentPage, currentMenu.value);
  120. }
  121. },
  122. },
  123. currentMenu.value.label || currentMenu.value.name
  124. ),
  125. ...(folderPath.value || [])
  126. .map((folder, index) => [
  127. h(SsCommonIcon, { class: "common-icon-arrow-right" }),
  128. h(
  129. "div",
  130. {
  131. class: "bread-crumb-item",
  132. onClick: () => handlePathClick(index),
  133. style: { cursor: "pointer" },
  134. },
  135. folder.title
  136. ),
  137. ])
  138. .flat(),
  139. ]);
  140. },
  141. };
  142. // ss-input form表单的输入
  143. const SsInput = {
  144. name: "SsInp", //把SsInput改为SsInp Ben(20251225)
  145. inheritAttrs: false, // 不直接继承属性到组件根元素
  146. props: {
  147. name: {
  148. type: String,
  149. required: true,
  150. default: "",
  151. },
  152. // 接收 v-model 绑定的值
  153. errTip: {
  154. type: String,
  155. },
  156. required: {
  157. type: Boolean,
  158. default: false,
  159. },
  160. placeholder: {
  161. type: String,
  162. default: "请输入",
  163. },
  164. defaultValue: [String, Number],
  165. modelValue: [String, Number],
  166. // 新增:附件配置
  167. fj: {
  168. type: Object,
  169. default: null,
  170. },
  171. // 新增:param 配置(用于附件功能)
  172. param: {
  173. type: Object,
  174. default: null,
  175. },
  176. // 新增:高度配置
  177. height: {
  178. type: String,
  179. default: "",
  180. },
  181. // 功能说明:传 height 时允许回车换行(多行输入);未传 height 默认单行 by xu 20260204
  182. },
  183. emits: ["update:modelValue", "input", "blur", "change"], // 允许更新 v-model 绑定的值
  184. setup(props, { emit }) {
  185. const errMsg = ref("");
  186. const inputRef = ref(null);
  187. const textareaRef = ref(null);
  188. const inputValue = ref(props.modelValue || props.defaultValue || "");
  189. const contentFloatingDiv = ref(false); // 控制浮动 DIV 的显示
  190. const floatingDivPosition = ref("bottom"); // 'bottom' 或 'top'
  191. const isFocused = ref(false); // 跟踪焦点状态
  192. // 附件相关变量(仅在传入 param 时初始化)
  193. let fjid = ref(null);
  194. let fjName = null;
  195. let mode = null;
  196. if (props.param && props.param.button) {
  197. fjid = ref(props.param.button.val);
  198. fjName = props.param.button.desc;
  199. mode = props.param.mode;
  200. }
  201. const showRequired = computed(() => {
  202. // 检查是否有验证规则(通过 window.ssVm 判断)
  203. const hasValidationRule = window.ssVm?.validations?.has(props.name);
  204. if (!hasValidationRule) return false;
  205. if (errMsg.value) return true;
  206. if (!inputValue.value) return true;
  207. return false;
  208. });
  209. // 计算floatdiv应该向上还是向下展开
  210. const calculateFloatingDivPosition = () => {
  211. nextTick(() => {
  212. const textarea = inputRef.value;
  213. if (!textarea) return;
  214. const rect = textarea.getBoundingClientRect();
  215. const viewportHeight = window.innerHeight;
  216. // 预估floatdiv的高度(最多5行 * 20px + 上下padding + border)
  217. const estimatedFloatDivHeight = 20 * 5 + 10 + 2; // 5行 + padding + border = 112px
  218. // 检查下方空间
  219. const spaceBelow = viewportHeight - rect.bottom;
  220. // 如果下方空间不足,且上方空间足够,则向上展开
  221. if (
  222. spaceBelow < estimatedFloatDivHeight &&
  223. rect.top > estimatedFloatDivHeight
  224. ) {
  225. floatingDivPosition.value = "top";
  226. } else {
  227. floatingDivPosition.value = "bottom";
  228. }
  229. });
  230. };
  231. // 计算floatdiv的top偏移量
  232. const getFloatingDivTop = computed(() => {
  233. if (props.height) {
  234. // 有height时,padding是5px
  235. return "5px";
  236. } else {
  237. // 没有height时是单行居中,需要计算居中位置
  238. // 假设input-container高度是32px(或者从CSS读取),单行20px
  239. // 居中偏移 = (容器高度 - 行高) / 2 = (32 - 20) / 2 = 6px
  240. return "6px";
  241. }
  242. });
  243. const validate = () => {
  244. if (window.ssVm) {
  245. const result = window.ssVm.validateField(props.name);
  246. console.log(result);
  247. errMsg.value = result.valid ? "" : result.message;
  248. }
  249. };
  250. // 使用 watch 监听 props.errTip 和 props.modelValue 的变化
  251. watch(
  252. () => props.errTip,
  253. (newVal) => {
  254. errMsg.value = newVal;
  255. },
  256. { immediate: true }
  257. );
  258. watch(
  259. () => props.modelValue,
  260. (newVal) => {
  261. inputValue.value = newVal;
  262. }
  263. );
  264. // 挂载时的逻辑
  265. onMounted(() => {
  266. errMsg.value = props.errTip;
  267. inputValue.value = props.modelValue || props.defaultValue || "";
  268. });
  269. // 计算并调整textarea的高度
  270. const adjustHeight = () => {
  271. nextTick(() => {
  272. const textarea = textareaRef.value;
  273. if (!textarea) return;
  274. // floatDiv的textarea始终自动计算高度,不受props.height影响
  275. // 重置高度以获得正确的scrollHeight
  276. textarea.style.height = "auto";
  277. // 计算新高度 - 统一限制为5行
  278. const lineHeight = parseInt(
  279. getComputedStyle(textarea).lineHeight,
  280. 10
  281. );
  282. const maxHeight = lineHeight * 5; // 统一为5行
  283. const newHeight = Math.min(textarea.scrollHeight, maxHeight);
  284. textarea.style.height = `${newHeight}px`;
  285. });
  286. };
  287. // 检查是否应该显示浮动窗口(需要同时满足:有焦点 + 内容超出)
  288. // 修复新增页面点击就出现floatdiv的问题 by xu 20251212
  289. const checkShouldShowFloatingDiv = () => {
  290. const textarea = inputRef.value;
  291. if (!textarea) return false;
  292. // 首先检查是否有内容,没有内容时不显示floatdiv by xu 20251212
  293. if (!inputValue.value || inputValue.value.toString().trim() === "") {
  294. console.log("[floatdiv] 内容为空,不显示floatdiv");
  295. return false;
  296. }
  297. // 判断内容是否超出 by xu 20251212
  298. // 同时检查横向和纵向溢出,任一方向溢出都应显示floatdiv
  299. // 纵向溢出需要加容差值,避免padding/border导致的误判 by xu 20251212
  300. const verticalTolerance = 5; // 容差值5px
  301. const isHorizontalOverflow =
  302. textarea.scrollWidth > textarea.clientWidth;
  303. const isVerticalOverflow =
  304. textarea.scrollHeight > textarea.clientHeight + verticalTolerance;
  305. const isOverflow = isHorizontalOverflow || isVerticalOverflow;
  306. console.log(
  307. "[floatdiv] 溢出检测 - scrollWidth:",
  308. textarea.scrollWidth,
  309. "clientWidth:",
  310. textarea.clientWidth,
  311. "horizontalOverflow:",
  312. isHorizontalOverflow
  313. );
  314. console.log(
  315. "[floatdiv] 溢出检测 - scrollHeight:",
  316. textarea.scrollHeight,
  317. "clientHeight:",
  318. textarea.clientHeight,
  319. "tolerance:",
  320. verticalTolerance,
  321. "verticalOverflow:",
  322. isVerticalOverflow
  323. );
  324. const shouldShow = isFocused.value && isOverflow;
  325. console.log(
  326. "[floatdiv] 最终判断 - isFocused:",
  327. isFocused.value,
  328. "isOverflow:",
  329. isOverflow,
  330. "shouldShow:",
  331. shouldShow
  332. );
  333. // 需要同时满足:有焦点 + 内容超出
  334. return shouldShow;
  335. };
  336. // 定义事件处理函数
  337. const onInput = (event) => {
  338. const newValue = event.target.value;
  339. inputValue.value = newValue;
  340. emit("update:modelValue", newValue);
  341. validate(); // 输入时验证
  342. nextTick(() => {
  343. // 检查是否需要显示浮动div
  344. contentFloatingDiv.value = checkShouldShowFloatingDiv();
  345. // 如果需要显示floatdiv,计算其位置
  346. if (contentFloatingDiv.value) {
  347. calculateFloatingDivPosition();
  348. }
  349. });
  350. adjustHeight();
  351. };
  352. const onFocus = (event) => {
  353. // 设置焦点状态为true
  354. isFocused.value = true;
  355. adjustHeight();
  356. // 检查是否应该显示浮动窗口
  357. nextTick(() => {
  358. contentFloatingDiv.value = checkShouldShowFloatingDiv();
  359. if (contentFloatingDiv.value) {
  360. calculateFloatingDivPosition();
  361. }
  362. });
  363. };
  364. // 失去焦点时进行验证
  365. const onBlur = (event) => {
  366. emit("blur", event.target);
  367. validate(); // 失焦时验证
  368. nextTick(() => {
  369. // 如果焦点不在 textarea 上,则隐藏浮动 div
  370. if (!document.activeElement.classList.contains("input-control")) {
  371. isFocused.value = false;
  372. contentFloatingDiv.value = false;
  373. }
  374. });
  375. };
  376. const onChange = (event) => {
  377. inputValue.value = event.target.value || "";
  378. emit("change", inputValue.value);
  379. };
  380. const onMouseover = (event) => {
  381. nextTick(() => {
  382. // setTimeout(contentFloatingDiv.value = true, 500)
  383. });
  384. };
  385. const onMouseleave = (event) => {
  386. // contentFloatingDiv.value = false
  387. };
  388. // 功能说明:传了 height 视为多行允许回车;未传 height 拦截回车(单行表现) by xu 20260204
  389. const onKeydown = (event) => {
  390. const allowMultiline =
  391. typeof props.height === "string" && props.height.trim() !== "";
  392. if (!allowMultiline && event.key === "Enter") {
  393. event.preventDefault();
  394. }
  395. };
  396. // 附件按钮点击处理(从 SsEditor 搬运)
  397. const onAttachmentClick = (e) => {
  398. e.preventDefault();
  399. if (!props.param || !props.param.button) {
  400. console.warn("未配置 param 参数");
  401. return;
  402. }
  403. console.log("附件点击了");
  404. console.log("param", props.param);
  405. console.log("cmsAddUrl", props.param.button.cmsAddUrl);
  406. // 如果 fjid 为空,先调用 cmsAddUrl 创建
  407. if (fjid.value == null || fjid.value == "") {
  408. $.ajax({
  409. type: "post",
  410. url: props.param.button.cmsAddUrl,
  411. async: false,
  412. data: {
  413. name: "fjid",
  414. ssNrObjName: "sh",
  415. ssNrObjId: "",
  416. },
  417. success: function (_fjid) {
  418. console.log("cmsAddUrl success", _fjid);
  419. fjid.value = _fjid;
  420. },
  421. });
  422. }
  423. // 构建参数字符串
  424. var str =
  425. "&nrid=T-" +
  426. fjid.value +
  427. "&objectId=" +
  428. fjid.value +
  429. "&objectName=" +
  430. fjName +
  431. "&callback=" +
  432. (window["fjidCallbackName"] || "");
  433. console.log("str", str);
  434. // 打开附件编辑对话框
  435. SS.openDialog({
  436. src: props.param.button.cmsUpdUrl + str,
  437. headerTitle: "编辑",
  438. width: 900,
  439. high: 664,
  440. zIndex: 51,
  441. });
  442. };
  443. return {
  444. errMsg,
  445. inputValue,
  446. showRequired,
  447. onInput,
  448. onBlur,
  449. onChange,
  450. onMouseover,
  451. onMouseleave,
  452. onKeydown, // 新增:键盘事件处理 by xu 20251212
  453. contentFloatingDiv,
  454. floatingDivPosition,
  455. getFloatingDivTop,
  456. inputRef,
  457. textareaRef,
  458. onFocus,
  459. onAttachmentClick,
  460. fjid, // 附件 ID,用于隐藏字段
  461. };
  462. },
  463. render() {
  464. const { resolveComponent, h } = Vue;
  465. const SsIcon = resolveComponent("ss-icon");
  466. const SsEditorIcon = resolveComponent("SsEditorIcon");
  467. // 构建主textarea的样式
  468. const mainTextareaStyle = {};
  469. if (this.height) {
  470. mainTextareaStyle.height = "auto";
  471. // mainTextareaStyle.paddingTop = '5px'; // 有高度时加上padding-top
  472. // mainTextareaStyle.paddingBottom = '5px'; // 有高度时加上padding-bottom
  473. } else {
  474. // 没有指定height时,固定为单行高度
  475. mainTextareaStyle.height = "20px"; // 行高20px
  476. mainTextareaStyle.lineHeight = "20px"; // 确保单行垂直居中
  477. mainTextareaStyle.display = "flex";
  478. mainTextareaStyle.marginBottom = "5px";
  479. }
  480. // 如果有附件按钮,为按钮留出空间
  481. if (this.fj || (this.param && this.param.button)) {
  482. //加上&&this.param.button条件 Ben(20251221)
  483. mainTextareaStyle.paddingRight = "75px";
  484. }
  485. const mainTextareaRows = this.height
  486. ? Math.floor(parseFloat("80px") / 20)
  487. : 1;
  488. return h("div", { class: "input" }, [
  489. h("div", { class: "input-container" }, [
  490. h("div", { class: "input", style: "padding:5px 0" }, [
  491. h("textarea", {
  492. ref: "inputRef",
  493. class: "input-control",
  494. name: this.name,
  495. value: this.inputValue,
  496. onInput: this.onInput,
  497. onFocus: this.onFocus,
  498. onBlur: this.onBlur,
  499. onChange: this.onChange,
  500. onKeydown: this.onKeydown, // 新增:禁止回车换行 by xu 20251212
  501. placeholder: this.placeholder,
  502. onMouseover: this.onMouseover, // 监听鼠标悬停
  503. onMouseleave: this.onMouseleave, // 监听鼠标离开
  504. rows: mainTextareaRows,
  505. ...this.$attrs,
  506. style: mainTextareaStyle,
  507. autocomplete: "off",
  508. }),
  509. // 附件按钮(优先使用 param,兼容旧的 fj)
  510. this.fj || (this.param && this.param.button) //加上&&this.param.button条件 Ben(20251221)
  511. ? h(
  512. "button",
  513. {
  514. type: "button",
  515. class: "fj-button",
  516. onClick: this.param
  517. ? this.onAttachmentClick
  518. : (e) => {
  519. e.preventDefault();
  520. console.log("附件配置:", this.fj);
  521. },
  522. },
  523. [
  524. h(SsEditorIcon, {
  525. class: "editor-icon-link",
  526. }),
  527. h("span", { class: "fj-button-text" }, "附件"),
  528. ]
  529. )
  530. : null,
  531. // this.showRequired ? h("div", { class: "required" }) : null,
  532. ]),
  533. this.contentFloatingDiv || ""
  534. ? h(
  535. "div",
  536. {
  537. class: "floating-div",
  538. style:
  539. this.floatingDivPosition === "bottom"
  540. ? {
  541. // 向下展开: 覆盖原输入框,top对齐首行
  542. top: this.getFloatingDivTop,
  543. bottom: "auto",
  544. }
  545. : {
  546. // 向上展开: 同样覆盖原输入框,但从底部开始计算
  547. top: "auto",
  548. bottom: this.height ? "5px" : "6px", // 对齐到原textarea的底部padding位置
  549. },
  550. },
  551. [
  552. h("textarea", {
  553. ref: "textareaRef",
  554. class: "input-control",
  555. value: this.inputValue,
  556. onInput: this.onInput,
  557. onBlur: this.onBlur,
  558. onFocus: this.onFocus,
  559. onKeydown: this.onKeydown, // 新增:禁止回车换行 by xu 20251212
  560. onMouseover: this.onMouseover, // 监听鼠标悬停
  561. onMouseleave: this.onMouseleave, // 监听鼠标离开
  562. autocomplete: "off",
  563. onVnodeMounted: (vnode) => {
  564. vnode.el.focus();
  565. },
  566. }),
  567. ]
  568. )
  569. : null,
  570. // this.errMsg ? h(SsValidate, { errMsg: this.errMsg }) : null,
  571. ]),
  572. // 附件相关的隐藏字段(仅在有 param 时才渲染)
  573. this.param && [
  574. // fjid 隐藏字段(只有当 fjid 有值时才渲染)
  575. this.fjid &&
  576. this.fjid.value &&
  577. h("input", {
  578. type: "hidden",
  579. name: "fjid",
  580. value: this.fjid.value,
  581. }),
  582. // 其他隐藏字段根据 name 生成
  583. /* 去掉。文本框不需要(这是富文本才有的) Ben 20251205
  584. h("input", {
  585. type: "hidden",
  586. name: this.name.replace(/wj$/, "") + "Edit",
  587. value: this.inputValue
  588. }),
  589. */
  590. // h("input", {
  591. // type: "hidden",
  592. // name: this.name.replace(/wj$/, "") + "wj",
  593. // value: this.inputValue
  594. // }),
  595. /* 去掉。文本框不需要(这是富文本才有的) Ben 20251205
  596. h("input", {
  597. type: "hidden",
  598. name: "ueditorpath",
  599. value: this.name
  600. }),
  601. */
  602. ],
  603. ]);
  604. },
  605. };
  606. // ss-normal-input 登录输入
  607. const SsLoginInput = {
  608. name: "SsLoginInput",
  609. inheritAttrs: false,
  610. props: {
  611. errTip: {
  612. type: String,
  613. },
  614. type: {
  615. type: String,
  616. default: "text",
  617. },
  618. required: {
  619. type: Boolean,
  620. default: false,
  621. },
  622. placeholder: {
  623. type: String,
  624. default: "请输入",
  625. },
  626. name: {
  627. type: String,
  628. default: "",
  629. },
  630. defaultValue: [String, Number],
  631. modelValue: [String, Number],
  632. },
  633. emits: ["update:modelValue", "input", "blur", "change"], // 允许更新 v-model 绑定的值
  634. setup(props, { emit }) {
  635. const errMsg = ref("");
  636. const inputRef = ref(null);
  637. const textareaRef = ref(null);
  638. const inputValue = ref(props.modelValue || props.defaultValue || "");
  639. // 使用 watch 监听 props.errTip 和 props.modelValue 的变化
  640. watch(
  641. () => props.errTip,
  642. (newVal) => {
  643. errMsg.value = newVal;
  644. },
  645. { immediate: true }
  646. );
  647. watch(
  648. () => props.modelValue,
  649. (newVal) => {
  650. inputValue.value = newVal;
  651. }
  652. );
  653. // 挂载时的逻辑
  654. onMounted(() => {
  655. errMsg.value = props.errTip;
  656. inputValue.value = props.modelValue || props.defaultValue || "";
  657. });
  658. // 定义事件处理函数
  659. const onInput = (event) => {
  660. const newValue = event.target.value;
  661. inputValue.value = newValue;
  662. emit("update:modelValue", newValue);
  663. };
  664. return { inputValue, onInput, inputRef, textareaRef };
  665. },
  666. render() {
  667. return h("div", { class: "input" }, [
  668. h("div", { class: "input-container" }, [
  669. h("div", { class: "input" }, [
  670. h("input", {
  671. ref: "inputRef",
  672. class: "input-control",
  673. name: this.name,
  674. value: this.inputValue,
  675. onInput: this.onInput,
  676. type: this.type,
  677. placeholder: this.placeholder,
  678. required: this.required,
  679. ...this.$attrs,
  680. autocomplete: "off",
  681. }),
  682. this.required ? h("div", { class: "required" }) : null,
  683. ]),
  684. ]),
  685. ]);
  686. },
  687. };
  688. // ss-login-button
  689. const SsLoginButton = {
  690. name: "SsLoginButton",
  691. inheritAttrs: false,
  692. props: {
  693. class: {
  694. type: String,
  695. default: "",
  696. },
  697. text: {
  698. type: String,
  699. default: "",
  700. },
  701. type: {
  702. type: String,
  703. default: "button",
  704. },
  705. },
  706. emits: ["click"],
  707. setup(props, { emit }) {
  708. // 定义事件处理函数
  709. const onClick = (event) => {
  710. // 发射一个 'click' 事件,你可以传递所需的参数
  711. emit("click", event);
  712. };
  713. return { props, onClick };
  714. },
  715. render() {
  716. const SsIcon = resolveComponent("ss-icon");
  717. const SsLoginIcon = resolveComponent("ss-login-icon");
  718. return h(
  719. "button",
  720. { class: "login-button", type: this.type, onClick: this.onClick },
  721. [
  722. h("span", [h(SsLoginIcon, { class: this.class })]),
  723. h("span", {}, this.text),
  724. ]
  725. );
  726. },
  727. };
  728. // ss-objp 下拉选择
  729. const SsObjp = {
  730. name: "SsObjp",
  731. inheritAttrs: false,
  732. props: {
  733. onchange: {
  734. //在此属性传入onChange的window全局回调函数,函数唯一参数是当前选中值 Ben(20251217)
  735. type: String,
  736. required: false,
  737. },
  738. filter: {
  739. type: String,
  740. required: false,
  741. },
  742. filterfield: {
  743. type: String,
  744. required: false,
  745. },
  746. // filterField: {
  747. // //此属性为页面表单元素的name用逗号分隔,作用为在向后台查询下拉菜单选项时,会带上这些name的表单元素的value值 Ben(20260313)
  748. // type: String,
  749. // required: false,
  750. // },
  751. cb: {
  752. type: String,
  753. required: true,
  754. },
  755. url: {
  756. type: String,
  757. required: true,
  758. },
  759. name: {
  760. type: String,
  761. required: true,
  762. },
  763. width: {
  764. type: String,
  765. default: "100%",
  766. },
  767. placeholder: {
  768. type: String,
  769. default: "请选择",
  770. },
  771. inp: {
  772. type: Boolean,
  773. default: false,
  774. },
  775. opt: {
  776. type: Array,
  777. default: () => [],
  778. },
  779. errTip: String,
  780. defaultValue: [String, Number],
  781. modelValue: [String, Number],
  782. direction: {
  783. type: String,
  784. default: "bottom",
  785. },
  786. },
  787. emits: ["update:modelValue", "input", "blur", "change"],
  788. setup(props, { emit }) {
  789. const canInput = props.inp;
  790. const errMsg = Vue.ref(props.errTip);
  791. const selectItem = Vue.ref({});
  792. let inputText = Vue.ref(""); // 用于存储输入框的文本
  793. const popupWinVisible = Vue.ref(false);
  794. const filteredOptions = Vue.ref(props.opt);
  795. const popupDirection = Vue.ref("bottom");
  796. const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
  797. const popupContentAreaMaxHeight = Vue.computed(() => {
  798. if (!popupMaxHeight.value || popupMaxHeight.value === "none")
  799. return null;
  800. const maxHeightNum = Number.parseFloat(popupMaxHeight.value);
  801. if (!Number.isFinite(maxHeightNum)) return null;
  802. // 功能说明:滚动条统一落在 .content-area(CSS 默认如此),因此需要扣掉 popup-win padding-top(10) 与 popup-content padding(15*2) by xu 20260126
  803. const contentAreaMaxHeight = Math.max(60, maxHeightNum - 40);
  804. return `${contentAreaMaxHeight}px`;
  805. });
  806. // 修复表格内下拉弹层被 overflow 截断:popup 使用 Teleport 到 body + fixed 定位 by xu 20260126
  807. const selectContainerRef = Vue.ref(null);
  808. const popupRef = Vue.ref(null);
  809. const teleportRootStyle = Vue.ref({
  810. position: "fixed",
  811. left: "0",
  812. top: "0",
  813. width: "0",
  814. height: "0",
  815. zIndex: 9999,
  816. pointerEvents: "none",
  817. });
  818. const popupLayerStyle = Vue.ref({
  819. position: "fixed",
  820. left: "0",
  821. top: "0",
  822. bottom: "auto", // 功能说明:覆盖 .popup-win.top 的 bottom 定位,避免 fixed 场景被撑高/错位 by xu 20260126
  823. minWidth: "0",
  824. zIndex: 9999,
  825. pointerEvents: "auto",
  826. });
  827. // const showRequired = Vue.computed(() => {
  828. // const hasValidationRule = window.ssVm?.validations?.has(props.name);
  829. // if (!hasValidationRule) return false;
  830. // if (errMsg.value) return true;
  831. // if (!selectItem.value?.value) return true;
  832. // return false;
  833. // });
  834. const validate = () => {
  835. if (window.ssVm) {
  836. const result = window.ssVm.validateField(props.name);
  837. // console.log("validate", window.ssVm.validateField(props.name));
  838. errMsg.value = result.valid ? "" : result.message;
  839. }
  840. };
  841. //在objPicker界面,选中value对应的项
  842. const updateSelectItem = () => {
  843. // console.log(props.opt);
  844. const item = props.opt.find((it) => it.value === props.modelValue);
  845. if (item) {
  846. selectItem.value = item;
  847. inputText.value = item.label;
  848. } else {
  849. selectItem.value = { label: "", value: "" };
  850. inputText.value = "";
  851. }
  852. // validate();
  853. };
  854. Vue.watch(
  855. () => props.errTip,
  856. (newVal) => {
  857. errMsg.value = newVal;
  858. }
  859. );
  860. Vue.watch(() => props.modelValue, updateSelectItem, { immediate: true });
  861. Vue.watch(
  862. () => props.opt,
  863. (newVal) => {
  864. updateSelectItem();
  865. filteredOptions.value = [...newVal];
  866. // console.log("filteredOptions", filteredOptions.value);
  867. }
  868. );
  869. //初始化objPicker在页面刚打开时的默认值
  870. async function initDefaultValue() {
  871. try {
  872. if (props.url && props.cb && props.modelValue) {
  873. let objectPickerParam;
  874. let url = props.url;
  875. //如果有定义过滤器
  876. if (props.filter) {
  877. //包含HTML实体的JSON字符串转为JSON对象,如原字符串是{&quot;dwid&quot;:&quot;88&quot;},注意key也必需用单引号包着
  878. // const decodedString = props.filter.replace(/&quot;/g, '"'); // 转换为: {"dwid":"88"}
  879. // objectPickerParam = JSON.parse(decodedString); // 转为json对象
  880. const filterObj = props.filter; // 转为json对象
  881. for (let k in filterObj) {
  882. let v = filterObj[k];
  883. url += "&" + k + "=" + v;
  884. }
  885. objectPickerParam = props.filter; // 转为json对象
  886. objectPickerParam["input"] = props.inp;
  887. objectPickerParam["codebook"] = props.cb;
  888. // alert(url);
  889. } else {
  890. objectPickerParam = { input: props.inp, codebook: props.cb };
  891. }
  892. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  893. const params = new URLSearchParams();
  894. params.append("objectpickerparam", objectPickerParamStr);
  895. params.append("objectpickertype", "2");
  896. params.append("objectpickervalue", props.modelValue); //需回显的值
  897. // alert("1params:"+JSON.stringify(params));
  898. axios
  899. .post(props.url, params, {
  900. headers: {
  901. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  902. },
  903. })
  904. .then((response) => {
  905. // alert(JSON.stringify(response.data));
  906. if ("timeout" == response.data.statusText) {
  907. alert("网络超时!");
  908. return;
  909. }
  910. if (response.data.result) {
  911. const keys = Object.keys(response.data.result);
  912. if (keys.length === 1) {
  913. let code = keys[0];
  914. let desc = response.data.result[keys[0]];
  915. if (props.opt)
  916. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  917. else {
  918. props.opt = [];
  919. }
  920. props.opt.push({ label: desc, value: code });
  921. updateSelectItem();
  922. // alert('props.opt:'+JSON.stringify(props.opt));
  923. }
  924. }
  925. });
  926. }
  927. } catch (error) {
  928. // callback(null, error.message); // 失败回调,传递错误
  929. }
  930. }
  931. // Vue.onMounted(updateSelectItem);
  932. const doSelectItem = (item) => {
  933. emit("update:modelValue", item.value);
  934. selectItem.value = item;
  935. inputText.value = item.label;
  936. hidePopup();
  937. nextTick(() => {
  938. console.log(item.value + "@@@props.modelValue:" + props.modelValue);
  939. validate();
  940. if (window.ssVm) {
  941. // 遍历所有验证规则,找到依赖当前字段的规则
  942. for (const [field, rules] of window.ssVm.validations.entries()) {
  943. for (const rule of rules) {
  944. if (rule.opt?.relField === props.name) {
  945. // console.log("Found dependent field:", field); // 调试日志
  946. window.ssVm.validateField(field);
  947. }
  948. }
  949. }
  950. }
  951. });
  952. callGlobalOnchg(item.value, item.label); // 值变化时尝试调用全局onchange回调函数 Ben(20251217)
  953. };
  954. // 用于调用全局onchange回调函数 Ben(20251217)
  955. const callGlobalOnchg = (value, desc) => {
  956. // 检查 onchange 属性是否提供了有效的函数名
  957. if (props.onchange && typeof props.onchange === "string") {
  958. // 检查 window 对象上是否存在该函数
  959. if (
  960. typeof window !== "undefined" &&
  961. window[props.onchange] &&
  962. typeof window[props.onchange] === "function"
  963. ) {
  964. try {
  965. window[props.onchange](value, desc); // 调用全局函数,并传入当前选中值
  966. } catch (error) {
  967. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  968. }
  969. } else {
  970. console.warn(`全局函数 ${props.onchange} 未定义或不是一个函数。`);
  971. }
  972. }
  973. };
  974. //可录入的objPicker,更新下拉菜单选项
  975. async function updateOptionBYInputText(inpTxt) {
  976. try {
  977. let objectPickerParam;
  978. let url = props.url;
  979. if (props.url && props.cb) {
  980. //如果有定义过滤器
  981. if (props.filter || props.filterfield) {
  982. let filterObj = props.filter;
  983. if (!props.filter) filterObj = {};
  984. if (props.filter) {
  985. const filterObj = props.filter; // 转为json对象
  986. for (let k in filterObj) {
  987. let v = filterObj[k];
  988. url += "&" + k + "=" + v;
  989. }
  990. }
  991. if (props.filterfield) {
  992. //加上filterfield的值过滤
  993. let filterfieldArr = props.filterfield.split(",");
  994. for (var i = 0; i < filterfieldArr.length; i++) {
  995. let fieldName = filterfieldArr[i];
  996. let fields = document.getElementsByName(fieldName);
  997. if (!fields || fields.length < 1) {
  998. alert("下拉菜单配置的过滤条件" + fieldName + "不存在!");
  999. continue;
  1000. }
  1001. let v = null;
  1002. for (let j = 0; j < fields.length; j++) {
  1003. if (fields[j].value) {
  1004. v = fields[j].value;
  1005. break;
  1006. }
  1007. }
  1008. // let field = document.getElementsByName(fieldName)[0];
  1009. // let v = field.value;
  1010. if (v) {
  1011. url += "&" + fieldName + "=" + v;
  1012. filterObj[fieldName] = v;
  1013. }
  1014. }
  1015. console.log("filterfield url:" + url);
  1016. }
  1017. //包含HTML实体的JSON字符串转为JSON对象,如原字符串是{&quot;dwid&quot;:&quot;88&quot;},注意key也必需用单引号包着
  1018. // const decodedString = props.filter.replace(/&quot;/g, '"'); // 转换为: {"dwid":"88"}
  1019. // objectPickerParam = JSON.parse(decodedString); // 转为json对象
  1020. objectPickerParam = filterObj;
  1021. objectPickerParam["input"] = props.inp;
  1022. objectPickerParam["codebook"] = props.cb;
  1023. // alert(url);
  1024. } else {
  1025. objectPickerParam = { input: props.inp, codebook: props.cb };
  1026. }
  1027. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  1028. const params = new URLSearchParams();
  1029. params.append("objectpickerparam", objectPickerParamStr);
  1030. params.append("objectpickertype", "1");
  1031. if (props.inp && props.inp === true) {
  1032. //把"true"改为true Ben(20251209)
  1033. params.append("objectpickersearchAll", 0); //只查录入的值
  1034. params.append("objectpickerinput", inpTxt); //录入的值
  1035. } else {
  1036. params.append("objectpickersearchAll", 1);
  1037. }
  1038. axios
  1039. .post(url, params, {
  1040. headers: {
  1041. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1042. },
  1043. })
  1044. .then((response) => {
  1045. if ("timeout" == response.data.statusText) {
  1046. alert("网络超时!");
  1047. return;
  1048. }
  1049. // 先清空选项 by xu 20251212
  1050. if (props.opt) {
  1051. props.opt.length = 0;
  1052. } else {
  1053. props.opt = [];
  1054. }
  1055. if (response.data.result) {
  1056. const keys = Object.keys(response.data.result);
  1057. // console.log("params:"+params+"@@response.data:"+JSON.stringify(response.data));
  1058. if (keys.length > 0) {
  1059. for (let k in response.data.result) {
  1060. props.opt.push({
  1061. label: response.data.result[k],
  1062. value: k,
  1063. });
  1064. }
  1065. // console.log('###inpTxt:'+inpTxt+';');
  1066. if (
  1067. props.inp &&
  1068. props.inp === true && //把"true"改为true Ben(20251209)
  1069. inpTxt.length > 0
  1070. ) {
  1071. //对于可录入的,用已录入的值作过滤
  1072. filteredOptions.value = props.opt.filter((option) =>
  1073. option.label
  1074. .toLowerCase()
  1075. .includes(inputText.value.toLowerCase())
  1076. );
  1077. // 可录入的objPicker,当搜索结果只有一项时,自动选中这一项 by xu 20251212
  1078. if (filteredOptions.value.length === 1) {
  1079. const autoSelectItem = filteredOptions.value[0];
  1080. console.log(
  1081. "[objp] 搜索结果只有一项,自动选中:",
  1082. autoSelectItem
  1083. );
  1084. doSelectItem(autoSelectItem);
  1085. return; // 自动选中后直接返回,不需要显示popup
  1086. }
  1087. filteredOptions.value.unshift({ label: "", value: "" });
  1088. // console.log('###做了过滤:'+inputText.value.toLowerCase()+';');
  1089. } else {
  1090. filteredOptions.value = props.opt;
  1091. filteredOptions.value.unshift({ label: "", value: "" });
  1092. }
  1093. console.log("props.opt11:" + JSON.stringify(props.opt));
  1094. } else {
  1095. // 没有数据时,清空过滤选项 by xu 20251212
  1096. filteredOptions.value = [];
  1097. console.log("[objp] 接口返回空数据");
  1098. }
  1099. } else {
  1100. // result不存在时,清空过滤选项 by xu 20251212
  1101. filteredOptions.value = [];
  1102. console.log("[objp] 接口返回无result");
  1103. }
  1104. // 无论是否有数据,都显示popup by xu 20251212
  1105. openPopup(); // Teleport 场景下统一打开并重定位 by xu 20260126
  1106. });
  1107. }
  1108. } catch (error) {
  1109. // callback(null, error.message); // 失败回调,传递错误
  1110. }
  1111. }
  1112. // 计算弹出方向和最大高度的方法 by xu 20251212
  1113. // 当空间不足时限制popup高度并显示滚动条
  1114. const calculatePopupDirection = () => {
  1115. const triggerEl =
  1116. selectContainerRef.value?.querySelector(".input") ||
  1117. selectContainerRef.value;
  1118. if (!triggerEl) return;
  1119. const selectRect = triggerEl.getBoundingClientRect();
  1120. const viewportHeight = window.innerHeight;
  1121. // 3. 计算上下可用空间
  1122. const spaceBelow = viewportHeight - selectRect.bottom - 10; // 减10px留边距
  1123. const spaceAbove = selectRect.top - 10; // 减10px留边距
  1124. // 4. popup预估高度(假设每项36px,最多显示8项 + padding)
  1125. const estimatedPopupHeight = 300;
  1126. const minPopupHeight = 100; // 最小高度
  1127. console.log(
  1128. "[popup] 空间计算 - spaceAbove:",
  1129. spaceAbove,
  1130. "spaceBelow:",
  1131. spaceBelow,
  1132. "estimatedHeight:",
  1133. estimatedPopupHeight
  1134. );
  1135. // 5. 判断方向和最大高度 by xu 20251212
  1136. if (spaceBelow >= estimatedPopupHeight) {
  1137. // 下方空间足够,向下展开,不限制高度
  1138. popupDirection.value = "bottom";
  1139. popupMaxHeight.value = "none";
  1140. console.log("[popup] 向下展开,空间充足");
  1141. } else if (spaceAbove >= estimatedPopupHeight) {
  1142. // 上方空间足够,向上展开,不限制高度
  1143. popupDirection.value = "top";
  1144. popupMaxHeight.value = "none";
  1145. console.log("[popup] 向上展开,空间充足");
  1146. } else {
  1147. // 上下空间都不足,选择空间大的方向,并限制高度出滚动条
  1148. if (spaceBelow >= spaceAbove) {
  1149. popupDirection.value = "bottom";
  1150. popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px";
  1151. console.log(
  1152. "[popup] 向下展开,空间不足,限制高度:",
  1153. popupMaxHeight.value
  1154. );
  1155. } else {
  1156. popupDirection.value = "top";
  1157. popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px";
  1158. console.log(
  1159. "[popup] 向上展开,空间不足,限制高度:",
  1160. popupMaxHeight.value
  1161. );
  1162. }
  1163. }
  1164. };
  1165. // Teleport popup 的定位(fixed) by xu 20260126
  1166. const updatePopupPosition = () => {
  1167. const triggerEl =
  1168. selectContainerRef.value?.querySelector(".input") ||
  1169. selectContainerRef.value;
  1170. if (!triggerEl) return;
  1171. const triggerRect = triggerEl.getBoundingClientRect();
  1172. const margin = 10;
  1173. const viewportWidth = window.innerWidth;
  1174. const viewportHeight = window.innerHeight;
  1175. const popupGap = 0; // 功能说明:定位不再做 -10 重叠,让 padding-top 自然形成间距 by xu 20260126
  1176. // 先给一个初始位置,确保下一帧可以测量弹层尺寸 by xu 20260126
  1177. popupLayerStyle.value = {
  1178. position: "fixed",
  1179. left: `${Math.max(margin, triggerRect.left)}px`,
  1180. top: `${Math.max(margin, triggerRect.bottom + popupGap)}px`, // 功能说明:与输入框底部对齐 by xu 20260126
  1181. bottom: "auto", // 功能说明:fixed 场景显式取消 bottom,避免与 top 同时生效 by xu 20260126
  1182. minWidth: `${Math.max(0, triggerRect.width)}px`,
  1183. zIndex: 9999,
  1184. pointerEvents: "auto",
  1185. };
  1186. Vue.nextTick(() => {
  1187. const popupEl = popupRef.value;
  1188. if (!popupEl) return;
  1189. const popupRect = popupEl.getBoundingClientRect();
  1190. const maxLeft = viewportWidth - popupRect.width - margin;
  1191. const left = Math.min(
  1192. Math.max(margin, triggerRect.left),
  1193. Math.max(margin, maxLeft)
  1194. );
  1195. let top;
  1196. if (popupDirection.value === "top") {
  1197. top = triggerRect.top - popupRect.height - popupGap; // 功能说明:向上展开时与输入框顶部对齐 by xu 20260126
  1198. top = Math.max(margin, top);
  1199. } else {
  1200. top = triggerRect.bottom + popupGap; // 功能说明:向下展开时与输入框底部对齐 by xu 20260126
  1201. if (top + popupRect.height > viewportHeight - margin) {
  1202. top = Math.max(
  1203. margin,
  1204. viewportHeight - popupRect.height - margin
  1205. );
  1206. }
  1207. }
  1208. popupLayerStyle.value = {
  1209. ...popupLayerStyle.value,
  1210. left: `${left}px`,
  1211. top: `${top}px`,
  1212. bottom: "auto", // 功能说明:无论 top/bottom 展开都用 top 定位,禁用 bottom by xu 20260126
  1213. };
  1214. });
  1215. };
  1216. const openPopup = () => {
  1217. if (!popupWinVisible.value) popupWinVisible.value = true;
  1218. Vue.nextTick(() => {
  1219. calculatePopupDirection();
  1220. updatePopupPosition();
  1221. });
  1222. };
  1223. // Teleport 场景下:滚动/缩放重定位 by xu 20260126
  1224. const handleViewportChange = () => {
  1225. if (!popupWinVisible.value) return;
  1226. calculatePopupDirection();
  1227. updatePopupPosition();
  1228. };
  1229. // Teleport 场景下:点击外部关闭 by xu 20260126
  1230. const onDocPointerDown = (event) => {
  1231. if (!popupWinVisible.value) return;
  1232. const target = event.target;
  1233. if (selectContainerRef.value?.contains(target)) return;
  1234. if (popupRef.value?.contains(target)) return;
  1235. hidePopup();
  1236. };
  1237. //点击下拉菜单的文本区域时,会触发的方法
  1238. function togglePopup() {
  1239. // 可录入的 objPicker,更新下拉菜单选项
  1240. updateOptionBYInputText(inputText.value);
  1241. // popupWinVisible.value = !popupWinVisible.value;
  1242. Vue.nextTick(() => {
  1243. calculatePopupDirection();
  1244. updatePopupPosition(); // Teleport 场景下同步定位 by xu 20260126
  1245. });
  1246. }
  1247. const hidePopup = () => {
  1248. popupWinVisible.value = false;
  1249. };
  1250. //点击下拉菜单的三角形时,会触发的方法
  1251. // 添加toggle逻辑,点击时切换显示/隐藏 by xu 20251212
  1252. const suffixClick = () => {
  1253. // 如果popup已显示,则关闭 by xu 20251212
  1254. if (popupWinVisible.value) {
  1255. hidePopup();
  1256. console.log("[objp] 点三角关闭popup");
  1257. return;
  1258. }
  1259. //可录入的objPicker,更新下拉菜单选项
  1260. updateOptionBYInputText("");
  1261. Vue.nextTick(() => {
  1262. calculatePopupDirection();
  1263. updatePopupPosition(); // Teleport 场景下同步定位 by xu 20260126
  1264. });
  1265. console.log("[objp] 点三角打开popup");
  1266. };
  1267. //可录入的objPicker,录入项变化时,会触发
  1268. async function handleInputChange(event) {
  1269. inputText.value = event.target.value;
  1270. if (!inputText.value) {
  1271. inputText.value = "";
  1272. }
  1273. //可录入的objPicker,更新下拉菜单选项
  1274. updateOptionBYInputText(inputText.value);
  1275. // filteredOptions.value = props.opt.filter((option) =>
  1276. // option.label.toLowerCase().includes(inputText.value.toLowerCase())
  1277. // );
  1278. // if (!popupWinVisible.value) {
  1279. // popupWinVisible.value = true; // 确保下拉框在输入时打开
  1280. // }
  1281. }
  1282. Vue.onMounted(() => {
  1283. initDefaultValue();
  1284. // Teleport 场景下:滚动/缩放需要重定位(scroll 用 capture 捕获容器滚动) by xu 20260126
  1285. window.addEventListener("resize", handleViewportChange);
  1286. window.addEventListener("scroll", handleViewportChange, true);
  1287. // 点击外部关闭(原本依赖 mouseleave,Teleport 后会误关) by xu 20260126
  1288. document.addEventListener("pointerdown", onDocPointerDown, true);
  1289. });
  1290. Vue.onUnmounted(() => {
  1291. window.removeEventListener("resize", handleViewportChange);
  1292. window.removeEventListener("scroll", handleViewportChange, true);
  1293. document.removeEventListener("pointerdown", onDocPointerDown, true);
  1294. });
  1295. return {
  1296. errMsg,
  1297. selectItem,
  1298. inputText,
  1299. canInput,
  1300. filteredOptions,
  1301. popupWinVisible,
  1302. popupDirection,
  1303. popupMaxHeight, // 添加popup最大高度 by xu 20251212
  1304. popupContentAreaMaxHeight,
  1305. selectContainerRef,
  1306. popupRef,
  1307. teleportRootStyle,
  1308. popupLayerStyle,
  1309. suffixClick,
  1310. togglePopup,
  1311. hidePopup,
  1312. doSelectItem,
  1313. handleInputChange,
  1314. };
  1315. },
  1316. template: `
  1317. <div class="input" style="position: relative" :style="{width: width}">
  1318. <div class="select-container" ref="selectContainerRef">
  1319. <div class="input" @click="togglePopup">
  1320. <input
  1321. type="hidden"
  1322. :name="name"
  1323. :value="selectItem.value"
  1324. .value="selectItem.value"
  1325. />
  1326. <input
  1327. v-model="inputText"
  1328. @input="handleInputChange"
  1329. v-if="canInput"
  1330. :placeholder="placeholder"
  1331. />
  1332. <input
  1333. v-else
  1334. :placeholder="placeholder"
  1335. :value="selectItem.label"
  1336. disabled
  1337. style="pointer-events: none;"
  1338. />
  1339. <div class="suffix" @click.stop="suffixClick">
  1340. <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
  1341. </div>
  1342. </div>
  1343. <!-- 修复表格内弹层被截断:popup Teleport 到 body by xu 20260126 -->
  1344. <teleport to="body">
  1345. <div v-show="popupWinVisible" class="select-container ss-objp-teleport-root" :style="teleportRootStyle">
  1346. <!-- popup弹出层,添加maxHeight和overflowY支持空间不足时滚动 by xu 20251212 -->
  1347. <div ref="popupRef" class="popup-win" :class="popupDirection" :style="[popupLayerStyle, { maxHeight: popupMaxHeight !== 'none' ? popupMaxHeight : 'none', overflowY: 'visible' }]">
  1348. <div v-if="opt && opt.length && filteredOptions.length > 0" class="popup-content">
  1349. <div class="content-area" :style="popupContentAreaMaxHeight ? { maxHeight: popupContentAreaMaxHeight, overflowY: 'auto' } : null">
  1350. <div v-for="(item, index) in filteredOptions" :key="index" @click="doSelectItem(item)" :class="{ active: item.value === selectItem.value }">
  1351. <span class="check-icon">
  1352. <ss-form-icon class="form-icon-select-checked" />
  1353. </span>
  1354. <span>{{ item.label }}</span>
  1355. </div>
  1356. </div>
  1357. </div>
  1358. <div v-else class="popup-content"><div class="content-area"><div class="content-area"> <span>无选项</span></div></div></div>
  1359. </div>
  1360. </div>
  1361. </teleport>
  1362. </div>
  1363. </div>
  1364. `,
  1365. };
  1366. // ss-hidden 隐藏字段组件
  1367. const SsHidden = {
  1368. name: "SsHidden",
  1369. props: {
  1370. modelValue: String,
  1371. name: {
  1372. type: String,
  1373. required: true,
  1374. },
  1375. rule: {
  1376. type: String,
  1377. required: true,
  1378. },
  1379. param: {
  1380. type: String,
  1381. required: true,
  1382. },
  1383. url: {
  1384. type: String,
  1385. required: true,
  1386. },
  1387. },
  1388. emits: ["update:modelValue"],
  1389. setup(props, { emit }) {
  1390. const errMsg = Vue.ref("");
  1391. const validate = () => {
  1392. if (window.ssVm) {
  1393. const result = window.ssVm.validateField(props.name);
  1394. console.log("validate", window.ssVm.validateField(props.name));
  1395. errMsg.value = result.valid ? "" : result.message;
  1396. }
  1397. };
  1398. Vue.onMounted(() => {
  1399. /**
  1400. * 初始化级联菜单值初始值思路:
  1401. * 1. 带隐藏字段(即带编码规则)的级联菜单
  1402. * 在隐藏字段这,可以取到要回显的值和编码规则,从而计算出各级下拉菜单要回显的值。
  1403. * 然后通过ajax取各级级联菜单的值回显。
  1404. * 2. 不带隐藏字段的级联,只能在各个下拉菜单的setup事件中通过ajax取回显值回显
  1405. */
  1406. // 当同组级联下拉菜单选中值变化时,会调用本隐藏字段下面这方法设置隐藏字段值
  1407. window.addEventListener(
  1408. "cascader-setHiddenVal-" + props.name,
  1409. (event) => {
  1410. const { value } = event.detail;
  1411. emit("update:modelValue", value);
  1412. console.log(value);
  1413. setTimeout(() => {
  1414. validate();
  1415. }, 50);
  1416. }
  1417. );
  1418. // 如果有初始值,触发回显过程
  1419. if (props.modelValue) {
  1420. console.log("级联隐藏字段,开始回显,初始值:", props.modelValue);
  1421. triggerCascaderEcho(props.modelValue);
  1422. validate();
  1423. }
  1424. });
  1425. // 触发级联回显
  1426. const triggerCascaderEcho = (code) => {
  1427. /**
  1428. * 开始回显,初始值: 440304
  1429. * 解析后的所有值: Array(3)0: "440000"1: "440300"2: "440304"length: 3[[Prototype]]: Array(0)
  1430. */
  1431. const values = parseHiddenCodeForAll(code, props.rule);
  1432. console.log("解析后的所有值:", values);
  1433. // 转换为 JSON 对象
  1434. // const paramObj = JSON.parse(props.param);
  1435. const paramObj = props.param;
  1436. let selectArr = paramObj.fieldOrd; //保存本组级联菜单项的数组,如:['hksheng','hkshi','hkxian']
  1437. if (selectArr.length != values.length) {
  1438. // alert('属性'+props.name+'的值'+code+'与级联菜单中下拉菜单的数目不匹配!');
  1439. return;
  1440. }
  1441. // 按顺序触发回显,并增加延迟确保数据加载
  1442. /**
  1443. * 通过隐藏字段的setup事件,
  1444. * 循环遍历各级下拉菜单,并触发定义在下拉菜单中的'cascader-echo'事件,
  1445. * 在此事件中完成每个下拉菜单回显值操作(只取当前要回显的键值对显示,
  1446. * 下拉菜单所有的值,在点击下拉菜单时,才通过ajax取)。
  1447. */
  1448. values.forEach((value, index) => {
  1449. if (value) {
  1450. setTimeout(() => {
  1451. let upperVal = undefined;
  1452. if (index != 0) {
  1453. upperVal = values[index - 1];
  1454. }
  1455. const echoEvent = new CustomEvent(
  1456. "cascader-echo-" + selectArr[index],
  1457. {
  1458. detail: {
  1459. name: props.name,
  1460. value: value,
  1461. // level: index + 1,
  1462. isAuto: true, // 标记为自动回显
  1463. upperVal: upperVal,
  1464. },
  1465. }
  1466. );
  1467. console.log(props.name + "--upperValue:" + upperVal);
  1468. window.dispatchEvent(echoEvent);
  1469. }, index * 500); // 每级增加500ms延迟
  1470. }
  1471. });
  1472. };
  1473. // 解析所有级别的代码
  1474. const parseHiddenCodeForAll = (code, rule) => {
  1475. if (!code || !rule) return [];
  1476. // 获取规则中每段的长度
  1477. const segments = [];
  1478. let currentChar = rule[0];
  1479. let currentLength = 1;
  1480. for (let i = 1; i < rule.length; i++) {
  1481. if (rule[i] === currentChar) {
  1482. currentLength++;
  1483. } else {
  1484. segments.push(currentLength);
  1485. currentChar = rule[i];
  1486. currentLength = 1;
  1487. }
  1488. }
  1489. segments.push(currentLength);
  1490. // 解析每一级的值
  1491. const values = [];
  1492. let position = 0;
  1493. segments.forEach((length, index) => {
  1494. const value = code
  1495. .substring(0, position + length)
  1496. .padEnd(rule.length, "0");
  1497. values.push(value);
  1498. position += length;
  1499. });
  1500. return values;
  1501. };
  1502. watchEffect(() => {});
  1503. return {};
  1504. },
  1505. template: `<input type="hidden" :name="name" :value="modelValue">`,
  1506. };
  1507. // ss-cascader 级联选择器
  1508. const SsCcp = {
  1509. name: "SsCcp",
  1510. inheritAttrs: false,
  1511. props: {
  1512. modelValue: String,
  1513. name: {
  1514. type: String,
  1515. required: true,
  1516. },
  1517. level: {
  1518. type: Number,
  1519. required: true,
  1520. },
  1521. opt: {
  1522. type: Array,
  1523. default: () => [],
  1524. },
  1525. placeholder: {
  1526. type: String,
  1527. default: "请选择",
  1528. },
  1529. width: {
  1530. type: String,
  1531. default: "150px",
  1532. },
  1533. direction: {
  1534. type: String,
  1535. default: "bottom",
  1536. },
  1537. mode: {
  1538. type: String,
  1539. default: "1",
  1540. },
  1541. //级联菜单配置参数,如果是数组,则代表本下拉菜单是多套级联菜单共用的第一级菜单。如果是对象,则只有一套级联菜单用此下拉菜单。
  1542. param: {
  1543. type: String,
  1544. required: true,
  1545. },
  1546. //向后台拿数据的url
  1547. url: {
  1548. type: String,
  1549. required: true,
  1550. },
  1551. },
  1552. emits: ["update:modelValue", "change"],
  1553. setup(props, { emit }) {
  1554. // alert('级联菜单初始化:'+props.name+':--:'+props.modelValue);
  1555. const selectItem = Vue.ref({ label: props.placeholder, value: "" });
  1556. const popupWinVisible = Vue.ref(false);
  1557. const isAutoEcho = Vue.ref(false); // 用于标记是否是自动回显
  1558. const upperValue = Vue.ref(""); //上级下拉菜单当前值,在初始化下拉菜单默认值时,和上级下拉菜单的值变化时,修改此upperValue变量
  1559. const popupDirection = Vue.ref("bottom");
  1560. const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
  1561. //有隐藏字段的下拉菜单,加载菜单项并展开事件
  1562. // 被上级下拉菜单选中值后,触发本下拉菜单刷新菜单项并弹出显示
  1563. window.addEventListener("cascader-open-" + props.name, async (event) => {
  1564. const { upperVal } = event.detail;
  1565. upperValue.value = upperVal;
  1566. console.log(
  1567. "22props.name:" +
  1568. props.name +
  1569. ",22props.upperValue:" +
  1570. upperValue.value
  1571. );
  1572. selectItem.value = ""; //清除本下拉菜单当前选中的值
  1573. emit("update:modelValue", ""); //通知父级
  1574. //清空下拉菜单,并设置第一项的值为placeholder
  1575. clearAndInit1stOpt();
  1576. //下个下拉菜单名
  1577. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1578. if (nextSelName) {
  1579. //清下个下拉菜单选中值和选项
  1580. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  1581. detail: {},
  1582. });
  1583. window.dispatchEvent(event);
  1584. }
  1585. showPopup();
  1586. });
  1587. //设置mode2的下级下拉菜单的上级菜单当前值
  1588. function setNextSelectUpperValue() {
  1589. //设置下级菜单的上级菜单当前值upperValue
  1590. let paramArr = undefined;
  1591. if (Array.isArray(props.param)) {
  1592. paramArr = props.param;
  1593. } else {
  1594. paramArr = [];
  1595. paramArr.push(props.param);
  1596. }
  1597. for (const oneParam of paramArr) {
  1598. //下个下拉菜单名
  1599. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  1600. if (nextSelName) {
  1601. setTimeout(() => {
  1602. const openNextEvent = new CustomEvent(
  1603. "cascade-setUpperVal-" + nextSelName,
  1604. {
  1605. detail: {
  1606. upperVal: props.modelValue,
  1607. },
  1608. }
  1609. );
  1610. window.dispatchEvent(openNextEvent);
  1611. }, 100);
  1612. }
  1613. } // end for
  1614. }
  1615. // 把上级 级联下拉菜单的值,设置进本组件的事件
  1616. window.addEventListener("cascade-setUpperVal-" + props.name, (event) => {
  1617. // alert('props.name:'+props.name+',props.upperValue:'+event.detail.upperVal);
  1618. const { upperVal } = event.detail;
  1619. upperValue.value = upperVal;
  1620. // console.log('props.name:'+props.name+',props.upperValue:'+upperValue.value);
  1621. });
  1622. //清空下拉菜单,并设置第一项的值为空
  1623. function clearAndInit1stOpt() {
  1624. if (props.opt)
  1625. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  1626. else {
  1627. props.opt = [];
  1628. }
  1629. props.opt.push({ label: "", value: "" });
  1630. }
  1631. //获取下一级下拉菜单,如果下一级下拉菜单不存在,则返回undefined
  1632. function getNextSel(selName, selNameArr) {
  1633. // 检查参数有效性
  1634. if (!Array.isArray(selNameArr) || selNameArr.length === 0) {
  1635. return undefined;
  1636. }
  1637. // 查找当前元素的索引
  1638. const currentIndex = selNameArr.indexOf(selName);
  1639. // 如果元素不存在或已经是最后一个元素,返回undefined
  1640. if (currentIndex === -1 || currentIndex === selNameArr.length - 1) {
  1641. return undefined;
  1642. }
  1643. // 返回下一个元素
  1644. return selNameArr[currentIndex + 1];
  1645. }
  1646. const validate = () => {
  1647. if (window.ssVm) {
  1648. return window.ssVm.validateField(props.name);
  1649. }
  1650. return { valid: true };
  1651. };
  1652. // 处理选择事件
  1653. const doSelectItem = (item) => {
  1654. selectItem.value = item;
  1655. emit("update:modelValue", item.value); //修改本下拉菜单在vue中保存的值
  1656. // alert('item.value:'+item.value);
  1657. if (props.mode === "1") {
  1658. // mode 1 模式:修改隐藏字段值
  1659. let event = new CustomEvent(
  1660. "cascader-setHiddenVal-" + props.param.combField,
  1661. {
  1662. detail: {
  1663. value: item.value,
  1664. },
  1665. }
  1666. );
  1667. window.dispatchEvent(event);
  1668. }
  1669. emit("change", item.value); //触发配置的change方法
  1670. nextTick(() => {
  1671. validate();
  1672. if (window.ssVm) {
  1673. for (const [field, rules] of window.ssVm.validations.entries()) {
  1674. for (const rule of rules) {
  1675. if (rule.options?.relField) {
  1676. const relFields = String(rule.options.relField)
  1677. .split(",")
  1678. .map((name) => name.trim())
  1679. .filter(Boolean);
  1680. if (relFields.includes(props.name)) {
  1681. window.ssVm.validateField(field);
  1682. }
  1683. }
  1684. }
  1685. }
  1686. }
  1687. });
  1688. //设置下级菜单的上级菜单当前值upperValue
  1689. let paramArr = undefined;
  1690. if (Array.isArray(props.param)) {
  1691. paramArr = props.param;
  1692. } else {
  1693. paramArr = [];
  1694. paramArr.push(props.param);
  1695. }
  1696. for (const oneParam of paramArr) {
  1697. //下个下拉菜单名
  1698. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  1699. if (nextSelName) {
  1700. setTimeout(() => {
  1701. const openNextEvent = new CustomEvent(
  1702. "cascader-open-" + nextSelName,
  1703. {
  1704. detail: {
  1705. upperVal: item.value,
  1706. },
  1707. }
  1708. );
  1709. window.dispatchEvent(openNextEvent);
  1710. }, 100);
  1711. }
  1712. } // end for
  1713. hidePopup();
  1714. //下个下拉菜单名
  1715. // let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1716. // if(nextSelName){
  1717. // // //设置下一级下拉菜单中保存的本下拉菜单值(upperValue)
  1718. // // event = new CustomEvent('cascade-setUpperVal-'+nextSelName, {
  1719. // // detail: {
  1720. // // value: item.value
  1721. // // }
  1722. // // });
  1723. // // window.dispatchEvent(event);
  1724. //
  1725. // //触发下一级下拉菜单,重新初始化下拉菜单项并弹出显示
  1726. // event = new CustomEvent('cascader-open-' +nextSelName, {
  1727. // detail: {
  1728. // upperVal: item.value
  1729. // }
  1730. // });
  1731. // window.dispatchEvent(event);
  1732. // }
  1733. // 只在手动选择时自动展开下一级
  1734. // if (!isAutoEcho.value) {
  1735. // const nextLevel = props.level + 1;
  1736. // setTimeout(() => {
  1737. // const openNextEvent = new CustomEvent('open-next-cascader', {
  1738. // detail: {
  1739. // name: props.name,
  1740. // level: nextLevel
  1741. // }
  1742. // });
  1743. // window.dispatchEvent(openNextEvent);
  1744. // }, 100);
  1745. // }
  1746. };
  1747. // 监听下一级展开事件 (仅 mode 2)
  1748. window.addEventListener("cascade-open", (event) => {
  1749. if (props.mode === "2") {
  1750. const { level } = event.detail;
  1751. if (level === props.level) {
  1752. popupWinVisible.value = true;
  1753. }
  1754. }
  1755. });
  1756. if (props.mode === "1") {
  1757. //如果是有隐藏字段的下拉菜单
  1758. // 监听回显事件
  1759. window.addEventListener(
  1760. "cascader-echo-" + props.name,
  1761. async (event) => {
  1762. const { name, value, isAuto, upperVal } = event.detail;
  1763. // level,
  1764. if (upperVal) {
  1765. upperValue.value = upperVal;
  1766. console.log(
  1767. "value:" +
  1768. value +
  1769. ",upperValue:" +
  1770. upperValue +
  1771. ",初始化级联组件时props.name:" +
  1772. props.name
  1773. );
  1774. }
  1775. // if (name === props.name && level === props.level) {
  1776. // 设置自动回显标记
  1777. isAutoEcho.value = true;
  1778. // if (props.opt.length === 0) {
  1779. // const loadDataEvent = new CustomEvent('cascader-load-data', {
  1780. // detail: {
  1781. // name: props.name,
  1782. // level: props.level,
  1783. // value: value
  1784. // }
  1785. // });
  1786. // window.dispatchEvent(loadDataEvent);
  1787. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  1788. //Vue.watch用于监听数据的变化,并在数据变化时执行特定的回调函数。
  1789. //这段代码使用了 Vue.js 的 watch API 来监听 props.opt 的变化,如果props.opt有变化,则自动
  1790. // const unwatch = Vue.watch(
  1791. // () => props.opt, // 监听的数据源(props.opt)
  1792. // (newOptions) => { // 回调函数
  1793. // if (newOptions.length > 0) { // 条件判断
  1794. // matchAndSelect(value); // 执行逻辑
  1795. // unwatch(); // 停止监听
  1796. // }
  1797. // },
  1798. // { immediate: true } // 配置:立即触发一次
  1799. // );
  1800. // } else {
  1801. // matchAndSelect(value);
  1802. // }
  1803. // 初始化级联菜单在页面刚打开时的默认值
  1804. async function initDefaultValue(value) {
  1805. try {
  1806. // alert(1);
  1807. if (
  1808. props.url &&
  1809. props.param
  1810. // && props.modelValue 对于有rule编码规则的级联菜单(即mode=1),modelValue一定是空的,所以注释掉,修复mode=1的级联菜单无法回显问题。Ben(20251124)
  1811. ) {
  1812. // alert(2);
  1813. /**
  1814. * let objectPickerParam=
  1815. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  1816. * "\"name\":\"hksheng\"," +
  1817. * "\"cascadingName\":\"dq\",\"cascadingInputsName\":\"hkdqm\"," +
  1818. * "\"codebook\":\"sheng\"}",
  1819. * "objectpickertype":2,
  1820. * "objectpickervalue":"440000"
  1821. * };
  1822. */
  1823. const objectPickerParam = {
  1824. input: "false",
  1825. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  1826. name: props.name, //本下拉菜单名
  1827. cascadingName: props.param.name, //级联菜单名
  1828. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  1829. codebook: props.param.codebook,
  1830. };
  1831. const objectPickerParamStr =
  1832. JSON.stringify(objectPickerParam);
  1833. const params = new URLSearchParams();
  1834. params.append("objectpickerparam", objectPickerParamStr);
  1835. params.append("objectpickertype", "2");
  1836. params.append("objectpickervalue", value); //需回显的值
  1837. axios
  1838. .post(props.url, params, {
  1839. headers: {
  1840. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1841. },
  1842. })
  1843. .then((response) => {
  1844. // alert(JSON.stringify(response.data));
  1845. if ("timeout" == response.data.statusText) {
  1846. alert("网络超时!");
  1847. return;
  1848. }
  1849. if (response.data.result) {
  1850. const keys = Object.keys(response.data.result);
  1851. if (keys.length === 1) {
  1852. let code = keys[0];
  1853. let desc = response.data.result[keys[0]];
  1854. clearAndInit1stOpt();
  1855. props.opt.push({ label: desc, value: code });
  1856. if (value) matchAndSelect(value);
  1857. // updateSelectItem();
  1858. // alert('props.opt:'+JSON.stringify(props.opt));
  1859. }
  1860. }
  1861. });
  1862. }
  1863. } catch (error) {
  1864. alert(error);
  1865. // callback(null, error.message); // 失败回调,传递错误
  1866. }
  1867. }
  1868. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  1869. initDefaultValue(value);
  1870. // 延迟重置自动回显标记
  1871. setTimeout(() => {
  1872. isAutoEcho.value = false;
  1873. }, 500);
  1874. }
  1875. );
  1876. // 被上级下拉菜单触发的,清除选中值和下拉菜单选项
  1877. window.addEventListener(
  1878. "cascader-cleanOpt-" + props.name,
  1879. async (event) => {
  1880. upperValue.value = "";
  1881. selectItem.value = ""; //清除本下拉菜单当前选中的值
  1882. emit("update:modelValue", ""); //通知父级
  1883. //清空所有下拉菜单项
  1884. if (props.opt) {
  1885. props.opt.length = 0;
  1886. } else {
  1887. props.opt = [];
  1888. }
  1889. //下个下拉菜单名
  1890. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1891. // alert('nextSelName:'+nextSelName+'--,props.name:'+props.name);
  1892. if (nextSelName) {
  1893. //清下个下拉菜单选中值和选项
  1894. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  1895. detail: {},
  1896. });
  1897. window.dispatchEvent(event);
  1898. }
  1899. }
  1900. );
  1901. } else if (props.mode === "2") {
  1902. //没隐藏字段的下拉菜单,在这初始化默认值
  1903. let needInitParam = undefined;
  1904. if (Array.isArray(props.param)) {
  1905. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  1906. console.log("needInitParam最后一项:" + JSON.stringify(needInitParam));
  1907. } else {
  1908. needInitParam = props.param;
  1909. }
  1910. // 初始化级联菜单在页面刚打开时的默认值
  1911. async function initDefaultValue(value, param) {
  1912. try {
  1913. // alert(1);
  1914. if (props.url && param && props.modelValue) {
  1915. // alert(2);
  1916. /**
  1917. * let param=
  1918. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"rylbm,gwid\"," +
  1919. * "\"name\":\"gwid\",\"cascadingName\":\"rylb_gw\"," +
  1920. * "\"codebook\":\"gwByRylb\"}",
  1921. * "objectpickertype":2,
  1922. * "objectpickervalue":"102121"};
  1923. */
  1924. // alert('props.name:'+props.name+',props.param.fieldOrd:'+props.param.fieldOrd);
  1925. const objectPickerParam = {
  1926. input: "false",
  1927. cascadingLevel: param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  1928. name: props.name, //本下拉菜单名
  1929. cascadingName: param.name, //级联菜单名
  1930. codebook: param.codebook,
  1931. };
  1932. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  1933. const sendParams = new URLSearchParams();
  1934. sendParams.append("objectpickerparam", objectPickerParamStr);
  1935. sendParams.append("objectpickertype", "2");
  1936. sendParams.append("objectpickervalue", value); //需回显的值
  1937. axios
  1938. .post(props.url, sendParams, {
  1939. headers: {
  1940. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1941. },
  1942. })
  1943. .then((response) => {
  1944. // alert(JSON.stringify(response.data));
  1945. if ("timeout" == response.data.statusText) {
  1946. alert("网络超时!");
  1947. return;
  1948. }
  1949. if (response.data.result) {
  1950. const keys = Object.keys(response.data.result);
  1951. console.log(
  1952. "name:" +
  1953. props.name +
  1954. ",@@级联初始化默认值value:" +
  1955. value +
  1956. "--param:" +
  1957. JSON.stringify(param) +
  1958. "--objectPickerParamStr:" +
  1959. objectPickerParamStr +
  1960. "--response.data:" +
  1961. JSON.stringify(response.data)
  1962. );
  1963. if (keys.length === 1) {
  1964. let code = keys[0];
  1965. let desc = response.data.result[keys[0]];
  1966. if (props.opt)
  1967. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  1968. else {
  1969. props.opt = [];
  1970. }
  1971. props.opt.push({ label: desc, value: code });
  1972. if (value) matchAndSelect(value);
  1973. console.log(
  1974. "GOOD mode2回显的默认值:" +
  1975. JSON.stringify({ label: desc, value: code }) +
  1976. "--props.param:" +
  1977. JSON.stringify(param)
  1978. );
  1979. // updateSelectItem();
  1980. // alert('props.opt:'+JSON.stringify(props.opt));
  1981. }
  1982. }
  1983. });
  1984. }
  1985. } catch (error) {
  1986. alert(error);
  1987. // callback(null, error.message); // 失败回调,传递错误
  1988. }
  1989. // 重置自动回显标记
  1990. isAutoEcho.value = false;
  1991. }
  1992. // 初始化级联菜单在页面刚打开时的默认值
  1993. initDefaultValue(props.modelValue, needInitParam);
  1994. //设置mode2的下级下拉菜单的上级菜单当前值
  1995. setNextSelectUpperValue();
  1996. }
  1997. //选中要回显的默认值
  1998. const matchAndSelect = (value) => {
  1999. const matchedOption = props.opt.find((opt) => opt.value === value);
  2000. if (matchedOption) {
  2001. selectItem.value = matchedOption;
  2002. emit("update:modelValue", value);
  2003. emit("change", value);
  2004. }
  2005. };
  2006. // 计算弹出方向和最大高度的方法 by xu 20251212
  2007. // 当空间不足时限制popup高度并显示滚动条
  2008. const calculatePopupDirection = () => {
  2009. // 1. 获取select容器元素
  2010. const selectEl = document.querySelector(
  2011. `[name="${props.name}"]`
  2012. )?.nextElementSibling;
  2013. console.log("selectEl:" + selectEl, props.name);
  2014. if (!selectEl) return;
  2015. // 2. 获取位置信息
  2016. const selectRect = selectEl.getBoundingClientRect();
  2017. const viewportHeight = window.innerHeight;
  2018. // 3. 计算上下可用空间 by xu 20251212
  2019. const spaceBelow = viewportHeight - selectRect.bottom - 10; // 减10px留边距
  2020. const spaceAbove = selectRect.top - 10; // 减10px留边距
  2021. // 4. popup预估高度(假设每项36px,最多显示8项 + padding)
  2022. const estimatedPopupHeight = 300;
  2023. const minPopupHeight = 100; // 最小高度
  2024. console.log(
  2025. "[popup] 空间计算 - spaceAbove:",
  2026. spaceAbove,
  2027. "spaceBelow:",
  2028. spaceBelow,
  2029. "estimatedHeight:",
  2030. estimatedPopupHeight
  2031. );
  2032. // 5. 判断方向和最大高度 by xu 20251212
  2033. if (spaceBelow >= estimatedPopupHeight) {
  2034. // 下方空间足够,向下展开,不限制高度
  2035. popupDirection.value = "bottom";
  2036. popupMaxHeight.value = "none";
  2037. console.log("[popup] 向下展开,空间充足");
  2038. } else if (spaceAbove >= estimatedPopupHeight) {
  2039. // 上方空间足够,向上展开,不限制高度
  2040. popupDirection.value = "top";
  2041. popupMaxHeight.value = "none";
  2042. console.log("[popup] 向上展开,空间充足");
  2043. } else {
  2044. // 上下空间都不足,选择空间大的方向,并限制高度出滚动条
  2045. if (spaceBelow >= spaceAbove) {
  2046. popupDirection.value = "bottom";
  2047. popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px";
  2048. console.log(
  2049. "[popup] 向下展开,空间不足,限制高度:",
  2050. popupMaxHeight.value
  2051. );
  2052. } else {
  2053. popupDirection.value = "top";
  2054. popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px";
  2055. console.log(
  2056. "[popup] 向上展开,空间不足,限制高度:",
  2057. popupMaxHeight.value
  2058. );
  2059. }
  2060. }
  2061. };
  2062. //级联菜单点击事件
  2063. const togglePopup = () => {
  2064. if (!popupWinVisible.value) {
  2065. //如果当前下拉菜单是隐藏的,先ajax重新加载下拉菜单项,再显示。
  2066. showPopup();
  2067. } else {
  2068. hidePopup();
  2069. }
  2070. };
  2071. //显示下拉菜单,在此之前先清除下拉菜单项
  2072. const showPopup = () => {
  2073. //清空下拉菜单,并设置第一项的值为空
  2074. clearAndInit1stOpt();
  2075. Vue.nextTick(() => {
  2076. calculatePopupDirection();
  2077. });
  2078. let url = props.url;
  2079. let filterObj = props.param.filter;
  2080. if (filterObj) {
  2081. for (let k in filterObj) {
  2082. let v = filterObj[k];
  2083. url += "&" + k + "=" + v;
  2084. }
  2085. }
  2086. if (props.mode === "1") {
  2087. //如果是有隐藏字段的下拉菜单
  2088. console.log("666url:" + url);
  2089. // alert('url:'+url);
  2090. // 获取级联菜单所有下拉菜单项
  2091. async function getSelectItems(value) {
  2092. try {
  2093. // alert(1);
  2094. if (props.url && props.param) {
  2095. // alert(2);
  2096. /**
  2097. * param={"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  2098. * "\"name\":\"hksheng\",\"cascadingName\":\"dq\"," +
  2099. * "\"cascadingInputsName\":\"hkdqm\",\"codebook\":\"sheng\"}",
  2100. * "objectpickertype":1,//2表示获取要回显的一项,1表示获取所有下拉菜单项
  2101. * "upperValue":"440000"
  2102. * };
  2103. */
  2104. const objectPickerParam = {
  2105. input: "false",
  2106. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2107. name: props.name, //本下拉菜单名
  2108. cascadingName: props.param.name, //级联菜单名
  2109. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  2110. codebook: props.param.codebook,
  2111. };
  2112. console.log("mode1 upperValue.value:" + upperValue.value);
  2113. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2114. const params = new URLSearchParams();
  2115. params.append("objectpickerparam", objectPickerParamStr);
  2116. params.append("objectpickertype", "1");
  2117. if (upperValue.value) {
  2118. params.append("upperValue", upperValue.value);
  2119. }
  2120. // params.append('objectpickervalue', value); //需回显的值
  2121. axios
  2122. .post(url, params, {
  2123. headers: {
  2124. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2125. },
  2126. })
  2127. .then((response) => {
  2128. if ("timeout" == response.data.statusText) {
  2129. alert("网络超时!");
  2130. return;
  2131. }
  2132. if (response.data.result) {
  2133. const keys = Object.keys(response.data.result);
  2134. console.log(
  2135. "params:" +
  2136. params +
  2137. "@@response.data:" +
  2138. JSON.stringify(response.data)
  2139. );
  2140. if (keys.length > 0) {
  2141. for (let k in response.data.result) {
  2142. props.opt.push({
  2143. label: response.data.result[k],
  2144. value: k,
  2145. });
  2146. }
  2147. console.log("props.opt11:" + JSON.stringify(props.opt));
  2148. } else {
  2149. // 没有数据时打印日志 by xu 20251212
  2150. console.log("[ccp mode1] 接口返回空数据");
  2151. }
  2152. } else {
  2153. // result不存在时打印日志 by xu 20251212
  2154. console.log("[ccp mode1] 接口返回无result");
  2155. }
  2156. // 无论是否有数据,都显示popup by xu 20251212
  2157. if (!popupWinVisible.value) {
  2158. popupWinVisible.value = true;
  2159. }
  2160. });
  2161. }
  2162. } catch (error) {
  2163. alert(error);
  2164. // callback(null, error.message); // 失败回调,传递错误
  2165. }
  2166. }
  2167. getSelectItems(props.modelValue);
  2168. } else if (props.mode === "2") {
  2169. //没隐藏字段的下拉菜单
  2170. let needInitParam = undefined;
  2171. if (Array.isArray(props.param)) {
  2172. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  2173. console.log(
  2174. "needInitParam最后一项:" + JSON.stringify(needInitParam)
  2175. );
  2176. } else {
  2177. needInitParam = props.param;
  2178. }
  2179. // 获取级联菜单所有下拉菜单项
  2180. async function getSelectItems(value, sendParam) {
  2181. try {
  2182. // alert(1);
  2183. if (props.url && sendParam) {
  2184. // alert(2);
  2185. /**
  2186. * param="{\"input\":\"false\",\"cascadingLevel\":\"dwid,sjryid\",
  2187. * \"ryid\":\"111121\",\"name\":\"sjryid\",
  2188. * \"cascadingName\":\"dw_sjry\",\"codebook\":\"sjryByDw\"}"
  2189. */
  2190. const objectPickerParam = {
  2191. input: "false",
  2192. cascadingLevel: sendParam.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2193. name: props.name, //本下拉菜单名
  2194. cascadingName: sendParam.name, //级联菜单名
  2195. codebook: sendParam.codebook,
  2196. };
  2197. console.log("mode2 upperValue.value:" + upperValue.value);
  2198. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2199. const params = new URLSearchParams();
  2200. params.append("objectpickerparam", objectPickerParamStr);
  2201. params.append("objectpickertype", "1");
  2202. if (upperValue.value) {
  2203. params.append("upperValue", upperValue.value);
  2204. }
  2205. // params.append('objectpickervalue', value); //需回显的值
  2206. axios
  2207. .post(url, params, {
  2208. headers: {
  2209. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2210. },
  2211. })
  2212. .then((response) => {
  2213. if ("timeout" == response.data.statusText) {
  2214. alert("网络超时!");
  2215. return;
  2216. }
  2217. if (response.data.result) {
  2218. const keys = Object.keys(response.data.result);
  2219. console.log(
  2220. "params:" +
  2221. params +
  2222. "@@response.data:" +
  2223. JSON.stringify(response.data)
  2224. );
  2225. if (keys.length > 0) {
  2226. for (let k in response.data.result) {
  2227. props.opt.push({
  2228. label: response.data.result[k],
  2229. value: k,
  2230. });
  2231. }
  2232. console.log("props.opt11:" + JSON.stringify(props.opt));
  2233. } else {
  2234. // 没有数据时打印日志 by xu 20251212
  2235. console.log("[ccp mode2] 接口返回空数据");
  2236. }
  2237. } else {
  2238. // result不存在时打印日志 by xu 20251212
  2239. console.log("[ccp mode2] 接口返回无result");
  2240. }
  2241. // 无论是否有数据,都显示popup by xu 20251212
  2242. if (!popupWinVisible.value) {
  2243. popupWinVisible.value = true;
  2244. }
  2245. });
  2246. }
  2247. } catch (error) {
  2248. alert(error);
  2249. // callback(null, error.message); // 失败回调,传递错误
  2250. }
  2251. }
  2252. getSelectItems(props.modelValue, needInitParam);
  2253. // popupWinVisible.value = !popupWinVisible.value;
  2254. }
  2255. };
  2256. const hidePopup = () => {
  2257. popupWinVisible.value = false;
  2258. };
  2259. // 合并所有的 onMounted 逻辑
  2260. Vue.onMounted(() => {
  2261. window.addEventListener("resize", calculatePopupDirection);
  2262. // 1. 监听展开下一级事件
  2263. window.addEventListener("open-next-cascader", (event) => {
  2264. const { name, level } = event.detail;
  2265. if (name === props.name && level === props.level) {
  2266. popupWinVisible.value = true;
  2267. }
  2268. });
  2269. // 2. 监听级联事件
  2270. window.addEventListener("cascader-change", (event) => {
  2271. const { name, level, value } = event.detail;
  2272. if (name === props.name && level < props.level) {
  2273. selectItem.value = { label: "", value: "" };
  2274. emit("update:modelValue", "");
  2275. if (ssHidden) {
  2276. ssHidden.updateValue(value);
  2277. }
  2278. }
  2279. });
  2280. });
  2281. Vue.onUnmounted(() => {
  2282. window.removeEventListener("resize", calculatePopupDirection);
  2283. });
  2284. // 监听值变化,处理回显 (mode 2)
  2285. Vue.watch(
  2286. () => props.modelValue,
  2287. (newVal) => {
  2288. if (props.mode === "2" && newVal) {
  2289. // 使用 watchEffect 替代嵌套的 watch
  2290. Vue.watchEffect(() => {
  2291. if (props.opt.length > 0) {
  2292. const matchedOption = props.opt.find(
  2293. (opt) => opt.value === newVal
  2294. );
  2295. if (matchedOption) {
  2296. selectItem.value = matchedOption;
  2297. }
  2298. }
  2299. });
  2300. } else {
  2301. // 原有的值变化处理
  2302. const item = props.opt.find((it) => it.value === newVal);
  2303. if (item) {
  2304. selectItem.value = item;
  2305. } else {
  2306. selectItem.value = { label: "", value: "" };
  2307. }
  2308. }
  2309. },
  2310. { immediate: true }
  2311. );
  2312. // 监听选项变化,当数据加载完成时进行匹配
  2313. Vue.watch(
  2314. () => props.opt,
  2315. (newOptions) => {
  2316. if (newOptions.length > 0) {
  2317. const matchedOption = newOptions.find(
  2318. (opt) => opt.value === selectItem.value.value
  2319. );
  2320. if (matchedOption) {
  2321. selectItem.value = matchedOption;
  2322. emit("update:modelValue", matchedOption.value);
  2323. emit("change", matchedOption.value);
  2324. }
  2325. }
  2326. }
  2327. );
  2328. return {
  2329. selectItem,
  2330. popupWinVisible,
  2331. popupDirection,
  2332. popupMaxHeight, // 添加popup最大高度 by xu 20251212
  2333. togglePopup,
  2334. hidePopup,
  2335. doSelectItem,
  2336. };
  2337. },
  2338. template: `
  2339. <div class="input ss-ccp-container" style="position: relative" :style="{width: width}">
  2340. <input type="hidden" :name="name" :value="modelValue">
  2341. <div class="select-container" @mouseleave="hidePopup">
  2342. <div class="input" @click="togglePopup">
  2343. <input
  2344. type="hidden"
  2345. :name="name"
  2346. :value="selectItem.value"
  2347. />
  2348. <input
  2349. :placeholder="placeholder"
  2350. :value="selectItem.label"
  2351. disabled
  2352. style="pointer-events: none;"
  2353. />
  2354. <div class="suffix">
  2355. <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
  2356. </div>
  2357. </div>
  2358. <!-- popup弹出层,添加maxHeight和overflowY支持空间不足时滚动 by xu 20251212 -->
  2359. <div v-show="popupWinVisible" class="popup-win " :class="popupDirection" :style="{ maxHeight: popupMaxHeight, overflowY: popupMaxHeight !== 'none' ? 'auto' : 'visible' }">
  2360. <div v-if="opt && opt.length > 0" class="popup-content">
  2361. <div class="content-area">
  2362. <div
  2363. v-for="(item, index) in opt"
  2364. :key="index"
  2365. @click="doSelectItem(item)"
  2366. :class="{ active: item.value === selectItem.value }"
  2367. >
  2368. <span class="check-icon">
  2369. <ss-form-icon class="form-icon-select-checked" />
  2370. </span>
  2371. <span>{{ item.label }}</span>
  2372. </div>
  2373. </div>
  2374. </div>
  2375. <div v-else class="popup-content">
  2376. <div class="content-area">
  2377. <div class="content-area">
  2378. <span>无选项</span>
  2379. </div>
  2380. </div>
  2381. </div>
  2382. </div>
  2383. </div>
  2384. </div>
  2385. `,
  2386. };
  2387. // ss-date-picker 日期时间选择器组件
  2388. const SsDatePicker = {
  2389. name: "SsDatePicker",
  2390. props: {
  2391. modelValue: {
  2392. type: [String, Number, Date],
  2393. default: "",
  2394. },
  2395. name: {
  2396. type: String,
  2397. required: true,
  2398. },
  2399. type: {
  2400. type: String,
  2401. default: "date",
  2402. validator: (value) => ["date", "datetime", "time"].includes(value),
  2403. },
  2404. fmt: {
  2405. type: String,
  2406. default: null,
  2407. },
  2408. placeholder: {
  2409. type: String,
  2410. default: "",
  2411. },
  2412. width: {
  2413. type: String,
  2414. default: "100%",
  2415. },
  2416. },
  2417. emits: ["update:modelValue"],
  2418. setup(props, { emit }) {
  2419. const errMsg = ref("");
  2420. const validate = () => {
  2421. if (window.ssVm) {
  2422. const result = window.ssVm.validateField(props.name);
  2423. console.log("validate", window.ssVm.validateField(props.name));
  2424. errMsg.value = result.valid ? "" : result.message;
  2425. }
  2426. };
  2427. // 根据type确定默认格式
  2428. const defaultFormat = computed(() => {
  2429. switch (props.type) {
  2430. case "datetime":
  2431. return "YYYY-MM-DD HH:mm:ss";
  2432. case "date":
  2433. return "YYYY-MM-DD";
  2434. case "time":
  2435. return "HH:mm:ss";
  2436. }
  2437. });
  2438. const convertJavaFormatToElement = (javaFormat) => {
  2439. if (!javaFormat) return null;
  2440. return javaFormat
  2441. .replace("yyyy", "YYYY")
  2442. .replace("MM", "MM")
  2443. .replace("dd", "DD")
  2444. .replace("HH", "HH")
  2445. .replace("mm", "mm")
  2446. .replace("ss", "ss");
  2447. };
  2448. const finalFormat = computed(() => {
  2449. if (props.fmt) {
  2450. return convertJavaFormatToElement(props.fmt);
  2451. }
  2452. return defaultFormat.value;
  2453. });
  2454. // 使用 resolveComponent 获取组件
  2455. const ElDatePicker = resolveComponent("ElDatePicker");
  2456. const ElTimePicker = resolveComponent("ElTimePicker");
  2457. const SsFormIcon = resolveComponent("SsFormIcon");
  2458. const ElIcon = resolveComponent("ElIcon");
  2459. const handleValueUpdate = (val) => {
  2460. emit("update:modelValue", val);
  2461. emit("change", val); // 同时触发 change 事件
  2462. setTimeout(() => {
  2463. validate();
  2464. }, 50);
  2465. };
  2466. const dateType = computed(() => {
  2467. const fmt = props.fmt || "";
  2468. if (fmt.includes("HH:mm:ss")) {
  2469. return "datetime";
  2470. } else if (fmt.includes("HH:mm")) {
  2471. return "datetime";
  2472. } else if (fmt.includes("mm:ss")) {
  2473. return "time";
  2474. }
  2475. return "date";
  2476. });
  2477. let useTimePicker = true;
  2478. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  2479. if (props.fmt) {
  2480. //有fmt属性,则以fmt属性优先判断类型
  2481. if (/[dMy]/.test(props.fmt)) {
  2482. //如果有传入日期格式,且含年月日
  2483. useTimePicker = false;
  2484. } else {
  2485. useTimePicker = true;
  2486. }
  2487. } else if (props.type !== "time") {
  2488. useTimePicker = false;
  2489. }
  2490. return () =>
  2491. h("div", { class: "ss-date-picker", style: { width: props.width } }, [
  2492. h("input", {
  2493. type: "hidden",
  2494. name: props.name,
  2495. value: props.modelValue,
  2496. }),
  2497. // 选择组件
  2498. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  2499. modelValue: props.modelValue,
  2500. "onUpdate:modelValue": handleValueUpdate,
  2501. type: dateType.value,
  2502. format: finalFormat.value,
  2503. "value-format": finalFormat.value,
  2504. clearable: true,
  2505. placeholder: props.placeholder,
  2506. class: "custom-date-picker", // 用于自定义样式
  2507. "time-arrow-control": props.type === "datetime", // 修改这里
  2508. size: "large", // 添加这一行,改为 large 尺寸
  2509. style: { width: "100%" },
  2510. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  2511. }),
  2512. ]);
  2513. },
  2514. };
  2515. // ss-icon 图标
  2516. // v3.0 增加 class 属性分支:有 class 走新逻辑,否则走 v1.0 逻辑 by xu 20251212
  2517. // v3.0 用法: <ss-icon class="icon-obj-ry menu-icon" />
  2518. // v1.0 用法: <ss-icon name="setting" size="20px" />
  2519. const SsIcon = {
  2520. name: "SsIcon",
  2521. // v3.0 禁用 class 透传,手动处理 by xu 20251215
  2522. inheritAttrs: false,
  2523. props: {
  2524. // v1.0: 以下为旧属性
  2525. name: { type: String },
  2526. size: { type: [Number, String], default: 16 },
  2527. unit: { type: String, default: "px" },
  2528. color: String,
  2529. type: {
  2530. type: String,
  2531. default: ssIcon.name,
  2532. validator: function (value) {
  2533. return [ssIcon, commonIcon].some((icon) => icon.name === value);
  2534. },
  2535. },
  2536. },
  2537. emits: ["update:modelValue", "input", "blur", "change"],
  2538. setup(props, { emit, attrs }) {
  2539. // v3.0 分支:有 class 属性时直接渲染(从 attrs 获取) by xu 20251215
  2540. if (attrs.class) {
  2541. return () =>
  2542. h("i", { ...attrs, class: attrs.class + " icon-container" });
  2543. }
  2544. // v1.0 分支:原有逻辑
  2545. const useIconType = computed(() => {
  2546. return [ssIcon, commonIcon].find(
  2547. (iconConfig) => iconConfig.name === props.type
  2548. );
  2549. });
  2550. const iconName = computed(() => {
  2551. const iconConfig = useIconType.value; // 注意:使用 .value 来访问响应式引用的值
  2552. if (!iconConfig) {
  2553. console.error(`Icon type "${props.type}" not found.`);
  2554. return "";
  2555. }
  2556. const iconType = iconConfig.types[props.name];
  2557. if (!iconType) {
  2558. console.error(
  2559. `Icon name "${props.name}" not found in type "${props.type}".`
  2560. );
  2561. return "";
  2562. }
  2563. return `${iconConfig.prefix}${iconType}`;
  2564. });
  2565. // 类似地,你可以计算 fontFamily 和 style
  2566. const fontFamily = computed(() => {
  2567. return useIconType.value ? useIconType.value.family : "";
  2568. });
  2569. // console.log(iconName.value,fontFamily.value)
  2570. const style = computed(() => {
  2571. const sizeStyle = isNum(props.size)
  2572. ? `${props.size}${props.unit}`
  2573. : props.size;
  2574. const styleObj = {
  2575. fontSize: sizeStyle,
  2576. color: props.color || "",
  2577. };
  2578. return toStyleStr(styleObj);
  2579. });
  2580. // 使用渲染函数定义模板逻辑
  2581. return () =>
  2582. h("i", {
  2583. class: ["icon-container", iconName.value, fontFamily.value],
  2584. style: style.value,
  2585. });
  2586. },
  2587. };
  2588. // 通用icon
  2589. const SsCommonIcon = {
  2590. name: "SsCommonIcon",
  2591. props: {
  2592. class: {
  2593. type: String,
  2594. required: true,
  2595. },
  2596. },
  2597. setup(props) {
  2598. return () =>
  2599. h("i", {
  2600. class: props.class + " common-icon",
  2601. });
  2602. },
  2603. };
  2604. // 登录页icon
  2605. const SsLoginIcon = {
  2606. name: "SsLoginIcon",
  2607. props: {
  2608. class: {
  2609. type: String,
  2610. required: true,
  2611. },
  2612. },
  2613. setup(props) {
  2614. return () =>
  2615. h("div", {
  2616. class: props.class + " login-icon",
  2617. });
  2618. },
  2619. };
  2620. // 弹窗icon
  2621. const SsDialogIcon = {
  2622. name: "SsDialogIcon",
  2623. props: {
  2624. class: {
  2625. type: String,
  2626. required: true,
  2627. },
  2628. },
  2629. setup(props) {
  2630. return () =>
  2631. h("i", {
  2632. class: props.class + " dialog-icon",
  2633. });
  2634. },
  2635. };
  2636. // 全局左侧导航图标组件
  2637. const SsNavIcon = {
  2638. name: "SsNavIcon",
  2639. props: {
  2640. class: {
  2641. type: String,
  2642. required: true,
  2643. },
  2644. },
  2645. setup(props) {
  2646. return () =>
  2647. h("div", {
  2648. class: props.class + " nav-icon",
  2649. });
  2650. },
  2651. };
  2652. // 顶部工具栏图标组件
  2653. const SsHeaderIcon = {
  2654. name: "SsHeaderIcon",
  2655. props: {
  2656. class: {
  2657. type: String,
  2658. required: true,
  2659. },
  2660. },
  2661. setup(props) {
  2662. return () =>
  2663. h("div", {
  2664. class: props.class + " header-icon",
  2665. });
  2666. },
  2667. };
  2668. // 全局菜单图标组件
  2669. const SsGolbalMenuIcon = {
  2670. name: "SsGolbalMenuIcon",
  2671. props: {
  2672. class: {
  2673. type: String,
  2674. required: true,
  2675. },
  2676. },
  2677. setup(props) {
  2678. return () =>
  2679. h("div", {
  2680. class: props.class + " global-menu-icon",
  2681. });
  2682. },
  2683. };
  2684. // 全局查询列表卡片图标
  2685. const SsCartListIcon = {
  2686. name: "SsCartListIcon",
  2687. props: {
  2688. class: {
  2689. type: String,
  2690. required: true,
  2691. },
  2692. },
  2693. setup(props) {
  2694. return () =>
  2695. h("div", {
  2696. class: props.class + " cart-list-icon",
  2697. });
  2698. },
  2699. };
  2700. // 全局底部工具栏图标组件
  2701. const SsQuickIcon = {
  2702. name: "SsQuickIcon",
  2703. props: {
  2704. class: {
  2705. type: String,
  2706. required: true,
  2707. },
  2708. },
  2709. setup(props) {
  2710. return () =>
  2711. h("div", {
  2712. class: props.class + " quick-icon",
  2713. });
  2714. },
  2715. };
  2716. // 表单组件icon
  2717. const SsFormIcon = {
  2718. name: "SsFormIcon",
  2719. props: {
  2720. class: {
  2721. type: String,
  2722. required: true,
  2723. },
  2724. },
  2725. setup(props) {
  2726. return () =>
  2727. h("div", {
  2728. class: props.class + " form-icon",
  2729. });
  2730. },
  2731. };
  2732. // 弹窗底部按钮icon
  2733. const SsBottomDivIcon = {
  2734. name: "SsBottomDivIcon",
  2735. props: {
  2736. class: {
  2737. type: String,
  2738. required: true,
  2739. },
  2740. },
  2741. setup(props) {
  2742. return () =>
  2743. h("div", {
  2744. class: props.class + " bottom-div-icon",
  2745. });
  2746. },
  2747. };
  2748. // editor组件icon
  2749. const SsEditorIcon = {
  2750. name: "SsEditorIcon",
  2751. props: {
  2752. class: {
  2753. type: String,
  2754. required: true,
  2755. },
  2756. },
  2757. setup(props) {
  2758. return () =>
  2759. h("i", {
  2760. class: props.class + " editor-icon",
  2761. });
  2762. },
  2763. };
  2764. // ss-validate校验器
  2765. const SsValidate = {
  2766. name: "SsValidate",
  2767. props: {
  2768. errMsg: { type: String },
  2769. textAlign: { type: String, default: "left" },
  2770. style: { type: Object, default: () => ({}) },
  2771. },
  2772. template: `<div class="validate-vline"></div>
  2773. <div class="validate-tip" :style="style">
  2774. <div class="tip" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  2775. <div class="tip-more" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  2776. </div>`,
  2777. };
  2778. // ss-onoff-array 多选按钮 数组形式
  2779. const SsonoffArray = {
  2780. name: "SsonoffArray",
  2781. props: {
  2782. name: {
  2783. type: String,
  2784. required: true,
  2785. },
  2786. opt: {
  2787. type: Array,
  2788. default: () => [],
  2789. },
  2790. defaultValue: [String, Number, Array],
  2791. modelValue: [String, Number, Array],
  2792. multiple: {
  2793. // 新增多选模式属性
  2794. type: Boolean,
  2795. default: false,
  2796. },
  2797. // 是否允许一项都不选,默认true允许 by xu 20251212
  2798. null: {
  2799. type: Boolean,
  2800. default: true,
  2801. },
  2802. },
  2803. emits: ["update:modelValue"], // 允许更新 v-model 绑定的值
  2804. setup(props, { emit }) {
  2805. console.log("多选按钮", props.opt);
  2806. // 使用数组来存储选中值
  2807. const checkedValue = ref(
  2808. props.multiple
  2809. ? Array.isArray(props.defaultValue)
  2810. ? props.defaultValue
  2811. : []
  2812. : props.defaultValue
  2813. );
  2814. const errMsg = ref(props.errTip);
  2815. // 生成icon名字
  2816. const genIconName = (itemValue) => {
  2817. if (props.multiple) {
  2818. return checkedValue.value.includes(itemValue)
  2819. ? "form-icon-onoff-checked"
  2820. : "form-icon-onoff-unchecked";
  2821. }
  2822. return checkedValue.value === itemValue
  2823. ? "form-icon-onoff-checked"
  2824. : "form-icon-onoff-unchecked";
  2825. };
  2826. // 选中项
  2827. const selectItem = (value) => {
  2828. if (props.multiple) {
  2829. // 多选模式
  2830. const index = checkedValue.value.indexOf(value);
  2831. if (index === -1) {
  2832. checkedValue.value = [...checkedValue.value, value];
  2833. } else {
  2834. // 取消选中当前项
  2835. const newValue = checkedValue.value.filter((v) => v !== value);
  2836. // 如果不允许为空且取消后为空,则阻止取消操作 by xu 20251212
  2837. if (!props.null && newValue.length === 0) {
  2838. return; // 阻止取消最后一项
  2839. }
  2840. checkedValue.value = newValue;
  2841. }
  2842. } else {
  2843. // 单选模式
  2844. // 如果点击的是当前已选中的项,判断是否允许取消 by xu 20251212
  2845. if (checkedValue.value === value) {
  2846. if (!props.null) {
  2847. return; // 不允许为空时,阻止取消
  2848. }
  2849. checkedValue.value = ""; // 允许为空时,取消选中
  2850. } else {
  2851. checkedValue.value = value;
  2852. }
  2853. }
  2854. emit("update:modelValue", checkedValue.value);
  2855. nextTick(() => {
  2856. // 触发验证
  2857. if (window.ssVm) {
  2858. window.ssVm.validateField(props.name);
  2859. }
  2860. });
  2861. };
  2862. return { checkedValue, genIconName, selectItem };
  2863. },
  2864. // 使用渲染函数定义模板逻辑
  2865. render() {
  2866. const SsFormIcon = resolveComponent("ss-form-icon");
  2867. return h("div", { class: "radio-container" }, [
  2868. // 根据情况创建 input
  2869. this.multiple
  2870. ? this.checkedValue.length
  2871. ? // 多选且有选中值:为选中项创建 input
  2872. this.checkedValue.map((value) =>
  2873. h("input", {
  2874. type: "checkbox",
  2875. name: this.name,
  2876. value: value,
  2877. checked: true,
  2878. style: { display: "none" },
  2879. })
  2880. )
  2881. : // 多选但没有选中值:创建一个空值 input
  2882. h("input", {
  2883. type: "hidden",
  2884. name: this.name,
  2885. value: "",
  2886. })
  2887. : // 单选模式:创建一个 input
  2888. h("input", {
  2889. type: "hidden",
  2890. name: this.name,
  2891. value: this.checkedValue || "",
  2892. }),
  2893. this.opt.map((item, i) =>
  2894. h(
  2895. "div",
  2896. {
  2897. key: i,
  2898. class: {
  2899. checked: this.multiple
  2900. ? this.checkedValue.includes(item.value)
  2901. : this.checkedValue === item.value,
  2902. },
  2903. style: { width: item.width },
  2904. onClick: () => this.selectItem(item.value),
  2905. },
  2906. [
  2907. h("span", null, item.label),
  2908. h("div", { class: "mark" }, [
  2909. h(SsFormIcon, {
  2910. class: this.genIconName(item.value),
  2911. }),
  2912. ]),
  2913. ]
  2914. )
  2915. ),
  2916. ]);
  2917. },
  2918. };
  2919. // ss-onoff 一个按钮
  2920. const Ssonoff = {
  2921. name: "Ssonoff",
  2922. props: {
  2923. name: {
  2924. type: String,
  2925. required: true,
  2926. },
  2927. label: {
  2928. type: String,
  2929. required: true,
  2930. },
  2931. value: {
  2932. type: [String, Number],
  2933. required: true,
  2934. },
  2935. width: {
  2936. type: String,
  2937. default: "",
  2938. },
  2939. onchange: {
  2940. // 在此属性传入 onChange 的 window 全局回调函数,第一参数是当前整组值 by Ben/xu(20260320)
  2941. type: String,
  2942. required: false,
  2943. },
  2944. modelValue: [String, Number, Array],
  2945. multiple: {
  2946. type: Boolean,
  2947. default: false,
  2948. },
  2949. null: {
  2950. type: Boolean,
  2951. default: true,
  2952. },
  2953. },
  2954. emits: ["update:modelValue", "change"],
  2955. setup(props, { emit }) {
  2956. const parseModelValue = (val) => {
  2957. if (Array.isArray(val)) {
  2958. return val
  2959. .map((item) => (item == null ? "" : item.toString()))
  2960. .filter(Boolean);
  2961. }
  2962. if (val == null || val === "") return [];
  2963. // 如果以逗号开头,去掉开头的逗号
  2964. const cleanValue = val.toString().replace(/^,+/, "");
  2965. if (!cleanValue) return [];
  2966. if (cleanValue.includes("|")) {
  2967. return cleanValue.split("|").filter(Boolean);
  2968. }
  2969. if (cleanValue.includes(",")) {
  2970. return cleanValue.split(",").filter(Boolean);
  2971. }
  2972. return [cleanValue];
  2973. };
  2974. const callGlobalOnchg = (groupValue) => {
  2975. if (props.onchange && typeof props.onchange === "string") {
  2976. if (
  2977. typeof window !== "undefined" &&
  2978. window[props.onchange] &&
  2979. typeof window[props.onchange] === "function"
  2980. ) {
  2981. try {
  2982. window[props.onchange](groupValue, props.value, props.label);
  2983. } catch (error) {
  2984. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  2985. }
  2986. } else {
  2987. console.warn(`全局函数 ${props.onchange} 未定义或不是一个函数。`);
  2988. }
  2989. }
  2990. };
  2991. // 判断当前按钮是否选中
  2992. const isChecked = computed(() => {
  2993. if (props.multiple) {
  2994. const currentValue = parseModelValue(props.modelValue);
  2995. return currentValue.includes(props.value.toString());
  2996. }
  2997. return props.modelValue + "" === props.value + ""; //强转为字符串类型再比较(改之前是数字类型和字符串类型作比较,永远为false) Ben 20251206
  2998. });
  2999. // 切换选中状态
  3000. const toggleSelect = () => {
  3001. let newModelValue;
  3002. if (props.multiple) {
  3003. const currentValue = parseModelValue(props.modelValue);
  3004. const currentButtonValue = props.value.toString();
  3005. const index = currentValue.indexOf(currentButtonValue);
  3006. let newValue;
  3007. if (index === -1) {
  3008. // 选中当前项
  3009. newValue = [...currentValue, currentButtonValue];
  3010. } else {
  3011. // 取消选中当前项
  3012. const filteredValue = currentValue.filter(
  3013. (value) => value !== currentButtonValue
  3014. );
  3015. // 如果不允许为空且取消后为空,则阻止取消操作
  3016. if (!props.null && filteredValue.length === 0) {
  3017. return; // 阻止取消最后一项
  3018. }
  3019. newValue = filteredValue;
  3020. }
  3021. newModelValue = newValue.join(",");
  3022. } else {
  3023. // 单选模式
  3024. const currentValue = parseModelValue(props.modelValue);
  3025. const isCurrentlySelected = currentValue.includes(
  3026. props.value.toString()
  3027. );
  3028. if (!isCurrentlySelected) {
  3029. // 选中当前项
  3030. newModelValue = props.value;
  3031. } else {
  3032. // 取消选中当前项
  3033. // 如果不允许为空且当前只有这一项被选中,则阻止取消操作
  3034. if (!props.null && currentValue.length === 1) {
  3035. return; // 阻止取消唯一选中项
  3036. }
  3037. newModelValue = "";
  3038. }
  3039. }
  3040. emit("update:modelValue", newModelValue);
  3041. emit("change", newModelValue, props.value, props.label);
  3042. callGlobalOnchg(newModelValue);
  3043. nextTick(() => {
  3044. // 触发验证
  3045. if (window.ssVm) {
  3046. window.ssVm.validateField(props.name);
  3047. }
  3048. });
  3049. };
  3050. return { isChecked, toggleSelect };
  3051. },
  3052. render() {
  3053. const SsFormIcon = resolveComponent("ss-form-icon");
  3054. return h("div", { class: "radio-container2" }, [
  3055. // 隐藏的表单元素
  3056. this.multiple
  3057. ? h("input", {
  3058. type: "hidden",
  3059. name: `${this.name}`, // 多选模式下使用数组形式的 name
  3060. value: this.isChecked ? this.value : "",
  3061. })
  3062. : this.isChecked &&
  3063. h("input", {
  3064. // 只有当前按钮被选中时才创建 input
  3065. type: "hidden",
  3066. name: this.name,
  3067. value: this.value,
  3068. }),
  3069. // 按钮显示
  3070. h(
  3071. "div",
  3072. {
  3073. class: { checked: this.isChecked },
  3074. style: { width: this.width },
  3075. onClick: this.toggleSelect,
  3076. },
  3077. [
  3078. h("span", null, this.label),
  3079. h("div", { class: "mark" }, [
  3080. h(SsFormIcon, {
  3081. class: this.isChecked
  3082. ? "form-icon-onoff-checked"
  3083. : "form-icon-onoff-unchecked",
  3084. }),
  3085. ]),
  3086. ]
  3087. ),
  3088. ]);
  3089. },
  3090. };
  3091. // ss-textarea
  3092. // ss-textarea
  3093. const SsTextarea = {
  3094. name: "SsTextarea",
  3095. props: {
  3096. name: {
  3097. type: String,
  3098. required: true,
  3099. },
  3100. placeholder: {
  3101. type: String,
  3102. default: "请输入",
  3103. },
  3104. defaultValue: [String, Number],
  3105. modelValue: [String, Number],
  3106. },
  3107. emits: ["update:modelValue"],
  3108. setup(props, { emit }) {
  3109. const inputValue = ref(props.modelValue || props.defaultValue || "");
  3110. // 监听 modelValue 变化
  3111. watch(
  3112. () => props.modelValue,
  3113. (newVal) => {
  3114. inputValue.value = newVal;
  3115. }
  3116. );
  3117. // 输入事件处理
  3118. const onInput = (event) => {
  3119. const newValue = event.target.value;
  3120. inputValue.value = newValue;
  3121. emit("update:modelValue", newValue);
  3122. // 触发验证
  3123. if (window.ssVm) {
  3124. window.ssVm.validateField(props.name);
  3125. }
  3126. };
  3127. // 失焦时验证
  3128. const onBlur = () => {
  3129. if (window.ssVm) {
  3130. window.ssVm.validateField(props.name);
  3131. }
  3132. };
  3133. return { inputValue, onInput, onBlur };
  3134. },
  3135. render() {
  3136. return h("div", { class: "textarea-container" }, [
  3137. h("div", { class: "textarea" }, [
  3138. h("input", {
  3139. type: "hidden",
  3140. name: this.name,
  3141. value: this.inputValue || "",
  3142. }),
  3143. h("textarea", {
  3144. placeholder: this.placeholder,
  3145. value: this.inputValue,
  3146. onInput: this.onInput,
  3147. onBlur: this.onBlur,
  3148. }),
  3149. ]),
  3150. ]);
  3151. },
  3152. };
  3153. // ss-editor 富文本编辑器 基于Jodit
  3154. const SsEditor = {
  3155. name: "SsEditor",
  3156. props: {
  3157. modelValue: {
  3158. type: String,
  3159. default: "",
  3160. },
  3161. html: {
  3162. type: String,
  3163. default: "",
  3164. },
  3165. name: {
  3166. type: String,
  3167. default: "",
  3168. },
  3169. url: {
  3170. type: String,
  3171. default: "",
  3172. },
  3173. height: {
  3174. type: [Number, String],
  3175. default: 400,
  3176. },
  3177. placeholder: {
  3178. type: String,
  3179. default: "请输入内容",
  3180. },
  3181. readonly: {
  3182. type: Boolean,
  3183. default: false,
  3184. },
  3185. uploadUrl: {
  3186. type: String,
  3187. default: "/ulByHttp", //原值为“upload” Ben(20251205)
  3188. },
  3189. param: {
  3190. type: Object,
  3191. default: () => ({}),
  3192. },
  3193. customButtons: {
  3194. type: Array,
  3195. default: () => [],
  3196. },
  3197. },
  3198. emits: ["update:modelValue", "ready", "change"],
  3199. setup(props, { emit }) {
  3200. const editorRef = ref(null);
  3201. const editorContent = ref("");
  3202. const currentModelValue = ref(props.modelValue || "");
  3203. const uniqueId = "editor-" + Date.now();
  3204. const errMsg = Vue.ref("");
  3205. // button 支持对象(旧格式,单个附件按钮)或数组(新格式,多个按钮)by xu 20250331
  3206. const buttonConfigRaw = props.param && props.param.button ? props.param.button : null;
  3207. const buttonArray = Array.isArray(buttonConfigRaw)
  3208. ? buttonConfigRaw
  3209. : buttonConfigRaw
  3210. ? [buttonConfigRaw]
  3211. : [];
  3212. // 找到附件按钮配置(有 cmsAddUrl 的)
  3213. const fjButton = buttonArray.find(btn => btn.cmsAddUrl && btn.cmsUpdUrl) || {};
  3214. const fjid = ref(fjButton.val || null);
  3215. const fjName = fjButton.desc || "附件";
  3216. // 筛选出自定义按钮(有 func 的)
  3217. const customButtonsFromParam = buttonArray.filter(btn => btn.func).map(btn => ({
  3218. name: btn.name,
  3219. text: btn.desc || btn.text,
  3220. tooltip: btn.desc || btn.tooltip,
  3221. icon: btn.icon || 'editor-icon-file',
  3222. onClick: btn.func // 函数名字符串
  3223. }));
  3224. const mode = props.param ? props.param.mode : null;
  3225. const normalizeHtml = (rawHtml) => {
  3226. if (rawHtml == null) {
  3227. return "";
  3228. }
  3229. const html = String(rawHtml).trim();
  3230. if (!html) {
  3231. return "";
  3232. }
  3233. if (
  3234. /<html[\s>]/i.test(html) ||
  3235. /<body[\s>]/i.test(html) ||
  3236. /<!doctype/i.test(html)
  3237. ) {
  3238. try {
  3239. const doc = new DOMParser().parseFromString(html, "text/html");
  3240. if (doc && doc.body) {
  3241. return doc.body.innerHTML || "";
  3242. }
  3243. } catch (e) {
  3244. console.warn("ss-editor 解析完整HTML失败,回退原始内容:", e);
  3245. }
  3246. }
  3247. return html;
  3248. };
  3249. const syncHiddenContentInput = (html) => {
  3250. const contentElements = document.getElementsByName(
  3251. props.name.replace(/wj$/, "") + "Edit"
  3252. );
  3253. if (contentElements.length > 0) {
  3254. contentElements[0].value = html;
  3255. }
  3256. };
  3257. const setEditorHtml = (html) => {
  3258. const normalizedHtml = normalizeHtml(html);
  3259. editorContent.value = normalizedHtml;
  3260. syncHiddenContentInput(normalizedHtml);
  3261. if (editorRef.value && editorRef.value.value !== normalizedHtml) {
  3262. editorRef.value.value = normalizedHtml;
  3263. }
  3264. };
  3265. const resolveWindowFunction = (handlerName) => {
  3266. if (!handlerName || typeof handlerName !== "string") {
  3267. return null;
  3268. }
  3269. return handlerName.split(".").reduce((current, key) => {
  3270. return current && current[key] != null ? current[key] : null;
  3271. }, window);
  3272. };
  3273. const getCustomButtonKey = (button, index) => {
  3274. const baseName =
  3275. (button &&
  3276. (button.key || button.name || button.text || button.tooltip)) ||
  3277. `button${index + 1}`;
  3278. return `ssCustomButton_${String(baseName).replace(
  3279. /[^a-zA-Z0-9_-]/g,
  3280. "_"
  3281. )}_${index}`;
  3282. };
  3283. const normalizeCustomButtons = (buttons = []) => {
  3284. return Array.isArray(buttons)
  3285. ? buttons.filter(Boolean).map((button, index) => ({
  3286. ...button,
  3287. _buttonKey: getCustomButtonKey(button, index),
  3288. }))
  3289. : [];
  3290. };
  3291. const renderButtonIcon = (icon) => {
  3292. if (!icon) {
  3293. return null;
  3294. }
  3295. if (typeof icon === "string" && icon.trim().startsWith("<")) {
  3296. return icon;
  3297. }
  3298. return `<span class="editor-icon ${icon}"></span>`;
  3299. };
  3300. const buildCustomButtonRegistry = (buttons = []) => {
  3301. const controls = {};
  3302. const buttonNames = [];
  3303. const iconMap = {};
  3304. normalizeCustomButtons(buttons).forEach((button) => {
  3305. const buttonKey = button._buttonKey;
  3306. const handler =
  3307. button.onClick ||
  3308. button.click ||
  3309. button.handler ||
  3310. button.exec ||
  3311. null;
  3312. const tooltip =
  3313. button.tooltip ||
  3314. button.text ||
  3315. button.label ||
  3316. button.name ||
  3317. "自定义按钮";
  3318. buttonNames.push(buttonKey);
  3319. if (button.icon) {
  3320. iconMap[buttonKey] = button.icon;
  3321. }
  3322. controls[buttonKey] = {
  3323. name: button.name || buttonKey,
  3324. tooltip,
  3325. exec: function (editor) {
  3326. const context = {
  3327. editor,
  3328. button,
  3329. props,
  3330. value:
  3331. editor && typeof editor.value !== "undefined"
  3332. ? editor.value
  3333. : "",
  3334. setValue: (value) => setEditorHtml(value),
  3335. getValue: () =>
  3336. editor && typeof editor.value !== "undefined"
  3337. ? editor.value
  3338. : "",
  3339. emit,
  3340. currentModelValue: currentModelValue.value,
  3341. fjid: fjid.value,
  3342. };
  3343. if (typeof handler === "function") {
  3344. return handler(context);
  3345. }
  3346. if (typeof handler === "string") {
  3347. const windowHandler = resolveWindowFunction(handler);
  3348. if (typeof windowHandler === "function") {
  3349. return windowHandler(context);
  3350. }
  3351. console.warn("ss-editor 自定义按钮未找到点击事件:", handler);
  3352. return undefined;
  3353. }
  3354. console.warn("ss-editor 自定义按钮缺少点击事件配置:", button);
  3355. return undefined;
  3356. },
  3357. };
  3358. });
  3359. return {
  3360. controls,
  3361. buttonNames,
  3362. iconMap,
  3363. };
  3364. };
  3365. const validate = () => {
  3366. if (window.ssVm) {
  3367. const result = window.ssVm.validateField(props.name);
  3368. console.log("validate", window.ssVm.validateField(props.name));
  3369. errMsg.value = result.valid ? "" : result.message;
  3370. }
  3371. };
  3372. onMounted(() => {
  3373. validate();
  3374. // 如果 prop 为空,尝试从各种来源读取按钮配置
  3375. let buttonsToUse = props.customButtons;
  3376. if (!buttonsToUse || buttonsToUse.length === 0) {
  3377. // 1. 优先从 param.button 数组中筛选(新格式)by xu 20250331
  3378. if (customButtonsFromParam && customButtonsFromParam.length > 0) {
  3379. buttonsToUse = customButtonsFromParam;
  3380. }
  3381. // 2. 尝试从 param.customButtons 读取(旧格式,兼容)
  3382. if (!buttonsToUse || buttonsToUse.length === 0) {
  3383. if (props.param && props.param.customButtons && props.param.customButtons.length > 0) {
  3384. buttonsToUse = props.param.customButtons;
  3385. }
  3386. }
  3387. // 3. 尝试通过桥接 API 读取
  3388. if (!buttonsToUse || buttonsToUse.length === 0) {
  3389. const vm = window.SS.dom.getVueApp({ scope: "chain" });
  3390. if (vm && vm.zwwjCustomButtons) {
  3391. buttonsToUse = vm.zwwjCustomButtons;
  3392. }
  3393. }
  3394. // 4. 从 formElemConfig 读取(兜底)
  3395. if (!buttonsToUse || buttonsToUse.length === 0) {
  3396. const zwwjConfig = window.SS.dom.formElemConfig?.zwwj;
  3397. if (zwwjConfig?.customButtons) {
  3398. buttonsToUse = zwwjConfig.customButtons;
  3399. } else {
  3400. buttonsToUse = window.SS.dom.formElemConfig?.zwwjCustomButtons;
  3401. }
  3402. }
  3403. }
  3404. const {
  3405. controls: customButtonControls,
  3406. buttonNames: customButtonNames,
  3407. iconMap: customButtonIconMap,
  3408. } = buildCustomButtonRegistry(buttonsToUse);
  3409. console.log(
  3410. "[SsEditor] 解析后的按钮:",
  3411. customButtonNames,
  3412. customButtonControls
  3413. );
  3414. const appendCustomButtons = (buttons = []) => {
  3415. if (!customButtonNames.length) {
  3416. return buttons;
  3417. }
  3418. const toolbarButtons = [...buttons];
  3419. const insertIndex = toolbarButtons.includes("dots")
  3420. ? toolbarButtons.indexOf("dots")
  3421. : toolbarButtons.includes("print")
  3422. ? toolbarButtons.indexOf("print")
  3423. : -1;
  3424. if (insertIndex >= 0) {
  3425. toolbarButtons.splice(insertIndex, 0, ...customButtonNames);
  3426. return toolbarButtons;
  3427. }
  3428. return [...toolbarButtons, ...customButtonNames];
  3429. };
  3430. const editor = Jodit.make(`#${uniqueId}`, {
  3431. height: props.height,
  3432. placeholder: props.placeholder,
  3433. readonly: props.readonly,
  3434. language: "zh_cn",
  3435. i18n: {
  3436. zh_cn: {
  3437. Link: "链接",
  3438. URL: "链接",
  3439. "No follow": "无跟踪",
  3440. "Class name": "类名",
  3441. Image: "图片",
  3442. File: "文件",
  3443. "Line height": "行高",
  3444. Alternative: "描述",
  3445. "Alternative text": "描述",
  3446. "Lower Alpha": "小写字母",
  3447. "Upper Alpha": "大写字母",
  3448. "Upper Roman": "大写罗马数字",
  3449. "Lower Roman": "小写罗马数字",
  3450. "Lower Greek": "小写希腊字母",
  3451. "Lower Letter": "小写字母",
  3452. "Upper Letter": "大写字母",
  3453. },
  3454. },
  3455. showXPathInStatusbar: false,
  3456. showCharsCounter: false,
  3457. showWordsCounter: false,
  3458. allowResizeY: false,
  3459. toolbarSticky: false,
  3460. statusbar: false,
  3461. uploader: {
  3462. url: props.uploadUrl,
  3463. format: "json",
  3464. method: "POST",
  3465. filesVariableName: function (i) {
  3466. return "imgs[" + i + "]";
  3467. },
  3468. headers: {
  3469. Accept: "application/json",
  3470. },
  3471. prepareData: function (formData) {
  3472. return formData;
  3473. },
  3474. isSuccess: function (resp) {
  3475. console.log("isSuccess resp:", resp);
  3476. return resp.code === 0;
  3477. },
  3478. getMessage: function (resp) {
  3479. console.log("getMessage resp:", resp);
  3480. return resp.msg || "上传失败";
  3481. },
  3482. process: function (resp) {
  3483. console.log("process resp:", resp);
  3484. return resp.data.url;
  3485. },
  3486. error: function (e) {
  3487. console.error("上传失败:", e.message);
  3488. },
  3489. defaultHandlerSuccess: function (resp) {
  3490. console.log("上传成功:", resp);
  3491. },
  3492. defaultHandlerError: function (err) {
  3493. console.error("上传错误:", err);
  3494. },
  3495. contentType: function () {
  3496. return false;
  3497. },
  3498. },
  3499. controls: {
  3500. font: {
  3501. list: {
  3502. Arial: "Arial",
  3503. SimSun: "宋体",
  3504. SimHei: "黑体",
  3505. "Microsoft YaHei": "微软雅黑",
  3506. KaiTi: "楷体",
  3507. FangSong: "仿宋",
  3508. "Times New Roman": "Times New Roman",
  3509. "Courier New": "Courier New",
  3510. },
  3511. },
  3512. customLinkButton: {
  3513. name: "link",
  3514. tooltip: "附件",
  3515. exec: function () {
  3516. if (!fjButton.cmsAddUrl || !fjButton.cmsUpdUrl) {
  3517. console.warn("ss-editor 未配置附件按钮地址,忽略附件操作");
  3518. return;
  3519. }
  3520. if (fjid.value == null || fjid.value === "") {
  3521. $.ajax({
  3522. type: "post",
  3523. url: fjButton.cmsAddUrl,
  3524. async: false,
  3525. data: {
  3526. name: "fjid",
  3527. ssNrObjName: "sh",
  3528. ssNrObjId: "",
  3529. },
  3530. success: function (_fjid) {
  3531. console.log("cmsAddUrl success", _fjid);
  3532. fjid.value = _fjid;
  3533. },
  3534. });
  3535. }
  3536. var str =
  3537. "&nrid=T-" +
  3538. fjid.value +
  3539. "&objectId=" +
  3540. fjid.value +
  3541. "&objectName=" +
  3542. fjName +
  3543. "&callback=" +
  3544. (window["fjidCallbackName"] || "");
  3545. console.log("str", str);
  3546. SS.openDialog({
  3547. src: buttonConfig.cmsUpdUrl + str,
  3548. headerTitle: "编辑",
  3549. width: 900,
  3550. high: 664,
  3551. zIndex: 51,
  3552. });
  3553. },
  3554. },
  3555. ...customButtonControls,
  3556. },
  3557. toolbarAdaptive: true,
  3558. // 调试:记录最终按钮配置
  3559. buttons: (() => {
  3560. const finalButtons = appendCustomButtons([
  3561. "fullsize",
  3562. "bold",
  3563. "italic",
  3564. "underline",
  3565. "strikethrough",
  3566. "eraser",
  3567. "|",
  3568. "font",
  3569. "fontsize",
  3570. "brush",
  3571. "paragraph",
  3572. "|",
  3573. "left",
  3574. "center",
  3575. "right",
  3576. "justify",
  3577. "|",
  3578. "ul",
  3579. "ol",
  3580. "indent",
  3581. "outdent",
  3582. "|",
  3583. "image",
  3584. "table",
  3585. "customLinkButton",
  3586. "print",
  3587. "|",
  3588. "undo",
  3589. "redo",
  3590. "find",
  3591. ]);
  3592. console.log("[SsEditor] 最终 buttons 配置:", finalButtons);
  3593. return finalButtons;
  3594. })(),
  3595. buttonsMD: appendCustomButtons([
  3596. "fullsize",
  3597. "bold",
  3598. "italic",
  3599. "underline",
  3600. "strikethrough",
  3601. "eraser",
  3602. "|",
  3603. "font",
  3604. "fontsize",
  3605. "brush",
  3606. "paragraph",
  3607. "|",
  3608. "font",
  3609. "fontsize",
  3610. "|",
  3611. "left",
  3612. "center",
  3613. "right",
  3614. "justify",
  3615. "|",
  3616. "image",
  3617. "customLinkButton",
  3618. "|",
  3619. "dots",
  3620. ]),
  3621. buttonsSM: appendCustomButtons([
  3622. "fullsize",
  3623. "bold",
  3624. "italic",
  3625. "|",
  3626. "image",
  3627. "|",
  3628. "dots",
  3629. ]),
  3630. buttonsXS: appendCustomButtons(["fullsize", "bold", "|", "dots"]),
  3631. sizeLG: 1024,
  3632. sizeMD: 768,
  3633. sizeSM: 576,
  3634. getIcon: function (name, clearName) {
  3635. const iconMap = {
  3636. bold: "editor-icon-bold",
  3637. italic: "editor-icon-italic",
  3638. underline: "editor-icon-underline",
  3639. strikethrough: "editor-icon-strikethrough",
  3640. eraser: "editor-icon-eraser",
  3641. copyformat: "editor-icon-copyformat",
  3642. font: "editor-icon-font",
  3643. fontsize: "editor-icon-fontsize",
  3644. brush: "editor-icon-brush",
  3645. paragraph: "editor-icon-paragraph",
  3646. left: "editor-icon-align-left",
  3647. center: "editor-icon-align-center",
  3648. right: "editor-icon-align-right",
  3649. justify: "editor-icon-align-justify",
  3650. ul: "editor-icon-ul",
  3651. ol: "editor-icon-ol",
  3652. indent: "editor-icon-indent",
  3653. outdent: "editor-icon-outdent",
  3654. image: "editor-icon-image",
  3655. file: "editor-icon-file",
  3656. video: "editor-icon-video",
  3657. table: "editor-icon-table",
  3658. link: "editor-icon-link",
  3659. source: "editor-icon-source",
  3660. eye: "editor-icon-preview",
  3661. fullsize: "editor-icon-fullsize",
  3662. shrink: "editor-icon-fullsize-exit",
  3663. print: "editor-icon-print",
  3664. undo: "editor-icon-undo",
  3665. redo: "editor-icon-redo",
  3666. search: "editor-icon-find",
  3667. selectall: "editor-icon-selectall",
  3668. };
  3669. const customIcon =
  3670. customButtonIconMap[clearName] || customButtonIconMap[name];
  3671. if (customIcon) {
  3672. return renderButtonIcon(customIcon);
  3673. }
  3674. const iconClass = iconMap[clearName] || iconMap[name];
  3675. if (iconClass) {
  3676. return renderButtonIcon(iconClass);
  3677. }
  3678. return null;
  3679. },
  3680. });
  3681. editorRef.value = editor;
  3682. editor.events.on("change", () => {
  3683. const html = editor.value || "";
  3684. editorContent.value = html;
  3685. syncHiddenContentInput(html);
  3686. emit("change", html);
  3687. setTimeout(() => {
  3688. validate();
  3689. }, 50);
  3690. });
  3691. emit("ready", editor);
  3692. if (props.html) {
  3693. setEditorHtml(props.html);
  3694. } else if (props.url) {
  3695. const params = new URLSearchParams();
  3696. if (mode) params.append("mode", mode);
  3697. if (props.modelValue) params.append("path", props.modelValue);
  3698. axios
  3699. .post(props.url, params, {
  3700. headers: {
  3701. "Content-Type": "application/x-www-form-urlencoded",
  3702. },
  3703. })
  3704. .then((response) => {
  3705. if ("timeout" == response.data.statusText) {
  3706. alert("网络超时!");
  3707. return;
  3708. }
  3709. const content = response.data.content;
  3710. if (content != null) {
  3711. setEditorHtml(content);
  3712. }
  3713. const filePath = response.data.path;
  3714. if (filePath) {
  3715. currentModelValue.value = filePath;
  3716. emit("update:modelValue", filePath);
  3717. }
  3718. });
  3719. } else {
  3720. setEditorHtml(props.html);
  3721. }
  3722. });
  3723. watch(
  3724. () => props.html,
  3725. (newValue) => {
  3726. setEditorHtml(newValue);
  3727. }
  3728. );
  3729. watch(
  3730. () => props.modelValue,
  3731. (newValue) => {
  3732. currentModelValue.value = newValue || "";
  3733. }
  3734. );
  3735. watch(
  3736. () => props.readonly,
  3737. (newValue) => {
  3738. if (editorRef.value) {
  3739. editorRef.value.setReadOnly(newValue);
  3740. }
  3741. }
  3742. );
  3743. // 监听 customButtons 变化,支持运行时动态更新 by xu 20250331
  3744. watch(
  3745. () => props.customButtons,
  3746. (newButtons) => {
  3747. if (!editorRef.value) return;
  3748. if (!newButtons || newButtons.length === 0) return;
  3749. console.log("[SsEditor] customButtons 变化:", newButtons);
  3750. const { controls, buttonNames } = buildCustomButtonRegistry(newButtons);
  3751. if (buttonNames.length === 0) return;
  3752. // 注册新控件到 Jodit
  3753. buttonNames.forEach((btnKey) => {
  3754. const control = controls[btnKey];
  3755. if (control && control.exec) {
  3756. // 使用 Jodit 的 register 方法注册新按钮
  3757. editorRef.value.controls.register(btnKey, control);
  3758. console.log("[SsEditor] 注册新按钮:", btnKey);
  3759. }
  3760. });
  3761. // 更新工具栏(需要重新构建)
  3762. const toolbar = editorRef.value.toolbar;
  3763. if (toolbar && toolbar.build) {
  3764. try {
  3765. // 获取当前配置并重新构建工具栏
  3766. const currentButtons = editorRef.value.options.buttons || [];
  3767. const newToolbarButtons = [...currentButtons, ...buttonNames];
  3768. editorRef.value.options.buttons = newToolbarButtons;
  3769. toolbar.build(newToolbarButtons, toolbar.container);
  3770. console.log("[SsEditor] 工具栏已更新,新按钮:", buttonNames);
  3771. } catch (e) {
  3772. console.warn("[SsEditor] 工具栏更新失败:", e);
  3773. }
  3774. }
  3775. },
  3776. { deep: true, immediate: false }
  3777. );
  3778. onBeforeUnmount(() => {
  3779. if (editorRef.value) {
  3780. editorRef.value.destruct();
  3781. }
  3782. });
  3783. return () =>
  3784. h("div", { class: "ss-editor-container" }, [
  3785. fjid.value &&
  3786. h("input", {
  3787. type: "hidden",
  3788. name: "fjid",
  3789. value: fjid.value,
  3790. }),
  3791. h("input", {
  3792. type: "hidden",
  3793. name: props.name.replace(/wj$/, "") + "Edit",
  3794. value: editorContent.value,
  3795. }),
  3796. h("input", {
  3797. type: "hidden",
  3798. name: props.name.replace(/wj$/, "") + "wj",
  3799. value: currentModelValue.value,
  3800. }),
  3801. h("input", {
  3802. type: "hidden",
  3803. name: "ueditorpath",
  3804. value: "mswj",
  3805. }),
  3806. h("textarea", { id: uniqueId }),
  3807. ]);
  3808. },
  3809. };
  3810. // 弹窗右边图标
  3811. const SsFullStyleHeader = {
  3812. name: "SsFullStyleHeader",
  3813. props: {
  3814. title: {
  3815. type: String,
  3816. default: "标题",
  3817. },
  3818. },
  3819. emits: ["close"],
  3820. setup(props, { emit }) {
  3821. // console.log(props.title)
  3822. const onClose = () => {
  3823. emit("close");
  3824. };
  3825. const SsIcon = resolveComponent("ss-icon");
  3826. return () =>
  3827. h("div", { class: "header-container" }, [
  3828. h("div", { class: "title" }, props.title),
  3829. h("div", { class: "handle-bar" }, [
  3830. h("div", { class: "left-bar" }, [
  3831. h(SsDialogIcon, { class: "dialog-icon-download" }),
  3832. h(SsDialogIcon, { class: "dialog-icon-print" }),
  3833. h(SsDialogIcon, { class: "dialog-icon-setting" }),
  3834. h(SsDialogIcon, { class: "dialog-icon-collect" }),
  3835. h(SsDialogIcon, { class: "dialog-icon-help" }),
  3836. h(SsDialogIcon, { class: "dialog-icon-full-screen" }),
  3837. h(SsDialogIcon, { class: "dialog-icon-lock" }),
  3838. ]),
  3839. h("div", { class: "close-bar", onClick: onClose }, [
  3840. h(SsDialogIcon, { class: "dialog-icon-close" }),
  3841. ]),
  3842. ]),
  3843. ]);
  3844. },
  3845. };
  3846. // ss-dialog弹窗
  3847. const SsDialog = {
  3848. name: "SsDialog",
  3849. props: {
  3850. src: {
  3851. type: String,
  3852. },
  3853. headerTitle: {
  3854. type: String,
  3855. // required: true,
  3856. default: "弹窗",
  3857. },
  3858. width: {
  3859. type: String,
  3860. default: "1400",
  3861. },
  3862. height: {
  3863. type: String,
  3864. default: "600",
  3865. },
  3866. params: {
  3867. type: Object,
  3868. default: () => ({}),
  3869. },
  3870. zIndex: {
  3871. type: Number,
  3872. default: 1000,
  3873. },
  3874. },
  3875. emits: ["close"],
  3876. setup(props, { slots, emit }) {
  3877. // 关闭窗口方法
  3878. const onClose = () => {
  3879. emit("close");
  3880. };
  3881. const showHeader = ref(true);
  3882. const headerVisible = ref(false);
  3883. const popupHieght = ref(props.height);
  3884. // 状态:存储位置信息
  3885. const position = reactive({
  3886. // 页面居中
  3887. x: (window.innerWidth - props.width) / 2,
  3888. y: (window.innerHeight - popupHieght.value) / 2,
  3889. isDragging: false,
  3890. offsetX: 0,
  3891. offsetY: 0,
  3892. });
  3893. // 鼠标按下时设置起始坐标并开始拖拽
  3894. const startDrag = (event) => {
  3895. position.isDragging = true;
  3896. position.offsetX = event.clientX - position.x;
  3897. position.offsetY = event.clientY - position.y;
  3898. };
  3899. // 鼠标移动时更新位置
  3900. const onDrag = (event) => {
  3901. if (position.isDragging) {
  3902. position.x = event.clientX - position.offsetX;
  3903. position.y = event.clientY - position.offsetY;
  3904. }
  3905. };
  3906. // 鼠标放开时结束拖拽
  3907. const endDrag = () => {
  3908. position.isDragging = false;
  3909. };
  3910. // 监听来自 iframe 的消息
  3911. const handleMessage = (event) => {
  3912. // 顶天立地
  3913. if (event.data && typeof event.data.hasScrollBar !== "undefined") {
  3914. if (event.data.hasScrollBar) {
  3915. // console.log(event);
  3916. position.y = 10;
  3917. showHeader.value = false;
  3918. headerVisible.value = true;
  3919. popupHieght.value = window.innerHeight - 20;
  3920. // console.log(popupHieght.value);
  3921. document.querySelector(".body").style.height = "100%";
  3922. document.querySelector(".body").style.paddingTop = "30px";
  3923. document.querySelector(".header-container ").style.position =
  3924. "absolute";
  3925. document.querySelector(".header-container ").style.zIndex = "10";
  3926. }
  3927. }
  3928. };
  3929. // 鼠标移入关闭按钮区域时显示头部
  3930. const onMouseEnterCloseButton = () => {
  3931. headerVisible.value = false;
  3932. };
  3933. // 鼠标移出关闭按钮区域时隐藏头部
  3934. const onMouseLeaveCloseButton = () => {
  3935. headerVisible.value = true;
  3936. };
  3937. // 在组件挂载时添加全局事件监听器
  3938. Vue.onMounted(() => {
  3939. // 如果传过来的高度大于窗口高度,则设置为窗口高度减去20 否则保持传过来的高度
  3940. popupHieght.value =
  3941. popupHieght.value > window.innerHeight
  3942. ? window.innerHeight - 20
  3943. : popupHieght.value;
  3944. const container = document.querySelector(".header-container");
  3945. if (container) {
  3946. container.addEventListener("mousedown", startDrag);
  3947. }
  3948. document.addEventListener("mousemove", onDrag);
  3949. document.addEventListener("mouseup", endDrag);
  3950. window.addEventListener("message", handleMessage);
  3951. });
  3952. // 在组件卸载时移除全局事件监听器
  3953. Vue.onUnmounted(() => {
  3954. document.removeEventListener("mousemove", onDrag);
  3955. document.removeEventListener("mouseup", endDrag);
  3956. window.removeEventListener("message", handleMessage);
  3957. });
  3958. const SsMark = resolveComponent("ss-mark");
  3959. const SsFullStyleHeader = resolveComponent("ss-full-style-header");
  3960. // render函数定义组件结构
  3961. return () =>
  3962. h(
  3963. Teleport,
  3964. { to: "body" }, // 使用 Teleport 将弹窗内容挂载到 body
  3965. h(SsMark, {}, [
  3966. h(
  3967. "div",
  3968. {
  3969. class: "popup-container",
  3970. style: {
  3971. position: "absolute",
  3972. left: `${position.x}px`,
  3973. top: `${position.y}px`,
  3974. width: props.width + "px",
  3975. height: popupHieght.value + "px",
  3976. zIndex: props.zIndex, // 确保弹窗在最上层
  3977. },
  3978. },
  3979. [
  3980. h(SsFullStyleHeader, {
  3981. class: "header",
  3982. title: props.headerTitle,
  3983. onClose: onClose,
  3984. onMousedown: startDrag, // 绑定拖动事件
  3985. onMouseUp: endDrag,
  3986. ...(!showHeader.value && {
  3987. onMouseenter: onMouseEnterCloseButton,
  3988. onMouseleave: onMouseLeaveCloseButton,
  3989. }),
  3990. style: {
  3991. cursor: position.isDragging ? "grabbing" : "grab",
  3992. visibility: headerVisible.value ? "hidden" : "visible",
  3993. },
  3994. }),
  3995. h(
  3996. "div",
  3997. {
  3998. class: "body",
  3999. style: {},
  4000. },
  4001. [
  4002. h("iframe", {
  4003. src: props.src,
  4004. frameborder: 0,
  4005. style: { width: "100%", height: "100%" },
  4006. }),
  4007. ]
  4008. ),
  4009. headerVisible.value &&
  4010. h("div", {
  4011. class: "close-button",
  4012. onMouseenter: onMouseEnterCloseButton,
  4013. onMouseleave: onMouseLeaveCloseButton,
  4014. style: {
  4015. position: "absolute",
  4016. top: "0",
  4017. right: "0",
  4018. // background: 'black',
  4019. width: "60px",
  4020. height: "60px",
  4021. cursor: "pointer",
  4022. },
  4023. }),
  4024. ]
  4025. ),
  4026. ])
  4027. );
  4028. },
  4029. };
  4030. // ss-mark遮罩层
  4031. const SsMark = {
  4032. name: "SsMark",
  4033. setup(props, { slots, emit }) {
  4034. return () =>
  4035. h("div", { class: "dialog-container" }, [
  4036. h("div", { class: "mark-content" }, [
  4037. h("div", { class: "dialog-contianer" }, [
  4038. slots.default ? slots.default() : "",
  4039. ]),
  4040. ]),
  4041. ]);
  4042. },
  4043. };
  4044. // ss-bottom-button 底部按钮
  4045. // 修改支持更多按钮 by xu 20251211
  4046. const SsBottomButton = {
  4047. name: "SsBottomButton",
  4048. props: {
  4049. text: {
  4050. type: String,
  4051. required: false,
  4052. },
  4053. type: {
  4054. type: String,
  4055. default: "button",
  4056. },
  4057. iconClass: {
  4058. type: String,
  4059. },
  4060. class: {
  4061. type: String,
  4062. default: "",
  4063. },
  4064. onclick: {
  4065. type: [Function, String],
  4066. default: null,
  4067. },
  4068. // 修改支持更多按钮 by xu 20251211
  4069. more: {
  4070. type: [Boolean, String],
  4071. default: false,
  4072. },
  4073. },
  4074. setup(props, { emit }) {
  4075. const SsBottomDivIcon = Vue.resolveComponent("ss-bottom-div-icon");
  4076. const showDropdown = Vue.ref(false);
  4077. // 修改支持更多按钮 by xu 20251211
  4078. const moreKey = Vue.computed(() => {
  4079. const val = props.more;
  4080. if (val === false || val === null || typeof val === "undefined") {
  4081. return null;
  4082. }
  4083. if (val === true || val === "" || val === "true") {
  4084. return "moreChg";
  4085. }
  4086. return val;
  4087. });
  4088. // 从配置中读取按钮信息和下拉选项
  4089. const config = Vue.computed(() => {
  4090. if (
  4091. moreKey.value &&
  4092. window.ss &&
  4093. window.ss.dom &&
  4094. window.ss.dom.btnElemConfig
  4095. ) {
  4096. return window.ss.dom.btnElemConfig[moreKey.value] || {};
  4097. }
  4098. return {};
  4099. });
  4100. const buttonText = Vue.computed(() => {
  4101. return props.text || config.value.desc || "";
  4102. });
  4103. const dropOptions = Vue.computed(() => {
  4104. return config.value.dropOptions || [];
  4105. });
  4106. const hasDropdown = Vue.computed(() => {
  4107. return dropOptions.value.length > 0;
  4108. });
  4109. const handleMouseEnter = () => {
  4110. if (hasDropdown.value) {
  4111. showDropdown.value = true;
  4112. }
  4113. };
  4114. const handleMouseLeave = () => {
  4115. showDropdown.value = false;
  4116. };
  4117. const handleDropItemClick = (option) => {
  4118. if (option.callback && typeof option.callback === "function") {
  4119. option.callback();
  4120. }
  4121. showDropdown.value = false;
  4122. };
  4123. return () =>
  4124. h(
  4125. "div",
  4126. {
  4127. class: "ss-bottom-button-wrapper",
  4128. onMouseenter: handleMouseEnter,
  4129. onMouseleave: handleMouseLeave,
  4130. },
  4131. [
  4132. h(
  4133. "button",
  4134. {
  4135. class: props.class,
  4136. onClick: (e) => {
  4137. e.stopPropagation();
  4138. emit("click", e);
  4139. if (props.onclick) {
  4140. // 如果是函数直接调用
  4141. if (typeof props.onclick === "function") {
  4142. props.onclick(e);
  4143. } else if (typeof props.onclick === "string") {
  4144. // 如果是字符串,使用直接的方法执行
  4145. // 临时存储按钮元素到全局变量
  4146. window.__ss_current_button = e.currentTarget;
  4147. // 直接执行代码,使用eval以保留原始上下文
  4148. try {
  4149. eval(props.onclick);
  4150. } finally {
  4151. // 清理全局变量
  4152. delete window.__ss_current_button;
  4153. }
  4154. }
  4155. }
  4156. },
  4157. type: props.type,
  4158. },
  4159. [
  4160. h("span", null, [
  4161. h(SsBottomDivIcon, {
  4162. class: props.iconClass,
  4163. }),
  4164. ]),
  4165. h("span", null, buttonText.value),
  4166. ]
  4167. ),
  4168. // 渲染下拉菜单
  4169. hasDropdown.value && showDropdown.value
  4170. ? h(
  4171. "div",
  4172. {
  4173. class: "ss-bottom-button-dropdown",
  4174. },
  4175. dropOptions.value.map((option) =>
  4176. h(
  4177. "div",
  4178. {
  4179. class: "ss-bottom-button-dropdown-item",
  4180. onClick: (e) => {
  4181. e.stopPropagation();
  4182. handleDropItemClick(option);
  4183. },
  4184. },
  4185. option.desc
  4186. )
  4187. )
  4188. )
  4189. : null,
  4190. ]
  4191. );
  4192. },
  4193. };
  4194. // ss-search搜索框
  4195. const SsSearch = {
  4196. name: "SsSearch",
  4197. props: {
  4198. theme: {
  4199. type: String,
  4200. default: "light",
  4201. validator: function (value) {
  4202. return ["dark", "light"].includes(value);
  4203. },
  4204. },
  4205. placeholder: {
  4206. type: String,
  4207. default: "请输入搜索条件",
  4208. },
  4209. },
  4210. setup(props, { emit }) {
  4211. const onClick = () => {
  4212. console.log("Search clicked");
  4213. emit("click");
  4214. };
  4215. const SsIcon = Vue.resolveComponent("ss-icon");
  4216. return () =>
  4217. Vue.h(
  4218. "div",
  4219. {
  4220. class: ["search-container", props.theme],
  4221. onClick: onClick,
  4222. },
  4223. [
  4224. Vue.h("input", {
  4225. placeholder: props.placeholder,
  4226. disabled: true,
  4227. }),
  4228. Vue.h(SsIcon, {
  4229. name: "search-result",
  4230. size: "20px",
  4231. }),
  4232. ]
  4233. );
  4234. },
  4235. };
  4236. // ss-cart-item 菜单页面的卡片 左右结构
  4237. const SsCartItem = {
  4238. name: "SsCartItem",
  4239. props: {
  4240. active: Boolean,
  4241. item: {
  4242. type: Object,
  4243. default: () => ({
  4244. thumb: "images/example/project-img.png",
  4245. title: "广州(国际)科技成果转化天河基地专",
  4246. description: "佳能中国广州分公司",
  4247. all: 50,
  4248. finish: 5,
  4249. }),
  4250. },
  4251. },
  4252. setup(props, { emit }) {
  4253. const item = props.item;
  4254. const itemWidth = Vue.computed(() => {
  4255. const containerWidth =
  4256. document.body.clientWidth || document.body.scrollWidth - 520;
  4257. const halfWidth = containerWidth / 2;
  4258. if (halfWidth < 480) {
  4259. return Math.min(containerWidth, 702) + "px";
  4260. } else {
  4261. return Math.min(halfWidth, 702) + "px";
  4262. }
  4263. });
  4264. const onItemClick = (e) => {
  4265. emit("click", e);
  4266. };
  4267. return {
  4268. item,
  4269. itemWidth,
  4270. onItemClick,
  4271. };
  4272. },
  4273. render() {
  4274. const SsIcon = Vue.resolveComponent("ss-icon");
  4275. return Vue.h(
  4276. "div",
  4277. {
  4278. class: { "item-container": true, active: this.active },
  4279. onClick: this.onItemClick,
  4280. style: { width: this.itemWidth },
  4281. },
  4282. [
  4283. Vue.h("div", { class: "header" }, [
  4284. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  4285. ]),
  4286. Vue.h("div", { class: "body" }, [
  4287. Vue.h("div", { class: "left" }, [
  4288. Vue.h("img", {
  4289. src: this.item.thumb,
  4290. alt: "Thumbnail",
  4291. class: "imgUnHandle",
  4292. style: { "object-fit": "cover", width: "100%", height: "100%" },
  4293. }),
  4294. ]),
  4295. Vue.h("div", { class: "right" }, [
  4296. Vue.h("div", { class: "title" }, this.item.title),
  4297. Vue.h("div", { class: "desc" }, this.item.description),
  4298. Vue.h("div", { class: "progress" }, [
  4299. Vue.h(
  4300. "div",
  4301. {
  4302. style: {
  4303. width: `${(this.item.finish / this.item.all) * 100}%`,
  4304. },
  4305. },
  4306. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  4307. ),
  4308. ]),
  4309. ]),
  4310. ]),
  4311. ]
  4312. );
  4313. },
  4314. };
  4315. // ss-cart-item2 菜单页面的卡片 上下结构
  4316. const SsCartItem2 = {
  4317. name: "SsCartItem2",
  4318. props: {
  4319. active: Boolean,
  4320. item: {
  4321. type: Object,
  4322. default: () => ({
  4323. thumb: "images/example/project-img.png",
  4324. title: "广州(国际)科技成果转化天河基地专",
  4325. description: "佳能中国广州分公司",
  4326. all: 50,
  4327. finish: 5,
  4328. }),
  4329. },
  4330. },
  4331. setup(props, { emit }) {
  4332. const item = props.item;
  4333. const itemWidth = Vue.computed(() => {
  4334. const containerWidth =
  4335. document.body.clientWidth || document.body.scrollWidth - 520;
  4336. const halfWidth = containerWidth / 2;
  4337. if (halfWidth < 480) {
  4338. return Math.min(containerWidth, 702) + "px";
  4339. } else {
  4340. return Math.min(halfWidth, 702) + "px";
  4341. }
  4342. });
  4343. const onItemClick = (e) => {
  4344. emit("click", e);
  4345. };
  4346. return {
  4347. item,
  4348. itemWidth,
  4349. onItemClick,
  4350. };
  4351. },
  4352. render() {
  4353. const SsIcon = Vue.resolveComponent("ss-icon");
  4354. return Vue.h(
  4355. "div",
  4356. {
  4357. class: { "item-container2": true, active: this.active },
  4358. onClick: this.onItemClick,
  4359. style: { width: this.itemWidth },
  4360. },
  4361. [
  4362. Vue.h("div", { class: "action-bar" }, [
  4363. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  4364. ]),
  4365. Vue.h("div", { class: "header" }, [
  4366. Vue.h("div", { class: "title" }, `${this.item.title}`),
  4367. ]),
  4368. Vue.h("div", { class: "body" }, [
  4369. Vue.h("div", { class: "left" }, [
  4370. Vue.h("img", {
  4371. src: this.item.thumb,
  4372. alt: "Thumbnail",
  4373. class: "imgUnHandle",
  4374. style: { "object-fit": "cover", width: "100%", height: "100%" },
  4375. }),
  4376. ]),
  4377. Vue.h("div", { class: "right" }, [
  4378. Vue.h("div", { class: "content" }, this.item.description),
  4379. Vue.h("div", { class: "tip" }, [
  4380. Vue.h("div", { class: "progress" }, [
  4381. Vue.h(
  4382. "div",
  4383. {
  4384. style: {
  4385. width: `${(this.item.finish / this.item.all) * 100}%`,
  4386. },
  4387. },
  4388. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  4389. ),
  4390. ]),
  4391. ]),
  4392. ]),
  4393. ]),
  4394. ]
  4395. );
  4396. },
  4397. };
  4398. /**
  4399. * SsListCard - 列表卡片组件
  4400. *
  4401. * @description 用于显示列表项的卡片组件,支持缩略图、标签、状态、操作按钮和选择功能
  4402. *
  4403. * @prop {Object} item - 卡片数据对象
  4404. * @prop {String} item.title - 卡片标题
  4405. * @prop {String} [item.thumb] - 缩略图 URL(可选)
  4406. * @prop {String} [item.thumbType] - 缩略图类型:'thumbnail'(缩略图)或默认(证件照)
  4407. * @prop {String} [item.status] - 卡片状态:'available'(可用-绿色)、'unavailable'(不可用-黄色)、'disabled'(禁用-红色)
  4408. * @prop {Array} item.tags - 标签数组,格式:[{键: 值}, ...]
  4409. * @prop {Function} item.onclick - 点击卡片的回调函数
  4410. * @prop {Array} [item.buttons] - 操作按钮数组(可选),显示在右上角齿轮
  4411. * @prop {Array} [item.statusIcons] - 状态图标数组(可选),显示在右上角,格式:[{class: '图标类名', title: '提示文字'}, ...]
  4412. *
  4413. * @example
  4414. * // 基础用法
  4415. * const item = {
  4416. * title: "卡片标题",
  4417. * tags: [
  4418. * { 类型: '文档' },
  4419. * { 状态: '进行中' }
  4420. * ],
  4421. * onclick: () => console.log('点击了卡片')
  4422. * };
  4423. *
  4424. * @example
  4425. * // 带缩略图和状态
  4426. * const item = {
  4427. * title: "场地预定",
  4428. * thumbType: 'thumbnail',
  4429. * thumb: "https://example.com/image.jpg",
  4430. * status: "available", // 绿色背景
  4431. * tags: [{ 容量: '50人' }],
  4432. * onclick: () => {}
  4433. * };
  4434. *
  4435. * @example
  4436. * // 带操作按钮和状态图标
  4437. * const item = {
  4438. * title: "会议室A",
  4439. * tags: [{ 楼层: '3F' }],
  4440. * onclick: () => {},
  4441. * // 右上角操作按钮(齿轮)
  4442. * buttons: [{
  4443. * class: 'cart-list-setting',
  4444. * title: '编辑',
  4445. * onclick: () => console.log('编辑')
  4446. * }],
  4447. * // 右上角状态图标(在齿轮右边)
  4448. * statusIcons: [{
  4449. * class: 'icon-emoji',
  4450. * title: '清洁中'
  4451. * }]
  4452. * };
  4453. *
  4454. * @features
  4455. * - 卡片选择:鼠标悬停右下角显示选择角标,点击切换选中状态,选中后显示底部深灰色线条
  4456. * - 状态颜色:根据 status 字段显示不同背景色(可用/不可用/禁用)
  4457. * - 图片类型:支持证件照(73×100px)和缩略图(180×100px)两种尺寸
  4458. * - 操作按钮:右上角齿轮,hover 显示,支持多个按钮下拉菜单
  4459. * - 状态图标:右上角显示状态图标,齿轮会根据图标数量自动左移
  4460. *
  4461. * @author xu
  4462. * @date 20260105
  4463. */
  4464. // 组件文档补全(JSDoc) by xu 20260108
  4465. /**
  4466. * SsListCard(左侧对象卡片)
  4467. *
  4468. * 用途:
  4469. * - 渲染左侧卡片(标题 + tags)
  4470. * - 右下角“角标”用于选中/取消选中(不会触发卡片 click)
  4471. *
  4472. * 调用示例:
  4473. * ```html
  4474. * <ss-list-card :item="item" @toggle-select="handleToggleSelect" @click="openDetail"></ss-list-card>
  4475. * ```
  4476. *
  4477. * Props:
  4478. * - `item`:卡片数据对象(建议含 `id/title/tags[]`;内部会读写 `item._ssSelected` 作为选中态)
  4479. *
  4480. * Emits:
  4481. * - `toggle-select`:点击角标触发,参数 `{ item, selected }`
  4482. * - `click`:点击卡片主体触发(用于打开详情等)
  4483. */
  4484. const SsListCard = {
  4485. name: "SsListCard",
  4486. props: {
  4487. ssObjName: { type: String, default: "" }, // 功能:业务对象名(用于默认缩略图 icon) by xu 20260109
  4488. cardClickAction: { type: String, default: "view" }, // 功能:卡片主体点击动作(view=查看;single=单选互斥) by xu 20260109
  4489. item: {
  4490. type: Object,
  4491. required: true,
  4492. },
  4493. },
  4494. emits: ["click", "change", "toggle-select"],
  4495. setup(props, { emit }) {
  4496. const item = props.item;
  4497. // 移除 itemWidth 计算属性,不再需要 by xu 20260105
  4498. // 判断卡片类型 by xu 20260105
  4499. const cardType = Vue.computed(() => {
  4500. // 支持“无图但保留缩略图占位”(同一业务列表图片形态一致) by xu 20260109
  4501. if (!item.thumb && !item.thumbType) return ""; // 业务列表“无图”形态
  4502. // 根据 thumbType 字段判断,如果没有则默认为证件照
  4503. return item.thumbType === "thumbnail" ? "card-thumbnail" : "card-photo";
  4504. });
  4505. // 判断状态类型 - 场地预定状态 by xu 20260105
  4506. const statusClass = Vue.computed(() => {
  4507. if (!item.status) return ""; // 无状态,默认白色
  4508. // 映射状态值到 CSS 类名
  4509. const statusMap = {
  4510. available: "status-available",
  4511. unavailable: "status-unavailable",
  4512. disabled: "status-disabled",
  4513. };
  4514. return statusMap[item.status] || "";
  4515. });
  4516. const onItemClick = (e) => {
  4517. // 清除所有类型卡片的 active 状态(卡片主体点击仅做 active 高亮) by xu 20260109
  4518. const allListCards = document.querySelectorAll(
  4519. ".knowledge-item-container"
  4520. );
  4521. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  4522. allListCards.forEach((card) => card.classList.remove("active"));
  4523. allFolderCards.forEach((card) => card.classList.remove("active"));
  4524. // 设置当前项的 active 状态
  4525. e.currentTarget.classList.add("active");
  4526. // 卡片主体点击动作由页面级配置控制 by xu 20260109
  4527. if (props.cardClickAction === "view") {
  4528. props.item.onclick?.();
  4529. // 通知父级:卡片点击(查看) by xu 20260109
  4530. emit("click", props.item);
  4531. }
  4532. };
  4533. const onItemChange = (e, icon, index) => {
  4534. e.stopPropagation(); // 阻止事件冒泡到卡片
  4535. props.item.buttons[0].onclick();
  4536. // emit("change", { item: props.item, icon, index });
  4537. };
  4538. return {
  4539. item,
  4540. cardType,
  4541. statusClass,
  4542. onItemClick,
  4543. onItemChange,
  4544. };
  4545. },
  4546. data() {
  4547. return {
  4548. showButtons: false,
  4549. selected: false, // 选择状态 by xu 20260105
  4550. showTextPopover: false, // 功能:右侧文字区 hover 展示全量 by xu 20260108
  4551. textPopoverType: "", // second-summary / second-tags / third / third-full by xu 20260108
  4552. textPopoverBottom: 0, // 功能:popover 从当前省略行位置向上展开 by xu 20260108
  4553. hideTextPopoverTimer: null, // 功能:鼠标从省略行移到浮层的缓冲 by xu 20260108
  4554. textPopoverPayload: null, // { kind, text?, lines? } by xu 20260108
  4555. ellipsisVisible: {
  4556. // 功能:只在真实出现 ... 时才显示命中区/允许 goheight by xu 20260109
  4557. secondSummary: false,
  4558. secondTags: false,
  4559. third: false,
  4560. thirdFull: false,
  4561. },
  4562. };
  4563. },
  4564. methods: {
  4565. __allowSelect() {
  4566. // 功能说明:无 rbarObj 时禁用选中能力(隐藏右下角勾选并禁止 toggle) by xu 20260122
  4567. try {
  4568. if (this?.$root && this.$root.hasObjPanel === false) return false;
  4569. if (
  4570. typeof window !== "undefined" &&
  4571. window.__objListVm &&
  4572. window.__objListVm.hasObjPanel === false
  4573. )
  4574. return false;
  4575. } catch (_) {}
  4576. return true;
  4577. },
  4578. // 切换选择状态(对外 emit,支持方案A父级 state 中转) by xu 20260106
  4579. toggleSelect(e) {
  4580. e.stopPropagation();
  4581. if (!this.__allowSelect()) return; // 功能说明:无 rbarObj 时禁止选中 by xu 20260122
  4582. // 使用 item 上的状态,便于父级/右侧边栏反向同步 by xu 20260106
  4583. this.item._ssSelected = !this.item?._ssSelected;
  4584. this.$emit("toggle-select", {
  4585. item: this.item,
  4586. selected: !!this.item?._ssSelected,
  4587. });
  4588. },
  4589. // 卡片主体点击=单选互斥:只有“本次切到选中”才清理其他选中 by xu 20260109
  4590. toggleSelectExclusive(e) {
  4591. e?.stopPropagation?.();
  4592. if (!this.__allowSelect()) return; // 功能说明:无 rbarObj 时禁止选中 by xu 20260122
  4593. this.item._ssSelected = !this.item?._ssSelected;
  4594. const selected = !!this.item?._ssSelected;
  4595. this.$emit("toggle-select", {
  4596. item: this.item,
  4597. selected,
  4598. exclusive: true,
  4599. });
  4600. },
  4601. // 功能:无缩略图时,用业务对象 icon 做默认图(ss-icon + icon-obj-xx) by xu 20260109
  4602. getBizThumbIconClass() {
  4603. const name = String(
  4604. this.ssObjName ||
  4605. this.item?.ssObjName ||
  4606. this.$root?.ssObjName ||
  4607. window?.ss?.dom?.ssObjName ||
  4608. ""
  4609. ).trim();
  4610. if (!name) return "";
  4611. return `icon-obj-${name}`;
  4612. },
  4613. // 功能:构造右侧文字区 4 行(摘要/类目或标签/对象号) by xu 20260108
  4614. buildRightTextLines() {
  4615. const item = this.item || {};
  4616. const summary = String(item?.desc ?? "").trim(); // 后端字段后续映射 by xu 20260108
  4617. const objNum = String(item?.objNum ?? "").trim(); // 后端字段后续映射 by xu 20260108
  4618. const categoryArr = Array.isArray(item?.category) ? item.category : [];
  4619. const tagsArr = Array.isArray(item?.tags) ? item.tags : [];
  4620. const hasTags = tagsArr.length > 0;
  4621. const hasCategory = categoryArr.length > 0;
  4622. // 第二部分(L1-L3):摘要优先,其次物品参数 by xu 20260108
  4623. const secondKind = summary ? "summary" : hasTags ? "tags" : "";
  4624. const hasSecond = !!secondKind;
  4625. // 第三部分(L4):对象号优先,其次类目 by xu 20260108
  4626. const thirdKind = objNum ? "objNum" : hasCategory ? "category" : "";
  4627. const hasThird = !!thirdKind;
  4628. const thirdFull = !hasSecond && hasThird; // 第二部分为空则第三部分占满 4 行 by xu 20260108
  4629. const secondFull = hasSecond && !hasThird && secondKind === "tags"; // 仅标签时占满 4 行(不留空行) by xu 20260109
  4630. const toValueText = (obj) => {
  4631. // 功能说明:类目/物品参数回显展示 key: value(否则只显示值看不懂) by xu 20260114
  4632. const [k, v] = Object.entries(obj || {})[0] || ["", ""];
  4633. const key = k !== undefined && k !== null ? String(k).trim() : "";
  4634. const val = v !== undefined && v !== null ? String(v).trim() : "";
  4635. if (key && val) return `${key}:${val}`;
  4636. if (val) return val;
  4637. if (key) return key;
  4638. return "";
  4639. };
  4640. const toLineList = (arr) =>
  4641. (arr || [])
  4642. .map(toValueText)
  4643. .map((s) => String(s ?? "").trim())
  4644. .filter(Boolean);
  4645. const flat = (arr) => toLineList(arr).join(" ");
  4646. // 第二部分 tags:默认 3 行;仅标签时占满 4 行(避免底部空一行) by xu 20260109
  4647. const secondTagsMaxLines = secondFull ? 4 : 3;
  4648. const secondTagsLinesFull = toLineList(tagsArr);
  4649. const secondTagsHead = secondTagsLinesFull.slice(
  4650. 0,
  4651. Math.max(0, secondTagsMaxLines - 1)
  4652. );
  4653. const secondTagsTail = secondTagsLinesFull.slice(
  4654. Math.max(0, secondTagsMaxLines - 1)
  4655. );
  4656. const secondTagsLast =
  4657. secondTagsTail.length <= 1
  4658. ? secondTagsTail[0] || ""
  4659. : secondTagsTail.join(" "); // 功能:最后一行平铺剩余 by xu 20260108
  4660. // 第三部分类目:卡片上串成一行;goheight 展开时一条一行 by xu 20260109
  4661. const categoryLinesFull = toLineList(categoryArr);
  4662. const categoryLine = categoryLinesFull.join(" ");
  4663. const thirdText =
  4664. thirdKind === "objNum"
  4665. ? objNum
  4666. : thirdKind === "category"
  4667. ? categoryLine
  4668. : "";
  4669. return {
  4670. secondKind,
  4671. thirdKind,
  4672. hasSecond,
  4673. hasThird,
  4674. thirdFull,
  4675. secondFull,
  4676. summary,
  4677. secondTagsMaxLines,
  4678. secondTagsHead,
  4679. secondTagsLast,
  4680. secondTagsLinesFull,
  4681. objNum,
  4682. categoryLine,
  4683. categoryLinesFull,
  4684. thirdText,
  4685. };
  4686. },
  4687. measureTextOverflowByLines(text, maxLines, width) {
  4688. const w = Number(width) || 0;
  4689. if (!w || !text) return false;
  4690. const probe = document.createElement("div");
  4691. probe.style.position = "fixed";
  4692. probe.style.left = "-99999px";
  4693. probe.style.top = "0";
  4694. probe.style.width = w + "px";
  4695. probe.style.fontSize = "18px";
  4696. probe.style.lineHeight = "24px";
  4697. probe.style.whiteSpace = "normal";
  4698. probe.style.wordBreak = "break-word";
  4699. probe.style.visibility = "hidden";
  4700. probe.textContent = text;
  4701. document.body.appendChild(probe);
  4702. const h = probe.getBoundingClientRect().height || 0;
  4703. document.body.removeChild(probe);
  4704. return h > maxLines * 24 + 1;
  4705. },
  4706. measureSingleLineOverflow(text, width) {
  4707. const w = Number(width) || 0;
  4708. if (!w || !text) return false;
  4709. const probe = document.createElement("span");
  4710. probe.style.position = "fixed";
  4711. probe.style.left = "-99999px";
  4712. probe.style.top = "0";
  4713. probe.style.display = "inline-block";
  4714. probe.style.maxWidth = w + "px";
  4715. probe.style.fontSize = "18px";
  4716. probe.style.lineHeight = "24px";
  4717. probe.style.whiteSpace = "nowrap";
  4718. probe.style.visibility = "hidden";
  4719. probe.textContent = text;
  4720. document.body.appendChild(probe);
  4721. const overflow =
  4722. (probe.scrollWidth || 0) > (probe.clientWidth || w) + 1;
  4723. document.body.removeChild(probe);
  4724. return overflow;
  4725. },
  4726. // 功能:根据当前卡片宽度刷新「是否出现 ...」状态(用于控制命中区显示) by xu 20260109
  4727. refreshEllipsisVisible() {
  4728. try {
  4729. const right = this.$el?.querySelector?.(".right");
  4730. const rawWidth =
  4731. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  4732. const width = Math.max(0, Math.round(rawWidth)); // 修复:内容区不再使用 padding-right 预留,测量按真实宽度 by xu 20260109
  4733. const model = this.buildRightTextLines();
  4734. const next = {
  4735. secondSummary: false,
  4736. secondTags: false,
  4737. third: false,
  4738. thirdFull: false,
  4739. };
  4740. if (model.secondKind === "summary" && model.summary) {
  4741. next.secondSummary = this.measureTextOverflowByLines(
  4742. model.summary,
  4743. 3,
  4744. width
  4745. );
  4746. }
  4747. if (model.secondKind === "tags") {
  4748. // 功能说明:tags 采用「最后一行平铺剩余」策略,是否出现 ... 仅取决于最后一行是否溢出(数量多但平铺放得下不算溢出) by xu 20260114
  4749. next.secondTags = this.measureSingleLineOverflow(
  4750. model.secondTagsLast,
  4751. width
  4752. );
  4753. }
  4754. if (model.hasThird && !model.thirdFull) {
  4755. next.third = this.measureSingleLineOverflow(model.thirdText, width);
  4756. }
  4757. if (model.hasThird && model.thirdFull) {
  4758. next.thirdFull = this.measureTextOverflowByLines(
  4759. model.thirdText,
  4760. 4,
  4761. width
  4762. );
  4763. }
  4764. const prev = this.ellipsisVisible || {};
  4765. const changed =
  4766. prev.secondSummary !== next.secondSummary ||
  4767. prev.secondTags !== next.secondTags ||
  4768. prev.third !== next.third ||
  4769. prev.thirdFull !== next.thirdFull;
  4770. if (changed) this.ellipsisVisible = next;
  4771. } catch (e) {
  4772. // ignore by xu 20260109
  4773. }
  4774. },
  4775. showTextPopoverFor(el, kind) {
  4776. // 调试开关:window.__SS_LISTCARD_DEBUG__ = true 时打印 hover/溢出判断日志 by xu 20260108
  4777. const debug =
  4778. typeof window !== "undefined" && !!window.__SS_LISTCARD_DEBUG__;
  4779. if (debug) {
  4780. console.log("[SsListCard] ellipsis hover", {
  4781. kind,
  4782. el: el?.className,
  4783. });
  4784. }
  4785. const model = this.buildRightTextLines();
  4786. const lineEl = el?.closest?.(".ss-card-text__line") || el;
  4787. const right = lineEl?.closest?.(".right") || el?.closest?.(".right");
  4788. const rawWidth =
  4789. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  4790. const width = Math.max(0, Math.round(rawWidth)); // 修复:内容区不再预留 padding-right,测量按真实宽度 by xu 20260109
  4791. const textEl =
  4792. kind === "second-summary"
  4793. ? lineEl?.querySelector?.(".ss-card-text__secondSummary")
  4794. : kind === "second-tags"
  4795. ? lineEl?.querySelector?.(".ss-card-text__tagLineLast")
  4796. : kind === "third"
  4797. ? lineEl?.querySelector?.(".ss-card-text__thirdLine")
  4798. : lineEl?.querySelector?.(".ss-card-text__thirdFull");
  4799. let payload = null;
  4800. // 仅当真实会出现 ... 时才允许 goheight(避免“没超出也能出 goheight”) by xu 20260109
  4801. const overflowed =
  4802. kind === "second-summary"
  4803. ? this.measureTextOverflowByLines(model.summary, 3, width)
  4804. : kind === "second-tags"
  4805. ? this.measureSingleLineOverflow(model.secondTagsLast, width) // 功能说明:同 refreshEllipsisVisible,tags 仅看最后一行是否溢出 by xu 20260114
  4806. : kind === "third"
  4807. ? this.measureSingleLineOverflow(model.thirdText, width)
  4808. : this.measureTextOverflowByLines(model.thirdText, 4, width);
  4809. if (!overflowed) return;
  4810. if (kind === "second-summary") {
  4811. if (model.summary) payload = { kind, text: model.summary };
  4812. } else if (kind === "second-tags") {
  4813. if (
  4814. Array.isArray(model.secondTagsLinesFull) &&
  4815. model.secondTagsLinesFull.length
  4816. ) {
  4817. payload = { kind, lines: model.secondTagsLinesFull };
  4818. }
  4819. } else if (kind === "third") {
  4820. if (
  4821. model.thirdKind === "category" &&
  4822. Array.isArray(model.categoryLinesFull) &&
  4823. model.categoryLinesFull.length
  4824. ) {
  4825. payload = { kind, lines: model.categoryLinesFull }; // 功能:类目展开一条一行 by xu 20260109
  4826. } else if (model.thirdText) {
  4827. payload = { kind, text: model.thirdText };
  4828. }
  4829. } else if (kind === "third-full") {
  4830. if (
  4831. model.thirdKind === "category" &&
  4832. Array.isArray(model.categoryLinesFull) &&
  4833. model.categoryLinesFull.length
  4834. ) {
  4835. payload = { kind, lines: model.categoryLinesFull }; // 功能:类目占满模式展开一条一行 by xu 20260109
  4836. } else if (model.thirdText) {
  4837. payload = { kind, text: model.thirdText };
  4838. }
  4839. }
  4840. if (debug) {
  4841. console.log("[SsListCard] ellipsis decide", {
  4842. kind,
  4843. rawWidth: Math.round(rawWidth),
  4844. width,
  4845. hasPayload: !!payload,
  4846. textEl: textEl?.className,
  4847. textClient: textEl
  4848. ? {
  4849. cw: textEl.clientWidth,
  4850. ch: textEl.clientHeight,
  4851. sw: textEl.scrollWidth,
  4852. sh: textEl.scrollHeight,
  4853. }
  4854. : null,
  4855. });
  4856. }
  4857. if (!payload) return;
  4858. this.clearHideTextPopoverTimer();
  4859. const container = lineEl?.closest?.(".right");
  4860. const containerRect = container?.getBoundingClientRect?.();
  4861. const lineRect = lineEl?.getBoundingClientRect?.();
  4862. if (containerRect && lineRect) {
  4863. const bottom = Math.max(
  4864. 0,
  4865. Math.round(containerRect.bottom - lineRect.bottom)
  4866. );
  4867. this.textPopoverBottom = bottom;
  4868. } else {
  4869. this.textPopoverBottom = 0;
  4870. }
  4871. this.textPopoverPayload = payload;
  4872. this.textPopoverType = kind;
  4873. this.showTextPopover = true;
  4874. if (debug) console.log("[SsListCard] goheight show", payload);
  4875. },
  4876. isOverflowing(el) {
  4877. if (!el) return false;
  4878. // 单行/多行省略统一判断:scroll 尺寸大于 client 尺寸即认为有 ... by xu 20260108
  4879. return (
  4880. (el.scrollWidth &&
  4881. el.clientWidth &&
  4882. el.scrollWidth > el.clientWidth + 1) ||
  4883. (el.scrollHeight &&
  4884. el.clientHeight &&
  4885. el.scrollHeight > el.clientHeight + 1)
  4886. );
  4887. },
  4888. isSummaryOverflowing(el) {
  4889. if (!el) return false;
  4890. // -webkit-line-clamp 场景下 scrollHeight 不稳定,改用“无 clamp 的离屏测量”判断是否超过 2 行 by xu 20260108
  4891. const text = String(this.item?.desc ?? "").trim();
  4892. if (!text) return false;
  4893. const rect = el.getBoundingClientRect?.();
  4894. const width = rect?.width || el.clientWidth || 0;
  4895. if (!width) return false;
  4896. const probe = document.createElement("div");
  4897. probe.style.position = "fixed";
  4898. probe.style.left = "-99999px";
  4899. probe.style.top = "0";
  4900. probe.style.width = width + "px";
  4901. probe.style.fontSize = "18px";
  4902. probe.style.lineHeight = "24px";
  4903. probe.style.whiteSpace = "normal";
  4904. probe.style.wordBreak = "break-word";
  4905. probe.style.visibility = "hidden";
  4906. probe.textContent = text;
  4907. document.body.appendChild(probe);
  4908. const h = probe.getBoundingClientRect().height || 0;
  4909. document.body.removeChild(probe);
  4910. return h > 48 + 1;
  4911. },
  4912. clearHideTextPopoverTimer() {
  4913. if (this.hideTextPopoverTimer) {
  4914. clearTimeout(this.hideTextPopoverTimer);
  4915. this.hideTextPopoverTimer = null;
  4916. }
  4917. },
  4918. // 修复 goheight hover 无响应:移除重复方法覆盖,统一使用上面的 showTextPopoverFor(el, kind) by xu 20260109
  4919. hideTextPopoverLater() {
  4920. this.clearHideTextPopoverTimer();
  4921. this.hideTextPopoverTimer = setTimeout(() => {
  4922. this.showTextPopover = false;
  4923. this.textPopoverType = "";
  4924. this.textPopoverPayload = null;
  4925. }, 120);
  4926. },
  4927. hideTextPopover() {
  4928. this.clearHideTextPopoverTimer();
  4929. this.showTextPopover = false;
  4930. this.textPopoverType = "";
  4931. this.textPopoverPayload = null;
  4932. },
  4933. // 功能:新需求下不在 updated 内做测量,避免死循环 by xu 20260108
  4934. },
  4935. mounted() {
  4936. // 无需在 mounted/updated 里做 overflow 测量(避免死循环),只在 hover 触发时判断 by xu 20260108
  4937. // 仅用于控制“...命中区是否显示”,不会触发循环更新 by xu 20260109
  4938. this.$nextTick?.(() => {
  4939. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  4940. });
  4941. this.__ssListCardResizeHandler = () => this.refreshEllipsisVisible?.(); // 功能:窗口变化时刷新 ... 显示 by xu 20260109
  4942. window.addEventListener?.("resize", this.__ssListCardResizeHandler);
  4943. },
  4944. updated() {
  4945. // 卡片数据更新后刷新一次 ... 显示状态(避免“宽度/内容变了但命中区不变”) by xu 20260109
  4946. this.$nextTick?.(() => {
  4947. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  4948. });
  4949. },
  4950. beforeUnmount() {
  4951. // 清理 timer,避免残留导致异常 by xu 20260108
  4952. this.clearHideTextPopoverTimer?.();
  4953. if (this.__ssListCardResizeHandler) {
  4954. window.removeEventListener?.("resize", this.__ssListCardResizeHandler);
  4955. this.__ssListCardResizeHandler = null;
  4956. }
  4957. },
  4958. render() {
  4959. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  4960. const SsIcon = Vue.resolveComponent("ss-icon");
  4961. const hasThumbArea = !!(this.item?.thumb || this.item?.thumbType); // 功能:无图但有 thumbType 时仍保留占位 by xu 20260109
  4962. const thumbSrc = (() => {
  4963. // 功能说明:兼容 thumb 为 raw path 或 {val}/{value},组件内统一转为 dlByHttp URL by xu 20260122
  4964. const t = this.item?.thumb;
  4965. if (!t) return "";
  4966. if (typeof t === "string") {
  4967. const s = t.trim();
  4968. if (!s) return "";
  4969. // 已经是 URL/绝对路径则直接使用;否则按 path 构建 dlByHttp by xu 20260122
  4970. if (
  4971. /^https?:\/\//i.test(s) ||
  4972. s.startsWith("/service?") ||
  4973. s.startsWith("/")
  4974. )
  4975. return s;
  4976. return buildThumbUrl(s);
  4977. }
  4978. return buildThumbUrl(t);
  4979. })();
  4980. return Vue.h(
  4981. "div",
  4982. {
  4983. class: {
  4984. "knowledge-item-container": true,
  4985. active: this.item.active,
  4986. [this.cardType]: !!this.cardType, // 动态添加卡片类型类名 by xu 20260105
  4987. [this.statusClass]: !!this.statusClass,
  4988. },
  4989. onClick: (e) => {
  4990. this.onItemClick?.(e);
  4991. if (this.__allowSelect() && this.cardClickAction === "single") {
  4992. // 功能说明:无 rbarObj 时不允许单选互斥 by xu 20260122
  4993. this.toggleSelectExclusive?.(e);
  4994. }
  4995. }, // 功能:卡片主体点击动作(view/single) by xu 20260109
  4996. // 移除固定宽度,由 CSS min-width 控制 by xu 20260105
  4997. },
  4998. [
  4999. // 右上角状态图标区域 by xu 20260105
  5000. this.item?.statusIcons?.length > 0 &&
  5001. Vue.h(
  5002. "div",
  5003. { class: "card-status-icons" },
  5004. this.item.statusIcons.map((icon) =>
  5005. Vue.h(SsIcon, {
  5006. class: `status-icon ${icon.class}`,
  5007. title: icon.title,
  5008. })
  5009. )
  5010. ),
  5011. this.item?.buttons?.length > 0 &&
  5012. Vue.h(
  5013. "div",
  5014. {
  5015. class: "header",
  5016. style:
  5017. this.item?.statusIcons?.length > 0
  5018. ? {
  5019. right: `${this.item.statusIcons.length * 48}px`,
  5020. borderTopRightRadius: "0",
  5021. }
  5022. : {},
  5023. onMouseenter: () => (this.showButtons = true),
  5024. onMouseleave: () => (this.showButtons = false),
  5025. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  5026. },
  5027. [
  5028. // 只在有按钮时渲染设置图标
  5029. // this.item?.buttons?.length > 0 &&
  5030. Vue.h("div", {
  5031. class: "cart-list-setting cart-list-icon",
  5032. title: this.item?.buttons?.[0]?.title,
  5033. }),
  5034. // 鼠标移入时显示按钮列表,与图标同级
  5035. // this.item?.buttons?.length > 0 &&
  5036. this.showButtons &&
  5037. this.item?.buttons?.length > 1 &&
  5038. Vue.h(
  5039. "div",
  5040. {
  5041. class: "cart-list-button-popup",
  5042. },
  5043. this.item.buttons.map((btn) =>
  5044. Vue.h(
  5045. "div",
  5046. {
  5047. onClick: (e) => {
  5048. e.stopPropagation();
  5049. btn.onclick?.();
  5050. },
  5051. },
  5052. [
  5053. // 如果有 class,显示对应的图标
  5054. btn.class &&
  5055. Vue.h(SsCartListIcon, {
  5056. class: [btn.class],
  5057. }),
  5058. // 显示按钮文本
  5059. Vue.h("span", null, btn.title),
  5060. ]
  5061. )
  5062. )
  5063. ),
  5064. ]
  5065. ),
  5066. Vue.h("div", { class: "body" }, [
  5067. Vue.h("div", { class: "box-header" }, [
  5068. Vue.h("div", `${this.item.title}`),
  5069. ]),
  5070. Vue.h(
  5071. "div",
  5072. {
  5073. class: !hasThumbArea ? "no-thumb box-body" : "box-body",
  5074. },
  5075. [
  5076. hasThumbArea
  5077. ? thumbSrc
  5078. ? Vue.h("div", { class: "left" }, [
  5079. Vue.h("img", {
  5080. src: thumbSrc,
  5081. alt: "Thumbnail",
  5082. class: "imgUnHandle",
  5083. style: {
  5084. "object-fit": "cover",
  5085. width: "100%",
  5086. height: "100%",
  5087. },
  5088. }),
  5089. ])
  5090. : Vue.h(
  5091. // 功能:无图占位(ss-icon + biz icon,居中) by xu 20260109
  5092. "div",
  5093. { class: "left ss-objlist-thumbPlaceholder" },
  5094. [
  5095. Vue.h(SsIcon, {
  5096. class: `${this.getBizThumbIconClass()} ss-objlist-thumbIcon`,
  5097. }),
  5098. ]
  5099. )
  5100. : null,
  5101. Vue.h(
  5102. "div",
  5103. {
  5104. class: "right",
  5105. },
  5106. (() => {
  5107. const model = this.buildRightTextLines(); // 功能:右侧文字区新规则(第二部分/第三部分优先级) by xu 20260108
  5108. const hasAny = !!(model?.hasSecond || model?.hasThird);
  5109. if (!hasAny) return [];
  5110. const children = [];
  5111. // 第二部分:L1-L3(摘要优先,其次 tags;不足留空;超出 L3 ...) by xu 20260108
  5112. if (model.hasSecond) {
  5113. if (model.secondKind === "summary") {
  5114. children.push(
  5115. Vue.h(
  5116. "div",
  5117. {
  5118. class:
  5119. "ss-card-text__line ss-card-text__secondBlock",
  5120. },
  5121. [
  5122. Vue.h(
  5123. "div",
  5124. {
  5125. class: "ss-card-text__secondSummary",
  5126. title: model.summary,
  5127. },
  5128. model.summary
  5129. ),
  5130. Vue.h("span", {
  5131. class: [
  5132. "ss-card-text__ellipsisHit",
  5133. "ss-card-text__ellipsisHit--second",
  5134. this.ellipsisVisible?.secondSummary
  5135. ? "is-on"
  5136. : "",
  5137. ],
  5138. title: "查看完整摘要",
  5139. onMouseenter: (e) =>
  5140. this.showTextPopoverFor(
  5141. e?.currentTarget,
  5142. "second-summary"
  5143. ),
  5144. onClick: (e) => {
  5145. e?.stopPropagation?.();
  5146. this.showTextPopoverFor(
  5147. e?.currentTarget,
  5148. "second-summary"
  5149. );
  5150. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5151. onMouseleave: () => this.hideTextPopoverLater(),
  5152. }),
  5153. ]
  5154. )
  5155. );
  5156. } else if (model.secondKind === "tags") {
  5157. children.push(
  5158. Vue.h(
  5159. "div",
  5160. {
  5161. class: [
  5162. "ss-card-text__line",
  5163. model.secondFull
  5164. ? "ss-card-text__secondFullBlock"
  5165. : "ss-card-text__secondBlock",
  5166. ],
  5167. },
  5168. [
  5169. // 功能:仅标签时占满 4 行 by xu 20260109
  5170. Vue.h(
  5171. "div",
  5172. { class: "ss-card-text__secondTags" },
  5173. [
  5174. ...model.secondTagsHead.map((t) =>
  5175. Vue.h(
  5176. "div",
  5177. {
  5178. class: "ss-card-text__tagLine",
  5179. title: t,
  5180. },
  5181. t
  5182. )
  5183. ),
  5184. // 第三行:平铺剩余(可能为空) by xu 20260108
  5185. Vue.h(
  5186. "div",
  5187. {
  5188. class:
  5189. "ss-card-text__tagLine is-last ss-card-text__tagLineLast",
  5190. title: model.secondTagsLast,
  5191. },
  5192. model.secondTagsLast
  5193. ),
  5194. ].filter(Boolean)
  5195. ),
  5196. // 只在最后一行出现 ... 时才触发 goheight by xu 20260108
  5197. Vue.h("span", {
  5198. class: [
  5199. "ss-card-text__ellipsisHit",
  5200. "ss-card-text__ellipsisHit--second",
  5201. this.ellipsisVisible?.secondTags
  5202. ? "is-on"
  5203. : "",
  5204. ],
  5205. title: "查看完整物品参数",
  5206. onMouseenter: (e) =>
  5207. this.showTextPopoverFor(
  5208. e?.currentTarget,
  5209. "second-tags"
  5210. ),
  5211. onClick: (e) => {
  5212. e?.stopPropagation?.();
  5213. this.showTextPopoverFor(
  5214. e?.currentTarget,
  5215. "second-tags"
  5216. );
  5217. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5218. onMouseleave: () => this.hideTextPopoverLater(),
  5219. }),
  5220. ]
  5221. )
  5222. );
  5223. }
  5224. }
  5225. // 第三部分:默认 L4;第二部分为空则占满 L1-L4 by xu 20260108
  5226. if (model.hasThird) {
  5227. if (model.thirdFull) {
  5228. children.push(
  5229. Vue.h(
  5230. "div",
  5231. {
  5232. class:
  5233. "ss-card-text__line ss-card-text__thirdFullBlock",
  5234. },
  5235. [
  5236. Vue.h(
  5237. "div",
  5238. {
  5239. class: "ss-card-text__thirdFull",
  5240. title: model.thirdText,
  5241. },
  5242. model.thirdText
  5243. ),
  5244. Vue.h("span", {
  5245. class: [
  5246. "ss-card-text__ellipsisHit",
  5247. "ss-card-text__ellipsisHit--third",
  5248. this.ellipsisVisible?.thirdFull
  5249. ? "is-on"
  5250. : "",
  5251. ],
  5252. title: "查看完整信息",
  5253. onMouseenter: (e) =>
  5254. this.showTextPopoverFor(
  5255. e?.currentTarget,
  5256. "third-full"
  5257. ),
  5258. onClick: (e) => {
  5259. e?.stopPropagation?.();
  5260. this.showTextPopoverFor(
  5261. e?.currentTarget,
  5262. "third-full"
  5263. );
  5264. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5265. onMouseleave: () => this.hideTextPopoverLater(),
  5266. }),
  5267. ]
  5268. )
  5269. );
  5270. } else {
  5271. children.push(
  5272. Vue.h(
  5273. "div",
  5274. {
  5275. class:
  5276. "ss-card-text__line ss-card-text__thirdLineWrap",
  5277. },
  5278. [
  5279. Vue.h(
  5280. "div",
  5281. {
  5282. class: "ss-card-text__thirdLine",
  5283. title: model.thirdText,
  5284. },
  5285. model.thirdText
  5286. ),
  5287. Vue.h("span", {
  5288. class: [
  5289. "ss-card-text__ellipsisHit",
  5290. "ss-card-text__ellipsisHit--third",
  5291. this.ellipsisVisible?.third ? "is-on" : "",
  5292. ],
  5293. title: "查看完整信息",
  5294. onMouseenter: (e) =>
  5295. this.showTextPopoverFor(
  5296. e?.currentTarget,
  5297. "third"
  5298. ),
  5299. onClick: (e) => {
  5300. e?.stopPropagation?.();
  5301. this.showTextPopoverFor(
  5302. e?.currentTarget,
  5303. "third"
  5304. );
  5305. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5306. onMouseleave: () => this.hideTextPopoverLater(),
  5307. }),
  5308. ]
  5309. )
  5310. );
  5311. }
  5312. }
  5313. // hover 展开浮层:宽度=右侧文字区,底对齐向上展开,带阴影 by xu 20260108
  5314. // popover 作为 `.right` 的 sibling 渲染,避免被 `.ss-card-text{overflow:hidden}` 裁剪 by xu 20260108
  5315. const popover =
  5316. this.showTextPopover &&
  5317. Vue.h(
  5318. "div",
  5319. {
  5320. class: "ss-card-text-popover",
  5321. style: { bottom: this.textPopoverBottom + "px" },
  5322. onMouseenter: () => {
  5323. this.clearHideTextPopoverTimer();
  5324. this.showTextPopover = true;
  5325. },
  5326. onMouseleave: () => this.hideTextPopoverLater(),
  5327. },
  5328. (() => {
  5329. const p = this.textPopoverPayload || {};
  5330. if (p.kind === "second-summary" && p.text) {
  5331. return [
  5332. Vue.h(
  5333. "div",
  5334. { class: "ss-card-text-popover__summary" },
  5335. p.text
  5336. ),
  5337. ];
  5338. }
  5339. if (Array.isArray(p.lines)) {
  5340. return [
  5341. Vue.h(
  5342. "div",
  5343. { class: "ss-card-text-popover__kvlist" },
  5344. p.lines.map((t) =>
  5345. Vue.h(
  5346. "div",
  5347. { class: "ss-card-text-popover__kv" },
  5348. t
  5349. )
  5350. )
  5351. ),
  5352. ];
  5353. }
  5354. if (
  5355. (p.kind === "third" || p.kind === "third-full") &&
  5356. p.text
  5357. ) {
  5358. return [
  5359. Vue.h(
  5360. "div",
  5361. { class: "ss-card-text-popover__objno" },
  5362. p.text
  5363. ),
  5364. ];
  5365. }
  5366. return [];
  5367. })()
  5368. );
  5369. return [
  5370. Vue.h("div", { class: "ss-card-text" }, children),
  5371. popover,
  5372. ];
  5373. })()
  5374. ),
  5375. ]
  5376. ),
  5377. ]),
  5378. // 右下角卡片选择图标 by xu 20260105
  5379. this.__allowSelect()
  5380. ? Vue.h(SsIcon, {
  5381. class: this.item?._ssSelected
  5382. ? "card-icon icon-cardChk-on"
  5383. : "card-icon icon-cardChk",
  5384. onClick: this.toggleSelect,
  5385. })
  5386. : null,
  5387. // 选中后底部线条 by xu 20260105
  5388. this.__allowSelect() &&
  5389. this.item?._ssSelected &&
  5390. Vue.h("div", { class: "select-bottom-line" }),
  5391. ]
  5392. );
  5393. },
  5394. };
  5395. // 二级对象卡片:复用一级对象新卡片布局/省略浮层,但去掉勾选与 single 选中,仅支持点击查看 by xu 20260115
  5396. const SsCObjCardList = {
  5397. name: "SsCObjCardList",
  5398. props: {
  5399. ssObjName: { type: String, default: "" }, // 功能说明:业务对象名(用于默认缩略图 icon) by xu 20260115
  5400. item: {
  5401. type: Object,
  5402. required: true,
  5403. },
  5404. },
  5405. emits: ["click", "change"],
  5406. setup(props, { emit }) {
  5407. const item = props.item;
  5408. const cardType = Vue.computed(() => {
  5409. if (!item.thumb && !item.thumbType) return "";
  5410. return item.thumbType === "thumbnail" ? "card-thumbnail" : "card-photo";
  5411. });
  5412. const statusClass = Vue.computed(() => {
  5413. if (!item.status) return "";
  5414. const statusMap = {
  5415. available: "status-available",
  5416. unavailable: "status-unavailable",
  5417. disabled: "status-disabled",
  5418. };
  5419. return statusMap[item.status] || "";
  5420. });
  5421. const onItemClick = (e) => {
  5422. // 清除所有类型卡片的 active 状态(保持与一级对象一致) by xu 20260115
  5423. const allListCards = document.querySelectorAll(
  5424. ".knowledge-item-container"
  5425. );
  5426. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  5427. allListCards.forEach((card) => card.classList.remove("active"));
  5428. allFolderCards.forEach((card) => card.classList.remove("active"));
  5429. e.currentTarget.classList.add("active");
  5430. // 二级对象卡片:点击仅查看(调用 item.onclick) by xu 20260115
  5431. props.item.onclick?.();
  5432. emit("click", props.item);
  5433. };
  5434. const onItemChange = (e) => {
  5435. e.stopPropagation();
  5436. props.item.buttons?.[0]?.onclick?.();
  5437. };
  5438. return { item, cardType, statusClass, onItemClick, onItemChange };
  5439. },
  5440. data() {
  5441. return {
  5442. showButtons: false,
  5443. showTextPopover: false, // 功能:右侧文字区 hover 展示全量 by xu 20260115
  5444. textPopoverType: "", // second-summary / second-tags / third / third-full by xu 20260115
  5445. textPopoverBottom: 0, // 功能:popover 从当前省略行位置向上展开 by xu 20260115
  5446. hideTextPopoverTimer: null, // 功能:鼠标从省略行移到浮层的缓冲 by xu 20260115
  5447. textPopoverPayload: null, // { kind, text?, lines? } by xu 20260115
  5448. ellipsisVisible: {
  5449. secondSummary: false,
  5450. secondTags: false,
  5451. third: false,
  5452. thirdFull: false,
  5453. }, // 功能:只在真实出现 ... 时才显示命中区/允许 goheight by xu 20260115
  5454. };
  5455. },
  5456. methods: {
  5457. getBizThumbIconClass() {
  5458. // 功能:无缩略图时,用业务对象 icon 做默认图(ss-icon + icon-obj-xx) by xu 20260115
  5459. const name = String(
  5460. this.ssObjName ||
  5461. this.item?.ssObjName ||
  5462. this.$root?.ssObjName ||
  5463. window?.ss?.dom?.ssObjName ||
  5464. ""
  5465. ).trim();
  5466. if (!name) return "";
  5467. return "icon-obj-" + name;
  5468. },
  5469. buildRightTextLines() {
  5470. // 功能:沿用一级对象卡片右侧文字区规则 by xu 20260115
  5471. const item = this.item || {};
  5472. const summary = String(item?.desc ?? "").trim();
  5473. const objNum = String(item?.objNum ?? "").trim();
  5474. const categoryArr = Array.isArray(item?.category) ? item.category : [];
  5475. const tagsArr = Array.isArray(item?.tags) ? item.tags : [];
  5476. const hasTags = tagsArr.length > 0;
  5477. const hasCategory = categoryArr.length > 0;
  5478. const secondKind = summary ? "summary" : hasTags ? "tags" : "";
  5479. const hasSecond = !!secondKind;
  5480. const thirdKind = objNum ? "objNum" : hasCategory ? "category" : "";
  5481. const hasThird = !!thirdKind;
  5482. const thirdFull = !hasSecond && hasThird;
  5483. const secondFull = hasSecond && !hasThird && secondKind === "tags";
  5484. const toValueText = (obj) => {
  5485. // 功能说明:类目/物品参数回显展示 key: value(否则只显示值看不懂) by xu 20260115
  5486. const [k, v] = Object.entries(obj || {})[0] || ["", ""];
  5487. const key = k !== undefined && k !== null ? String(k).trim() : "";
  5488. const val = v !== undefined && v !== null ? String(v).trim() : "";
  5489. if (key && val) return key + ":" + val;
  5490. if (val) return val;
  5491. if (key) return key;
  5492. return "";
  5493. };
  5494. const toLineList = (arr) =>
  5495. (arr || [])
  5496. .map(toValueText)
  5497. .map((s) => String(s ?? "").trim())
  5498. .filter(Boolean);
  5499. const secondTagsMaxLines = secondFull ? 4 : 3;
  5500. const secondTagsLinesFull = toLineList(tagsArr);
  5501. const secondTagsHead = secondTagsLinesFull.slice(
  5502. 0,
  5503. Math.max(0, secondTagsMaxLines - 1)
  5504. );
  5505. const secondTagsTail = secondTagsLinesFull.slice(
  5506. Math.max(0, secondTagsMaxLines - 1)
  5507. );
  5508. const secondTagsLast =
  5509. secondTagsTail.length <= 1
  5510. ? secondTagsTail[0] || ""
  5511. : secondTagsTail.join(" ");
  5512. const categoryLinesFull = toLineList(categoryArr);
  5513. const categoryLine = categoryLinesFull.join(" ");
  5514. const thirdText =
  5515. thirdKind === "objNum"
  5516. ? objNum
  5517. : thirdKind === "category"
  5518. ? categoryLine
  5519. : "";
  5520. return {
  5521. secondKind,
  5522. thirdKind,
  5523. hasSecond,
  5524. hasThird,
  5525. thirdFull,
  5526. secondFull,
  5527. summary,
  5528. secondTagsMaxLines,
  5529. secondTagsHead,
  5530. secondTagsLast,
  5531. secondTagsLinesFull,
  5532. objNum,
  5533. categoryLine,
  5534. categoryLinesFull,
  5535. thirdText,
  5536. };
  5537. },
  5538. measureTextOverflowByLines(text, maxLines, width) {
  5539. const w = Number(width) || 0;
  5540. if (!w || !text) return false;
  5541. const probe = document.createElement("div");
  5542. probe.style.position = "fixed";
  5543. probe.style.left = "-99999px";
  5544. probe.style.top = "0";
  5545. probe.style.width = w + "px";
  5546. probe.style.fontSize = "18px";
  5547. probe.style.lineHeight = "24px";
  5548. probe.style.whiteSpace = "normal";
  5549. probe.style.wordBreak = "break-word";
  5550. probe.style.visibility = "hidden";
  5551. probe.textContent = text;
  5552. document.body.appendChild(probe);
  5553. const h = probe.getBoundingClientRect().height || 0;
  5554. document.body.removeChild(probe);
  5555. return h > maxLines * 24 + 1;
  5556. },
  5557. measureSingleLineOverflow(text, width) {
  5558. const w = Number(width) || 0;
  5559. if (!w || !text) return false;
  5560. const probe = document.createElement("span");
  5561. probe.style.position = "fixed";
  5562. probe.style.left = "-99999px";
  5563. probe.style.top = "0";
  5564. probe.style.display = "inline-block";
  5565. probe.style.maxWidth = w + "px";
  5566. probe.style.fontSize = "18px";
  5567. probe.style.lineHeight = "24px";
  5568. probe.style.whiteSpace = "nowrap";
  5569. probe.style.visibility = "hidden";
  5570. probe.textContent = text;
  5571. document.body.appendChild(probe);
  5572. const overflow =
  5573. (probe.scrollWidth || 0) > (probe.clientWidth || w) + 1;
  5574. document.body.removeChild(probe);
  5575. return overflow;
  5576. },
  5577. refreshEllipsisVisible() {
  5578. // 功能:刷新「是否出现 ...」状态(用于控制命中区显示) by xu 20260115
  5579. try {
  5580. const right = this.$el?.querySelector?.(".right");
  5581. const rawWidth =
  5582. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  5583. const width = Math.max(0, Math.round(rawWidth));
  5584. const model = this.buildRightTextLines();
  5585. const next = {
  5586. secondSummary: false,
  5587. secondTags: false,
  5588. third: false,
  5589. thirdFull: false,
  5590. };
  5591. if (model.secondKind === "summary" && model.summary) {
  5592. next.secondSummary = this.measureTextOverflowByLines(
  5593. model.summary,
  5594. 3,
  5595. width
  5596. );
  5597. }
  5598. if (model.secondKind === "tags") {
  5599. next.secondTags = this.measureSingleLineOverflow(
  5600. model.secondTagsLast,
  5601. width
  5602. ); // 功能说明:tags 仅看最后一行是否溢出 by xu 20260115
  5603. }
  5604. if (model.hasThird && !model.thirdFull) {
  5605. next.third = this.measureSingleLineOverflow(model.thirdText, width);
  5606. }
  5607. if (model.hasThird && model.thirdFull) {
  5608. next.thirdFull = this.measureTextOverflowByLines(
  5609. model.thirdText,
  5610. 4,
  5611. width
  5612. );
  5613. }
  5614. const prev = this.ellipsisVisible || {};
  5615. const changed =
  5616. prev.secondSummary !== next.secondSummary ||
  5617. prev.secondTags !== next.secondTags ||
  5618. prev.third !== next.third ||
  5619. prev.thirdFull !== next.thirdFull;
  5620. if (changed) this.ellipsisVisible = next;
  5621. } catch (e) {
  5622. // ignore by xu 20260115
  5623. }
  5624. },
  5625. clearHideTextPopoverTimer() {
  5626. if (this.hideTextPopoverTimer) {
  5627. clearTimeout(this.hideTextPopoverTimer);
  5628. this.hideTextPopoverTimer = null;
  5629. }
  5630. },
  5631. hideTextPopoverLater() {
  5632. this.clearHideTextPopoverTimer();
  5633. this.hideTextPopoverTimer = setTimeout(() => {
  5634. this.showTextPopover = false;
  5635. this.textPopoverType = "";
  5636. this.textPopoverPayload = null;
  5637. }, 120);
  5638. },
  5639. showTextPopoverFor(el, kind) {
  5640. const model = this.buildRightTextLines();
  5641. const lineEl = el?.closest?.(".ss-card-text__line") || el;
  5642. const right = lineEl?.closest?.(".right") || el?.closest?.(".right");
  5643. const rawWidth =
  5644. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  5645. const width = Math.max(0, Math.round(rawWidth));
  5646. const overflowed =
  5647. kind === "second-summary"
  5648. ? this.measureTextOverflowByLines(model.summary, 3, width)
  5649. : kind === "second-tags"
  5650. ? this.measureSingleLineOverflow(model.secondTagsLast, width)
  5651. : kind === "third"
  5652. ? this.measureSingleLineOverflow(model.thirdText, width)
  5653. : this.measureTextOverflowByLines(model.thirdText, 4, width);
  5654. if (!overflowed) return;
  5655. let payload = null;
  5656. if (kind === "second-summary") {
  5657. if (model.summary) payload = { kind, text: model.summary };
  5658. } else if (kind === "second-tags") {
  5659. if (
  5660. Array.isArray(model.secondTagsLinesFull) &&
  5661. model.secondTagsLinesFull.length
  5662. ) {
  5663. payload = { kind, lines: model.secondTagsLinesFull };
  5664. }
  5665. } else if (kind === "third") {
  5666. if (
  5667. model.thirdKind === "category" &&
  5668. Array.isArray(model.categoryLinesFull) &&
  5669. model.categoryLinesFull.length
  5670. ) {
  5671. payload = { kind, lines: model.categoryLinesFull };
  5672. } else if (model.thirdText) {
  5673. payload = { kind, text: model.thirdText };
  5674. }
  5675. } else if (kind === "third-full") {
  5676. if (
  5677. model.thirdKind === "category" &&
  5678. Array.isArray(model.categoryLinesFull) &&
  5679. model.categoryLinesFull.length
  5680. ) {
  5681. payload = { kind, lines: model.categoryLinesFull };
  5682. } else if (model.thirdText) {
  5683. payload = { kind, text: model.thirdText };
  5684. }
  5685. }
  5686. if (!payload) return;
  5687. this.clearHideTextPopoverTimer();
  5688. const container = lineEl?.closest?.(".right");
  5689. const containerRect = container?.getBoundingClientRect?.();
  5690. const lineRect = lineEl?.getBoundingClientRect?.();
  5691. if (containerRect && lineRect) {
  5692. const bottom = Math.max(
  5693. 0,
  5694. Math.round(containerRect.bottom - lineRect.bottom)
  5695. );
  5696. this.textPopoverBottom = bottom;
  5697. } else {
  5698. this.textPopoverBottom = 0;
  5699. }
  5700. this.textPopoverPayload = payload;
  5701. this.textPopoverType = kind;
  5702. this.showTextPopover = true;
  5703. },
  5704. },
  5705. mounted() {
  5706. this.$nextTick?.(() => {
  5707. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5708. });
  5709. this.__ssCObjCardResizeHandler = () => this.refreshEllipsisVisible?.(); // 功能说明:窗口变化时刷新 ... 显示 by xu 20260115
  5710. window.addEventListener?.("resize", this.__ssCObjCardResizeHandler);
  5711. },
  5712. updated() {
  5713. this.$nextTick?.(() => {
  5714. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5715. });
  5716. },
  5717. beforeUnmount() {
  5718. this.clearHideTextPopoverTimer?.();
  5719. if (this.__ssCObjCardResizeHandler) {
  5720. window.removeEventListener?.("resize", this.__ssCObjCardResizeHandler);
  5721. this.__ssCObjCardResizeHandler = null;
  5722. }
  5723. },
  5724. render() {
  5725. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  5726. const SsIcon = Vue.resolveComponent("ss-icon");
  5727. const hasThumbArea = !!(this.item?.thumb || this.item?.thumbType);
  5728. const thumbSrc = (() => {
  5729. // 功能说明:兼容 thumb 为 raw path 或 {val}/{value},组件内统一转为 dlByHttp URL by xu 20260122
  5730. const t = this.item?.thumb;
  5731. if (!t) return "";
  5732. if (typeof t === "string") {
  5733. const s = t.trim();
  5734. if (!s) return "";
  5735. if (
  5736. /^https?:\/\//i.test(s) ||
  5737. s.startsWith("/service?") ||
  5738. s.startsWith("/")
  5739. )
  5740. return s;
  5741. return buildThumbUrl(s);
  5742. }
  5743. return buildThumbUrl(t);
  5744. })();
  5745. return Vue.h(
  5746. "div",
  5747. {
  5748. class: {
  5749. "knowledge-item-container": true,
  5750. active: this.item.active,
  5751. [this.cardType]: !!this.cardType,
  5752. [this.statusClass]: !!this.statusClass,
  5753. },
  5754. onClick: (e) => this.onItemClick?.(e), // 功能说明:二级对象卡片点击仅查看 by xu 20260115
  5755. },
  5756. [
  5757. this.item?.statusIcons?.length > 0 &&
  5758. Vue.h(
  5759. "div",
  5760. { class: "card-status-icons" },
  5761. this.item.statusIcons.map((icon) =>
  5762. Vue.h(SsIcon, {
  5763. class: "status-icon " + icon.class,
  5764. title: icon.title,
  5765. })
  5766. )
  5767. ),
  5768. this.item?.buttons?.length > 0 &&
  5769. Vue.h(
  5770. "div",
  5771. {
  5772. class: "header",
  5773. style:
  5774. this.item?.statusIcons?.length > 0
  5775. ? {
  5776. right: String(this.item.statusIcons.length * 48) + "px",
  5777. borderTopRightRadius: "0",
  5778. }
  5779. : {},
  5780. onMouseenter: () => (this.showButtons = true),
  5781. onMouseleave: () => (this.showButtons = false),
  5782. onClick: (e) => this.onItemChange(e),
  5783. },
  5784. [
  5785. Vue.h("div", {
  5786. class: "cart-list-setting cart-list-icon",
  5787. title: this.item?.buttons?.[0]?.title,
  5788. }),
  5789. this.showButtons &&
  5790. this.item?.buttons?.length > 1 &&
  5791. Vue.h(
  5792. "div",
  5793. { class: "cart-list-button-popup" },
  5794. this.item.buttons.map((btn) =>
  5795. Vue.h(
  5796. "div",
  5797. {
  5798. onClick: (e) => {
  5799. e.stopPropagation();
  5800. btn.onclick?.();
  5801. },
  5802. },
  5803. [
  5804. btn.class &&
  5805. Vue.h(SsCartListIcon, { class: [btn.class] }),
  5806. Vue.h("span", null, btn.title),
  5807. ]
  5808. )
  5809. )
  5810. ),
  5811. ]
  5812. ),
  5813. Vue.h("div", { class: "body" }, [
  5814. Vue.h("div", { class: "box-header" }, [
  5815. Vue.h("div", String(this.item.title || "")),
  5816. ]),
  5817. Vue.h(
  5818. "div",
  5819. { class: !hasThumbArea ? "no-thumb box-body" : "box-body" },
  5820. [
  5821. hasThumbArea
  5822. ? thumbSrc
  5823. ? Vue.h("div", { class: "left" }, [
  5824. Vue.h("img", {
  5825. src: thumbSrc,
  5826. alt: "Thumbnail",
  5827. class: "imgUnHandle",
  5828. style: {
  5829. "object-fit": "cover",
  5830. width: "100%",
  5831. height: "100%",
  5832. },
  5833. }),
  5834. ])
  5835. : Vue.h(
  5836. "div",
  5837. { class: "left ss-objlist-thumbPlaceholder" },
  5838. [
  5839. Vue.h(SsIcon, {
  5840. class:
  5841. this.getBizThumbIconClass() +
  5842. " ss-objlist-thumbIcon",
  5843. }),
  5844. ]
  5845. )
  5846. : null,
  5847. Vue.h(
  5848. "div",
  5849. { class: "right" },
  5850. (() => {
  5851. const model = this.buildRightTextLines();
  5852. const hasAny = !!(model?.hasSecond || model?.hasThird);
  5853. if (!hasAny) return [];
  5854. const children = [];
  5855. if (model.hasSecond && model.secondKind === "summary") {
  5856. children.push(
  5857. Vue.h(
  5858. "div",
  5859. {
  5860. class:
  5861. "ss-card-text__line ss-card-text__secondBlock",
  5862. },
  5863. [
  5864. Vue.h(
  5865. "div",
  5866. {
  5867. class: "ss-card-text__secondSummary",
  5868. title: model.summary,
  5869. },
  5870. model.summary
  5871. ),
  5872. Vue.h("span", {
  5873. class: [
  5874. "ss-card-text__ellipsisHit",
  5875. "ss-card-text__ellipsisHit--second",
  5876. this.ellipsisVisible?.secondSummary
  5877. ? "is-on"
  5878. : "",
  5879. ],
  5880. title: "查看完整信息",
  5881. onMouseenter: (e) =>
  5882. this.showTextPopoverFor(
  5883. e?.currentTarget,
  5884. "second-summary"
  5885. ),
  5886. onClick: (e) => {
  5887. e?.stopPropagation?.();
  5888. this.showTextPopoverFor(
  5889. e?.currentTarget,
  5890. "second-summary"
  5891. );
  5892. },
  5893. onMouseleave: () => this.hideTextPopoverLater(),
  5894. }),
  5895. ]
  5896. )
  5897. );
  5898. }
  5899. if (model.hasSecond && model.secondKind === "tags") {
  5900. children.push(
  5901. Vue.h(
  5902. "div",
  5903. {
  5904. class: [
  5905. "ss-card-text__line",
  5906. model.secondFull
  5907. ? "ss-card-text__secondFullBlock"
  5908. : "ss-card-text__secondBlock",
  5909. ],
  5910. },
  5911. [
  5912. Vue.h(
  5913. "div",
  5914. { class: "ss-card-text__secondTags" },
  5915. [
  5916. ...model.secondTagsHead.map((t) =>
  5917. Vue.h(
  5918. "div",
  5919. {
  5920. class: "ss-card-text__tagLine",
  5921. title: t,
  5922. },
  5923. t
  5924. )
  5925. ),
  5926. Vue.h(
  5927. "div",
  5928. {
  5929. class:
  5930. "ss-card-text__tagLine is-last ss-card-text__tagLineLast",
  5931. title: model.secondTagsLast,
  5932. },
  5933. model.secondTagsLast
  5934. ),
  5935. ]
  5936. ),
  5937. Vue.h("span", {
  5938. class: [
  5939. "ss-card-text__ellipsisHit",
  5940. "ss-card-text__ellipsisHit--second",
  5941. this.ellipsisVisible?.secondTags ? "is-on" : "",
  5942. ],
  5943. title: "查看完整信息",
  5944. onMouseenter: (e) =>
  5945. this.showTextPopoverFor(
  5946. e?.currentTarget,
  5947. "second-tags"
  5948. ),
  5949. onClick: (e) => {
  5950. e?.stopPropagation?.();
  5951. this.showTextPopoverFor(
  5952. e?.currentTarget,
  5953. "second-tags"
  5954. );
  5955. },
  5956. onMouseleave: () => this.hideTextPopoverLater(),
  5957. }),
  5958. ]
  5959. )
  5960. );
  5961. }
  5962. if (model.hasThird) {
  5963. if (model.thirdFull) {
  5964. children.push(
  5965. Vue.h(
  5966. "div",
  5967. {
  5968. class:
  5969. "ss-card-text__line ss-card-text__thirdFullBlock",
  5970. },
  5971. [
  5972. Vue.h(
  5973. "div",
  5974. {
  5975. class: "ss-card-text__thirdFull",
  5976. title: model.thirdText,
  5977. },
  5978. model.thirdText
  5979. ),
  5980. Vue.h("span", {
  5981. class: [
  5982. "ss-card-text__ellipsisHit",
  5983. "ss-card-text__ellipsisHit--third",
  5984. this.ellipsisVisible?.thirdFull
  5985. ? "is-on"
  5986. : "",
  5987. ],
  5988. title: "查看完整信息",
  5989. onMouseenter: (e) =>
  5990. this.showTextPopoverFor(
  5991. e?.currentTarget,
  5992. "third-full"
  5993. ),
  5994. onClick: (e) => {
  5995. e?.stopPropagation?.();
  5996. this.showTextPopoverFor(
  5997. e?.currentTarget,
  5998. "third-full"
  5999. );
  6000. },
  6001. onMouseleave: () => this.hideTextPopoverLater(),
  6002. }),
  6003. ]
  6004. )
  6005. );
  6006. } else {
  6007. children.push(
  6008. Vue.h(
  6009. "div",
  6010. {
  6011. class:
  6012. "ss-card-text__line ss-card-text__thirdLineWrap",
  6013. },
  6014. [
  6015. Vue.h(
  6016. "div",
  6017. {
  6018. class: "ss-card-text__thirdLine",
  6019. title: model.thirdText,
  6020. },
  6021. model.thirdText
  6022. ),
  6023. Vue.h("span", {
  6024. class: [
  6025. "ss-card-text__ellipsisHit",
  6026. "ss-card-text__ellipsisHit--third",
  6027. this.ellipsisVisible?.third ? "is-on" : "",
  6028. ],
  6029. title: "查看完整信息",
  6030. onMouseenter: (e) =>
  6031. this.showTextPopoverFor(
  6032. e?.currentTarget,
  6033. "third"
  6034. ),
  6035. onClick: (e) => {
  6036. e?.stopPropagation?.();
  6037. this.showTextPopoverFor(
  6038. e?.currentTarget,
  6039. "third"
  6040. );
  6041. },
  6042. onMouseleave: () => this.hideTextPopoverLater(),
  6043. }),
  6044. ]
  6045. )
  6046. );
  6047. }
  6048. }
  6049. const popover =
  6050. this.showTextPopover &&
  6051. Vue.h(
  6052. "div",
  6053. {
  6054. class: "ss-card-text-popover",
  6055. style: { bottom: this.textPopoverBottom + "px" },
  6056. onMouseenter: () => {
  6057. this.clearHideTextPopoverTimer();
  6058. this.showTextPopover = true;
  6059. },
  6060. onMouseleave: () => this.hideTextPopoverLater(),
  6061. },
  6062. (() => {
  6063. const p = this.textPopoverPayload || {};
  6064. if (p.kind === "second-summary" && p.text) {
  6065. return [
  6066. Vue.h(
  6067. "div",
  6068. { class: "ss-card-text-popover__summary" },
  6069. p.text
  6070. ),
  6071. ];
  6072. }
  6073. if (Array.isArray(p.lines)) {
  6074. return [
  6075. Vue.h(
  6076. "div",
  6077. { class: "ss-card-text-popover__kvlist" },
  6078. p.lines.map((t) =>
  6079. Vue.h(
  6080. "div",
  6081. { class: "ss-card-text-popover__kv" },
  6082. t
  6083. )
  6084. )
  6085. ),
  6086. ];
  6087. }
  6088. if (
  6089. (p.kind === "third" || p.kind === "third-full") &&
  6090. p.text
  6091. ) {
  6092. return [
  6093. Vue.h(
  6094. "div",
  6095. { class: "ss-card-text-popover__objno" },
  6096. p.text
  6097. ),
  6098. ];
  6099. }
  6100. return [];
  6101. })()
  6102. );
  6103. return [
  6104. Vue.h("div", { class: "ss-card-text" }, children),
  6105. popover,
  6106. ];
  6107. })()
  6108. ),
  6109. ]
  6110. ),
  6111. ]),
  6112. ]
  6113. );
  6114. },
  6115. };
  6116. // ss-sidebar 右侧边栏(容器 + 子组件),用于 objList 右侧区域 by xu 20260106
  6117. // 组件文档补全(JSDoc) by xu 20260108
  6118. /**
  6119. * SsSidebarButtons(右侧边栏顶部按钮栏)
  6120. *
  6121. * 用途:
  6122. * - 渲染 objList 右侧顶部快捷操作(预定/入住/退房/清洁...)
  6123. * - 内部复用 `ss-search-button`(项目现有按钮样式/交互)
  6124. *
  6125. * 调用示例:
  6126. * ```html
  6127. * <ss-sidebar-buttons :items="sidebarButtons" />
  6128. * ```
  6129. *
  6130. * Props:
  6131. * - `items`: 按钮配置数组
  6132. * - `{ id, text, icon?, onClick? }`
  6133. *
  6134. * Emits:
  6135. * - `click`:点击按钮时触发,参数为按钮对象
  6136. */
  6137. const SsSidebarButtons = {
  6138. name: "SsSidebarButtons",
  6139. props: {
  6140. items: { type: Array, default: () => [] },
  6141. },
  6142. emits: ["click"],
  6143. render() {
  6144. const SsSearchButton = Vue.resolveComponent("ss-search-button");
  6145. const items = this.items || [];
  6146. if (!items.length) return null;
  6147. return Vue.h(
  6148. "div",
  6149. { class: "ss-sidebar-actions" },
  6150. items.map((btn) =>
  6151. // 顶部操作按钮复用 ss-search-button(先 mock 固定按钮) by xu 20260106
  6152. Vue.h(SsSearchButton, {
  6153. text: btn?.text ?? "",
  6154. iconClass: btn?.iconClass ?? "",
  6155. opt: btn?.opt ?? [],
  6156. checkId: btn?.checkId ?? "0",
  6157. width: btn?.width,
  6158. id: btn?.id,
  6159. onClick: (e) => {
  6160. e?.stopPropagation?.();
  6161. btn?.onClick?.(btn);
  6162. this.$emit("click", btn);
  6163. },
  6164. })
  6165. )
  6166. );
  6167. },
  6168. };
  6169. // 组件文档补全(JSDoc) by xu 20260108
  6170. /**
  6171. * SsSidebarChart(ECharts 容器渲染)
  6172. *
  6173. * 用途:
  6174. * - 仅负责 echarts init / setOption / resize / dispose
  6175. * - 被 `ss-sidebar-chart-hover` 与图表面板复用
  6176. *
  6177. * 调用示例:
  6178. * ```html
  6179. * <ss-sidebar-chart :options="option" height="220px" />
  6180. * ```
  6181. *
  6182. * Props:
  6183. * - `options`:ECharts option(Object)
  6184. * - `height`:容器高度(String)
  6185. */
  6186. const SsSidebarChart = {
  6187. name: "SsSidebarChart",
  6188. props: {
  6189. options: { type: Object, default: () => ({}) },
  6190. height: { type: String, default: "200px" },
  6191. },
  6192. setup(props) {
  6193. const elRef = Vue.ref(null);
  6194. let chart = null;
  6195. const renderChart = () => {
  6196. if (!elRef.value || !window.echarts) return;
  6197. if (!chart) {
  6198. chart = window.echarts.init(elRef.value);
  6199. }
  6200. chart.setOption(props.options || {}, true);
  6201. };
  6202. const resizeChart = () => {
  6203. chart?.resize?.();
  6204. };
  6205. Vue.onMounted(() => {
  6206. renderChart();
  6207. window.addEventListener("resize", resizeChart);
  6208. });
  6209. Vue.onBeforeUnmount(() => {
  6210. window.removeEventListener("resize", resizeChart);
  6211. chart?.dispose?.();
  6212. chart = null;
  6213. });
  6214. Vue.watch(
  6215. () => props.options,
  6216. () => {
  6217. renderChart();
  6218. },
  6219. { deep: true }
  6220. );
  6221. return { elRef };
  6222. },
  6223. render() {
  6224. return Vue.h("div", {
  6225. ref: "elRef",
  6226. style: {
  6227. width: "100%",
  6228. height: this.height,
  6229. // 图表容器不加 padding/border,由外层布局控制 by xu 20260106
  6230. background: "transparent",
  6231. border: "none",
  6232. "border-radius": "0",
  6233. },
  6234. });
  6235. },
  6236. };
  6237. // ss-sidebar-chart-hover:hover 弹出左侧大图(支持图钉/全屏) by xu 20260106
  6238. // 组件文档补全(JSDoc) by xu 20260108
  6239. /**
  6240. * SsSidebarChartHover(小图 + hover 左侧大图预览 + 图钉固定 + 全屏)
  6241. *
  6242. * 用途:
  6243. * - 右侧统计图小卡片:hover 时在左侧弹出大图预览
  6244. * - 预览头部:左侧图标+标题;右侧固定/全屏按钮(icon-base)
  6245. * - 全屏:方案A(浏览器 Fullscreen API)
  6246. *
  6247. * 调用示例(由 ss-sidebar chart panel 内部调用):
  6248. * ```html
  6249. * <ss-sidebar-chart-hover
  6250. * title="校舍建筑面积和总体分布"
  6251. * icon-class="menu-icon icon-obj-jzw"
  6252. * :options="option"
  6253. * height="220px"
  6254. * />
  6255. * ```
  6256. *
  6257. * Props:
  6258. * - `title/iconClass/icon`:用于预览/全屏 header 显示(与面板 header 一致)
  6259. * - `options`:ECharts option
  6260. * - `height`:小图高度
  6261. * - `previewWidth/previewHeight`:预览建议尺寸(会按视口自适应)
  6262. */
  6263. const SsSidebarChartHover = {
  6264. name: "SsSidebarChartHover",
  6265. props: {
  6266. // hover 大图标题/图标(与小图面板 header 一致) by xu 20260108
  6267. title: { type: String, default: "" },
  6268. iconClass: { type: String, default: "" },
  6269. icon: { type: String, default: "" },
  6270. options: { type: Object, default: () => ({}) },
  6271. height: { type: String, default: "220px" },
  6272. // hover 弹窗建议尺寸:默认 1000x650(比例由逻辑统一管控),实际渲染会按比例自适应视口 by xu 20260115
  6273. previewWidth: { type: Number, default: 1000 },
  6274. previewHeight: { type: Number, default: 650 },
  6275. },
  6276. setup(props) {
  6277. const triggerRef = Vue.ref(null);
  6278. const fullscreenRef = Vue.ref(null);
  6279. const open = Vue.ref(false);
  6280. const pinned = Vue.ref(false);
  6281. const fullscreen = Vue.ref(false);
  6282. const hoveringTrigger = Vue.ref(false);
  6283. const hoveringPreview = Vue.ref(false);
  6284. const previewStyle = Vue.ref({});
  6285. let closeTimer = null;
  6286. const updatePreviewPosition = () => {
  6287. const el = triggerRef.value;
  6288. if (!el) return;
  6289. const rect = el.getBoundingClientRect();
  6290. // 功能说明:优先使用 visualViewport(避免浏览器 UI/缩放导致可视区与 innerHeight 偏差,出现预览被遮挡约 70px) by xu 20260116
  6291. const docEl = document.documentElement;
  6292. const vv = window.visualViewport;
  6293. let viewportLeft = Number(vv?.offsetLeft ?? 0) || 0;
  6294. let viewportTop = Number(vv?.offsetTop ?? 0) || 0;
  6295. let vw =
  6296. Number(vv?.width ?? 0) ||
  6297. Number(docEl?.clientWidth || 0) ||
  6298. window.innerWidth;
  6299. let vh =
  6300. Number(vv?.height ?? 0) ||
  6301. Number(docEl?.clientHeight || 0) ||
  6302. window.innerHeight;
  6303. // 功能说明:若页面在 iframe 内,父页面可能裁切 iframe 可见区域(overflow/弹窗容器),需要用“iframe可见区域”做二次约束 by xu 20260116
  6304. try {
  6305. const inIframe = window.top && window.top !== window;
  6306. const frameEl = window.frameElement;
  6307. if (inIframe && frameEl && window.top?.document) {
  6308. const topVv = window.top.visualViewport;
  6309. const topDocEl = window.top.document.documentElement;
  6310. const topVw =
  6311. Number(topVv?.width ?? 0) ||
  6312. Number(topDocEl?.clientWidth || 0) ||
  6313. window.top.innerWidth;
  6314. const topVh =
  6315. Number(topVv?.height ?? 0) ||
  6316. Number(topDocEl?.clientHeight || 0) ||
  6317. window.top.innerHeight;
  6318. const fr = frameEl.getBoundingClientRect?.();
  6319. if (fr && fr.width > 0 && fr.height > 0) {
  6320. const visibleW = Math.max(
  6321. 0,
  6322. Math.min(fr.right, topVw) - Math.max(fr.left, 0)
  6323. );
  6324. const visibleH = Math.max(
  6325. 0,
  6326. Math.min(fr.bottom, topVh) - Math.max(fr.top, 0)
  6327. );
  6328. if (visibleW > 0) {
  6329. vw = Math.min(vw, visibleW);
  6330. viewportLeft = Math.max(0, -fr.left); // iframe内坐标系偏移(左侧被裁切时) by xu 20260116
  6331. }
  6332. if (visibleH > 0) {
  6333. vh = Math.min(vh, visibleH);
  6334. viewportTop = Math.max(0, -fr.top); // iframe内坐标系偏移(顶部被裁切时) by xu 20260116
  6335. }
  6336. }
  6337. }
  6338. } catch (_) {}
  6339. // 预览窗尺寸:优先保证“完整可见”,其次再尽量对齐右侧 header 顶部 by xu 20260116
  6340. const viewportPaddingX = 40;
  6341. const viewportPaddingTop = 20;
  6342. const viewportPaddingBottom = 10;
  6343. // 功能说明:hover 预览框不要覆盖右侧栏,优先放在 ss-sidebar 左侧;必要时动态缩小宽度 by xu 20260115
  6344. const sidebarEl = el.closest ? el.closest(".ss-sidebar") : null;
  6345. const sidebarRect = sidebarEl?.getBoundingClientRect?.();
  6346. const maxWidthByViewport = Math.max(240, vw - viewportPaddingX);
  6347. const maxWidthByLeftSpace = sidebarRect
  6348. ? Math.max(
  6349. 240,
  6350. sidebarRect.left - viewportPaddingX - 14 /* gapFromSidebar */
  6351. )
  6352. : maxWidthByViewport;
  6353. // 功能说明:预览框尺寸按比例(默认 5:3)缩放,并提供最大/最小值约束 by xu 20260115
  6354. const ratio = 3 / 5;
  6355. const minWidth = 320;
  6356. const minHeight = 240;
  6357. const maxHeightByViewport = Math.max(
  6358. minHeight,
  6359. vh - viewportPaddingTop - viewportPaddingBottom
  6360. );
  6361. const maxWidthByProp = Number(props.previewWidth) || 1000;
  6362. const maxHeightByProp = Number(props.previewHeight) || 650;
  6363. // 优先按高度撑满可视区(保证预览完整可见),再根据左侧可用宽度回退 by xu 20260116
  6364. const maxHeight = Math.min(maxHeightByProp, maxHeightByViewport);
  6365. let height = Math.max(minHeight, maxHeight);
  6366. let width = Math.round(height / ratio);
  6367. width = Math.min(
  6368. width,
  6369. maxWidthByProp,
  6370. maxWidthByViewport,
  6371. maxWidthByLeftSpace
  6372. );
  6373. width = Math.max(minWidth, width);
  6374. height = Math.round(width * ratio);
  6375. if (height > maxHeight) {
  6376. height = maxHeight;
  6377. width = Math.round(height / ratio);
  6378. }
  6379. // 默认贴着小图左侧弹出,右边缘与小图左边缘轻微重叠,避免 1px 缝隙导致 hover 闪断 by xu 20260108
  6380. const overlap = 2;
  6381. const gapFromSidebar = 14; // 功能说明:弹窗与右侧边栏留出距离(更不贴近) by xu 20260108
  6382. // 优先:贴在 sidebar 左侧(不压住右侧栏内容) by xu 20260115
  6383. let left = sidebarRect
  6384. ? sidebarRect.left - gapFromSidebar - width + overlap
  6385. : rect.left - width - gapFromSidebar + overlap;
  6386. // 如果左侧空间不足,则贴右侧(兜底,同样重叠) by xu 20260108
  6387. if (left < 0) left = rect.right + gapFromSidebar - overlap;
  6388. left = Math.max(
  6389. viewportLeft,
  6390. Math.min(left, viewportLeft + vw - width)
  6391. );
  6392. // top:优先保证完整可见,然后才贴近 header 顶部 by xu 20260116
  6393. let headerEl = el;
  6394. while (headerEl && !headerEl.classList?.contains("ss-sidebar-panel")) {
  6395. headerEl = headerEl.parentElement;
  6396. }
  6397. let headerRect = headerEl
  6398. ?.querySelector(".ss-sidebar-panel__header")
  6399. ?.getBoundingClientRect();
  6400. let top = headerRect?.top ?? rect.top;
  6401. top = Math.max(
  6402. viewportTop + viewportPaddingTop,
  6403. Math.min(top, viewportTop + vh - height - viewportPaddingBottom)
  6404. );
  6405. previewStyle.value = {
  6406. position: "fixed",
  6407. left: `${Math.round(left)}px`,
  6408. top: `${Math.round(top)}px`,
  6409. width: `${width}px`,
  6410. height: `${height}px`,
  6411. zIndex: 2147483647, // 功能说明:提高层级到接近浏览器上限,避免仍被页面固定栏/弹窗遮挡 by xu 20260116
  6412. };
  6413. };
  6414. const clearCloseTimer = () => {
  6415. if (closeTimer) {
  6416. clearTimeout(closeTimer);
  6417. closeTimer = null;
  6418. }
  6419. };
  6420. const scheduleClose = () => {
  6421. clearCloseTimer();
  6422. if (pinned.value || fullscreen.value) return;
  6423. if (hoveringTrigger.value || hoveringPreview.value) return; // 功能:鼠标在小图/大图之间移动不关闭 by xu 20260108
  6424. closeTimer = setTimeout(() => {
  6425. open.value = false;
  6426. }, 100);
  6427. };
  6428. const openPreview = () => {
  6429. clearCloseTimer();
  6430. updatePreviewPosition();
  6431. open.value = true;
  6432. };
  6433. const togglePin = () => {
  6434. pinned.value = !pinned.value;
  6435. if (pinned.value) {
  6436. open.value = true;
  6437. updatePreviewPosition();
  6438. }
  6439. };
  6440. const toggleFullscreen = () => {
  6441. // 全屏:采用浏览器 Fullscreen API(方案A),不使用遮罩弹窗 by xu 20260108
  6442. if (!fullscreen.value) {
  6443. open.value = false; // 避免同时渲染预览与全屏 by xu 20260108
  6444. fullscreen.value = true;
  6445. Vue.nextTick(() => {
  6446. const el = fullscreenRef.value;
  6447. if (el?.requestFullscreen) {
  6448. el.requestFullscreen().catch(() => {
  6449. // requestFullscreen 失败则回退为非全屏状态 by xu 20260108
  6450. fullscreen.value = false;
  6451. });
  6452. } else {
  6453. fullscreen.value = false;
  6454. }
  6455. });
  6456. } else {
  6457. if (document?.exitFullscreen) {
  6458. document.exitFullscreen().catch(() => {});
  6459. }
  6460. }
  6461. };
  6462. const handleFullscreenChange = () => {
  6463. const isFs = !!document.fullscreenElement;
  6464. fullscreen.value = isFs; // 功能说明:同步 ESC/系统退出全屏状态 by xu 20260108
  6465. if (isFs) {
  6466. open.value = false;
  6467. clearCloseTimer();
  6468. return;
  6469. }
  6470. // 退出全屏后:若固定或仍 hover,则恢复预览,否则关闭 by xu 20260108
  6471. if (pinned.value || hoveringTrigger.value || hoveringPreview.value) {
  6472. open.value = true;
  6473. updatePreviewPosition();
  6474. } else {
  6475. open.value = false;
  6476. }
  6477. };
  6478. Vue.onMounted(() => {
  6479. window.addEventListener("resize", updatePreviewPosition);
  6480. window.addEventListener("scroll", updatePreviewPosition, true);
  6481. document.addEventListener("fullscreenchange", handleFullscreenChange); // 功能说明:监听全屏状态变化 by xu 20260108
  6482. });
  6483. Vue.onBeforeUnmount(() => {
  6484. clearCloseTimer();
  6485. window.removeEventListener("resize", updatePreviewPosition);
  6486. window.removeEventListener("scroll", updatePreviewPosition, true);
  6487. document.removeEventListener(
  6488. "fullscreenchange",
  6489. handleFullscreenChange
  6490. );
  6491. });
  6492. return {
  6493. triggerRef,
  6494. fullscreenRef,
  6495. open,
  6496. pinned,
  6497. fullscreen,
  6498. hoveringTrigger,
  6499. hoveringPreview,
  6500. previewStyle,
  6501. openPreview,
  6502. scheduleClose,
  6503. clearCloseTimer,
  6504. togglePin,
  6505. toggleFullscreen,
  6506. };
  6507. },
  6508. render() {
  6509. const SsIcon = Vue.resolveComponent("ss-icon");
  6510. const Chart = Vue.resolveComponent("ss-sidebar-chart");
  6511. const hasHeader = !!(this.title || this.iconClass || this.icon); // 功能:hover 大图显示左侧图标+标题 by xu 20260108
  6512. const previewContent = Vue.h(
  6513. "div",
  6514. {
  6515. class: { "ss-sidebar-chart-preview": true, "is-pinned": this.pinned },
  6516. style: this.previewStyle,
  6517. onMouseenter: () => {
  6518. this.hoveringPreview = true;
  6519. this.clearCloseTimer();
  6520. },
  6521. onMouseleave: () => {
  6522. this.hoveringPreview = false;
  6523. this.scheduleClose();
  6524. },
  6525. },
  6526. [
  6527. hasHeader
  6528. ? Vue.h(
  6529. "div",
  6530. {
  6531. class:
  6532. "ss-sidebar-panel__header ss-sidebar-chart-preview__header",
  6533. },
  6534. [
  6535. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  6536. this.iconClass
  6537. ? Vue.h(SsIcon, {
  6538. class: this.iconClass + " ss-sidebar-panel__icon",
  6539. })
  6540. : this.icon
  6541. ? Vue.h(SsIcon, {
  6542. name: this.icon,
  6543. size: "16px",
  6544. class: "ss-sidebar-panel__icon",
  6545. })
  6546. : null,
  6547. Vue.h("span", null, this.title || "统计图"),
  6548. ]),
  6549. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6550. Vue.h(
  6551. "button",
  6552. {
  6553. type: "button",
  6554. class: {
  6555. "ss-sidebar-chart-tool": true,
  6556. "is-active": this.pinned,
  6557. },
  6558. title: this.pinned ? "取消固定" : "固定",
  6559. onClick: (e) => {
  6560. e.stopPropagation();
  6561. this.togglePin();
  6562. },
  6563. },
  6564. // 功能说明:右侧栏 hover 工具图标使用 ss-sidebar-base-icon(不复用左侧 menu-base-icon) by xu 20260123
  6565. [
  6566. Vue.h(SsIcon, {
  6567. class: this.pinned
  6568. ? "ss-sidebar-base-icon icon-fix-bold"
  6569. : "ss-sidebar-base-icon icon-fix",
  6570. }),
  6571. ]
  6572. ),
  6573. Vue.h(
  6574. "button",
  6575. {
  6576. type: "button",
  6577. class: "ss-sidebar-chart-tool",
  6578. title: "全屏",
  6579. onClick: (e) => {
  6580. e.stopPropagation();
  6581. this.toggleFullscreen();
  6582. },
  6583. },
  6584. [
  6585. Vue.h(SsIcon, {
  6586. class: this.fullscreen
  6587. ? "ss-sidebar-base-icon icon-fs-exit"
  6588. : "ss-sidebar-base-icon icon-fs",
  6589. }),
  6590. ]
  6591. ),
  6592. ]),
  6593. ]
  6594. )
  6595. : Vue.h(
  6596. "div",
  6597. {
  6598. class:
  6599. "ss-sidebar-chart-preview__header ss-sidebar-chart-preview__header--simple",
  6600. },
  6601. [
  6602. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6603. Vue.h(
  6604. "button",
  6605. {
  6606. type: "button",
  6607. class: {
  6608. "ss-sidebar-chart-tool": true,
  6609. "is-active": this.pinned,
  6610. },
  6611. title: this.pinned ? "取消固定" : "固定",
  6612. onClick: (e) => {
  6613. e.stopPropagation();
  6614. this.togglePin();
  6615. },
  6616. },
  6617. [
  6618. Vue.h(SsIcon, {
  6619. class: this.pinned
  6620. ? "ss-sidebar-base-icon icon-fix-bold"
  6621. : "ss-sidebar-base-icon icon-fix",
  6622. }),
  6623. ]
  6624. ),
  6625. Vue.h(
  6626. "button",
  6627. {
  6628. type: "button",
  6629. class: "ss-sidebar-chart-tool",
  6630. title: "全屏",
  6631. onClick: (e) => {
  6632. e.stopPropagation();
  6633. this.toggleFullscreen();
  6634. },
  6635. },
  6636. [
  6637. Vue.h(SsIcon, {
  6638. class: this.fullscreen
  6639. ? "ss-sidebar-base-icon icon-chk-on"
  6640. : "ss-sidebar-base-icon icon-chk",
  6641. }),
  6642. ]
  6643. ),
  6644. ]),
  6645. ]
  6646. ),
  6647. Vue.h("div", { class: "ss-sidebar-chart-preview__body" }, [
  6648. Vue.h(Chart, { options: this.options, height: "100%" }),
  6649. ]),
  6650. ]
  6651. );
  6652. const fullscreenContent =
  6653. this.fullscreen &&
  6654. Vue.h(
  6655. "div",
  6656. {
  6657. ref: "fullscreenRef",
  6658. class: "ss-sidebar-chart-fullscreen",
  6659. },
  6660. [
  6661. Vue.h(
  6662. "div",
  6663. {
  6664. class:
  6665. "ss-sidebar-panel__header ss-sidebar-chart-fullscreen__header",
  6666. },
  6667. [
  6668. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  6669. this.iconClass
  6670. ? Vue.h(SsIcon, {
  6671. class: this.iconClass + " ss-sidebar-panel__icon",
  6672. })
  6673. : this.icon
  6674. ? Vue.h(SsIcon, {
  6675. name: this.icon,
  6676. size: "16px",
  6677. class: "ss-sidebar-panel__icon",
  6678. })
  6679. : null,
  6680. Vue.h("span", null, this.title || "统计图"),
  6681. ]),
  6682. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6683. Vue.h(
  6684. "button",
  6685. {
  6686. type: "button",
  6687. class: {
  6688. "ss-sidebar-chart-tool": true,
  6689. "is-active": this.pinned,
  6690. },
  6691. title: this.pinned ? "取消固定" : "固定",
  6692. onClick: (e) => {
  6693. e.stopPropagation();
  6694. this.togglePin();
  6695. },
  6696. },
  6697. [
  6698. Vue.h(SsIcon, {
  6699. class: this.pinned
  6700. ? "ss-sidebar-base-icon icon-fix-bold"
  6701. : "ss-sidebar-base-icon icon-fix",
  6702. }),
  6703. ]
  6704. ),
  6705. Vue.h(
  6706. "button",
  6707. {
  6708. type: "button",
  6709. class: "ss-sidebar-chart-tool",
  6710. title: "退出全屏",
  6711. onClick: (e) => {
  6712. e.stopPropagation();
  6713. this.toggleFullscreen();
  6714. },
  6715. },
  6716. [
  6717. Vue.h(SsIcon, {
  6718. class: "ss-sidebar-base-icon icon-fs-exit",
  6719. }),
  6720. ]
  6721. ),
  6722. ]),
  6723. ]
  6724. ),
  6725. Vue.h("div", { class: "ss-sidebar-chart-fullscreen__body" }, [
  6726. Vue.h(Chart, { options: this.options, height: "100%" }),
  6727. ]),
  6728. ]
  6729. );
  6730. return Vue.h("div", { class: "ss-sidebar-chart-hover" }, [
  6731. Vue.h(
  6732. "div",
  6733. {
  6734. ref: "triggerRef",
  6735. class: "ss-sidebar-chart-hover__trigger",
  6736. onMouseenter: () => {
  6737. this.hoveringTrigger = true;
  6738. this.openPreview();
  6739. },
  6740. onMouseleave: () => {
  6741. this.hoveringTrigger = false;
  6742. this.scheduleClose();
  6743. },
  6744. },
  6745. [Vue.h(Chart, { options: this.options, height: this.height })]
  6746. ),
  6747. (this.open || this.fullscreen) &&
  6748. Vue.h(Vue.Teleport, { to: "body" }, [
  6749. this.open ? previewContent : null,
  6750. fullscreenContent || null,
  6751. ]),
  6752. ]);
  6753. },
  6754. };
  6755. // 组件文档补全(JSDoc) by xu 20260108
  6756. /**
  6757. * SsSidebarList(右侧业务面板:人员/已选/服务/预定...)
  6758. *
  6759. * 用途:
  6760. * - 统一渲染面板 header(图标/标题/数量/右侧按钮)
  6761. * - 统一渲染 list(固定行高、hover、右侧移除按钮等)
  6762. *
  6763. * 调用示例(由 ss-sidebar 通过 panels 配置驱动):
  6764. * ```js
  6765. * { type:'list', title:'已选', iconClass:'menu-icon icon-obj-xcd', mode:'selected', items:selectedItems, closable:true }
  6766. * ```
  6767. *
  6768. * Props(核心):
  6769. * - `title`:header 标题
  6770. * - `iconClass/icon`:header 图标(优先 iconClass)
  6771. * - `count`:数量回显(图表面板可不传)
  6772. * - `closable`:是否显示“清空”按钮(触发 emit clear)
  6773. * - `headerFilters`:header 条件数组(组件名 + props),用于联调接口搜索
  6774. * - `headerSearchButton`:是否显示搜索按钮(触发 emit search)
  6775. * - `items`:列表数据
  6776. * - `mode`:`selected` 时右侧按钮语义为“移除”
  6777. * - `itemLayout`:`simple` / `person`(人员号槽位)
  6778. * - `itemAction`:是否显示 item 右侧操作按钮(hover 才出现)
  6779. *
  6780. * Emits:
  6781. * - `remove(item)`:点击 item 右侧移除
  6782. * - `clear()`:点击 header 清空
  6783. * - `search({keyword, filters})`:点击 header 搜索
  6784. */
  6785. const SsSidebarList = {
  6786. name: "SsSidebarList",
  6787. props: {
  6788. title: { type: String, default: "" },
  6789. // header 图标:优先使用 iconClass(走 ss-icon v3.0 class 分支) by xu 20260106
  6790. iconClass: { type: String, default: "" },
  6791. icon: { type: String, default: "" }, // 兼容旧写法(ss-icon name)
  6792. count: { type: [Number, String], default: "" },
  6793. // 选中类分区:右侧关闭按钮=清空分区数据 by xu 20260106
  6794. closable: { type: Boolean, default: false },
  6795. searchable: { type: Boolean, default: false },
  6796. // 搜索框是否放在 header 内(人员块需要该布局) by xu 20260106
  6797. searchInHeader: { type: Boolean, default: false },
  6798. // header 搜索:下拉条件 + 搜索按钮(适合“人员”块) by xu 20260106
  6799. headerFilters: { type: Array, default: () => [] },
  6800. headerSearchButton: { type: Boolean, default: false },
  6801. searchPlaceholder: { type: String, default: "搜索" },
  6802. // 列表项布局:simple(仅标题) / person(标题+人员号槽位) by xu 20260106
  6803. itemLayout: { type: String, default: "simple" },
  6804. itemAction: { type: Boolean, default: true },
  6805. collapsible: { type: Boolean, default: true }, // 功能说明:是否允许双击 header 折叠/展开 by xu 20260116
  6806. collapsed: { type: Boolean, default: false }, // 功能说明:折叠态仅展示 header by xu 20260116
  6807. items: { type: Array, default: () => [] },
  6808. mode: { type: String, default: "search" }, // search / selected
  6809. },
  6810. emits: ["select", "remove", "clear", "search", "toggle-collapse"],
  6811. data() {
  6812. return {
  6813. keyword: "",
  6814. filterValues: {},
  6815. }; // 功能说明:折叠状态完全由 props.collapsed 驱动,避免多面板复用导致状态不同步 by xu 20260116
  6816. },
  6817. created() {
  6818. // header 下拉条件默认值初始化 by xu 20260106
  6819. (this.headerFilters || []).forEach((f) => {
  6820. if (!f || !f.key) return;
  6821. if (this.filterValues[f.key] !== undefined) return;
  6822. const first = f?.options?.[0]?.value ?? "";
  6823. this.filterValues[f.key] = f.value !== undefined ? f.value : first;
  6824. });
  6825. },
  6826. methods: {
  6827. __shouldIgnoreHeaderToggle(e) {
  6828. // 功能说明:忽略工具区/输入区触发折叠,避免误触 by xu 20260116
  6829. const t = e?.target;
  6830. if (!t || !t.closest) return false;
  6831. if (t.closest(".ss-sidebar-panel__tools")) return true;
  6832. if (t.closest(".ss-sidebar-panel__filters")) return true;
  6833. if (t.closest("input,textarea,select,button")) return true;
  6834. return false;
  6835. },
  6836. __toggleCollapseInternal(e, source) {
  6837. if (!this.collapsible) return;
  6838. if (this.__shouldIgnoreHeaderToggle(e)) return;
  6839. const nextCollapsed = !this.collapsed;
  6840. console.log("[SsSidebarList] toggle emit", {
  6841. title: this.title,
  6842. source,
  6843. to: nextCollapsed,
  6844. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  6845. // 功能说明:由父组件(SsSidebar.toggleSectionCollapse)统一控制 section 高度与折叠数组 by xu 20260116
  6846. this.$emit("toggle-collapse");
  6847. },
  6848. },
  6849. render() {
  6850. const items = this.items || [];
  6851. const SsIcon = Vue.resolveComponent("ss-icon");
  6852. const isSelectedMode = this.mode === "selected";
  6853. const activeKeyword = this.filterValues?.keyword ?? this.keyword; // 功能:keyword 优先取 headerFilters.keyword by xu 20260106
  6854. const hasHeaderKeyword = (this.headerFilters || []).some(
  6855. (f) => f?.key === "keyword"
  6856. ); // 功能:header 内 keyword 过滤 by xu 20260106
  6857. const renderHeaderFilter = (f) => {
  6858. if (!f) return null;
  6859. const key = f.key;
  6860. const componentName = f.component;
  6861. if (!key || !componentName) return null;
  6862. const Comp = Vue.resolveComponent(componentName);
  6863. if (!Comp) return null;
  6864. const modelValue = this.filterValues[key];
  6865. const props = f.props || {};
  6866. return Vue.h(Comp, {
  6867. ...props,
  6868. modelValue,
  6869. "onUpdate:modelValue": (v) => {
  6870. this.filterValues[key] = v;
  6871. },
  6872. });
  6873. };
  6874. const filteredItems =
  6875. this.searchable && activeKeyword
  6876. ? items.filter((it) =>
  6877. String(it?.title ?? "")
  6878. .toLowerCase()
  6879. .includes(String(activeKeyword).toLowerCase())
  6880. )
  6881. : items;
  6882. if (!filteredItems.length && !this.title) return null;
  6883. if (this.collapsed) {
  6884. return Vue.h("div", { class: "ss-sidebar-panel" }, [
  6885. this.title
  6886. ? Vue.h(
  6887. "div",
  6888. {
  6889. class: "ss-sidebar-panel__header",
  6890. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  6891. onDblclick: (e) => {
  6892. e?.preventDefault?.();
  6893. e?.stopPropagation?.();
  6894. console.log("[SsSidebarList] header dblclick", {
  6895. title: this.title,
  6896. collapsed: true,
  6897. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  6898. this.__toggleCollapseInternal(e, "dblclick");
  6899. },
  6900. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  6901. },
  6902. [
  6903. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  6904. this.iconClass
  6905. ? Vue.h(SsIcon, {
  6906. class: this.iconClass + " ss-sidebar-panel__icon",
  6907. })
  6908. : this.icon
  6909. ? Vue.h(SsIcon, {
  6910. name: this.icon,
  6911. size: "16px",
  6912. class: "ss-sidebar-panel__icon",
  6913. })
  6914. : null,
  6915. Vue.h("span", null, this.title),
  6916. this.count !== ""
  6917. ? Vue.h(
  6918. "span",
  6919. { class: "ss-sidebar-panel__count" },
  6920. `(${this.count})`
  6921. )
  6922. : null,
  6923. ]),
  6924. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6925. this.closable
  6926. ? Vue.h(
  6927. "button",
  6928. {
  6929. type: "button",
  6930. class: "ss-sidebar-icon-btn ss-sidebar-header-btn",
  6931. title: "清空",
  6932. onClick: (e) => {
  6933. e.stopPropagation();
  6934. this.$emit("clear");
  6935. },
  6936. },
  6937. [
  6938. Vue.h(SsIcon, {
  6939. class: "ss-sidebar-base-icon icon-cl",
  6940. }),
  6941. ] // 功能说明:右侧栏“已选”清空按钮图标使用 ss-sidebar-base-icon by xu 20260123
  6942. )
  6943. : null,
  6944. ]),
  6945. ]
  6946. )
  6947. : null,
  6948. ]);
  6949. }
  6950. return Vue.h("div", { class: "ss-sidebar-panel" }, [
  6951. this.title
  6952. ? Vue.h(
  6953. "div",
  6954. {
  6955. class: "ss-sidebar-panel__header",
  6956. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  6957. onDblclick: (e) => {
  6958. e?.preventDefault?.();
  6959. e?.stopPropagation?.();
  6960. console.log("[SsSidebarList] header dblclick", {
  6961. title: this.title,
  6962. collapsed: false,
  6963. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  6964. this.__toggleCollapseInternal(e, "dblclick");
  6965. },
  6966. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  6967. },
  6968. [
  6969. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  6970. // 图标 + 标题(每个分区都有) by xu 20260106
  6971. this.iconClass
  6972. ? Vue.h(SsIcon, {
  6973. class: this.iconClass + " ss-sidebar-panel__icon",
  6974. })
  6975. : this.icon
  6976. ? Vue.h(SsIcon, {
  6977. name: this.icon,
  6978. size: "16px",
  6979. class: "ss-sidebar-panel__icon",
  6980. })
  6981. : null,
  6982. Vue.h("span", null, this.title),
  6983. // 数量回显:图表分区可不传 count by xu 20260106
  6984. this.count !== ""
  6985. ? Vue.h(
  6986. "span",
  6987. { class: "ss-sidebar-panel__count" },
  6988. `(${this.count})`
  6989. )
  6990. : null,
  6991. ]),
  6992. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6993. // header 条件(例如下拉框)+ 右侧搜索按钮 by xu 20260106
  6994. this.headerFilters?.length
  6995. ? Vue.h(
  6996. "div",
  6997. { class: "ss-sidebar-panel__filters" },
  6998. this.headerFilters
  6999. .map(renderHeaderFilter)
  7000. .filter(Boolean)
  7001. )
  7002. : null,
  7003. this.headerSearchButton
  7004. ? Vue.h(
  7005. "button",
  7006. {
  7007. type: "button",
  7008. class: "ss-sidebar-icon-btn",
  7009. title: "搜索",
  7010. onClick: (e) => {
  7011. e.stopPropagation();
  7012. this.$emit("search", {
  7013. // headerFilters 内也可能包含 keyword by xu 20260106
  7014. keyword: activeKeyword,
  7015. filters: { ...(this.filterValues || {}) },
  7016. });
  7017. },
  7018. },
  7019. [Vue.h(SsIcon, { name: "search", size: "14px" })]
  7020. )
  7021. : null,
  7022. // 人员块:搜索框在 header 内 by xu 20260106
  7023. this.searchable &&
  7024. this.searchInHeader &&
  7025. !this.headerSearchButton
  7026. ? Vue.h(
  7027. "div",
  7028. { class: "ss-sidebar-panel__searchInline" },
  7029. [
  7030. Vue.h(
  7031. "div",
  7032. { class: "ss-sidebar-search is-inline" },
  7033. [
  7034. Vue.h(SsIcon, {
  7035. name: "search",
  7036. size: "14px",
  7037. class: "ss-sidebar-search__prefix",
  7038. }),
  7039. Vue.h("input", {
  7040. class: "ss-sidebar-search__input",
  7041. value: this.keyword,
  7042. placeholder: this.searchPlaceholder,
  7043. onInput: (e) => {
  7044. this.keyword = e?.target?.value ?? "";
  7045. },
  7046. }),
  7047. ]
  7048. ),
  7049. ]
  7050. )
  7051. : null,
  7052. this.closable
  7053. ? Vue.h(
  7054. "button",
  7055. {
  7056. type: "button",
  7057. class: "ss-sidebar-icon-btn ss-sidebar-header-btn",
  7058. title: "清空",
  7059. onClick: (e) => {
  7060. e.stopPropagation();
  7061. this.$emit("clear");
  7062. },
  7063. },
  7064. // 清空按钮使用 icon-base 的 icon-cl by xu 20260106
  7065. [
  7066. Vue.h(SsIcon, {
  7067. class: "ss-sidebar-base-icon icon-cl",
  7068. }),
  7069. ] // 功能说明:右侧栏清空按钮图标使用 ss-sidebar-base-icon by xu 20260123
  7070. )
  7071. : null,
  7072. ]),
  7073. ]
  7074. )
  7075. : null,
  7076. // 非 header 内搜索:独立一行 by xu 20260106
  7077. // headerSearchButton/headerFilters 已覆盖搜索能力时,不再额外渲染独立搜索行 by xu 20260106
  7078. this.searchable &&
  7079. !this.searchInHeader &&
  7080. !this.headerSearchButton &&
  7081. !hasHeaderKeyword
  7082. ? Vue.h("div", { class: "ss-sidebar-panel__search" }, [
  7083. Vue.h("div", { class: "ss-sidebar-search" }, [
  7084. Vue.h(SsIcon, {
  7085. name: "search",
  7086. size: "14px",
  7087. class: "ss-sidebar-search__prefix",
  7088. }),
  7089. Vue.h("input", {
  7090. class: "ss-sidebar-search__input",
  7091. value: this.keyword,
  7092. placeholder: this.searchPlaceholder,
  7093. onInput: (e) => {
  7094. this.keyword = e?.target?.value ?? "";
  7095. },
  7096. }),
  7097. ]),
  7098. ])
  7099. : null,
  7100. Vue.h(
  7101. "div",
  7102. { class: "ss-sidebar-list" },
  7103. filteredItems.map((item, idx) => {
  7104. const title = item?.title ?? "";
  7105. const tags = item?.tags || [];
  7106. const isPersonLayout = this.itemLayout === "person";
  7107. const hasTags = !isPersonLayout && tags?.length > 0; // 列表项垂直对齐:有 tags 顶对齐 by xu 20260106
  7108. return Vue.h(
  7109. "div",
  7110. {
  7111. class: {
  7112. "ss-sidebar-list-item": true,
  7113. "is-first": idx === 0,
  7114. "is-person": isPersonLayout,
  7115. "has-tags": hasTags,
  7116. },
  7117. },
  7118. [
  7119. Vue.h("div", { class: "ss-sidebar-list-item__main" }, [
  7120. Vue.h(
  7121. "div",
  7122. { class: "ss-sidebar-list-item__title" },
  7123. Vue.h(
  7124. "span",
  7125. {
  7126. style: {
  7127. "white-space": "nowrap",
  7128. overflow: "hidden",
  7129. "text-overflow": "ellipsis",
  7130. },
  7131. },
  7132. title
  7133. )
  7134. ),
  7135. // 非人员布局才显示 tags by xu 20260106
  7136. !isPersonLayout && tags?.length
  7137. ? Vue.h(
  7138. "div",
  7139. { class: "ss-sidebar-list-item__tags" },
  7140. tags.map((tag) => {
  7141. const [k, v] = Object.entries(tag)[0] || ["", ""];
  7142. return Vue.h(
  7143. "span",
  7144. { class: "ss-sidebar-tag", title: `${k}: ${v}` },
  7145. `${k}: ${v}`
  7146. );
  7147. })
  7148. )
  7149. : null,
  7150. ]),
  7151. // 人员布局:中间保留“人员号”槽位 by xu 20260106
  7152. isPersonLayout
  7153. ? Vue.h(
  7154. "div",
  7155. {
  7156. class: "ss-sidebar-list-item__meta",
  7157. title: String(item?.meta ?? ""),
  7158. },
  7159. item?.meta ?? ""
  7160. )
  7161. : null,
  7162. this.itemAction
  7163. ? Vue.h(
  7164. "button",
  7165. {
  7166. type: "button",
  7167. class: {
  7168. // item 操作按钮:默认无背景/无边框,hover 才高亮 by xu 20260106
  7169. "ss-sidebar-item-btn": true,
  7170. },
  7171. title: isSelectedMode ? "移除" : "选择",
  7172. onClick: (e) => {
  7173. e.stopPropagation();
  7174. if (isSelectedMode) this.$emit("remove", item);
  7175. else this.$emit("select", item);
  7176. },
  7177. },
  7178. [
  7179. // item 移除图标使用 icon-base 的 icon-cl by xu 20260106
  7180. isSelectedMode
  7181. ? Vue.h(SsIcon, {
  7182. class: "ss-sidebar-base-icon icon-cl",
  7183. }) // 功能说明:右侧栏 item 移除图标使用 ss-sidebar-base-icon by xu 20260123
  7184. : Vue.h(SsIcon, { name: "check", size: "14px" }),
  7185. ]
  7186. )
  7187. : null,
  7188. ]
  7189. );
  7190. })
  7191. ),
  7192. ]);
  7193. },
  7194. };
  7195. // ss-sidebar-report-table:右侧“统计表/报表”面板(pstatList grtjlbm=51 聚拢渲染) by xu 20260115
  7196. const SsSidebarReportTable = {
  7197. name: "SsSidebarReportTable",
  7198. props: {
  7199. title: { type: String, default: "" },
  7200. iconClass: { type: String, default: "" },
  7201. icon: { type: String, default: "" },
  7202. items: { type: Array, default: () => [] }, // pstatList(grtjlbm=51) 数组
  7203. onOpen: { type: Function, default: null }, // (srv, ctx) => void
  7204. collapsible: { type: Boolean, default: true }, // 功能说明:是否允许双击 header 折叠/展开 by xu 20260116
  7205. collapsed: { type: Boolean, default: false }, // 功能说明:折叠态仅展示 header by xu 20260116
  7206. },
  7207. emits: ["open", "toggle-collapse"],
  7208. data() {
  7209. return {}; // 功能说明:折叠状态完全由 props.collapsed 驱动 by xu 20260116
  7210. },
  7211. methods: {
  7212. __toggleCollapseInternal(e, source) {
  7213. if (!this.collapsible) return;
  7214. const next = !this.collapsed;
  7215. console.log("[SsSidebarReportTable] toggle emit", {
  7216. title: this.title,
  7217. source,
  7218. to: next,
  7219. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7220. this.$emit("toggle-collapse");
  7221. },
  7222. },
  7223. render() {
  7224. const SsIcon = Vue.resolveComponent("ss-icon");
  7225. const list = this.items || [];
  7226. if (!this.title && !list.length) return null;
  7227. const header = this.title
  7228. ? Vue.h(
  7229. "div",
  7230. {
  7231. class: "ss-sidebar-panel__header",
  7232. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  7233. onDblclick: (e) => {
  7234. e?.preventDefault?.();
  7235. e?.stopPropagation?.();
  7236. console.log("[SsSidebarReportTable] header dblclick", {
  7237. title: this.title,
  7238. collapsed: this.collapsed,
  7239. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7240. this.__toggleCollapseInternal(e, "dblclick");
  7241. },
  7242. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  7243. },
  7244. [
  7245. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7246. this.iconClass
  7247. ? Vue.h(SsIcon, {
  7248. class: this.iconClass + " ss-sidebar-panel__icon",
  7249. })
  7250. : this.icon
  7251. ? Vue.h(SsIcon, {
  7252. name: this.icon,
  7253. size: "16px",
  7254. class: "ss-sidebar-panel__icon",
  7255. })
  7256. : null,
  7257. Vue.h("span", null, this.title),
  7258. ]),
  7259. Vue.h("div", { class: "ss-sidebar-panel__tools" }),
  7260. ]
  7261. )
  7262. : null;
  7263. const renderReport = (report) => {
  7264. const title = String(report?.mc ?? "");
  7265. const mx = Array.isArray(report?.grtjmxList) ? report.grtjmxList : [];
  7266. if (!title && !mx.length) return null;
  7267. // 功能说明:每个报表对象渲染为一个 table(有边框、无圆角、表间距10px;样式由 base.css 统一控制) by xu 20260115
  7268. const cols = Math.max(1, mx.length);
  7269. // 功能说明:table 外层包一层 wrap,子项过多时支持横向滚动 by xu 20260115
  7270. return Vue.h("div", { class: "ss-sidebar-report-table-wrap" }, [
  7271. Vue.h("table", { class: "ss-sidebar-report-table" }, [
  7272. Vue.h("thead", null, [
  7273. Vue.h("tr", null, [
  7274. Vue.h(
  7275. "th",
  7276. { class: "ss-sidebar-report-table__title", colspan: cols },
  7277. Vue.h(
  7278. "div",
  7279. { class: "ss-sidebar-report-table__title-content" },
  7280. [
  7281. Vue.h("span", { class: "ss-sidebar-report-table__dot" }),
  7282. Vue.h(
  7283. "span",
  7284. { class: "ss-sidebar-report-table__title-text", title },
  7285. title
  7286. ),
  7287. ]
  7288. )
  7289. ),
  7290. ]),
  7291. ]),
  7292. Vue.h("tbody", null, [
  7293. Vue.h(
  7294. "tr",
  7295. null,
  7296. mx.map((cell) => {
  7297. const text = String(cell?.mc ?? "");
  7298. const srv = {
  7299. servName: cell?.fwm ?? "",
  7300. dest: cell?.bjm ?? "",
  7301. title: text,
  7302. width: cell?.width,
  7303. height: cell?.height,
  7304. minHeight: cell?.height,
  7305. maxHeight: cell?.height,
  7306. showTitle: text,
  7307. };
  7308. return Vue.h(
  7309. "td",
  7310. {
  7311. class: "ss-sidebar-report-table__cell",
  7312. title: text,
  7313. onClick: (e) => {
  7314. e?.stopPropagation?.();
  7315. try {
  7316. this.onOpen?.(srv, { report, cell });
  7317. } catch (_) {}
  7318. this.$emit("open", { report, cell, srv });
  7319. },
  7320. },
  7321. text
  7322. );
  7323. })
  7324. ),
  7325. ]),
  7326. ]),
  7327. ]);
  7328. };
  7329. // 功能说明:报表面板增加独立 class,便于 base.css 统一控制 padding/间距 by xu 20260115
  7330. return Vue.h(
  7331. "div",
  7332. { class: "ss-sidebar-panel ss-sidebar-report-panel" },
  7333. [
  7334. header,
  7335. this.collapsed
  7336. ? null
  7337. : Vue.h(
  7338. "div",
  7339. // 功能说明:报表列表滚动/高度样式下沉到 base.css,避免写在 DOM 上 by xu 20260115
  7340. { class: "ss-sidebar-report__list" },
  7341. list.map(renderReport).filter(Boolean)
  7342. ),
  7343. ]
  7344. );
  7345. },
  7346. };
  7347. // 组件文档补全(JSDoc) by xu 20260108
  7348. /**
  7349. * SsSidebar(objList 右侧边栏容器)
  7350. *
  7351. * 用途:
  7352. * - 统一渲染顶部按钮栏(buttons)
  7353. * - 统一渲染中间业务面板(list panels,可拖拽调高度)
  7354. * - 统一渲染底部图表(chart panels,内部用 ss-sidebar-chart-hover)
  7355. *
  7356. * 调用示例:
  7357. * ```html
  7358. * <ss-sidebar :buttons="sidebarButtons" :panels="sidebarPanels" @remove="handleSidebarRemove" />
  7359. * ```
  7360. *
  7361. * Props:
  7362. * - `buttons`:顶部按钮配置数组
  7363. * - `panels`:分区配置数组(`type: 'list' | 'chart'`)
  7364. *
  7365. * Events(向外透传):
  7366. * - `remove(item)`:来自 list 面板移除
  7367. * - `select(item)`:来自 list 面板选择(如后续需要)
  7368. */
  7369. const SsSidebar = {
  7370. name: "SsSidebar",
  7371. props: {
  7372. buttons: { type: Array, default: () => [] },
  7373. charts: { type: Array, default: () => [] },
  7374. list: { type: Array, default: () => [] }, // legacy
  7375. listMode: { type: String, default: "search" }, // legacy
  7376. panels: { type: Array, default: () => [] },
  7377. },
  7378. emits: ["select", "remove"],
  7379. data() {
  7380. return {
  7381. // 业务面板高度(索引 -> px) by xu 20260106
  7382. sectionHeights: [],
  7383. sectionCollapsed: [], // 功能说明:面板折叠状态(sectionPanels 索引) by xu 20260116
  7384. sectionHeightsExpanded: [], // 功能说明:面板展开高度缓存(用于折叠后恢复) by xu 20260116
  7385. sectionLastItemCounts: [], // 功能说明:记录栏目数据量,供“无数据默认关闭/已选自动展开”规则复用 by xu 20260313
  7386. chartCollapsed: [], // 功能说明:图表面板折叠状态(chartPanels 索引) by xu 20260116
  7387. chartHeaderTitleDownAt: [], // 功能说明:双击检测绑定到 chart 标题区 by xu 20260116
  7388. reportCollapsed: [], // 功能说明:报表面板折叠状态(reportPanels 索引) by xu 20260116
  7389. resizeTimer: null,
  7390. resizing: false,
  7391. resizeIndex: -1,
  7392. resizeStartY: 0,
  7393. resizeStartPrev: 0,
  7394. resizeStartNext: 0,
  7395. __resizeMoveHandler: null, // 功能说明:显式绑定 this 的 pointermove handler,避免 addEventListener 场景 this 丢失导致拖拽无效 by xu 20260122
  7396. __resizeEndHandler: null, // 功能说明:显式绑定 this 的 pointerup handler,确保能正确结束拖拽 by xu 20260122
  7397. __resizeCancelHandler: null, // 功能说明:显式绑定 this 的 pointercancel handler,触控取消也能收尾 by xu 20260122
  7398. __resizePrevSectionEl: null, // 功能说明:拖拽时直接写 DOM 高度(修复响应式更新不生效) by xu 20260122
  7399. __resizeNextSectionEl: null, // 功能说明:拖拽时直接写 DOM 高度(修复响应式更新不生效) by xu 20260122
  7400. };
  7401. },
  7402. methods: {
  7403. // 初始化默认高度(只在第一次/面板数量变化时补齐) by xu 20260106
  7404. ensureSectionHeights(sectionCount) {
  7405. if (!Array.isArray(this.sectionHeights)) this.sectionHeights = [];
  7406. if (this.sectionHeights.length === sectionCount) return;
  7407. const next = [];
  7408. for (let i = 0; i < sectionCount; i++) {
  7409. next[i] = this.sectionHeights[i] ?? 190; // 默认高度 by xu 20260106
  7410. }
  7411. this.sectionHeights = next;
  7412. // 功能说明:面板数量变化时补齐折叠/缓存数组长度 by xu 20260116
  7413. this.sectionCollapsed = Array.from(
  7414. { length: sectionCount },
  7415. (_, i) => !!this.sectionCollapsed?.[i]
  7416. );
  7417. this.sectionHeightsExpanded = Array.from(
  7418. { length: sectionCount },
  7419. (_, i) => this.sectionHeightsExpanded?.[i] ?? null
  7420. );
  7421. this.sectionLastItemCounts = Array.from(
  7422. { length: sectionCount },
  7423. (_, i) => Number(this.sectionLastItemCounts?.[i] ?? 0) || 0
  7424. );
  7425. },
  7426. __getPanelsForSectionState(panelsInput) {
  7427. return (panelsInput || []).length
  7428. ? panelsInput
  7429. : this.list?.length
  7430. ? [
  7431. {
  7432. type: "list",
  7433. title: "已选",
  7434. icon: "",
  7435. mode: this.listMode,
  7436. items: this.list,
  7437. },
  7438. ]
  7439. : [];
  7440. },
  7441. __getSectionPanelsForState(panelsInput) {
  7442. return this.__getPanelsForSectionState(panelsInput)
  7443. .filter((p) => {
  7444. const k = String(p?._tabKey ?? "")
  7445. .trim()
  7446. .toLowerCase();
  7447. const t = String(p?.title ?? "").trim();
  7448. if (k === "rbarobj") return false;
  7449. if (t === "对象") return false;
  7450. return true;
  7451. })
  7452. .filter((p) => p?.type !== "chart" && p?.type !== "report-table");
  7453. },
  7454. __getSectionPanelCount(panel) {
  7455. const explicitCount = Number(panel?.count);
  7456. if (Number.isFinite(explicitCount)) return explicitCount;
  7457. return Array.isArray(panel?.items) ? panel.items.length : 0;
  7458. },
  7459. __setSectionCollapsedState(index, collapsed) {
  7460. const i = Number(index);
  7461. if (isNaN(i) || i < 0) return;
  7462. const nextCollapsed = !!collapsed;
  7463. const collapsedHeight = 37;
  7464. const cur = !!this.sectionCollapsed?.[i];
  7465. const currentHeight = Number(this.sectionHeights?.[i] ?? 190) || 190;
  7466. if (nextCollapsed === cur) {
  7467. if (nextCollapsed && currentHeight !== collapsedHeight) {
  7468. this.sectionHeights.splice(i, 1, collapsedHeight);
  7469. }
  7470. return;
  7471. }
  7472. if (nextCollapsed) {
  7473. this.sectionHeightsExpanded[i] =
  7474. currentHeight > collapsedHeight
  7475. ? currentHeight
  7476. : Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  7477. this.sectionHeights.splice(i, 1, collapsedHeight);
  7478. } else {
  7479. const restore =
  7480. Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  7481. this.sectionHeights.splice(i, 1, restore);
  7482. }
  7483. this.sectionCollapsed.splice(i, 1, nextCollapsed);
  7484. },
  7485. __syncSectionAutoCollapse(panelsInput) {
  7486. const sectionPanels = this.__getSectionPanelsForState(panelsInput);
  7487. const sectionCount = sectionPanels.length;
  7488. this.ensureSectionHeights(sectionCount);
  7489. const prevCounts = Array.isArray(this.sectionLastItemCounts)
  7490. ? this.sectionLastItemCounts.slice()
  7491. : [];
  7492. const nextCounts = Array.from({ length: sectionCount }, (_, i) =>
  7493. this.__getSectionPanelCount(sectionPanels[i])
  7494. );
  7495. this.sectionLastItemCounts = nextCounts;
  7496. sectionPanels.forEach((panel, index) => {
  7497. const count = Number(nextCounts[index] ?? 0) || 0;
  7498. const prevCount = Number(prevCounts[index] ?? 0) || 0;
  7499. const title = String(panel?.title ?? "").trim();
  7500. if (count <= 0) {
  7501. this.__setSectionCollapsedState(index, true);
  7502. return;
  7503. }
  7504. if (title === "已选" && count > prevCount) {
  7505. this.__setSectionCollapsedState(index, false);
  7506. }
  7507. });
  7508. },
  7509. toggleSectionCollapse(index) {
  7510. // 功能说明:双击 header 折叠/展开 section 面板(仅控制高度与内容渲染) by xu 20260116
  7511. const i = Number(index);
  7512. if (isNaN(i) || i < 0) return;
  7513. // 功能说明:加更细粒度日志,定位“多面板折叠无视觉效果”的根因(高度是否真的变、DOM 是否更新) by xu 20260116
  7514. const collapsedHeight = 37; // 功能说明:header(35) + panel 边框(2),避免 flex shrink 导致 header 变 25px by xu 20260116
  7515. const cur = !!this.sectionCollapsed?.[i];
  7516. console.log("[SsSidebar] toggleSectionCollapse", {
  7517. index: i,
  7518. to: !cur,
  7519. prevHeight: this.sectionHeights?.[i],
  7520. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7521. if (!cur) {
  7522. this.sectionHeightsExpanded[i] = this.sectionHeights[i] ?? 190;
  7523. this.sectionHeights.splice(i, 1, collapsedHeight);
  7524. } else {
  7525. const restore =
  7526. Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  7527. this.sectionHeights.splice(i, 1, restore);
  7528. }
  7529. this.sectionCollapsed.splice(i, 1, !cur);
  7530. console.log("[SsSidebar] section state(after)", {
  7531. index: i,
  7532. height: this.sectionHeights?.[i],
  7533. collapsed: this.sectionCollapsed?.[i],
  7534. allHeights: Array.from(this.sectionHeights || []),
  7535. allCollapsed: Array.from(this.sectionCollapsed || []),
  7536. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7537. Vue.nextTick(() => {
  7538. try {
  7539. const root = this.$el;
  7540. const sections = root?.querySelectorAll?.(".ss-sidebar-section");
  7541. const el = sections?.[i];
  7542. const rectH = el?.getBoundingClientRect?.().height;
  7543. console.log("[SsSidebar] section dom(beforeFix)", {
  7544. index: i,
  7545. styleHeight: el?.style?.height,
  7546. rectH,
  7547. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7548. // 功能说明:若渲染未把 height patch 到 DOM,则在 nextTick 强制同步一次(并打印) by xu 20260116
  7549. const targetH =
  7550. (Number(this.sectionHeights?.[i] ?? 190) || 190) + "px";
  7551. if (el && el.style && el.style.height !== targetH) {
  7552. el.style.height = targetH;
  7553. }
  7554. if (el?.classList) {
  7555. el.classList.toggle("is-collapsed", !!this.sectionCollapsed?.[i]);
  7556. }
  7557. const rectAfter = el?.getBoundingClientRect?.().height;
  7558. console.log("[SsSidebar] section dom(afterFix)", {
  7559. index: i,
  7560. styleHeight: el?.style?.height,
  7561. rectH: rectAfter,
  7562. targetH,
  7563. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7564. } catch (err) {
  7565. console.log("[SsSidebar] section dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7566. }
  7567. });
  7568. },
  7569. toggleChartCollapse(index) {
  7570. // 功能说明:双击 header 折叠/展开底部 chart 面板(隐藏/显示 chart-hover) by xu 20260116
  7571. const i = Number(index);
  7572. if (isNaN(i) || i < 0) return;
  7573. const cur = !!this.chartCollapsed?.[i];
  7574. console.log("[SsSidebar] toggleChartCollapse", { index: i, to: !cur }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7575. this.chartCollapsed.splice(i, 1, !cur);
  7576. console.log("[SsSidebar] chart state(after)", {
  7577. index: i,
  7578. collapsed: this.chartCollapsed?.[i],
  7579. allCollapsed: Array.from(this.chartCollapsed || []),
  7580. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7581. Vue.nextTick(() => {
  7582. try {
  7583. const root = this.$el;
  7584. const el = root?.querySelector?.(
  7585. `.ss-sidebar-chart-panel[data-chart-idx="${i}"]`
  7586. );
  7587. console.log("[SsSidebar] chart dom(beforeFix)", {
  7588. index: i,
  7589. found: !!el,
  7590. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7591. if (el?.classList)
  7592. el.classList.toggle("is-collapsed", !!this.chartCollapsed?.[i]);
  7593. console.log("[SsSidebar] chart dom(afterFix)", {
  7594. index: i,
  7595. collapsed: !!this.chartCollapsed?.[i],
  7596. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7597. } catch (err) {
  7598. console.log("[SsSidebar] chart dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7599. }
  7600. });
  7601. },
  7602. toggleReportCollapse(index) {
  7603. // 功能说明:双击 header 折叠/展开底部 report-table 面板(隐藏/显示表格) by xu 20260116
  7604. const i = Number(index);
  7605. if (isNaN(i) || i < 0) return;
  7606. const cur = !!this.reportCollapsed?.[i];
  7607. console.log("[SsSidebar] toggleReportCollapse", { index: i, to: !cur }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7608. this.reportCollapsed.splice(i, 1, !cur);
  7609. console.log("[SsSidebar] report state(after)", {
  7610. index: i,
  7611. collapsed: this.reportCollapsed?.[i],
  7612. allCollapsed: Array.from(this.reportCollapsed || []),
  7613. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7614. Vue.nextTick(() => {
  7615. try {
  7616. const root = this.$el;
  7617. const el = root?.querySelector?.(
  7618. `.ss-sidebar-report-panel[data-report-idx="${i}"]`
  7619. );
  7620. console.log("[SsSidebar] report dom(beforeFix)", {
  7621. index: i,
  7622. found: !!el,
  7623. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7624. if (el?.classList)
  7625. el.classList.toggle("is-collapsed", !!this.reportCollapsed?.[i]);
  7626. console.log("[SsSidebar] report dom(afterFix)", {
  7627. index: i,
  7628. collapsed: !!this.reportCollapsed?.[i],
  7629. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7630. } catch (err) {
  7631. console.log("[SsSidebar] report dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7632. }
  7633. });
  7634. },
  7635. startResize(index, e) {
  7636. if (e?.preventDefault) e.preventDefault();
  7637. if (e?.stopPropagation) e.stopPropagation();
  7638. if (this.resizing) return;
  7639. // 长按 0.5s 后才进入拖拽调高度 by xu 20260106
  7640. clearTimeout(this.resizeTimer);
  7641. // 功能说明:修复“长按拖拽偶发失效/卡死”——pointerup 早于 500ms 时必须取消 timer,否则 timer 触发后进入 resizing=true 且再也收不到 pointerup,导致后续都无法拖拽 by xu 20260122
  7642. const pointerId = e?.pointerId;
  7643. const cancelPendingResize = (ev) => {
  7644. try {
  7645. if (
  7646. pointerId != null &&
  7647. ev?.pointerId != null &&
  7648. ev.pointerId !== pointerId
  7649. )
  7650. return;
  7651. } catch (_) {}
  7652. clearTimeout(this.resizeTimer);
  7653. this.resizeTimer = null;
  7654. document.removeEventListener("pointerup", cancelPendingResize, true);
  7655. document.removeEventListener(
  7656. "pointercancel",
  7657. cancelPendingResize,
  7658. true
  7659. );
  7660. };
  7661. // 功能说明:用 document+capture 监听,避免 window 监听在部分容器/iframe 场景丢事件导致拖拽无响应 by xu 20260122
  7662. document.addEventListener("pointerup", cancelPendingResize, {
  7663. passive: false,
  7664. once: true,
  7665. capture: true,
  7666. });
  7667. document.addEventListener("pointercancel", cancelPendingResize, {
  7668. passive: false,
  7669. once: true,
  7670. capture: true,
  7671. });
  7672. const startY = e?.clientY ?? 0;
  7673. const gapEl = e?.currentTarget;
  7674. // 功能说明:记录 gap 前后 section 节点,拖拽过程中直接写入 style.height,避免某些环境下 Vue render 不刷新导致“拖拽无视觉变化” by xu 20260122
  7675. this.__resizePrevSectionEl = gapEl?.previousElementSibling || null;
  7676. this.__resizeNextSectionEl = gapEl?.nextElementSibling || null;
  7677. this.resizeTimer = setTimeout(() => {
  7678. // 定时器触发后进入拖拽态,移除“取消等待”监听,避免误取消 by xu 20260122
  7679. document.removeEventListener("pointerup", cancelPendingResize, true);
  7680. document.removeEventListener(
  7681. "pointercancel",
  7682. cancelPendingResize,
  7683. true
  7684. );
  7685. this.resizing = true;
  7686. this.resizeIndex = index;
  7687. this.resizeStartY = startY;
  7688. this.resizeStartPrev = this.sectionHeights[index] ?? 190;
  7689. this.resizeStartNext = this.sectionHeights[index + 1] ?? 190;
  7690. gapEl?.classList?.add("is-active");
  7691. try {
  7692. if (gapEl?.setPointerCapture && pointerId != null)
  7693. gapEl.setPointerCapture(pointerId);
  7694. } catch (_) {} // 功能说明:捕获 pointer,避免拖拽过程中移出窗口导致 pointermove 丢失 by xu 20260122
  7695. // 功能说明:用 document+capture,确保拖拽时 pointermove/up 不会被中途 stopPropagation 影响 by xu 20260122
  7696. document.addEventListener(
  7697. "pointermove",
  7698. this.__resizeMoveHandler || this.onResizeMove,
  7699. { passive: false, capture: true }
  7700. );
  7701. document.addEventListener(
  7702. "pointerup",
  7703. this.__resizeEndHandler || this.endResize,
  7704. { passive: false, once: true, capture: true }
  7705. );
  7706. document.addEventListener(
  7707. "pointercancel",
  7708. this.__resizeCancelHandler || this.endResize,
  7709. { passive: false, once: true, capture: true }
  7710. ); // 功能说明:触控/手势取消时也要结束拖拽 by xu 20260122
  7711. }, 500);
  7712. },
  7713. onResizeMove(e) {
  7714. if (!this.resizing) return;
  7715. if (e?.preventDefault) e.preventDefault();
  7716. const dy = (e?.clientY ?? 0) - this.resizeStartY;
  7717. const minPanelHeight = 83; // header(35) + listMin(48) by xu 20260106
  7718. const prev = Math.max(minPanelHeight, this.resizeStartPrev + dy);
  7719. const next = Math.max(minPanelHeight, this.resizeStartNext - dy);
  7720. // 若其中一个达到最小值,则停止继续挤压 by xu 20260106
  7721. const adjustedDy = prev - this.resizeStartPrev;
  7722. const nextAdjusted = this.resizeStartNext - adjustedDy;
  7723. const appliedPrev = prev;
  7724. const appliedNext = Math.max(minPanelHeight, nextAdjusted);
  7725. this.sectionHeights.splice(this.resizeIndex, 1, appliedPrev);
  7726. this.sectionHeights.splice(this.resizeIndex + 1, 1, appliedNext);
  7727. // 功能说明:强制触发一次 sectionHeights 引用变化,避免某些运行时环境下 splice 未触发视图更新导致“拖拽没反应” by xu 20260122
  7728. this.sectionHeights = (this.sectionHeights || []).slice();
  7729. // 功能说明:兜底——直接写 DOM 的 height,确保视觉立即响应(用于排查/修复某些环境下 render 不更新) by xu 20260122
  7730. try {
  7731. if (this.__resizePrevSectionEl?.style)
  7732. this.__resizePrevSectionEl.style.height = appliedPrev + "px";
  7733. if (this.__resizeNextSectionEl?.style)
  7734. this.__resizeNextSectionEl.style.height = appliedNext + "px";
  7735. } catch (_) {}
  7736. },
  7737. endResize(e) {
  7738. clearTimeout(this.resizeTimer);
  7739. this.resizeTimer = null;
  7740. if (!this.resizing) return;
  7741. if (e?.preventDefault) e.preventDefault();
  7742. const activeGaps = document.querySelectorAll(
  7743. ".ss-sidebar-gap.is-active"
  7744. );
  7745. activeGaps.forEach((g) => g.classList.remove("is-active"));
  7746. this.resizing = false;
  7747. this.resizeIndex = -1;
  7748. this.__resizePrevSectionEl = null; // 功能说明:释放 DOM 引用,避免内存泄漏 by xu 20260122
  7749. this.__resizeNextSectionEl = null; // 功能说明:释放 DOM 引用,避免内存泄漏 by xu 20260122
  7750. document.removeEventListener(
  7751. "pointermove",
  7752. this.__resizeMoveHandler || this.onResizeMove,
  7753. true
  7754. );
  7755. document.removeEventListener(
  7756. "pointercancel",
  7757. this.__resizeCancelHandler || this.endResize,
  7758. true
  7759. ); // 功能说明:清理 cancel 监听,避免残留 by xu 20260122
  7760. },
  7761. },
  7762. watch: {
  7763. panels: {
  7764. handler(nextPanels) {
  7765. this.__syncSectionAutoCollapse(nextPanels);
  7766. },
  7767. deep: true,
  7768. immediate: true,
  7769. },
  7770. list: {
  7771. handler(nextList) {
  7772. if ((this.panels || []).length) return;
  7773. this.__syncSectionAutoCollapse(nextList);
  7774. },
  7775. deep: true,
  7776. immediate: true,
  7777. },
  7778. },
  7779. mounted() {
  7780. clearTimeout(this.resizeTimer);
  7781. this.resizeTimer = null;
  7782. // 功能说明:绑定拖拽事件 handler(用于 add/removeEventListener) by xu 20260122
  7783. if (!this.__resizeMoveHandler)
  7784. this.__resizeMoveHandler = (e) => this.onResizeMove?.(e);
  7785. if (!this.__resizeEndHandler)
  7786. this.__resizeEndHandler = (e) => this.endResize?.(e);
  7787. if (!this.__resizeCancelHandler)
  7788. this.__resizeCancelHandler = (e) => this.endResize?.(e);
  7789. // 功能说明:暂时回退为固定底部留白方案(CSS 控制),后续再定位遮挡根因 by xu 20260115
  7790. },
  7791. beforeUnmount() {
  7792. clearTimeout(this.resizeTimer);
  7793. this.resizeTimer = null;
  7794. document.removeEventListener(
  7795. "pointermove",
  7796. this.__resizeMoveHandler || this.onResizeMove,
  7797. true
  7798. );
  7799. document.removeEventListener(
  7800. "pointerup",
  7801. this.__resizeEndHandler || this.endResize,
  7802. true
  7803. );
  7804. document.removeEventListener(
  7805. "pointercancel",
  7806. this.__resizeCancelHandler || this.endResize,
  7807. true
  7808. );
  7809. },
  7810. render() {
  7811. const SsSidebarButtonsComp = Vue.resolveComponent("ss-sidebar-buttons");
  7812. const SsSidebarChartComp = Vue.resolveComponent("ss-sidebar-chart");
  7813. const SsSidebarListComp = Vue.resolveComponent("ss-sidebar-list");
  7814. const SsSidebarReportTableComp = Vue.resolveComponent(
  7815. "ss-sidebar-report-table"
  7816. );
  7817. const SsIcon = Vue.resolveComponent("ss-icon");
  7818. // 支持 panels(多分区),list/listMode 作为 legacy 兜底 by xu 20260106
  7819. const panels = (this.panels || []).length
  7820. ? this.panels
  7821. : this.list?.length
  7822. ? [
  7823. {
  7824. type: "list",
  7825. title: "已选",
  7826. icon: "",
  7827. mode: this.listMode,
  7828. items: this.list,
  7829. },
  7830. ]
  7831. : [];
  7832. // 功能说明:右侧栏强制移除“对象”tab(兼容后端返回 rbarObj/rbarobj 或直接返回中文“对象”标题) by xu 20260116
  7833. const panelsNoObj = (panels || []).filter((p) => {
  7834. const k = String(p?._tabKey ?? "")
  7835. .trim()
  7836. .toLowerCase();
  7837. const t = String(p?.title ?? "").trim();
  7838. if (k === "rbarobj") return false;
  7839. if (t === "对象") return false;
  7840. return true;
  7841. });
  7842. // 功能说明:report-table 作为底部报表区(放在统计图下面),不参与可拖拽 section 面板 by xu 20260115
  7843. const sectionPanels = panelsNoObj.filter(
  7844. (p) => p?.type !== "chart" && p?.type !== "report-table"
  7845. );
  7846. const chartPanels = panelsNoObj.filter((p) => p?.type === "chart");
  7847. const reportPanels = panelsNoObj.filter(
  7848. (p) => p?.type === "report-table"
  7849. );
  7850. this.ensureSectionHeights(sectionPanels.length);
  7851. // 功能说明:补齐 chart/report 折叠数组长度 by xu 20260116
  7852. this.chartCollapsed = Array.from(
  7853. { length: chartPanels.length },
  7854. (_, i) => !!this.chartCollapsed?.[i]
  7855. );
  7856. this.chartHeaderTitleDownAt = Array.from(
  7857. { length: chartPanels.length },
  7858. (_, i) => this.chartHeaderTitleDownAt?.[i] ?? 0
  7859. );
  7860. this.reportCollapsed = Array.from(
  7861. { length: reportPanels.length },
  7862. (_, i) => !!this.reportCollapsed?.[i]
  7863. );
  7864. return Vue.h("div", { class: "ss-sidebar" }, [
  7865. this.buttons?.length
  7866. ? Vue.h(SsSidebarButtonsComp, { items: this.buttons })
  7867. : null,
  7868. Vue.h(
  7869. "div",
  7870. { class: "ss-sidebar__inner" },
  7871. [
  7872. ...(this.charts || []).map((c) =>
  7873. Vue.h(SsSidebarChartComp, {
  7874. options: c?.options || {},
  7875. height: c?.height || "200px",
  7876. })
  7877. ),
  7878. // 可拖拽的业务面板容器 by xu 20260106
  7879. Vue.h(
  7880. "div",
  7881. { class: "ss-sidebar-sections", style: { flex: "0 0 auto" } },
  7882. sectionPanels.flatMap((p, idx) => {
  7883. const panelContent =
  7884. p?.type === "report-table"
  7885. ? Vue.h(SsSidebarReportTableComp, {
  7886. key: `ss-sidebar-report-in-section-${idx}-${
  7887. p?.title ?? ""
  7888. }`,
  7889. title: p?.title ?? "",
  7890. icon: p?.icon ?? "",
  7891. iconClass: p?.iconClass ?? "",
  7892. items: p?.items || [],
  7893. onOpen: (srv, ctx) => p?.onOpen?.(srv, ctx),
  7894. })
  7895. : Vue.h(SsSidebarListComp, {
  7896. key: `ss-sidebar-list-${idx}-${p?.title ?? ""}`,
  7897. title: p?.title ?? "",
  7898. icon: p?.icon ?? "",
  7899. count: p?.count ?? p?.items?.length ?? "",
  7900. closable: !!p?.closable,
  7901. searchable: !!p?.searchable,
  7902. searchInHeader: !!p?.searchInHeader,
  7903. headerFilters: p?.headerFilters || [],
  7904. headerSearchButton: !!p?.headerSearchButton,
  7905. searchPlaceholder: p?.searchPlaceholder ?? "搜索",
  7906. itemLayout: p?.itemLayout ?? "simple",
  7907. itemAction: p?.itemAction ?? true,
  7908. collapsible: true,
  7909. collapsed: !!this.sectionCollapsed?.[idx],
  7910. onToggleCollapse: () =>
  7911. this.toggleSectionCollapse?.(idx),
  7912. iconClass: p?.iconClass ?? "",
  7913. items: p?.items || [],
  7914. mode: p?.mode || "search",
  7915. onSelect: (item) => this.$emit("select", item),
  7916. onRemove: (item) => this.$emit("remove", item),
  7917. onClear: () => p?.onClear?.(),
  7918. onSearch: (payload) => p?.onSearch?.(payload),
  7919. });
  7920. const section = Vue.h(
  7921. "div",
  7922. {
  7923. class: {
  7924. "ss-sidebar-section": true,
  7925. "is-collapsed": !!this.sectionCollapsed?.[idx],
  7926. },
  7927. key: `ss-sidebar-section-${idx}-${p?.type ?? "list"}-${
  7928. p?.title ?? ""
  7929. }`,
  7930. style: {
  7931. height: (this.sectionHeights[idx] ?? 190) + "px",
  7932. flex: "0 0 auto",
  7933. },
  7934. },
  7935. [
  7936. Vue.h("div", { class: "ss-sidebar-section__content" }, [
  7937. panelContent,
  7938. ]),
  7939. ]
  7940. );
  7941. const gap =
  7942. idx < sectionPanels.length - 1
  7943. ? Vue.h("div", {
  7944. class: "ss-sidebar-gap",
  7945. onPointerdown: (e) => this.startResize(idx, e),
  7946. })
  7947. : null;
  7948. return gap ? [section, gap] : [section];
  7949. })
  7950. ),
  7951. // 图表区固定在底部(hover 弹出大图) by xu 20260106
  7952. ...chartPanels.map((p, chartIdx) =>
  7953. Vue.h(
  7954. "div",
  7955. {
  7956. class: {
  7957. "ss-sidebar-panel": true,
  7958. "ss-sidebar-chart-panel": true,
  7959. "is-collapsed": !!this.chartCollapsed?.[chartIdx],
  7960. },
  7961. style: { flex: "0 0 auto", minHeight: "37px" },
  7962. "data-chart-idx": chartIdx,
  7963. key: `ss-sidebar-chart-${chartIdx}-${p?.title ?? ""}`,
  7964. },
  7965. [
  7966. p?.title
  7967. ? Vue.h(
  7968. "div",
  7969. {
  7970. class: "ss-sidebar-panel__header",
  7971. onDblclick: (e) => {
  7972. e?.preventDefault?.();
  7973. e?.stopPropagation?.();
  7974. console.log("[SsSidebar] chart header dblclick", {
  7975. idx: chartIdx,
  7976. title: p?.title,
  7977. });
  7978. this.toggleChartCollapse?.(chartIdx);
  7979. },
  7980. },
  7981. [
  7982. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7983. p?.iconClass
  7984. ? Vue.h(SsIcon, {
  7985. class:
  7986. p.iconClass + " ss-sidebar-panel__icon",
  7987. })
  7988. : p?.icon
  7989. ? Vue.h(SsIcon, {
  7990. name: p.icon,
  7991. size: "16px",
  7992. class: "ss-sidebar-panel__icon",
  7993. })
  7994. : null,
  7995. Vue.h("span", null, p.title),
  7996. ]),
  7997. Vue.h("div", { class: "ss-sidebar-panel__tools" }),
  7998. ]
  7999. )
  8000. : null,
  8001. this.chartCollapsed?.[chartIdx]
  8002. ? null
  8003. : Vue.h(Vue.resolveComponent("ss-sidebar-chart-hover"), {
  8004. title: p?.title ?? "",
  8005. iconClass: p?.iconClass ?? "",
  8006. icon: p?.icon ?? "",
  8007. options: p?.options || {},
  8008. height: p?.height || "240px",
  8009. }),
  8010. ]
  8011. )
  8012. ),
  8013. ...reportPanels.map((p, reportIdx) =>
  8014. Vue.h(
  8015. "div",
  8016. {
  8017. class: {
  8018. "ss-sidebar-report-panel-wrap": true,
  8019. "ss-sidebar-report-panel": true,
  8020. "is-collapsed": !!this.reportCollapsed?.[reportIdx],
  8021. },
  8022. style: { flex: "0 0 auto", minHeight: "37px" },
  8023. "data-report-idx": reportIdx,
  8024. key: `ss-sidebar-report-wrap-${reportIdx}-${p?.title ?? ""}`,
  8025. },
  8026. [
  8027. Vue.h(SsSidebarReportTableComp, {
  8028. key: `ss-sidebar-report-${reportIdx}-${p?.title ?? ""}`,
  8029. title: p?.title ?? "",
  8030. icon: p?.icon ?? "",
  8031. iconClass: p?.iconClass ?? "",
  8032. items: p?.items || [],
  8033. collapsible: true,
  8034. collapsed: !!this.reportCollapsed?.[reportIdx],
  8035. onToggleCollapse: () =>
  8036. this.toggleReportCollapse?.(reportIdx),
  8037. onOpen: (srv, ctx) => p?.onOpen?.(srv, ctx),
  8038. }),
  8039. ]
  8040. )
  8041. ),
  8042. ].filter(Boolean)
  8043. ),
  8044. ]);
  8045. },
  8046. };
  8047. // ss-folder-card 文件夹卡片
  8048. const SsFolderCard = {
  8049. name: "SsFolderCard",
  8050. props: {
  8051. item: {
  8052. type: Object,
  8053. required: true,
  8054. },
  8055. },
  8056. data() {
  8057. return {
  8058. showButtons: false,
  8059. };
  8060. },
  8061. emits: ["click", "change"],
  8062. setup(props, { emit }) {
  8063. const item = props.item;
  8064. const showChildren = ref(false);
  8065. const eventBus = window.parent.sharedEventBus;
  8066. const itemWidth = Vue.computed(() => {
  8067. // 功能说明:页面改为 grid 等分布局后,卡片宽度交给容器控制,这里固定 100% by xu 20260116
  8068. return "100%";
  8069. });
  8070. onMounted(() => {
  8071. eventBus.subscribe("folderPath", (path) => {
  8072. const currentPath = path || [];
  8073. // 如果当前文件夹不在路径中,则销毁视图
  8074. if (
  8075. !currentPath.some((item) => item.folder.title === props.item.title)
  8076. ) {
  8077. showChildren.value = false;
  8078. }
  8079. });
  8080. });
  8081. const onItemClick = (e) => {
  8082. if (e && e.stopPropagation) {
  8083. e.stopPropagation();
  8084. }
  8085. // 单击只处理 active 状态
  8086. if (e && e.currentTarget) {
  8087. const allListCards = document.querySelectorAll(
  8088. ".knowledge-item-container"
  8089. );
  8090. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8091. allListCards.forEach((card) => card.classList.remove("active"));
  8092. allFolderCards.forEach((card) => card.classList.remove("active"));
  8093. e.currentTarget.classList.add("active");
  8094. } else {
  8095. // 如果是数据对象,需要找到对应的 DOM 元素
  8096. const allListCards = document.querySelectorAll(
  8097. ".knowledge-item-container"
  8098. );
  8099. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8100. allListCards.forEach((card) => card.classList.remove("active"));
  8101. allFolderCards.forEach((card) => card.classList.remove("active"));
  8102. // 找到标题匹配的文件夹元素
  8103. const targetFolder = Array.from(allFolderCards).find((card) =>
  8104. card.textContent.includes(e.title)
  8105. );
  8106. if (targetFolder) {
  8107. targetFolder.classList.add("active");
  8108. }
  8109. }
  8110. emit("click", item);
  8111. };
  8112. // 修改双击处理函数
  8113. const handleFolderDblClick = (folder, e) => {
  8114. if (e) e.stopPropagation();
  8115. if (folder.children?.length) {
  8116. showChildren.value = true;
  8117. const pathInfo = {
  8118. title: folder.title,
  8119. folder: folder,
  8120. };
  8121. const currentPath = eventBus.getState("folderPath") || [];
  8122. if (!currentPath.some((item) => item.title === folder.title)) {
  8123. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  8124. }
  8125. }
  8126. };
  8127. const onItemChange = (e, icon, index) => {
  8128. e.stopPropagation();
  8129. props.item.buttons[0].onclick();
  8130. // emit("change", { item: props.item, icon, index });
  8131. };
  8132. return {
  8133. item,
  8134. itemWidth,
  8135. showChildren,
  8136. onItemClick,
  8137. onItemChange,
  8138. handleFolderDblClick,
  8139. };
  8140. },
  8141. render() {
  8142. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  8143. if (this.showChildren) {
  8144. return h(SsFolderCartView, {
  8145. folder: this.item,
  8146. });
  8147. }
  8148. return Vue.h(
  8149. "div",
  8150. {
  8151. class: { "ss-folder-list": true, active: this.item.active },
  8152. onClick: (e) => {
  8153. e.stopPropagation();
  8154. this.onItemClick(e);
  8155. },
  8156. onDblclick: (e) => this.handleFolderDblClick(this.item, e),
  8157. style: { width: this.itemWidth },
  8158. },
  8159. [
  8160. // 文件夹特有的装饰元素
  8161. Vue.h("div", { class: "ss-folder-list-trapezoid" }),
  8162. Vue.h("div", { class: "ss-folder-list-top-transparent" }),
  8163. Vue.h("div", { class: "ss-folder-list-top" }),
  8164. Vue.h("div", { class: "ss-folder-list-right" }),
  8165. // header 部分(按钮)
  8166. this.item?.buttons?.length > 0 &&
  8167. Vue.h(
  8168. "div",
  8169. {
  8170. class: "header",
  8171. onMouseenter: () => (this.showButtons = true),
  8172. onMouseleave: () => (this.showButtons = false),
  8173. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  8174. },
  8175. [
  8176. // this.item?.buttons?.length > 0 &&
  8177. Vue.h("div", {
  8178. class: "cart-list-setting cart-list-icon",
  8179. title: this.item?.buttons?.[0]?.title,
  8180. }),
  8181. // this.item?.buttons?.length > 0 &&
  8182. this.showButtons &&
  8183. this.item?.buttons?.length > 1 &&
  8184. Vue.h(
  8185. "div",
  8186. {
  8187. class: "cart-list-button-popup",
  8188. },
  8189. this.item.buttons.map((btn) =>
  8190. Vue.h(
  8191. "div",
  8192. {
  8193. onClick: (e) => {
  8194. e.stopPropagation();
  8195. btn.onclick?.();
  8196. },
  8197. },
  8198. [
  8199. btn.class &&
  8200. Vue.h(SsCartListIcon, {
  8201. class: [btn.class],
  8202. }),
  8203. Vue.h("span", null, btn.title),
  8204. ]
  8205. )
  8206. )
  8207. ),
  8208. ]
  8209. ),
  8210. // body 部分
  8211. Vue.h("div", { class: "body" }, [
  8212. Vue.h("div", { class: "box-header" }, [
  8213. Vue.h("div", null, this.item.title),
  8214. ]),
  8215. Vue.h(
  8216. "div",
  8217. {
  8218. class: !this.item.thumb ? "no-thumb box-body" : "box-body",
  8219. },
  8220. [
  8221. this.item.thumb
  8222. ? Vue.h("div", { class: "left" }, [
  8223. Vue.h("img", {
  8224. src: this.item.thumb,
  8225. alt: "Thumbnail",
  8226. class: "imgUnHandle",
  8227. style: {
  8228. "object-fit": "cover",
  8229. width: "100%",
  8230. height: "100%",
  8231. },
  8232. }),
  8233. ])
  8234. : null,
  8235. Vue.h("div", { class: "right" }, [
  8236. ...this.item.tags.map((tag) => {
  8237. const [key, value] = Object.entries(tag)[0];
  8238. return Vue.h(
  8239. "div",
  8240. {
  8241. class: "title",
  8242. title: `${key}: ${value}`,
  8243. },
  8244. `${key}: ${value}`
  8245. );
  8246. }),
  8247. ]),
  8248. ]
  8249. ),
  8250. ]),
  8251. ]
  8252. );
  8253. },
  8254. };
  8255. // SsFolderCartView 组件 - 用于显示文件夹内容
  8256. const SsFolderCartView = {
  8257. name: "SsFolderCartView",
  8258. props: {
  8259. folder: {
  8260. type: Object,
  8261. required: true,
  8262. },
  8263. },
  8264. emits: ["click"],
  8265. setup(props, { emit }) {
  8266. const eventBus = window.parent.sharedEventBus;
  8267. const currentFolder = ref(props.folder);
  8268. const showChildren = ref(false);
  8269. const onItemClick = (e) => {
  8270. if (e && e.stopPropagation) {
  8271. e.stopPropagation();
  8272. }
  8273. // 单击只处理 active 状态
  8274. if (e && e.currentTarget) {
  8275. const allListCards = document.querySelectorAll(
  8276. ".knowledge-item-container"
  8277. );
  8278. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8279. allListCards.forEach((card) => card.classList.remove("active"));
  8280. allFolderCards.forEach((card) => card.classList.remove("active"));
  8281. e.currentTarget.classList.add("active");
  8282. } else {
  8283. // 如果是数据对象,需要找到对应的 DOM 元素
  8284. const allListCards = document.querySelectorAll(
  8285. ".knowledge-item-container"
  8286. );
  8287. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8288. allListCards.forEach((card) => card.classList.remove("active"));
  8289. allFolderCards.forEach((card) => card.classList.remove("active"));
  8290. // 找到标题匹配的文件夹元素
  8291. const targetFolder = Array.from(allFolderCards).find((card) =>
  8292. card.textContent.includes(e.title)
  8293. );
  8294. if (targetFolder) {
  8295. targetFolder.classList.add("active");
  8296. }
  8297. }
  8298. emit("click", props.folder);
  8299. };
  8300. const handleFolderDblClick = (folder, e) => {
  8301. if (e) e.stopPropagation();
  8302. if (folder.children?.length) {
  8303. showChildren.value = true;
  8304. const pathInfo = {
  8305. title: folder.title,
  8306. folder: folder,
  8307. };
  8308. const currentPath = eventBus.getState("folderPath") || [];
  8309. if (!currentPath.some((item) => item.title === folder.title)) {
  8310. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  8311. currentFolder.value = folder;
  8312. }
  8313. }
  8314. };
  8315. const goBack = (targetFolder) => {
  8316. if (targetFolder === null) {
  8317. // 返回根目录
  8318. eventBus.publish("folderPath", []);
  8319. } else {
  8320. currentFolder.value = targetFolder;
  8321. }
  8322. };
  8323. return {
  8324. currentFolder,
  8325. showChildren,
  8326. onItemClick,
  8327. handleFolderDblClick,
  8328. goBack,
  8329. };
  8330. },
  8331. render() {
  8332. return h(
  8333. "div",
  8334. {
  8335. class: "page-container",
  8336. style: {
  8337. position: "fixed",
  8338. top: 0,
  8339. left: 0,
  8340. width: "100%",
  8341. height: "100%",
  8342. background: "var(--lightgray)",
  8343. padding: "20px 0",
  8344. zIndex: 1000,
  8345. },
  8346. },
  8347. [
  8348. // 搜索栏
  8349. h("div", { class: "search-bar" }, [
  8350. h("div", { class: "search-bar-contaienr" }, [
  8351. h(SsBreadcrumb, {
  8352. level: {
  8353. onBack: this.goBack,
  8354. },
  8355. }),
  8356. ]),
  8357. ]),
  8358. // 内容区域
  8359. h(
  8360. "div",
  8361. {
  8362. class: "content-area item-content-area",
  8363. style: { gap: "20px" },
  8364. },
  8365. [
  8366. ...(this.currentFolder.children || []).map((child, index) =>
  8367. h(child.children ? SsFolderCard : SsListCard, {
  8368. key: index,
  8369. item: child,
  8370. onClick: (e) => this.onItemClick(e),
  8371. onDblclick: (e) => this.handleFolderDblClick(child, e),
  8372. })
  8373. ),
  8374. ]
  8375. ),
  8376. ]
  8377. );
  8378. },
  8379. };
  8380. // ss-page分页
  8381. const SsPage = {
  8382. name: "SsPage",
  8383. props: {
  8384. total: {
  8385. type: Number,
  8386. required: true,
  8387. },
  8388. size: {
  8389. type: Number,
  8390. default: 10,
  8391. },
  8392. page: {
  8393. type: Number,
  8394. default: 1,
  8395. },
  8396. onChange: {
  8397. type: Function,
  8398. default: () => {},
  8399. },
  8400. },
  8401. setup(props) {
  8402. const totalItems = ref(props.total); // 总条目数
  8403. const totalPages = ref(Math.ceil(props.total / props.size));
  8404. const currentPage = ref(props.page); // 当前页码
  8405. // 计算显示的信息
  8406. const pageInfo = ref(
  8407. `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`
  8408. );
  8409. // 上一页的逻辑
  8410. const goToPreviousPage = (e) => {
  8411. e.preventDefault(); // 阻止默认行为
  8412. if (currentPage.value > 1) {
  8413. currentPage.value -= 1;
  8414. updatePageInfo();
  8415. props.onChange?.({
  8416. pageNo: currentPage.value, // 当前页码
  8417. rowNumPer: props.size, // 每页条数
  8418. rowNum: props.total, // 总记录数
  8419. });
  8420. }
  8421. };
  8422. // 下一页的逻辑
  8423. const goToNextPage = (e) => {
  8424. e.preventDefault(); // 阻止默认行为
  8425. if (currentPage.value < totalPages.value) {
  8426. currentPage.value += 1;
  8427. updatePageInfo();
  8428. props.onChange?.({
  8429. pageNo: currentPage.value, // 当前页码
  8430. rowNumPer: props.size, // 每页条数
  8431. rowNum: props.total, // 总记录数
  8432. });
  8433. }
  8434. };
  8435. // 更新页码信息的函数
  8436. const updatePageInfo = () => {
  8437. pageInfo.value = `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`;
  8438. };
  8439. return {
  8440. pageInfo,
  8441. totalPages,
  8442. goToPreviousPage,
  8443. goToNextPage,
  8444. };
  8445. },
  8446. render(props, { slots, emit }) {
  8447. return Vue.h("div", { class: "pager-container" }, [
  8448. Vue.h("input", { type: "hidden", name: "rowNum", value: props.total }),
  8449. Vue.h("input", {
  8450. type: "hidden",
  8451. name: "rowNumPer",
  8452. value: props.size,
  8453. }),
  8454. Vue.h("input", {
  8455. type: "hidden",
  8456. name: "pageCount",
  8457. value: this.totalPages,
  8458. }),
  8459. Vue.h("input", { type: "hidden", name: "pageNo", value: props.page }),
  8460. Vue.h("div", { class: "pager-content" }, [
  8461. Vue.h("div", { class: "info" }, this.pageInfo),
  8462. Vue.h(
  8463. "div",
  8464. { class: "btn" },
  8465. Vue.h(
  8466. "button",
  8467. { onClick: (e) => this.goToPreviousPage(e) },
  8468. "上一页"
  8469. )
  8470. ),
  8471. Vue.h(
  8472. "div",
  8473. { class: "btn" },
  8474. Vue.h("button", { onClick: (e) => this.goToNextPage(e) }, "下一页")
  8475. ),
  8476. ]),
  8477. ]);
  8478. },
  8479. };
  8480. // ss-right-info 一级页面右边栏
  8481. const SSRightInfo = {
  8482. name: "SSRightInfo",
  8483. setup() {
  8484. // 初始化响应式数据
  8485. const item = ref({
  8486. thumb: "images/example/project-img.png", // 更换为适合你项目的实际路径
  8487. title: "工业和信息化产业高质量发展资金",
  8488. });
  8489. return {
  8490. item,
  8491. };
  8492. },
  8493. render() {
  8494. return Vue.h("div", { class: "info-container" }, [
  8495. Vue.h("div", { class: "header" }, [
  8496. Vue.h("div", [
  8497. Vue.h("img", {
  8498. src: this.item.thumb,
  8499. class: "imgUnHandle",
  8500. style: { "object-fit": "cover", width: "100%", height: "100%" },
  8501. }), // 将 ImageViewer 替换为 img 标签
  8502. ]),
  8503. Vue.h("div", [Vue.h("div", this.item.title)]),
  8504. ]),
  8505. Vue.h("div", { class: "section-container" }, [
  8506. Vue.h("div", { class: "section" }, [
  8507. Vue.h("div", { class: "title" }, "合同"),
  8508. Vue.h("div", { class: "text" }, "合同总金额:42,399,320"),
  8509. Vue.h(
  8510. "div",
  8511. { class: "a" },
  8512. "《工业和信息化产业高质量发展资金补助合同》"
  8513. ),
  8514. ]),
  8515. Vue.h("div", { class: "section" }, [
  8516. Vue.h("div", { class: "title" }, "发票"),
  8517. Vue.h("div", { class: "text" }, "应开发票总额:42,399,320"),
  8518. Vue.h("div", { class: "text" }, "已开发票金额:17,235,345"),
  8519. Vue.h("div", { class: "text" }, "未开发票金额:25,163,975"),
  8520. ]),
  8521. Vue.h("div", { class: "section" }, [
  8522. Vue.h("div", { class: "title" }, "项目组成员"),
  8523. Vue.h("div", { class: "text" }, "我司:3人"),
  8524. Vue.h("div", { class: "text" }, "对方:2人"),
  8525. Vue.h("div", { class: "text" }, "项目负责人:张三"),
  8526. ]),
  8527. Vue.h("div", { class: "section" }, [
  8528. Vue.h("div", { class: "title" }, "采购"),
  8529. Vue.h("div", { class: "text" }, "总额:999,320"),
  8530. Vue.h("div", { class: "text" }, "已付金额:335,345"),
  8531. Vue.h("div", { class: "text" }, "未付金额:663,975"),
  8532. ]),
  8533. ]),
  8534. ]);
  8535. },
  8536. };
  8537. //
  8538. const SsSuccessPopup = {
  8539. name: "SsSuccessPopup",
  8540. props: {
  8541. right: {
  8542. type: String,
  8543. default: "20px",
  8544. },
  8545. bottom: {
  8546. type: String,
  8547. default: "calc(100% + 5px)",
  8548. },
  8549. },
  8550. setup(props, { expose }) {
  8551. // 响应式状态:是否可见
  8552. const visible = ref(false);
  8553. // 计算样式
  8554. const style = computed(() => {
  8555. return {
  8556. "--message-dialog-right": props.right,
  8557. "--message-dialog-bottom": props.bottom,
  8558. };
  8559. });
  8560. // 显示对话框的方法
  8561. const show = () => {
  8562. visible.value = true;
  8563. };
  8564. // 隐藏对话框的方法
  8565. const hide = () => {
  8566. visible.value = false;
  8567. };
  8568. // 将方法暴露给外部使用
  8569. expose({ show, hide });
  8570. // 返回渲染函数
  8571. return () => {
  8572. if (!visible.value) return null;
  8573. const SsIcon = resolveComponent("ss-icon");
  8574. return h(
  8575. "div",
  8576. {
  8577. class: "success-popup",
  8578. style: style.value,
  8579. onClick: (e) => e.stopPropagation(),
  8580. },
  8581. [
  8582. h("div", { class: "left" }, [
  8583. h("div", { class: "icon" }, [
  8584. h(SsIcon, { name: "check", size: "36px" }),
  8585. ]),
  8586. ]),
  8587. h("div", { class: "right" }, [
  8588. h("div", { class: "title" }, "提交成功"),
  8589. h("div", { class: "desc" }, "您的信息已成功提交。"),
  8590. ]),
  8591. ]
  8592. );
  8593. };
  8594. },
  8595. };
  8596. const SsErrorDialog = {
  8597. name: "SsErrorDialog",
  8598. setup(props, { emit }) {
  8599. const visible = ref(false);
  8600. const style = computed(() => {
  8601. return {};
  8602. });
  8603. const show = () => {
  8604. visible.value = true;
  8605. };
  8606. const hide = () => {
  8607. visible.value = false;
  8608. };
  8609. const onBack = () => {
  8610. emit("back");
  8611. hide();
  8612. };
  8613. return {
  8614. visible,
  8615. style,
  8616. show,
  8617. hide,
  8618. onBack,
  8619. };
  8620. },
  8621. render() {
  8622. const SsIcon = resolveComponent("ss-icon");
  8623. return this.visible
  8624. ? h(
  8625. "div",
  8626. {
  8627. class: "errorDialog",
  8628. style: this.style,
  8629. onClick: (event) => event.stopPropagation(),
  8630. },
  8631. [
  8632. h("div", { class: "body" }, [
  8633. h("div", { class: "left" }, [
  8634. h("div", { class: "icon" }, [
  8635. h(SsIcon, { name: "close", size: "36px" }),
  8636. ]),
  8637. ]),
  8638. h("div", { class: "right" }, [
  8639. h("div", { class: "title" }, "操作失败"),
  8640. h("div", { class: "desc" }, "请点击返回以继续。"),
  8641. ]),
  8642. ]),
  8643. h("div", { class: "footer" }, [
  8644. h("div", { class: "left" }),
  8645. h("div", { class: "right" }, [
  8646. h(
  8647. "div",
  8648. {
  8649. class: "btn",
  8650. onClick: this.onBack,
  8651. },
  8652. [h(SsIcon, { name: "arrow-left-line" }), h("div", "返回")]
  8653. ),
  8654. ]),
  8655. ]),
  8656. ]
  8657. )
  8658. : null;
  8659. },
  8660. };
  8661. /**
  8662. * 审核链条
  8663. * @name ss-verify
  8664. * @param { Array } verify-list 审核节点列表
  8665. * @property { Array } verify-list 审核节点列表
  8666. * @example <ss-verify :verify-list="verifyList"></ss-verify>
  8667. * verify-list [
  8668. * {
  8669. * groupName: "", // 群组名称
  8670. * open: true, // 默认是否展开
  8671. * children:[ //群组里的人员
  8672. * {
  8673. * thumb: "images/example/user-4.png", // 头像
  8674. * name: "李丽思 ", // 姓名
  8675. * role: "人事处处长", // 角色
  8676. * description: "同意。", // 审核意见
  8677. * time: "09:38 08/11", // 审核时间
  8678. * video: false, // false不显示/true显示 视频icon
  8679. * link: false, // false不显示/true显示 链接icon 后续应该是附件
  8680. * }
  8681. * ]
  8682. * }
  8683. * ]
  8684. */
  8685. const SsVerify = {
  8686. name: "SsVerify",
  8687. props: {
  8688. verifyList: {
  8689. type: Array,
  8690. required: true,
  8691. },
  8692. },
  8693. setup(props) {
  8694. const toggleOpen = (item) => {
  8695. item.open = !item.open;
  8696. };
  8697. onMounted(() => {
  8698. setTimeout(() => {
  8699. const lastOpenGroup = document.querySelector(".group-item-last-open");
  8700. console.log("lastOpenGroup", lastOpenGroup);
  8701. if (lastOpenGroup) {
  8702. const nodes = $(lastOpenGroup).find(".verify-node-container");
  8703. if (nodes.length) {
  8704. let totalHeight = 0;
  8705. const gudingHeight = 100;
  8706. if (nodes.length === 1) {
  8707. totalHeight = gudingHeight;
  8708. } else {
  8709. // 累加除最后一个节点外的所有节点高度
  8710. for (let i = 0; i < nodes.length - 1; i++) {
  8711. totalHeight += $(nodes[i]).outerHeight();
  8712. }
  8713. totalHeight += gudingHeight;
  8714. }
  8715. console.log("节点信息:", {
  8716. 节点总数: nodes.length,
  8717. 计算后的高度: totalHeight,
  8718. });
  8719. lastOpenGroup.style.setProperty(
  8720. "--group-line-height",
  8721. `${totalHeight}px`
  8722. );
  8723. }
  8724. }
  8725. }, 0);
  8726. });
  8727. return {
  8728. toggleOpen,
  8729. };
  8730. },
  8731. render() {
  8732. const SsIcon = resolveComponent("ss-icon");
  8733. const SsCommonIcon = resolveComponent("ss-common-icon");
  8734. const SsVerifyNode = resolveComponent("ss-verify-node");
  8735. return h(
  8736. "div",
  8737. { class: "verify-nodes" },
  8738. this.verifyList.map((item, i) =>
  8739. h(
  8740. "div",
  8741. {
  8742. key: i,
  8743. class: {
  8744. "group-item": true,
  8745. "group-item-last-open":
  8746. i === this.verifyList.length - 1 && item.open,
  8747. },
  8748. },
  8749. [
  8750. h(
  8751. "div",
  8752. {
  8753. class: "group-item-title",
  8754. onClick: () => this.toggleOpen(item),
  8755. },
  8756. [
  8757. h("div", { class: "icon" }, [
  8758. item.open
  8759. ? h(SsCommonIcon, { class: "common-icon-folder-open" })
  8760. : h(SsCommonIcon, { class: "common-icon-folder-close" }),
  8761. h(
  8762. "div",
  8763. {
  8764. class: "num",
  8765. style: { top: item.open ? "60%" : "55%" },
  8766. },
  8767. item.children?.length || 0
  8768. ),
  8769. ]),
  8770. h("div", { class: "name" }, item.groupName),
  8771. ]
  8772. ),
  8773. item.open && item.children?.length > 0
  8774. ? h(
  8775. "div",
  8776. { class: "group-item-children" },
  8777. item.children.map((citem, j) =>
  8778. h(SsVerifyNode, {
  8779. key: j,
  8780. item: citem,
  8781. // isGroup: i + 1 !== this.verifyList.length,
  8782. isGroup: true,
  8783. })
  8784. )
  8785. )
  8786. : null,
  8787. ]
  8788. )
  8789. )
  8790. );
  8791. },
  8792. };
  8793. /**
  8794. * 审核页面的审核节点
  8795. * @name ss-verify-node
  8796. * @param {Object} item 审核节点信息
  8797. * @param {Boolean} isGroup 是否为分组节点
  8798. */
  8799. const SsVerifyNode = {
  8800. name: "SsVerifyNode",
  8801. props: {
  8802. item: {
  8803. type: Object,
  8804. required: true,
  8805. },
  8806. isGroup: {
  8807. type: Boolean,
  8808. default: false,
  8809. },
  8810. },
  8811. render() {
  8812. const SsIcon = resolveComponent("ss-icon");
  8813. const SsCommonIcon = resolveComponent("ss-common-icon");
  8814. return Vue.h("div", { class: "verify-node-container" }, [
  8815. Vue.h("div", { class: "info" }, [
  8816. Vue.h("div", { class: "avatar" }, [
  8817. Vue.h("img", {
  8818. src: this.item.thumb,
  8819. style: {
  8820. width: "50px",
  8821. height: "50px",
  8822. borderRadius: "50%",
  8823. },
  8824. }),
  8825. ]),
  8826. Vue.h("div", { class: "desc" }, [
  8827. Vue.h("div", this.item.name),
  8828. Vue.h("div", this.item.role),
  8829. ]),
  8830. Vue.h("div", { class: "link" }, [
  8831. Vue.h("div", [
  8832. this.item.video
  8833. ? Vue.h(SsCommonIcon, { class: "common-icon-video" })
  8834. : null,
  8835. this.item.link
  8836. ? Vue.h(SsCommonIcon, {
  8837. class: "common-icon-paper-clip",
  8838. })
  8839. : null,
  8840. ]),
  8841. ]),
  8842. ]),
  8843. Vue.h(
  8844. "div",
  8845. {
  8846. class: {
  8847. description: true,
  8848. link: this.isGroup,
  8849. },
  8850. attrs: { "data-num": "3" },
  8851. },
  8852. [Vue.h("div", this.item.description)]
  8853. ),
  8854. Vue.h("div", { class: "time" }, this.item.time),
  8855. ]);
  8856. },
  8857. };
  8858. /**
  8859. * 智能识别图片的左侧图片播放 可以放大缩小旋转图片
  8860. * @name ss-orc-img-box
  8861. * @param { Object } image-obj 包含图片的url, 和图片的名称
  8862. *
  8863. */
  8864. const SsOrcImgBox = {
  8865. name: "SsOrcImgBox",
  8866. props: {
  8867. imageObj: {
  8868. type: Object,
  8869. required: true,
  8870. },
  8871. },
  8872. setup(props) {
  8873. const zoom = ref(1);
  8874. const rotation = ref(0);
  8875. const containerWidth = ref(0);
  8876. const containerHeight = ref(0);
  8877. const container = ref(null);
  8878. const imgPosition = ref({ x: 0, y: 0 });
  8879. const isDragging = ref(false);
  8880. const lastMousePosition = ref({ x: 0, y: 0 });
  8881. const imgStyle = computed(() => ({
  8882. width: `${zoom.value * 100}%`,
  8883. height: `${zoom.value * 100}%`,
  8884. transform: `rotate(${rotation.value}deg) translate(${imgPosition.value.x}px, ${imgPosition.value.y}px)`,
  8885. transformOrigin: "center center",
  8886. cursor: isDragging.value ? "grabbing" : "grab",
  8887. }));
  8888. const resetZoom = () => {
  8889. zoom.value = 1;
  8890. rotation.value = rotation.value + 90;
  8891. imgPosition.value = { x: 0, y: 0 };
  8892. };
  8893. const handleRangeChange = (event) => {
  8894. const value = event.target.value / 50; // 0 到 100 映射到 0 到 2 的缩放
  8895. zoom.value = Math.max(value, 0.1); // 设置最小缩放值为 0.1
  8896. };
  8897. const updateImgBoxDimensions = () => {
  8898. if (container.value) {
  8899. containerWidth.value = container.value.clientWidth;
  8900. containerHeight.value = container.value.clientHeight;
  8901. }
  8902. };
  8903. const onMouseDown = (event) => {
  8904. isDragging.value = true;
  8905. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  8906. };
  8907. const onMouseMove = (event) => {
  8908. if (isDragging.value) {
  8909. const dx = event.clientX - lastMousePosition.value.x;
  8910. const dy = event.clientY - lastMousePosition.value.y;
  8911. // 防止旋转后拖动的x,y反转
  8912. // 首先将当前旋转角度从度数转换为弧度,因为 JavaScript 的 Math 库使用弧度
  8913. const angle = rotation.value * (Math.PI / 180);
  8914. // 使用基本的二维旋转矩阵将原始位移 dx 和 dy 转换为旋转后的位移 rotatedDx 和 rotatedDy。
  8915. const rotatedDx = dx * Math.cos(angle) + dy * Math.sin(angle);
  8916. const rotatedDy = dy * Math.cos(angle) - dx * Math.sin(angle);
  8917. imgPosition.value = {
  8918. x: imgPosition.value.x + rotatedDx,
  8919. y: imgPosition.value.y + rotatedDy,
  8920. };
  8921. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  8922. }
  8923. };
  8924. const onMouseUp = () => {
  8925. isDragging.value = false;
  8926. };
  8927. onMounted(() => {
  8928. nextTick(() => {
  8929. updateImgBoxDimensions();
  8930. window.addEventListener("resize", updateImgBoxDimensions);
  8931. window.addEventListener("mousemove", onMouseMove);
  8932. window.addEventListener("mouseup", onMouseUp);
  8933. });
  8934. });
  8935. return {
  8936. zoom,
  8937. rotation,
  8938. container,
  8939. imgStyle,
  8940. resetZoom,
  8941. handleRangeChange,
  8942. containerWidth,
  8943. containerHeight,
  8944. onMouseDown,
  8945. imgPosition,
  8946. };
  8947. },
  8948. render() {
  8949. const SsIcon = resolveComponent("ss-icon");
  8950. return h("div", { class: "ocr-img-box" }, [
  8951. h("div", { class: "img-bar" }, [
  8952. h("div", this.imageObj.name),
  8953. h("div", { class: "action-bar" }, [
  8954. h("div", { class: "ocr-img-range-box" }, [
  8955. h("input", {
  8956. type: "range",
  8957. min: 0,
  8958. max: 100,
  8959. value: this.zoom * 50, // 初始位置为50
  8960. onInput: this.handleRangeChange,
  8961. }),
  8962. h("span", { class: "line" }),
  8963. ]),
  8964. h(SsIcon, {
  8965. name: "reset",
  8966. size: "26px",
  8967. onClick: this.resetZoom,
  8968. }),
  8969. ]),
  8970. ]),
  8971. h("div", { class: "img-viewer", ref: "container" }, [
  8972. h(
  8973. "div",
  8974. {
  8975. class: "img-box",
  8976. style: {
  8977. width: `${this.containerWidth}px`,
  8978. height: `${this.containerHeight}px`,
  8979. overflow: "hidden",
  8980. position: "relative",
  8981. },
  8982. },
  8983. [
  8984. h("img", {
  8985. src: this.imageObj.thumb,
  8986. style: this.imgStyle,
  8987. class: "zoomable-img",
  8988. onMousedown: this.onMouseDown,
  8989. }),
  8990. ]
  8991. ),
  8992. ]),
  8993. ]);
  8994. },
  8995. };
  8996. // 搜索输入框组件
  8997. const SsSearchInput = {
  8998. name: "SsSearchInput",
  8999. props: {
  9000. name: String,
  9001. placeholder: String,
  9002. width: {
  9003. type: String,
  9004. default: "100px",
  9005. },
  9006. modelValue: String,
  9007. },
  9008. emits: ["update:modelValue", "search"],
  9009. setup(props, { emit }) {
  9010. const handleInput = (e) => {
  9011. emit("update:modelValue", e.target.value);
  9012. };
  9013. const handleKeyup = (e) => {
  9014. if (e.key === "Enter") {
  9015. emit("search");
  9016. }
  9017. };
  9018. return { handleInput, handleKeyup };
  9019. },
  9020. render() {
  9021. return h(
  9022. "div",
  9023. {
  9024. class: "input",
  9025. style: this.width ? { width: this.width } : undefined,
  9026. },
  9027. [
  9028. h("input", {
  9029. name: this.name,
  9030. placeholder: this.placeholder,
  9031. value: this.modelValue,
  9032. onInput: this.handleInput,
  9033. onKeyup: this.handleKeyup,
  9034. }),
  9035. ]
  9036. );
  9037. },
  9038. };
  9039. // ss-search-date-picker 日期时间选择器组件
  9040. const SsSearchDatePicker = {
  9041. name: "SsSearchDatePicker",
  9042. props: {
  9043. modelValue: {
  9044. type: [String, Number, Date],
  9045. default: "",
  9046. },
  9047. name: {
  9048. type: String,
  9049. required: true,
  9050. },
  9051. type: {
  9052. type: String,
  9053. default: "date",
  9054. validator: (value) => ["date", "datetime", "time"].includes(value),
  9055. },
  9056. fmt: {
  9057. type: String,
  9058. default: null,
  9059. },
  9060. placeholder: {
  9061. type: String,
  9062. default: "",
  9063. },
  9064. width: {
  9065. type: String,
  9066. default: "100%",
  9067. },
  9068. },
  9069. emits: ["update:modelValue"],
  9070. setup(props, { emit }) {
  9071. const errMsg = ref("");
  9072. const validate = () => {
  9073. if (window.ssVm) {
  9074. const result = window.ssVm.validateField(props.name);
  9075. console.log("validate", window.ssVm.validateField(props.name));
  9076. errMsg.value = result.valid ? "" : result.message;
  9077. }
  9078. };
  9079. // 根据type确定默认格式
  9080. const defaultFormat = computed(() => {
  9081. switch (props.type) {
  9082. case "datetime":
  9083. return "YYYY-MM-DD HH:mm:ss";
  9084. case "date":
  9085. return "YYYY-MM-DD";
  9086. case "time":
  9087. return "HH:mm:ss";
  9088. }
  9089. });
  9090. const convertJavaFormatToElement = (javaFormat) => {
  9091. if (!javaFormat) return null;
  9092. return javaFormat
  9093. .replace("yyyy", "YYYY")
  9094. .replace("MM", "MM")
  9095. .replace("dd", "DD")
  9096. .replace("HH", "HH")
  9097. .replace("mm", "mm")
  9098. .replace("ss", "ss");
  9099. };
  9100. const finalFormat = computed(() => {
  9101. if (props.fmt) {
  9102. return convertJavaFormatToElement(props.fmt);
  9103. }
  9104. return defaultFormat.value;
  9105. });
  9106. // 使用 resolveComponent 获取组件
  9107. const ElDatePicker = resolveComponent("ElDatePicker");
  9108. const ElTimePicker = resolveComponent("ElTimePicker");
  9109. const SsFormIcon = resolveComponent("SsFormIcon");
  9110. const ElIcon = resolveComponent("ElIcon");
  9111. let useTimePicker = true;
  9112. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  9113. if (props.fmt) {
  9114. //有fmt属性,则以fmt属性优先判断类型
  9115. if (/[dMy]/.test(props.fmt)) {
  9116. //如果有传入日期格式,且含年月日
  9117. useTimePicker = false;
  9118. } else {
  9119. useTimePicker = true;
  9120. }
  9121. } else if (props.type !== "time") {
  9122. useTimePicker = false;
  9123. }
  9124. const dateType = computed(() => {
  9125. const fmt = props.fmt || "";
  9126. if (fmt.includes("HH:mm:ss")) {
  9127. return "datetime";
  9128. } else if (fmt.includes("HH:mm")) {
  9129. return "datetime";
  9130. } else if (fmt.includes("mm:ss")) {
  9131. return "time";
  9132. }
  9133. return "date";
  9134. });
  9135. const handleValueUpdate = (val) => {
  9136. emit("update:modelValue", val);
  9137. emit("change", val); // 同时触发 change 事件
  9138. setTimeout(() => {
  9139. validate();
  9140. }, 50);
  9141. };
  9142. return () =>
  9143. h(
  9144. "div",
  9145. { class: "ss-search-date-picker", style: { width: props.width } },
  9146. [
  9147. h("input", {
  9148. type: "hidden",
  9149. name: props.name,
  9150. value: props.modelValue,
  9151. }),
  9152. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  9153. modelValue: props.modelValue,
  9154. "onUpdate:modelValue": handleValueUpdate,
  9155. type: dateType.value,
  9156. format: finalFormat.value,
  9157. "value-format": finalFormat.value,
  9158. clearable: true,
  9159. placeholder: props.placeholder,
  9160. class: "custom-date-picker", // 用于自定义样式
  9161. "time-arrow-control": props.type === "datetime", // 修改这里
  9162. size: "large", // 添加这一行,改为 large 尺寸
  9163. style: { width: "100%" },
  9164. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  9165. }),
  9166. ]
  9167. );
  9168. },
  9169. };
  9170. // 搜索按钮组件(包含下拉按钮)
  9171. const SsSearchButton = {
  9172. name: "SsSearchButton",
  9173. props: {
  9174. text: {
  9175. type: String,
  9176. required: true,
  9177. },
  9178. iconClass: {
  9179. type: String,
  9180. required: false,
  9181. },
  9182. opt: {
  9183. type: Array,
  9184. default: () => [],
  9185. },
  9186. checkId: {
  9187. type: String,
  9188. default: "0",
  9189. },
  9190. width: {
  9191. //add by Ben(20251225)
  9192. type: String,
  9193. required: false,
  9194. },
  9195. id: {
  9196. //add by Ben(20251225)
  9197. type: String,
  9198. required: false,
  9199. },
  9200. },
  9201. emits: ["click"],
  9202. setup(props, { emit }) {
  9203. const currentId = ref(props.checkId || "0");
  9204. const showPopup = ref(false);
  9205. const handleMouseEnter = () => {
  9206. showPopup.value = true;
  9207. };
  9208. const handleMouseLeave = () => {
  9209. showPopup.value = false;
  9210. };
  9211. // 添加点击事件处理,阻止默认行为
  9212. const handleClick = (e) => {
  9213. e.preventDefault();
  9214. if (props.opt?.length > 0) {
  9215. const selectedOption =
  9216. currentId.value === "0"
  9217. ? props.opt[0]
  9218. : props.opt.find((opt) => opt.id === currentId.value);
  9219. if (selectedOption) {
  9220. selectedOption.callback?.();
  9221. }
  9222. } else {
  9223. emit("click", e);
  9224. }
  9225. };
  9226. // 获取显示文本
  9227. const getDisplayText = () => {
  9228. if (!props.opt?.length) return props.text;
  9229. const selectedOption =
  9230. currentId.value === "0"
  9231. ? props.opt[0]
  9232. : props.opt.find((opt) => opt.id === currentId.value);
  9233. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  9234. };
  9235. return () =>
  9236. h(
  9237. "button",
  9238. {
  9239. class:
  9240. props.opt?.length > 0
  9241. ? "ss-drop-button ss-drop-button-more"
  9242. : "ss-drop-button",
  9243. type: "button", // 明确指定按钮类型为 button
  9244. onMouseenter: handleMouseEnter,
  9245. onMouseleave: handleMouseLeave,
  9246. onClick: handleClick, // 添加点击事件处理
  9247. style: { width: props.width }, //add by Ben(20251225)
  9248. id: props.id, //add by Ben(20251225)
  9249. },
  9250. [
  9251. props.iconClass
  9252. ? h("span", {
  9253. class: props.iconClass,
  9254. style: { fontFamily: "iconfont", marginRight: "5px" },
  9255. })
  9256. : null,
  9257. h("span", getDisplayText()),
  9258. props.opt.length > 0 &&
  9259. showPopup.value &&
  9260. h(
  9261. "div",
  9262. {
  9263. class: "popup",
  9264. },
  9265. props.opt.map((item) =>
  9266. h(
  9267. "div",
  9268. {
  9269. onClick: (e) => {
  9270. e.preventDefault(); // 选项点击也阻止默认行为
  9271. e.stopPropagation(); // 阻止事件冒泡
  9272. currentId.value = item.id; // 更新当前选中的ID
  9273. item.callback();
  9274. showPopup.value = false; // 选择后关闭弹窗
  9275. },
  9276. },
  9277. item.desc
  9278. )
  9279. )
  9280. ),
  9281. ]
  9282. );
  9283. },
  9284. };
  9285. // 下拉按钮组件
  9286. const SsDropButton = {
  9287. name: "SsDropButton",
  9288. props: {
  9289. text: {
  9290. type: String,
  9291. required: true,
  9292. },
  9293. iconClass: {
  9294. type: String,
  9295. required: true,
  9296. },
  9297. opt: {
  9298. type: Array,
  9299. default: () => [],
  9300. },
  9301. checkId: {
  9302. type: String,
  9303. default: "0",
  9304. },
  9305. onclick: {
  9306. type: Function,
  9307. default: null,
  9308. },
  9309. },
  9310. setup(props) {
  9311. const currentId = ref(props.checkId || "0");
  9312. const showPopup = ref(false);
  9313. const handleMouseEnter = () => {
  9314. showPopup.value = true;
  9315. };
  9316. const handleMouseLeave = () => {
  9317. showPopup.value = false;
  9318. };
  9319. // 添加点击事件处理,阻止默认行为
  9320. const handleClick = (e) => {
  9321. e.preventDefault();
  9322. if (props.opt?.length > 0) {
  9323. const selectedOption =
  9324. currentId.value === "0"
  9325. ? props.opt[0]
  9326. : props.opt.find((opt) => opt.id === currentId.value);
  9327. if (selectedOption) {
  9328. selectedOption.callback?.();
  9329. }
  9330. } else if (props.onclick) {
  9331. props.onclick();
  9332. }
  9333. };
  9334. // 获取显示文本
  9335. const getDisplayText = () => {
  9336. if (!props.opt?.length) return props.text;
  9337. const selectedOption =
  9338. currentId.value === "0"
  9339. ? props.opt[0]
  9340. : props.opt.find((opt) => opt.id === currentId.value);
  9341. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  9342. };
  9343. return () =>
  9344. h(
  9345. "button",
  9346. {
  9347. class:
  9348. props.opt?.length > 0
  9349. ? "ss-drop-button ss-drop-button-more"
  9350. : "ss-drop-button",
  9351. type: "button", // 明确指定按钮类型为 button
  9352. onMouseenter: handleMouseEnter,
  9353. onMouseleave: handleMouseLeave,
  9354. onClick: handleClick, // 添加点击事件处理
  9355. },
  9356. [
  9357. h("span", {
  9358. class: props.iconClass,
  9359. style: { fontFamily: "iconfont" },
  9360. }),
  9361. h("span", getDisplayText()),
  9362. props.opt.length > 0 &&
  9363. showPopup.value &&
  9364. h(
  9365. "div",
  9366. {
  9367. class: "popup",
  9368. },
  9369. props.opt.map((item) =>
  9370. h(
  9371. "div",
  9372. {
  9373. onClick: (e) => {
  9374. e.preventDefault(); // 选项点击也阻止默认行为
  9375. e.stopPropagation(); // 阻止事件冒泡
  9376. currentId.value = item.id; // 更新当前选中的ID
  9377. item.callback();
  9378. showPopup.value = false; // 选择后关闭弹窗
  9379. },
  9380. },
  9381. item.desc
  9382. )
  9383. )
  9384. ),
  9385. ]
  9386. );
  9387. },
  9388. };
  9389. /**
  9390. * 二级页面标签组件
  9391. * @name ss-sub-tab
  9392. * @description 用于展示二级页面的布局组件,包含左侧垂直标签导航(支持分组)和右侧iframe内容区
  9393. * @property {String} headerImage - 左侧顶部图片地址
  9394. * @property {Array} menuList - 菜单配置列表
  9395. * @property {Object} [activeMenu] - 当前选中的菜单项,不传则自动选择第一个可选菜单
  9396. * @property {Array} footerButtons - 底部按钮配置列表
  9397. */
  9398. /**
  9399. * SsSubTab 左侧菜单+iframe内容组件
  9400. * v3.0 改造:去掉顶部图片,改为图标+悬浮模式,iframe懒加载 by xu 20251216
  9401. */
  9402. const SsSubTab = {
  9403. name: "SsSubTab",
  9404. props: {
  9405. menuList: {
  9406. type: Array,
  9407. required: true,
  9408. },
  9409. activeMenu: {
  9410. type: String,
  9411. default: "",
  9412. },
  9413. footerButtons: {
  9414. type: Array,
  9415. default: () => [],
  9416. },
  9417. leftDisplay: {
  9418. type: Boolean,
  9419. default: true,
  9420. },
  9421. // v3.0 新增:菜单模式 collapse(悬浮展开) / fixed(始终收起) by xu 20251216
  9422. initialMode: {
  9423. type: String,
  9424. default: "collapse",
  9425. },
  9426. },
  9427. emits: ["menu-change", "footer-click"],
  9428. setup(props, { emit }) {
  9429. // v3.0 新增:默认图标映射,使用icon-biz图标 by xu 20251216
  9430. const defaultIcons = [
  9431. "icon-obj-ry", // 人员
  9432. "icon-obj-dw", // 单位
  9433. "icon-obj-gw", // 岗位
  9434. "icon-biz-rc", // 人才
  9435. "icon-biz-xc", // 巡查
  9436. "icon-biz-cl", // 材料
  9437. "icon-biz-men", // 门
  9438. "icon-obj-xy", // 协议
  9439. ];
  9440. //功能: SsSubTab 支持后端下发 iconName + pobj/cobj 两级菜单 by xu 20251222
  9441. const isTrue = (v) => v === true || v === "true" || v === 1 || v === "1"; //功能 by xu 20251222
  9442. const resolveIconClass = (iconNameOrClass, fallbackIndex) => {
  9443. //功能 by xu 20251222
  9444. const fallback = `menu-icon ${
  9445. defaultIcons[fallbackIndex % defaultIcons.length]
  9446. }`;
  9447. if (!iconNameOrClass) {
  9448. return fallback;
  9449. }
  9450. // 已经是完整 class(可能包含 menu-icon / menu-base-icon / 多个 class)
  9451. if (
  9452. typeof iconNameOrClass === "string" &&
  9453. iconNameOrClass.indexOf(" ") > -1
  9454. ) {
  9455. return iconNameOrClass;
  9456. }
  9457. const iconName = iconNameOrClass;
  9458. if (iconName === "menu-icon" || iconName === "menu-base-icon") {
  9459. return fallback;
  9460. }
  9461. // 业务图标库:icon-biz / icon-obj -> menu-icon
  9462. if (
  9463. typeof iconName === "string" &&
  9464. (iconName.indexOf("icon-obj-") === 0 ||
  9465. iconName.indexOf("icon-biz-") === 0)
  9466. ) {
  9467. return `menu-icon ${iconName}`;
  9468. }
  9469. // 默认认为是 icon-base 图标 -> menu-base-icon
  9470. return `menu-base-icon ${iconName}`;
  9471. };
  9472. const getMenuIcon = (item, index) => {
  9473. //功能 by xu 20251222
  9474. if (!item) {
  9475. return resolveIconClass(null, index);
  9476. }
  9477. //功能: 变动图标后端暂不正确,前端先写死为 icon-chg by xu 20251223
  9478. if (item.title === "变动" || item.name === "sys_bd") {
  9479. return resolveIconClass("icon-chg", index);
  9480. }
  9481. // 兼容旧字段 icon(优先使用)
  9482. if (item.icon) return resolveIconClass(item.icon, index);
  9483. // v3.0 使用后端下发 iconName
  9484. if (item.iconName) return resolveIconClass(item.iconName, index);
  9485. return resolveIconClass(null, index);
  9486. };
  9487. //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  9488. const getFooterIcon = (button) => {
  9489. //功能 by xu 20251224
  9490. if (!button) return "menu-base-icon icon-subm";
  9491. const iconNameOrClass =
  9492. button.iconClass || button.iconName || button.icon;
  9493. if (!iconNameOrClass) return "menu-base-icon icon-subm";
  9494. if (
  9495. typeof iconNameOrClass === "string" &&
  9496. iconNameOrClass.indexOf(" ") > -1
  9497. ) {
  9498. return iconNameOrClass;
  9499. }
  9500. return `menu-base-icon ${iconNameOrClass}`;
  9501. };
  9502. //功能: pobj/cobj 扁平结构转换为 children 树结构,兼容原 children 结构 by xu 20251222
  9503. const normalizeMenuList = (rawList) => {
  9504. if (!Array.isArray(rawList) || rawList.length === 0) {
  9505. return [];
  9506. }
  9507. const hasTree = rawList.some(
  9508. (it) => Array.isArray(it?.children) && it.children.length > 0
  9509. );
  9510. if (hasTree) {
  9511. return rawList.map((it) => ({
  9512. ...it,
  9513. __level: 1,
  9514. children: Array.isArray(it.children)
  9515. ? it.children.map((c) => ({ ...c, __level: 2 }))
  9516. : it.children,
  9517. }));
  9518. }
  9519. const hasMarker = rawList.some(
  9520. (it) => it && ("pobj" in it || "cobj" in it)
  9521. );
  9522. if (!hasMarker) {
  9523. return rawList.map((it) => ({ ...it, __level: 1 }));
  9524. }
  9525. const result = [];
  9526. let currentGroup = null;
  9527. for (const item of rawList) {
  9528. //功能: “变动”始终按一级处理(即使后端误传 pobj/cobj)by xu 20251223
  9529. const isChgItem =
  9530. item && (item.title === "变动" || item.name === "sys_bd");
  9531. if (isChgItem) {
  9532. result.push({ ...item, __level: 1 });
  9533. continue;
  9534. }
  9535. const isParent = isTrue(item?.pobj);
  9536. const isChild = isTrue(item?.cobj);
  9537. if (isParent) {
  9538. currentGroup = {
  9539. ...item,
  9540. __level: 1,
  9541. children: [],
  9542. };
  9543. result.push(currentGroup);
  9544. continue;
  9545. }
  9546. if (isChild && currentGroup) {
  9547. currentGroup.children.push({ ...item, __level: 2 });
  9548. continue;
  9549. }
  9550. //功能: 变动等无 pobj/cobj 的选项按一级展示(不挂到 children,也不打断当前分组)by xu 20251223
  9551. result.push({ ...item, __level: 1 });
  9552. }
  9553. return result;
  9554. };
  9555. const menuListComputed = computed(() =>
  9556. normalizeMenuList(props.menuList)
  9557. ); //功能 by xu 20251222
  9558. //功能: 分组展开状态(默认展开),避免 computed 生成对象导致 open 状态丢失 by xu 20251222
  9559. const groupOpenState = reactive({}); // { [key]: boolean }
  9560. const getGroupKey = (item) => item?.name || item?.title || ""; //功能 by xu 20251222
  9561. const isGroupOpen = (item) => {
  9562. //功能 by xu 20251222
  9563. const key = getGroupKey(item);
  9564. if (!key) return true;
  9565. return groupOpenState[key] !== false;
  9566. };
  9567. const toggleGroupOpen = (item) => {
  9568. //功能 by xu 20251222
  9569. const key = getGroupKey(item);
  9570. if (!key) return;
  9571. groupOpenState[key] = !isGroupOpen(item);
  9572. };
  9573. const getLevelClass = (item, fallbackLevel) => {
  9574. //功能 by xu 20251222
  9575. //功能: “变动”始终按一级样式处理 by xu 20251223
  9576. if (item && (item.title === "变动" || item.name === "sys_bd")) {
  9577. return "level-1";
  9578. }
  9579. const level = item?.__level || fallbackLevel || 1;
  9580. return level === 2 ? "level-2" : "level-1";
  9581. };
  9582. // v3.0 新增:菜单模式管理 by xu 20251216
  9583. const menuMode = ref(props.initialMode);
  9584. const isHovering = ref(false);
  9585. const toggleMenuMode = () => {
  9586. menuMode.value = menuMode.value === "collapse" ? "fixed" : "collapse";
  9587. };
  9588. //功能: 提供给旧UI弹窗顶部按钮调用的 API(替代点击 .menu-mode-toggle DOM)by xu 20251224
  9589. const registerSsSubTabApi = () => {
  9590. //功能 by xu 20251224
  9591. try {
  9592. window.SS = window.SS || {};
  9593. window.SS.dom = window.SS.dom || {};
  9594. //功能: 兼容小写 ss 命名空间(部分页面只引用 window.ss)by xu 20251224
  9595. window.ss = window.ss || window.SS;
  9596. window.ss.dom = window.ss.dom || window.SS.dom;
  9597. const api = {
  9598. toggleMenuMode,
  9599. getMenuMode: () => menuMode.value,
  9600. };
  9601. window.SS.dom.ssSubTabApi = api;
  9602. window.ss.dom.ssSubTabApi = api;
  9603. //功能: 多层弹窗(如 objPlay -> objInfo) 场景,将 API 注册到 topWindow 供按钮跨层调用 by xu 20251224
  9604. try {
  9605. const wdDialogId =
  9606. window.wd &&
  9607. wd.display &&
  9608. wd.display.getwdDialogId &&
  9609. wd.display.getwdDialogId();
  9610. if (wdDialogId && window.top) {
  9611. window.top.__ssSubTabApiMap = window.top.__ssSubTabApiMap || {};
  9612. window.top.__ssSubTabApiMap[wdDialogId] = api;
  9613. }
  9614. } catch (e) {}
  9615. try {
  9616. console.log(
  9617. "[SsSubTabApi] registered",
  9618. window.location && window.location.pathname
  9619. );
  9620. } catch (e) {}
  9621. } catch (e) {}
  9622. };
  9623. const unregisterSsSubTabApi = () => {
  9624. //功能 by xu 20251224
  9625. try {
  9626. //功能: 从 topWindow 解绑(避免弹窗关闭后残留)by xu 20251224
  9627. try {
  9628. const wdDialogId =
  9629. window.wd &&
  9630. wd.display &&
  9631. wd.display.getwdDialogId &&
  9632. wd.display.getwdDialogId();
  9633. if (
  9634. wdDialogId &&
  9635. window.top &&
  9636. window.top.__ssSubTabApiMap &&
  9637. window.top.__ssSubTabApiMap[wdDialogId]
  9638. ) {
  9639. delete window.top.__ssSubTabApiMap[wdDialogId];
  9640. }
  9641. } catch (e) {}
  9642. if (window.SS?.dom?.ssSubTabApi?.toggleMenuMode === toggleMenuMode) {
  9643. delete window.SS.dom.ssSubTabApi;
  9644. }
  9645. if (window.ss?.dom?.ssSubTabApi?.toggleMenuMode === toggleMenuMode) {
  9646. delete window.ss.dom.ssSubTabApi;
  9647. }
  9648. } catch (e) {}
  9649. };
  9650. //功能: 立即注册,避免 enable 早于 onMounted 导致“api not ready”by xu 20251224
  9651. registerSsSubTabApi(); //功能 by xu 20251224
  9652. onBeforeUnmount(unregisterSsSubTabApi); //功能 by xu 20251224
  9653. const onMouseEnter = () => {
  9654. if (menuMode.value === "collapse") {
  9655. isHovering.value = true;
  9656. }
  9657. };
  9658. const onMouseLeave = () => {
  9659. isHovering.value = false;
  9660. };
  9661. const isExpanded = computed(() => {
  9662. return menuMode.value === "collapse" && isHovering.value;
  9663. });
  9664. // v3.0 新增:iframe 懒加载,点击才加载 by xu 20251216
  9665. const loadedMenus = ref(new Set());
  9666. const isMenuLoaded = (menuName) => {
  9667. return loadedMenus.value.has(menuName);
  9668. };
  9669. // 根据标题找到对应的菜单项
  9670. const findMenuByTitle = (title) => {
  9671. for (const item of menuListComputed.value) {
  9672. //功能 by xu 20251222
  9673. if (item.children?.length > 0) {
  9674. const child = item.children.find((c) => c.title === title);
  9675. if (child) return child;
  9676. } else if (item.title === title) {
  9677. return item;
  9678. }
  9679. }
  9680. return null;
  9681. };
  9682. // 计算默认选中的菜单项
  9683. const defaultActiveMenu = computed(() => {
  9684. if (props.activeMenu) {
  9685. const menu = findMenuByTitle(props.activeMenu);
  9686. if (menu) return menu;
  9687. }
  9688. const firstItem = menuListComputed.value[0]; //功能 by xu 20251222
  9689. if (!firstItem) return null;
  9690. //功能: 默认选中第一个一级菜单(不默认跳到第一个二级)by xu 20251224
  9691. return firstItem;
  9692. });
  9693. const currentMenu = ref(defaultActiveMenu.value);
  9694. // 监听外部activeMenu变化
  9695. watch(
  9696. () => props.activeMenu,
  9697. (newTitle) => {
  9698. if (newTitle) {
  9699. const menu = findMenuByTitle(newTitle);
  9700. if (menu) {
  9701. currentMenu.value = menu;
  9702. }
  9703. }
  9704. }
  9705. );
  9706. // 初始化:默认选中项加入已加载集合
  9707. watch(
  9708. currentMenu,
  9709. (menu) => {
  9710. if (menu?.name) {
  9711. loadedMenus.value.add(menu.name);
  9712. }
  9713. },
  9714. { immediate: true }
  9715. );
  9716. // 选择菜单项时触发 menu-change 钩子
  9717. const selectItem = (item) => {
  9718. currentMenu.value = item;
  9719. // 标记为已加载
  9720. if (item.name) {
  9721. loadedMenus.value.add(item.name);
  9722. }
  9723. emit("menu-change", item);
  9724. };
  9725. // 处理底部按钮点击
  9726. const handleFooterClick = (button, index) => {
  9727. emit("footer-click", { button, index });
  9728. };
  9729. return {
  9730. menuListComputed, //功能 by xu 20251222
  9731. currentMenu,
  9732. selectItem,
  9733. handleFooterClick,
  9734. getFooterIcon, //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  9735. menuMode,
  9736. isHovering,
  9737. isExpanded,
  9738. toggleMenuMode,
  9739. onMouseEnter,
  9740. onMouseLeave,
  9741. isMenuLoaded,
  9742. getMenuIcon,
  9743. isGroupOpen, //功能 by xu 20251222
  9744. toggleGroupOpen, //功能 by xu 20251222
  9745. getLevelClass, //功能 by xu 20251222
  9746. };
  9747. },
  9748. template: `
  9749. <div class="project-edit-container">
  9750. <div class="left-side"
  9751. v-if="leftDisplay"
  9752. :data-mode="menuMode"
  9753. :class="{ 'is-expanded': isExpanded }"
  9754. @mouseenter="onMouseEnter"
  9755. @mouseleave="onMouseLeave">
  9756. <!-- 菜单内容 -->
  9757. <div class="menu-content">
  9758. <div class="scroll-view">
  9759. <template v-for="(menuItem, i) in menuListComputed" :key="i">
  9760. <!-- 分组菜单 -->
  9761. <div v-if="menuItem.children?.length > 0" class="group">
  9762. <!-- 功能: 一级(pobj)可点击进入,箭头仅控制展开/收起;二级点击不影响一级选中状态 by xu 20251223 -->
  9763. <div class="menu-item"
  9764. :class="[getLevelClass(menuItem, 1), { active: menuItem.name === currentMenu?.name }]"
  9765. @click="selectItem(menuItem)">
  9766. <ss-icon :class="getMenuIcon(menuItem, i)" />
  9767. <span class="menu-label">{{ menuItem.title }}</span>
  9768. <!-- 功能: 一级菜单有子项时显示 dot(参考全局左侧菜单)by xu 20251224 -->
  9769. <div class="has-children-dot"></div>
  9770. <div class="menu-tooltip">{{ menuItem.title }}</div>
  9771. </div>
  9772. <!-- 功能: 二级菜单始终展示,不做收缩展开 by xu 20251223 -->
  9773. <div class="group-detail">
  9774. <div v-for="(item, j) in menuItem.children"
  9775. :key="j"
  9776. class="menu-item"
  9777. :class="[getLevelClass(item, 2), { active: item.name === currentMenu?.name }]"
  9778. @click.stop="selectItem(item)">
  9779. <ss-icon :class="getMenuIcon(item, j)" />
  9780. <span class="menu-label">{{ item.title }}</span>
  9781. </div>
  9782. </div>
  9783. </div>
  9784. <!-- 普通菜单项 -->
  9785. <div v-else
  9786. class="menu-item"
  9787. :class="[getLevelClass(menuItem, 1), { active: menuItem.name === currentMenu?.name }]"
  9788. @click="selectItem(menuItem)">
  9789. <ss-icon :class="getMenuIcon(menuItem, i)" />
  9790. <span class="menu-label">{{ menuItem.title }}</span>
  9791. <div class="menu-tooltip">{{ menuItem.title }}</div>
  9792. </div>
  9793. </template>
  9794. </div>
  9795. </div>
  9796. <!-- 底部按钮 -->
  9797. <div v-if="footerButtons.length > 0"
  9798. class="sub-tab-menu-footer"
  9799. :class="{ 'has-text': !!footerButtons[0].text }"
  9800. @click="footerButtons[0].onclick">
  9801. <ss-icon :class="getFooterIcon(footerButtons[0])" />
  9802. <div class="footer-label" v-if="footerButtons[0].text">{{ footerButtons[0].text }}</div>
  9803. <ss-icon v-if="footerButtons.length > 1" class="footer-arrow" name="arrow-up" size="24px" />
  9804. <div v-if="footerButtons.length > 1" class="sub-tab-menu-popup">
  9805. <div v-for="(button, index) in footerButtons.slice(1)"
  9806. :key="index"
  9807. @click.stop="button.onclick">
  9808. {{ button.text }}
  9809. </div>
  9810. </div>
  9811. </div>
  9812. </div>
  9813. <!-- 右侧内容区域 - 懒加载 iframe -->
  9814. <div class="content-area fit-height-content" style="overflow: hidden;" :style="!leftDisplay ? { width: '100%' } : {}">
  9815. <template v-for="(menuItem, i) in menuList" :key="i">
  9816. <iframe
  9817. v-if="isMenuLoaded(menuItem.name)"
  9818. :src="menuItem.url"
  9819. style="height: 100%;width: 100%;"
  9820. frameborder="0"
  9821. class="sub-tab-iframe"
  9822. :id="i === 0 ? 'sub-tab-iframe' : ''"
  9823. v-show="currentMenu?.name === menuItem.name"
  9824. />
  9825. </template>
  9826. </div>
  9827. </div>
  9828. `,
  9829. };
  9830. // <iframe
  9831. // v-if="currentMenu?.url"
  9832. // :src="currentMenu.url"
  9833. // style="height: 100%;width: 100%;"
  9834. // frameborder="0"
  9835. // id="sub-tab-iframe"
  9836. // />
  9837. // ss-photo-upload 通用图片上传组件
  9838. const SsImgUpload = {
  9839. name: "SsImgUpload",
  9840. props: {
  9841. name: {
  9842. type: String,
  9843. required: true,
  9844. },
  9845. // 图片URL,用于回显
  9846. // url: {
  9847. // type: String,
  9848. // default: "",
  9849. // },
  9850. // 样式类名
  9851. class: {
  9852. type: String,
  9853. required: true,
  9854. },
  9855. // 裁剪配置
  9856. cropperOpt: {
  9857. type: Object,
  9858. default: () => ({
  9859. width: 360,
  9860. height: 360,
  9861. aspectRatio: 1,
  9862. }),
  9863. },
  9864. //上传图片url(未加图片名参数之前的部分)
  9865. ulUrl: {
  9866. type: String,
  9867. required: true,
  9868. },
  9869. //下载图片url(未加图片名参数之前的部分)
  9870. dlUrl: {
  9871. type: String,
  9872. required: true,
  9873. },
  9874. modelValue: [String, Number],
  9875. },
  9876. emits: ["update:modelValue"],
  9877. setup(props, { emit }) {
  9878. const inputId = Vue.computed(
  9879. () => `file_${Vue.getCurrentInstance().uid}`
  9880. );
  9881. //修改图片初始显示路径
  9882. let pathVal = ref(props.modelValue);
  9883. let picUrl = ref("");
  9884. if (props.modelValue) {
  9885. picUrl.value = props.dlUrl + "&path=" + props.modelValue;
  9886. }
  9887. Vue.onMounted(() => {
  9888. window.SS.cropper.init({
  9889. el: $(`#${inputId.value}`),
  9890. photoSize: {
  9891. width: props.cropperOpt.width,
  9892. height: props.cropperOpt.height,
  9893. },
  9894. aspectRatio: props.cropperOpt.aspectRatio,
  9895. uploadUrl: props.ulUrl,
  9896. success: (path) => {
  9897. pathVal.value = path;
  9898. picUrl.value = props.dlUrl + "&path=" + path;
  9899. emit("update:modelValue", path);
  9900. },
  9901. });
  9902. });
  9903. return () =>
  9904. h("div", { class: [props.class] }, [
  9905. h("input", {
  9906. type: "file",
  9907. accept: "image/*",
  9908. id: inputId.value,
  9909. style: { display: "none" },
  9910. }),
  9911. h("input", {
  9912. type: "hidden",
  9913. name: props.name,
  9914. value: pathVal.value,
  9915. }),
  9916. h(
  9917. "div",
  9918. {
  9919. style: {
  9920. width: "100%",
  9921. height: "100%",
  9922. },
  9923. onClick: () => $(`#${inputId.value}`).click(),
  9924. },
  9925. [
  9926. picUrl.value &&
  9927. h("img", {
  9928. src: picUrl.value,
  9929. style:
  9930. "width: 100%; height: 100%;object-fit: inherit;position: relative;z-index: 11;",
  9931. }),
  9932. ]
  9933. ),
  9934. ]);
  9935. },
  9936. };
  9937. // 初始化函数,负责创建和挂载 Vue 应用
  9938. // window.SS = { dom: {} };
  9939. /**
  9940. * 获取当前窗口的父窗口
  9941. * @returns {Window} 父窗口对象
  9942. */
  9943. window.SS.topWin = (function (p, c) {
  9944. while (p != c) {
  9945. c = p;
  9946. p = p.parent;
  9947. }
  9948. return c;
  9949. })(window.parent, window);
  9950. window.SS.createSsDialogInstance = createSsDialogInstance;
  9951. /**
  9952. * 创建弹窗
  9953. * @param {Object} setting
  9954. * @param {Function} callbackEvent
  9955. */
  9956. window.SS.openDialog = function (setting, callbackEvent) {
  9957. if (setting.params) {
  9958. const encodedParams = encodeURIComponent(JSON.stringify(setting.params));
  9959. setting.src +=
  9960. (setting.src.includes("?") ? "&" : "?") + "params=" + encodedParams;
  9961. }
  9962. if (window.parent && window.parent !== window) {
  9963. window.parent.SS.createSsDialogInstance(setting, callbackEvent);
  9964. } else {
  9965. createSsDialogInstance(setting, callbackEvent);
  9966. }
  9967. };
  9968. //关闭弹窗
  9969. window.SS.closeDialog = function () {
  9970. console.log("关闭弹窗");
  9971. if (topWindow.dialogInstances.length > 0) {
  9972. const instance = topWindow.dialogInstances.pop();
  9973. console.log("instance", instance);
  9974. console.log("instance.callbackEvent", instance.callbackEvent);
  9975. console.log(
  9976. "instance.callbackEvent.end",
  9977. typeof instance.callbackEvent === "function"
  9978. );
  9979. if (instance.callbackEvent) {
  9980. // 判断是否有end回调并执行
  9981. if (typeof instance.callbackEvent === "function") {
  9982. instance.callbackEvent();
  9983. }
  9984. if (typeof instance.callbackEvent.end === "function") {
  9985. instance.callbackEvent.end();
  9986. }
  9987. }
  9988. instance.app.unmount(); // 卸载最后一个实例
  9989. if (instance.container && instance.container.parentNode) {
  9990. instance.container.parentNode.removeChild(instance.container); // 移除容器
  9991. }
  9992. }
  9993. };
  9994. /**
  9995. * 裁剪插件
  9996. */
  9997. window.SS.cropper = {
  9998. init: function (setting) {
  9999. if (!window.top.SS) window.top.SS = {};
  10000. // 重要:确保 cropper 对象的完整初始化
  10001. if (!window.top.SS.cropper) {
  10002. window.top.SS.cropper = {
  10003. settings: new Map(),
  10004. _backupSettings: {},
  10005. getSetting: this.getSetting,
  10006. clearSetting: this.clearSetting,
  10007. debug: this.debug,
  10008. };
  10009. } else if (!window.top.SS.cropper.settings) {
  10010. // 如果 cropper 存在但 settings 不存在,重新初始化 settings
  10011. window.top.SS.cropper.settings = new Map();
  10012. window.top.SS.cropper._backupSettings = {};
  10013. }
  10014. const uploaderId = `uploader_${Date.now()}_${Math.random()
  10015. .toString(36)
  10016. .substr(2, 9)}`;
  10017. window.top.SS.cropper.settings.set(uploaderId, setting);
  10018. window.top.SS.cropper._backupSettings[uploaderId] = setting;
  10019. setting.box = setting.box || "1";
  10020. var winSetting = {
  10021. headerTitle: "图片裁剪",
  10022. src: "/js/cropper/cropper.jsp", //原来在"/newUI/page/cropper.jsp" Ben(20251205)
  10023. width: "900",
  10024. height: "500",
  10025. };
  10026. $(setting.el).change(function () {
  10027. if (!window.SS.cropper.verify(setting)) {
  10028. $(setting.el).val(""); // 清空文件选择
  10029. return false;
  10030. }
  10031. var files = this.files;
  10032. if (files && files.length) {
  10033. if (!window.SS.cropper.verifySize($(setting.el)[0], 5)) {
  10034. $(setting.el).val(""); // 清空文件选择
  10035. alert("文件大小不能超过5M,请重新选择");
  10036. return false;
  10037. }
  10038. var URL = window.URL || window.webkitURL;
  10039. var file = files[0];
  10040. setting.file = file;
  10041. if (
  10042. /^image\/\w+$/.test(file.type) &&
  10043. /\.(jpg|jpeg|png|)$/i.test(file.name)
  10044. ) {
  10045. var uploadedImageURL = URL.createObjectURL(file);
  10046. setting.data = uploadedImageURL;
  10047. setting.fileName = file.name;
  10048. // console.log()
  10049. winSetting.params = {
  10050. ...setting,
  10051. uploaderId,
  10052. };
  10053. console.log("ss-componets中change之后的winSetting", winSetting);
  10054. SS.openDialog(winSetting, {
  10055. success: function (win) {
  10056. console.log("裁剪插件成功");
  10057. // win.cropperSetting = setting;
  10058. },
  10059. end: function () {
  10060. console.log("裁剪插件结束");
  10061. $(setting.el).val(""); // 清空文件选择
  10062. },
  10063. });
  10064. } else {
  10065. alert("请选择图片文件,支持jpg、jpeg、png格式");
  10066. }
  10067. }
  10068. });
  10069. return uploaderId;
  10070. },
  10071. verify: function (setting) {
  10072. if (!setting) {
  10073. console.error(" cropper setting is not undefined! ");
  10074. return false;
  10075. }
  10076. if (!setting.el) {
  10077. console.error(" cropper setting.el is not undefined! ");
  10078. return false;
  10079. }
  10080. if (setting.photoSize) {
  10081. if (
  10082. (!setting.photoSize.width && setting.photoSize.height) ||
  10083. (!setting.photoSize.height && setting.photoSize.width)
  10084. ) {
  10085. console.error(
  10086. " cropper setting.photoSize { width, height } is not undefined! "
  10087. );
  10088. return false;
  10089. }
  10090. }
  10091. if (!setting.box) {
  10092. setting.box = "1";
  10093. }
  10094. if (!setting.aspectRatio) {
  10095. setting.aspectRatio = 1 / 1;
  10096. }
  10097. return true;
  10098. },
  10099. verifySize: function (fileEl, maxSize) {
  10100. // 判断是否为IE浏览器: /msie/i.test(navigator.userAgent) 为一个简单正则
  10101. var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  10102. var fileSize = 0;
  10103. if (isIE && !fileEl.files) {
  10104. // IE浏览器
  10105. var filePath = fileEl.value; // 获得上传文件的绝对路径
  10106. var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
  10107. var file = fileSystem.GetFile(filePath);
  10108. fileSize = file.Size; // 文件大小,单位:b
  10109. } else {
  10110. // 非IE浏览器
  10111. fileSize = fileEl.files[0].size;
  10112. }
  10113. var size = fileSize / 1024 / 1024;
  10114. return !(size > maxSize);
  10115. },
  10116. // 获取特定上传组件的setting
  10117. getSetting: function (uploaderId) {
  10118. if (!window.top.SS?.cropper) {
  10119. console.warn("顶层窗口中未找到 SS.cropper");
  10120. return null;
  10121. }
  10122. // 优先从 Map 中获取
  10123. let setting = window.top.SS.cropper.settings.get(uploaderId);
  10124. // 如果 Map 中没有,尝试从备份中获取
  10125. if (!setting && window.top.SS.cropper._backupSettings[uploaderId]) {
  10126. console.log("从备份中恢复 setting");
  10127. setting = window.top.SS.cropper._backupSettings[uploaderId];
  10128. // 恢复到 Map 中
  10129. window.top.SS.cropper.settings.set(uploaderId, setting);
  10130. }
  10131. return setting;
  10132. },
  10133. // 清理特定上传组件的setting
  10134. clearSetting: function (uploaderId) {
  10135. if (!window.top.SS?.cropper) return;
  10136. window.top.SS.cropper.settings.delete(uploaderId);
  10137. delete window.top.SS.cropper._backupSettings[uploaderId];
  10138. console.log(
  10139. "清理设置后的 Map size:",
  10140. window.top.SS.cropper.settings.size
  10141. );
  10142. },
  10143. };
  10144. /**
  10145. * 获取url中的参数
  10146. * @returns {Object}
  10147. */
  10148. window.SS.getQueryParams = function () {
  10149. const params = {};
  10150. const queryString = window.location.search.substring(1);
  10151. const pairs = queryString.split("&");
  10152. for (let i = 0; i < pairs.length; i++) {
  10153. const pair = pairs[i].split("=");
  10154. params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  10155. }
  10156. if (params.params) {
  10157. try {
  10158. params.params = JSON.parse(params.params);
  10159. } catch (e) {
  10160. console.error("Failed to parse params:", e);
  10161. }
  10162. }
  10163. return params;
  10164. };
  10165. /**
  10166. * 创建vue应用
  10167. * @param {Object} config 配置项
  10168. * @values {String} config.el 挂载的元素
  10169. * @values {Boolean} config.isDialogPage 是否是弹窗页面 决定了是否可以使用顶天立地
  10170. * @values {Object} config.vueOptions vue配置项
  10171. * @returns {Object} vue实例
  10172. */
  10173. window.ss = window.ss || window.SS;
  10174. window.ss.dom = window.ss.dom || window.SS.dom;
  10175. window.SS.dom._vueAppSeq =
  10176. window.SS.dom._vueAppSeq || window.ss.dom._vueAppSeq || 0;
  10177. window.SS.dom.vueApps = window.SS.dom.vueApps || window.ss.dom.vueApps || [];
  10178. window.ss.dom._vueAppSeq = window.SS.dom._vueAppSeq;
  10179. window.ss.dom.vueApps = window.SS.dom.vueApps;
  10180. window.SS.dom._registerVueApp = function ({ vm, el, appKey, scope, href }) {
  10181. if (!vm) return null;
  10182. const registry = window.SS.dom.vueApps || (window.SS.dom.vueApps = []);
  10183. const id = `vue-app-${++window.SS.dom._vueAppSeq}`;
  10184. const record = {
  10185. id,
  10186. el: el || "",
  10187. appKey: appKey || "",
  10188. scope: scope || "current",
  10189. href: href || window.location.href,
  10190. createdAt: Date.now(),
  10191. vm,
  10192. win: window,
  10193. };
  10194. registry.push(record);
  10195. window.SS.dom.currentApp = vm;
  10196. window.SS.dom.currentAppRecord = record;
  10197. if (window.ss && window.ss.dom) {
  10198. window.ss.dom.vueApps = registry;
  10199. window.ss.dom._vueAppSeq = window.SS.dom._vueAppSeq;
  10200. window.ss.dom.currentApp = vm;
  10201. window.ss.dom.currentAppRecord = record;
  10202. }
  10203. return record;
  10204. };
  10205. window.SS.dom._getVmData = function (vm) {
  10206. if (!vm) return null;
  10207. return vm.$data || vm;
  10208. };
  10209. window.SS.dom._hasVmKey = function (vm, key) {
  10210. if (!vm || !key) return false;
  10211. const data = window.SS.dom._getVmData(vm);
  10212. return key in vm || (!!data && key in data);
  10213. };
  10214. window.SS.dom._hasVmMethod = function (vm, methodName) {
  10215. return !!(vm && methodName && typeof vm[methodName] === "function");
  10216. };
  10217. window.SS.dom._normalizeBridgeOptions = function (
  10218. options = {},
  10219. defaults = {}
  10220. ) {
  10221. return {
  10222. scope: "chain",
  10223. ...defaults,
  10224. ...options,
  10225. };
  10226. };
  10227. window.SS.dom._matchVueRecord = function (record, options = {}) {
  10228. if (!record || !record.vm) return false;
  10229. if (options.appKey && record.appKey !== options.appKey) return false;
  10230. if (options.el && record.el !== options.el) return false;
  10231. if (options.id && record.id !== options.id) return false;
  10232. if (
  10233. options.dataKey &&
  10234. !window.SS.dom._hasVmKey(record.vm, options.dataKey)
  10235. ) {
  10236. return false;
  10237. }
  10238. if (
  10239. options.methodName &&
  10240. !window.SS.dom._hasVmMethod(record.vm, options.methodName)
  10241. ) {
  10242. return false;
  10243. }
  10244. if (typeof options.predicate === "function") {
  10245. try {
  10246. if (!options.predicate(record.vm, record)) {
  10247. return false;
  10248. }
  10249. } catch (e) {
  10250. return false;
  10251. }
  10252. }
  10253. return true;
  10254. };
  10255. window.SS.dom._getWindowVueRecord = function (targetWindow, options = {}) {
  10256. if (!targetWindow || !targetWindow.SS || !targetWindow.SS.dom) return null;
  10257. const registry = targetWindow.SS.dom.vueApps || [];
  10258. for (let i = registry.length - 1; i >= 0; i--) {
  10259. if (targetWindow.SS.dom._matchVueRecord(registry[i], options)) {
  10260. return registry[i];
  10261. }
  10262. }
  10263. const currentRecord = targetWindow.SS.dom.currentAppRecord;
  10264. if (targetWindow.SS.dom._matchVueRecord(currentRecord, options)) {
  10265. return currentRecord;
  10266. }
  10267. const currentVm = targetWindow.SS.dom.currentApp;
  10268. const fallbackRecord = currentVm
  10269. ? {
  10270. vm: currentVm,
  10271. win: targetWindow,
  10272. el: "",
  10273. appKey: "",
  10274. id: "",
  10275. }
  10276. : null;
  10277. if (targetWindow.SS.dom._matchVueRecord(fallbackRecord, options)) {
  10278. return fallbackRecord;
  10279. }
  10280. return null;
  10281. };
  10282. window.SS.dom.getVueAppRecord = function (options = {}) {
  10283. const scope = options.scope || "current";
  10284. if (scope === "current") {
  10285. return window.SS.dom._getWindowVueRecord(window, options);
  10286. }
  10287. if (scope === "top") {
  10288. try {
  10289. return window.SS.dom._getWindowVueRecord(window.top, options);
  10290. } catch (e) {
  10291. return null;
  10292. }
  10293. }
  10294. if (scope === "parent") {
  10295. try {
  10296. if (window.parent && window.parent !== window) {
  10297. return window.SS.dom._getWindowVueRecord(window.parent, options);
  10298. }
  10299. } catch (e) {
  10300. return null;
  10301. }
  10302. return null;
  10303. }
  10304. if (scope === "chain") {
  10305. let currentWindow = window;
  10306. while (currentWindow) {
  10307. try {
  10308. const record = window.SS.dom._getWindowVueRecord(
  10309. currentWindow,
  10310. options
  10311. );
  10312. if (record) {
  10313. return record;
  10314. }
  10315. } catch (e) {
  10316. return null;
  10317. }
  10318. if (currentWindow === currentWindow.parent) {
  10319. break;
  10320. }
  10321. currentWindow = currentWindow.parent;
  10322. }
  10323. return null;
  10324. }
  10325. return window.SS.dom._getWindowVueRecord(window, options);
  10326. };
  10327. window.SS.dom.getVueApp = function (options = {}) {
  10328. const record = window.SS.dom.getVueAppRecord(options);
  10329. return record ? record.vm : null;
  10330. };
  10331. window.SS.dom.getVmValue = function (key, options = {}) {
  10332. const vm = window.SS.dom.getVueApp(
  10333. window.SS.dom._normalizeBridgeOptions(options, { dataKey: key })
  10334. );
  10335. if (!vm) return undefined;
  10336. return vm[key];
  10337. };
  10338. window.SS.dom.setVmValue = function (key, value, options = {}) {
  10339. const vm = window.SS.dom.getVueApp(
  10340. window.SS.dom._normalizeBridgeOptions(options, { dataKey: key })
  10341. );
  10342. if (!vm) return false;
  10343. vm[key] = value;
  10344. return true;
  10345. };
  10346. window.SS.dom.callVmMethod = function (methodName, args = [], options = {}) {
  10347. const vm = window.SS.dom.getVueApp(
  10348. window.SS.dom._normalizeBridgeOptions(options, { methodName })
  10349. );
  10350. if (!vm || typeof vm[methodName] !== "function") {
  10351. return undefined;
  10352. }
  10353. return vm[methodName].apply(vm, args);
  10354. };
  10355. window.SS.dom.get = function (key, options = {}) {
  10356. return window.SS.dom.getVmValue(key, options);
  10357. };
  10358. window.SS.dom.set = function (key, value, options = {}) {
  10359. return window.SS.dom.setVmValue(key, value, options);
  10360. };
  10361. window.SS.dom.call = function (methodName, args = [], options = {}) {
  10362. return window.SS.dom.callVmMethod(methodName, args, options);
  10363. };
  10364. [
  10365. "_registerVueApp",
  10366. "_getVmData",
  10367. "_hasVmKey",
  10368. "_hasVmMethod",
  10369. "_normalizeBridgeOptions",
  10370. "_matchVueRecord",
  10371. "_getWindowVueRecord",
  10372. "getVueAppRecord",
  10373. "getVueApp",
  10374. "getVmValue",
  10375. "setVmValue",
  10376. "callVmMethod",
  10377. "get",
  10378. "set",
  10379. "call",
  10380. ].forEach((name) => {
  10381. window.ss.dom[name] = window.SS.dom[name];
  10382. });
  10383. window.SS.dom.initializeFormApp = function (config) {
  10384. const {
  10385. el,
  10386. isDialogPage = false,
  10387. appKey = "",
  10388. scope = "current",
  10389. ...vueOptions
  10390. } = config;
  10391. const app = createApp({
  10392. ...vueOptions,
  10393. });
  10394. if (isDialogPage) {
  10395. function checkScroll() {
  10396. const elements = document.querySelectorAll(".fit-height-content");
  10397. let hasScrollBar = false;
  10398. elements.forEach((el) => {
  10399. if (el.scrollHeight > el.clientHeight) {
  10400. hasScrollBar = true;
  10401. }
  10402. });
  10403. window.parent.postMessage({ hasScrollBar }, "*");
  10404. }
  10405. function addScrollListeners() {
  10406. const elements = document.querySelectorAll("div");
  10407. elements.forEach((el) => {
  10408. el.addEventListener("scroll", checkScroll);
  10409. });
  10410. }
  10411. const observer = new MutationObserver(() => {
  10412. addScrollListeners();
  10413. checkScroll();
  10414. });
  10415. observer.observe(document.body, {
  10416. childList: true,
  10417. subtree: true,
  10418. });
  10419. window.addEventListener("resize", checkScroll);
  10420. }
  10421. app.component("SsLoginIcon", SsLoginIcon);
  10422. app.component("SsMark", SsMark);
  10423. app.component("SsFullStyleHeader", SsFullStyleHeader);
  10424. app.component("SsDialog", SsDialog);
  10425. app.component("SsInp", SsInput);
  10426. app.component("SsObjp", SsObjp);
  10427. app.component("SsHidden", SsHidden);
  10428. app.component("SsCcp", SsCcp);
  10429. app.component("SsDatePicker", SsDatePicker);
  10430. app.component("SsIcon", SsIcon);
  10431. app.component("SsCommonIcon", SsCommonIcon);
  10432. app.component("SsBreadcrumb", SsBreadcrumb);
  10433. app.component("SsEditor", SsEditor);
  10434. app.component("SsDialogIcon", SsDialogIcon);
  10435. app.component("SsBottomButton", SsBottomButton);
  10436. app.component("SsNavIcon", SsNavIcon);
  10437. app.component("SsHeaderIcon", SsHeaderIcon);
  10438. app.component("SsGolbalMenuIcon", SsGolbalMenuIcon);
  10439. app.component("SsCartListIcon", SsCartListIcon);
  10440. app.component("SsQuickIcon", SsQuickIcon);
  10441. app.component("SsFormIcon", SsFormIcon);
  10442. app.component("SsBottomDivIcon", SsBottomDivIcon);
  10443. app.component("SsEditorIcon", SsEditorIcon);
  10444. app.component("SsValidate", SsValidate);
  10445. app.component("SsOnoff", Ssonoff);
  10446. app.component("SsonoffArray", SsonoffArray);
  10447. app.component("SsTextarea", SsTextarea);
  10448. app.component("SsLoginInput", SsLoginInput);
  10449. app.component("SsLoginButton", SsLoginButton);
  10450. app.component("SsSearch", SsSearch);
  10451. app.component("SsCartItem", SsCartItem);
  10452. app.component("SsCartItem2", SsCartItem2);
  10453. app.component("SsListCard", SsListCard);
  10454. app.component("ss-cobj-card-list", SsCObjCardList);
  10455. app.component("SsFolderCard", SsFolderCard);
  10456. app.component("ss-sidebar", SsSidebar);
  10457. app.component("ss-sidebar-buttons", SsSidebarButtons);
  10458. app.component("ss-sidebar-chart", SsSidebarChart);
  10459. app.component("ss-sidebar-chart-hover", SsSidebarChartHover);
  10460. app.component("ss-sidebar-list", SsSidebarList);
  10461. app.component("ss-sidebar-report-table", SsSidebarReportTable);
  10462. app.component("SsFolderCartView", SsFolderCartView);
  10463. app.component("SsPage", SsPage);
  10464. app.component("SsRightInfo", SSRightInfo);
  10465. app.component("SsSuccessPopup", SsSuccessPopup);
  10466. app.component("SsErrorDialog", SsErrorDialog);
  10467. app.component("SsVerify", SsVerify);
  10468. app.component("SsVerifyNode", SsVerifyNode);
  10469. app.component("SsOrcImgBox", SsOrcImgBox);
  10470. app.component("ss-search-input", SsSearchInput);
  10471. app.component("ss-search-date-picker", SsSearchDatePicker);
  10472. app.component("ss-search-button", SsSearchButton);
  10473. app.component("ss-drop-button", SsDropButton);
  10474. app.component("ss-sub-tab", SsSubTab);
  10475. app.component("ss-img", SsImgUpload);
  10476. app.use(ElementPlus, {
  10477. locale: ElementPlusLocaleZhCn,
  10478. });
  10479. for (const componentName in IndexComponents) {
  10480. app.component(componentName, IndexComponents[componentName]);
  10481. }
  10482. for (const componentName in EchartComponents) {
  10483. app.component(componentName, EchartComponents[componentName]);
  10484. }
  10485. let vm;
  10486. try {
  10487. vm = app.mount(el);
  10488. vm.data = vueOptions.data();
  10489. window.SS.dom._registerVueApp({
  10490. vm,
  10491. el,
  10492. appKey,
  10493. scope,
  10494. href: window.location.href,
  10495. });
  10496. console.log("vm:", vm);
  10497. console.log("vueOptions:", vueOptions);
  10498. } catch (error) {
  10499. console.log("Mount failed:" + error);
  10500. }
  10501. return vm;
  10502. };
  10503. })();