ss-components.js 402 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087
  1. import {commonIcon, ssIcon} from "./icon-config.js";
  2. import * as IndexComponents from "./ss-index-components.js";
  3. import * as EchartComponents from "./ss-echarts-compnents.js";
  4. import {buildThumbUrl, isNum, toStyleStr,} from "./tools.js"; // 功能说明:组件内统一构建缩略图URL、打开服务弹窗,减少 JSP 层字段转换 by xu 20260122
  5. import {EVEN_VAR} from "./EventBus.js";
  6. // import * as elements from "../lib/element-plus.js";
  7. (function () {
  8. const {
  9. createApp,
  10. ref,
  11. reactive,
  12. watch,
  13. onMounted,
  14. onBeforeUnmount,
  15. h,
  16. computed,
  17. resolveComponent,
  18. watchEffect,
  19. nextTick,
  20. onVnodeMounted,
  21. Teleport,
  22. inject,
  23. provide,
  24. } = Vue;
  25. // 弹窗默认遮罩z-index
  26. let currentZIndex = 100;
  27. // 目前已存在的弹窗
  28. const topWindow = window.top;
  29. topWindow.dialogInstances = topWindow.dialogInstances || [];
  30. // 新建弹窗
  31. function createSsDialogInstance(setting, callbackEvent) {
  32. currentZIndex += 10; // 动态提升 z-index
  33. const container = document.createElement("div");
  34. document.body.appendChild(container);
  35. const app = Vue.createApp({
  36. render() {
  37. return h(SsDialog, {
  38. ...setting,
  39. zIndex: currentZIndex,
  40. onClose() {
  41. document.body.removeChild(container); // 仅移除弹窗容器
  42. const index = topWindow.dialogInstances.indexOf(app);
  43. if (index > -1) {
  44. topWindow.dialogInstances.splice(index, 1); // 移除实例
  45. }
  46. // 关闭后的回调
  47. if (callbackEvent && typeof callbackEvent === "function") {
  48. callbackEvent();
  49. }
  50. app.unmount(); // 仅卸载弹窗实例
  51. if (container.parentNode) {
  52. container.parentNode.removeChild(container); // 确保移除容器
  53. }
  54. },
  55. });
  56. },
  57. });
  58. topWindow.dialogInstances.push({ app, callbackEvent, container });
  59. app.component("ss-mark", SsMark); // 注册 ss-mark 组件
  60. app.component("ss-icon", SsIcon);
  61. app.component("ss-full-style-header", SsFullStyleHeader); // 注册 ss-full-style-header 组件
  62. app.mount(container);
  63. }
  64. // ss-breadcrumb 一级菜单页面面包屑
  65. const SsBreadcrumb = {
  66. name: "SsBreadcrumb",
  67. props: {
  68. level: {
  69. type: Object,
  70. default: null,
  71. },
  72. },
  73. setup(props) {
  74. const currentMenu = ref(null);
  75. const folderPath = ref([]);
  76. const eventBus = window.parent.sharedEventBus;
  77. // 监听页面变化
  78. onMounted(() => {
  79. // 获取初始页面
  80. currentMenu.value = eventBus.getState(EVEN_VAR.currentPage);
  81. folderPath.value = eventBus.getState("folderPath") || [];
  82. // 订阅页面变化
  83. eventBus.subscribe(EVEN_VAR.currentPage, (page) => {
  84. currentMenu.value = page;
  85. });
  86. eventBus.subscribe("folderPath", (path) => {
  87. folderPath.value = path || [];
  88. });
  89. });
  90. // 修改点击处理函数
  91. const handlePathClick = (index) => {
  92. if (props.level?.onBack) {
  93. // 截取到点击的位置,后面的路径会被销毁
  94. const newPath = folderPath.value.slice(0, index + 1);
  95. eventBus.publish("folderPath", newPath);
  96. // 返回到对应层级
  97. const targetFolder = newPath[newPath.length - 1]?.folder || null;
  98. props.level.onBack(targetFolder);
  99. }
  100. };
  101. const SsCommonIcon = resolveComponent("SsCommonIcon");
  102. return () =>
  103. h("div", { class: "bread-crumb" }, [
  104. currentMenu.value &&
  105. h(
  106. "div",
  107. {
  108. onClick: () => {
  109. if (props.level?.onBack) {
  110. eventBus.publish("folderPath", []);
  111. props.level.onBack(null); // 返回到根目录
  112. } else {
  113. eventBus.publish(EVEN_VAR.currentPage, currentMenu.value);
  114. }
  115. },
  116. },
  117. currentMenu.value.label || currentMenu.value.name
  118. ),
  119. ...(folderPath.value || [])
  120. .map((folder, index) => [
  121. h(SsCommonIcon, { class: "common-icon-arrow-right" }),
  122. h(
  123. "div",
  124. {
  125. class: "bread-crumb-item",
  126. onClick: () => handlePathClick(index),
  127. style: { cursor: "pointer" },
  128. },
  129. folder.title
  130. ),
  131. ])
  132. .flat(),
  133. ]);
  134. },
  135. };
  136. // ss-input form表单的输入
  137. const SsInput = {
  138. name: "SsInp", //把SsInput改为SsInp Ben(20251225)
  139. inheritAttrs: false, // 不直接继承属性到组件根元素
  140. props: {
  141. name: {
  142. type: String,
  143. required: true,
  144. default: "",
  145. },
  146. // 接收 v-model 绑定的值
  147. errTip: {
  148. type: String,
  149. },
  150. required: {
  151. type: Boolean,
  152. default: false,
  153. },
  154. placeholder: {
  155. type: String,
  156. default: "", // : "请输入",。再改,去掉 placeholder 默认值 "请输入" 。Lin
  157. },
  158. defaultValue: [String, Number],
  159. modelValue: [String, Number],
  160. // 新增:附件配置
  161. fj: {
  162. type: Object,
  163. default: null,
  164. },
  165. // 新增:param 配置(用于附件功能)
  166. param: {
  167. type: Object,
  168. default: null,
  169. },
  170. // 新增:高度配置
  171. height: {
  172. type: String,
  173. default: "",
  174. },
  175. // 功能说明:传 height 时允许回车换行(多行输入);未传 height 默认单行 by xu 20260204
  176. // 功能说明:onChange 全局回调 prop,桥接 API 赋值时自动触发 by xu 20260416
  177. onchange: {
  178. type: String,
  179. required: false,
  180. },
  181. },
  182. emits: ["update:modelValue", "input", "blur", "change"], // 允许更新 v-model 绑定的值
  183. setup(props, { emit }) {
  184. const errMsg = ref("");
  185. const inputRef = ref(null);
  186. const textareaRef = ref(null);
  187. const inputValue = ref(props.modelValue || props.defaultValue || "");
  188. const contentFloatingDiv = ref(false); // 控制浮动 DIV 的显示
  189. const floatingDivPosition = ref("bottom"); // 'bottom' 或 'top'
  190. const isFocused = ref(false); // 跟踪焦点状态
  191. // 附件相关变量(仅在传入 param 时初始化)
  192. let fjid = ref(null);
  193. let fjName = null;
  194. let mode = null;
  195. if (props.param && props.param.button) {
  196. fjid = ref(props.param.button.val);
  197. fjName = props.param.button.desc;
  198. mode = props.param.mode;
  199. }
  200. // 功能说明:只有存在非空校验(notNull)且值为空时,才显示红线 by xu 20260402
  201. const hasNotNullRule = () => {
  202. const validations = window.ssVm?.validations?.get(props.name);
  203. if (!validations || validations.length === 0) return false;
  204. return validations.some(v => v.ruleName && v.ruleName.includes('notNull'));
  205. };
  206. const showRequired = computed(() => {
  207. const validations = window.ssVm?.validations?.get(props.name);
  208. if (!validations || validations.length === 0) return false;
  209. // 检查是否存在 notNull 规则
  210. const hasNotNull = validations.some(v => v.ruleName && v.ruleName.includes('notNull'));
  211. // 有非空规则且值为空时显示红线
  212. if (hasNotNull && !inputValue.value) {
  213. return true;
  214. }
  215. return false;
  216. });
  217. // 计算floatdiv应该向上还是向下展开
  218. const calculateFloatingDivPosition = () => {
  219. nextTick(() => {
  220. const textarea = inputRef.value;
  221. if (!textarea) return;
  222. const rect = textarea.getBoundingClientRect();
  223. /* 改,改用 <div class='content-div' 的高度 -- 支持 <input height=。Lin
  224. * 原,基于录入窗口的高度计算,但弹出的 growh 录入框是在 <table 里的,导致 <table 的顶上被滚走,且 弹出的 growh 录入框 下部被截断 -- 再次进入时,完全被截断
  225. const viewportHeight = window.innerHeight;
  226. */ const contDivRect = document.querySelector('.content-div').getBoundingClientRect();
  227. // 预估floatdiv的高度(最多5行 * 20px + 上下padding + border)
  228. /* 再改。Lin
  229. const estimatedFloatDivHeight = 20 * 5 + 10 + 2; // 5行 + padding + border = 112px
  230. */
  231. const lineHeight = parseInt(getComputedStyle(textarea).lineHeight, 10);
  232. const estimatedFloatDivHeight = lineHeight * 5 + 10 + 2;
  233. // 检查下方空间
  234. /* 改,改用 <div class='content-div' 的高度 -- 支持 <input height=。Lin
  235. const spaceBelow = viewportHeight - rect.bottom;
  236. */ const spaceBelow = contDivRect.bottom - rect.top -5; // 底下留 5 个空白。Lin
  237. /// 增加,如果高度不够 5行,减少 growh 录入框的高度。Lin
  238. const spaceAbove = rect.bottom - contDivRect.top -5; // 顶上留 5 个空白。Lin
  239. ///
  240. // 如果下方空间不足,且上方空间足够,则向上展开
  241. /* 改,支持 <input height=。Lin
  242. * 高度够时,需要优先向上 growh -- 对于有 <input height=,统一在底下留 5 个空白
  243. * 增加 "如果高度不够 5行,减少 growh 录入框的高度" -- 抄自 SsObjp.calculatePopupDirection()
  244. if (
  245. spaceBelow < estimatedFloatDivHeight &&
  246. rect.top > estimatedFloatDivHeight
  247. ) {
  248. floatingDivPosition.value = "top";
  249. } else {
  250. floatingDivPosition.value = "bottom";
  251. }
  252. */
  253. if (spaceAbove >= estimatedFloatDivHeight) { // "上方空间足够,向上展开,不限制高度"。Lin
  254. floatingDivPosition.value = "top";
  255. } else if (spaceBelow >= estimatedFloatDivHeight) { // "下方空间足够,向下展开,不限制高度"。Lin
  256. floatingDivPosition.value = "bottom";
  257. } else { // "上下空间都不足,选择空间大的方向,并限制高度出滚动条"。Lin
  258. let growhDivHeight; // 增加,减少后的高度。Lin
  259. if (spaceBelow >= spaceAbove) {
  260. floatingDivPosition.value = "bottom";
  261. growhDivHeight = spaceBelow; // popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px"。Lin
  262. } else {
  263. floatingDivPosition.value = "top";
  264. growhDivHeight = spaceAbove; // popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px"。Lin
  265. }
  266. /// 增加,写 增加的全局变量 --growh-textarea-max-height(带px)。Lin
  267. document.documentElement.style.setProperty('--growh-textarea-max-height', growhDivHeight +"px");
  268. ///
  269. }
  270. });
  271. };
  272. // 计算floatdiv的top偏移量
  273. const getFloatingDivTop = computed(() => {
  274. if (props.height) {
  275. // 有height时,padding是5px
  276. return "5px";
  277. } else {
  278. // 没有height时是单行居中,需要计算居中位置
  279. // 假设input-container高度是32px(或者从CSS读取),单行20px
  280. // 居中偏移 = (容器高度 - 行高) / 2 = (32 - 20) / 2 = 6px
  281. return "6px";
  282. }
  283. });
  284. const validate = () => {
  285. if (window.ssVm) {
  286. const result = window.ssVm.validateField(props.name);
  287. errMsg.value = result.valid ? "" : result.message;
  288. }
  289. };
  290. // 功能说明:调用全局 onChange 回调 by xu 20260416
  291. const callGlobalOnchg = (value) => {
  292. if (props.onchange && typeof props.onchange === "string") {
  293. if (
  294. typeof window !== "undefined" &&
  295. window[props.onchange] &&
  296. typeof window[props.onchange] === "function"
  297. ) {
  298. try {
  299. window[props.onchange](value);
  300. } catch (error) {
  301. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  302. }
  303. }
  304. }
  305. };
  306. // 使用 watch 监听 props.errTip 和 props.modelValue 的变化
  307. watch(
  308. () => props.errTip,
  309. (newVal) => {
  310. errMsg.value = newVal;
  311. },
  312. { immediate: true }
  313. );
  314. watch(
  315. () => props.modelValue,
  316. (newVal) => {
  317. inputValue.value = newVal;
  318. // 桥接 API 赋值时触发全局 onChange by xu 20260416
  319. callGlobalOnchg(newVal);
  320. }
  321. );
  322. // 挂载时的逻辑
  323. onMounted(() => {
  324. errMsg.value = props.errTip;
  325. inputValue.value = props.modelValue || props.defaultValue || "";
  326. });
  327. // 计算并调整textarea的高度
  328. const adjustHeight = () => {
  329. nextTick(() => {
  330. const textarea = textareaRef.value;
  331. if (!textarea) return;
  332. // floatDiv的textarea始终自动计算高度,不受props.height影响
  333. // 重置高度以获得正确的scrollHeight
  334. textarea.style.height = "auto";
  335. // 计算新高度 - 统一限制为5行
  336. const lineHeight = parseInt(
  337. getComputedStyle(textarea).lineHeight,
  338. 10
  339. );
  340. const maxHeight = lineHeight * 5; // 统一为5行
  341. /* 改,支持 <input height=。Lin
  342. * 原 height= 大于 5 行时,仍弹出 5 行 -- base.css 里的样式 .floating-div textarea 里的属性 max-height: calc(20px * 5 + 10px),写死 5 行
  343. * 增加全局变量 --growh-textarea-max-height(带px),并把 max-height: 改为 var(--growh-textarea-max-height)
  344. const newHeight = Math.min(textarea.scrollHeight, maxHeight);
  345. */
  346. let newHeight;
  347. if (!props.height || (parseInt(props.height, 10) <= maxHeight))
  348. newHeight = Math.min(textarea.scrollHeight, maxHeight);
  349. else // 有 <input height=,且高于 5 行。Lin
  350. newHeight = parseInt(props.height, 10);
  351. newHeight -= 5; // 底下留 5 个空白。Lin
  352. document.documentElement.style.setProperty('--growh-textarea-max-height', newHeight +"px");
  353. textarea.style.height = `${newHeight}px`;
  354. });
  355. };
  356. // 检查是否应该显示浮动窗口(需要同时满足:有焦点 + 内容超出)
  357. // 修复新增页面点击就出现floatdiv的问题 by xu 20251212
  358. const checkShouldShowFloatingDiv = () => {
  359. const textarea = inputRef.value;
  360. if (!textarea) return false;
  361. // 首先检查是否有内容,没有内容时不显示floatdiv by xu 20251212
  362. if (!inputValue.value || inputValue.value.toString().trim() === "") {
  363. console.log("[floatdiv] 内容为空,不显示floatdiv");
  364. return false;
  365. }
  366. // 判断内容是否超出 by xu 20251212
  367. // 同时检查横向和纵向溢出,任一方向溢出都应显示floatdiv
  368. // 纵向溢出需要加容差值,避免padding/border导致的误判 by xu 20251212
  369. const verticalTolerance = 5; // 容差值5px
  370. const isHorizontalOverflow =
  371. textarea.scrollWidth > textarea.clientWidth;
  372. const isVerticalOverflow =
  373. textarea.scrollHeight > textarea.clientHeight + verticalTolerance;
  374. const isOverflow = isHorizontalOverflow || isVerticalOverflow;
  375. console.log(
  376. "[floatdiv] 溢出检测 - scrollWidth:",
  377. textarea.scrollWidth,
  378. "clientWidth:",
  379. textarea.clientWidth,
  380. "horizontalOverflow:",
  381. isHorizontalOverflow
  382. );
  383. console.log(
  384. "[floatdiv] 溢出检测 - scrollHeight:",
  385. textarea.scrollHeight,
  386. "clientHeight:",
  387. textarea.clientHeight,
  388. "tolerance:",
  389. verticalTolerance,
  390. "verticalOverflow:",
  391. isVerticalOverflow
  392. );
  393. const shouldShow = isFocused.value && isOverflow;
  394. console.log(
  395. "[floatdiv] 最终判断 - isFocused:",
  396. isFocused.value,
  397. "isOverflow:",
  398. isOverflow,
  399. "shouldShow:",
  400. shouldShow
  401. );
  402. // 需要同时满足:有焦点 + 内容超出
  403. return shouldShow;
  404. };
  405. // 定义事件处理函数
  406. const onInput = (event) => {
  407. const newValue = event.target.value;
  408. inputValue.value = newValue;
  409. emit("update:modelValue", newValue);
  410. validate(); // 输入时验证
  411. nextTick(() => {
  412. // 检查是否需要显示浮动div
  413. contentFloatingDiv.value = checkShouldShowFloatingDiv();
  414. // 如果需要显示floatdiv,计算其位置
  415. if (contentFloatingDiv.value) {
  416. calculateFloatingDivPosition();
  417. }
  418. });
  419. adjustHeight();
  420. };
  421. const onFocus = (event) => {
  422. // 设置焦点状态为true
  423. isFocused.value = true;
  424. adjustHeight();
  425. // 检查是否应该显示浮动窗口
  426. nextTick(() => {
  427. contentFloatingDiv.value = checkShouldShowFloatingDiv();
  428. if (contentFloatingDiv.value) {
  429. calculateFloatingDivPosition();
  430. }
  431. });
  432. };
  433. // 失去焦点时进行验证
  434. const onBlur = (event) => {
  435. emit("blur", event.target);
  436. validate(); // 失焦时验证
  437. nextTick(() => {
  438. // 如果焦点不在 textarea 上,则隐藏浮动 div
  439. if (!document.activeElement.classList.contains("input-control")) {
  440. isFocused.value = false;
  441. contentFloatingDiv.value = false;
  442. }
  443. });
  444. };
  445. const onChange = (event) => {
  446. inputValue.value = event.target.value || "";
  447. emit("change", inputValue.value);
  448. };
  449. const onMouseover = (event) => {
  450. nextTick(() => {
  451. // setTimeout(contentFloatingDiv.value = true, 500)
  452. });
  453. };
  454. const onMouseleave = (event) => {
  455. // contentFloatingDiv.value = false
  456. };
  457. // 功能说明:传了 height 视为多行允许回车;未传 height 拦截回车(单行表现) by xu 20260204
  458. const onKeydown = (event) => {
  459. const allowMultiline =
  460. typeof props.height === "string" && props.height.trim() !== "";
  461. if (!allowMultiline && event.key === "Enter") {
  462. event.preventDefault();
  463. }
  464. };
  465. // 增加 <div class="input" 的 onClick 事件 -- 支持点击 <div 进入录入行。Lin
  466. const onInputDivClick = (event) => {
  467. if (!event.target.id) // 点击的是 <textarea 时,没有 .id -- <div class="input" 包含 <textarea。Lin
  468. return;
  469. console.log("<div class='input' 被点击了");
  470. const textArea = document.getElementsByName(event.target.id)[0];
  471. if (!textArea) // 点击 描述 录入框里的 附件按钮时,textArea 为空。Lin
  472. return;
  473. const rect = textArea.getBoundingClientRect(); // 获取 textarea 的位置和尺寸
  474. const x = event.clientX - rect.left; // 计算点击的 x 坐标相对于 textarea 的位置
  475. /* 去掉,只有一行的 <textarea 才会有 <div class="input" 的空白可点击。Lin
  476. var y = event.clientY - rect.top; // 计算点击的 y 坐标相对于 textarea 的位置
  477. */
  478. // 将坐标转换为 textarea 中的字符位置(基于行和字符索引)
  479. /* 去掉,只有一行的 <textarea 才会有 <div class="input" 的空白可点击。Lin
  480. const lineHeight = parseInt(window.getComputedStyle(textArea).lineHeight); // 获取行高
  481. */
  482. const charIndex = Math.floor(x / (textArea.offsetWidth / textArea.cols)); // 计算字符索引(简化版,可能需要更复杂的逻辑以处理不同字体和宽度)
  483. /* 去掉,只有一行的 <textarea 才会有 <div class="input" 的空白可点击。Lin
  484. var lineIndex = Math.floor(y / lineHeight); // 计算行索引
  485. */
  486. // 设置光标位置
  487. textArea.setSelectionRange(charIndex, charIndex); // 设置光标位置,可能需要调整以适应实际需求
  488. textArea.focus(); // 确保 textarea 获取焦点
  489. };
  490. // 附件按钮点击处理(从 SsEditor 搬运)
  491. const onAttachmentClick = (e) => {
  492. e.preventDefault();
  493. if (!props.param || !props.param.button) {
  494. console.warn("未配置 param 参数");
  495. return;
  496. }
  497. console.log("附件点击了");
  498. console.log("param", props.param);
  499. console.log("cmsAddUrl", props.param.button.cmsAddUrl);
  500. // 如果 fjid 为空,先调用 cmsAddUrl 创建
  501. if (fjid.value == null || fjid.value == "") {
  502. $.ajax({
  503. type: "post",
  504. url: props.param.button.cmsAddUrl,
  505. async: false,
  506. data: {
  507. name: "fjid",
  508. ssNrObjName: "sh",
  509. ssNrObjId: "",
  510. },
  511. success: function (_fjid) {
  512. console.log("cmsAddUrl success", _fjid);
  513. fjid.value = _fjid;
  514. },
  515. });
  516. }
  517. // 构建参数字符串
  518. var str =
  519. "&nrid=T-" +
  520. fjid.value +
  521. "&objectId=" +
  522. fjid.value +
  523. "&objectName=" +
  524. fjName +
  525. "&callback=" +
  526. (window["fjidCallbackName"] || "");
  527. console.log("str", str);
  528. // 打开附件编辑对话框
  529. SS.openDialog({
  530. src: props.param.button.cmsUpdUrl + str,
  531. headerTitle: "编辑",
  532. width: 900,
  533. high: 664,
  534. zIndex: 51,
  535. });
  536. };
  537. return {
  538. errMsg,
  539. inputValue,
  540. showRequired,
  541. onInput,
  542. onBlur,
  543. onChange,
  544. onMouseover,
  545. onMouseleave,
  546. onKeydown, // 新增:键盘事件处理 by xu 20251212
  547. contentFloatingDiv,
  548. floatingDivPosition,
  549. getFloatingDivTop,
  550. inputRef,
  551. textareaRef,
  552. onFocus,
  553. onInputDivClick, // 再增加,增加 <div class="input" 的 onClick 事件 -- 支持点击 <div 进入录入行。Lin
  554. onAttachmentClick,
  555. fjid, // 附件 ID,用于隐藏字段
  556. };
  557. },
  558. render() {
  559. const { resolveComponent, h } = Vue;
  560. const SsIcon = resolveComponent("ss-icon");
  561. const SsEditorIcon = resolveComponent("SsEditorIcon");
  562. // 构建主textarea的样式
  563. const mainTextareaStyle = {};
  564. if (this.height) {
  565. /* 改,支持 <input height=。Lin
  566. * 原,录入框高度固定 -- 不受 <input height= 影响
  567. mainTextareaStyle.height = "auto";
  568. */ mainTextareaStyle.height = this.height;
  569. // mainTextareaStyle.paddingTop = '5px'; // 有高度时加上padding-top
  570. // mainTextareaStyle.paddingBottom = '5px'; // 有高度时加上padding-bottom
  571. } else {
  572. // 没有指定height时,固定为单行高度
  573. /* 再改,切掉了 _ 和 jpg 的下部。Lin
  574. mainTextareaStyle.height = "20px"; // 行高20px
  575. mainTextareaStyle.lineHeight = "20px"; // 确保单行垂直居中
  576. */
  577. mainTextareaStyle.height = "24px"; // 行高20px
  578. mainTextareaStyle.lineHeight = "24px"; // 确保单行垂直居中
  579. mainTextareaStyle.display = "flex";
  580. // mainTextareaStyle.marginBottom = "5px"; // 再去掉,不知何用。Lin
  581. }
  582. // 如果有附件按钮,为按钮留出空间
  583. if (this.fj || (this.param && this.param.button)) {
  584. //加上&&this.param.button条件 Ben(20251221)
  585. /* 再改,textarea 文本右侧,离 附件 按钮的空白多了。Lin
  586. mainTextareaStyle.paddingRight = "75px";
  587. */ mainTextareaStyle.paddingRight = "65px";
  588. }
  589. const mainTextareaRows = this.height
  590. ? Math.floor(parseFloat("80px") / 20)
  591. : 1;
  592. return h("div", { class: "input" }, [
  593. h("div", { class: "input-container" }, [
  594. /* 再改,增加 <div class="input" 的 id 和 onClick 事件 -- 支持点击 <div 进入录入行。Lin
  595. h("div", { class: "input", style: "padding:5px 0" }, [
  596. */ h("div", { class: "input", style: "padding:5px 0", id: this.name, onClick: this.onInputDivClick }, [
  597. h("textarea", {
  598. ref: "inputRef",
  599. class: "input-control",
  600. name: this.name,
  601. value: this.inputValue,
  602. onInput: this.onInput,
  603. onFocus: this.onFocus,
  604. onBlur: this.onBlur,
  605. onChange: this.onChange,
  606. onKeydown: this.onKeydown, // 新增:禁止回车换行 by xu 20251212
  607. /* 再改,不输出空的 placeholder -- <textarea placeholder。Lin
  608. placeholder: this.placeholder,
  609. */ placeholder: this.placeholder? this.placeholder : undefined,
  610. onMouseover: this.onMouseover, // 监听鼠标悬停
  611. onMouseleave: this.onMouseleave, // 监听鼠标离开
  612. rows: mainTextareaRows,
  613. ...this.$attrs,
  614. style: mainTextareaStyle,
  615. autocomplete: "off",
  616. }),
  617. // 附件按钮(优先使用 param,兼容旧的 fj)
  618. this.fj || (this.param && this.param.button) //加上&&this.param.button条件 Ben(20251221)
  619. ? h(
  620. "button",
  621. {
  622. type: "button",
  623. class: "fj-button",
  624. onClick: this.param
  625. ? this.onAttachmentClick
  626. : (e) => {
  627. e.preventDefault();
  628. console.log("附件配置:", this.fj);
  629. },
  630. },
  631. [
  632. h(SsEditorIcon, {
  633. class: "editor-icon-link",
  634. }),
  635. h("span", { class: "fj-button-text" }, "附件"),
  636. ]
  637. )
  638. : null,
  639. ]),
  640. this.contentFloatingDiv || ""
  641. ? h(
  642. "div",
  643. {
  644. class: "floating-div",
  645. style:
  646. this.floatingDivPosition === "bottom"
  647. ? {
  648. // 向下展开: 覆盖原输入框,top对齐首行
  649. top: this.getFloatingDivTop,
  650. bottom: "auto",
  651. }
  652. : {
  653. // 向上展开: 同样覆盖原输入框,但从底部开始计算
  654. top: "auto",
  655. bottom: this.height ? "5px" : "6px", // 对齐到原textarea的底部padding位置
  656. },
  657. },
  658. [
  659. h("textarea", {
  660. ref: "textareaRef",
  661. class: "input-control",
  662. value: this.inputValue,
  663. onInput: this.onInput,
  664. onBlur: this.onBlur,
  665. onFocus: this.onFocus,
  666. onKeydown: this.onKeydown, // 新增:禁止回车换行 by xu 20251212
  667. onMouseover: this.onMouseover, // 监听鼠标悬停
  668. onMouseleave: this.onMouseleave, // 监听鼠标离开
  669. autocomplete: "off",
  670. onVnodeMounted: (vnode) => {
  671. vnode.el.focus();
  672. },
  673. }),
  674. ]
  675. )
  676. : null,
  677. // this.errMsg ? h(SsValidate, { errMsg: this.errMsg }) : null,
  678. ]),
  679. // 附件相关的隐藏字段(仅在有 param 时才渲染)
  680. this.param && [
  681. // fjid 隐藏字段(只有当 fjid 有值时才渲染)
  682. this.fjid &&
  683. this.fjid.value &&
  684. h("input", {
  685. type: "hidden",
  686. name: "fjid",
  687. value: this.fjid.value,
  688. }),
  689. // 其他隐藏字段根据 name 生成
  690. /* 去掉。文本框不需要(这是富文本才有的) Ben 20251205
  691. h("input", {
  692. type: "hidden",
  693. name: this.name.replace(/wj$/, "") + "Edit",
  694. value: this.inputValue
  695. }),
  696. */
  697. // h("input", {
  698. // type: "hidden",
  699. // name: this.name.replace(/wj$/, "") + "wj",
  700. // value: this.inputValue
  701. // }),
  702. /* 去掉。文本框不需要(这是富文本才有的) Ben 20251205
  703. h("input", {
  704. type: "hidden",
  705. name: "ueditorpath",
  706. value: this.name
  707. }),
  708. */
  709. ],
  710. ]);
  711. },
  712. };
  713. // ss-normal-input 登录输入
  714. const SsLoginInput = {
  715. name: "SsLoginInput",
  716. inheritAttrs: false,
  717. props: {
  718. errTip: {
  719. type: String,
  720. },
  721. type: {
  722. type: String,
  723. default: "text",
  724. },
  725. required: {
  726. type: Boolean,
  727. default: false,
  728. },
  729. placeholder: {
  730. type: String,
  731. default: "", // : "请输入",。再改,去掉 placeholder 默认值 "请输入" 。Lin
  732. },
  733. name: {
  734. type: String,
  735. default: "",
  736. },
  737. defaultValue: [String, Number],
  738. modelValue: [String, Number],
  739. },
  740. emits: ["update:modelValue", "input", "blur", "change"], // 允许更新 v-model 绑定的值
  741. setup(props, { emit }) {
  742. const errMsg = ref("");
  743. const inputRef = ref(null);
  744. const textareaRef = ref(null);
  745. const inputValue = ref(props.modelValue || props.defaultValue || "");
  746. // 使用 watch 监听 props.errTip 和 props.modelValue 的变化
  747. watch(
  748. () => props.errTip,
  749. (newVal) => {
  750. errMsg.value = newVal;
  751. },
  752. { immediate: true }
  753. );
  754. watch(
  755. () => props.modelValue,
  756. (newVal) => {
  757. inputValue.value = newVal;
  758. }
  759. );
  760. // 挂载时的逻辑
  761. onMounted(() => {
  762. errMsg.value = props.errTip;
  763. inputValue.value = props.modelValue || props.defaultValue || "";
  764. });
  765. // 定义事件处理函数
  766. const onInput = (event) => {
  767. const newValue = event.target.value;
  768. inputValue.value = newValue;
  769. emit("update:modelValue", newValue);
  770. };
  771. return { inputValue, onInput, inputRef, textareaRef };
  772. },
  773. render() {
  774. return h("div", { class: "input" }, [
  775. h("div", { class: "input-container" }, [
  776. h("div", { class: "input" }, [
  777. h("input", {
  778. ref: "inputRef",
  779. class: "input-control",
  780. name: this.name,
  781. value: this.inputValue,
  782. onInput: this.onInput,
  783. type: this.type,
  784. placeholder: this.placeholder,
  785. required: this.required,
  786. ...this.$attrs,
  787. autocomplete: "off",
  788. }),
  789. ]),
  790. ]),
  791. ]);
  792. },
  793. };
  794. // ss-login-button
  795. const SsLoginButton = {
  796. name: "SsLoginButton",
  797. inheritAttrs: false,
  798. props: {
  799. class: {
  800. type: String,
  801. default: "",
  802. },
  803. text: {
  804. type: String,
  805. default: "",
  806. },
  807. type: {
  808. type: String,
  809. default: "button",
  810. },
  811. },
  812. emits: ["click"],
  813. setup(props, { emit }) {
  814. // 定义事件处理函数
  815. const onClick = (event) => {
  816. // 发射一个 'click' 事件,你可以传递所需的参数
  817. emit("click", event);
  818. };
  819. return { props, onClick };
  820. },
  821. render() {
  822. const SsIcon = resolveComponent("ss-icon");
  823. const SsLoginIcon = resolveComponent("ss-login-icon");
  824. return h(
  825. "button",
  826. { class: "login-button", type: this.type, onClick: this.onClick },
  827. [
  828. h("span", [h(SsLoginIcon, { class: this.class })]),
  829. h("span", {}, this.text),
  830. ]
  831. );
  832. },
  833. };
  834. // ss-objp 下拉选择
  835. const SsObjp = {
  836. name: "SsObjp",
  837. inheritAttrs: false,
  838. props: {
  839. onchange: {
  840. //在此属性传入onChange的window全局回调函数,函数唯一参数是当前选中值 Ben(20251217)
  841. type: String,
  842. required: false,
  843. },
  844. filter: {
  845. type: String,
  846. required: false,
  847. },
  848. filterfield: {
  849. type: String,
  850. required: false,
  851. },
  852. // filterField: {
  853. // //此属性为页面表单元素的name用逗号分隔,作用为在向后台查询下拉菜单选项时,会带上这些name的表单元素的value值 Ben(20260313)
  854. // type: String,
  855. // required: false,
  856. // },
  857. cb: {
  858. type: String,
  859. /* 再改,改为允许为空 -- 增加用接口方式更新查询列表里的记录。Lin
  860. required: true,
  861. */ required: false,
  862. },
  863. url: {
  864. type: String,
  865. /* 再改,改为允许为空 -- 增加用接口方式更新查询列表里的记录。Lin
  866. required: true,
  867. */ required: false,
  868. },
  869. name: {
  870. type: String,
  871. required: true,
  872. },
  873. width: {
  874. type: String,
  875. /* 再改,修改 <ss-objp 的默认宽度 -- 原,导致没有指定 <obj 里的 <field width= 时,查询条件里的 <ss-objp 巨宽。Lin
  876. * 原 objList.jsp 里写死 width="150px",现改为 可由 <obj 里的 <field width= 控制了
  877. default: "100%",
  878. */
  879. /* 再改,不指定 width: 时撑满整个宽度 -- 去掉 下拉按钮。Lin
  880. default: "150px",
  881. */ default: "100%",
  882. },
  883. placeholder: {
  884. type: String,
  885. default: "", // : "请选择",。再改,去掉 placeholder 默认值 "请选择" 。Lin
  886. },
  887. inp: {
  888. type: Boolean,
  889. default: false,
  890. },
  891. /// 再增加,增加 <ss-objp :search="true" -- 紧挨录入行的下拉按钮。Lin
  892. search: {
  893. type: Boolean,
  894. default: false,
  895. },
  896. ///
  897. opt: {
  898. type: Array,
  899. default: () => [],
  900. },
  901. errTip: String,
  902. defaultValue: [String, Number],
  903. modelValue: [String, Number],
  904. direction: {
  905. type: String,
  906. default: "bottom",
  907. },
  908. },
  909. emits: ["update:modelValue", "input", "blur", "change", "refresh-opt"], //? 增加, "refresh-opt"]。Lin
  910. setup(props, { emit }) {
  911. const canInput = props.inp;
  912. const errMsg = Vue.ref(props.errTip);
  913. const selectItem = Vue.ref({});
  914. let inputText = Vue.ref(""); // 用于存储输入框的文本
  915. const popupWinVisible = Vue.ref(false);
  916. const filteredOptions = Vue.ref(props.opt);
  917. const popupDirection = Vue.ref("bottom");
  918. const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
  919. const popupContentAreaMaxHeight = Vue.computed(() => {
  920. if (!popupMaxHeight.value || popupMaxHeight.value === "none")
  921. return null;
  922. const maxHeightNum = Number.parseFloat(popupMaxHeight.value);
  923. if (!Number.isFinite(maxHeightNum)) return null;
  924. // 功能说明:滚动条统一落在 .content-area(CSS 默认如此),因此需要扣掉 popup-win padding-top(10) 与 popup-content padding(15*2) by xu 20260126
  925. const contentAreaMaxHeight = Math.max(60, maxHeightNum - 40);
  926. return `${contentAreaMaxHeight}px`;
  927. });
  928. // 修复表格内下拉弹层被 overflow 截断:popup 使用 Teleport 到 body + fixed 定位 by xu 20260126
  929. const selectContainerRef = Vue.ref(null);
  930. const popupRef = Vue.ref(null);
  931. const teleportRootStyle = Vue.ref({
  932. position: "fixed",
  933. left: "0",
  934. top: "0",
  935. width: "0",
  936. height: "0",
  937. zIndex: 9999,
  938. pointerEvents: "none",
  939. });
  940. const popupLayerStyle = Vue.ref({
  941. position: "fixed",
  942. left: "0",
  943. top: "0",
  944. bottom: "auto", // 功能说明:覆盖 .popup-win.top 的 bottom 定位,避免 fixed 场景被撑高/错位 by xu 20260126
  945. minWidth: "0",
  946. zIndex: 9999,
  947. pointerEvents: "auto",
  948. });
  949. // const showRequired = Vue.computed(() => {
  950. // const hasValidationRule = window.ssVm?.validations?.has(props.name);
  951. // if (!hasValidationRule) return false;
  952. // if (errMsg.value) return true;
  953. // if (!selectItem.value?.value) return true;
  954. // return false;
  955. // });
  956. const validate = () => {
  957. if (window.ssVm) {
  958. const result = window.ssVm.validateField(props.name);
  959. // console.log("validate", window.ssVm.validateField(props.name));
  960. errMsg.value = result.valid ? "" : result.message;
  961. }
  962. };
  963. //在objPicker界面,选中value对应的项
  964. const updateSelectItem = () => {
  965. // console.log(props.opt);
  966. const item = props.opt.find((it) => it.value === props.modelValue);
  967. if (item) { // 这里不需要加 && props.modelValue !== "0","0" 的话,item 为空 -- 显示必填字段下拉选择框里的 钩(选中)。Lin
  968. selectItem.value = item;
  969. inputText.value = item.label;
  970. } else {
  971. selectItem.value = { label: "", value: "" };
  972. inputText.value = "";
  973. }
  974. // validate();
  975. };
  976. Vue.watch(
  977. () => props.errTip,
  978. (newVal) => {
  979. errMsg.value = newVal;
  980. }
  981. );
  982. // 功能说明:调用全局 onChange 回调,必须在 handleModelValueChange 之前定义 by xu 20260416
  983. const callGlobalOnchg = (value, desc) => {
  984. if (props.onchange && typeof props.onchange === "string") {
  985. if (
  986. typeof window !== "undefined" &&
  987. window[props.onchange] &&
  988. typeof window[props.onchange] === "function"
  989. ) {
  990. try {
  991. /* 再改,增加入口参数为 code、desc、name。Lin
  992. window[props.onchange](value, desc);
  993. */ window[props.onchange](value, desc, props.name);
  994. } catch (error) {
  995. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  996. }
  997. }
  998. }
  999. };
  1000. // 功能说明:封装 modelValue 变化后的联动逻辑,兼容用户点击和桥接 API 赋值 by xu 20260416
  1001. const handleModelValueChange = (newValue) => {
  1002. updateSelectItem();
  1003. /* 改,增加 && newValue !== "0",显示必填字段下拉选择框里的 钩(选中) -- 必填字段为 int/long,其默认值为 0。Lin
  1004. * 被下面的 Vue.watch(() => props.modelValue, handleModelValueChange, { immediate: true }) 调用,并传入 props.modelValue 到 newValue
  1005. if (newValue) {
  1006. */ if (newValue && newValue !== "0") {
  1007. // 如果当前 options 里没有对应项,去服务端请求回显
  1008. const exists = props.opt.some((it) => it.value === newValue);
  1009. if (!exists && props.url && props.cb) {
  1010. let url = props.url;
  1011. if (props.filter) {
  1012. const filterObj = props.filter;
  1013. for (let k in filterObj) {
  1014. url += "&" + k + "=" + filterObj[k];
  1015. }
  1016. }
  1017. const params = new URLSearchParams();
  1018. params.append("objectpickerparam", JSON.stringify({ input: props.inp, codebook: props.cb }));
  1019. params.append("objectpickertype", "2");
  1020. params.append("objectpickervalue", newValue);
  1021. axios.post(url, params, {
  1022. headers: { "Content-Type": "application/x-www-form-urlencoded" }
  1023. }).then((response) => {
  1024. if ("timeout" == response.data.statusText) {
  1025. alert("网络超时!");
  1026. return;
  1027. }
  1028. if (response.data.result) {
  1029. /* 改,ObjpResultB.result(Map<String, String>) 改为 List<Map<String, String>> -- 支持按服务器端的顺序显示下拉列表。Lin
  1030. const keys = Object.keys(response.data.result);
  1031. if (keys.length === 1) {
  1032. let code = keys[0];
  1033. let desc = response.data.result[keys[0]];
  1034. */
  1035. if (response.data.result.length === 1) {
  1036. var m = Object.entries(response.data.result[0])[0];
  1037. let code = m[0];
  1038. let desc = m[1];
  1039. props.opt.length = 0;
  1040. props.opt.push({ label: desc, value: code });
  1041. updateSelectItem();
  1042. callGlobalOnchg(code, desc);
  1043. }
  1044. }
  1045. });
  1046. } else if (selectItem.value && selectItem.value.value) {
  1047. // options 里有对应项,触发 onChange
  1048. callGlobalOnchg(selectItem.value.value, selectItem.value.label);
  1049. }
  1050. } else {
  1051. // 值为空时清空选中
  1052. callGlobalOnchg("", "");
  1053. }
  1054. };
  1055. Vue.watch(() => props.modelValue, handleModelValueChange, { immediate: true });
  1056. Vue.watch(
  1057. () => props.opt,
  1058. (newVal) => {
  1059. updateSelectItem();
  1060. filteredOptions.value = [...newVal];
  1061. // console.log("filteredOptions", filteredOptions.value);
  1062. }
  1063. );
  1064. //初始化objPicker在页面刚打开时的默认值
  1065. async function initDefaultValue() {
  1066. try {
  1067. /* 改,增加 && props.modelValue !== "0",显示必填字段下拉选择框里的 钩(选中) -- 必填字段为 int/long,其默认值为 0。Lin
  1068. if (props.url && props.cb && props.modelValue) {
  1069. */ if (props.url && props.cb && props.modelValue && props.modelValue !== "0") {
  1070. let objectPickerParam;
  1071. let url = props.url;
  1072. //如果有定义过滤器
  1073. if (props.filter) {
  1074. //包含HTML实体的JSON字符串转为JSON对象,如原字符串是{&quot;dwid&quot;:&quot;88&quot;},注意key也必需用单引号包着
  1075. // const decodedString = props.filter.replace(/&quot;/g, '"'); // 转换为: {"dwid":"88"}
  1076. // objectPickerParam = JSON.parse(decodedString); // 转为json对象
  1077. const filterObj = props.filter; // 转为json对象
  1078. for (let k in filterObj) {
  1079. let v = filterObj[k];
  1080. url += "&" + k + "=" + v;
  1081. }
  1082. objectPickerParam = props.filter; // 转为json对象
  1083. objectPickerParam["input"] = props.inp;
  1084. objectPickerParam["codebook"] = props.cb;
  1085. // alert(url);
  1086. } else {
  1087. objectPickerParam = { input: props.inp, codebook: props.cb };
  1088. }
  1089. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  1090. const params = new URLSearchParams();
  1091. params.append("objectpickerparam", objectPickerParamStr);
  1092. params.append("objectpickertype", "2");
  1093. params.append("objectpickervalue", props.modelValue); //需回显的值
  1094. // alert("1params:"+JSON.stringify(params));
  1095. axios
  1096. .post(props.url, params, {
  1097. headers: {
  1098. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1099. },
  1100. })
  1101. .then((response) => {
  1102. // alert(JSON.stringify(response.data));
  1103. if ("timeout" == response.data.statusText) {
  1104. alert("网络超时!");
  1105. return;
  1106. }
  1107. if (response.data.result) {
  1108. /* 改,ObjpResultB.result(Map<String, String>) 改为 List<Map<String, String>> -- 支持按服务器端的顺序显示下拉列表。Lin
  1109. const keys = Object.keys(response.data.result);
  1110. if (keys.length === 1) {
  1111. let code = keys[0];
  1112. let desc = response.data.result[keys[0]];
  1113. */
  1114. if (response.data.result.length === 1) {
  1115. var m = Object.entries(response.data.result[0])[0];
  1116. let code = m[0];
  1117. let desc = m[1];
  1118. if (props.opt)
  1119. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  1120. else {
  1121. props.opt = [];
  1122. }
  1123. props.opt.push({ label: desc, value: code });
  1124. updateSelectItem();
  1125. // alert('props.opt:'+JSON.stringify(props.opt));
  1126. }
  1127. }
  1128. });
  1129. }
  1130. } catch (error) {
  1131. // callback(null, error.message); // 失败回调,传递错误
  1132. }
  1133. }
  1134. // Vue.onMounted(updateSelectItem);
  1135. const doSelectItem = (item) => {
  1136. emit("update:modelValue", item.value);
  1137. selectItem.value = item;
  1138. inputText.value = item.label;
  1139. hidePopup();
  1140. nextTick(() => {
  1141. console.log(item.value + "@@@props.modelValue:" + props.modelValue);
  1142. validate();
  1143. if (window.ssVm) {
  1144. // 遍历所有验证规则,找到依赖当前字段的规则
  1145. for (const [field, rules] of window.ssVm.validations.entries()) {
  1146. for (const rule of rules) {
  1147. if (rule.opt?.relField === props.name) {
  1148. // console.log("Found dependent field:", field); // 调试日志
  1149. window.ssVm.validateField(field);
  1150. }
  1151. }
  1152. }
  1153. }
  1154. });
  1155. // callGlobalOnchg 已移到 handleModelValueChange 统一处理,避免用户点击和桥接 API 赋值行为不一致 by xu 20260416
  1156. };
  1157. //可录入的objPicker,更新下拉菜单选项
  1158. async function updateOptionBYInputText(inpTxt) {
  1159. try {
  1160. let objectPickerParam;
  1161. let url = props.url;
  1162. /* 再改,不一定需要 :cb= 了 -- 扩展 <ss-objp,增加支持自定义服务生成下拉列表。Lin
  1163. if (props.url && props.cb) {
  1164. */ if (props.url) {
  1165. //如果有定义过滤器
  1166. if (props.filter || props.filterfield) {
  1167. let filterObj = props.filter;
  1168. if (!props.filter) filterObj = {};
  1169. if (props.filter) {
  1170. const filterObj = props.filter; // 转为json对象
  1171. for (let k in filterObj) {
  1172. let v = filterObj[k];
  1173. url += "&" + k + "=" + v;
  1174. }
  1175. }
  1176. if (props.filterfield) {
  1177. //加上filterfield的值过滤
  1178. let filterfieldArr = props.filterfield.split(",");
  1179. for (var i = 0; i < filterfieldArr.length; i++) {
  1180. let fieldName = filterfieldArr[i];
  1181. let fields = document.getElementsByName(fieldName);
  1182. if (!fields || fields.length < 1) {
  1183. alert("下拉菜单配置的过滤条件" + fieldName + "不存在!");
  1184. continue;
  1185. }
  1186. let v = null;
  1187. for (let j = 0; j < fields.length; j++) {
  1188. if (fields[j].value) {
  1189. v = fields[j].value;
  1190. break;
  1191. }
  1192. }
  1193. // let field = document.getElementsByName(fieldName)[0];
  1194. // let v = field.value;
  1195. if (v) {
  1196. url += "&" + fieldName + "=" + v;
  1197. filterObj[fieldName] = v;
  1198. }
  1199. }
  1200. console.log("filterfield url:" + url);
  1201. }
  1202. //包含HTML实体的JSON字符串转为JSON对象,如原字符串是{&quot;dwid&quot;:&quot;88&quot;},注意key也必需用单引号包着
  1203. // const decodedString = props.filter.replace(/&quot;/g, '"'); // 转换为: {"dwid":"88"}
  1204. // objectPickerParam = JSON.parse(decodedString); // 转为json对象
  1205. objectPickerParam = filterObj;
  1206. objectPickerParam["input"] = props.inp;
  1207. objectPickerParam["codebook"] = props.cb;
  1208. // alert(url);
  1209. } else {
  1210. objectPickerParam = { input: props.inp, codebook: props.cb };
  1211. }
  1212. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  1213. const params = new URLSearchParams();
  1214. params.append("objectpickerparam", objectPickerParamStr);
  1215. params.append("objectpickertype", "1");
  1216. if (props.inp && props.inp === true) {
  1217. //把"true"改为true Ben(20251209)
  1218. params.append("objectpickersearchAll", 0); //只查录入的值
  1219. params.append("objectpickerinput", inpTxt); //录入的值
  1220. // 功能说明:将输入值也加到 URL 参数,避免后端只读 URL 不读 body by xu 20250408
  1221. if (inpTxt) {
  1222. url += "&objectpickerinput=" + encodeURIComponent(inpTxt);
  1223. }
  1224. } else {
  1225. params.append("objectpickersearchAll", 1);
  1226. }
  1227. /// 再增加,增加参数 ddpPobjSearchKey(父对象)、ddpObjSearchKey -- 扩展 <ss-objp,增加支持自定义服务生成下拉列表。Lin
  1228. /* 再改,let/const ddpPobjSearchKey 不会挂载到 windiw 里
  1229. if (window.ddpPobjSearchKey)
  1230. */ if (typeof ddpPobjSearchKey !== 'undefined' && ddpPobjSearchKey)
  1231. params.append("ddpPobjSearchKey", JSON.stringify(ddpPobjSearchKey));
  1232. /* 再去掉,不需要 -- 对子对象的查询,是在 ddpEdit.jsp 调用 ajax。Lin
  1233. if (window.ddpObjSearchKey)
  1234. params.append("ddpObjSearchKey", JSON.stringify(window.ddpObjSearchKey));
  1235. */
  1236. const appEl = document.getElementById("app");
  1237. if (appEl)
  1238. params.append("ddpParmMap", JSON.stringify(appEl.__vue_app__._instance.proxy.ddpParmMap));
  1239. ///
  1240. axios
  1241. .post(url, params, {
  1242. headers: {
  1243. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1244. },
  1245. })
  1246. .then((response) => {
  1247. if ("timeout" == response.data.statusText) {
  1248. alert("网络超时!");
  1249. return;
  1250. }
  1251. // 先清空选项 by xu 20251212
  1252. if (props.opt) {
  1253. props.opt.length = 0;
  1254. } else {
  1255. props.opt = [];
  1256. }
  1257. if (response.data.result) {
  1258. /* 改,ObjpResultB.result(Map<String, String>) 改为 List<Map<String, String>> -- 支持按服务器端的顺序显示下拉列表。Lin
  1259. const keys = Object.keys(response.data.result);
  1260. // console.log("params:"+params+"@@response.data:"+JSON.stringify(response.data));
  1261. if (keys.length > 0) {
  1262. for (let k in response.data.result) {
  1263. props.opt.push({
  1264. label: response.data.result[k],
  1265. value: k,
  1266. */
  1267. if (response.data.result.length > 0) {
  1268. for (let i=0; i<response.data.result.length; i++) {
  1269. var m = Object.entries(response.data.result[i])[0];
  1270. props.opt.push({
  1271. label: m[1],
  1272. value: m[0],
  1273. });
  1274. }
  1275. // console.log('###inpTxt:'+inpTxt+';');
  1276. if (
  1277. props.inp &&
  1278. props.inp === true && //把"true"改为true Ben(20251209)
  1279. inpTxt.length > 0
  1280. ) {
  1281. //对于可录入的,用已录入的值作过滤
  1282. /* 再改,改为在后台过滤录入框录入的内容。Lin
  1283. filteredOptions.value = props.opt.filter((option) =>
  1284. option.label
  1285. .toLowerCase()
  1286. .includes(inputText.value.toLowerCase())
  1287. );
  1288. */ filteredOptions.value = props.opt;
  1289. // 可录入的objPicker,当搜索结果只有一项时,自动选中这一项 by xu 20251212
  1290. if (filteredOptions.value.length === 1) {
  1291. const autoSelectItem = filteredOptions.value[0];
  1292. console.log(
  1293. "[objp] 搜索结果只有一项,自动选中:",
  1294. autoSelectItem
  1295. );
  1296. doSelectItem(autoSelectItem);
  1297. return; // 自动选中后直接返回,不需要显示popup
  1298. }
  1299. filteredOptions.value.unshift({ label: "", value: "" });
  1300. // console.log('###做了过滤:'+inputText.value.toLowerCase()+';');
  1301. } else {
  1302. filteredOptions.value = props.opt;
  1303. filteredOptions.value.unshift({ label: "", value: "" });
  1304. }
  1305. console.log("props.opt11:" + JSON.stringify(props.opt));
  1306. } else {
  1307. // 没有数据时,清空过滤选项 by xu 20251212
  1308. filteredOptions.value = [];
  1309. console.log("[objp] 接口返回空数据");
  1310. }
  1311. } else {
  1312. // result不存在时,清空过滤选项 by xu 20251212
  1313. filteredOptions.value = [];
  1314. console.log("[objp] 接口返回无result");
  1315. }
  1316. // 无论是否有数据,都显示popup by xu 20251212
  1317. openPopup(); // Teleport 场景下统一打开并重定位 by xu 20260126
  1318. });
  1319. }
  1320. } catch (error) {
  1321. // callback(null, error.message); // 失败回调,传递错误
  1322. }
  1323. }
  1324. // 计算弹出方向和最大高度的方法 by xu 20251212
  1325. // 当空间不足时限制popup高度并显示滚动条
  1326. const calculatePopupDirection = () => {
  1327. const triggerEl =
  1328. selectContainerRef.value?.querySelector(".input") ||
  1329. selectContainerRef.value;
  1330. if (!triggerEl) return;
  1331. const selectRect = triggerEl.getBoundingClientRect();
  1332. const viewportHeight = window.innerHeight;
  1333. // 3. 计算上下可用空间
  1334. const spaceBelow = viewportHeight - selectRect.bottom - 10; // 减10px留边距
  1335. const spaceAbove = selectRect.top - 10; // 减10px留边距
  1336. // 4. popup预估高度(假设每项36px,最多显示8项 + padding)
  1337. const estimatedPopupHeight = 300;
  1338. const minPopupHeight = 100; // 最小高度
  1339. console.log(
  1340. "[popup] 空间计算 - spaceAbove:",
  1341. spaceAbove,
  1342. "spaceBelow:",
  1343. spaceBelow,
  1344. "estimatedHeight:",
  1345. estimatedPopupHeight
  1346. );
  1347. // 5. 判断方向和最大高度 by xu 20251212
  1348. if (spaceBelow >= estimatedPopupHeight) {
  1349. // 下方空间足够,向下展开,不限制高度
  1350. popupDirection.value = "bottom";
  1351. popupMaxHeight.value = "none";
  1352. console.log("[popup] 向下展开,空间充足");
  1353. } else if (spaceAbove >= estimatedPopupHeight) {
  1354. // 上方空间足够,向上展开,不限制高度
  1355. popupDirection.value = "top";
  1356. popupMaxHeight.value = "none";
  1357. console.log("[popup] 向上展开,空间充足");
  1358. } else {
  1359. // 上下空间都不足,选择空间大的方向,并限制高度出滚动条
  1360. if (spaceBelow >= spaceAbove) {
  1361. popupDirection.value = "bottom";
  1362. popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px";
  1363. console.log(
  1364. "[popup] 向下展开,空间不足,限制高度:",
  1365. popupMaxHeight.value
  1366. );
  1367. } else {
  1368. popupDirection.value = "top";
  1369. popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px";
  1370. console.log(
  1371. "[popup] 向上展开,空间不足,限制高度:",
  1372. popupMaxHeight.value
  1373. );
  1374. }
  1375. }
  1376. };
  1377. // Teleport popup 的定位(fixed) by xu 20260126
  1378. const updatePopupPosition = () => {
  1379. const triggerEl =
  1380. selectContainerRef.value?.querySelector(".input") ||
  1381. selectContainerRef.value;
  1382. if (!triggerEl) return;
  1383. const triggerRect = triggerEl.getBoundingClientRect();
  1384. const margin = 10;
  1385. const viewportWidth = window.innerWidth;
  1386. const viewportHeight = window.innerHeight;
  1387. /* 改,改为紧挨录入行的下拉按钮。Lin
  1388. const popupGap = 0; // 功能说明:定位不再做 -10 重叠,让 padding-top 自然形成间距 by xu 20260126
  1389. */
  1390. let popupGap;
  1391. if (props.search)
  1392. popupGap = -8;
  1393. else
  1394. popupGap = -18;
  1395. // 先给一个初始位置,确保下一帧可以测量弹层尺寸 by xu 20260126
  1396. popupLayerStyle.value = {
  1397. position: "fixed",
  1398. left: `${Math.max(margin, triggerRect.left)}px`,
  1399. top: `${Math.max(margin, triggerRect.bottom + popupGap)}px`, // 功能说明:与输入框底部对齐 by xu 20260126
  1400. bottom: "auto", // 功能说明:fixed 场景显式取消 bottom,避免与 top 同时生效 by xu 20260126
  1401. minWidth: `${Math.max(0, triggerRect.width)}px`,
  1402. zIndex: 9999,
  1403. pointerEvents: "auto",
  1404. };
  1405. Vue.nextTick(() => {
  1406. const popupEl = popupRef.value;
  1407. if (!popupEl) return;
  1408. const popupRect = popupEl.getBoundingClientRect();
  1409. const maxLeft = viewportWidth - popupRect.width - margin;
  1410. const left = Math.min(
  1411. Math.max(margin, triggerRect.left),
  1412. Math.max(margin, maxLeft)
  1413. );
  1414. let top;
  1415. if (popupDirection.value === "top") {
  1416. /* 改,上拉时,紧挨录入行的下拉按钮。Lin
  1417. top = triggerRect.top - popupRect.height - popupGap; // 功能说明:向上展开时与输入框顶部对齐 by xu 20260126
  1418. */ top = triggerRect.top - popupRect.height - popupGap -10; // 功能说明:向上展开时与输入框顶部对齐 by xu 20260126
  1419. top = Math.max(margin, top);
  1420. } else {
  1421. top = triggerRect.bottom + popupGap; // 功能说明:向下展开时与输入框底部对齐 by xu 20260126
  1422. if (top + popupRect.height > viewportHeight - margin) {
  1423. top = Math.max(
  1424. margin,
  1425. viewportHeight - popupRect.height - margin
  1426. );
  1427. }
  1428. }
  1429. popupLayerStyle.value = {
  1430. ...popupLayerStyle.value,
  1431. left: `${left}px`,
  1432. top: `${top}px`,
  1433. bottom: "auto", // 功能说明:无论 top/bottom 展开都用 top 定位,禁用 bottom by xu 20260126
  1434. };
  1435. });
  1436. };
  1437. const openPopup = () => {
  1438. if (!popupWinVisible.value) popupWinVisible.value = true;
  1439. Vue.nextTick(() => {
  1440. calculatePopupDirection();
  1441. updatePopupPosition();
  1442. });
  1443. };
  1444. // Teleport 场景下:滚动/缩放重定位 by xu 20260126
  1445. const handleViewportChange = () => {
  1446. if (!popupWinVisible.value) return;
  1447. calculatePopupDirection();
  1448. updatePopupPosition();
  1449. };
  1450. // Teleport 场景下:点击外部关闭 by xu 20260126
  1451. const onDocPointerDown = (event) => {
  1452. if (!popupWinVisible.value) return;
  1453. const target = event.target;
  1454. if (selectContainerRef.value?.contains(target)) return;
  1455. if (popupRef.value?.contains(target)) return;
  1456. hidePopup();
  1457. };
  1458. //点击下拉菜单的文本区域时,会触发的方法
  1459. function togglePopup() {
  1460. /// 再增加,增加 inp="false" 时点击录入框时关闭下拉列表框 -- 抄自 SsCcp 的 const togglePopup = () => {。Lin
  1461. /* 再改,inp="true" 时,再次点击录入框也能关闭 -- 与 inp="false" 的操作一致,也与 ccp 的操作一样。Lin
  1462. if (!props.inp && popupWinVisible.value) {
  1463. */ if (popupWinVisible.value) {
  1464. hidePopup();
  1465. return;
  1466. }
  1467. ///
  1468. // 可录入的 objPicker,更新下拉菜单选项
  1469. /* 再改,不过滤录入框里的内容 -- 修正点击录入框的行为。Lin
  1470. updateOptionBYInputText(inputText.value);
  1471. */ updateOptionBYInputText("");
  1472. // popupWinVisible.value = !popupWinVisible.value;
  1473. Vue.nextTick(() => {
  1474. calculatePopupDirection();
  1475. updatePopupPosition(); // Teleport 场景下同步定位 by xu 20260126
  1476. });
  1477. }
  1478. const hidePopup = () => {
  1479. popupWinVisible.value = false;
  1480. };
  1481. //点击下拉菜单的三角形时,会触发的方法
  1482. // 添加toggle逻辑,点击时切换显示/隐藏 by xu 20251212
  1483. /* 再去掉,去掉下拉按钮了。Lin
  1484. const suffixClick = () => {
  1485. // 如果popup已显示,则关闭 by xu 20251212
  1486. if (popupWinVisible.value) {
  1487. hidePopup();
  1488. console.log("[objp] 点三角关闭popup");
  1489. return;
  1490. }
  1491. //可录入的objPicker,更新下拉菜单选项
  1492. updateOptionBYInputText("");
  1493. Vue.nextTick(() => {
  1494. calculatePopupDirection();
  1495. updatePopupPosition(); // Teleport 场景下同步定位 by xu 20260126
  1496. });
  1497. console.log("[objp] 点三角打开popup");
  1498. };
  1499. */
  1500. //可录入的objPicker,录入项变化时,会触发
  1501. async function handleInputChange(event) {
  1502. inputText.value = event.target.value;
  1503. if (!inputText.value) {
  1504. inputText.value = "";
  1505. }
  1506. //可录入的objPicker,更新下拉菜单选项
  1507. updateOptionBYInputText(inputText.value);
  1508. // filteredOptions.value = props.opt.filter((option) =>
  1509. // option.label.toLowerCase().includes(inputText.value.toLowerCase())
  1510. // );
  1511. // if (!popupWinVisible.value) {
  1512. // popupWinVisible.value = true; // 确保下拉框在输入时打开
  1513. // }
  1514. }
  1515. /// 增加,改为鼠标离开自动关闭,抄自新的 SsCcp。Lin
  1516. // 增加 leaveInput、enterInput、leavePopup、enterPopup,以实现录入行和下拉选择框互相离开、进入时不关闭下拉选择框
  1517. // 增加延时 hidePopupTimer 和 clearTimerByHidePopup(),等待鼠标从录入行进入下拉选择框(mouseenter事件) -- 鼠标一旦进入下拉选择框,清除延时,阻止关闭下拉选择框
  1518. let hidePopupTimer = null; // 等待鼠标从录入行进入下拉选择框 -- 延时到才关闭。Lin
  1519. // 鼠标离开录入行(mouseleave事件) -- 保持下拉选择框。Lin
  1520. const leaveInput = () => {
  1521. hidePopupTimer = setTimeout(() => {
  1522. popupWinVisible.value = false;
  1523. }, 200); // 200ms延迟,给鼠标移动到下拉选择框的时间
  1524. };
  1525. // 鼠标进入下拉选择框(mouseenter事件) -- 保持下拉选择框。Lin
  1526. const enterPopup = () => {
  1527. clearTimeout(hidePopupTimer); // 清除等待关闭的定时器
  1528. popupWinVisible.value = true;
  1529. };
  1530. let keepPopupTimer = null; // 等待鼠标从下拉选择框进入录入行 -- 延时到才关闭。Lin
  1531. // 鼠标离开下拉选择框(mouseleave事件) -- 保持下拉选择框。Lin
  1532. const leavePopup = () => {
  1533. keepPopupTimer = setTimeout(() => {
  1534. popupWinVisible.value = false;
  1535. }, 200); // 200ms延迟,给鼠标移动到下拉选择框的时间
  1536. };
  1537. // 鼠标进入录入行(mouseenter事件) -- 保持下拉选择框。Lin
  1538. const enterInput = () => {
  1539. if (popupWinVisible.value) {
  1540. clearTimeout(keepPopupTimer); // 清除等待关闭的定时器
  1541. popupWinVisible.value = true;
  1542. }
  1543. };
  1544. ///
  1545. Vue.onMounted(() => {
  1546. initDefaultValue();
  1547. // Teleport 场景下:滚动/缩放需要重定位(scroll 用 capture 捕获容器滚动) by xu 20260126
  1548. window.addEventListener("resize", handleViewportChange);
  1549. window.addEventListener("scroll", handleViewportChange, true);
  1550. // 点击外部关闭(原本依赖 mouseleave,Teleport 后会误关) by xu 20260126
  1551. document.addEventListener("pointerdown", onDocPointerDown, true);
  1552. /* 先去掉,去掉 objp_refreshOpt,改用服务,类似 loadObjpOpt -- 用 objp_refreshOpt,在 ajax 里调用时,不能刷新。Lin
  1553. window.objp_refreshOpt = refreshOpt; // 再增加,在页面调用 window.objp_refreshOpt 来更新 props.opt -- 增加用接口方式更新查询列表里的记录。Lin
  1554. */
  1555. });
  1556. Vue.onUnmounted(() => {
  1557. window.removeEventListener("resize", handleViewportChange);
  1558. window.removeEventListener("scroll", handleViewportChange, true);
  1559. document.removeEventListener("pointerdown", onDocPointerDown, true);
  1560. });
  1561. /// 再增加,在页面调用 window.objp_refreshOpt 来更新 props.opt -- 增加用接口方式更新查询列表里的记录。Lin
  1562. /* 先去掉,去掉 objp_refreshOpt,改用服务,类似 loadObjpOpt -- 用 objp_refreshOpt,在 ajax 里调用时,不能刷新。Lin
  1563. const refreshOpt = (optMap) => {
  1564. props.opt.length = 0;
  1565. props.opt.push(...optMap);
  1566. filteredOptions.value = props.opt;
  1567. }
  1568. */
  1569. ///
  1570. return {
  1571. errMsg,
  1572. selectItem,
  1573. inputText,
  1574. canInput,
  1575. filteredOptions,
  1576. popupWinVisible,
  1577. popupDirection,
  1578. popupMaxHeight, // 添加popup最大高度 by xu 20251212
  1579. popupContentAreaMaxHeight,
  1580. selectContainerRef,
  1581. popupRef,
  1582. teleportRootStyle,
  1583. popupLayerStyle,
  1584. // suffixClick, // 再去掉,去掉下拉按钮了。Lin
  1585. togglePopup,
  1586. hidePopup,
  1587. doSelectItem,
  1588. handleInputChange,
  1589. /// 增加,改为鼠标离开自动关闭,抄自新的 SsCcp。Lin
  1590. leaveInput,
  1591. enterInput,
  1592. leavePopup,
  1593. enterPopup,
  1594. ///
  1595. /* 先去掉,去掉 objp_refreshOpt,改用服务,类似 loadObjpOpt -- 用 objp_refreshOpt,在 ajax 里调用时,不能刷新。Lin
  1596. refreshOpt, // 再增加,在页面调用 window.objp_refreshOpt 来更新 props.opt -- 增加用接口方式更新查询列表里的记录。Lin
  1597. */
  1598. };
  1599. },
  1600. template: `
  1601. <div class="input" style="position: relative" :style="{width: width}">
  1602. <!-- 改,增加 leaveInput、enterInput -- 改为鼠标离开自动关闭,抄自新的 SsCcp。Lin
  1603. <div class="select-container" ref="selectContainerRef">
  1604. --> <div class="select-container" ref="selectContainerRef" @mouseleave="leaveInput" @mouseenter="enterInput">
  1605. <div class="input" @click="togglePopup">
  1606. <!-- 再改,去掉 .value=,属于语法错误。去掉后,好像没问题。Lin
  1607. <input
  1608. type="hidden"
  1609. :name="name"
  1610. :value="selectItem.value"
  1611. .value="selectItem.value"
  1612. />
  1613. -->
  1614. <input
  1615. type="hidden"
  1616. :name="name"
  1617. :value="selectItem.value"
  1618. />
  1619. <input
  1620. v-model="inputText"
  1621. @input="handleInputChange"
  1622. v-if="canInput"
  1623. :placeholder="placeholder"
  1624. />
  1625. <input
  1626. v-else
  1627. :placeholder="placeholder"
  1628. :value="selectItem.label"
  1629. disabled
  1630. style="pointer-events: none;"
  1631. />
  1632. <!-- 再去掉,去掉下拉按钮,改为段分隔符 L。Lin
  1633. <div class="suffix" @click.stop="suffixClick">
  1634. <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
  1635. </div>
  1636. -->
  1637. </div>
  1638. <!-- 修复表格内弹层被截断:popup Teleport 到 body by xu 20260126 -->
  1639. <teleport to="body">
  1640. <!-- 改,增加 leaveInput、enterInput -- 改为鼠标离开自动关闭,抄自新的 SsCcp。Lin
  1641. <div v-show="popupWinVisible" class="select-container ss-objp-teleport-root" :style="teleportRootStyle">
  1642. --> <div v-show="popupWinVisible" class="select-container ss-objp-teleport-root" :style="teleportRootStyle"
  1643. @mouseleave="leavePopup" @mouseenter="enterPopup">
  1644. <!-- popup弹出层,添加maxHeight和overflowY支持空间不足时滚动 by xu 20251212 -->
  1645. <!-- 改,去掉 :class="popupDirection",去掉下拉列表框的尖角。Lin
  1646. <div ref="popupRef" class="popup-win" :class="popupDirection" :style="[popupLayerStyle, { maxHeight: popupMaxHeight !== 'none' ? popupMaxHeight : 'none', overflowY: 'visible' }]">
  1647. --> <div ref="popupRef" class="popup-win" :style="[popupLayerStyle, { maxHeight: popupMaxHeight !== 'none' ? popupMaxHeight : 'none', overflowY: 'visible' }]">
  1648. <div v-if="opt && opt.length && filteredOptions.length > 0" class="popup-content">
  1649. <div class="content-area" :style="popupContentAreaMaxHeight ? { maxHeight: popupContentAreaMaxHeight, overflowY: 'auto' } : null">
  1650. <div
  1651. v-for="(item, index) in filteredOptions"
  1652. :key="index"
  1653. @click="doSelectItem(item)"
  1654. :class="{ active: item.value === selectItem.value }"
  1655. >
  1656. <span class="check-icon">
  1657. <ss-form-icon class="form-icon-select-checked" />
  1658. </span>
  1659. <span>{{ item.label }}</span>
  1660. </div>
  1661. </div>
  1662. </div>
  1663. <div v-else class="popup-content">
  1664. <div class="content-area">
  1665. <div class="content-area">
  1666. <span>无选项</span>
  1667. </div>
  1668. </div>
  1669. </div>
  1670. </div>
  1671. </div>
  1672. </teleport>
  1673. </div>
  1674. </div>
  1675. `,
  1676. };
  1677. // ss-hidden 隐藏字段组件
  1678. const SsHidden = {
  1679. name: "SsHidden",
  1680. props: {
  1681. modelValue: String,
  1682. name: {
  1683. type: String,
  1684. required: true,
  1685. },
  1686. rule: {
  1687. type: String,
  1688. required: false,//因为要单独发布非级联用的隐藏字段,改为非必需
  1689. },
  1690. param: {
  1691. type: String,
  1692. required: false,//因为要单独发布非级联用的隐藏字段,改为非必需
  1693. },
  1694. url: {
  1695. type: String,
  1696. required: false,//因为要单独发布非级联用的隐藏字段,改为非必需
  1697. },
  1698. },
  1699. emits: ["update:modelValue"],
  1700. setup(props, { emit }) {
  1701. const errMsg = Vue.ref("");
  1702. const validate = () => {
  1703. if (window.ssVm) {
  1704. const result = window.ssVm.validateField(props.name);
  1705. console.log("validate", window.ssVm.validateField(props.name));
  1706. errMsg.value = result.valid ? "" : result.message;
  1707. }
  1708. };
  1709. Vue.onMounted(() => {
  1710. /**
  1711. * 初始化级联菜单值初始值思路:
  1712. * 1. 带隐藏字段(即带编码规则)的级联菜单
  1713. * 在隐藏字段这,可以取到要回显的值和编码规则,从而计算出各级下拉菜单要回显的值。
  1714. * 然后通过ajax取各级级联菜单的值回显。
  1715. * 2. 不带隐藏字段的级联,只能在各个下拉菜单的setup事件中通过ajax取回显值回显
  1716. */
  1717. // 当同组级联下拉菜单选中值变化时,会调用本隐藏字段下面这方法设置隐藏字段值
  1718. window.addEventListener(
  1719. "cascader-setHiddenVal-" + props.name,
  1720. (event) => {
  1721. const { value } = event.detail;
  1722. emit("update:modelValue", value);
  1723. console.log(value);
  1724. setTimeout(() => {
  1725. validate();
  1726. }, 50);
  1727. }
  1728. );
  1729. // 如果有初始值,触发回显过程
  1730. if (props.modelValue&&props.param) {//增加props.param非空判断,非级联的hidden没props.param Ben(20260414)
  1731. console.log("级联隐藏字段,开始回显,初始值:", props.modelValue);
  1732. triggerCascaderEcho(props.modelValue);
  1733. validate();
  1734. }
  1735. });
  1736. // 触发级联回显
  1737. const triggerCascaderEcho = (code) => {
  1738. /**
  1739. * 开始回显,初始值: 440304
  1740. * 解析后的所有值: Array(3)0: "440000"1: "440300"2: "440304"length: 3[[Prototype]]: Array(0)
  1741. */
  1742. const values = parseHiddenCodeForAll(code, props.rule);
  1743. console.log("解析后的所有值:", values);
  1744. // 转换为 JSON 对象
  1745. // const paramObj = JSON.parse(props.param);
  1746. const paramObj = props.param;
  1747. let selectArr = paramObj.fieldOrd; //保存本组级联菜单项的数组,如:['hksheng','hkshi','hkxian']
  1748. if (selectArr.length != values.length) {
  1749. // alert('属性'+props.name+'的值'+code+'与级联菜单中下拉菜单的数目不匹配!');
  1750. return;
  1751. }
  1752. // 按顺序触发回显,并增加延迟确保数据加载
  1753. /**
  1754. * 通过隐藏字段的setup事件,
  1755. * 循环遍历各级下拉菜单,并触发定义在下拉菜单中的'cascader-echo'事件,
  1756. * 在此事件中完成每个下拉菜单回显值操作(只取当前要回显的键值对显示,
  1757. * 下拉菜单所有的值,在点击下拉菜单时,才通过ajax取)。
  1758. */
  1759. values.forEach((value, index) => {
  1760. if (value) {
  1761. setTimeout(() => {
  1762. let upperVal = undefined;
  1763. if (index != 0) {
  1764. upperVal = values[index - 1];
  1765. }
  1766. const echoEvent = new CustomEvent(
  1767. "cascader-echo-" + selectArr[index],
  1768. {
  1769. detail: {
  1770. name: props.name,
  1771. value: value,
  1772. // level: index + 1,
  1773. isAuto: true, // 标记为自动回显
  1774. upperVal: upperVal,
  1775. },
  1776. }
  1777. );
  1778. console.log(props.name + "--upperValue:" + upperVal);
  1779. window.dispatchEvent(echoEvent);
  1780. }, index * 500); // 每级增加500ms延迟
  1781. }
  1782. });
  1783. };
  1784. // 解析所有级别的代码
  1785. const parseHiddenCodeForAll = (code, rule) => {
  1786. if (!code || !rule) return [];
  1787. // 获取规则中每段的长度
  1788. const segments = [];
  1789. let currentChar = rule[0];
  1790. let currentLength = 1;
  1791. for (let i = 1; i < rule.length; i++) {
  1792. if (rule[i] === currentChar) {
  1793. currentLength++;
  1794. } else {
  1795. segments.push(currentLength);
  1796. currentChar = rule[i];
  1797. currentLength = 1;
  1798. }
  1799. }
  1800. segments.push(currentLength);
  1801. // 解析每一级的值
  1802. const values = [];
  1803. let position = 0;
  1804. segments.forEach((length, index) => {
  1805. const value = code
  1806. .substring(0, position + length)
  1807. .padEnd(rule.length, "0");
  1808. values.push(value);
  1809. position += length;
  1810. });
  1811. return values;
  1812. };
  1813. watchEffect(() => {});
  1814. return {};
  1815. },
  1816. template: `<input type="hidden" :name="name" :value="modelValue">`,
  1817. };
  1818. // ss-cascader 级联选择器
  1819. const SsCcp = {
  1820. name: "SsCcp",
  1821. inheritAttrs: false,
  1822. props: {
  1823. /// 再增加,增加支持改变值后的回调,在 doSelectItem(item) 里调用 -- props.modelValue 是 inp="true" 方面的。Lin
  1824. onchange: {
  1825. //在此属性传入onChange的window全局回调函数,函数唯一参数是当前选中值 Ben(20251217)
  1826. type: String,
  1827. required: false,
  1828. },
  1829. ///
  1830. modelValue: String,
  1831. name: {
  1832. type: String,
  1833. required: true,
  1834. },
  1835. level: {
  1836. type: Number,
  1837. required: true,
  1838. },
  1839. opt: {
  1840. type: Array,
  1841. default: () => [],
  1842. },
  1843. placeholder: {
  1844. type: String,
  1845. default: "", // : "请选择",。再改,去掉 placeholder 默认值 "请选择" 。Lin
  1846. },
  1847. width: {
  1848. type: String,
  1849. /* 再改,不指定 width: 时撑满整个宽度 -- 去掉 下拉按钮。Lin
  1850. default: "150px",
  1851. */ default: "100%",
  1852. },
  1853. direction: {
  1854. type: String,
  1855. default: "bottom",
  1856. },
  1857. mode: {
  1858. type: String,
  1859. default: "1",
  1860. },
  1861. //级联菜单配置参数,如果是数组,则代表本下拉菜单是多套级联菜单共用的第一级菜单。如果是对象,则只有一套级联菜单用此下拉菜单。
  1862. param: {
  1863. type: String,
  1864. required: true,
  1865. },
  1866. //向后台拿数据的url
  1867. url: {
  1868. type: String,
  1869. required: true,
  1870. },
  1871. /// 再增加,增加 <ss-ccp :search="true" -- 紧挨录入行的下拉按钮。Lin
  1872. search: {
  1873. type: Boolean,
  1874. default: false,
  1875. },
  1876. ///
  1877. /// 再增加,增加 <ss-ccp :inp= -- SsCcp 支持 inp="true"。Lin
  1878. inp: {
  1879. type: Boolean,
  1880. default: false,
  1881. },
  1882. ///
  1883. },
  1884. emits: ["update:modelValue", "change"],
  1885. setup(props, { emit }) {
  1886. /// 增加,增加 <ss-ccp :inp= -- SsCcp 支持 inp="true"。Lin
  1887. const canInput = props.inp;
  1888. let inputText = Vue.ref(""); // 用于存储输入框的文本
  1889. const filteredOptions = Vue.ref(props.opt);
  1890. ///
  1891. // alert('级联菜单初始化:'+props.name+':--:'+props.modelValue);
  1892. const selectItem = Vue.ref({ label: props.placeholder, value: "" });
  1893. const popupWinVisible = Vue.ref(false);
  1894. const isAutoEcho = Vue.ref(false); // 用于标记是否是自动回显
  1895. const upperValue = Vue.ref(""); //上级下拉菜单当前值,在初始化下拉菜单默认值时,和上级下拉菜单的值变化时,修改此upperValue变量
  1896. const popupDirection = Vue.ref("bottom");
  1897. const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
  1898. /// 增加,"修复表格内弹层被截断:popup Teleport 到 body"。Lin
  1899. // 抄自 SsObjp.setup( 里的 "修复表格内下拉弹层被 overflow 截断:popup 使用 Teleport 到 body + fixed 定位"
  1900. const popupRef = Vue.ref(null);
  1901. const teleportRootStyle = Vue.ref({
  1902. position: "fixed",
  1903. left: "0",
  1904. top: "0",
  1905. width: "0",
  1906. height: "0",
  1907. zIndex: 9999,
  1908. pointerEvents: "none",
  1909. });
  1910. const popupLayerStyle = Vue.ref({
  1911. position: "fixed",
  1912. left: "0",
  1913. top: "0",
  1914. bottom: "auto", // 功能说明:覆盖 .popup-win.top 的 bottom 定位,避免 fixed 场景被撑高/错位 by xu 20260126
  1915. minWidth: "0",
  1916. zIndex: 9999,
  1917. pointerEvents: "auto",
  1918. });
  1919. ///
  1920. //有隐藏字段的下拉菜单,加载菜单项并展开事件
  1921. // 被上级下拉菜单选中值后,触发本下拉菜单刷新菜单项并弹出显示
  1922. window.addEventListener("cascader-open-" + props.name, async (event) => {
  1923. const { upperVal } = event.detail;
  1924. upperValue.value = upperVal;
  1925. console.log(
  1926. "22props.name:" +
  1927. props.name +
  1928. ",22props.upperValue:" +
  1929. upperValue.value
  1930. );
  1931. selectItem.value = ""; //清除本下拉菜单当前选中的值
  1932. emit("update:modelValue", ""); //通知父级
  1933. //清空下拉菜单,并设置第一项的值为placeholder
  1934. clearAndInit1stOpt();
  1935. //下个下拉菜单名
  1936. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1937. if (nextSelName) {
  1938. //清下个下拉菜单选中值和选项
  1939. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  1940. detail: {},
  1941. });
  1942. window.dispatchEvent(event);
  1943. }
  1944. /* 再改。Lin
  1945. * 解决父级选中 空,子级弹出 空白下拉选择框
  1946. * 解决选中父级后,子级不出现 钩 的问题
  1947. showPopup();
  1948. */
  1949. if (upperValue.value) {
  1950. updateSelectItem(); // 再增加,解决选中父级后,子级不出现 钩 的问题。Lin
  1951. showPopup();
  1952. } else {
  1953. hidePopup();
  1954. }
  1955. });
  1956. //设置mode2的下级下拉菜单的上级菜单当前值
  1957. function setNextSelectUpperValue() {
  1958. //设置下级菜单的上级菜单当前值upperValue
  1959. let paramArr = undefined;
  1960. if (Array.isArray(props.param)) {
  1961. paramArr = props.param;
  1962. } else {
  1963. paramArr = [];
  1964. paramArr.push(props.param);
  1965. }
  1966. for (const oneParam of paramArr) {
  1967. //下个下拉菜单名
  1968. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  1969. if (nextSelName) {
  1970. setTimeout(() => {
  1971. const openNextEvent = new CustomEvent(
  1972. "cascade-setUpperVal-" + nextSelName,
  1973. {
  1974. detail: {
  1975. upperVal: props.modelValue,
  1976. },
  1977. }
  1978. );
  1979. window.dispatchEvent(openNextEvent);
  1980. }, 100);
  1981. }
  1982. } // end for
  1983. }
  1984. // 把上级 级联下拉菜单的值,设置进本组件的事件
  1985. window.addEventListener("cascade-setUpperVal-" + props.name, (event) => {
  1986. // alert('props.name:'+props.name+',props.upperValue:'+event.detail.upperVal);
  1987. const { upperVal } = event.detail;
  1988. upperValue.value = upperVal;
  1989. // console.log('props.name:'+props.name+',props.upperValue:'+upperValue.value);
  1990. });
  1991. //清空下拉菜单,并设置第一项的值为空
  1992. function clearAndInit1stOpt() {
  1993. if (props.opt)
  1994. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  1995. else {
  1996. props.opt = [];
  1997. }
  1998. props.opt.push({ label: "", value: "" });
  1999. }
  2000. //获取下一级下拉菜单,如果下一级下拉菜单不存在,则返回undefined
  2001. function getNextSel(selName, selNameArr) {
  2002. // 检查参数有效性
  2003. if (!Array.isArray(selNameArr) || selNameArr.length === 0) {
  2004. return undefined;
  2005. }
  2006. // 查找当前元素的索引
  2007. const currentIndex = selNameArr.indexOf(selName);
  2008. // 如果元素不存在或已经是最后一个元素,返回undefined
  2009. if (currentIndex === -1 || currentIndex === selNameArr.length - 1) {
  2010. return undefined;
  2011. }
  2012. // 返回下一个元素
  2013. return selNameArr[currentIndex + 1];
  2014. }
  2015. const validate = () => {
  2016. if (window.ssVm) {
  2017. return window.ssVm.validateField(props.name);
  2018. }
  2019. return { valid: true };
  2020. };
  2021. /// 再增加,抄自 SsObjp.updateSelectItem() -- SsCcp 支持 inp="true"。Lin
  2022. //在objPicker界面,选中value对应的项
  2023. const updateSelectItem = () => {
  2024. // console.log(props.opt);
  2025. const item = props.opt.find((it) => it.value === props.modelValue);
  2026. if (item) { // 这里不需要加 && props.modelValue !== "0","0" 的话,item 为空 -- 显示必填字段下拉选择框里的 钩(选中)。Lin
  2027. selectItem.value = item;
  2028. inputText.value = item.label;
  2029. } else {
  2030. selectItem.value = { label: "", value: "" };
  2031. inputText.value = "";
  2032. }
  2033. // validate();
  2034. };
  2035. ///
  2036. // 处理选择事件
  2037. const doSelectItem = (item) => {
  2038. selectItem.value = item;
  2039. inputText.value = item.label; // 再增加,增加 inputText -- SsCcp 支持 inp="true"。Lin
  2040. emit("update:modelValue", item.value); //修改本下拉菜单在vue中保存的值
  2041. // alert('item.value:'+item.value);
  2042. if (props.mode === "1") {
  2043. // mode 1 模式:修改隐藏字段值
  2044. let event = new CustomEvent(
  2045. "cascader-setHiddenVal-" + props.param.combField,
  2046. {
  2047. detail: {
  2048. value: item.value,
  2049. },
  2050. }
  2051. );
  2052. window.dispatchEvent(event);
  2053. }
  2054. emit("change", item.value); //触发配置的change方法 // 应该没用,父级(<ss-ccp)里没有配置 @change=。Lin
  2055. nextTick(() => {
  2056. validate();
  2057. if (window.ssVm) {
  2058. for (const [field, rules] of window.ssVm.validations.entries()) {
  2059. for (const rule of rules) {
  2060. if (rule.options?.relField) {
  2061. const relFields = String(rule.options.relField)
  2062. .split(",")
  2063. .map((name) => name.trim())
  2064. .filter(Boolean);
  2065. if (relFields.includes(props.name)) {
  2066. window.ssVm.validateField(field);
  2067. }
  2068. }
  2069. }
  2070. }
  2071. }
  2072. });
  2073. //设置下级菜单的上级菜单当前值upperValue
  2074. let paramArr = undefined;
  2075. if (Array.isArray(props.param)) {
  2076. paramArr = props.param;
  2077. } else {
  2078. paramArr = [];
  2079. paramArr.push(props.param);
  2080. }
  2081. for (const oneParam of paramArr) {
  2082. //下个下拉菜单名
  2083. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  2084. if (nextSelName) {
  2085. setTimeout(() => {
  2086. const openNextEvent = new CustomEvent(
  2087. "cascader-open-" + nextSelName,
  2088. {
  2089. detail: {
  2090. upperVal: item.value,
  2091. },
  2092. }
  2093. );
  2094. window.dispatchEvent(openNextEvent);
  2095. }, 100);
  2096. }
  2097. } // end for
  2098. hidePopup();
  2099. //下个下拉菜单名
  2100. // let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  2101. // if(nextSelName){
  2102. // // //设置下一级下拉菜单中保存的本下拉菜单值(upperValue)
  2103. // // event = new CustomEvent('cascade-setUpperVal-'+nextSelName, {
  2104. // // detail: {
  2105. // // value: item.value
  2106. // // }
  2107. // // });
  2108. // // window.dispatchEvent(event);
  2109. //
  2110. // //触发下一级下拉菜单,重新初始化下拉菜单项并弹出显示
  2111. // event = new CustomEvent('cascader-open-' +nextSelName, {
  2112. // detail: {
  2113. // upperVal: item.value
  2114. // }
  2115. // });
  2116. // window.dispatchEvent(event);
  2117. // }
  2118. // 只在手动选择时自动展开下一级
  2119. // if (!isAutoEcho.value) {
  2120. // const nextLevel = props.level + 1;
  2121. // setTimeout(() => {
  2122. // const openNextEvent = new CustomEvent('open-next-cascader', {
  2123. // detail: {
  2124. // name: props.name,
  2125. // level: nextLevel
  2126. // }
  2127. // });
  2128. // window.dispatchEvent(openNextEvent);
  2129. // }, 100);
  2130. // }
  2131. /// 再增加,增加支持改变值后的回调 -- 抄自 SsUpload.handleModelValueChange(newValue) < SsObjp.handleModelValueChange(newValue)。Lin
  2132. if (!props.onchange || typeof props.onchange !== "string" ||
  2133. typeof window === "undefined" || !window[props.onchange] || typeof window[props.onchange] !== "function")
  2134. return;
  2135. try {
  2136. /* 再改,增加入口参数为 code、desc、name。Lin
  2137. window[props.onchange](item.value); // (value, desc)。Lin
  2138. */ window[props.onchange](item.value, item.label, props.name); // (value, desc)。Lin
  2139. } catch (error) {
  2140. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  2141. }
  2142. ///
  2143. };
  2144. // 监听下一级展开事件 (仅 mode 2)
  2145. window.addEventListener("cascade-open", (event) => {
  2146. if (props.mode === "2") {
  2147. const { level } = event.detail;
  2148. if (level === props.level) {
  2149. popupWinVisible.value = true;
  2150. }
  2151. }
  2152. });
  2153. if (props.mode === "1") {
  2154. //如果是有隐藏字段的下拉菜单
  2155. // 监听回显事件
  2156. window.addEventListener(
  2157. "cascader-echo-" + props.name,
  2158. async (event) => {
  2159. const { name, value, isAuto, upperVal } = event.detail;
  2160. // level,
  2161. if (upperVal) {
  2162. upperValue.value = upperVal;
  2163. console.log(
  2164. "value:" +
  2165. value +
  2166. ",upperValue:" +
  2167. upperValue +
  2168. ",初始化级联组件时props.name:" +
  2169. props.name
  2170. );
  2171. }
  2172. // if (name === props.name && level === props.level) {
  2173. // 设置自动回显标记
  2174. isAutoEcho.value = true;
  2175. // if (props.opt.length === 0) {
  2176. // const loadDataEvent = new CustomEvent('cascader-load-data', {
  2177. // detail: {
  2178. // name: props.name,
  2179. // level: props.level,
  2180. // value: value
  2181. // }
  2182. // });
  2183. // window.dispatchEvent(loadDataEvent);
  2184. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  2185. //Vue.watch用于监听数据的变化,并在数据变化时执行特定的回调函数。
  2186. //这段代码使用了 Vue.js 的 watch API 来监听 props.opt 的变化,如果props.opt有变化,则自动
  2187. // const unwatch = Vue.watch(
  2188. // () => props.opt, // 监听的数据源(props.opt)
  2189. // (newOptions) => { // 回调函数
  2190. // if (newOptions.length > 0) { // 条件判断
  2191. // matchAndSelect(value); // 执行逻辑
  2192. // unwatch(); // 停止监听
  2193. // }
  2194. // },
  2195. // { immediate: true } // 配置:立即触发一次
  2196. // );
  2197. // } else {
  2198. // matchAndSelect(value);
  2199. // }
  2200. // 初始化级联菜单在页面刚打开时的默认值
  2201. async function initDefaultValue(value) {
  2202. try {
  2203. // alert(1);
  2204. if (
  2205. props.url &&
  2206. props.param
  2207. // && props.modelValue 对于有rule编码规则的级联菜单(即mode=1),modelValue一定是空的,所以注释掉,修复mode=1的级联菜单无法回显问题。Ben(20251124)
  2208. ) {
  2209. // alert(2);
  2210. /**
  2211. * let objectPickerParam=
  2212. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  2213. * "\"name\":\"hksheng\"," +
  2214. * "\"cascadingName\":\"dq\",\"cascadingInputsName\":\"hkdqm\"," +
  2215. * "\"codebook\":\"sheng\"}",
  2216. * "objectpickertype":2,
  2217. * "objectpickervalue":"440000"
  2218. * };
  2219. */
  2220. const objectPickerParam = {
  2221. input: "false",
  2222. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2223. name: props.name, //本下拉菜单名
  2224. cascadingName: props.param.name, //级联菜单名
  2225. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  2226. codebook: props.param.codebook,
  2227. };
  2228. const objectPickerParamStr =
  2229. JSON.stringify(objectPickerParam);
  2230. const params = new URLSearchParams();
  2231. params.append("objectpickerparam", objectPickerParamStr);
  2232. params.append("objectpickertype", "2");
  2233. params.append("objectpickervalue", value); //需回显的值
  2234. axios
  2235. .post(props.url, params, {
  2236. headers: {
  2237. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2238. },
  2239. })
  2240. .then((response) => {
  2241. // alert(JSON.stringify(response.data));
  2242. if ("timeout" == response.data.statusText) {
  2243. alert("网络超时!");
  2244. return;
  2245. }
  2246. if (response.data.result) {
  2247. const keys = Object.keys(response.data.result);
  2248. if (keys.length === 1) {
  2249. let code = keys[0];
  2250. let desc = response.data.result[keys[0]];
  2251. clearAndInit1stOpt();
  2252. props.opt.push({ label: desc, value: code });
  2253. if (value) matchAndSelect(value);
  2254. // updateSelectItem();
  2255. // alert('props.opt:'+JSON.stringify(props.opt));
  2256. }
  2257. }
  2258. });
  2259. }
  2260. } catch (error) {
  2261. alert(error);
  2262. // callback(null, error.message); // 失败回调,传递错误
  2263. }
  2264. }
  2265. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  2266. initDefaultValue(value);
  2267. // 延迟重置自动回显标记
  2268. setTimeout(() => {
  2269. isAutoEcho.value = false;
  2270. }, 500);
  2271. }
  2272. );
  2273. // 被上级下拉菜单触发的,清除选中值和下拉菜单选项
  2274. window.addEventListener(
  2275. "cascader-cleanOpt-" + props.name,
  2276. async (event) => {
  2277. upperValue.value = "";
  2278. selectItem.value = ""; //清除本下拉菜单当前选中的值
  2279. emit("update:modelValue", ""); //通知父级
  2280. //清空所有下拉菜单项
  2281. if (props.opt) {
  2282. props.opt.length = 0;
  2283. } else {
  2284. props.opt = [];
  2285. }
  2286. //下个下拉菜单名
  2287. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  2288. // alert('nextSelName:'+nextSelName+'--,props.name:'+props.name);
  2289. if (nextSelName) {
  2290. //清下个下拉菜单选中值和选项
  2291. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  2292. detail: {},
  2293. });
  2294. window.dispatchEvent(event);
  2295. }
  2296. }
  2297. );
  2298. } else if (props.mode === "2") {
  2299. //没隐藏字段的下拉菜单,在这初始化默认值
  2300. let needInitParam = undefined;
  2301. if (Array.isArray(props.param)) {
  2302. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  2303. console.log("needInitParam最后一项:" + JSON.stringify(needInitParam));
  2304. } else {
  2305. needInitParam = props.param;
  2306. }
  2307. // 初始化级联菜单在页面刚打开时的默认值
  2308. async function initDefaultValue(value, param) {
  2309. try {
  2310. // alert(1);
  2311. /* 改,增加 && props.modelValue !== "0",显示必填字段下拉选择框里的 钩(选中) -- 必填字段为 int/long,其默认值为 0。Lin
  2312. if (props.url && param && props.modelValue) {
  2313. */ if (props.url && param && props.modelValue && props.modelValue !== "0") {
  2314. // alert(2);
  2315. /**
  2316. * let param=
  2317. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"rylbm,gwid\"," +
  2318. * "\"name\":\"gwid\",\"cascadingName\":\"rylb_gw\"," +
  2319. * "\"codebook\":\"gwByRylb\"}",
  2320. * "objectpickertype":2,
  2321. * "objectpickervalue":"102121"};
  2322. */
  2323. // alert('props.name:'+props.name+',props.param.fieldOrd:'+props.param.fieldOrd);
  2324. const objectPickerParam = {
  2325. input: "false",
  2326. cascadingLevel: param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2327. name: props.name, //本下拉菜单名
  2328. cascadingName: param.name, //级联菜单名
  2329. codebook: param.codebook,
  2330. };
  2331. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2332. const sendParams = new URLSearchParams();
  2333. sendParams.append("objectpickerparam", objectPickerParamStr);
  2334. sendParams.append("objectpickertype", "2");
  2335. sendParams.append("objectpickervalue", value); //需回显的值
  2336. axios
  2337. .post(props.url, sendParams, {
  2338. headers: {
  2339. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2340. },
  2341. })
  2342. .then((response) => {
  2343. // alert(JSON.stringify(response.data));
  2344. if ("timeout" == response.data.statusText) {
  2345. alert("网络超时!");
  2346. return;
  2347. }
  2348. if (response.data.result) {
  2349. /* 改,ObjpResultB.result(Map<String, String>) 改为 List<Map<String, String>> -- 支持按服务器端的顺序显示下拉列表。Lin
  2350. const keys = Object.keys(response.data.result);
  2351. console.log(
  2352. "name:" +
  2353. props.name +
  2354. ",@@级联初始化默认值value:" +
  2355. value +
  2356. "--param:" +
  2357. JSON.stringify(param) +
  2358. "--objectPickerParamStr:" +
  2359. objectPickerParamStr +
  2360. "--response.data:" +
  2361. JSON.stringify(response.data)
  2362. );
  2363. if (keys.length === 1) {
  2364. let code = keys[0];
  2365. let desc = response.data.result[keys[0]];
  2366. */
  2367. if (response.data.result.length === 1) {
  2368. var m = Object.entries(response.data.result[0])[0];
  2369. let code = m[0];
  2370. let desc = m[1];
  2371. if (props.opt)
  2372. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  2373. else {
  2374. props.opt = [];
  2375. }
  2376. props.opt.push({ label: desc, value: code });
  2377. updateSelectItem(); // 再增加,来自 SsObjp.initDefaultValue() -- SsCcp 支持 inp="true"。Lin
  2378. if (value) matchAndSelect(value);
  2379. console.log(
  2380. "GOOD mode2回显的默认值:" +
  2381. JSON.stringify({ label: desc, value: code }) +
  2382. "--props.param:" +
  2383. JSON.stringify(param)
  2384. );
  2385. // updateSelectItem();
  2386. // alert('props.opt:'+JSON.stringify(props.opt));
  2387. }
  2388. }
  2389. });
  2390. }
  2391. } catch (error) {
  2392. alert(error);
  2393. // callback(null, error.message); // 失败回调,传递错误
  2394. }
  2395. // 重置自动回显标记
  2396. isAutoEcho.value = false;
  2397. }
  2398. // 初始化级联菜单在页面刚打开时的默认值
  2399. initDefaultValue(props.modelValue, needInitParam);
  2400. //设置mode2的下级下拉菜单的上级菜单当前值
  2401. setNextSelectUpperValue();
  2402. }
  2403. //选中要回显的默认值
  2404. const matchAndSelect = (value) => {
  2405. const matchedOption = props.opt.find((opt) => opt.value === value);
  2406. if (matchedOption) {
  2407. selectItem.value = matchedOption;
  2408. emit("update:modelValue", value);
  2409. emit("change", value);
  2410. }
  2411. };
  2412. /// 再增加,抄自 SsObjp.updateOptionBYInputText(inpTxt) -- SsCcp 支持 inp="true"。Lin
  2413. // 增加处理同时带多个级联 -- 单位 > 部门 + 单位 > 上级人员
  2414. //可录入的objPicker,更新下拉菜单选项
  2415. async function updateOptionBYInputText(inpTxt) {
  2416. try {
  2417. let objectPickerParam;
  2418. let url = props.url;
  2419. /// 再增加,增加 parm,只处理最后一个级联 -- 增加处理同时带多个级联:单位 > 部门 + 单位 > 上级人员。Lin
  2420. // 下面的程序里,相应地改动:
  2421. // props.cb 改为 parm.codebook -- <ss-ccp 在 param= 里写 codebook:'jzw'
  2422. // props.filter 改为 parm.filter -- <ss-ccp 在 param= 里写 filter:
  2423. // props.filterfield 改为 parm.filterfield -- <ss-ccp 在 param= 里写 filterfield:
  2424. // props.param.fieldOrd 改为 parm.fieldOrd -- <ss-ccp 在 param= 里写 fieldOrd:
  2425. let parm;
  2426. if (Array.isArray(props.param))
  2427. parm = props.param[props.param.length -1]; //只初始化数组最后一项
  2428. else
  2429. parm = props.param;
  2430. ///
  2431. if (props.url && parm.codebook) { // && props.cb)。<ss-ccp 在 param= 里写 codebook:'jzw'。Lin
  2432. //如果有定义过滤器
  2433. if (parm.filter || // (props.filter ||。<ss-ccp 在 param= 里写 filter:。Lin
  2434. parm.filterfield) { // props.filterfield)。<ss-ccp 在 param= 里写 filterfield:。Lin
  2435. let filterObj = parm.filter; // = props.filter。<ss-ccp 在 param= 里写 filter:。Lin
  2436. if (!parm.filter) // (!props.filter)。<ss-ccp 在 param= 里写 filter:。Lin
  2437. filterObj = {};
  2438. if (parm.filter) { // (props.filter)。<ss-ccp 在 param= 里写 filter:。Lin
  2439. const filterObj = parm.filter; // "转为json对象"。= props.filter。<ss-ccp 在 param= 里写 filter:。Lin
  2440. for (let k in filterObj) {
  2441. let v = filterObj[k];
  2442. url += "&" + k + "=" + v;
  2443. }
  2444. }
  2445. if (parm.filterfield) { // (props.filterfield)。<ss-ccp 在 param= 里写 filterfield:。Lin
  2446. //加上filterfield的值过滤
  2447. let filterfieldArr = parm.filterfield.split(","); // = props.filterfield.。<ss-ccp 在 param= 里写 filterfield:。Lin
  2448. for (var i = 0; i < filterfieldArr.length; i++) {
  2449. let fieldName = filterfieldArr[i];
  2450. let fields = document.getElementsByName(fieldName);
  2451. if (!fields || fields.length < 1) {
  2452. alert("下拉菜单配置的过滤条件" + fieldName + "不存在!");
  2453. continue;
  2454. }
  2455. let v = null;
  2456. for (let j = 0; j < fields.length; j++) {
  2457. if (fields[j].value) {
  2458. v = fields[j].value;
  2459. break;
  2460. }
  2461. }
  2462. // let field = document.getElementsByName(fieldName)[0];
  2463. // let v = field.value;
  2464. if (v) {
  2465. url += "&" + fieldName + "=" + v;
  2466. filterObj[fieldName] = v;
  2467. }
  2468. }
  2469. console.log("filterfield url:" + url);
  2470. }
  2471. //包含HTML实体的JSON字符串转为JSON对象,如原字符串是{&quot;dwid&quot;:&quot;88&quot;},注意key也必需用单引号包着
  2472. // const decodedString = props.filter.replace(/&quot;/g, '"'); // 转换为: {"dwid":"88"}
  2473. // objectPickerParam = JSON.parse(decodedString); // 转为json对象
  2474. objectPickerParam = filterObj;
  2475. objectPickerParam["input"] = props.inp;
  2476. objectPickerParam["codebook"] = parm.codebook; // = props.cb。<ss-ccp 在 param=里写 codebook:'jzw'。Lin
  2477. // alert(url);
  2478. } else {
  2479. objectPickerParam = { input: props.inp, codebook: parm.codebook }; // : props.cb }。<ss-ccp 在 param=里写 codebook:'jzw'。Lin
  2480. }
  2481. /// 再增加,设置 request."objectpickerparam" 里的 cascadingLevel: 值 -- SsCcp 支持 inp="true"。Lin
  2482. objectPickerParam["cascadingLevel"] = parm.fieldOrd.join(","); //如:"hksheng,hkshi,hkxian"
  2483. ///
  2484. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2485. const params = new URLSearchParams();
  2486. params.append("objectpickerparam", objectPickerParamStr);
  2487. params.append("objectpickertype", "1");
  2488. /// 再增加,设置上级选择的值 -- SsCcp 支持 inp="true"。Lin
  2489. if (upperValue.value)
  2490. params.append("upperValue", upperValue.value);
  2491. ///
  2492. if (props.inp && props.inp === true) {
  2493. //把"true"改为true Ben(20251209)
  2494. params.append("objectpickersearchAll", 0); //只查录入的值
  2495. params.append("objectpickerinput", inpTxt); //录入的值
  2496. // 功能说明:将输入值也加到 URL 参数,避免后端只读 URL 不读 body by xu 20250408
  2497. if (inpTxt) {
  2498. url += "&objectpickerinput=" + encodeURIComponent(inpTxt);
  2499. }
  2500. } else {
  2501. params.append("objectpickersearchAll", 1);
  2502. }
  2503. axios
  2504. .post(url, params, {
  2505. headers: {
  2506. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2507. },
  2508. })
  2509. .then((response) => {
  2510. if ("timeout" == response.data.statusText) {
  2511. alert("网络超时!");
  2512. return;
  2513. }
  2514. // 先清空选项 by xu 20251212
  2515. if (props.opt) {
  2516. props.opt.length = 0;
  2517. } else {
  2518. props.opt = [];
  2519. }
  2520. if (response.data.result) {
  2521. /* 改,ObjpResultB.result(Map<String, String>) 改为 List<Map<String, String>> -- 支持按服务器端的顺序显示下拉列表。Lin
  2522. const keys = Object.keys(response.data.result);
  2523. // console.log("params:"+params+"@@response.data:"+JSON.stringify(response.data));
  2524. if (keys.length > 0) {
  2525. for (let k in response.data.result) {
  2526. props.opt.push({
  2527. label: response.data.result[k],
  2528. value: k,
  2529. */
  2530. if (response.data.result.length > 0) {
  2531. for (let i=0; i<response.data.result.length; i++) {
  2532. var m = Object.entries(response.data.result[i])[0];
  2533. props.opt.push({
  2534. label: m[1],
  2535. value: m[0],
  2536. });
  2537. }
  2538. // console.log('###inpTxt:'+inpTxt+';');
  2539. if (
  2540. props.inp &&
  2541. props.inp === true && //把"true"改为true Ben(20251209)
  2542. inpTxt.length > 0
  2543. ) {
  2544. //对于可录入的,用已录入的值作过滤
  2545. /* 再改,改为在后台过滤录入框录入的内容。Lin
  2546. filteredOptions.value = props.opt.filter((option) =>
  2547. option.label
  2548. .toLowerCase()
  2549. .includes(inputText.value.toLowerCase())
  2550. );
  2551. */ filteredOptions.value = props.opt;
  2552. // 可录入的objPicker,当搜索结果只有一项时,自动选中这一项 by xu 20251212
  2553. if (filteredOptions.value.length === 1) {
  2554. const autoSelectItem = filteredOptions.value[0];
  2555. console.log(
  2556. "[objp] 搜索结果只有一项,自动选中:",
  2557. autoSelectItem
  2558. );
  2559. doSelectItem(autoSelectItem);
  2560. return; // 自动选中后直接返回,不需要显示popup
  2561. }
  2562. filteredOptions.value.unshift({ label: "", value: "" });
  2563. // console.log('###做了过滤:'+inputText.value.toLowerCase()+';');
  2564. } else {
  2565. filteredOptions.value = props.opt;
  2566. filteredOptions.value.unshift({ label: "", value: "" });
  2567. }
  2568. console.log("props.opt11:" + JSON.stringify(props.opt));
  2569. } else {
  2570. // 没有数据时,清空过滤选项 by xu 20251212
  2571. filteredOptions.value = [];
  2572. console.log("[objp] 接口返回空数据");
  2573. }
  2574. } else {
  2575. // result不存在时,清空过滤选项 by xu 20251212
  2576. filteredOptions.value = [];
  2577. console.log("[objp] 接口返回无result");
  2578. }
  2579. // 无论是否有数据,都显示popup by xu 20251212
  2580. openPopup(); // Teleport 场景下统一打开并重定位 by xu 20260126
  2581. });
  2582. }
  2583. } catch (error) {
  2584. // callback(null, error.message); // 失败回调,传递错误
  2585. }
  2586. }
  2587. ///
  2588. // 计算弹出方向和最大高度的方法 by xu 20251212
  2589. // 当空间不足时限制popup高度并显示滚动条
  2590. const calculatePopupDirection = () => {
  2591. // 1. 获取select容器元素
  2592. const selectEl = document.querySelector(
  2593. `[name="${props.name}"]`
  2594. )?.nextElementSibling;
  2595. console.log("selectEl:" + selectEl, props.name);
  2596. if (!selectEl) return;
  2597. // 2. 获取位置信息
  2598. const selectRect = selectEl.getBoundingClientRect();
  2599. const viewportHeight = window.innerHeight;
  2600. // 3. 计算上下可用空间 by xu 20251212
  2601. const spaceBelow = viewportHeight - selectRect.bottom - 10; // 减10px留边距
  2602. const spaceAbove = selectRect.top - 10; // 减10px留边距
  2603. // 4. popup预估高度(假设每项36px,最多显示8项 + padding)
  2604. const estimatedPopupHeight = 300;
  2605. const minPopupHeight = 100; // 最小高度
  2606. console.log(
  2607. "[popup] 空间计算 - spaceAbove:",
  2608. spaceAbove,
  2609. "spaceBelow:",
  2610. spaceBelow,
  2611. "estimatedHeight:",
  2612. estimatedPopupHeight
  2613. );
  2614. // 5. 判断方向和最大高度 by xu 20251212
  2615. if (spaceBelow >= estimatedPopupHeight) {
  2616. // 下方空间足够,向下展开,不限制高度
  2617. popupDirection.value = "bottom";
  2618. popupMaxHeight.value = "none";
  2619. console.log("[popup] 向下展开,空间充足");
  2620. } else if (spaceAbove >= estimatedPopupHeight) {
  2621. // 上方空间足够,向上展开,不限制高度
  2622. popupDirection.value = "top";
  2623. popupMaxHeight.value = "none";
  2624. console.log("[popup] 向上展开,空间充足");
  2625. } else {
  2626. // 上下空间都不足,选择空间大的方向,并限制高度出滚动条
  2627. if (spaceBelow >= spaceAbove) {
  2628. popupDirection.value = "bottom";
  2629. popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px";
  2630. console.log(
  2631. "[popup] 向下展开,空间不足,限制高度:",
  2632. popupMaxHeight.value
  2633. );
  2634. } else {
  2635. popupDirection.value = "top";
  2636. popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px";
  2637. console.log(
  2638. "[popup] 向上展开,空间不足,限制高度:",
  2639. popupMaxHeight.value
  2640. );
  2641. }
  2642. }
  2643. };
  2644. //级联菜单点击事件
  2645. const togglePopup = () => {
  2646. /// 再增加,来自 SsObjp.togglePopup() -- SsCcp 支持 inp="true"。Lin
  2647. // 可录入的 objPicker,更新下拉菜单选项
  2648. /* 再去掉,把 updateOptionBYInputText( 融入 showPopup() 里。Lin
  2649. * 导致读取了两次码本:updateOptionBYInputText( 带过滤,showPopup() 不带过滤
  2650. updateOptionBYInputText(inputText.value);
  2651. */
  2652. ///
  2653. if (!popupWinVisible.value) {
  2654. //如果当前下拉菜单是隐藏的,先ajax重新加载下拉菜单项,再显示。
  2655. showPopup();
  2656. } else {
  2657. hidePopup();
  2658. }
  2659. };
  2660. //显示下拉菜单,在此之前先清除下拉菜单项
  2661. const showPopup = () => {
  2662. //清空下拉菜单,并设置第一项的值为空
  2663. clearAndInit1stOpt();
  2664. Vue.nextTick(() => {
  2665. calculatePopupDirection();
  2666. });
  2667. let url = props.url;
  2668. let filterObj = props.param.filter;
  2669. if (filterObj) {
  2670. for (let k in filterObj) {
  2671. let v = filterObj[k];
  2672. url += "&" + k + "=" + v;
  2673. }
  2674. }
  2675. if (props.mode === "1") {
  2676. //如果是有隐藏字段的下拉菜单
  2677. console.log("666url:" + url);
  2678. // alert('url:'+url);
  2679. // 获取级联菜单所有下拉菜单项
  2680. async function getSelectItems(value) {
  2681. try {
  2682. // alert(1);
  2683. if (props.url && props.param) {
  2684. // alert(2);
  2685. /**
  2686. * param={"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  2687. * "\"name\":\"hksheng\",\"cascadingName\":\"dq\"," +
  2688. * "\"cascadingInputsName\":\"hkdqm\",\"codebook\":\"sheng\"}",
  2689. * "objectpickertype":1,//2表示获取要回显的一项,1表示获取所有下拉菜单项
  2690. * "upperValue":"440000"
  2691. * };
  2692. */
  2693. const objectPickerParam = {
  2694. input: "false",
  2695. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2696. name: props.name, //本下拉菜单名
  2697. cascadingName: props.param.name, //级联菜单名
  2698. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  2699. codebook: props.param.codebook,
  2700. };
  2701. console.log("mode1 upperValue.value:" + upperValue.value);
  2702. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2703. const params = new URLSearchParams();
  2704. params.append("objectpickerparam", objectPickerParamStr);
  2705. params.append("objectpickertype", "1");
  2706. if (upperValue.value) {
  2707. params.append("upperValue", upperValue.value);
  2708. }
  2709. // params.append('objectpickervalue', value); //需回显的值
  2710. axios
  2711. .post(url, params, {
  2712. headers: {
  2713. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2714. },
  2715. })
  2716. .then((response) => {
  2717. if ("timeout" == response.data.statusText) {
  2718. alert("网络超时!");
  2719. return;
  2720. }
  2721. if (response.data.result) {
  2722. /* 改,ObjpResultB.result(Map<String, String>) 改为 List<Map<String, String>> -- 支持按服务器端的顺序显示下拉列表。Lin
  2723. const keys = Object.keys(response.data.result);
  2724. console.log(
  2725. "params:" +
  2726. params +
  2727. "@@response.data:" +
  2728. JSON.stringify(response.data)
  2729. );
  2730. if (keys.length > 0) {
  2731. for (let k in response.data.result) {
  2732. props.opt.push({
  2733. label: response.data.result[k],
  2734. value: k,
  2735. */
  2736. if (response.data.result.length > 0) {
  2737. for (let i=0; i<response.data.result.length; i++) {
  2738. var m = Object.entries(response.data.result[i])[0];
  2739. props.opt.push({
  2740. label: m[1],
  2741. value: m[0],
  2742. });
  2743. }
  2744. console.log("props.opt11:" + JSON.stringify(props.opt));
  2745. } else {
  2746. // 没有数据时打印日志 by xu 20251212
  2747. console.log("[ccp mode1] 接口返回空数据");
  2748. }
  2749. } else {
  2750. // result不存在时打印日志 by xu 20251212
  2751. console.log("[ccp mode1] 接口返回无result");
  2752. }
  2753. // 无论是否有数据,都显示popup by xu 20251212
  2754. if (!popupWinVisible.value) {
  2755. popupWinVisible.value = true;
  2756. }
  2757. /// 增加,"修复表格内弹层被截断:popup Teleport 到 body"。抄自 SsObjp.template。Lin
  2758. // 无论是否有数据,都显示popup by xu 20251212
  2759. openPopup(); // Teleport 场景下统一打开并重定位 by xu 20260126
  2760. ///
  2761. });
  2762. }
  2763. } catch (error) {
  2764. alert(error);
  2765. // callback(null, error.message); // 失败回调,传递错误
  2766. }
  2767. }
  2768. getSelectItems(props.modelValue);
  2769. } else if (props.mode === "2") {
  2770. //没隐藏字段的下拉菜单
  2771. let needInitParam = undefined;
  2772. if (Array.isArray(props.param)) {
  2773. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  2774. console.log(
  2775. "needInitParam最后一项:" + JSON.stringify(needInitParam)
  2776. );
  2777. } else {
  2778. needInitParam = props.param;
  2779. }
  2780. // 获取级联菜单所有下拉菜单项
  2781. async function getSelectItems(value, sendParam) {
  2782. try {
  2783. // alert(1);
  2784. if (props.url && sendParam) {
  2785. // alert(2);
  2786. /**
  2787. * param="{\"input\":\"false\",\"cascadingLevel\":\"dwid,sjryid\",
  2788. * \"ryid\":\"111121\",\"name\":\"sjryid\",
  2789. * \"cascadingName\":\"dw_sjry\",\"codebook\":\"sjryByDw\"}"
  2790. */
  2791. const objectPickerParam = {
  2792. input: "false",
  2793. cascadingLevel: sendParam.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2794. name: props.name, //本下拉菜单名
  2795. cascadingName: sendParam.name, //级联菜单名
  2796. codebook: sendParam.codebook,
  2797. };
  2798. console.log("mode2 upperValue.value:" + upperValue.value);
  2799. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2800. const params = new URLSearchParams();
  2801. params.append("objectpickerparam", objectPickerParamStr);
  2802. params.append("objectpickertype", "1");
  2803. /// 再增加,增加 objectpickerinput: inputText.value -- SsCcp 支持 inp="true"。Lin
  2804. /* 再改,不过滤录入框里的内容 -- 修正点击录入框的行为。Lin
  2805. params.append("objectpickerinput", inputText.value);
  2806. */ params.append("objectpickerinput", "");
  2807. ///
  2808. if (upperValue.value) {
  2809. params.append("upperValue", upperValue.value);
  2810. }
  2811. // params.append('objectpickervalue', value); //需回显的值
  2812. axios
  2813. .post(url, params, {
  2814. headers: {
  2815. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2816. },
  2817. })
  2818. .then((response) => {
  2819. if ("timeout" == response.data.statusText) {
  2820. alert("网络超时!");
  2821. return;
  2822. }
  2823. if (response.data.result) {
  2824. /* 改,ObjpResultB.result(Map<String, String>) 改为 List<Map<String, String>> -- 支持按服务器端的顺序显示下拉列表。Lin
  2825. const keys = Object.keys(response.data.result);
  2826. console.log(
  2827. "params:" +
  2828. params +
  2829. "@@response.data:" +
  2830. JSON.stringify(response.data)
  2831. );
  2832. if (keys.length > 0) {
  2833. for (let k in response.data.result) {
  2834. props.opt.push({
  2835. label: response.data.result[k],
  2836. value: k,
  2837. */
  2838. if (response.data.result.length > 0) {
  2839. for (let i=0; i<response.data.result.length; i++) {
  2840. var m = Object.entries(response.data.result[i])[0];
  2841. props.opt.push({
  2842. label: m[1],
  2843. value: m[0],
  2844. });
  2845. }
  2846. console.log("props.opt11:" + JSON.stringify(props.opt));
  2847. } else {
  2848. // 没有数据时打印日志 by xu 20251212
  2849. console.log("[ccp mode2] 接口返回空数据");
  2850. }
  2851. } else {
  2852. // result不存在时打印日志 by xu 20251212
  2853. console.log("[ccp mode2] 接口返回无result");
  2854. }
  2855. // 无论是否有数据,都显示popup by xu 20251212
  2856. if (!popupWinVisible.value) {
  2857. popupWinVisible.value = true;
  2858. }
  2859. /// 增加,"修复表格内弹层被截断:popup Teleport 到 body"。抄自 SsObjp.template。Lin
  2860. // 无论是否有数据,都显示popup by xu 20251212
  2861. openPopup(); // Teleport 场景下统一打开并重定位 by xu 20260126
  2862. ///
  2863. });
  2864. }
  2865. } catch (error) {
  2866. alert(error);
  2867. // callback(null, error.message); // 失败回调,传递错误
  2868. }
  2869. }
  2870. getSelectItems(props.modelValue, needInitParam);
  2871. // popupWinVisible.value = !popupWinVisible.value;
  2872. }
  2873. };
  2874. const hidePopup = () => {
  2875. popupWinVisible.value = false;
  2876. };
  2877. /// 再增加,增加下拉按钮的 suffixClick 事件 -- SsCcp 支持 inp="true"。Lin
  2878. // 之前,无论点击 录入框 还是 下拉按钮,都只列出选中的那个 "测试_A宿舍楼"
  2879. //点击下拉菜单的三角形时,会触发的方法
  2880. // 添加toggle逻辑,点击时切换显示/隐藏 by xu 20251212
  2881. /* 再去掉,去掉下拉按钮了。Lin
  2882. const suffixClick = () => {
  2883. // 如果popup已显示,则关闭 by xu 20251212
  2884. if (popupWinVisible.value) {
  2885. hidePopup();
  2886. console.log("[ccp] 点三角关闭popup");
  2887. return;
  2888. }
  2889. //可录入的objPicker,更新下拉菜单选项
  2890. updateOptionBYInputText("");
  2891. Vue.nextTick(() => {
  2892. calculatePopupDirection();
  2893. updatePopupPosition(); // Teleport 场景下同步定位 by xu 20260126
  2894. });
  2895. console.log("[ccp] 点三角打开popup");
  2896. };
  2897. */
  2898. ///
  2899. /// 增加,"修复表格内弹层被截断:popup Teleport 到 body"。抄自 SsObjp.template。Lin
  2900. // 增加 leaveInput、enterInput、leavePopup、enterPopup,以实现录入行和下拉选择框互相离开、进入时不关闭下拉选择框
  2901. // 增加延时 hidePopupTimer 和 clearTimerByHidePopup(),等待鼠标从录入行进入下拉选择框(mouseenter事件) -- 鼠标一旦进入下拉选择框,清除延时,阻止关闭下拉选择框
  2902. let hidePopupTimer = null; // 等待鼠标从录入行进入下拉选择框 -- 延时到才关闭。Lin
  2903. // 鼠标离开录入行(mouseleave事件) -- 保持下拉选择框。Lin
  2904. const leaveInput = () => {
  2905. hidePopupTimer = setTimeout(() => {
  2906. popupWinVisible.value = false;
  2907. }, 200); // 200ms延迟,给鼠标移动到下拉选择框的时间
  2908. };
  2909. // 鼠标进入下拉选择框(mouseenter事件) -- 保持下拉选择框。Lin
  2910. const enterPopup = () => {
  2911. clearTimeout(hidePopupTimer); // 清除等待关闭的定时器
  2912. popupWinVisible.value = true;
  2913. };
  2914. let keepPopupTimer = null; // 等待鼠标从下拉选择框进入录入行 -- 延时到才关闭。Lin
  2915. // 鼠标离开下拉选择框(mouseleave事件) -- 保持下拉选择框。Lin
  2916. const leavePopup = () => {
  2917. keepPopupTimer = setTimeout(() => {
  2918. popupWinVisible.value = false;
  2919. }, 200); // 200ms延迟,给鼠标移动到下拉选择框的时间
  2920. };
  2921. // 鼠标进入录入行(mouseenter事件) -- 保持下拉选择框。Lin
  2922. const enterInput = () => {
  2923. if (popupWinVisible.value) {
  2924. clearTimeout(keepPopupTimer); // 清除等待关闭的定时器
  2925. popupWinVisible.value = true;
  2926. }
  2927. };
  2928. ///
  2929. /// 再增加,抄自 Objp.handleInputChange(event) -- SsCcp 支持 inp="true"。Lin
  2930. //可录入的objPicker,录入项变化时,会触发
  2931. async function handleInputChange(event) {
  2932. inputText.value = event.target.value;
  2933. if (!inputText.value) {
  2934. inputText.value = "";
  2935. }
  2936. //可录入的objPicker,更新下拉菜单选项
  2937. updateOptionBYInputText(inputText.value);
  2938. // filteredOptions.value = props.opt.filter((option) =>
  2939. // option.label.toLowerCase().includes(inputText.value.toLowerCase())
  2940. // );
  2941. // if (!popupWinVisible.value) {
  2942. // popupWinVisible.value = true; // 确保下拉框在输入时打开
  2943. // }
  2944. }
  2945. ///
  2946. // 合并所有的 onMounted 逻辑
  2947. Vue.onMounted(() => {
  2948. window.addEventListener("resize", calculatePopupDirection);
  2949. // 1. 监听展开下一级事件
  2950. window.addEventListener("open-next-cascader", (event) => {
  2951. const { name, level } = event.detail;
  2952. if (name === props.name && level === props.level) {
  2953. popupWinVisible.value = true;
  2954. }
  2955. });
  2956. // 2. 监听级联事件
  2957. window.addEventListener("cascader-change", (event) => {
  2958. const { name, level, value } = event.detail;
  2959. if (name === props.name && level < props.level) {
  2960. selectItem.value = { label: "", value: "" };
  2961. emit("update:modelValue", "");
  2962. if (ssHidden) {
  2963. ssHidden.updateValue(value);
  2964. }
  2965. }
  2966. });
  2967. });
  2968. Vue.onUnmounted(() => {
  2969. window.removeEventListener("resize", calculatePopupDirection);
  2970. });
  2971. // 监听值变化,处理回显 (mode 2)
  2972. Vue.watch(
  2973. () => props.modelValue,
  2974. (newVal) => {
  2975. if (props.mode === "2" && newVal) {
  2976. // 使用 watchEffect 替代嵌套的 watch
  2977. Vue.watchEffect(() => {
  2978. if (props.opt.length > 0) {
  2979. const matchedOption = props.opt.find(
  2980. (opt) => opt.value === newVal
  2981. );
  2982. if (matchedOption) {
  2983. selectItem.value = matchedOption;
  2984. }
  2985. }
  2986. });
  2987. } else {
  2988. // 原有的值变化处理
  2989. const item = props.opt.find((it) => it.value === newVal);
  2990. if (item) {
  2991. selectItem.value = item;
  2992. } else {
  2993. selectItem.value = { label: "", value: "" };
  2994. }
  2995. }
  2996. },
  2997. { immediate: true }
  2998. );
  2999. // 监听选项变化,当数据加载完成时进行匹配
  3000. Vue.watch(
  3001. () => props.opt,
  3002. (newOptions) => {
  3003. /// 再增加,来自 SsObjp.Vue.watch(() => props.opt, (newOptions) => { -- SsCcp 支持 inp="true"。Lin
  3004. updateSelectItem();
  3005. filteredOptions.value = [...newOptions];
  3006. ///
  3007. if (newOptions.length > 0) {
  3008. const matchedOption = newOptions.find(
  3009. (opt) => opt.value === selectItem.value.value
  3010. );
  3011. if (matchedOption) {
  3012. selectItem.value = matchedOption;
  3013. emit("update:modelValue", matchedOption.value);
  3014. emit("change", matchedOption.value);
  3015. }
  3016. }
  3017. }
  3018. );
  3019. ///// 再增加,抄自 SsObjp.Vue.watch(() => props.modelValue, handleModelValueChange, { immediate: true }) -- SsCcp 支持 inp="true"。Lin
  3020. /* 再去掉,应该没用。Lin
  3021. * 调用 props.onchange 指定的方法
  3022. * 在增加支持改变值后的回调前,props.onchange 没有值
  3023. * 增加支持改变值后的回调后,值为改变值后的回调方法
  3024. * 另,在 const doSelectItem = (item) => { 里的 window[props.onchange](item.value) 调用了 onChange=方法
  3025. // 功能说明:调用全局 onChange 回调,必须在 handleModelValueChange 之前定义 by xu 20260416
  3026. const callGlobalOnchg = (value, desc) => {
  3027. if (props.onchange && typeof props.onchange === "string") {
  3028. if (
  3029. typeof window !== "undefined" &&
  3030. window[props.onchange] &&
  3031. typeof window[props.onchange] === "function"
  3032. ) {
  3033. try {
  3034. window[props.onchange](value, desc);
  3035. } catch (error) {
  3036. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  3037. }
  3038. }
  3039. }
  3040. };
  3041. */
  3042. // 功能说明:封装 modelValue 变化后的联动逻辑,兼容用户点击和桥接 API 赋值 by xu 20260416
  3043. const handleModelValueChange = (newValue) => {
  3044. updateSelectItem();
  3045. /* 改,增加 && newValue !== "0",显示必填字段下拉选择框里的 钩(选中) -- 必填字段为 int/long,其默认值为 0。Lin
  3046. * 被下面的 Vue.watch(() => props.modelValue, handleModelValueChange, { immediate: true }) 调用,并传入 props.modelValue 到 newValue
  3047. if (newValue) {
  3048. */ if (newValue && newValue !== "0") {
  3049. // 如果当前 options 里没有对应项,去服务端请求回显
  3050. const exists = props.opt.some((it) => it.value === newValue);
  3051. if (!exists && props.url && props.cb) {
  3052. let url = props.url;
  3053. if (props.filter) {
  3054. const filterObj = props.filter;
  3055. for (let k in filterObj) {
  3056. url += "&" + k + "=" + filterObj[k];
  3057. }
  3058. }
  3059. const params = new URLSearchParams();
  3060. params.append("objectpickerparam", JSON.stringify({ input: props.inp, codebook: props.cb }));
  3061. params.append("objectpickertype", "2");
  3062. params.append("objectpickervalue", newValue);
  3063. axios.post(url, params, {
  3064. headers: { "Content-Type": "application/x-www-form-urlencoded" }
  3065. }).then((response) => {
  3066. if ("timeout" == response.data.statusText) {
  3067. alert("网络超时!");
  3068. return;
  3069. }
  3070. if (response.data.result) {
  3071. /* 改,ObjpResultB.result(Map<String, String>) 改为 List<Map<String, String>> -- 支持按服务器端的顺序显示下拉列表。Lin
  3072. const keys = Object.keys(response.data.result);
  3073. if (keys.length === 1) {
  3074. let code = keys[0];
  3075. let desc = response.data.result[keys[0]];
  3076. */
  3077. if (response.data.result.length === 1) {
  3078. var m = Object.entries(response.data.result[0])[0];
  3079. let code = m[0];
  3080. let desc = m[1];
  3081. props.opt.length = 0;
  3082. props.opt.push({ label: desc, value: code });
  3083. updateSelectItem();
  3084. /* 再去掉,应该没用。Lin
  3085. * 调用 props.onchange 指定的方法
  3086. * 在增加支持改变值后的回调前,props.onchange 没有值
  3087. * 增加支持改变值后的回调后,值为改变值后的回调方法
  3088. callGlobalOnchg(code, desc);
  3089. */
  3090. }
  3091. }
  3092. });
  3093. } else if (selectItem.value && selectItem.value.value) {
  3094. /* 再去掉,应该没用。Lin
  3095. * 调用 props.onchange 指定的方法
  3096. * 在增加支持改变值后的回调前,props.onchange 没有值
  3097. * 增加支持改变值后的回调后,值为改变值后的回调方法
  3098. // options 里有对应项,触发 onChange
  3099. callGlobalOnchg(selectItem.value.value, selectItem.value.label);
  3100. */
  3101. }
  3102. } else {
  3103. /* 再去掉,应该没用。Lin
  3104. * 调用 props.onchange 指定的方法
  3105. * 在增加支持改变值后的回调前,props.onchange 没有值
  3106. * 增加支持改变值后的回调后,值为改变值后的回调方法
  3107. // 值为空时清空选中
  3108. callGlobalOnchg("", "");
  3109. */
  3110. }
  3111. };
  3112. Vue.watch(() => props.modelValue, handleModelValueChange, { immediate: true });
  3113. /////
  3114. ///// 增加,"修复表格内弹层被截断:popup Teleport 到 body"。抄自 SsObjp.setup(。Lin
  3115. // Teleport popup 的定位(fixed) by xu 20260126
  3116. const updatePopupPosition = () => {
  3117. /* 改,抄自 SsCcp.calculatePopupDirection()。Lin
  3118. * 在 SsObjp.updatePopupPosition() 里,能通过 selectContainerRef 获取到 triggerEl
  3119. * 在 SsObjp.template: 里的 <div class="select-container",有 ref="selectContainerRef"
  3120. const triggerEl =
  3121. selectContainerRef.value?.querySelector(".input") ||
  3122. selectContainerRef.value;
  3123. */ const triggerEl = document.querySelector(
  3124. `[name="${props.name}"]`
  3125. )?.nextElementSibling;
  3126. if (!triggerEl) return;
  3127. const triggerRect = triggerEl.getBoundingClientRect();
  3128. const margin = 10;
  3129. const viewportWidth = window.innerWidth;
  3130. const viewportHeight = window.innerHeight;
  3131. /* 改,改为紧挨录入行的下拉按钮。Lin
  3132. const popupGap = 0; // 功能说明:定位不再做 -10 重叠,让 padding-top 自然形成间距 by xu 20260126
  3133. */
  3134. let popupGap;
  3135. if (props.search)
  3136. popupGap = -8;
  3137. else
  3138. popupGap = -18;
  3139. // 先给一个初始位置,确保下一帧可以测量弹层尺寸 by xu 20260126
  3140. popupLayerStyle.value = {
  3141. position: "fixed",
  3142. left: `${Math.max(margin, triggerRect.left)}px`,
  3143. top: `${Math.max(margin, triggerRect.bottom + popupGap)}px`, // 功能说明:与输入框底部对齐 by xu 20260126
  3144. bottom: "auto", // 功能说明:fixed 场景显式取消 bottom,避免与 top 同时生效 by xu 20260126
  3145. minWidth: `${Math.max(0, triggerRect.width)}px`,
  3146. zIndex: 9999,
  3147. pointerEvents: "auto",
  3148. };
  3149. Vue.nextTick(() => {
  3150. const popupEl = popupRef.value;
  3151. if (!popupEl) return;
  3152. const popupRect = popupEl.getBoundingClientRect();
  3153. const maxLeft = viewportWidth - popupRect.width - margin;
  3154. const left = Math.min(
  3155. Math.max(margin, triggerRect.left),
  3156. Math.max(margin, maxLeft)
  3157. );
  3158. let top;
  3159. if (popupDirection.value === "top") {
  3160. /* 改,上拉时,紧挨录入行的下拉按钮。Lin
  3161. top = triggerRect.top - popupRect.height - popupGap; // 功能说明:向上展开时与输入框顶部对齐 by xu 20260126
  3162. */ top = triggerRect.top - popupRect.height - popupGap -10; // 功能说明:向上展开时与输入框顶部对齐 by xu 20260126
  3163. top = Math.max(margin, top);
  3164. } else {
  3165. top = triggerRect.bottom + popupGap; // 功能说明:向下展开时与输入框底部对齐 by xu 20260126
  3166. if (top + popupRect.height > viewportHeight - margin) {
  3167. top = Math.max(
  3168. margin,
  3169. viewportHeight - popupRect.height - margin
  3170. );
  3171. }
  3172. }
  3173. popupLayerStyle.value = {
  3174. ...popupLayerStyle.value,
  3175. left: `${left}px`,
  3176. top: `${top}px`,
  3177. bottom: "auto", // 功能说明:无论 top/bottom 展开都用 top 定位,禁用 bottom by xu 20260126
  3178. };
  3179. });
  3180. };
  3181. /// 再增加,增加 cascader-hidePopup-xxx 事件,以关闭所有下级下拉列表。Lin
  3182. // 被上级下拉菜单触发的,清除选中值和下拉菜单选项
  3183. window.addEventListener("cascader-hidePopup-"+ props.name,
  3184. async (event) => {
  3185. hidePopup();
  3186. //下个下拉菜单名
  3187. const nextSelName = getNextSel(props.name, props.param.fieldOrd);
  3188. // alert('nextSelName:'+nextSelName+'--,props.name:'+props.name);
  3189. if (nextSelName) {
  3190. //清下个下拉菜单选中值和选项
  3191. const customEvent = new CustomEvent("cascader-hidePopup-"+ nextSelName);
  3192. window.dispatchEvent(customEvent);
  3193. }
  3194. });
  3195. ///
  3196. const openPopup = () => {
  3197. if (!popupWinVisible.value) popupWinVisible.value = true;
  3198. ///// 再增加,增加打开本级下拉列表时关闭所有下级下拉列表。Lin
  3199. /// 抄自 SsCcp.doSelectItem(item)。Lin
  3200. //设置下级菜单的上级菜单当前值upperValue
  3201. let paramArr;
  3202. if (Array.isArray(props.param)) {
  3203. paramArr = props.param;
  3204. } else {
  3205. paramArr = [];
  3206. paramArr.push(props.param);
  3207. }
  3208. for (const oneParam of paramArr) {
  3209. //下个下拉菜单名
  3210. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  3211. if (nextSelName) {
  3212. ///
  3213. /// 抄自 SsCcp.window.addEventListener("cascader-open-" + props.name。Lin
  3214. //清下个下拉菜单选中值和选项
  3215. const customEvent = new CustomEvent("cascader-hidePopup-"+ nextSelName);
  3216. window.dispatchEvent(customEvent);
  3217. ///
  3218. }
  3219. }
  3220. /////
  3221. Vue.nextTick(() => {
  3222. calculatePopupDirection();
  3223. updatePopupPosition();
  3224. });
  3225. };
  3226. /////
  3227. return {
  3228. selectItem,
  3229. popupWinVisible,
  3230. popupDirection,
  3231. popupMaxHeight, // 添加popup最大高度 by xu 20251212
  3232. togglePopup,
  3233. hidePopup,
  3234. doSelectItem,
  3235. /// 增加,"修复表格内弹层被截断:popup Teleport 到 body"。抄自 SsObjp.setup(。Lin
  3236. leaveInput,
  3237. enterInput,
  3238. leavePopup,
  3239. enterPopup,
  3240. popupRef,
  3241. teleportRootStyle,
  3242. popupLayerStyle,
  3243. ///
  3244. /// 增加,增加 <ss-ccp :inp= -- SsCcp 支持 inp="true"。Lin
  3245. canInput,
  3246. inputText,
  3247. handleInputChange,
  3248. // suffixClick, // 再去掉,去掉下拉按钮了。Lin
  3249. filteredOptions,
  3250. ///
  3251. };
  3252. },
  3253. template: `
  3254. <div class="input ss-ccp-container" style="position: relative" :style="{width: width}">
  3255. <input type="hidden" :name="name" :value="modelValue">
  3256. <!-- 改,"修复表格内弹层被截断:popup Teleport 到 body"。抄自 SsObjp.template。Lin
  3257. 把 @mouseleave="hidePopup" 拆分为 leaveInput、enterInput、leavePopup、enterPopup,以实现录入行和下拉选择框互相离开、进入时不关闭下拉选择框
  3258. <div class="select-container" @mouseleave="hidePopup">
  3259. --> <div class="select-container" @mouseleave="leaveInput" @mouseenter="enterInput">
  3260. <div class="input" @click="togglePopup">
  3261. <input
  3262. type="hidden"
  3263. :name="name"
  3264. :value="selectItem.value"
  3265. />
  3266. <!-- 再改,使其能录入 -- 抄自 SsObjp.template: 里的 <input v-if="canInput" -- SsCcp 支持 inp="true"。Lin
  3267. <input
  3268. :placeholder="placeholder"
  3269. :value="selectItem.label"
  3270. disabled
  3271. style="pointer-events: none;"
  3272. />
  3273. -->
  3274. <input
  3275. v-model="inputText"
  3276. @input="handleInputChange"
  3277. v-if="canInput"
  3278. :placeholder="placeholder"
  3279. />
  3280. <input
  3281. v-else
  3282. :placeholder="placeholder"
  3283. :value="selectItem.label"
  3284. disabled
  3285. style="pointer-events: none;"
  3286. />
  3287. <!-- 再去掉,去掉下拉按钮,改为段分隔符 L。Lin
  3288. <x!-- 再改,增加 @click.stop="suffixClick" -- 增加下拉按钮的 suffixClick 事件 -- SsCcp 支持 inp="true"。Lin
  3289. 之前,无论点击 录入框 还是 下拉按钮,都只列出选中的那个 "测试_A宿舍楼"
  3290. <div class="suffix">
  3291. --x> <div class="suffix" @click.stop="suffixClick">
  3292. <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
  3293. </div>
  3294. -->
  3295. </div>
  3296. <!-- 增加,"修复表格内弹层被截断:popup Teleport 到 body"。抄自 SsObjp.template。Lin
  3297. 增加 @mouseleave="leavePopup",鼠标离开下拉选择框时关闭
  3298. 增加 @mouseenter="enterPopup",清除 leaveInput 的延时,阻止下拉选择框的关闭 -->
  3299. <teleport to="body">
  3300. <div v-show="popupWinVisible" class="select-container ss-ccp-teleport-root" :style="teleportRootStyle"
  3301. @mouseleave="leavePopup" @mouseenter="enterPopup">
  3302. <!-- -->
  3303. <!-- popup弹出层,添加maxHeight和overflowY支持空间不足时滚动 by xu 20251212 -->
  3304. <!-- 改,"修复表格内弹层被截断:popup Teleport 到 body"。仿自 SsObjp.template。Lin
  3305. 去掉 :class="popupDirection",不要尖角
  3306. <div v-show="popupWinVisible" class="popup-win " :class="popupDirection" :style="{ maxHeight: popupMaxHeight, overflowY: popupMaxHeight !== 'none' ? 'auto' : 'visible' }">
  3307. <div v-if="opt && opt.length > 0" class="popup-content">
  3308. -->
  3309. <div ref="popupRef" class="popup-win " :style="[popupLayerStyle, { maxHeight: popupMaxHeight !== 'none' ? popupMaxHeight : 'none', overflowY: 'visible' }]">
  3310. <!-- 再改,增加 filteredOptions -- SsCcp 支持 inp="true"。Lin
  3311. <div v-if="opt && opt.length > 0" class="popup-content">
  3312. --> <div v-if="opt && opt.length && filteredOptions.length > 0" class="popup-content">
  3313. <div class="content-area">
  3314. <!-- 再改,增加 filteredOptions -- SsCcp 支持 inp="true"。Lin
  3315. <div
  3316. v-for="(item, index) in opt"
  3317. :key="index"
  3318. @click="doSelectItem(item)"
  3319. :class="{ active: item.value === selectItem.value }"
  3320. >
  3321. -->
  3322. <div
  3323. v-for="(item, index) in filteredOptions"
  3324. :key="index"
  3325. @click="doSelectItem(item)"
  3326. :class="{ active: item.value === selectItem.value }"
  3327. >
  3328. <span class="check-icon">
  3329. <ss-form-icon class="form-icon-select-checked" />
  3330. </span>
  3331. <span>{{ item.label }}</span>
  3332. </div>
  3333. </div>
  3334. </div>
  3335. <div v-else class="popup-content">
  3336. <div class="content-area">
  3337. <div class="content-area">
  3338. <span>无选项</span>
  3339. </div>
  3340. </div>
  3341. </div>
  3342. </div>
  3343. <!-- 增加,"修复表格内弹层被截断:popup Teleport 到 body"。抄自 SsObjp.template。Lin -->
  3344. </div>
  3345. </teleport>
  3346. <!-- -->
  3347. </div>
  3348. </div>
  3349. `,
  3350. };
  3351. // ss-date-picker 日期时间选择器组件
  3352. const SsDatePicker = {
  3353. name: "SsDatePicker",
  3354. props: {
  3355. modelValue: {
  3356. type: [String, Number, Date],
  3357. default: "",
  3358. },
  3359. name: {
  3360. type: String,
  3361. required: true,
  3362. },
  3363. type: {
  3364. type: String,
  3365. default: "date",
  3366. validator: (value) => ["date", "datetime", "time"].includes(value),
  3367. },
  3368. fmt: {
  3369. type: String,
  3370. default: null,
  3371. },
  3372. placeholder: {
  3373. type: String,
  3374. default: "",
  3375. },
  3376. width: {
  3377. type: String,
  3378. default: "100%",
  3379. },
  3380. },
  3381. emits: ["update:modelValue"],
  3382. setup(props, { emit }) {
  3383. const errMsg = ref("");
  3384. const validate = () => {
  3385. if (window.ssVm) {
  3386. const result = window.ssVm.validateField(props.name);
  3387. console.log("validate", window.ssVm.validateField(props.name));
  3388. errMsg.value = result.valid ? "" : result.message;
  3389. }
  3390. };
  3391. // 根据type确定默认格式
  3392. const defaultFormat = computed(() => {
  3393. switch (props.type) {
  3394. case "datetime":
  3395. return "YYYY-MM-DD HH:mm:ss";
  3396. case "date":
  3397. return "YYYY-MM-DD";
  3398. case "time":
  3399. return "HH:mm:ss";
  3400. }
  3401. });
  3402. const convertJavaFormatToElement = (javaFormat) => {
  3403. if (!javaFormat) return null;
  3404. return javaFormat
  3405. .replace("yyyy", "YYYY")
  3406. .replace("MM", "MM")
  3407. .replace("dd", "DD")
  3408. .replace("HH", "HH")
  3409. .replace("mm", "mm")
  3410. .replace("ss", "ss");
  3411. };
  3412. const finalFormat = computed(() => {
  3413. if (props.fmt) {
  3414. return convertJavaFormatToElement(props.fmt);
  3415. }
  3416. return defaultFormat.value;
  3417. });
  3418. // 使用 resolveComponent 获取组件
  3419. const ElDatePicker = resolveComponent("ElDatePicker");
  3420. const ElTimePicker = resolveComponent("ElTimePicker");
  3421. const SsFormIcon = resolveComponent("SsFormIcon");
  3422. const ElIcon = resolveComponent("ElIcon");
  3423. const handleValueUpdate = (val) => {
  3424. emit("update:modelValue", val);
  3425. emit("change", val); // 同时触发 change 事件
  3426. setTimeout(() => {
  3427. validate();
  3428. }, 50);
  3429. };
  3430. const dateType = computed(() => {
  3431. const fmt = props.fmt || "";
  3432. if (fmt.includes("HH:mm:ss")) {
  3433. return "datetime";
  3434. } else if (fmt.includes("HH:mm")) {
  3435. return "datetime";
  3436. } else if (fmt.includes("mm:ss")) {
  3437. return "time";
  3438. }
  3439. return "date";
  3440. });
  3441. let useTimePicker = true;
  3442. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  3443. if (props.fmt) {
  3444. //有fmt属性,则以fmt属性优先判断类型
  3445. if (/[dMy]/.test(props.fmt)) {
  3446. //如果有传入日期格式,且含年月日
  3447. useTimePicker = false;
  3448. } else {
  3449. useTimePicker = true;
  3450. }
  3451. } else if (props.type !== "time") {
  3452. useTimePicker = false;
  3453. }
  3454. return () =>
  3455. h("div", { class: "ss-date-picker", style: { width: props.width } }, [
  3456. h("input", {
  3457. type: "hidden",
  3458. name: props.name,
  3459. value: props.modelValue,
  3460. }),
  3461. // 选择组件
  3462. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  3463. modelValue: props.modelValue,
  3464. "onUpdate:modelValue": handleValueUpdate,
  3465. type: dateType.value,
  3466. format: finalFormat.value,
  3467. "value-format": finalFormat.value,
  3468. clearable: true,
  3469. placeholder: props.placeholder,
  3470. class: "custom-date-picker", // 用于自定义样式
  3471. "time-arrow-control": props.type === "datetime", // 修改这里
  3472. size: "large", // 添加这一行,改为 large 尺寸
  3473. style: { width: "100%" },
  3474. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  3475. }),
  3476. ]);
  3477. },
  3478. };
  3479. // ss-icon 图标
  3480. // v3.0 增加 class 属性分支:有 class 走新逻辑,否则走 v1.0 逻辑 by xu 20251212
  3481. // v3.0 用法: <ss-icon class="icon-obj-ry menu-icon" />
  3482. // v1.0 用法: <ss-icon name="setting" size="20px" />
  3483. const SsIcon = {
  3484. name: "SsIcon",
  3485. // v3.0 禁用 class 透传,手动处理 by xu 20251215
  3486. inheritAttrs: false,
  3487. props: {
  3488. // v1.0: 以下为旧属性
  3489. name: { type: String },
  3490. size: { type: [Number, String], default: 16 },
  3491. unit: { type: String, default: "px" },
  3492. color: String,
  3493. type: {
  3494. type: String,
  3495. default: ssIcon.name,
  3496. validator: function (value) {
  3497. return [ssIcon, commonIcon].some((icon) => icon.name === value);
  3498. },
  3499. },
  3500. },
  3501. emits: ["update:modelValue", "input", "blur", "change"],
  3502. setup(props, { emit, attrs }) {
  3503. // v3.0 分支:有 class 属性时直接渲染(从 attrs 获取) by xu 20251215
  3504. if (attrs.class) {
  3505. return () =>
  3506. h("i", { ...attrs, class: attrs.class + " icon-container" });
  3507. }
  3508. // v1.0 分支:原有逻辑
  3509. const useIconType = computed(() => {
  3510. return [ssIcon, commonIcon].find(
  3511. (iconConfig) => iconConfig.name === props.type
  3512. );
  3513. });
  3514. const iconName = computed(() => {
  3515. const iconConfig = useIconType.value; // 注意:使用 .value 来访问响应式引用的值
  3516. if (!iconConfig) {
  3517. console.error(`Icon type "${props.type}" not found.`);
  3518. return "";
  3519. }
  3520. const iconType = iconConfig.types[props.name];
  3521. if (!iconType) {
  3522. console.error(
  3523. `Icon name "${props.name}" not found in type "${props.type}".`
  3524. );
  3525. return "";
  3526. }
  3527. return `${iconConfig.prefix}${iconType}`;
  3528. });
  3529. // 类似地,你可以计算 fontFamily 和 style
  3530. const fontFamily = computed(() => {
  3531. return useIconType.value ? useIconType.value.family : "";
  3532. });
  3533. // console.log(iconName.value,fontFamily.value)
  3534. const style = computed(() => {
  3535. const sizeStyle = isNum(props.size)
  3536. ? `${props.size}${props.unit}`
  3537. : props.size;
  3538. const styleObj = {
  3539. fontSize: sizeStyle,
  3540. color: props.color || "",
  3541. };
  3542. return toStyleStr(styleObj);
  3543. });
  3544. // 使用渲染函数定义模板逻辑
  3545. return () =>
  3546. h("i", {
  3547. class: ["icon-container", iconName.value, fontFamily.value],
  3548. style: style.value,
  3549. });
  3550. },
  3551. };
  3552. // 通用icon
  3553. const SsCommonIcon = {
  3554. name: "SsCommonIcon",
  3555. props: {
  3556. class: {
  3557. type: String,
  3558. required: true,
  3559. },
  3560. },
  3561. setup(props) {
  3562. return () =>
  3563. h("i", {
  3564. class: props.class + " common-icon",
  3565. });
  3566. },
  3567. };
  3568. // 登录页icon
  3569. const SsLoginIcon = {
  3570. name: "SsLoginIcon",
  3571. props: {
  3572. class: {
  3573. type: String,
  3574. required: true,
  3575. },
  3576. },
  3577. setup(props) {
  3578. return () =>
  3579. h("div", {
  3580. class: props.class + " login-icon",
  3581. });
  3582. },
  3583. };
  3584. // 弹窗icon
  3585. const SsDialogIcon = {
  3586. name: "SsDialogIcon",
  3587. props: {
  3588. class: {
  3589. type: String,
  3590. required: true,
  3591. },
  3592. },
  3593. setup(props) {
  3594. return () =>
  3595. h("i", {
  3596. class: props.class + " dialog-icon",
  3597. });
  3598. },
  3599. };
  3600. // 全局左侧导航图标组件
  3601. const SsNavIcon = {
  3602. name: "SsNavIcon",
  3603. props: {
  3604. class: {
  3605. type: String,
  3606. required: true,
  3607. },
  3608. },
  3609. setup(props) {
  3610. return () =>
  3611. h("div", {
  3612. class: props.class + " nav-icon",
  3613. });
  3614. },
  3615. };
  3616. // 顶部工具栏图标组件
  3617. const SsHeaderIcon = {
  3618. name: "SsHeaderIcon",
  3619. props: {
  3620. class: {
  3621. type: String,
  3622. required: true,
  3623. },
  3624. },
  3625. setup(props) {
  3626. return () =>
  3627. h("div", {
  3628. class: props.class + " header-icon",
  3629. });
  3630. },
  3631. };
  3632. // 全局菜单图标组件
  3633. const SsGolbalMenuIcon = {
  3634. name: "SsGolbalMenuIcon",
  3635. props: {
  3636. class: {
  3637. type: String,
  3638. required: true,
  3639. },
  3640. },
  3641. setup(props) {
  3642. return () =>
  3643. h("div", {
  3644. class: props.class + " global-menu-icon",
  3645. });
  3646. },
  3647. };
  3648. // 全局查询列表卡片图标
  3649. const SsCartListIcon = {
  3650. name: "SsCartListIcon",
  3651. props: {
  3652. class: {
  3653. type: String,
  3654. required: true,
  3655. },
  3656. },
  3657. setup(props) {
  3658. return () =>
  3659. h("div", {
  3660. class: props.class + " cart-list-icon",
  3661. });
  3662. },
  3663. };
  3664. // 全局底部工具栏图标组件
  3665. const SsQuickIcon = {
  3666. name: "SsQuickIcon",
  3667. props: {
  3668. class: {
  3669. type: String,
  3670. required: true,
  3671. },
  3672. },
  3673. setup(props) {
  3674. return () =>
  3675. h("div", {
  3676. class: props.class + " quick-icon",
  3677. });
  3678. },
  3679. };
  3680. // 表单组件icon
  3681. const SsFormIcon = {
  3682. name: "SsFormIcon",
  3683. props: {
  3684. class: {
  3685. type: String,
  3686. required: true,
  3687. },
  3688. },
  3689. setup(props) {
  3690. return () =>
  3691. h("div", {
  3692. class: props.class + " form-icon",
  3693. });
  3694. },
  3695. };
  3696. // 弹窗底部按钮icon
  3697. const SsBottomDivIcon = {
  3698. name: "SsBottomDivIcon",
  3699. props: {
  3700. class: {
  3701. type: String,
  3702. required: true,
  3703. },
  3704. },
  3705. setup(props) {
  3706. return () =>
  3707. h("div", {
  3708. class: props.class + " bottom-div-icon",
  3709. });
  3710. },
  3711. };
  3712. // editor组件icon
  3713. const SsEditorIcon = {
  3714. name: "SsEditorIcon",
  3715. props: {
  3716. class: {
  3717. type: String,
  3718. required: true,
  3719. },
  3720. },
  3721. setup(props) {
  3722. return () =>
  3723. h("i", {
  3724. class: props.class + " editor-icon",
  3725. });
  3726. },
  3727. };
  3728. // ss-validate校验器
  3729. const SsValidate = {
  3730. name: "SsValidate",
  3731. props: {
  3732. errMsg: { type: String },
  3733. textAlign: { type: String, default: "left" },
  3734. style: { type: Object, default: () => ({}) },
  3735. },
  3736. template: `<div class="validate-vline"></div>
  3737. <div class="validate-tip" :style="style">
  3738. <div class="tip" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  3739. <div class="tip-more" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  3740. </div>`,
  3741. };
  3742. // ss-onoff-array 多选按钮 数组形式
  3743. const SsonoffArray = {
  3744. name: "SsonoffArray",
  3745. props: {
  3746. name: {
  3747. type: String,
  3748. required: true,
  3749. },
  3750. opt: {
  3751. type: Array,
  3752. default: () => [],
  3753. },
  3754. defaultValue: [String, Number, Array],
  3755. modelValue: [String, Number, Array],
  3756. multiple: {
  3757. // 新增多选模式属性
  3758. type: Boolean,
  3759. default: false,
  3760. },
  3761. // 是否允许一项都不选,默认true允许 by xu 20251212
  3762. null: {
  3763. type: Boolean,
  3764. default: true,
  3765. },
  3766. },
  3767. emits: ["update:modelValue"], // 允许更新 v-model 绑定的值
  3768. setup(props, { emit }) {
  3769. console.log("多选按钮", props.opt);
  3770. // 使用数组来存储选中值
  3771. const checkedValue = ref(
  3772. props.multiple
  3773. ? Array.isArray(props.defaultValue)
  3774. ? props.defaultValue
  3775. : []
  3776. : props.defaultValue
  3777. );
  3778. const errMsg = ref(props.errTip);
  3779. // 生成icon名字
  3780. const genIconName = (itemValue) => {
  3781. if (props.multiple) {
  3782. return checkedValue.value.includes(itemValue)
  3783. ? "form-icon-onoff-checked"
  3784. : "form-icon-onoff-unchecked";
  3785. }
  3786. return checkedValue.value === itemValue
  3787. ? "form-icon-onoff-checked"
  3788. : "form-icon-onoff-unchecked";
  3789. };
  3790. // 选中项
  3791. const selectItem = (value) => {
  3792. if (props.multiple) {
  3793. // 多选模式
  3794. const index = checkedValue.value.indexOf(value);
  3795. if (index === -1) {
  3796. checkedValue.value = [...checkedValue.value, value];
  3797. } else {
  3798. // 取消选中当前项
  3799. const newValue = checkedValue.value.filter((v) => v !== value);
  3800. // 如果不允许为空且取消后为空,则阻止取消操作 by xu 20251212
  3801. if (!props.null && newValue.length === 0) {
  3802. return; // 阻止取消最后一项
  3803. }
  3804. checkedValue.value = newValue;
  3805. }
  3806. } else {
  3807. // 单选模式
  3808. // 如果点击的是当前已选中的项,判断是否允许取消 by xu 20251212
  3809. if (checkedValue.value === value) {
  3810. if (!props.null) {
  3811. return; // 不允许为空时,阻止取消
  3812. }
  3813. checkedValue.value = ""; // 允许为空时,取消选中
  3814. } else {
  3815. checkedValue.value = value;
  3816. }
  3817. }
  3818. emit("update:modelValue", checkedValue.value);
  3819. nextTick(() => {
  3820. // 触发验证
  3821. if (window.ssVm) {
  3822. window.ssVm.validateField(props.name);
  3823. }
  3824. });
  3825. };
  3826. return { checkedValue, genIconName, selectItem };
  3827. },
  3828. // 使用渲染函数定义模板逻辑
  3829. render() {
  3830. const SsFormIcon = resolveComponent("ss-form-icon");
  3831. return h("div", { class: "radio-container" }, [
  3832. // 根据情况创建 input
  3833. this.multiple
  3834. ? this.checkedValue.length
  3835. ? // 多选且有选中值:为选中项创建 input
  3836. this.checkedValue.map((value) =>
  3837. h("input", {
  3838. type: "checkbox",
  3839. name: this.name,
  3840. value: value,
  3841. checked: true,
  3842. style: { display: "none" },
  3843. })
  3844. )
  3845. : // 多选但没有选中值:创建一个空值 input
  3846. h("input", {
  3847. type: "hidden",
  3848. name: this.name,
  3849. value: "",
  3850. })
  3851. : // 单选模式:创建一个 input
  3852. h("input", {
  3853. type: "hidden",
  3854. name: this.name,
  3855. value: this.checkedValue || "",
  3856. }),
  3857. this.opt.map((item, i) =>
  3858. h(
  3859. "div",
  3860. {
  3861. key: i,
  3862. class: {
  3863. checked: this.multiple
  3864. ? this.checkedValue.includes(item.value)
  3865. : this.checkedValue === item.value,
  3866. },
  3867. style: { width: item.width },
  3868. onClick: () => this.selectItem(item.value),
  3869. },
  3870. [
  3871. h("span", null, item.label),
  3872. h("div", { class: "mark" }, [
  3873. h(SsFormIcon, {
  3874. class: this.genIconName(item.value),
  3875. }),
  3876. ]),
  3877. ]
  3878. )
  3879. ),
  3880. ]);
  3881. },
  3882. };
  3883. // ss-onoff 一个按钮
  3884. const SsOnoff = { // Ssonoff =。Lin
  3885. name: "SsOnoff", // : "Ssonoff",。Lin
  3886. props: {
  3887. name: {
  3888. type: String,
  3889. required: true,
  3890. },
  3891. label: {
  3892. type: String,
  3893. required: true,
  3894. },
  3895. value: {
  3896. type: [String, Number],
  3897. required: true,
  3898. },
  3899. width: {
  3900. type: String,
  3901. default: "",
  3902. },
  3903. onchange: {
  3904. // 在此属性传入 onChange 的 window 全局回调函数,第一参数是当前整组值 by Ben/xu(20260320)
  3905. type: String,
  3906. required: false,
  3907. },
  3908. modelValue: [String, Number, Array],
  3909. multiple: {
  3910. type: Boolean,
  3911. /* 再改,与 <onoff.ss rad= 的默认值("false")保持一致。Lin
  3912. default: false,
  3913. */ default: true,
  3914. },
  3915. null: {
  3916. type: Boolean,
  3917. /* 再改,与 <onoff.ss rad= 的默认值("false")保持一致。Lin
  3918. default: true,
  3919. */ default: false,
  3920. },
  3921. },
  3922. emits: ["update:modelValue", "change"],
  3923. setup(props, { emit }) {
  3924. const parseModelValue = (val) => {
  3925. if (Array.isArray(val)) {
  3926. return val
  3927. .map((item) => (item == null ? "" : item.toString()))
  3928. .filter(Boolean);
  3929. }
  3930. if (val == null || val === "") return [];
  3931. // 如果以逗号开头,去掉开头的逗号
  3932. const cleanValue = val.toString().replace(/^,+/, "");
  3933. if (!cleanValue) return [];
  3934. if (cleanValue.includes("|")) {
  3935. return cleanValue.split("|").filter(Boolean);
  3936. }
  3937. if (cleanValue.includes(",")) {
  3938. return cleanValue.split(",").filter(Boolean);
  3939. }
  3940. return [cleanValue];
  3941. };
  3942. const callGlobalOnchg = (groupValue) => {
  3943. if (props.onchange && typeof props.onchange === "string") {
  3944. if (
  3945. typeof window !== "undefined" &&
  3946. window[props.onchange] &&
  3947. typeof window[props.onchange] === "function"
  3948. ) {
  3949. try {
  3950. window[props.onchange](groupValue, props.value, props.label);
  3951. } catch (error) {
  3952. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  3953. }
  3954. } else {
  3955. console.warn(`全局函数 ${props.onchange} 未定义或不是一个函数。`);
  3956. }
  3957. }
  3958. };
  3959. // 判断当前按钮是否选中
  3960. const isChecked = computed(() => {
  3961. if (props.multiple) {
  3962. const currentValue = parseModelValue(props.modelValue);
  3963. return currentValue.includes(props.value.toString());
  3964. }
  3965. return props.modelValue + "" === props.value + ""; //强转为字符串类型再比较(改之前是数字类型和字符串类型作比较,永远为false) Ben 20251206
  3966. });
  3967. // 功能说明:watch modelValue 变化,兼容桥接 API 赋值触发 onChange by xu 20260416
  3968. let isToggleTriggering = false; // 避免 toggleSelect 内部 emit 重复触发
  3969. Vue.watch(
  3970. () => props.modelValue,
  3971. (newVal) => {
  3972. /* 再改,使 checkbox 也能调用 props.onchang 方法 -- 对 checkbox,没有 toggleSelect(清掉上一个选中)。Lin
  3973. if (isToggleTriggering) return;
  3974. */
  3975. if (isToggleTriggering && !props.multiple)
  3976. return;
  3977. callGlobalOnchg(newVal);
  3978. }
  3979. );
  3980. // 切换选中状态
  3981. const toggleSelect = () => {
  3982. let newModelValue;
  3983. if (props.multiple) {
  3984. const currentValue = parseModelValue(props.modelValue);
  3985. const currentButtonValue = props.value.toString();
  3986. const index = currentValue.indexOf(currentButtonValue);
  3987. let newValue;
  3988. if (index === -1) {
  3989. // 选中当前项
  3990. newValue = [...currentValue, currentButtonValue];
  3991. } else {
  3992. // 取消选中当前项
  3993. const filteredValue = currentValue.filter(
  3994. (value) => value !== currentButtonValue
  3995. );
  3996. // 如果不允许为空且取消后为空,则阻止取消操作
  3997. if (!props.null && filteredValue.length === 0) {
  3998. return; // 阻止取消最后一项
  3999. }
  4000. newValue = filteredValue;
  4001. }
  4002. newModelValue = newValue.join(",");
  4003. } else {
  4004. // 单选模式
  4005. const currentValue = parseModelValue(props.modelValue);
  4006. const isCurrentlySelected = currentValue.includes(
  4007. props.value.toString()
  4008. );
  4009. if (!isCurrentlySelected) {
  4010. // 选中当前项
  4011. newModelValue = props.value;
  4012. } else {
  4013. // 取消选中当前项
  4014. // 如果不允许为空且当前只有这一项被选中,则阻止取消操作
  4015. if (!props.null && currentValue.length === 1) {
  4016. return; // 阻止取消唯一选中项
  4017. }
  4018. newModelValue = "";
  4019. }
  4020. }
  4021. isToggleTriggering = true; // emit 前设置,避免 watch 重复触发 onChange by xu 20260416
  4022. emit("update:modelValue", newModelValue);
  4023. emit("change", newModelValue, props.value, props.label);
  4024. nextTick(() => {
  4025. isToggleTriggering = false; // 重置标志,允许后续桥接 API 赋值触发 onChange by xu 20260416
  4026. // 触发验证
  4027. if (window.ssVm) {
  4028. window.ssVm.validateField(props.name);
  4029. }
  4030. });
  4031. };
  4032. return { isChecked, toggleSelect };
  4033. },
  4034. render() {
  4035. const SsFormIcon = resolveComponent("ss-form-icon");
  4036. return h("div", { class: "radio-container2" }, [
  4037. // 隐藏的表单元素
  4038. this.multiple
  4039. ? h("input", {
  4040. type: "hidden",
  4041. name: `${this.name}`, // 多选模式下使用数组形式的 name
  4042. value: this.isChecked ? this.value : "",
  4043. })
  4044. : this.isChecked &&
  4045. h("input", {
  4046. // 只有当前按钮被选中时才创建 input
  4047. type: "hidden",
  4048. name: this.name,
  4049. value: this.value,
  4050. }),
  4051. // 按钮显示
  4052. h(
  4053. "div",
  4054. {
  4055. class: { checked: this.isChecked },
  4056. style: { width: this.width },
  4057. onClick: this.toggleSelect,
  4058. },
  4059. [
  4060. h("span", null, this.label),
  4061. h("div", { class: "mark" }, [
  4062. h(SsFormIcon, {
  4063. class: this.isChecked
  4064. ? "form-icon-onoff-checked"
  4065. : "form-icon-onoff-unchecked",
  4066. }),
  4067. ]),
  4068. ]
  4069. ),
  4070. ]);
  4071. },
  4072. };
  4073. // ss-textarea
  4074. // ss-textarea
  4075. const SsTextarea = {
  4076. name: "SsTextarea",
  4077. props: {
  4078. name: {
  4079. type: String,
  4080. required: true,
  4081. },
  4082. placeholder: {
  4083. type: String,
  4084. default: "", // : "请输入",。再改,去掉 placeholder 默认值 "请输入" 。Lin
  4085. },
  4086. defaultValue: [String, Number],
  4087. modelValue: [String, Number],
  4088. // 功能说明:onChange 全局回调 prop,桥接 API 赋值时自动触发 by xu 20260416
  4089. onchange: {
  4090. type: String,
  4091. required: false,
  4092. },
  4093. },
  4094. emits: ["update:modelValue"],
  4095. setup(props, { emit }) {
  4096. const inputValue = ref(props.modelValue || props.defaultValue || "");
  4097. // 功能说明:调用全局 onChange 回调 by xu 20260416
  4098. const callGlobalOnchg = (value) => {
  4099. if (props.onchange && typeof props.onchange === "string") {
  4100. if (
  4101. typeof window !== "undefined" &&
  4102. window[props.onchange] &&
  4103. typeof window[props.onchange] === "function"
  4104. ) {
  4105. try {
  4106. window[props.onchange](value);
  4107. } catch (error) {
  4108. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  4109. }
  4110. }
  4111. }
  4112. };
  4113. // 监听 modelValue 变化
  4114. watch(
  4115. () => props.modelValue,
  4116. (newVal) => {
  4117. inputValue.value = newVal;
  4118. callGlobalOnchg(newVal);
  4119. }
  4120. );
  4121. // 输入事件处理
  4122. const onInput = (event) => {
  4123. const newValue = event.target.value;
  4124. inputValue.value = newValue;
  4125. emit("update:modelValue", newValue);
  4126. // 触发验证
  4127. if (window.ssVm) {
  4128. window.ssVm.validateField(props.name);
  4129. }
  4130. };
  4131. // 失焦时验证
  4132. const onBlur = () => {
  4133. if (window.ssVm) {
  4134. window.ssVm.validateField(props.name);
  4135. }
  4136. };
  4137. return { inputValue, onInput, onBlur };
  4138. },
  4139. render() {
  4140. return h("div", { class: "textarea-container" }, [
  4141. h("div", { class: "textarea" }, [
  4142. h("input", {
  4143. type: "hidden",
  4144. name: this.name,
  4145. value: this.inputValue || "",
  4146. }),
  4147. h("textarea", {
  4148. placeholder: this.placeholder,
  4149. value: this.inputValue,
  4150. onInput: this.onInput,
  4151. onBlur: this.onBlur,
  4152. }),
  4153. ]),
  4154. ]);
  4155. },
  4156. };
  4157. // ss-editor 富文本编辑器 基于Jodit
  4158. const SsEditor = {
  4159. name: "SsEditor",
  4160. props: {
  4161. modelValue: {
  4162. type: String,
  4163. default: "",
  4164. },
  4165. html: {
  4166. type: String,
  4167. default: "",
  4168. },
  4169. name: {
  4170. type: String,
  4171. default: "",
  4172. },
  4173. url: {
  4174. type: String,
  4175. default: "",
  4176. },
  4177. height: {
  4178. type: [Number, String],
  4179. default: 400,
  4180. },
  4181. placeholder: {
  4182. type: String,
  4183. default: "", // : "请输入内容",。再改,去掉 placeholder 默认值 "请输入内容" 。Lin
  4184. },
  4185. mode: {
  4186. type: String,
  4187. default: "edit", // 'edit' | 'play'
  4188. },
  4189. uploadUrl: {
  4190. type: String,
  4191. default: "/ulByHttp", //原值为“upload” Ben(20251205)
  4192. },
  4193. param: {
  4194. type: Object,
  4195. default: () => ({}),
  4196. },
  4197. },
  4198. emits: ["update:modelValue", "ready", "change"],
  4199. setup(props, { emit }) {
  4200. const editorRef = ref(null);
  4201. const editorContent = ref("");
  4202. const currentModelValue = ref(props.modelValue || "");
  4203. const uniqueId = "editor-" + Date.now();
  4204. const errMsg = Vue.ref("");
  4205. // button 支持对象(旧格式,单个附件按钮)或数组(新格式,多个按钮)by xu 20250331
  4206. const buttonConfigRaw = props.param && props.param.button ? props.param.button : null;
  4207. const buttonArray = Array.isArray(buttonConfigRaw)
  4208. ? buttonConfigRaw
  4209. : buttonConfigRaw
  4210. ? [buttonConfigRaw]
  4211. : [];
  4212. // 找到附件按钮配置(有 cmsAddUrl 的)
  4213. const fjButton = buttonArray.find(btn => btn.cmsAddUrl && btn.cmsUpdUrl) || {};
  4214. const fjid = ref(fjButton.val || null);
  4215. const fjName = fjButton.desc || "附件";
  4216. // 筛选出自定义按钮(有 func 的)
  4217. const customButtonsFromParam = buttonArray.filter(btn => btn.func).map(btn => ({
  4218. name: btn.name,
  4219. text: btn.desc || btn.text,
  4220. tooltip: btn.desc || btn.tooltip,
  4221. icon: btn.icon || 'editor-icon-file',
  4222. onClick: btn.func // 函数名字符串
  4223. }));
  4224. const mode = props.param ? props.param.mode : null;
  4225. const normalizeHtml = (rawHtml) => {
  4226. if (rawHtml == null) {
  4227. return "";
  4228. }
  4229. const html = String(rawHtml).trim();
  4230. if (!html) {
  4231. return "";
  4232. }
  4233. if (
  4234. /<html[\s>]/i.test(html) ||
  4235. /<body[\s>]/i.test(html) ||
  4236. /<!doctype/i.test(html)
  4237. ) {
  4238. try {
  4239. const doc = new DOMParser().parseFromString(html, "text/html");
  4240. if (doc && doc.body) {
  4241. return doc.body.innerHTML || "";
  4242. }
  4243. } catch (e) {
  4244. console.warn("ss-editor 解析完整HTML失败,回退原始内容:", e);
  4245. }
  4246. }
  4247. return html;
  4248. };
  4249. const syncHiddenContentInput = (html) => {
  4250. const contentElements = document.getElementsByName(
  4251. props.name.replace(/wj$/, "") + "Edit"
  4252. );
  4253. if (contentElements.length > 0) {
  4254. contentElements[0].value = html;
  4255. }
  4256. };
  4257. const setEditorHtml = (html) => {
  4258. const normalizedHtml = normalizeHtml(html);
  4259. editorContent.value = normalizedHtml;
  4260. syncHiddenContentInput(normalizedHtml);
  4261. if (editorRef.value && editorRef.value.value !== normalizedHtml) {
  4262. editorRef.value.value = normalizedHtml;
  4263. }
  4264. };
  4265. const resolveWindowFunction = (handlerName) => {
  4266. if (!handlerName || typeof handlerName !== "string") {
  4267. return null;
  4268. }
  4269. return handlerName.split(".").reduce((current, key) => {
  4270. return current && current[key] != null ? current[key] : null;
  4271. }, window);
  4272. };
  4273. const getCustomButtonKey = (button, index) => {
  4274. const baseName =
  4275. (button &&
  4276. (button.key || button.name || button.text || button.tooltip)) ||
  4277. `button${index + 1}`;
  4278. return `ssCustomButton_${String(baseName).replace(
  4279. /[^a-zA-Z0-9_-]/g,
  4280. "_"
  4281. )}_${index}`;
  4282. };
  4283. const normalizeCustomButtons = (buttons = []) => {
  4284. return Array.isArray(buttons)
  4285. ? buttons.filter(Boolean).map((button, index) => ({
  4286. ...button,
  4287. _buttonKey: getCustomButtonKey(button, index),
  4288. }))
  4289. : [];
  4290. };
  4291. const renderButtonIcon = (icon) => {
  4292. if (!icon) {
  4293. return null;
  4294. }
  4295. if (typeof icon === "string" && icon.trim().startsWith("<")) {
  4296. return icon;
  4297. }
  4298. return `<span class="editor-icon ${icon}"></span>`;
  4299. };
  4300. const buildCustomButtonRegistry = (buttons = []) => {
  4301. const controls = {};
  4302. const buttonNames = [];
  4303. const iconMap = {};
  4304. normalizeCustomButtons(buttons).forEach((button) => {
  4305. const buttonKey = button._buttonKey;
  4306. const handler =
  4307. button.onClick ||
  4308. button.click ||
  4309. button.handler ||
  4310. button.exec ||
  4311. null;
  4312. const tooltip =
  4313. button.tooltip ||
  4314. button.text ||
  4315. button.label ||
  4316. button.name ||
  4317. "自定义按钮";
  4318. buttonNames.push(buttonKey);
  4319. if (button.icon) {
  4320. iconMap[buttonKey] = button.icon;
  4321. }
  4322. controls[buttonKey] = {
  4323. name: button.name || buttonKey,
  4324. tooltip,
  4325. exec: function (editor) {
  4326. const context = {
  4327. editor,
  4328. button,
  4329. props,
  4330. value:
  4331. editor && typeof editor.value !== "undefined"
  4332. ? editor.value
  4333. : "",
  4334. setValue: (value) => setEditorHtml(value),
  4335. getValue: () =>
  4336. editor && typeof editor.value !== "undefined"
  4337. ? editor.value
  4338. : "",
  4339. emit,
  4340. currentModelValue: currentModelValue.value,
  4341. fjid: fjid.value,
  4342. };
  4343. if (typeof handler === "function") {
  4344. return handler(context);
  4345. }
  4346. if (typeof handler === "string") {
  4347. const windowHandler = resolveWindowFunction(handler);
  4348. if (typeof windowHandler === "function") {
  4349. return windowHandler(context);
  4350. }
  4351. console.warn("ss-editor 自定义按钮未找到点击事件:", handler);
  4352. return undefined;
  4353. }
  4354. console.warn("ss-editor 自定义按钮缺少点击事件配置:", button);
  4355. return undefined;
  4356. },
  4357. };
  4358. });
  4359. return {
  4360. controls,
  4361. buttonNames,
  4362. iconMap,
  4363. };
  4364. };
  4365. const validate = () => {
  4366. if (window.ssVm) {
  4367. const result = window.ssVm.validateField(props.name);
  4368. console.log("validate", window.ssVm.validateField(props.name));
  4369. errMsg.value = result.valid ? "" : result.message;
  4370. }
  4371. };
  4372. onMounted(() => {
  4373. validate();
  4374. // 只读模式下不初始化 Jodit,直接设置内容 by xu 20250402
  4375. if (props.mode === "play") {
  4376. if (props.html) {
  4377. setEditorHtml(props.html);
  4378. } else if (props.url) {
  4379. const params = new URLSearchParams();
  4380. if (mode) params.append("mode", mode);
  4381. if (props.modelValue) params.append("path", props.modelValue);
  4382. axios
  4383. .post(props.url, params, {
  4384. headers: {
  4385. "Content-Type": "application/x-www-form-urlencoded",
  4386. },
  4387. })
  4388. .then((response) => {
  4389. if ("timeout" == response.data.statusText) {
  4390. alert("网络超时!");
  4391. return;
  4392. }
  4393. const content = response.data.content;
  4394. if (content != null) {
  4395. setEditorHtml(content);
  4396. }
  4397. const filePath = response.data.path;
  4398. if (filePath) {
  4399. currentModelValue.value = filePath;
  4400. emit("update:modelValue", filePath);
  4401. }
  4402. });
  4403. } else {
  4404. setEditorHtml(props.html);
  4405. }
  4406. return;
  4407. }
  4408. // 读取按钮配置 by xu 20250408(移除废弃的 props.customButtons)
  4409. let buttonsToUse = [];
  4410. // 1. 优先从 param.button 数组中筛选(新格式)by xu 20250331
  4411. if (customButtonsFromParam && customButtonsFromParam.length > 0) {
  4412. buttonsToUse = customButtonsFromParam;
  4413. }
  4414. // 2. 尝试从 param.customButtons 读取(旧格式,兼容)
  4415. if (!buttonsToUse || buttonsToUse.length === 0) {
  4416. if (props.param && props.param.customButtons && props.param.customButtons.length > 0) {
  4417. buttonsToUse = props.param.customButtons;
  4418. }
  4419. }
  4420. // 3. 尝试通过桥接 API 读取
  4421. if (!buttonsToUse || buttonsToUse.length === 0) {
  4422. const vm = window.SS.dom.getVueApp({ scope: "chain" });
  4423. if (vm && vm.zwwjCustomButtons) {
  4424. buttonsToUse = vm.zwwjCustomButtons;
  4425. }
  4426. }
  4427. // 4. 从 formElemConfig 读取(兜底)
  4428. if (!buttonsToUse || buttonsToUse.length === 0) {
  4429. const zwwjConfig = window.SS.dom.formElemConfig?.zwwj;
  4430. if (zwwjConfig?.customButtons) {
  4431. buttonsToUse = zwwjConfig.customButtons;
  4432. } else {
  4433. buttonsToUse = window.SS.dom.formElemConfig?.zwwjCustomButtons;
  4434. }
  4435. }
  4436. const {
  4437. controls: customButtonControls,
  4438. buttonNames: customButtonNames,
  4439. iconMap: customButtonIconMap,
  4440. } = buildCustomButtonRegistry(buttonsToUse);
  4441. console.log(
  4442. "[SsEditor] 解析后的按钮:",
  4443. customButtonNames,
  4444. customButtonControls
  4445. );
  4446. const appendCustomButtons = (buttons = []) => {
  4447. if (!customButtonNames.length) {
  4448. return buttons;
  4449. }
  4450. const toolbarButtons = [...buttons];
  4451. const insertIndex = toolbarButtons.includes("dots")
  4452. ? toolbarButtons.indexOf("dots")
  4453. : toolbarButtons.includes("print")
  4454. ? toolbarButtons.indexOf("print")
  4455. : -1;
  4456. if (insertIndex >= 0) {
  4457. toolbarButtons.splice(insertIndex, 0, ...customButtonNames);
  4458. return toolbarButtons;
  4459. }
  4460. return [...toolbarButtons, ...customButtonNames];
  4461. };
  4462. const editor = Jodit.make(`#${uniqueId}`, {
  4463. // showTooltip: true, // 增加,增加显示工具条图标的 tips -- 不用增加,会显示 -- 但 buttonsXS 时,置了也不显示。Lin
  4464. minHeight: 120, // 再增加,不指定时为 200px。Lin
  4465. height: props.height,
  4466. placeholder: props.placeholder,
  4467. readonly: props.mode === "play",
  4468. language: "zh_cn",
  4469. i18n: {
  4470. zh_cn: {
  4471. Link: "链接",
  4472. URL: "链接",
  4473. "No follow": "无跟踪",
  4474. "Class name": "类名",
  4475. Image: "图片",
  4476. File: "文件",
  4477. "Line height": "行高",
  4478. Alternative: "描述",
  4479. "Alternative text": "描述",
  4480. "Lower Alpha": "小写字母",
  4481. "Upper Alpha": "大写字母",
  4482. "Upper Roman": "大写罗马数字",
  4483. "Lower Roman": "小写罗马数字",
  4484. "Lower Greek": "小写希腊字母",
  4485. "Lower Letter": "小写字母",
  4486. "Upper Letter": "大写字母",
  4487. },
  4488. },
  4489. showXPathInStatusbar: false,
  4490. showCharsCounter: false,
  4491. showWordsCounter: false,
  4492. allowResizeY: false,
  4493. toolbarSticky: false,
  4494. statusbar: false,
  4495. uploader: {
  4496. url: props.uploadUrl,
  4497. format: "json",
  4498. method: "POST",
  4499. filesVariableName: function (i) {
  4500. return "imgs[" + i + "]";
  4501. },
  4502. headers: {
  4503. Accept: "application/json",
  4504. },
  4505. prepareData: function (formData) {
  4506. return formData;
  4507. },
  4508. isSuccess: function (resp) {
  4509. console.log("isSuccess resp:", resp);
  4510. return resp.code === 0;
  4511. },
  4512. getMessage: function (resp) {
  4513. console.log("getMessage resp:", resp);
  4514. return resp.msg || "上传失败";
  4515. },
  4516. process: function (resp) {
  4517. console.log("process resp:", resp);
  4518. return resp.data.url;
  4519. },
  4520. error: function (e) {
  4521. console.error("上传失败:", e.message);
  4522. },
  4523. defaultHandlerSuccess: function (resp) {
  4524. console.log("上传成功:", resp);
  4525. },
  4526. defaultHandlerError: function (err) {
  4527. console.error("上传错误:", err);
  4528. },
  4529. contentType: function () {
  4530. return false;
  4531. },
  4532. },
  4533. controls: {
  4534. font: {
  4535. list: {
  4536. SimSun: "宋体",
  4537. SimHei: "黑体",
  4538. "Microsoft YaHei": "微软雅黑",
  4539. KaiTi: "楷体",
  4540. FangSong: "仿宋",
  4541. Arial: "Arial",
  4542. "Times New Roman": "Times New Roman",
  4543. "Courier New": "Courier New",
  4544. },
  4545. },
  4546. customLinkButton: {
  4547. name: "link",
  4548. tooltip: "附件",
  4549. exec: function () {
  4550. if (!fjButton.cmsAddUrl || !fjButton.cmsUpdUrl) {
  4551. console.warn("ss-editor 未配置附件按钮地址,忽略附件操作");
  4552. return;
  4553. }
  4554. if (fjid.value == null || fjid.value === "") {
  4555. $.ajax({
  4556. type: "post",
  4557. url: fjButton.cmsAddUrl,
  4558. async: false,
  4559. data: {
  4560. name: "fjid",
  4561. ssNrObjName: "sh",
  4562. ssNrObjId: "",
  4563. },
  4564. success: function (_fjid) {
  4565. console.log("cmsAddUrl success", _fjid);
  4566. fjid.value = _fjid;
  4567. },
  4568. });
  4569. }
  4570. var str =
  4571. "&nrid=T-" +
  4572. fjid.value +
  4573. "&objectId=" +
  4574. fjid.value +
  4575. "&objectName=" +
  4576. fjName +
  4577. "&callback=" +
  4578. (window["fjidCallbackName"] || "");
  4579. console.log("str", str);
  4580. SS.openDialog({
  4581. /* 再改,改为 fjButton.,应该是没改彻底 -- 修正 附件 按钮。Lin
  4582. src: buttonConfig.cmsUpdUrl + str,
  4583. */ src: fjButton.cmsUpdUrl + str,
  4584. headerTitle: "编辑",
  4585. width: 900,
  4586. high: 664,
  4587. zIndex: 51,
  4588. });
  4589. },
  4590. },
  4591. ...customButtonControls,
  4592. },
  4593. toolbarAdaptive: true,
  4594. // 调试:记录最终按钮配置
  4595. buttons: (() => {
  4596. const finalButtons = appendCustomButtons([
  4597. "fullsize",
  4598. "bold",
  4599. "italic",
  4600. "underline",
  4601. "strikethrough",
  4602. "eraser",
  4603. "|",
  4604. "font",
  4605. "fontsize",
  4606. "brush",
  4607. "paragraph",
  4608. "|",
  4609. "left",
  4610. "center",
  4611. "right",
  4612. "justify",
  4613. "|",
  4614. "ul",
  4615. "ol",
  4616. "indent",
  4617. "outdent",
  4618. "|",
  4619. "image",
  4620. "table",
  4621. /* 去掉,用自定义的 cms 附件按钮。Lin
  4622. "customLinkButton",
  4623. */
  4624. "print",
  4625. "|",
  4626. "undo",
  4627. "redo",
  4628. "find",
  4629. ]);
  4630. console.log("[SsEditor] 最终 buttons 配置:", finalButtons);
  4631. return finalButtons;
  4632. })(),
  4633. buttonsMD: appendCustomButtons([
  4634. "fullsize",
  4635. "bold",
  4636. "italic",
  4637. "underline",
  4638. "strikethrough",
  4639. "eraser",
  4640. "|",
  4641. "font",
  4642. "fontsize",
  4643. "brush",
  4644. "paragraph",
  4645. "|",
  4646. /* 去掉,重复了。Lin
  4647. "font",
  4648. "fontsize",
  4649. "|",
  4650. */
  4651. "left",
  4652. "center",
  4653. "right",
  4654. "justify",
  4655. "|",
  4656. "image",
  4657. "table", // 增加,增加 表格 按钮。Lin
  4658. /* 去掉,用自定义的 cms 附件按钮。Lin
  4659. "customLinkButton",
  4660. */
  4661. "|",
  4662. "dots",
  4663. ]),
  4664. buttonsSM: appendCustomButtons([
  4665. "fullsize",
  4666. "bold",
  4667. "italic",
  4668. "underline",
  4669. "|",
  4670. "font",
  4671. "fontsize",
  4672. "|",
  4673. "left",
  4674. "center",
  4675. "|",
  4676. "image",
  4677. "table", // 增加,增加 表格 按钮。Lin
  4678. /* 去掉,用自定义的 cms 附件按钮。Lin
  4679. "customLinkButton",
  4680. */
  4681. "|",
  4682. "dots",
  4683. ]),
  4684. buttonsXS: appendCustomButtons([
  4685. "fullsize",
  4686. "bold",
  4687. "underline",
  4688. "|",
  4689. "font",
  4690. "fontsize",
  4691. "|",
  4692. "left",
  4693. "center",
  4694. "|",
  4695. "dots"
  4696. ]),
  4697. sizeLG: 1024,
  4698. sizeMD: 768,
  4699. sizeSM: 576,
  4700. getIcon: function (name, clearName) {
  4701. const iconMap = {
  4702. bold: "editor-icon-bold",
  4703. italic: "editor-icon-italic",
  4704. underline: "editor-icon-underline",
  4705. strikethrough: "editor-icon-strikethrough",
  4706. eraser: "editor-icon-eraser",
  4707. copyformat: "editor-icon-copyformat",
  4708. font: "editor-icon-font",
  4709. fontsize: "editor-icon-fontsize",
  4710. brush: "editor-icon-brush",
  4711. paragraph: "editor-icon-paragraph",
  4712. left: "editor-icon-align-left",
  4713. center: "editor-icon-align-center",
  4714. right: "editor-icon-align-right",
  4715. justify: "editor-icon-align-justify",
  4716. ul: "editor-icon-ul",
  4717. ol: "editor-icon-ol",
  4718. indent: "editor-icon-indent",
  4719. outdent: "editor-icon-outdent",
  4720. image: "editor-icon-image",
  4721. file: "editor-icon-file",
  4722. video: "editor-icon-video",
  4723. table: "editor-icon-table",
  4724. link: "editor-icon-link",
  4725. source: "editor-icon-source",
  4726. eye: "editor-icon-preview",
  4727. fullsize: "editor-icon-fullsize",
  4728. shrink: "editor-icon-fullsize-exit",
  4729. print: "editor-icon-print",
  4730. undo: "editor-icon-undo",
  4731. redo: "editor-icon-redo",
  4732. search: "editor-icon-find",
  4733. selectall: "editor-icon-selectall",
  4734. };
  4735. const customIcon =
  4736. customButtonIconMap[clearName] || customButtonIconMap[name];
  4737. if (customIcon) {
  4738. return renderButtonIcon(customIcon);
  4739. }
  4740. const iconClass = iconMap[clearName] || iconMap[name];
  4741. if (iconClass) {
  4742. return renderButtonIcon(iconClass);
  4743. }
  4744. return null;
  4745. },
  4746. });
  4747. editorRef.value = editor;
  4748. editor.events.on("change", () => {
  4749. const html = editor.value || "";
  4750. editorContent.value = html;
  4751. syncHiddenContentInput(html);
  4752. emit("change", html);
  4753. setTimeout(() => {
  4754. validate();
  4755. }, 50);
  4756. });
  4757. emit("ready", editor);
  4758. if (props.html) {
  4759. setEditorHtml(props.html);
  4760. } else if (props.url) {
  4761. const params = new URLSearchParams();
  4762. if (mode) params.append("mode", mode);
  4763. if (props.modelValue) params.append("path", props.modelValue);
  4764. axios
  4765. .post(props.url, params, {
  4766. headers: {
  4767. "Content-Type": "application/x-www-form-urlencoded",
  4768. },
  4769. })
  4770. .then((response) => {
  4771. if ("timeout" == response.data.statusText) {
  4772. alert("网络超时!");
  4773. return;
  4774. }
  4775. const content = response.data.content;
  4776. if (content != null) {
  4777. setEditorHtml(content);
  4778. }
  4779. const filePath = response.data.path;
  4780. if (filePath) {
  4781. currentModelValue.value = filePath;
  4782. emit("update:modelValue", filePath);
  4783. }
  4784. });
  4785. } else {
  4786. setEditorHtml(props.html);
  4787. }
  4788. });
  4789. watch(
  4790. () => props.html,
  4791. (newValue) => {
  4792. setEditorHtml(newValue);
  4793. }
  4794. );
  4795. watch(
  4796. () => props.modelValue,
  4797. (newValue) => {
  4798. currentModelValue.value = newValue || "";
  4799. }
  4800. );
  4801. watch(
  4802. () => props.mode,
  4803. (newMode) => {
  4804. if (editorRef.value) {
  4805. editorRef.value.setReadOnly(newMode === "play");
  4806. }
  4807. }
  4808. );
  4809. onBeforeUnmount(() => {
  4810. if (editorRef.value) {
  4811. editorRef.value.destruct();
  4812. }
  4813. });
  4814. // 只读模式:打开附件弹窗 by xu 20250402
  4815. const openAttachmentDialog = () => {
  4816. if (!fjButton.cmsAddUrl || !fjButton.cmsUpdUrl) {
  4817. console.warn("ss-editor 未配置附件按钮地址,忽略附件操作");
  4818. return;
  4819. }
  4820. if (fjid.value == null || fjid.value === "") {
  4821. $.ajax({
  4822. type: "post",
  4823. url: fjButton.cmsAddUrl,
  4824. async: false,
  4825. data: {
  4826. name: "fjid",
  4827. ssNrObjName: "sh",
  4828. ssNrObjId: "",
  4829. },
  4830. success: function (_fjid) {
  4831. console.log("cmsAddUrl success", _fjid);
  4832. fjid.value = _fjid;
  4833. },
  4834. });
  4835. }
  4836. var str =
  4837. "&nrid=T-" +
  4838. fjid.value +
  4839. "&objectId=" +
  4840. fjid.value +
  4841. "&objectName=" +
  4842. fjName +
  4843. "&callback=" +
  4844. (window["fjidCallbackName"] || "");
  4845. console.log("str", str);
  4846. SS.openDialog({
  4847. src: fjButton.cmsUpdUrl + str,
  4848. headerTitle: "编辑",
  4849. width: 900,
  4850. high: 664,
  4851. zIndex: 51,
  4852. });
  4853. };
  4854. return () => {
  4855. // 只读模式:不初始化 Jodit,直接渲染 HTML + 附件按钮 by xu 20250402
  4856. if (props.mode === "play") {
  4857. return h("div", { class: "ss-editor-container ss-editor-readonly" }, [
  4858. fjid.value &&
  4859. h("input", {
  4860. type: "hidden",
  4861. name: "fjid",
  4862. value: fjid.value,
  4863. }),
  4864. h("input", {
  4865. type: "hidden",
  4866. name: props.name.replace(/wj$/, "") + "Edit",
  4867. value: editorContent.value,
  4868. }),
  4869. h("input", {
  4870. type: "hidden",
  4871. name: props.name.replace(/wj$/, "") + "wj",
  4872. value: currentModelValue.value,
  4873. }),
  4874. h("input", {
  4875. type: "hidden",
  4876. name: "ueditorpath",
  4877. value: "mswj",
  4878. }),
  4879. // 附件按钮(只读模式下仍显示)
  4880. fjButton.cmsAddUrl && fjButton.cmsUpdUrl &&
  4881. h("div", {
  4882. class: "ss-editor-attach-btn",
  4883. onClick: openAttachmentDialog,
  4884. }, [
  4885. h("span", { class: "editor-icon editor-icon-link" }),
  4886. h("span", { class: "ss-editor-attach-text" }, "附件")
  4887. ]),
  4888. // HTML 内容展示
  4889. h("div", {
  4890. class: "ss-editor-readonly-content",
  4891. innerHTML: editorContent.value,
  4892. }),
  4893. ]);
  4894. }
  4895. // 正常编辑模式:渲染 textarea 供 Jodit 初始化
  4896. return h("div", { class: "ss-editor-container" }, [
  4897. fjid.value &&
  4898. h("input", {
  4899. type: "hidden",
  4900. name: "fjid",
  4901. value: fjid.value,
  4902. }),
  4903. h("input", {
  4904. type: "hidden",
  4905. name: props.name.replace(/wj$/, "") + "Edit",
  4906. value: editorContent.value,
  4907. }),
  4908. h("input", {
  4909. type: "hidden",
  4910. name: props.name.replace(/wj$/, "") + "wj",
  4911. value: currentModelValue.value,
  4912. }),
  4913. h("input", {
  4914. type: "hidden",
  4915. name: "ueditorpath",
  4916. value: props.name.replace(/wj$/, "") + "wj",
  4917. }),
  4918. /// 再增加,把 附件 按钮独立到 jodit 外。Lin
  4919. // 抄自上面的 SsEditor 只读模式部分
  4920. // 附件按钮(只读模式下仍显示)
  4921. fjButton.cmsAddUrl && fjButton.cmsUpdUrl &&
  4922. h("div", {
  4923. class: "ss-editor-attach-btn",
  4924. onClick: openAttachmentDialog,
  4925. }, [
  4926. h("span", { class: "editor-icon editor-icon-link" }),
  4927. h("span", { class: "ss-editor-attach-text" }, "附件")
  4928. ]),
  4929. ///
  4930. h("textarea", { id: uniqueId }),
  4931. ]);
  4932. };
  4933. },
  4934. };
  4935. // 弹窗右边图标
  4936. const SsFullStyleHeader = {
  4937. name: "SsFullStyleHeader",
  4938. props: {
  4939. title: {
  4940. type: String,
  4941. default: "标题",
  4942. },
  4943. },
  4944. emits: ["close"],
  4945. setup(props, { emit }) {
  4946. // console.log(props.title)
  4947. const onClose = () => {
  4948. emit("close");
  4949. };
  4950. const SsIcon = resolveComponent("ss-icon");
  4951. return () =>
  4952. h("div", { class: "header-container" }, [
  4953. h("div", { class: "title" }, props.title),
  4954. h("div", { class: "handle-bar" }, [
  4955. h("div", { class: "left-bar" }, [
  4956. h(SsDialogIcon, { class: "dialog-icon-download" }),
  4957. h(SsDialogIcon, { class: "dialog-icon-print" }),
  4958. h(SsDialogIcon, { class: "dialog-icon-setting" }),
  4959. h(SsDialogIcon, { class: "dialog-icon-collect" }),
  4960. h(SsDialogIcon, { class: "dialog-icon-help" }),
  4961. h(SsDialogIcon, { class: "dialog-icon-full-screen" }),
  4962. h(SsDialogIcon, { class: "dialog-icon-lock" }),
  4963. ]),
  4964. h("div", { class: "close-bar", onClick: onClose }, [
  4965. h(SsDialogIcon, { class: "dialog-icon-close" }),
  4966. ]),
  4967. ]),
  4968. ]);
  4969. },
  4970. };
  4971. // ss-dialog弹窗
  4972. const SsDialog = {
  4973. name: "SsDialog",
  4974. props: {
  4975. src: {
  4976. type: String,
  4977. },
  4978. headerTitle: {
  4979. type: String,
  4980. // required: true,
  4981. default: "弹窗",
  4982. },
  4983. width: {
  4984. type: String,
  4985. default: "1400",
  4986. },
  4987. height: {
  4988. type: String,
  4989. default: "600",
  4990. },
  4991. params: {
  4992. type: Object,
  4993. default: () => ({}),
  4994. },
  4995. zIndex: {
  4996. type: Number,
  4997. default: 1000,
  4998. },
  4999. },
  5000. emits: ["close"],
  5001. setup(props, { slots, emit }) {
  5002. // 关闭窗口方法
  5003. const onClose = () => {
  5004. emit("close");
  5005. };
  5006. const showHeader = ref(true);
  5007. const headerVisible = ref(false);
  5008. const popupHieght = ref(props.height);
  5009. // 状态:存储位置信息
  5010. const position = reactive({
  5011. // 页面居中
  5012. x: (window.innerWidth - props.width) / 2,
  5013. y: (window.innerHeight - popupHieght.value) / 2,
  5014. isDragging: false,
  5015. offsetX: 0,
  5016. offsetY: 0,
  5017. });
  5018. // 鼠标按下时设置起始坐标并开始拖拽
  5019. const startDrag = (event) => {
  5020. position.isDragging = true;
  5021. position.offsetX = event.clientX - position.x;
  5022. position.offsetY = event.clientY - position.y;
  5023. };
  5024. // 鼠标移动时更新位置
  5025. const onDrag = (event) => {
  5026. if (position.isDragging) {
  5027. position.x = event.clientX - position.offsetX;
  5028. position.y = event.clientY - position.offsetY;
  5029. }
  5030. };
  5031. // 鼠标放开时结束拖拽
  5032. const endDrag = () => {
  5033. position.isDragging = false;
  5034. };
  5035. // 监听来自 iframe 的消息
  5036. const handleMessage = (event) => {
  5037. // 顶天立地
  5038. if (event.data && typeof event.data.hasScrollBar !== "undefined") {
  5039. if (event.data.hasScrollBar) {
  5040. // console.log(event);
  5041. position.y = 10;
  5042. showHeader.value = false;
  5043. headerVisible.value = true;
  5044. popupHieght.value = window.innerHeight - 20;
  5045. // console.log(popupHieght.value);
  5046. document.querySelector(".body").style.height = "100%";
  5047. document.querySelector(".body").style.paddingTop = "30px";
  5048. document.querySelector(".header-container ").style.position =
  5049. "absolute";
  5050. document.querySelector(".header-container ").style.zIndex = "10";
  5051. }
  5052. }
  5053. };
  5054. // 鼠标移入关闭按钮区域时显示头部
  5055. const onMouseEnterCloseButton = () => {
  5056. headerVisible.value = false;
  5057. };
  5058. // 鼠标移出关闭按钮区域时隐藏头部
  5059. const onMouseLeaveCloseButton = () => {
  5060. headerVisible.value = true;
  5061. };
  5062. // 在组件挂载时添加全局事件监听器
  5063. Vue.onMounted(() => {
  5064. // 如果传过来的高度大于窗口高度,则设置为窗口高度减去20 否则保持传过来的高度
  5065. popupHieght.value =
  5066. popupHieght.value > window.innerHeight
  5067. ? window.innerHeight - 20
  5068. : popupHieght.value;
  5069. const container = document.querySelector(".header-container");
  5070. if (container) {
  5071. container.addEventListener("mousedown", startDrag);
  5072. }
  5073. document.addEventListener("mousemove", onDrag);
  5074. document.addEventListener("mouseup", endDrag);
  5075. window.addEventListener("message", handleMessage);
  5076. });
  5077. // 在组件卸载时移除全局事件监听器
  5078. Vue.onUnmounted(() => {
  5079. document.removeEventListener("mousemove", onDrag);
  5080. document.removeEventListener("mouseup", endDrag);
  5081. window.removeEventListener("message", handleMessage);
  5082. });
  5083. const SsMark = resolveComponent("ss-mark");
  5084. const SsFullStyleHeader = resolveComponent("ss-full-style-header");
  5085. // render函数定义组件结构
  5086. return () =>
  5087. h(
  5088. Teleport,
  5089. { to: "body" }, // 使用 Teleport 将弹窗内容挂载到 body
  5090. h(SsMark, {}, [
  5091. h(
  5092. "div",
  5093. {
  5094. class: "popup-container",
  5095. style: {
  5096. position: "absolute",
  5097. left: `${position.x}px`,
  5098. top: `${position.y}px`,
  5099. width: props.width + "px",
  5100. height: popupHieght.value + "px",
  5101. zIndex: props.zIndex, // 确保弹窗在最上层
  5102. },
  5103. },
  5104. [
  5105. h(SsFullStyleHeader, {
  5106. class: "header",
  5107. title: props.headerTitle,
  5108. onClose: onClose,
  5109. onMousedown: startDrag, // 绑定拖动事件
  5110. onMouseUp: endDrag,
  5111. ...(!showHeader.value && {
  5112. onMouseenter: onMouseEnterCloseButton,
  5113. onMouseleave: onMouseLeaveCloseButton,
  5114. }),
  5115. style: {
  5116. cursor: position.isDragging ? "grabbing" : "grab",
  5117. visibility: headerVisible.value ? "hidden" : "visible",
  5118. },
  5119. }),
  5120. h(
  5121. "div",
  5122. {
  5123. class: "body",
  5124. style: {},
  5125. },
  5126. [
  5127. h("iframe", {
  5128. src: props.src,
  5129. frameborder: 0,
  5130. style: { width: "100%", height: "100%" },
  5131. }),
  5132. ]
  5133. ),
  5134. headerVisible.value &&
  5135. h("div", {
  5136. class: "close-button",
  5137. onMouseenter: onMouseEnterCloseButton,
  5138. onMouseleave: onMouseLeaveCloseButton,
  5139. style: {
  5140. position: "absolute",
  5141. top: "0",
  5142. right: "0",
  5143. // background: 'black',
  5144. width: "60px",
  5145. height: "60px",
  5146. cursor: "pointer",
  5147. },
  5148. }),
  5149. ]
  5150. ),
  5151. ])
  5152. );
  5153. },
  5154. };
  5155. // ss-mark遮罩层
  5156. const SsMark = {
  5157. name: "SsMark",
  5158. setup(props, { slots, emit }) {
  5159. return () =>
  5160. h("div", { class: "dialog-container" }, [
  5161. h("div", { class: "mark-content" }, [
  5162. h("div", { class: "dialog-contianer" }, [
  5163. slots.default ? slots.default() : "",
  5164. ]),
  5165. ]),
  5166. ]);
  5167. },
  5168. };
  5169. // ss-bottom-button 底部按钮
  5170. // 修改支持更多按钮 by xu 20251211
  5171. const SsBottomButton = {
  5172. name: "SsBottomButton",
  5173. props: {
  5174. text: {
  5175. type: String,
  5176. required: false,
  5177. },
  5178. type: {
  5179. type: String,
  5180. default: "button",
  5181. },
  5182. iconClass: {
  5183. type: String,
  5184. },
  5185. /* 再去掉,没用到,生成 <button class type="button" 里的空 class。Lin
  5186. class: {
  5187. type: String,
  5188. default: "",
  5189. },
  5190. */
  5191. /// 再增加,增加支持 id=。Lin
  5192. id: {
  5193. //add by Ben(20251225)
  5194. type: String,
  5195. required: false,
  5196. },
  5197. ///
  5198. onclick: {
  5199. type: [Function, String],
  5200. default: null,
  5201. },
  5202. // 修改支持更多按钮 by xu 20251211
  5203. more: {
  5204. type: [Boolean, String],
  5205. default: false,
  5206. },
  5207. },
  5208. setup(props, { emit }) {
  5209. const SsBottomDivIcon = Vue.resolveComponent("ss-bottom-div-icon");
  5210. const showDropdown = Vue.ref(false);
  5211. // 修改支持更多按钮 by xu 20251211
  5212. const moreKey = Vue.computed(() => {
  5213. const val = props.more;
  5214. if (val === false || val === null || typeof val === "undefined") {
  5215. return null;
  5216. }
  5217. if (val === true || val === "" || val === "true") {
  5218. return "moreChg";
  5219. }
  5220. return val;
  5221. });
  5222. // 从配置中读取按钮信息和下拉选项
  5223. const config = Vue.computed(() => {
  5224. if (
  5225. moreKey.value &&
  5226. window.ss &&
  5227. window.ss.dom &&
  5228. window.ss.dom.btnElemConfig
  5229. ) {
  5230. return window.ss.dom.btnElemConfig[moreKey.value] || {};
  5231. }
  5232. return {};
  5233. });
  5234. const buttonText = Vue.computed(() => {
  5235. return props.text || config.value.desc || "";
  5236. });
  5237. const dropOptions = Vue.computed(() => {
  5238. return config.value.dropOptions || [];
  5239. });
  5240. const hasDropdown = Vue.computed(() => {
  5241. return dropOptions.value.length > 0;
  5242. });
  5243. const handleMouseEnter = () => {
  5244. if (hasDropdown.value) {
  5245. showDropdown.value = true;
  5246. }
  5247. };
  5248. const handleMouseLeave = () => {
  5249. showDropdown.value = false;
  5250. };
  5251. const handleDropItemClick = (option) => {
  5252. if (option.callback && typeof option.callback === "function") {
  5253. option.callback();
  5254. }
  5255. showDropdown.value = false;
  5256. };
  5257. return () =>
  5258. h(
  5259. "div",
  5260. {
  5261. class: "ss-bottom-button-wrapper",
  5262. onMouseenter: handleMouseEnter,
  5263. onMouseleave: handleMouseLeave,
  5264. },
  5265. [
  5266. h(
  5267. "button",
  5268. {
  5269. // class: props.class, // 再去掉,没用到,生成 <button class type="button" 里的空 class。Lin
  5270. id: props.id, // 再增加,增加支持 id=。Lin
  5271. onClick: (e) => {
  5272. e.stopPropagation();
  5273. emit("click", e);
  5274. if (props.onclick) {
  5275. // 如果是函数直接调用
  5276. if (typeof props.onclick === "function") {
  5277. props.onclick(e);
  5278. } else if (typeof props.onclick === "string") {
  5279. // 如果是字符串,使用直接的方法执行
  5280. // 临时存储按钮元素到全局变量
  5281. window.__ss_current_button = e.currentTarget;
  5282. // 直接执行代码,使用eval以保留原始上下文
  5283. try {
  5284. eval(props.onclick);
  5285. } finally {
  5286. // 清理全局变量
  5287. delete window.__ss_current_button;
  5288. }
  5289. }
  5290. }
  5291. },
  5292. type: props.type,
  5293. },
  5294. [
  5295. h("span", null, [
  5296. h(SsBottomDivIcon, {
  5297. class: props.iconClass,
  5298. }),
  5299. ]),
  5300. h("span", null, buttonText.value),
  5301. ]
  5302. ),
  5303. // 渲染下拉菜单
  5304. hasDropdown.value && showDropdown.value
  5305. ? h(
  5306. "div",
  5307. {
  5308. class: "ss-bottom-button-dropdown",
  5309. },
  5310. dropOptions.value.map((option) =>
  5311. h(
  5312. "div",
  5313. {
  5314. class: "ss-bottom-button-dropdown-item",
  5315. onClick: (e) => {
  5316. e.stopPropagation();
  5317. handleDropItemClick(option);
  5318. },
  5319. },
  5320. option.desc
  5321. )
  5322. )
  5323. )
  5324. : null,
  5325. ]
  5326. );
  5327. },
  5328. };
  5329. // ss-search搜索框
  5330. const SsSearch = {
  5331. name: "SsSearch",
  5332. props: {
  5333. theme: {
  5334. type: String,
  5335. default: "light",
  5336. validator: function (value) {
  5337. return ["dark", "light"].includes(value);
  5338. },
  5339. },
  5340. placeholder: {
  5341. type: String,
  5342. default: "", // : "请输入搜索条件",。再改,去掉 placeholder 默认值 "请输入搜索条件" 。Lin
  5343. },
  5344. },
  5345. setup(props, { emit }) {
  5346. const onClick = () => {
  5347. console.log("Search clicked");
  5348. emit("click");
  5349. };
  5350. const SsIcon = Vue.resolveComponent("ss-icon");
  5351. return () =>
  5352. Vue.h(
  5353. "div",
  5354. {
  5355. class: ["search-container", props.theme],
  5356. onClick: onClick,
  5357. },
  5358. [
  5359. Vue.h("input", {
  5360. placeholder: props.placeholder,
  5361. disabled: true,
  5362. }),
  5363. Vue.h(SsIcon, {
  5364. name: "search-result",
  5365. size: "20px",
  5366. }),
  5367. ]
  5368. );
  5369. },
  5370. };
  5371. // ss-cart-item 菜单页面的卡片 左右结构
  5372. const SsCartItem = {
  5373. name: "SsCartItem",
  5374. props: {
  5375. active: Boolean,
  5376. item: {
  5377. type: Object,
  5378. default: () => ({
  5379. thumb: "images/example/project-img.png",
  5380. title: "广州(国际)科技成果转化天河基地专",
  5381. description: "佳能中国广州分公司",
  5382. all: 50,
  5383. finish: 5,
  5384. }),
  5385. },
  5386. },
  5387. setup(props, { emit }) {
  5388. const item = props.item;
  5389. const itemWidth = Vue.computed(() => {
  5390. const containerWidth =
  5391. document.body.clientWidth || document.body.scrollWidth - 520;
  5392. const halfWidth = containerWidth / 2;
  5393. if (halfWidth < 480) {
  5394. return Math.min(containerWidth, 702) + "px";
  5395. } else {
  5396. return Math.min(halfWidth, 702) + "px";
  5397. }
  5398. });
  5399. const onItemClick = (e) => {
  5400. emit("click", e);
  5401. };
  5402. return {
  5403. item,
  5404. itemWidth,
  5405. onItemClick,
  5406. };
  5407. },
  5408. render() {
  5409. const SsIcon = Vue.resolveComponent("ss-icon");
  5410. return Vue.h(
  5411. "div",
  5412. {
  5413. class: { "item-container": true, active: this.active },
  5414. onClick: this.onItemClick,
  5415. style: { width: this.itemWidth },
  5416. },
  5417. [
  5418. Vue.h("div", { class: "header" }, [
  5419. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  5420. ]),
  5421. Vue.h("div", { class: "body" }, [
  5422. Vue.h("div", { class: "left" }, [
  5423. Vue.h("img", {
  5424. src: this.item.thumb,
  5425. alt: "Thumbnail",
  5426. class: "imgUnHandle",
  5427. style: { "object-fit": "cover", width: "100%", height: "100%" },
  5428. }),
  5429. ]),
  5430. Vue.h("div", { class: "right" }, [
  5431. Vue.h("div", { class: "title" }, this.item.title),
  5432. Vue.h("div", { class: "desc" }, this.item.description),
  5433. Vue.h("div", { class: "progress" }, [
  5434. Vue.h(
  5435. "div",
  5436. {
  5437. style: {
  5438. width: `${(this.item.finish / this.item.all) * 100}%`,
  5439. },
  5440. },
  5441. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  5442. ),
  5443. ]),
  5444. ]),
  5445. ]),
  5446. ]
  5447. );
  5448. },
  5449. };
  5450. // ss-cart-item2 菜单页面的卡片 上下结构
  5451. const SsCartItem2 = {
  5452. name: "SsCartItem2",
  5453. props: {
  5454. active: Boolean,
  5455. item: {
  5456. type: Object,
  5457. default: () => ({
  5458. thumb: "images/example/project-img.png",
  5459. title: "广州(国际)科技成果转化天河基地专",
  5460. description: "佳能中国广州分公司",
  5461. all: 50,
  5462. finish: 5,
  5463. }),
  5464. },
  5465. },
  5466. setup(props, { emit }) {
  5467. const item = props.item;
  5468. const itemWidth = Vue.computed(() => {
  5469. const containerWidth =
  5470. document.body.clientWidth || document.body.scrollWidth - 520;
  5471. const halfWidth = containerWidth / 2;
  5472. if (halfWidth < 480) {
  5473. return Math.min(containerWidth, 702) + "px";
  5474. } else {
  5475. return Math.min(halfWidth, 702) + "px";
  5476. }
  5477. });
  5478. const onItemClick = (e) => {
  5479. emit("click", e);
  5480. };
  5481. return {
  5482. item,
  5483. itemWidth,
  5484. onItemClick,
  5485. };
  5486. },
  5487. render() {
  5488. const SsIcon = Vue.resolveComponent("ss-icon");
  5489. return Vue.h(
  5490. "div",
  5491. {
  5492. class: { "item-container2": true, active: this.active },
  5493. onClick: this.onItemClick,
  5494. style: { width: this.itemWidth },
  5495. },
  5496. [
  5497. Vue.h("div", { class: "action-bar" }, [
  5498. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  5499. ]),
  5500. Vue.h("div", { class: "header" }, [
  5501. Vue.h("div", { class: "title" }, `${this.item.title}`),
  5502. ]),
  5503. Vue.h("div", { class: "body" }, [
  5504. Vue.h("div", { class: "left" }, [
  5505. Vue.h("img", {
  5506. src: this.item.thumb,
  5507. alt: "Thumbnail",
  5508. class: "imgUnHandle",
  5509. style: { "object-fit": "cover", width: "100%", height: "100%" },
  5510. }),
  5511. ]),
  5512. Vue.h("div", { class: "right" }, [
  5513. Vue.h("div", { class: "content" }, this.item.description),
  5514. Vue.h("div", { class: "tip" }, [
  5515. Vue.h("div", { class: "progress" }, [
  5516. Vue.h(
  5517. "div",
  5518. {
  5519. style: {
  5520. width: `${(this.item.finish / this.item.all) * 100}%`,
  5521. },
  5522. },
  5523. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  5524. ),
  5525. ]),
  5526. ]),
  5527. ]),
  5528. ]),
  5529. ]
  5530. );
  5531. },
  5532. };
  5533. /**
  5534. * SsListCard - 列表卡片组件
  5535. *
  5536. * @description 用于显示列表项的卡片组件,支持缩略图、标签、状态、操作按钮和选择功能
  5537. *
  5538. * @prop {Object} item - 卡片数据对象
  5539. * @prop {String} item.title - 卡片标题
  5540. * @prop {String} [item.thumb] - 缩略图 URL(可选)
  5541. * @prop {String} [item.thumbType] - 缩略图类型:'thumbnail'(缩略图)或默认(证件照)
  5542. * @prop {String} [item.status] - 卡片状态:'available'(可用-绿色)、'unavailable'(不可用-黄色)、'disabled'(禁用-红色)
  5543. * @prop {Array} item.tags - 标签数组,格式:[{键: 值}, ...]
  5544. * @prop {Function} item.onclick - 点击卡片的回调函数
  5545. * @prop {Array} [item.buttons] - 操作按钮数组(可选),显示在右上角齿轮
  5546. * @prop {Array} [item.statusIcons] - 状态图标数组(可选),显示在右上角,格式:[{class: '图标类名', title: '提示文字'}, ...]
  5547. *
  5548. * @example
  5549. * // 基础用法
  5550. * const item = {
  5551. * title: "卡片标题",
  5552. * tags: [
  5553. * { 类型: '文档' },
  5554. * { 状态: '进行中' }
  5555. * ],
  5556. * onclick: () => console.log('点击了卡片')
  5557. * };
  5558. *
  5559. * @example
  5560. * // 带缩略图和状态
  5561. * const item = {
  5562. * title: "场地预定",
  5563. * thumbType: 'thumbnail',
  5564. * thumb: "https://example.com/image.jpg",
  5565. * status: "available", // 绿色背景
  5566. * tags: [{ 容量: '50人' }],
  5567. * onclick: () => {}
  5568. * };
  5569. *
  5570. * @example
  5571. * // 带操作按钮和状态图标
  5572. * const item = {
  5573. * title: "会议室A",
  5574. * tags: [{ 楼层: '3F' }],
  5575. * onclick: () => {},
  5576. * // 右上角操作按钮(齿轮)
  5577. * buttons: [{
  5578. * class: 'cart-list-setting',
  5579. * title: '编辑',
  5580. * onclick: () => console.log('编辑')
  5581. * }],
  5582. * // 右上角状态图标(在齿轮右边)
  5583. * statusIcons: [{
  5584. * class: 'icon-emoji',
  5585. * title: '清洁中'
  5586. * }]
  5587. * };
  5588. *
  5589. * @features
  5590. * - 卡片选择:鼠标悬停右下角显示选择角标,点击切换选中状态,选中后显示底部深灰色线条
  5591. * - 状态颜色:根据 status 字段显示不同背景色(可用/不可用/禁用)
  5592. * - 图片类型:支持证件照(73×100px)和缩略图(180×100px)两种尺寸
  5593. * - 操作按钮:右上角齿轮,hover 显示,支持多个按钮下拉菜单
  5594. * - 状态图标:右上角显示状态图标,齿轮会根据图标数量自动左移
  5595. *
  5596. * @author xu
  5597. * @date 20260105
  5598. */
  5599. // 组件文档补全(JSDoc) by xu 20260108
  5600. /**
  5601. * SsListCard(左侧对象卡片)
  5602. *
  5603. * 用途:
  5604. * - 渲染左侧卡片(标题 + tags)
  5605. * - 右下角“角标”用于选中/取消选中(不会触发卡片 click)
  5606. *
  5607. * 调用示例:
  5608. * ```html
  5609. * <ss-list-card :item="item" @toggle-select="handleToggleSelect" @click="openDetail"></ss-list-card>
  5610. * ```
  5611. *
  5612. * Props:
  5613. * - `item`:卡片数据对象(建议含 `id/title/tags[]`;内部会读写 `item._ssSelected` 作为选中态)
  5614. *
  5615. * Emits:
  5616. * - `toggle-select`:点击角标触发,参数 `{ item, selected }`
  5617. * - `click`:点击卡片主体触发(用于打开详情等)
  5618. */
  5619. const SsListCard = {
  5620. name: "SsListCard",
  5621. props: {
  5622. ssObjName: { type: String, default: "" }, // 功能:业务对象名(用于默认缩略图 icon) by xu 20260109
  5623. cardClickAction: { type: String, default: "view" }, // 功能:卡片主体点击动作(view=查看;single=单选互斥) by xu 20260109
  5624. item: {
  5625. type: Object,
  5626. required: true,
  5627. },
  5628. },
  5629. emits: ["click", "change", "toggle-select"],
  5630. setup(props, { emit }) {
  5631. const item = props.item;
  5632. // 移除 itemWidth 计算属性,不再需要 by xu 20260105
  5633. // 判断卡片类型 by xu 20260105
  5634. const cardType = Vue.computed(() => {
  5635. // 支持“无图但保留缩略图占位”(同一业务列表图片形态一致) by xu 20260109
  5636. if (!item.thumb && !item.thumbType) return ""; // 业务列表“无图”形态
  5637. // 根据 thumbType 字段判断,如果没有则默认为证件照
  5638. return item.thumbType === "thumbnail" ? "card-thumbnail" : "card-photo";
  5639. });
  5640. // 判断状态类型 - 场地预定状态 by xu 20260105
  5641. const statusClass = Vue.computed(() => {
  5642. if (!item.status) return ""; // 无状态,默认白色
  5643. // 映射状态值到 CSS 类名
  5644. const statusMap = {
  5645. available: "status-available",
  5646. unavailable: "status-unavailable",
  5647. disabled: "status-disabled",
  5648. };
  5649. return statusMap[item.status] || "";
  5650. });
  5651. const onItemClick = (e) => {
  5652. // 清除所有类型卡片的 active 状态(卡片主体点击仅做 active 高亮) by xu 20260109
  5653. const allListCards = document.querySelectorAll(
  5654. ".knowledge-item-container"
  5655. );
  5656. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  5657. allListCards.forEach((card) => card.classList.remove("active"));
  5658. allFolderCards.forEach((card) => card.classList.remove("active"));
  5659. // 设置当前项的 active 状态
  5660. e.currentTarget.classList.add("active");
  5661. // 卡片主体点击动作由页面级配置控制 by xu 20260109
  5662. if (props.cardClickAction === "view") {
  5663. props.item.onclick?.();
  5664. // 通知父级:卡片点击(查看) by xu 20260109
  5665. emit("click", props.item);
  5666. }
  5667. };
  5668. const onItemChange = (e, icon, index) => {
  5669. e.stopPropagation(); // 阻止事件冒泡到卡片
  5670. props.item.buttons[0].onclick();
  5671. // emit("change", { item: props.item, icon, index });
  5672. };
  5673. return {
  5674. item,
  5675. cardType,
  5676. statusClass,
  5677. onItemClick,
  5678. onItemChange,
  5679. };
  5680. },
  5681. data() {
  5682. return {
  5683. showButtons: false,
  5684. selected: false, // 选择状态 by xu 20260105
  5685. showTextPopover: false, // 功能:右侧文字区 hover 展示全量 by xu 20260108
  5686. textPopoverType: "", // second-summary / second-tags / third / third-full by xu 20260108
  5687. textPopoverBottom: 0, // 功能:popover 从当前省略行位置向上展开 by xu 20260108
  5688. hideTextPopoverTimer: null, // 功能:鼠标从省略行移到浮层的缓冲 by xu 20260108
  5689. textPopoverPayload: null, // { kind, text?, lines? } by xu 20260108
  5690. ellipsisVisible: {
  5691. // 功能:只在真实出现 ... 时才显示命中区/允许 goheight by xu 20260109
  5692. secondSummary: false,
  5693. secondTags: false,
  5694. third: false,
  5695. thirdFull: false,
  5696. },
  5697. };
  5698. },
  5699. methods: {
  5700. __allowSelect() {
  5701. // 功能说明:无 rbarObj 时禁用选中能力(隐藏右下角勾选并禁止 toggle) by xu 20260122
  5702. try {
  5703. if (this?.$root && this.$root.hasObjPanel === false) return false;
  5704. if (
  5705. typeof window !== "undefined" &&
  5706. window.__objListVm &&
  5707. window.__objListVm.hasObjPanel === false
  5708. )
  5709. return false;
  5710. } catch (_) {}
  5711. return true;
  5712. },
  5713. // 切换选择状态(对外 emit,支持方案A父级 state 中转) by xu 20260106
  5714. toggleSelect(e) {
  5715. e.stopPropagation();
  5716. if (!this.__allowSelect()) return; // 功能说明:无 rbarObj 时禁止选中 by xu 20260122
  5717. // 使用 item 上的状态,便于父级/右侧边栏反向同步 by xu 20260106
  5718. this.item._ssSelected = !this.item?._ssSelected;
  5719. this.$emit("toggle-select", {
  5720. item: this.item,
  5721. selected: !!this.item?._ssSelected,
  5722. });
  5723. },
  5724. // 卡片主体点击=单选互斥:只有“本次切到选中”才清理其他选中 by xu 20260109
  5725. toggleSelectExclusive(e) {
  5726. e?.stopPropagation?.();
  5727. if (!this.__allowSelect()) return; // 功能说明:无 rbarObj 时禁止选中 by xu 20260122
  5728. this.item._ssSelected = !this.item?._ssSelected;
  5729. const selected = !!this.item?._ssSelected;
  5730. this.$emit("toggle-select", {
  5731. item: this.item,
  5732. selected,
  5733. exclusive: true,
  5734. });
  5735. },
  5736. // 功能:无缩略图时,用业务对象 icon 做默认图(ss-icon + icon-obj-xx) by xu 20260109
  5737. getBizThumbIconClass() {
  5738. const name = String(
  5739. this.ssObjName ||
  5740. this.item?.ssObjName ||
  5741. this.$root?.ssObjName ||
  5742. window?.ss?.dom?.ssObjName ||
  5743. ""
  5744. ).trim();
  5745. if (!name) return "";
  5746. return `icon-obj-${name}`;
  5747. },
  5748. // 功能:构造右侧文字区 4 行(摘要/类目或标签/对象号) by xu 20260108
  5749. buildRightTextLines() {
  5750. const item = this.item || {};
  5751. const summary = String(item?.desc ?? "").trim(); // 后端字段后续映射 by xu 20260108
  5752. const objNum = String(item?.objNum ?? "").trim(); // 后端字段后续映射 by xu 20260108
  5753. const categoryArr = Array.isArray(item?.category) ? item.category : [];
  5754. const tagsArr = Array.isArray(item?.tags) ? item.tags : [];
  5755. const hasTags = tagsArr.length > 0;
  5756. const hasCategory = categoryArr.length > 0;
  5757. // 第二部分(L1-L3):摘要优先,其次物品参数 by xu 20260108
  5758. const secondKind = summary ? "summary" : hasTags ? "tags" : "";
  5759. const hasSecond = !!secondKind;
  5760. // 第三部分(L4):对象号优先,其次类目 by xu 20260108
  5761. /* 再改,不显示 cat 里的对象id(数据库id)。Lin
  5762. const thirdKind = objNum ? "objNum" : hasCategory ? "category" : "";
  5763. */ const thirdKind = objNum ? "objNum" : hasCategory ? "category" : "";
  5764. const hasThird = !!thirdKind;
  5765. const thirdFull = !hasSecond && hasThird; // 第二部分为空则第三部分占满 4 行 by xu 20260108
  5766. const secondFull = hasSecond && !hasThird && secondKind === "tags"; // 仅标签时占满 4 行(不留空行) by xu 20260109
  5767. const toValueText = (obj) => {
  5768. // 功能说明:类目/物品参数回显展示 key: value(否则只显示值看不懂) by xu 20260114
  5769. const [k, v] = Object.entries(obj || {})[0] || ["", ""];
  5770. const key = k !== undefined && k !== null ? String(k).trim() : "";
  5771. /*? 再改,值为 0 也不显示 -- 返回 "",在 toLineList(arr) 里的 .filter(Boolean) 滤掉。Lin
  5772. const val = v !== undefined && v !== null ? String(v).trim() : "";
  5773. ?*/ const val = (v !== undefined && v !== null && v !== 0)? String(v).trim() : "";
  5774. if (key && val) return `${key}:${val}`;
  5775. /*? 再去掉,改为 "要不显示一对,要不不显示"。Lin
  5776. if (val) return val;
  5777. if (key) return key;
  5778. ?*/
  5779. return "";
  5780. };
  5781. const toLineList = (arr) =>
  5782. (arr || [])
  5783. .map(toValueText)
  5784. .map((s) => String(s ?? "").trim())
  5785. .filter(Boolean);
  5786. const flat = (arr) => toLineList(arr).join(" ");
  5787. // 第二部分 tags:默认 3 行;仅标签时占满 4 行(避免底部空一行) by xu 20260109
  5788. const secondTagsMaxLines = secondFull ? 4 : 3;
  5789. const secondTagsLinesFull = toLineList(tagsArr);
  5790. const secondTagsHead = secondTagsLinesFull.slice(
  5791. 0,
  5792. Math.max(0, secondTagsMaxLines - 1)
  5793. );
  5794. const secondTagsTail = secondTagsLinesFull.slice(
  5795. Math.max(0, secondTagsMaxLines - 1)
  5796. );
  5797. const secondTagsLast =
  5798. secondTagsTail.length <= 1
  5799. ? secondTagsTail[0] || ""
  5800. : secondTagsTail.join(" "); // 功能:最后一行平铺剩余 by xu 20260108
  5801. // 第三部分类目:卡片上串成一行;goheight 展开时一条一行 by xu 20260109
  5802. const categoryLinesFull = toLineList(categoryArr);
  5803. const categoryLine = categoryLinesFull.join(" ");
  5804. const thirdText =
  5805. thirdKind === "objNum"
  5806. ? objNum
  5807. : thirdKind === "category"
  5808. ? categoryLine
  5809. : "";
  5810. return {
  5811. secondKind,
  5812. thirdKind,
  5813. hasSecond,
  5814. hasThird,
  5815. thirdFull,
  5816. secondFull,
  5817. summary,
  5818. secondTagsMaxLines,
  5819. secondTagsHead,
  5820. secondTagsLast,
  5821. secondTagsLinesFull,
  5822. objNum,
  5823. categoryLine,
  5824. categoryLinesFull,
  5825. thirdText,
  5826. };
  5827. },
  5828. measureTextOverflowByLines(text, maxLines, width) {
  5829. const w = Number(width) || 0;
  5830. if (!w || !text) return false;
  5831. const probe = document.createElement("div");
  5832. probe.style.position = "fixed";
  5833. probe.style.left = "-99999px";
  5834. probe.style.top = "0";
  5835. probe.style.width = w + "px";
  5836. probe.style.fontSize = "18px";
  5837. probe.style.lineHeight = "24px";
  5838. probe.style.whiteSpace = "normal";
  5839. probe.style.wordBreak = "break-word";
  5840. probe.style.visibility = "hidden";
  5841. probe.textContent = text;
  5842. document.body.appendChild(probe);
  5843. const h = probe.getBoundingClientRect().height || 0;
  5844. document.body.removeChild(probe);
  5845. return h > maxLines * 24 + 1;
  5846. },
  5847. measureSingleLineOverflow(text, width) {
  5848. const w = Number(width) || 0;
  5849. if (!w || !text) return false;
  5850. const probe = document.createElement("span");
  5851. probe.style.position = "fixed";
  5852. probe.style.left = "-99999px";
  5853. probe.style.top = "0";
  5854. probe.style.display = "inline-block";
  5855. probe.style.maxWidth = w + "px";
  5856. probe.style.fontSize = "18px";
  5857. probe.style.lineHeight = "24px";
  5858. probe.style.whiteSpace = "nowrap";
  5859. probe.style.visibility = "hidden";
  5860. probe.textContent = text;
  5861. document.body.appendChild(probe);
  5862. const overflow =
  5863. (probe.scrollWidth || 0) > (probe.clientWidth || w) + 1;
  5864. document.body.removeChild(probe);
  5865. return overflow;
  5866. },
  5867. // 功能:根据当前卡片宽度刷新「是否出现 ...」状态(用于控制命中区显示) by xu 20260109
  5868. refreshEllipsisVisible() {
  5869. try {
  5870. const right = this.$el?.querySelector?.(".right");
  5871. const rawWidth =
  5872. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  5873. const width = Math.max(0, Math.round(rawWidth)); // 修复:内容区不再使用 padding-right 预留,测量按真实宽度 by xu 20260109
  5874. const model = this.buildRightTextLines();
  5875. const next = {
  5876. secondSummary: false,
  5877. secondTags: false,
  5878. third: false,
  5879. thirdFull: false,
  5880. };
  5881. if (model.secondKind === "summary" && model.summary) {
  5882. next.secondSummary = this.measureTextOverflowByLines(
  5883. model.summary,
  5884. 3,
  5885. width
  5886. );
  5887. }
  5888. if (model.secondKind === "tags") {
  5889. // 功能说明:tags 采用「最后一行平铺剩余」策略,是否出现 ... 仅取决于最后一行是否溢出(数量多但平铺放得下不算溢出) by xu 20260114
  5890. next.secondTags = this.measureSingleLineOverflow(
  5891. model.secondTagsLast,
  5892. width
  5893. );
  5894. }
  5895. if (model.hasThird && !model.thirdFull) {
  5896. next.third = this.measureSingleLineOverflow(model.thirdText, width);
  5897. }
  5898. if (model.hasThird && model.thirdFull) {
  5899. next.thirdFull = this.measureTextOverflowByLines(
  5900. model.thirdText,
  5901. 4,
  5902. width
  5903. );
  5904. }
  5905. const prev = this.ellipsisVisible || {};
  5906. const changed =
  5907. prev.secondSummary !== next.secondSummary ||
  5908. prev.secondTags !== next.secondTags ||
  5909. prev.third !== next.third ||
  5910. prev.thirdFull !== next.thirdFull;
  5911. if (changed) this.ellipsisVisible = next;
  5912. } catch (e) {
  5913. // ignore by xu 20260109
  5914. }
  5915. },
  5916. showTextPopoverFor(el, kind) {
  5917. // 调试开关:window.__SS_LISTCARD_DEBUG__ = true 时打印 hover/溢出判断日志 by xu 20260108
  5918. const debug =
  5919. typeof window !== "undefined" && !!window.__SS_LISTCARD_DEBUG__;
  5920. if (debug) {
  5921. console.log("[SsListCard] ellipsis hover", {
  5922. kind,
  5923. el: el?.className,
  5924. });
  5925. }
  5926. const model = this.buildRightTextLines();
  5927. const lineEl = el?.closest?.(".ss-card-text__line") || el;
  5928. const right = lineEl?.closest?.(".right") || el?.closest?.(".right");
  5929. const rawWidth =
  5930. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  5931. const width = Math.max(0, Math.round(rawWidth)); // 修复:内容区不再预留 padding-right,测量按真实宽度 by xu 20260109
  5932. const textEl =
  5933. kind === "second-summary"
  5934. ? lineEl?.querySelector?.(".ss-card-text__secondSummary")
  5935. : kind === "second-tags"
  5936. ? lineEl?.querySelector?.(".ss-card-text__tagLineLast")
  5937. : kind === "third"
  5938. ? lineEl?.querySelector?.(".ss-card-text__thirdLine")
  5939. : lineEl?.querySelector?.(".ss-card-text__thirdFull");
  5940. let payload = null;
  5941. // 仅当真实会出现 ... 时才允许 goheight(避免“没超出也能出 goheight”) by xu 20260109
  5942. const overflowed =
  5943. kind === "second-summary"
  5944. ? this.measureTextOverflowByLines(model.summary, 3, width)
  5945. : kind === "second-tags"
  5946. ? this.measureSingleLineOverflow(model.secondTagsLast, width) // 功能说明:同 refreshEllipsisVisible,tags 仅看最后一行是否溢出 by xu 20260114
  5947. : kind === "third"
  5948. ? this.measureSingleLineOverflow(model.thirdText, width)
  5949. : this.measureTextOverflowByLines(model.thirdText, 4, width);
  5950. if (!overflowed) return;
  5951. if (kind === "second-summary") {
  5952. if (model.summary) payload = { kind, text: model.summary };
  5953. } else if (kind === "second-tags") {
  5954. if (
  5955. Array.isArray(model.secondTagsLinesFull) &&
  5956. model.secondTagsLinesFull.length
  5957. ) {
  5958. payload = { kind, lines: model.secondTagsLinesFull };
  5959. }
  5960. } else if (kind === "third") {
  5961. if (
  5962. model.thirdKind === "category" &&
  5963. Array.isArray(model.categoryLinesFull) &&
  5964. model.categoryLinesFull.length
  5965. ) {
  5966. payload = { kind, lines: model.categoryLinesFull }; // 功能:类目展开一条一行 by xu 20260109
  5967. } else if (model.thirdText) {
  5968. payload = { kind, text: model.thirdText };
  5969. }
  5970. } else if (kind === "third-full") {
  5971. if (
  5972. model.thirdKind === "category" &&
  5973. Array.isArray(model.categoryLinesFull) &&
  5974. model.categoryLinesFull.length
  5975. ) {
  5976. payload = { kind, lines: model.categoryLinesFull }; // 功能:类目占满模式展开一条一行 by xu 20260109
  5977. } else if (model.thirdText) {
  5978. payload = { kind, text: model.thirdText };
  5979. }
  5980. }
  5981. if (debug) {
  5982. console.log("[SsListCard] ellipsis decide", {
  5983. kind,
  5984. rawWidth: Math.round(rawWidth),
  5985. width,
  5986. hasPayload: !!payload,
  5987. textEl: textEl?.className,
  5988. textClient: textEl
  5989. ? {
  5990. cw: textEl.clientWidth,
  5991. ch: textEl.clientHeight,
  5992. sw: textEl.scrollWidth,
  5993. sh: textEl.scrollHeight,
  5994. }
  5995. : null,
  5996. });
  5997. }
  5998. if (!payload) return;
  5999. this.clearHideTextPopoverTimer();
  6000. const container = lineEl?.closest?.(".right");
  6001. const containerRect = container?.getBoundingClientRect?.();
  6002. const lineRect = lineEl?.getBoundingClientRect?.();
  6003. if (containerRect && lineRect) {
  6004. const bottom = Math.max(
  6005. 0,
  6006. Math.round(containerRect.bottom - lineRect.bottom)
  6007. );
  6008. this.textPopoverBottom = bottom;
  6009. } else {
  6010. this.textPopoverBottom = 0;
  6011. }
  6012. this.textPopoverPayload = payload;
  6013. this.textPopoverType = kind;
  6014. this.showTextPopover = true;
  6015. if (debug) console.log("[SsListCard] goheight show", payload);
  6016. },
  6017. isOverflowing(el) {
  6018. if (!el) return false;
  6019. // 单行/多行省略统一判断:scroll 尺寸大于 client 尺寸即认为有 ... by xu 20260108
  6020. return (
  6021. (el.scrollWidth &&
  6022. el.clientWidth &&
  6023. el.scrollWidth > el.clientWidth + 1) ||
  6024. (el.scrollHeight &&
  6025. el.clientHeight &&
  6026. el.scrollHeight > el.clientHeight + 1)
  6027. );
  6028. },
  6029. isSummaryOverflowing(el) {
  6030. if (!el) return false;
  6031. // -webkit-line-clamp 场景下 scrollHeight 不稳定,改用“无 clamp 的离屏测量”判断是否超过 2 行 by xu 20260108
  6032. const text = String(this.item?.desc ?? "").trim();
  6033. if (!text) return false;
  6034. const rect = el.getBoundingClientRect?.();
  6035. const width = rect?.width || el.clientWidth || 0;
  6036. if (!width) return false;
  6037. const probe = document.createElement("div");
  6038. probe.style.position = "fixed";
  6039. probe.style.left = "-99999px";
  6040. probe.style.top = "0";
  6041. probe.style.width = width + "px";
  6042. probe.style.fontSize = "18px";
  6043. probe.style.lineHeight = "24px";
  6044. probe.style.whiteSpace = "normal";
  6045. probe.style.wordBreak = "break-word";
  6046. probe.style.visibility = "hidden";
  6047. probe.textContent = text;
  6048. document.body.appendChild(probe);
  6049. const h = probe.getBoundingClientRect().height || 0;
  6050. document.body.removeChild(probe);
  6051. return h > 48 + 1;
  6052. },
  6053. clearHideTextPopoverTimer() {
  6054. if (this.hideTextPopoverTimer) {
  6055. clearTimeout(this.hideTextPopoverTimer);
  6056. this.hideTextPopoverTimer = null;
  6057. }
  6058. },
  6059. // 修复 goheight hover 无响应:移除重复方法覆盖,统一使用上面的 showTextPopoverFor(el, kind) by xu 20260109
  6060. hideTextPopoverLater() {
  6061. this.clearHideTextPopoverTimer();
  6062. this.hideTextPopoverTimer = setTimeout(() => {
  6063. this.showTextPopover = false;
  6064. this.textPopoverType = "";
  6065. this.textPopoverPayload = null;
  6066. }, 120);
  6067. },
  6068. hideTextPopover() {
  6069. this.clearHideTextPopoverTimer();
  6070. this.showTextPopover = false;
  6071. this.textPopoverType = "";
  6072. this.textPopoverPayload = null;
  6073. },
  6074. // 功能:新需求下不在 updated 内做测量,避免死循环 by xu 20260108
  6075. },
  6076. mounted() {
  6077. // 无需在 mounted/updated 里做 overflow 测量(避免死循环),只在 hover 触发时判断 by xu 20260108
  6078. // 仅用于控制“...命中区是否显示”,不会触发循环更新 by xu 20260109
  6079. this.$nextTick?.(() => {
  6080. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  6081. });
  6082. this.__ssListCardResizeHandler = () => this.refreshEllipsisVisible?.(); // 功能:窗口变化时刷新 ... 显示 by xu 20260109
  6083. window.addEventListener?.("resize", this.__ssListCardResizeHandler);
  6084. },
  6085. updated() {
  6086. // 卡片数据更新后刷新一次 ... 显示状态(避免“宽度/内容变了但命中区不变”) by xu 20260109
  6087. this.$nextTick?.(() => {
  6088. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  6089. });
  6090. },
  6091. beforeUnmount() {
  6092. // 清理 timer,避免残留导致异常 by xu 20260108
  6093. this.clearHideTextPopoverTimer?.();
  6094. if (this.__ssListCardResizeHandler) {
  6095. window.removeEventListener?.("resize", this.__ssListCardResizeHandler);
  6096. this.__ssListCardResizeHandler = null;
  6097. }
  6098. },
  6099. render() {
  6100. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  6101. const SsIcon = Vue.resolveComponent("ss-icon");
  6102. const hasThumbArea = !!(this.item?.thumb || this.item?.thumbType); // 功能:无图但有 thumbType 时仍保留占位 by xu 20260109
  6103. const thumbSrc = (() => {
  6104. // 功能说明:兼容 thumb 为 raw path 或 {val}/{value},组件内统一转为 dlByHttp URL by xu 20260122
  6105. const t = this.item?.thumb;
  6106. if (!t) return "";
  6107. if (typeof t === "string") {
  6108. const s = t.trim();
  6109. if (!s) return "";
  6110. // 已经是 URL/绝对路径则直接使用;否则按 path 构建 dlByHttp by xu 20260122
  6111. if (
  6112. /^https?:\/\//i.test(s) ||
  6113. s.startsWith("/service?") ||
  6114. s.startsWith("/")
  6115. )
  6116. return s;
  6117. return buildThumbUrl(s);
  6118. }
  6119. return buildThumbUrl(t);
  6120. })();
  6121. return Vue.h(
  6122. "div",
  6123. {
  6124. class: {
  6125. "knowledge-item-container": true,
  6126. active: this.item.active,
  6127. [this.cardType]: !!this.cardType, // 动态添加卡片类型类名 by xu 20260105
  6128. [this.statusClass]: !!this.statusClass,
  6129. },
  6130. onClick: (e) => {
  6131. this.onItemClick?.(e);
  6132. if (this.__allowSelect() && this.cardClickAction === "single") {
  6133. // 功能说明:无 rbarObj 时不允许单选互斥 by xu 20260122
  6134. this.toggleSelectExclusive?.(e);
  6135. }
  6136. }, // 功能:卡片主体点击动作(view/single) by xu 20260109
  6137. // 移除固定宽度,由 CSS min-width 控制 by xu 20260105
  6138. },
  6139. [
  6140. // 右上角状态图标区域 by xu 20260105
  6141. this.item?.statusIcons?.length > 0 &&
  6142. Vue.h(
  6143. "div",
  6144. { class: "card-status-icons" },
  6145. this.item.statusIcons.map((icon) =>
  6146. Vue.h(SsIcon, {
  6147. class: `status-icon ${icon.class}`,
  6148. title: icon.title,
  6149. })
  6150. )
  6151. ),
  6152. this.item?.buttons?.length > 0 &&
  6153. Vue.h(
  6154. "div",
  6155. {
  6156. class: "header",
  6157. style:
  6158. this.item?.statusIcons?.length > 0
  6159. ? {
  6160. right: `${this.item.statusIcons.length * 48}px`,
  6161. borderTopRightRadius: "0",
  6162. }
  6163. : {},
  6164. onMouseenter: () => (this.showButtons = true),
  6165. onMouseleave: () => (this.showButtons = false),
  6166. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  6167. },
  6168. [
  6169. // 只在有按钮时渲染设置图标
  6170. // this.item?.buttons?.length > 0 &&
  6171. Vue.h("div", {
  6172. class: "cart-list-setting cart-list-icon",
  6173. title: this.item?.buttons?.[0]?.title,
  6174. }),
  6175. // 鼠标移入时显示按钮列表,与图标同级
  6176. // this.item?.buttons?.length > 0 &&
  6177. this.showButtons &&
  6178. this.item?.buttons?.length > 1 &&
  6179. Vue.h(
  6180. "div",
  6181. {
  6182. class: "cart-list-button-popup",
  6183. },
  6184. this.item.buttons.map((btn) =>
  6185. Vue.h(
  6186. "div",
  6187. {
  6188. onClick: (e) => {
  6189. e.stopPropagation();
  6190. btn.onclick?.();
  6191. },
  6192. },
  6193. [
  6194. // 如果有 class,显示对应的图标
  6195. btn.class &&
  6196. Vue.h(SsCartListIcon, {
  6197. class: [btn.class],
  6198. }),
  6199. // 显示按钮文本
  6200. Vue.h("span", null, btn.title),
  6201. ]
  6202. )
  6203. )
  6204. ),
  6205. ]
  6206. ),
  6207. Vue.h("div", { class: "body" }, [
  6208. Vue.h("div", { class: "box-header" }, [
  6209. Vue.h("div", `${this.item.title}`),
  6210. ]),
  6211. Vue.h(
  6212. "div",
  6213. {
  6214. class: !hasThumbArea ? "no-thumb box-body" : "box-body",
  6215. },
  6216. [
  6217. hasThumbArea
  6218. ? thumbSrc
  6219. ? Vue.h("div", { class: "left" }, [
  6220. Vue.h("img", {
  6221. src: thumbSrc,
  6222. alt: "Thumbnail",
  6223. class: "imgUnHandle",
  6224. style: {
  6225. "object-fit": "cover",
  6226. width: "100%",
  6227. height: "100%",
  6228. },
  6229. }),
  6230. ])
  6231. : Vue.h(
  6232. // 功能:无图占位(ss-icon + biz icon,居中) by xu 20260109
  6233. "div",
  6234. { class: "left ss-objlist-thumbPlaceholder" },
  6235. [
  6236. Vue.h(SsIcon, {
  6237. class: `${this.getBizThumbIconClass()} ss-objlist-thumbIcon`,
  6238. }),
  6239. ]
  6240. )
  6241. : null,
  6242. Vue.h(
  6243. "div",
  6244. {
  6245. class: "right",
  6246. },
  6247. (() => {
  6248. const model = this.buildRightTextLines(); // 功能:右侧文字区新规则(第二部分/第三部分优先级) by xu 20260108
  6249. const hasAny = !!(model?.hasSecond || model?.hasThird);
  6250. if (!hasAny) return [];
  6251. const children = [];
  6252. // 第二部分:L1-L3(摘要优先,其次 tags;不足留空;超出 L3 ...) by xu 20260108
  6253. if (model.hasSecond) {
  6254. if (model.secondKind === "summary") {
  6255. children.push(
  6256. Vue.h(
  6257. "div",
  6258. {
  6259. class:
  6260. "ss-card-text__line ss-card-text__secondBlock",
  6261. },
  6262. [
  6263. Vue.h(
  6264. "div",
  6265. {
  6266. class: "ss-card-text__secondSummary",
  6267. title: model.summary,
  6268. },
  6269. model.summary
  6270. ),
  6271. Vue.h("span", {
  6272. class: [
  6273. "ss-card-text__ellipsisHit",
  6274. "ss-card-text__ellipsisHit--second",
  6275. this.ellipsisVisible?.secondSummary
  6276. ? "is-on"
  6277. : "",
  6278. ],
  6279. title: "查看完整摘要",
  6280. onMouseenter: (e) =>
  6281. this.showTextPopoverFor(
  6282. e?.currentTarget,
  6283. "second-summary"
  6284. ),
  6285. onClick: (e) => {
  6286. e?.stopPropagation?.();
  6287. this.showTextPopoverFor(
  6288. e?.currentTarget,
  6289. "second-summary"
  6290. );
  6291. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  6292. onMouseleave: () => this.hideTextPopoverLater(),
  6293. }),
  6294. ]
  6295. )
  6296. );
  6297. } else if (model.secondKind === "tags") {
  6298. children.push(
  6299. Vue.h(
  6300. "div",
  6301. {
  6302. class: [
  6303. "ss-card-text__line",
  6304. model.secondFull
  6305. ? "ss-card-text__secondFullBlock"
  6306. : "ss-card-text__secondBlock",
  6307. ],
  6308. },
  6309. [
  6310. // 功能:仅标签时占满 4 行 by xu 20260109
  6311. Vue.h(
  6312. "div",
  6313. { class: "ss-card-text__secondTags" },
  6314. [
  6315. ...model.secondTagsHead.map((t) =>
  6316. Vue.h(
  6317. "div",
  6318. {
  6319. class: "ss-card-text__tagLine",
  6320. title: t,
  6321. },
  6322. t
  6323. )
  6324. ),
  6325. // 第三行:平铺剩余(可能为空) by xu 20260108
  6326. Vue.h(
  6327. "div",
  6328. {
  6329. class:
  6330. "ss-card-text__tagLine is-last ss-card-text__tagLineLast",
  6331. title: model.secondTagsLast,
  6332. },
  6333. model.secondTagsLast
  6334. ),
  6335. ].filter(Boolean)
  6336. ),
  6337. // 只在最后一行出现 ... 时才触发 goheight by xu 20260108
  6338. Vue.h("span", {
  6339. class: [
  6340. "ss-card-text__ellipsisHit",
  6341. "ss-card-text__ellipsisHit--second",
  6342. this.ellipsisVisible?.secondTags
  6343. ? "is-on"
  6344. : "",
  6345. ],
  6346. title: "查看完整物品参数",
  6347. onMouseenter: (e) =>
  6348. this.showTextPopoverFor(
  6349. e?.currentTarget,
  6350. "second-tags"
  6351. ),
  6352. onClick: (e) => {
  6353. e?.stopPropagation?.();
  6354. this.showTextPopoverFor(
  6355. e?.currentTarget,
  6356. "second-tags"
  6357. );
  6358. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  6359. onMouseleave: () => this.hideTextPopoverLater(),
  6360. }),
  6361. ]
  6362. )
  6363. );
  6364. }
  6365. }
  6366. // 第三部分:默认 L4;第二部分为空则占满 L1-L4 by xu 20260108
  6367. if (model.hasThird) {
  6368. if (model.thirdFull) {
  6369. children.push(
  6370. Vue.h(
  6371. "div",
  6372. {
  6373. class:
  6374. "ss-card-text__line ss-card-text__thirdFullBlock",
  6375. },
  6376. [
  6377. Vue.h(
  6378. "div",
  6379. {
  6380. class: "ss-card-text__thirdFull",
  6381. title: model.thirdText,
  6382. },
  6383. model.thirdText
  6384. ),
  6385. Vue.h("span", {
  6386. class: [
  6387. "ss-card-text__ellipsisHit",
  6388. "ss-card-text__ellipsisHit--third",
  6389. this.ellipsisVisible?.thirdFull
  6390. ? "is-on"
  6391. : "",
  6392. ],
  6393. title: "查看完整信息",
  6394. onMouseenter: (e) =>
  6395. this.showTextPopoverFor(
  6396. e?.currentTarget,
  6397. "third-full"
  6398. ),
  6399. onClick: (e) => {
  6400. e?.stopPropagation?.();
  6401. this.showTextPopoverFor(
  6402. e?.currentTarget,
  6403. "third-full"
  6404. );
  6405. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  6406. onMouseleave: () => this.hideTextPopoverLater(),
  6407. }),
  6408. ]
  6409. )
  6410. );
  6411. } else {
  6412. children.push(
  6413. Vue.h(
  6414. "div",
  6415. {
  6416. class:
  6417. "ss-card-text__line ss-card-text__thirdLineWrap",
  6418. },
  6419. [
  6420. Vue.h(
  6421. "div",
  6422. {
  6423. class: "ss-card-text__thirdLine",
  6424. title: model.thirdText,
  6425. },
  6426. model.thirdText
  6427. ),
  6428. Vue.h("span", {
  6429. class: [
  6430. "ss-card-text__ellipsisHit",
  6431. "ss-card-text__ellipsisHit--third",
  6432. this.ellipsisVisible?.third ? "is-on" : "",
  6433. ],
  6434. title: "查看完整信息",
  6435. onMouseenter: (e) =>
  6436. this.showTextPopoverFor(
  6437. e?.currentTarget,
  6438. "third"
  6439. ),
  6440. onClick: (e) => {
  6441. e?.stopPropagation?.();
  6442. this.showTextPopoverFor(
  6443. e?.currentTarget,
  6444. "third"
  6445. );
  6446. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  6447. onMouseleave: () => this.hideTextPopoverLater(),
  6448. }),
  6449. ]
  6450. )
  6451. );
  6452. }
  6453. }
  6454. // hover 展开浮层:宽度=右侧文字区,底对齐向上展开,带阴影 by xu 20260108
  6455. // popover 作为 `.right` 的 sibling 渲染,避免被 `.ss-card-text{overflow:hidden}` 裁剪 by xu 20260108
  6456. const popover =
  6457. this.showTextPopover &&
  6458. Vue.h(
  6459. "div",
  6460. {
  6461. class: "ss-card-text-popover",
  6462. style: { bottom: this.textPopoverBottom + "px" },
  6463. onMouseenter: () => {
  6464. this.clearHideTextPopoverTimer();
  6465. this.showTextPopover = true;
  6466. },
  6467. onMouseleave: () => this.hideTextPopoverLater(),
  6468. },
  6469. (() => {
  6470. const p = this.textPopoverPayload || {};
  6471. if (p.kind === "second-summary" && p.text) {
  6472. return [
  6473. Vue.h(
  6474. "div",
  6475. { class: "ss-card-text-popover__summary" },
  6476. p.text
  6477. ),
  6478. ];
  6479. }
  6480. if (Array.isArray(p.lines)) {
  6481. return [
  6482. Vue.h(
  6483. "div",
  6484. { class: "ss-card-text-popover__kvlist" },
  6485. p.lines.map((t) =>
  6486. Vue.h(
  6487. "div",
  6488. { class: "ss-card-text-popover__kv" },
  6489. t
  6490. )
  6491. )
  6492. ),
  6493. ];
  6494. }
  6495. if (
  6496. (p.kind === "third" || p.kind === "third-full") &&
  6497. p.text
  6498. ) {
  6499. return [
  6500. Vue.h(
  6501. "div",
  6502. { class: "ss-card-text-popover__objno" },
  6503. p.text
  6504. ),
  6505. ];
  6506. }
  6507. return [];
  6508. })()
  6509. );
  6510. return [
  6511. Vue.h("div", { class: "ss-card-text" }, children),
  6512. popover,
  6513. ];
  6514. })()
  6515. ),
  6516. ]
  6517. ),
  6518. ]),
  6519. // 右下角卡片选择图标 by xu 20260105
  6520. this.__allowSelect()
  6521. ? Vue.h(SsIcon, {
  6522. class: this.item?._ssSelected
  6523. ? "card-icon icon-cardChk-on"
  6524. : "card-icon icon-cardChk",
  6525. onClick: this.toggleSelect,
  6526. })
  6527. : null,
  6528. // 选中后底部线条 by xu 20260105
  6529. this.__allowSelect() &&
  6530. this.item?._ssSelected &&
  6531. Vue.h("div", { class: "select-bottom-line" }),
  6532. ]
  6533. );
  6534. },
  6535. };
  6536. // 二级对象卡片:复用一级对象新卡片布局/省略浮层,但去掉勾选与 single 选中,仅支持点击查看 by xu 20260115
  6537. const SsCObjCardList = {
  6538. name: "SsCObjCardList",
  6539. props: {
  6540. ssObjName: { type: String, default: "" }, // 功能说明:业务对象名(用于默认缩略图 icon) by xu 20260115
  6541. dataType: { type: String, default: "" }, // 功能说明:页面类型(play=查看模式不显示右上角按钮) by xu 20250408
  6542. item: {
  6543. type: Object,
  6544. required: true,
  6545. },
  6546. },
  6547. emits: ["click", "change"],
  6548. setup(props, { emit }) {
  6549. const item = props.item;
  6550. const dataType = props.dataType; // 功能说明:页面类型 by xu 20250408
  6551. const cardType = Vue.computed(() => {
  6552. if (!item.thumb && !item.thumbType) return "";
  6553. return item.thumbType === "thumbnail" ? "card-thumbnail" : "card-photo";
  6554. });
  6555. const statusClass = Vue.computed(() => {
  6556. if (!item.status) return "";
  6557. const statusMap = {
  6558. available: "status-available",
  6559. unavailable: "status-unavailable",
  6560. disabled: "status-disabled",
  6561. };
  6562. return statusMap[item.status] || "";
  6563. });
  6564. const onItemClick = (e) => {
  6565. // 清除所有类型卡片的 active 状态(保持与一级对象一致) by xu 20260115
  6566. const allListCards = document.querySelectorAll(
  6567. ".knowledge-item-container"
  6568. );
  6569. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  6570. allListCards.forEach((card) => card.classList.remove("active"));
  6571. allFolderCards.forEach((card) => card.classList.remove("active"));
  6572. e.currentTarget.classList.add("active");
  6573. // 二级对象卡片:点击仅查看(调用 item.onclick) by xu 20260115
  6574. props.item.onclick?.();
  6575. emit("click", props.item);
  6576. };
  6577. const onItemChange = (e) => {
  6578. e.stopPropagation();
  6579. props.item.buttons?.[0]?.onclick?.();
  6580. };
  6581. return { item, dataType, cardType, statusClass, onItemClick, onItemChange };
  6582. },
  6583. data() {
  6584. return {
  6585. showButtons: false,
  6586. showTextPopover: false, // 功能:右侧文字区 hover 展示全量 by xu 20260115
  6587. textPopoverType: "", // second-summary / second-tags / third / third-full by xu 20260115
  6588. textPopoverBottom: 0, // 功能:popover 从当前省略行位置向上展开 by xu 20260115
  6589. hideTextPopoverTimer: null, // 功能:鼠标从省略行移到浮层的缓冲 by xu 20260115
  6590. textPopoverPayload: null, // { kind, text?, lines? } by xu 20260115
  6591. ellipsisVisible: {
  6592. secondSummary: false,
  6593. secondTags: false,
  6594. third: false,
  6595. thirdFull: false,
  6596. }, // 功能:只在真实出现 ... 时才显示命中区/允许 goheight by xu 20260115
  6597. };
  6598. },
  6599. methods: {
  6600. getBizThumbIconClass() {
  6601. // 功能:无缩略图时,用业务对象 icon 做默认图(ss-icon + icon-obj-xx) by xu 20260115
  6602. const name = String(
  6603. this.ssObjName ||
  6604. this.item?.ssObjName ||
  6605. this.$root?.ssObjName ||
  6606. window?.ss?.dom?.ssObjName ||
  6607. ""
  6608. ).trim();
  6609. if (!name) return "";
  6610. return "icon-obj-" + name;
  6611. },
  6612. buildRightTextLines() {
  6613. // 功能:沿用一级对象卡片右侧文字区规则 by xu 20260115
  6614. const item = this.item || {};
  6615. const summary = String(item?.desc ?? "").trim();
  6616. const objNum = String(item?.objNum ?? "").trim();
  6617. const categoryArr = Array.isArray(item?.category) ? item.category : [];
  6618. const tagsArr = Array.isArray(item?.tags) ? item.tags : [];
  6619. const hasTags = tagsArr.length > 0;
  6620. const hasCategory = categoryArr.length > 0;
  6621. const secondKind = summary ? "summary" : hasTags ? "tags" : "";
  6622. const hasSecond = !!secondKind;
  6623. const thirdKind = objNum ? "objNum" : hasCategory ? "category" : "";
  6624. const hasThird = !!thirdKind;
  6625. const thirdFull = !hasSecond && hasThird;
  6626. const secondFull = hasSecond && !hasThird && secondKind === "tags";
  6627. const toValueText = (obj) => {
  6628. // 功能说明:类目/物品参数回显展示 key: value(否则只显示值看不懂) by xu 20260115
  6629. const [k, v] = Object.entries(obj || {})[0] || ["", ""];
  6630. const key = k !== undefined && k !== null ? String(k).trim() : "";
  6631. const val = v !== undefined && v !== null ? String(v).trim() : "";
  6632. if (key && val) return key + ":" + val;
  6633. if (val) return val;
  6634. if (key) return key;
  6635. return "";
  6636. };
  6637. const toLineList = (arr) =>
  6638. (arr || [])
  6639. .map(toValueText)
  6640. .map((s) => String(s ?? "").trim())
  6641. .filter(Boolean);
  6642. const secondTagsMaxLines = secondFull ? 4 : 3;
  6643. const secondTagsLinesFull = toLineList(tagsArr);
  6644. const secondTagsHead = secondTagsLinesFull.slice(
  6645. 0,
  6646. Math.max(0, secondTagsMaxLines - 1)
  6647. );
  6648. const secondTagsTail = secondTagsLinesFull.slice(
  6649. Math.max(0, secondTagsMaxLines - 1)
  6650. );
  6651. const secondTagsLast =
  6652. secondTagsTail.length <= 1
  6653. ? secondTagsTail[0] || ""
  6654. : secondTagsTail.join(" ");
  6655. const categoryLinesFull = toLineList(categoryArr);
  6656. const categoryLine = categoryLinesFull.join(" ");
  6657. const thirdText =
  6658. thirdKind === "objNum"
  6659. ? objNum
  6660. : thirdKind === "category"
  6661. ? categoryLine
  6662. : "";
  6663. return {
  6664. secondKind,
  6665. thirdKind,
  6666. hasSecond,
  6667. hasThird,
  6668. thirdFull,
  6669. secondFull,
  6670. summary,
  6671. secondTagsMaxLines,
  6672. secondTagsHead,
  6673. secondTagsLast,
  6674. secondTagsLinesFull,
  6675. objNum,
  6676. categoryLine,
  6677. categoryLinesFull,
  6678. thirdText,
  6679. };
  6680. },
  6681. measureTextOverflowByLines(text, maxLines, width) {
  6682. const w = Number(width) || 0;
  6683. if (!w || !text) return false;
  6684. const probe = document.createElement("div");
  6685. probe.style.position = "fixed";
  6686. probe.style.left = "-99999px";
  6687. probe.style.top = "0";
  6688. probe.style.width = w + "px";
  6689. probe.style.fontSize = "18px";
  6690. probe.style.lineHeight = "24px";
  6691. probe.style.whiteSpace = "normal";
  6692. probe.style.wordBreak = "break-word";
  6693. probe.style.visibility = "hidden";
  6694. probe.textContent = text;
  6695. document.body.appendChild(probe);
  6696. const h = probe.getBoundingClientRect().height || 0;
  6697. document.body.removeChild(probe);
  6698. return h > maxLines * 24 + 1;
  6699. },
  6700. measureSingleLineOverflow(text, width) {
  6701. const w = Number(width) || 0;
  6702. if (!w || !text) return false;
  6703. const probe = document.createElement("span");
  6704. probe.style.position = "fixed";
  6705. probe.style.left = "-99999px";
  6706. probe.style.top = "0";
  6707. probe.style.display = "inline-block";
  6708. probe.style.maxWidth = w + "px";
  6709. probe.style.fontSize = "18px";
  6710. probe.style.lineHeight = "24px";
  6711. probe.style.whiteSpace = "nowrap";
  6712. probe.style.visibility = "hidden";
  6713. probe.textContent = text;
  6714. document.body.appendChild(probe);
  6715. const overflow =
  6716. (probe.scrollWidth || 0) > (probe.clientWidth || w) + 1;
  6717. document.body.removeChild(probe);
  6718. return overflow;
  6719. },
  6720. refreshEllipsisVisible() {
  6721. // 功能:刷新「是否出现 ...」状态(用于控制命中区显示) by xu 20260115
  6722. try {
  6723. const right = this.$el?.querySelector?.(".right");
  6724. const rawWidth =
  6725. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  6726. const width = Math.max(0, Math.round(rawWidth));
  6727. const model = this.buildRightTextLines();
  6728. const next = {
  6729. secondSummary: false,
  6730. secondTags: false,
  6731. third: false,
  6732. thirdFull: false,
  6733. };
  6734. if (model.secondKind === "summary" && model.summary) {
  6735. next.secondSummary = this.measureTextOverflowByLines(
  6736. model.summary,
  6737. 3,
  6738. width
  6739. );
  6740. }
  6741. if (model.secondKind === "tags") {
  6742. next.secondTags = this.measureSingleLineOverflow(
  6743. model.secondTagsLast,
  6744. width
  6745. ); // 功能说明:tags 仅看最后一行是否溢出 by xu 20260115
  6746. }
  6747. if (model.hasThird && !model.thirdFull) {
  6748. next.third = this.measureSingleLineOverflow(model.thirdText, width);
  6749. }
  6750. if (model.hasThird && model.thirdFull) {
  6751. next.thirdFull = this.measureTextOverflowByLines(
  6752. model.thirdText,
  6753. 4,
  6754. width
  6755. );
  6756. }
  6757. const prev = this.ellipsisVisible || {};
  6758. const changed =
  6759. prev.secondSummary !== next.secondSummary ||
  6760. prev.secondTags !== next.secondTags ||
  6761. prev.third !== next.third ||
  6762. prev.thirdFull !== next.thirdFull;
  6763. if (changed) this.ellipsisVisible = next;
  6764. } catch (e) {
  6765. // ignore by xu 20260115
  6766. }
  6767. },
  6768. clearHideTextPopoverTimer() {
  6769. if (this.hideTextPopoverTimer) {
  6770. clearTimeout(this.hideTextPopoverTimer);
  6771. this.hideTextPopoverTimer = null;
  6772. }
  6773. },
  6774. hideTextPopoverLater() {
  6775. this.clearHideTextPopoverTimer();
  6776. this.hideTextPopoverTimer = setTimeout(() => {
  6777. this.showTextPopover = false;
  6778. this.textPopoverType = "";
  6779. this.textPopoverPayload = null;
  6780. }, 120);
  6781. },
  6782. showTextPopoverFor(el, kind) {
  6783. const model = this.buildRightTextLines();
  6784. const lineEl = el?.closest?.(".ss-card-text__line") || el;
  6785. const right = lineEl?.closest?.(".right") || el?.closest?.(".right");
  6786. const rawWidth =
  6787. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  6788. const width = Math.max(0, Math.round(rawWidth));
  6789. const overflowed =
  6790. kind === "second-summary"
  6791. ? this.measureTextOverflowByLines(model.summary, 3, width)
  6792. : kind === "second-tags"
  6793. ? this.measureSingleLineOverflow(model.secondTagsLast, width)
  6794. : kind === "third"
  6795. ? this.measureSingleLineOverflow(model.thirdText, width)
  6796. : this.measureTextOverflowByLines(model.thirdText, 4, width);
  6797. if (!overflowed) return;
  6798. let payload = null;
  6799. if (kind === "second-summary") {
  6800. if (model.summary) payload = { kind, text: model.summary };
  6801. } else if (kind === "second-tags") {
  6802. if (
  6803. Array.isArray(model.secondTagsLinesFull) &&
  6804. model.secondTagsLinesFull.length
  6805. ) {
  6806. payload = { kind, lines: model.secondTagsLinesFull };
  6807. }
  6808. } else if (kind === "third") {
  6809. if (
  6810. model.thirdKind === "category" &&
  6811. Array.isArray(model.categoryLinesFull) &&
  6812. model.categoryLinesFull.length
  6813. ) {
  6814. payload = { kind, lines: model.categoryLinesFull };
  6815. } else if (model.thirdText) {
  6816. payload = { kind, text: model.thirdText };
  6817. }
  6818. } else if (kind === "third-full") {
  6819. if (
  6820. model.thirdKind === "category" &&
  6821. Array.isArray(model.categoryLinesFull) &&
  6822. model.categoryLinesFull.length
  6823. ) {
  6824. payload = { kind, lines: model.categoryLinesFull };
  6825. } else if (model.thirdText) {
  6826. payload = { kind, text: model.thirdText };
  6827. }
  6828. }
  6829. if (!payload) return;
  6830. this.clearHideTextPopoverTimer();
  6831. const container = lineEl?.closest?.(".right");
  6832. const containerRect = container?.getBoundingClientRect?.();
  6833. const lineRect = lineEl?.getBoundingClientRect?.();
  6834. if (containerRect && lineRect) {
  6835. const bottom = Math.max(
  6836. 0,
  6837. Math.round(containerRect.bottom - lineRect.bottom)
  6838. );
  6839. this.textPopoverBottom = bottom;
  6840. } else {
  6841. this.textPopoverBottom = 0;
  6842. }
  6843. this.textPopoverPayload = payload;
  6844. this.textPopoverType = kind;
  6845. this.showTextPopover = true;
  6846. },
  6847. },
  6848. mounted() {
  6849. this.$nextTick?.(() => {
  6850. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  6851. });
  6852. this.__ssCObjCardResizeHandler = () => this.refreshEllipsisVisible?.(); // 功能说明:窗口变化时刷新 ... 显示 by xu 20260115
  6853. window.addEventListener?.("resize", this.__ssCObjCardResizeHandler);
  6854. },
  6855. updated() {
  6856. this.$nextTick?.(() => {
  6857. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  6858. });
  6859. },
  6860. beforeUnmount() {
  6861. this.clearHideTextPopoverTimer?.();
  6862. if (this.__ssCObjCardResizeHandler) {
  6863. window.removeEventListener?.("resize", this.__ssCObjCardResizeHandler);
  6864. this.__ssCObjCardResizeHandler = null;
  6865. }
  6866. },
  6867. render() {
  6868. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  6869. const SsIcon = Vue.resolveComponent("ss-icon");
  6870. const hasThumbArea = !!(this.item?.thumb || this.item?.thumbType);
  6871. const thumbSrc = (() => {
  6872. // 功能说明:兼容 thumb 为 raw path 或 {val}/{value},组件内统一转为 dlByHttp URL by xu 20260122
  6873. const t = this.item?.thumb;
  6874. if (!t) return "";
  6875. if (typeof t === "string") {
  6876. const s = t.trim();
  6877. if (!s) return "";
  6878. if (
  6879. /^https?:\/\//i.test(s) ||
  6880. s.startsWith("/service?") ||
  6881. s.startsWith("/")
  6882. )
  6883. return s;
  6884. return buildThumbUrl(s);
  6885. }
  6886. return buildThumbUrl(t);
  6887. })();
  6888. return Vue.h(
  6889. "div",
  6890. {
  6891. class: {
  6892. "knowledge-item-container": true,
  6893. active: this.item.active,
  6894. [this.cardType]: !!this.cardType,
  6895. [this.statusClass]: !!this.statusClass,
  6896. },
  6897. onClick: (e) => this.onItemClick?.(e), // 功能说明:二级对象卡片点击仅查看 by xu 20260115
  6898. },
  6899. [
  6900. this.item?.statusIcons?.length > 0 &&
  6901. Vue.h(
  6902. "div",
  6903. { class: "card-status-icons" },
  6904. this.item.statusIcons.map((icon) =>
  6905. Vue.h(SsIcon, {
  6906. class: "status-icon " + icon.class,
  6907. title: icon.title,
  6908. })
  6909. )
  6910. ),
  6911. this.item?.buttons?.length > 0 && this.dataType !== "play" &&
  6912. Vue.h(
  6913. "div",
  6914. {
  6915. class: "header",
  6916. style:
  6917. this.item?.statusIcons?.length > 0
  6918. ? {
  6919. right: String(this.item.statusIcons.length * 48) + "px",
  6920. borderTopRightRadius: "0",
  6921. }
  6922. : {},
  6923. onMouseenter: () => (this.showButtons = true),
  6924. onMouseleave: () => (this.showButtons = false),
  6925. onClick: (e) => this.onItemChange(e),
  6926. },
  6927. [
  6928. Vue.h("div", {
  6929. class: "cart-list-setting cart-list-icon",
  6930. title: this.item?.buttons?.[0]?.title,
  6931. }),
  6932. this.showButtons &&
  6933. this.item?.buttons?.length > 1 &&
  6934. Vue.h(
  6935. "div",
  6936. { class: "cart-list-button-popup" },
  6937. this.item.buttons.map((btn) =>
  6938. Vue.h(
  6939. "div",
  6940. {
  6941. onClick: (e) => {
  6942. e.stopPropagation();
  6943. btn.onclick?.();
  6944. },
  6945. },
  6946. [
  6947. btn.class &&
  6948. Vue.h(SsCartListIcon, { class: [btn.class] }),
  6949. Vue.h("span", null, btn.title),
  6950. ]
  6951. )
  6952. )
  6953. ),
  6954. ]
  6955. ),
  6956. Vue.h("div", { class: "body" }, [
  6957. Vue.h("div", { class: "box-header" }, [
  6958. Vue.h("div", String(this.item.title || "")),
  6959. ]),
  6960. Vue.h(
  6961. "div",
  6962. { class: !hasThumbArea ? "no-thumb box-body" : "box-body" },
  6963. [
  6964. hasThumbArea
  6965. ? thumbSrc
  6966. ? Vue.h("div", { class: "left" }, [
  6967. Vue.h("img", {
  6968. src: thumbSrc,
  6969. alt: "Thumbnail",
  6970. class: "imgUnHandle",
  6971. style: {
  6972. "object-fit": "cover",
  6973. width: "100%",
  6974. height: "100%",
  6975. },
  6976. }),
  6977. ])
  6978. : Vue.h(
  6979. "div",
  6980. { class: "left ss-objlist-thumbPlaceholder" },
  6981. [
  6982. Vue.h(SsIcon, {
  6983. class:
  6984. this.getBizThumbIconClass() +
  6985. " ss-objlist-thumbIcon",
  6986. }),
  6987. ]
  6988. )
  6989. : null,
  6990. Vue.h(
  6991. "div",
  6992. { class: "right" },
  6993. (() => {
  6994. const model = this.buildRightTextLines();
  6995. const hasAny = !!(model?.hasSecond || model?.hasThird);
  6996. if (!hasAny) return [];
  6997. const children = [];
  6998. if (model.hasSecond && model.secondKind === "summary") {
  6999. children.push(
  7000. Vue.h(
  7001. "div",
  7002. {
  7003. class:
  7004. "ss-card-text__line ss-card-text__secondBlock",
  7005. },
  7006. [
  7007. Vue.h(
  7008. "div",
  7009. {
  7010. class: "ss-card-text__secondSummary",
  7011. title: model.summary,
  7012. },
  7013. model.summary
  7014. ),
  7015. Vue.h("span", {
  7016. class: [
  7017. "ss-card-text__ellipsisHit",
  7018. "ss-card-text__ellipsisHit--second",
  7019. this.ellipsisVisible?.secondSummary
  7020. ? "is-on"
  7021. : "",
  7022. ],
  7023. title: "查看完整信息",
  7024. onMouseenter: (e) =>
  7025. this.showTextPopoverFor(
  7026. e?.currentTarget,
  7027. "second-summary"
  7028. ),
  7029. onClick: (e) => {
  7030. e?.stopPropagation?.();
  7031. this.showTextPopoverFor(
  7032. e?.currentTarget,
  7033. "second-summary"
  7034. );
  7035. },
  7036. onMouseleave: () => this.hideTextPopoverLater(),
  7037. }),
  7038. ]
  7039. )
  7040. );
  7041. }
  7042. if (model.hasSecond && model.secondKind === "tags") {
  7043. children.push(
  7044. Vue.h(
  7045. "div",
  7046. {
  7047. class: [
  7048. "ss-card-text__line",
  7049. model.secondFull
  7050. ? "ss-card-text__secondFullBlock"
  7051. : "ss-card-text__secondBlock",
  7052. ],
  7053. },
  7054. [
  7055. Vue.h(
  7056. "div",
  7057. { class: "ss-card-text__secondTags" },
  7058. [
  7059. ...model.secondTagsHead.map((t) =>
  7060. Vue.h(
  7061. "div",
  7062. {
  7063. class: "ss-card-text__tagLine",
  7064. title: t,
  7065. },
  7066. t
  7067. )
  7068. ),
  7069. Vue.h(
  7070. "div",
  7071. {
  7072. class:
  7073. "ss-card-text__tagLine is-last ss-card-text__tagLineLast",
  7074. title: model.secondTagsLast,
  7075. },
  7076. model.secondTagsLast
  7077. ),
  7078. ]
  7079. ),
  7080. Vue.h("span", {
  7081. class: [
  7082. "ss-card-text__ellipsisHit",
  7083. "ss-card-text__ellipsisHit--second",
  7084. this.ellipsisVisible?.secondTags ? "is-on" : "",
  7085. ],
  7086. title: "查看完整信息",
  7087. onMouseenter: (e) =>
  7088. this.showTextPopoverFor(
  7089. e?.currentTarget,
  7090. "second-tags"
  7091. ),
  7092. onClick: (e) => {
  7093. e?.stopPropagation?.();
  7094. this.showTextPopoverFor(
  7095. e?.currentTarget,
  7096. "second-tags"
  7097. );
  7098. },
  7099. onMouseleave: () => this.hideTextPopoverLater(),
  7100. }),
  7101. ]
  7102. )
  7103. );
  7104. }
  7105. if (model.hasThird) {
  7106. if (model.thirdFull) {
  7107. children.push(
  7108. Vue.h(
  7109. "div",
  7110. {
  7111. class:
  7112. "ss-card-text__line ss-card-text__thirdFullBlock",
  7113. },
  7114. [
  7115. Vue.h(
  7116. "div",
  7117. {
  7118. class: "ss-card-text__thirdFull",
  7119. title: model.thirdText,
  7120. },
  7121. model.thirdText
  7122. ),
  7123. Vue.h("span", {
  7124. class: [
  7125. "ss-card-text__ellipsisHit",
  7126. "ss-card-text__ellipsisHit--third",
  7127. this.ellipsisVisible?.thirdFull
  7128. ? "is-on"
  7129. : "",
  7130. ],
  7131. title: "查看完整信息",
  7132. onMouseenter: (e) =>
  7133. this.showTextPopoverFor(
  7134. e?.currentTarget,
  7135. "third-full"
  7136. ),
  7137. onClick: (e) => {
  7138. e?.stopPropagation?.();
  7139. this.showTextPopoverFor(
  7140. e?.currentTarget,
  7141. "third-full"
  7142. );
  7143. },
  7144. onMouseleave: () => this.hideTextPopoverLater(),
  7145. }),
  7146. ]
  7147. )
  7148. );
  7149. } else {
  7150. children.push(
  7151. Vue.h(
  7152. "div",
  7153. {
  7154. class:
  7155. "ss-card-text__line ss-card-text__thirdLineWrap",
  7156. },
  7157. [
  7158. Vue.h(
  7159. "div",
  7160. {
  7161. class: "ss-card-text__thirdLine",
  7162. title: model.thirdText,
  7163. },
  7164. model.thirdText
  7165. ),
  7166. Vue.h("span", {
  7167. class: [
  7168. "ss-card-text__ellipsisHit",
  7169. "ss-card-text__ellipsisHit--third",
  7170. this.ellipsisVisible?.third ? "is-on" : "",
  7171. ],
  7172. title: "查看完整信息",
  7173. onMouseenter: (e) =>
  7174. this.showTextPopoverFor(
  7175. e?.currentTarget,
  7176. "third"
  7177. ),
  7178. onClick: (e) => {
  7179. e?.stopPropagation?.();
  7180. this.showTextPopoverFor(
  7181. e?.currentTarget,
  7182. "third"
  7183. );
  7184. },
  7185. onMouseleave: () => this.hideTextPopoverLater(),
  7186. }),
  7187. ]
  7188. )
  7189. );
  7190. }
  7191. }
  7192. const popover =
  7193. this.showTextPopover &&
  7194. Vue.h(
  7195. "div",
  7196. {
  7197. class: "ss-card-text-popover",
  7198. style: { bottom: this.textPopoverBottom + "px" },
  7199. onMouseenter: () => {
  7200. this.clearHideTextPopoverTimer();
  7201. this.showTextPopover = true;
  7202. },
  7203. onMouseleave: () => this.hideTextPopoverLater(),
  7204. },
  7205. (() => {
  7206. const p = this.textPopoverPayload || {};
  7207. if (p.kind === "second-summary" && p.text) {
  7208. return [
  7209. Vue.h(
  7210. "div",
  7211. { class: "ss-card-text-popover__summary" },
  7212. p.text
  7213. ),
  7214. ];
  7215. }
  7216. if (Array.isArray(p.lines)) {
  7217. return [
  7218. Vue.h(
  7219. "div",
  7220. { class: "ss-card-text-popover__kvlist" },
  7221. p.lines.map((t) =>
  7222. Vue.h(
  7223. "div",
  7224. { class: "ss-card-text-popover__kv" },
  7225. t
  7226. )
  7227. )
  7228. ),
  7229. ];
  7230. }
  7231. if (
  7232. (p.kind === "third" || p.kind === "third-full") &&
  7233. p.text
  7234. ) {
  7235. return [
  7236. Vue.h(
  7237. "div",
  7238. { class: "ss-card-text-popover__objno" },
  7239. p.text
  7240. ),
  7241. ];
  7242. }
  7243. return [];
  7244. })()
  7245. );
  7246. return [
  7247. Vue.h("div", { class: "ss-card-text" }, children),
  7248. popover,
  7249. ];
  7250. })()
  7251. ),
  7252. ]
  7253. ),
  7254. ]),
  7255. ]
  7256. );
  7257. },
  7258. };
  7259. // ss-sidebar 右侧边栏(容器 + 子组件),用于 objList 右侧区域 by xu 20260106
  7260. // 组件文档补全(JSDoc) by xu 20260108
  7261. /**
  7262. * SsSidebarButtons(右侧边栏顶部按钮栏)
  7263. *
  7264. * 用途:
  7265. * - 渲染 objList 右侧顶部快捷操作(预定/入住/退房/清洁...)
  7266. * - 内部复用 `ss-search-button`(项目现有按钮样式/交互)
  7267. *
  7268. * 调用示例:
  7269. * ```html
  7270. * <ss-sidebar-buttons :items="sidebarButtons" />
  7271. * ```
  7272. *
  7273. * Props:
  7274. * - `items`: 按钮配置数组
  7275. * - `{ id, text, icon?, onClick? }`
  7276. *
  7277. * Emits:
  7278. * - `click`:点击按钮时触发,参数为按钮对象
  7279. */
  7280. const SsSidebarButtons = {
  7281. name: "SsSidebarButtons",
  7282. props: {
  7283. items: { type: Array, default: () => [] },
  7284. },
  7285. emits: ["click"],
  7286. render() {
  7287. const SsSearchButton = Vue.resolveComponent("ss-search-button");
  7288. const items = this.items || [];
  7289. if (!items.length) return null;
  7290. return Vue.h(
  7291. "div",
  7292. { class: "ss-sidebar-actions" },
  7293. items.map((btn) =>
  7294. // 顶部操作按钮复用 ss-search-button(先 mock 固定按钮) by xu 20260106
  7295. Vue.h(SsSearchButton, {
  7296. text: btn?.text ?? "",
  7297. iconClass: btn?.iconClass ?? "",
  7298. opt: btn?.opt ?? [],
  7299. checkId: btn?.checkId ?? "0",
  7300. width: btn?.width,
  7301. id: btn?.id,
  7302. onClick: (e) => {
  7303. e?.stopPropagation?.();
  7304. btn?.onClick?.(btn);
  7305. this.$emit("click", btn);
  7306. },
  7307. })
  7308. )
  7309. );
  7310. },
  7311. };
  7312. // 组件文档补全(JSDoc) by xu 20260108
  7313. /**
  7314. * SsSidebarChart(ECharts 容器渲染)
  7315. *
  7316. * 用途:
  7317. * - 仅负责 echarts init / setOption / resize / dispose
  7318. * - 被 `ss-sidebar-chart-hover` 与图表面板复用
  7319. *
  7320. * 调用示例:
  7321. * ```html
  7322. * <ss-sidebar-chart :options="option" height="220px" />
  7323. * ```
  7324. *
  7325. * Props:
  7326. * - `options`:ECharts option(Object)
  7327. * - `height`:容器高度(String)
  7328. */
  7329. const SsSidebarChart = {
  7330. name: "SsSidebarChart",
  7331. props: {
  7332. options: { type: Object, default: () => ({}) },
  7333. height: { type: String, default: "200px" },
  7334. },
  7335. setup(props) {
  7336. const elRef = Vue.ref(null);
  7337. let chart = null;
  7338. const renderChart = () => {
  7339. if (!elRef.value || !window.echarts) return;
  7340. if (!chart) {
  7341. chart = window.echarts.init(elRef.value);
  7342. }
  7343. chart.setOption(props.options || {}, true);
  7344. };
  7345. const resizeChart = () => {
  7346. chart?.resize?.();
  7347. };
  7348. Vue.onMounted(() => {
  7349. renderChart();
  7350. window.addEventListener("resize", resizeChart);
  7351. });
  7352. Vue.onBeforeUnmount(() => {
  7353. window.removeEventListener("resize", resizeChart);
  7354. chart?.dispose?.();
  7355. chart = null;
  7356. });
  7357. Vue.watch(
  7358. () => props.options,
  7359. () => {
  7360. renderChart();
  7361. },
  7362. { deep: true }
  7363. );
  7364. return { elRef };
  7365. },
  7366. render() {
  7367. return Vue.h("div", {
  7368. ref: "elRef",
  7369. style: {
  7370. width: "100%",
  7371. height: this.height,
  7372. // 图表容器不加 padding/border,由外层布局控制 by xu 20260106
  7373. background: "transparent",
  7374. border: "none",
  7375. "border-radius": "0",
  7376. },
  7377. });
  7378. },
  7379. };
  7380. // ss-sidebar-chart-hover:hover 弹出左侧大图(支持图钉/全屏) by xu 20260106
  7381. // 组件文档补全(JSDoc) by xu 20260108
  7382. /**
  7383. * SsSidebarChartHover(小图 + hover 左侧大图预览 + 图钉固定 + 全屏)
  7384. *
  7385. * 用途:
  7386. * - 右侧统计图小卡片:hover 时在左侧弹出大图预览
  7387. * - 预览头部:左侧图标+标题;右侧固定/全屏按钮(icon-base)
  7388. * - 全屏:方案A(浏览器 Fullscreen API)
  7389. *
  7390. * 调用示例(由 ss-sidebar chart panel 内部调用):
  7391. * ```html
  7392. * <ss-sidebar-chart-hover
  7393. * title="校舍建筑面积和总体分布"
  7394. * icon-class="menu-icon icon-obj-jzw"
  7395. * :options="option"
  7396. * height="220px"
  7397. * />
  7398. * ```
  7399. *
  7400. * Props:
  7401. * - `title/iconClass/icon`:用于预览/全屏 header 显示(与面板 header 一致)
  7402. * - `options`:ECharts option
  7403. * - `height`:小图高度
  7404. * - `previewWidth/previewHeight`:预览建议尺寸(会按视口自适应)
  7405. */
  7406. const SsSidebarChartHover = {
  7407. name: "SsSidebarChartHover",
  7408. props: {
  7409. // hover 大图标题/图标(与小图面板 header 一致) by xu 20260108
  7410. title: { type: String, default: "" },
  7411. iconClass: { type: String, default: "" },
  7412. icon: { type: String, default: "" },
  7413. options: { type: Object, default: () => ({}) },
  7414. height: { type: String, default: "220px" },
  7415. // hover 弹窗建议尺寸:默认 1000x650(比例由逻辑统一管控),实际渲染会按比例自适应视口 by xu 20260115
  7416. previewWidth: { type: Number, default: 1000 },
  7417. previewHeight: { type: Number, default: 650 },
  7418. },
  7419. setup(props) {
  7420. const triggerRef = Vue.ref(null);
  7421. const fullscreenRef = Vue.ref(null);
  7422. const open = Vue.ref(false);
  7423. const pinned = Vue.ref(false);
  7424. const fullscreen = Vue.ref(false);
  7425. const hoveringTrigger = Vue.ref(false);
  7426. const hoveringPreview = Vue.ref(false);
  7427. const previewStyle = Vue.ref({});
  7428. let closeTimer = null;
  7429. const updatePreviewPosition = () => {
  7430. const el = triggerRef.value;
  7431. if (!el) return;
  7432. const rect = el.getBoundingClientRect();
  7433. // 功能说明:优先使用 visualViewport(避免浏览器 UI/缩放导致可视区与 innerHeight 偏差,出现预览被遮挡约 70px) by xu 20260116
  7434. const docEl = document.documentElement;
  7435. const vv = window.visualViewport;
  7436. let viewportLeft = Number(vv?.offsetLeft ?? 0) || 0;
  7437. let viewportTop = Number(vv?.offsetTop ?? 0) || 0;
  7438. let vw =
  7439. Number(vv?.width ?? 0) ||
  7440. Number(docEl?.clientWidth || 0) ||
  7441. window.innerWidth;
  7442. let vh =
  7443. Number(vv?.height ?? 0) ||
  7444. Number(docEl?.clientHeight || 0) ||
  7445. window.innerHeight;
  7446. // 功能说明:若页面在 iframe 内,父页面可能裁切 iframe 可见区域(overflow/弹窗容器),需要用“iframe可见区域”做二次约束 by xu 20260116
  7447. try {
  7448. const inIframe = window.top && window.top !== window;
  7449. const frameEl = window.frameElement;
  7450. if (inIframe && frameEl && window.top?.document) {
  7451. const topVv = window.top.visualViewport;
  7452. const topDocEl = window.top.document.documentElement;
  7453. const topVw =
  7454. Number(topVv?.width ?? 0) ||
  7455. Number(topDocEl?.clientWidth || 0) ||
  7456. window.top.innerWidth;
  7457. const topVh =
  7458. Number(topVv?.height ?? 0) ||
  7459. Number(topDocEl?.clientHeight || 0) ||
  7460. window.top.innerHeight;
  7461. const fr = frameEl.getBoundingClientRect?.();
  7462. if (fr && fr.width > 0 && fr.height > 0) {
  7463. const visibleW = Math.max(
  7464. 0,
  7465. Math.min(fr.right, topVw) - Math.max(fr.left, 0)
  7466. );
  7467. const visibleH = Math.max(
  7468. 0,
  7469. Math.min(fr.bottom, topVh) - Math.max(fr.top, 0)
  7470. );
  7471. if (visibleW > 0) {
  7472. vw = Math.min(vw, visibleW);
  7473. viewportLeft = Math.max(0, -fr.left); // iframe内坐标系偏移(左侧被裁切时) by xu 20260116
  7474. }
  7475. if (visibleH > 0) {
  7476. vh = Math.min(vh, visibleH);
  7477. viewportTop = Math.max(0, -fr.top); // iframe内坐标系偏移(顶部被裁切时) by xu 20260116
  7478. }
  7479. }
  7480. }
  7481. } catch (_) {}
  7482. // 预览窗尺寸:优先保证“完整可见”,其次再尽量对齐右侧 header 顶部 by xu 20260116
  7483. const viewportPaddingX = 40;
  7484. const viewportPaddingTop = 20;
  7485. const viewportPaddingBottom = 10;
  7486. // 功能说明:hover 预览框不要覆盖右侧栏,优先放在 ss-sidebar 左侧;必要时动态缩小宽度 by xu 20260115
  7487. const sidebarEl = el.closest ? el.closest(".ss-sidebar") : null;
  7488. const sidebarRect = sidebarEl?.getBoundingClientRect?.();
  7489. const maxWidthByViewport = Math.max(240, vw - viewportPaddingX);
  7490. const maxWidthByLeftSpace = sidebarRect
  7491. ? Math.max(
  7492. 240,
  7493. sidebarRect.left - viewportPaddingX - 14 /* gapFromSidebar */
  7494. )
  7495. : maxWidthByViewport;
  7496. // 功能说明:预览框尺寸按比例(默认 5:3)缩放,并提供最大/最小值约束 by xu 20260115
  7497. const ratio = 3 / 5;
  7498. const minWidth = 320;
  7499. const minHeight = 240;
  7500. const maxHeightByViewport = Math.max(
  7501. minHeight,
  7502. vh - viewportPaddingTop - viewportPaddingBottom
  7503. );
  7504. const maxWidthByProp = Number(props.previewWidth) || 1000;
  7505. const maxHeightByProp = Number(props.previewHeight) || 650;
  7506. // 优先按高度撑满可视区(保证预览完整可见),再根据左侧可用宽度回退 by xu 20260116
  7507. const maxHeight = Math.min(maxHeightByProp, maxHeightByViewport);
  7508. let height = Math.max(minHeight, maxHeight);
  7509. let width = Math.round(height / ratio);
  7510. width = Math.min(
  7511. width,
  7512. maxWidthByProp,
  7513. maxWidthByViewport,
  7514. maxWidthByLeftSpace
  7515. );
  7516. width = Math.max(minWidth, width);
  7517. height = Math.round(width * ratio);
  7518. if (height > maxHeight) {
  7519. height = maxHeight;
  7520. width = Math.round(height / ratio);
  7521. }
  7522. // 默认贴着小图左侧弹出,右边缘与小图左边缘轻微重叠,避免 1px 缝隙导致 hover 闪断 by xu 20260108
  7523. const overlap = 2;
  7524. const gapFromSidebar = 14; // 功能说明:弹窗与右侧边栏留出距离(更不贴近) by xu 20260108
  7525. // 优先:贴在 sidebar 左侧(不压住右侧栏内容) by xu 20260115
  7526. let left = sidebarRect
  7527. ? sidebarRect.left - gapFromSidebar - width + overlap
  7528. : rect.left - width - gapFromSidebar + overlap;
  7529. // 如果左侧空间不足,则贴右侧(兜底,同样重叠) by xu 20260108
  7530. if (left < 0) left = rect.right + gapFromSidebar - overlap;
  7531. left = Math.max(
  7532. viewportLeft,
  7533. Math.min(left, viewportLeft + vw - width)
  7534. );
  7535. // top:优先保证完整可见,然后才贴近 header 顶部 by xu 20260116
  7536. let headerEl = el;
  7537. while (headerEl && !headerEl.classList?.contains("ss-sidebar-panel")) {
  7538. headerEl = headerEl.parentElement;
  7539. }
  7540. let headerRect = headerEl
  7541. ?.querySelector(".ss-sidebar-panel__header")
  7542. ?.getBoundingClientRect();
  7543. let top = headerRect?.top ?? rect.top;
  7544. top = Math.max(
  7545. viewportTop + viewportPaddingTop,
  7546. Math.min(top, viewportTop + vh - height - viewportPaddingBottom)
  7547. );
  7548. previewStyle.value = {
  7549. position: "fixed",
  7550. left: `${Math.round(left)}px`,
  7551. top: `${Math.round(top)}px`,
  7552. width: `${width}px`,
  7553. height: `${height}px`,
  7554. zIndex: 2147483647, // 功能说明:提高层级到接近浏览器上限,避免仍被页面固定栏/弹窗遮挡 by xu 20260116
  7555. };
  7556. };
  7557. const clearCloseTimer = () => {
  7558. if (closeTimer) {
  7559. clearTimeout(closeTimer);
  7560. closeTimer = null;
  7561. }
  7562. };
  7563. const scheduleClose = () => {
  7564. clearCloseTimer();
  7565. if (pinned.value || fullscreen.value) return;
  7566. if (hoveringTrigger.value || hoveringPreview.value) return; // 功能:鼠标在小图/大图之间移动不关闭 by xu 20260108
  7567. closeTimer = setTimeout(() => {
  7568. open.value = false;
  7569. }, 100);
  7570. };
  7571. const openPreview = () => {
  7572. clearCloseTimer();
  7573. updatePreviewPosition();
  7574. open.value = true;
  7575. };
  7576. const togglePin = () => {
  7577. pinned.value = !pinned.value;
  7578. if (pinned.value) {
  7579. open.value = true;
  7580. updatePreviewPosition();
  7581. }
  7582. };
  7583. const toggleFullscreen = () => {
  7584. // 全屏:采用浏览器 Fullscreen API(方案A),不使用遮罩弹窗 by xu 20260108
  7585. if (!fullscreen.value) {
  7586. open.value = false; // 避免同时渲染预览与全屏 by xu 20260108
  7587. fullscreen.value = true;
  7588. Vue.nextTick(() => {
  7589. const el = fullscreenRef.value;
  7590. if (el?.requestFullscreen) {
  7591. el.requestFullscreen().catch(() => {
  7592. // requestFullscreen 失败则回退为非全屏状态 by xu 20260108
  7593. fullscreen.value = false;
  7594. });
  7595. } else {
  7596. fullscreen.value = false;
  7597. }
  7598. });
  7599. } else {
  7600. if (document?.exitFullscreen) {
  7601. document.exitFullscreen().catch(() => {});
  7602. }
  7603. }
  7604. };
  7605. const handleFullscreenChange = () => {
  7606. const isFs = !!document.fullscreenElement;
  7607. fullscreen.value = isFs; // 功能说明:同步 ESC/系统退出全屏状态 by xu 20260108
  7608. if (isFs) {
  7609. open.value = false;
  7610. clearCloseTimer();
  7611. return;
  7612. }
  7613. // 退出全屏后:若固定或仍 hover,则恢复预览,否则关闭 by xu 20260108
  7614. if (pinned.value || hoveringTrigger.value || hoveringPreview.value) {
  7615. open.value = true;
  7616. updatePreviewPosition();
  7617. } else {
  7618. open.value = false;
  7619. }
  7620. };
  7621. Vue.onMounted(() => {
  7622. window.addEventListener("resize", updatePreviewPosition);
  7623. window.addEventListener("scroll", updatePreviewPosition, true);
  7624. document.addEventListener("fullscreenchange", handleFullscreenChange); // 功能说明:监听全屏状态变化 by xu 20260108
  7625. });
  7626. Vue.onBeforeUnmount(() => {
  7627. clearCloseTimer();
  7628. window.removeEventListener("resize", updatePreviewPosition);
  7629. window.removeEventListener("scroll", updatePreviewPosition, true);
  7630. document.removeEventListener(
  7631. "fullscreenchange",
  7632. handleFullscreenChange
  7633. );
  7634. });
  7635. return {
  7636. triggerRef,
  7637. fullscreenRef,
  7638. open,
  7639. pinned,
  7640. fullscreen,
  7641. hoveringTrigger,
  7642. hoveringPreview,
  7643. previewStyle,
  7644. openPreview,
  7645. scheduleClose,
  7646. clearCloseTimer,
  7647. togglePin,
  7648. toggleFullscreen,
  7649. };
  7650. },
  7651. render() {
  7652. const SsIcon = Vue.resolveComponent("ss-icon");
  7653. const Chart = Vue.resolveComponent("ss-sidebar-chart");
  7654. const hasHeader = !!(this.title || this.iconClass || this.icon); // 功能:hover 大图显示左侧图标+标题 by xu 20260108
  7655. const previewContent = Vue.h(
  7656. "div",
  7657. {
  7658. class: { "ss-sidebar-chart-preview": true, "is-pinned": this.pinned },
  7659. style: this.previewStyle,
  7660. onMouseenter: () => {
  7661. this.hoveringPreview = true;
  7662. this.clearCloseTimer();
  7663. },
  7664. onMouseleave: () => {
  7665. this.hoveringPreview = false;
  7666. this.scheduleClose();
  7667. },
  7668. },
  7669. [
  7670. hasHeader
  7671. ? Vue.h(
  7672. "div",
  7673. {
  7674. class:
  7675. "ss-sidebar-panel__header ss-sidebar-chart-preview__header",
  7676. },
  7677. [
  7678. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7679. this.iconClass
  7680. ? Vue.h(SsIcon, {
  7681. class: this.iconClass + " ss-sidebar-panel__icon",
  7682. })
  7683. : this.icon
  7684. ? Vue.h(SsIcon, {
  7685. name: this.icon,
  7686. size: "16px",
  7687. class: "ss-sidebar-panel__icon",
  7688. })
  7689. : null,
  7690. Vue.h("span", null, this.title || "统计图"),
  7691. ]),
  7692. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7693. Vue.h(
  7694. "button",
  7695. {
  7696. type: "button",
  7697. class: {
  7698. "ss-sidebar-chart-tool": true,
  7699. "is-active": this.pinned,
  7700. },
  7701. title: this.pinned ? "取消固定" : "固定",
  7702. onClick: (e) => {
  7703. e.stopPropagation();
  7704. this.togglePin();
  7705. },
  7706. },
  7707. // 功能说明:右侧栏 hover 工具图标使用 ss-sidebar-base-icon(不复用左侧 menu-base-icon) by xu 20260123
  7708. [
  7709. Vue.h(SsIcon, {
  7710. class: this.pinned
  7711. ? "ss-sidebar-base-icon icon-fix-bold"
  7712. : "ss-sidebar-base-icon icon-fix",
  7713. }),
  7714. ]
  7715. ),
  7716. Vue.h(
  7717. "button",
  7718. {
  7719. type: "button",
  7720. class: "ss-sidebar-chart-tool",
  7721. title: "全屏",
  7722. onClick: (e) => {
  7723. e.stopPropagation();
  7724. this.toggleFullscreen();
  7725. },
  7726. },
  7727. [
  7728. Vue.h(SsIcon, {
  7729. class: this.fullscreen
  7730. ? "ss-sidebar-base-icon icon-fs-exit"
  7731. : "ss-sidebar-base-icon icon-fs",
  7732. }),
  7733. ]
  7734. ),
  7735. ]),
  7736. ]
  7737. )
  7738. : Vue.h(
  7739. "div",
  7740. {
  7741. class:
  7742. "ss-sidebar-chart-preview__header ss-sidebar-chart-preview__header--simple",
  7743. },
  7744. [
  7745. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7746. Vue.h(
  7747. "button",
  7748. {
  7749. type: "button",
  7750. class: {
  7751. "ss-sidebar-chart-tool": true,
  7752. "is-active": this.pinned,
  7753. },
  7754. title: this.pinned ? "取消固定" : "固定",
  7755. onClick: (e) => {
  7756. e.stopPropagation();
  7757. this.togglePin();
  7758. },
  7759. },
  7760. [
  7761. Vue.h(SsIcon, {
  7762. class: this.pinned
  7763. ? "ss-sidebar-base-icon icon-fix-bold"
  7764. : "ss-sidebar-base-icon icon-fix",
  7765. }),
  7766. ]
  7767. ),
  7768. Vue.h(
  7769. "button",
  7770. {
  7771. type: "button",
  7772. class: "ss-sidebar-chart-tool",
  7773. title: "全屏",
  7774. onClick: (e) => {
  7775. e.stopPropagation();
  7776. this.toggleFullscreen();
  7777. },
  7778. },
  7779. [
  7780. Vue.h(SsIcon, {
  7781. class: this.fullscreen
  7782. ? "ss-sidebar-base-icon icon-chk-on"
  7783. : "ss-sidebar-base-icon icon-chk",
  7784. }),
  7785. ]
  7786. ),
  7787. ]),
  7788. ]
  7789. ),
  7790. Vue.h("div", { class: "ss-sidebar-chart-preview__body" }, [
  7791. Vue.h(Chart, { options: this.options, height: "100%" }),
  7792. ]),
  7793. ]
  7794. );
  7795. const fullscreenContent =
  7796. this.fullscreen &&
  7797. Vue.h(
  7798. "div",
  7799. {
  7800. ref: "fullscreenRef",
  7801. class: "ss-sidebar-chart-fullscreen",
  7802. },
  7803. [
  7804. Vue.h(
  7805. "div",
  7806. {
  7807. class:
  7808. "ss-sidebar-panel__header ss-sidebar-chart-fullscreen__header",
  7809. },
  7810. [
  7811. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7812. this.iconClass
  7813. ? Vue.h(SsIcon, {
  7814. class: this.iconClass + " ss-sidebar-panel__icon",
  7815. })
  7816. : this.icon
  7817. ? Vue.h(SsIcon, {
  7818. name: this.icon,
  7819. size: "16px",
  7820. class: "ss-sidebar-panel__icon",
  7821. })
  7822. : null,
  7823. Vue.h("span", null, this.title || "统计图"),
  7824. ]),
  7825. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7826. Vue.h(
  7827. "button",
  7828. {
  7829. type: "button",
  7830. class: {
  7831. "ss-sidebar-chart-tool": true,
  7832. "is-active": this.pinned,
  7833. },
  7834. title: this.pinned ? "取消固定" : "固定",
  7835. onClick: (e) => {
  7836. e.stopPropagation();
  7837. this.togglePin();
  7838. },
  7839. },
  7840. [
  7841. Vue.h(SsIcon, {
  7842. class: this.pinned
  7843. ? "ss-sidebar-base-icon icon-fix-bold"
  7844. : "ss-sidebar-base-icon icon-fix",
  7845. }),
  7846. ]
  7847. ),
  7848. Vue.h(
  7849. "button",
  7850. {
  7851. type: "button",
  7852. class: "ss-sidebar-chart-tool",
  7853. title: "退出全屏",
  7854. onClick: (e) => {
  7855. e.stopPropagation();
  7856. this.toggleFullscreen();
  7857. },
  7858. },
  7859. [
  7860. Vue.h(SsIcon, {
  7861. class: "ss-sidebar-base-icon icon-fs-exit",
  7862. }),
  7863. ]
  7864. ),
  7865. ]),
  7866. ]
  7867. ),
  7868. Vue.h("div", { class: "ss-sidebar-chart-fullscreen__body" }, [
  7869. Vue.h(Chart, { options: this.options, height: "100%" }),
  7870. ]),
  7871. ]
  7872. );
  7873. return Vue.h("div", { class: "ss-sidebar-chart-hover" }, [
  7874. Vue.h(
  7875. "div",
  7876. {
  7877. ref: "triggerRef",
  7878. class: "ss-sidebar-chart-hover__trigger",
  7879. onMouseenter: () => {
  7880. this.hoveringTrigger = true;
  7881. this.openPreview();
  7882. },
  7883. onMouseleave: () => {
  7884. this.hoveringTrigger = false;
  7885. this.scheduleClose();
  7886. },
  7887. },
  7888. [Vue.h(Chart, { options: this.options, height: this.height })]
  7889. ),
  7890. (this.open || this.fullscreen) &&
  7891. Vue.h(Vue.Teleport, { to: "body" }, [
  7892. this.open ? previewContent : null,
  7893. fullscreenContent || null,
  7894. ]),
  7895. ]);
  7896. },
  7897. };
  7898. // 组件文档补全(JSDoc) by xu 20260108
  7899. /**
  7900. * SsSidebarList(右侧业务面板:人员/已选/服务/预定...)
  7901. *
  7902. * 用途:
  7903. * - 统一渲染面板 header(图标/标题/数量/右侧按钮)
  7904. * - 统一渲染 list(固定行高、hover、右侧移除按钮等)
  7905. *
  7906. * 调用示例(由 ss-sidebar 通过 panels 配置驱动):
  7907. * ```js
  7908. * { type:'list', title:'已选', iconClass:'menu-icon icon-obj-xcd', mode:'selected', items:selectedItems, closable:true }
  7909. * ```
  7910. *
  7911. * Props(核心):
  7912. * - `title`:header 标题
  7913. * - `iconClass/icon`:header 图标(优先 iconClass)
  7914. * - `count`:数量回显(图表面板可不传)
  7915. * - `closable`:是否显示“清空”按钮(触发 emit clear)
  7916. * - `headerFilters`:header 条件数组(组件名 + props),用于联调接口搜索
  7917. * - `headerSearchButton`:是否显示搜索按钮(触发 emit search)
  7918. * - `items`:列表数据
  7919. * - `mode`:`selected` 时右侧按钮语义为“移除”
  7920. * - `itemLayout`:`simple` / `person`(人员号槽位)
  7921. * - `itemAction`:是否显示 item 右侧操作按钮(hover 才出现)
  7922. *
  7923. * Emits:
  7924. * - `remove(item)`:点击 item 右侧移除
  7925. * - `clear()`:点击 header 清空
  7926. * - `search({keyword, filters})`:点击 header 搜索
  7927. */
  7928. const SsSidebarList = {
  7929. name: "SsSidebarList",
  7930. props: {
  7931. title: { type: String, default: "" },
  7932. // header 图标:优先使用 iconClass(走 ss-icon v3.0 class 分支) by xu 20260106
  7933. iconClass: { type: String, default: "" },
  7934. icon: { type: String, default: "" }, // 兼容旧写法(ss-icon name)
  7935. count: { type: [Number, String], default: "" },
  7936. // 选中类分区:右侧关闭按钮=清空分区数据 by xu 20260106
  7937. closable: { type: Boolean, default: false },
  7938. searchable: { type: Boolean, default: false },
  7939. // 搜索框是否放在 header 内(人员块需要该布局) by xu 20260106
  7940. searchInHeader: { type: Boolean, default: false },
  7941. // header 搜索:下拉条件 + 搜索按钮(适合“人员”块) by xu 20260106
  7942. headerFilters: { type: Array, default: () => [] },
  7943. headerSearchButton: { type: Boolean, default: false },
  7944. searchPlaceholder: { type: String, default: "搜索" },
  7945. // 列表项布局:simple(仅标题) / person(标题+人员号槽位) by xu 20260106
  7946. itemLayout: { type: String, default: "simple" },
  7947. itemAction: { type: Boolean, default: true },
  7948. collapsible: { type: Boolean, default: true }, // 功能说明:是否允许双击 header 折叠/展开 by xu 20260116
  7949. collapsed: { type: Boolean, default: false }, // 功能说明:折叠态仅展示 header by xu 20260116
  7950. items: { type: Array, default: () => [] },
  7951. mode: { type: String, default: "search" }, // search / selected
  7952. },
  7953. emits: ["select", "remove", "clear", "search", "toggle-collapse"],
  7954. data() {
  7955. return {
  7956. keyword: "",
  7957. filterValues: {},
  7958. }; // 功能说明:折叠状态完全由 props.collapsed 驱动,避免多面板复用导致状态不同步 by xu 20260116
  7959. },
  7960. created() {
  7961. // header 下拉条件默认值初始化 by xu 20260106
  7962. (this.headerFilters || []).forEach((f) => {
  7963. if (!f || !f.key) return;
  7964. if (this.filterValues[f.key] !== undefined) return;
  7965. const first = f?.options?.[0]?.value ?? "";
  7966. this.filterValues[f.key] = f.value !== undefined ? f.value : first;
  7967. });
  7968. },
  7969. methods: {
  7970. __shouldIgnoreHeaderToggle(e) {
  7971. // 功能说明:忽略工具区/输入区触发折叠,避免误触 by xu 20260116
  7972. const t = e?.target;
  7973. if (!t || !t.closest) return false;
  7974. if (t.closest(".ss-sidebar-panel__tools")) return true;
  7975. if (t.closest(".ss-sidebar-panel__filters")) return true;
  7976. if (t.closest("input,textarea,select,button")) return true;
  7977. return false;
  7978. },
  7979. __toggleCollapseInternal(e, source) {
  7980. if (!this.collapsible) return;
  7981. if (this.__shouldIgnoreHeaderToggle(e)) return;
  7982. const nextCollapsed = !this.collapsed;
  7983. console.log("[SsSidebarList] toggle emit", {
  7984. title: this.title,
  7985. source,
  7986. to: nextCollapsed,
  7987. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7988. // 功能说明:由父组件(SsSidebar.toggleSectionCollapse)统一控制 section 高度与折叠数组 by xu 20260116
  7989. this.$emit("toggle-collapse");
  7990. },
  7991. },
  7992. render() {
  7993. const items = this.items || [];
  7994. const SsIcon = Vue.resolveComponent("ss-icon");
  7995. const isSelectedMode = this.mode === "selected";
  7996. const activeKeyword = this.filterValues?.keyword ?? this.keyword; // 功能:keyword 优先取 headerFilters.keyword by xu 20260106
  7997. const hasHeaderKeyword = (this.headerFilters || []).some(
  7998. (f) => f?.key === "keyword"
  7999. ); // 功能:header 内 keyword 过滤 by xu 20260106
  8000. const renderHeaderFilter = (f) => {
  8001. if (!f) return null;
  8002. const key = f.key;
  8003. const componentName = f.component;
  8004. if (!key || !componentName) return null;
  8005. const Comp = Vue.resolveComponent(componentName);
  8006. if (!Comp) return null;
  8007. const modelValue = this.filterValues[key];
  8008. const props = f.props || {};
  8009. return Vue.h(Comp, {
  8010. ...props,
  8011. modelValue,
  8012. "onUpdate:modelValue": (v) => {
  8013. this.filterValues[key] = v;
  8014. },
  8015. });
  8016. };
  8017. const filteredItems =
  8018. this.searchable && activeKeyword
  8019. ? items.filter((it) =>
  8020. String(it?.title ?? "")
  8021. .toLowerCase()
  8022. .includes(String(activeKeyword).toLowerCase())
  8023. )
  8024. : items;
  8025. if (!filteredItems.length && !this.title) return null;
  8026. if (this.collapsed) {
  8027. return Vue.h("div", { class: "ss-sidebar-panel" }, [
  8028. this.title
  8029. ? Vue.h(
  8030. "div",
  8031. {
  8032. class: "ss-sidebar-panel__header",
  8033. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  8034. onDblclick: (e) => {
  8035. e?.preventDefault?.();
  8036. e?.stopPropagation?.();
  8037. console.log("[SsSidebarList] header dblclick", {
  8038. title: this.title,
  8039. collapsed: true,
  8040. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8041. this.__toggleCollapseInternal(e, "dblclick");
  8042. },
  8043. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  8044. },
  8045. [
  8046. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  8047. this.iconClass
  8048. ? Vue.h(SsIcon, {
  8049. class: this.iconClass + " ss-sidebar-panel__icon",
  8050. })
  8051. : this.icon
  8052. ? Vue.h(SsIcon, {
  8053. name: this.icon,
  8054. size: "16px",
  8055. class: "ss-sidebar-panel__icon",
  8056. })
  8057. : null,
  8058. Vue.h("span", null, this.title),
  8059. this.count !== ""
  8060. ? Vue.h(
  8061. "span",
  8062. { class: "ss-sidebar-panel__count" },
  8063. `(${this.count})`
  8064. )
  8065. : null,
  8066. ]),
  8067. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  8068. this.closable
  8069. ? Vue.h(
  8070. "button",
  8071. {
  8072. type: "button",
  8073. class: "ss-sidebar-icon-btn ss-sidebar-header-btn",
  8074. title: "清空",
  8075. onClick: (e) => {
  8076. e.stopPropagation();
  8077. this.$emit("clear");
  8078. },
  8079. },
  8080. [
  8081. Vue.h(SsIcon, {
  8082. class: "ss-sidebar-base-icon icon-cl",
  8083. }),
  8084. ] // 功能说明:右侧栏“已选”清空按钮图标使用 ss-sidebar-base-icon by xu 20260123
  8085. )
  8086. : null,
  8087. ]),
  8088. ]
  8089. )
  8090. : null,
  8091. ]);
  8092. }
  8093. return Vue.h("div", { class: "ss-sidebar-panel" }, [
  8094. this.title
  8095. ? Vue.h(
  8096. "div",
  8097. {
  8098. class: "ss-sidebar-panel__header",
  8099. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  8100. onDblclick: (e) => {
  8101. e?.preventDefault?.();
  8102. e?.stopPropagation?.();
  8103. console.log("[SsSidebarList] header dblclick", {
  8104. title: this.title,
  8105. collapsed: false,
  8106. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8107. this.__toggleCollapseInternal(e, "dblclick");
  8108. },
  8109. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  8110. },
  8111. [
  8112. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  8113. // 图标 + 标题(每个分区都有) by xu 20260106
  8114. this.iconClass
  8115. ? Vue.h(SsIcon, {
  8116. class: this.iconClass + " ss-sidebar-panel__icon",
  8117. })
  8118. : this.icon
  8119. ? Vue.h(SsIcon, {
  8120. name: this.icon,
  8121. size: "16px",
  8122. class: "ss-sidebar-panel__icon",
  8123. })
  8124. : null,
  8125. Vue.h("span", null, this.title),
  8126. // 数量回显:图表分区可不传 count by xu 20260106
  8127. this.count !== ""
  8128. ? Vue.h(
  8129. "span",
  8130. { class: "ss-sidebar-panel__count" },
  8131. `(${this.count})`
  8132. )
  8133. : null,
  8134. ]),
  8135. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  8136. // header 条件(例如下拉框)+ 右侧搜索按钮 by xu 20260106
  8137. this.headerFilters?.length
  8138. ? Vue.h(
  8139. "div",
  8140. { class: "ss-sidebar-panel__filters" },
  8141. this.headerFilters
  8142. .map(renderHeaderFilter)
  8143. .filter(Boolean)
  8144. )
  8145. : null,
  8146. this.headerSearchButton
  8147. ? Vue.h(
  8148. "button",
  8149. {
  8150. type: "button",
  8151. class: "ss-sidebar-icon-btn",
  8152. title: "搜索",
  8153. onClick: (e) => {
  8154. e.stopPropagation();
  8155. this.$emit("search", {
  8156. // headerFilters 内也可能包含 keyword by xu 20260106
  8157. keyword: activeKeyword,
  8158. filters: { ...(this.filterValues || {}) },
  8159. });
  8160. },
  8161. },
  8162. [Vue.h(SsIcon, { name: "search", size: "14px" })]
  8163. )
  8164. : null,
  8165. // 人员块:搜索框在 header 内 by xu 20260106
  8166. this.searchable &&
  8167. this.searchInHeader &&
  8168. !this.headerSearchButton
  8169. ? Vue.h(
  8170. "div",
  8171. { class: "ss-sidebar-panel__searchInline" },
  8172. [
  8173. Vue.h(
  8174. "div",
  8175. { class: "ss-sidebar-search is-inline" },
  8176. [
  8177. Vue.h(SsIcon, {
  8178. name: "search",
  8179. size: "14px",
  8180. class: "ss-sidebar-search__prefix",
  8181. }),
  8182. Vue.h("input", {
  8183. class: "ss-sidebar-search__input",
  8184. value: this.keyword,
  8185. placeholder: this.searchPlaceholder,
  8186. onInput: (e) => {
  8187. this.keyword = e?.target?.value ?? "";
  8188. },
  8189. }),
  8190. ]
  8191. ),
  8192. ]
  8193. )
  8194. : null,
  8195. this.closable
  8196. ? Vue.h(
  8197. "button",
  8198. {
  8199. type: "button",
  8200. class: "ss-sidebar-icon-btn ss-sidebar-header-btn",
  8201. title: "清空",
  8202. onClick: (e) => {
  8203. e.stopPropagation();
  8204. this.$emit("clear");
  8205. },
  8206. },
  8207. // 清空按钮使用 icon-base 的 icon-cl by xu 20260106
  8208. [
  8209. Vue.h(SsIcon, {
  8210. class: "ss-sidebar-base-icon icon-cl",
  8211. }),
  8212. ] // 功能说明:右侧栏清空按钮图标使用 ss-sidebar-base-icon by xu 20260123
  8213. )
  8214. : null,
  8215. ]),
  8216. ]
  8217. )
  8218. : null,
  8219. // 非 header 内搜索:独立一行 by xu 20260106
  8220. // headerSearchButton/headerFilters 已覆盖搜索能力时,不再额外渲染独立搜索行 by xu 20260106
  8221. this.searchable &&
  8222. !this.searchInHeader &&
  8223. !this.headerSearchButton &&
  8224. !hasHeaderKeyword
  8225. ? Vue.h("div", { class: "ss-sidebar-panel__search" }, [
  8226. Vue.h("div", { class: "ss-sidebar-search" }, [
  8227. Vue.h(SsIcon, {
  8228. name: "search",
  8229. size: "14px",
  8230. class: "ss-sidebar-search__prefix",
  8231. }),
  8232. Vue.h("input", {
  8233. class: "ss-sidebar-search__input",
  8234. value: this.keyword,
  8235. placeholder: this.searchPlaceholder,
  8236. onInput: (e) => {
  8237. this.keyword = e?.target?.value ?? "";
  8238. },
  8239. }),
  8240. ]),
  8241. ])
  8242. : null,
  8243. Vue.h(
  8244. "div",
  8245. { class: "ss-sidebar-list" },
  8246. filteredItems.map((item, idx) => {
  8247. const title = item?.title ?? "";
  8248. const tags = item?.tags || [];
  8249. const isPersonLayout = this.itemLayout === "person";
  8250. const hasTags = !isPersonLayout && tags?.length > 0; // 列表项垂直对齐:有 tags 顶对齐 by xu 20260106
  8251. return Vue.h(
  8252. "div",
  8253. {
  8254. class: {
  8255. "ss-sidebar-list-item": true,
  8256. "is-first": idx === 0,
  8257. "is-person": isPersonLayout,
  8258. "has-tags": hasTags,
  8259. },
  8260. },
  8261. [
  8262. Vue.h("div", { class: "ss-sidebar-list-item__main" }, [
  8263. Vue.h(
  8264. "div",
  8265. { class: "ss-sidebar-list-item__title" },
  8266. Vue.h(
  8267. "span",
  8268. {
  8269. style: {
  8270. "white-space": "nowrap",
  8271. overflow: "hidden",
  8272. "text-overflow": "ellipsis",
  8273. },
  8274. },
  8275. title
  8276. )
  8277. ),
  8278. // 非人员布局才显示 tags by xu 20260106
  8279. !isPersonLayout && tags?.length
  8280. ? Vue.h(
  8281. "div",
  8282. { class: "ss-sidebar-list-item__tags" },
  8283. tags.map((tag) => {
  8284. const [k, v] = Object.entries(tag)[0] || ["", ""];
  8285. return Vue.h(
  8286. "span",
  8287. { class: "ss-sidebar-tag", title: `${k}: ${v}` },
  8288. `${k}: ${v}`
  8289. );
  8290. })
  8291. )
  8292. : null,
  8293. ]),
  8294. // 人员布局:中间保留“人员号”槽位 by xu 20260106
  8295. isPersonLayout
  8296. ? Vue.h(
  8297. "div",
  8298. {
  8299. class: "ss-sidebar-list-item__meta",
  8300. title: String(item?.meta ?? ""),
  8301. },
  8302. item?.meta ?? ""
  8303. )
  8304. : null,
  8305. this.itemAction
  8306. ? Vue.h(
  8307. "button",
  8308. {
  8309. type: "button",
  8310. class: {
  8311. // item 操作按钮:默认无背景/无边框,hover 才高亮 by xu 20260106
  8312. "ss-sidebar-item-btn": true,
  8313. },
  8314. title: isSelectedMode ? "移除" : "选择",
  8315. onClick: (e) => {
  8316. e.stopPropagation();
  8317. if (isSelectedMode) this.$emit("remove", item);
  8318. else this.$emit("select", item);
  8319. },
  8320. },
  8321. [
  8322. // item 移除图标使用 icon-base 的 icon-cl by xu 20260106
  8323. isSelectedMode
  8324. ? Vue.h(SsIcon, {
  8325. class: "ss-sidebar-base-icon icon-cl",
  8326. }) // 功能说明:右侧栏 item 移除图标使用 ss-sidebar-base-icon by xu 20260123
  8327. : Vue.h(SsIcon, { name: "check", size: "14px" }),
  8328. ]
  8329. )
  8330. : null,
  8331. ]
  8332. );
  8333. })
  8334. ),
  8335. ]);
  8336. },
  8337. };
  8338. // ss-sidebar-report-table:右侧“统计表/报表”面板(pstatList grtjlbm=51 聚拢渲染) by xu 20260115
  8339. const SsSidebarReportTable = {
  8340. name: "SsSidebarReportTable",
  8341. props: {
  8342. title: { type: String, default: "" },
  8343. iconClass: { type: String, default: "" },
  8344. icon: { type: String, default: "" },
  8345. items: { type: Array, default: () => [] }, // pstatList(grtjlbm=51) 数组
  8346. onOpen: { type: Function, default: null }, // (srv, ctx) => void
  8347. collapsible: { type: Boolean, default: true }, // 功能说明:是否允许双击 header 折叠/展开 by xu 20260116
  8348. collapsed: { type: Boolean, default: false }, // 功能说明:折叠态仅展示 header by xu 20260116
  8349. },
  8350. emits: ["open", "toggle-collapse"],
  8351. data() {
  8352. return {}; // 功能说明:折叠状态完全由 props.collapsed 驱动 by xu 20260116
  8353. },
  8354. methods: {
  8355. __toggleCollapseInternal(e, source) {
  8356. if (!this.collapsible) return;
  8357. const next = !this.collapsed;
  8358. console.log("[SsSidebarReportTable] toggle emit", {
  8359. title: this.title,
  8360. source,
  8361. to: next,
  8362. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8363. this.$emit("toggle-collapse");
  8364. },
  8365. },
  8366. render() {
  8367. const SsIcon = Vue.resolveComponent("ss-icon");
  8368. const list = this.items || [];
  8369. if (!this.title && !list.length) return null;
  8370. const header = this.title
  8371. ? Vue.h(
  8372. "div",
  8373. {
  8374. class: "ss-sidebar-panel__header",
  8375. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  8376. onDblclick: (e) => {
  8377. e?.preventDefault?.();
  8378. e?.stopPropagation?.();
  8379. console.log("[SsSidebarReportTable] header dblclick", {
  8380. title: this.title,
  8381. collapsed: this.collapsed,
  8382. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8383. this.__toggleCollapseInternal(e, "dblclick");
  8384. },
  8385. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  8386. },
  8387. [
  8388. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  8389. this.iconClass
  8390. ? Vue.h(SsIcon, {
  8391. class: this.iconClass + " ss-sidebar-panel__icon",
  8392. })
  8393. : this.icon
  8394. ? Vue.h(SsIcon, {
  8395. name: this.icon,
  8396. size: "16px",
  8397. class: "ss-sidebar-panel__icon",
  8398. })
  8399. : null,
  8400. Vue.h("span", null, this.title),
  8401. ]),
  8402. Vue.h("div", { class: "ss-sidebar-panel__tools" }),
  8403. ]
  8404. )
  8405. : null;
  8406. const renderReport = (report) => {
  8407. const title = String(report?.mc ?? "");
  8408. const mx = Array.isArray(report?.grtjmxList) ? report.grtjmxList : [];
  8409. if (!title && !mx.length) return null;
  8410. // 功能说明:每个报表对象渲染为一个 table(有边框、无圆角、表间距10px;样式由 base.css 统一控制) by xu 20260115
  8411. const cols = Math.max(1, mx.length);
  8412. // 功能说明:table 外层包一层 wrap,子项过多时支持横向滚动 by xu 20260115
  8413. return Vue.h("div", { class: "ss-sidebar-report-table-wrap" }, [
  8414. Vue.h("table", { class: "ss-sidebar-report-table" }, [
  8415. Vue.h("thead", null, [
  8416. Vue.h("tr", null, [
  8417. Vue.h(
  8418. "th",
  8419. { class: "ss-sidebar-report-table__title", colspan: cols },
  8420. Vue.h(
  8421. "div",
  8422. { class: "ss-sidebar-report-table__title-content" },
  8423. [
  8424. Vue.h("span", { class: "ss-sidebar-report-table__dot" }),
  8425. Vue.h(
  8426. "span",
  8427. { class: "ss-sidebar-report-table__title-text", title },
  8428. title
  8429. ),
  8430. ]
  8431. )
  8432. ),
  8433. ]),
  8434. ]),
  8435. Vue.h("tbody", null, [
  8436. Vue.h(
  8437. "tr",
  8438. null,
  8439. mx.map((cell) => {
  8440. const text = String(cell?.mc ?? "");
  8441. const srv = {
  8442. servName: cell?.fwm ?? "",
  8443. dest: cell?.bjm ?? "",
  8444. title: text,
  8445. width: cell?.width,
  8446. height: cell?.height,
  8447. minHeight: cell?.height,
  8448. maxHeight: cell?.height,
  8449. showTitle: text,
  8450. };
  8451. return Vue.h(
  8452. "td",
  8453. {
  8454. class: "ss-sidebar-report-table__cell",
  8455. title: text,
  8456. onClick: (e) => {
  8457. e?.stopPropagation?.();
  8458. try {
  8459. this.onOpen?.(srv, { report, cell });
  8460. } catch (_) {}
  8461. this.$emit("open", { report, cell, srv });
  8462. },
  8463. },
  8464. text
  8465. );
  8466. })
  8467. ),
  8468. ]),
  8469. ]),
  8470. ]);
  8471. };
  8472. // 功能说明:报表面板增加独立 class,便于 base.css 统一控制 padding/间距 by xu 20260115
  8473. return Vue.h(
  8474. "div",
  8475. { class: "ss-sidebar-panel ss-sidebar-report-panel" },
  8476. [
  8477. header,
  8478. this.collapsed
  8479. ? null
  8480. : Vue.h(
  8481. "div",
  8482. // 功能说明:报表列表滚动/高度样式下沉到 base.css,避免写在 DOM 上 by xu 20260115
  8483. { class: "ss-sidebar-report__list" },
  8484. list.map(renderReport).filter(Boolean)
  8485. ),
  8486. ]
  8487. );
  8488. },
  8489. };
  8490. // 组件文档补全(JSDoc) by xu 20260108
  8491. /**
  8492. * SsSidebar(objList 右侧边栏容器)
  8493. *
  8494. * 用途:
  8495. * - 统一渲染顶部按钮栏(buttons)
  8496. * - 统一渲染中间业务面板(list panels,可拖拽调高度)
  8497. * - 统一渲染底部图表(chart panels,内部用 ss-sidebar-chart-hover)
  8498. *
  8499. * 调用示例:
  8500. * ```html
  8501. * <ss-sidebar :buttons="sidebarButtons" :panels="sidebarPanels" @remove="handleSidebarRemove" />
  8502. * ```
  8503. *
  8504. * Props:
  8505. * - `buttons`:顶部按钮配置数组
  8506. * - `panels`:分区配置数组(`type: 'list' | 'chart'`)
  8507. *
  8508. * Events(向外透传):
  8509. * - `remove(item)`:来自 list 面板移除
  8510. * - `select(item)`:来自 list 面板选择(如后续需要)
  8511. */
  8512. const SsSidebar = {
  8513. name: "SsSidebar",
  8514. props: {
  8515. buttons: { type: Array, default: () => [] },
  8516. charts: { type: Array, default: () => [] },
  8517. list: { type: Array, default: () => [] }, // legacy
  8518. listMode: { type: String, default: "search" }, // legacy
  8519. panels: { type: Array, default: () => [] },
  8520. },
  8521. emits: ["select", "remove"],
  8522. data() {
  8523. return {
  8524. // 业务面板高度(索引 -> px) by xu 20260106
  8525. sectionHeights: [],
  8526. sectionCollapsed: [], // 功能说明:面板折叠状态(sectionPanels 索引) by xu 20260116
  8527. sectionHeightsExpanded: [], // 功能说明:面板展开高度缓存(用于折叠后恢复) by xu 20260116
  8528. sectionLastItemCounts: [], // 功能说明:记录栏目数据量,供“无数据默认关闭/已选自动展开”规则复用 by xu 20260313
  8529. chartCollapsed: [], // 功能说明:图表面板折叠状态(chartPanels 索引) by xu 20260116
  8530. chartHeaderTitleDownAt: [], // 功能说明:双击检测绑定到 chart 标题区 by xu 20260116
  8531. reportCollapsed: [], // 功能说明:报表面板折叠状态(reportPanels 索引) by xu 20260116
  8532. resizeTimer: null,
  8533. resizing: false,
  8534. resizeIndex: -1,
  8535. resizeStartY: 0,
  8536. resizeStartPrev: 0,
  8537. resizeStartNext: 0,
  8538. __resizeMoveHandler: null, // 功能说明:显式绑定 this 的 pointermove handler,避免 addEventListener 场景 this 丢失导致拖拽无效 by xu 20260122
  8539. __resizeEndHandler: null, // 功能说明:显式绑定 this 的 pointerup handler,确保能正确结束拖拽 by xu 20260122
  8540. __resizeCancelHandler: null, // 功能说明:显式绑定 this 的 pointercancel handler,触控取消也能收尾 by xu 20260122
  8541. __resizePrevSectionEl: null, // 功能说明:拖拽时直接写 DOM 高度(修复响应式更新不生效) by xu 20260122
  8542. __resizeNextSectionEl: null, // 功能说明:拖拽时直接写 DOM 高度(修复响应式更新不生效) by xu 20260122
  8543. };
  8544. },
  8545. methods: {
  8546. // 初始化默认高度(只在第一次/面板数量变化时补齐) by xu 20260106
  8547. ensureSectionHeights(sectionCount) {
  8548. if (!Array.isArray(this.sectionHeights)) this.sectionHeights = [];
  8549. if (this.sectionHeights.length === sectionCount) return;
  8550. const next = [];
  8551. for (let i = 0; i < sectionCount; i++) {
  8552. next[i] = this.sectionHeights[i] ?? 190; // 默认高度 by xu 20260106
  8553. }
  8554. this.sectionHeights = next;
  8555. // 功能说明:面板数量变化时补齐折叠/缓存数组长度 by xu 20260116
  8556. this.sectionCollapsed = Array.from(
  8557. { length: sectionCount },
  8558. (_, i) => !!this.sectionCollapsed?.[i]
  8559. );
  8560. this.sectionHeightsExpanded = Array.from(
  8561. { length: sectionCount },
  8562. (_, i) => this.sectionHeightsExpanded?.[i] ?? null
  8563. );
  8564. this.sectionLastItemCounts = Array.from(
  8565. { length: sectionCount },
  8566. (_, i) => Number(this.sectionLastItemCounts?.[i] ?? 0) || 0
  8567. );
  8568. },
  8569. __getPanelsForSectionState(panelsInput) {
  8570. return (panelsInput || []).length
  8571. ? panelsInput
  8572. : this.list?.length
  8573. ? [
  8574. {
  8575. type: "list",
  8576. title: "已选",
  8577. icon: "",
  8578. mode: this.listMode,
  8579. items: this.list,
  8580. },
  8581. ]
  8582. : [];
  8583. },
  8584. __getSectionPanelsForState(panelsInput) {
  8585. return this.__getPanelsForSectionState(panelsInput)
  8586. .filter((p) => {
  8587. const k = String(p?._tabKey ?? "")
  8588. .trim()
  8589. .toLowerCase();
  8590. const t = String(p?.title ?? "").trim();
  8591. if (k === "rbarobj") return false;
  8592. if (t === "对象") return false;
  8593. return true;
  8594. })
  8595. .filter((p) => p?.type !== "chart" && p?.type !== "report-table");
  8596. },
  8597. __getSectionPanelCount(panel) {
  8598. const explicitCount = Number(panel?.count);
  8599. if (Number.isFinite(explicitCount)) return explicitCount;
  8600. return Array.isArray(panel?.items) ? panel.items.length : 0;
  8601. },
  8602. __setSectionCollapsedState(index, collapsed) {
  8603. const i = Number(index);
  8604. if (isNaN(i) || i < 0) return;
  8605. const nextCollapsed = !!collapsed;
  8606. const collapsedHeight = 37;
  8607. const cur = !!this.sectionCollapsed?.[i];
  8608. const currentHeight = Number(this.sectionHeights?.[i] ?? 190) || 190;
  8609. if (nextCollapsed === cur) {
  8610. if (nextCollapsed && currentHeight !== collapsedHeight) {
  8611. this.sectionHeights.splice(i, 1, collapsedHeight);
  8612. }
  8613. return;
  8614. }
  8615. if (nextCollapsed) {
  8616. this.sectionHeightsExpanded[i] =
  8617. currentHeight > collapsedHeight
  8618. ? currentHeight
  8619. : Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  8620. this.sectionHeights.splice(i, 1, collapsedHeight);
  8621. } else {
  8622. const restore =
  8623. Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  8624. this.sectionHeights.splice(i, 1, restore);
  8625. }
  8626. this.sectionCollapsed.splice(i, 1, nextCollapsed);
  8627. },
  8628. __syncSectionAutoCollapse(panelsInput) {
  8629. const sectionPanels = this.__getSectionPanelsForState(panelsInput);
  8630. const sectionCount = sectionPanels.length;
  8631. this.ensureSectionHeights(sectionCount);
  8632. const prevCounts = Array.isArray(this.sectionLastItemCounts)
  8633. ? this.sectionLastItemCounts.slice()
  8634. : [];
  8635. const nextCounts = Array.from({ length: sectionCount }, (_, i) =>
  8636. this.__getSectionPanelCount(sectionPanels[i])
  8637. );
  8638. this.sectionLastItemCounts = nextCounts;
  8639. sectionPanels.forEach((panel, index) => {
  8640. const count = Number(nextCounts[index] ?? 0) || 0;
  8641. const prevCount = Number(prevCounts[index] ?? 0) || 0;
  8642. const title = String(panel?.title ?? "").trim();
  8643. if (count <= 0) {
  8644. this.__setSectionCollapsedState(index, true);
  8645. return;
  8646. }
  8647. if (title === "已选" && count > prevCount) {
  8648. this.__setSectionCollapsedState(index, false);
  8649. }
  8650. });
  8651. },
  8652. toggleSectionCollapse(index) {
  8653. // 功能说明:双击 header 折叠/展开 section 面板(仅控制高度与内容渲染) by xu 20260116
  8654. const i = Number(index);
  8655. if (isNaN(i) || i < 0) return;
  8656. // 功能说明:加更细粒度日志,定位“多面板折叠无视觉效果”的根因(高度是否真的变、DOM 是否更新) by xu 20260116
  8657. const collapsedHeight = 37; // 功能说明:header(35) + panel 边框(2),避免 flex shrink 导致 header 变 25px by xu 20260116
  8658. const cur = !!this.sectionCollapsed?.[i];
  8659. console.log("[SsSidebar] toggleSectionCollapse", {
  8660. index: i,
  8661. to: !cur,
  8662. prevHeight: this.sectionHeights?.[i],
  8663. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8664. if (!cur) {
  8665. this.sectionHeightsExpanded[i] = this.sectionHeights[i] ?? 190;
  8666. this.sectionHeights.splice(i, 1, collapsedHeight);
  8667. } else {
  8668. const restore =
  8669. Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  8670. this.sectionHeights.splice(i, 1, restore);
  8671. }
  8672. this.sectionCollapsed.splice(i, 1, !cur);
  8673. console.log("[SsSidebar] section state(after)", {
  8674. index: i,
  8675. height: this.sectionHeights?.[i],
  8676. collapsed: this.sectionCollapsed?.[i],
  8677. allHeights: Array.from(this.sectionHeights || []),
  8678. allCollapsed: Array.from(this.sectionCollapsed || []),
  8679. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8680. Vue.nextTick(() => {
  8681. try {
  8682. const root = this.$el;
  8683. const sections = root?.querySelectorAll?.(".ss-sidebar-section");
  8684. const el = sections?.[i];
  8685. const rectH = el?.getBoundingClientRect?.().height;
  8686. console.log("[SsSidebar] section dom(beforeFix)", {
  8687. index: i,
  8688. styleHeight: el?.style?.height,
  8689. rectH,
  8690. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8691. // 功能说明:若渲染未把 height patch 到 DOM,则在 nextTick 强制同步一次(并打印) by xu 20260116
  8692. const targetH =
  8693. (Number(this.sectionHeights?.[i] ?? 190) || 190) + "px";
  8694. if (el && el.style && el.style.height !== targetH) {
  8695. el.style.height = targetH;
  8696. }
  8697. if (el?.classList) {
  8698. el.classList.toggle("is-collapsed", !!this.sectionCollapsed?.[i]);
  8699. }
  8700. const rectAfter = el?.getBoundingClientRect?.().height;
  8701. console.log("[SsSidebar] section dom(afterFix)", {
  8702. index: i,
  8703. styleHeight: el?.style?.height,
  8704. rectH: rectAfter,
  8705. targetH,
  8706. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8707. } catch (err) {
  8708. console.log("[SsSidebar] section dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8709. }
  8710. });
  8711. },
  8712. toggleChartCollapse(index) {
  8713. // 功能说明:双击 header 折叠/展开底部 chart 面板(隐藏/显示 chart-hover) by xu 20260116
  8714. const i = Number(index);
  8715. if (isNaN(i) || i < 0) return;
  8716. const cur = !!this.chartCollapsed?.[i];
  8717. console.log("[SsSidebar] toggleChartCollapse", { index: i, to: !cur }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8718. this.chartCollapsed.splice(i, 1, !cur);
  8719. console.log("[SsSidebar] chart state(after)", {
  8720. index: i,
  8721. collapsed: this.chartCollapsed?.[i],
  8722. allCollapsed: Array.from(this.chartCollapsed || []),
  8723. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8724. Vue.nextTick(() => {
  8725. try {
  8726. const root = this.$el;
  8727. const el = root?.querySelector?.(
  8728. `.ss-sidebar-chart-panel[data-chart-idx="${i}"]`
  8729. );
  8730. console.log("[SsSidebar] chart dom(beforeFix)", {
  8731. index: i,
  8732. found: !!el,
  8733. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8734. if (el?.classList)
  8735. el.classList.toggle("is-collapsed", !!this.chartCollapsed?.[i]);
  8736. console.log("[SsSidebar] chart dom(afterFix)", {
  8737. index: i,
  8738. collapsed: !!this.chartCollapsed?.[i],
  8739. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8740. } catch (err) {
  8741. console.log("[SsSidebar] chart dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8742. }
  8743. });
  8744. },
  8745. toggleReportCollapse(index) {
  8746. // 功能说明:双击 header 折叠/展开底部 report-table 面板(隐藏/显示表格) by xu 20260116
  8747. const i = Number(index);
  8748. if (isNaN(i) || i < 0) return;
  8749. const cur = !!this.reportCollapsed?.[i];
  8750. console.log("[SsSidebar] toggleReportCollapse", { index: i, to: !cur }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8751. this.reportCollapsed.splice(i, 1, !cur);
  8752. console.log("[SsSidebar] report state(after)", {
  8753. index: i,
  8754. collapsed: this.reportCollapsed?.[i],
  8755. allCollapsed: Array.from(this.reportCollapsed || []),
  8756. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8757. Vue.nextTick(() => {
  8758. try {
  8759. const root = this.$el;
  8760. const el = root?.querySelector?.(
  8761. `.ss-sidebar-report-panel[data-report-idx="${i}"]`
  8762. );
  8763. console.log("[SsSidebar] report dom(beforeFix)", {
  8764. index: i,
  8765. found: !!el,
  8766. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8767. if (el?.classList)
  8768. el.classList.toggle("is-collapsed", !!this.reportCollapsed?.[i]);
  8769. console.log("[SsSidebar] report dom(afterFix)", {
  8770. index: i,
  8771. collapsed: !!this.reportCollapsed?.[i],
  8772. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8773. } catch (err) {
  8774. console.log("[SsSidebar] report dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8775. }
  8776. });
  8777. },
  8778. startResize(index, e) {
  8779. if (e?.preventDefault) e.preventDefault();
  8780. if (e?.stopPropagation) e.stopPropagation();
  8781. if (this.resizing) return;
  8782. // 长按 0.5s 后才进入拖拽调高度 by xu 20260106
  8783. clearTimeout(this.resizeTimer);
  8784. // 功能说明:修复“长按拖拽偶发失效/卡死”——pointerup 早于 500ms 时必须取消 timer,否则 timer 触发后进入 resizing=true 且再也收不到 pointerup,导致后续都无法拖拽 by xu 20260122
  8785. const pointerId = e?.pointerId;
  8786. const cancelPendingResize = (ev) => {
  8787. try {
  8788. if (
  8789. pointerId != null &&
  8790. ev?.pointerId != null &&
  8791. ev.pointerId !== pointerId
  8792. )
  8793. return;
  8794. } catch (_) {}
  8795. clearTimeout(this.resizeTimer);
  8796. this.resizeTimer = null;
  8797. document.removeEventListener("pointerup", cancelPendingResize, true);
  8798. document.removeEventListener(
  8799. "pointercancel",
  8800. cancelPendingResize,
  8801. true
  8802. );
  8803. };
  8804. // 功能说明:用 document+capture 监听,避免 window 监听在部分容器/iframe 场景丢事件导致拖拽无响应 by xu 20260122
  8805. document.addEventListener("pointerup", cancelPendingResize, {
  8806. passive: false,
  8807. once: true,
  8808. capture: true,
  8809. });
  8810. document.addEventListener("pointercancel", cancelPendingResize, {
  8811. passive: false,
  8812. once: true,
  8813. capture: true,
  8814. });
  8815. const startY = e?.clientY ?? 0;
  8816. const gapEl = e?.currentTarget;
  8817. // 功能说明:记录 gap 前后 section 节点,拖拽过程中直接写入 style.height,避免某些环境下 Vue render 不刷新导致“拖拽无视觉变化” by xu 20260122
  8818. this.__resizePrevSectionEl = gapEl?.previousElementSibling || null;
  8819. this.__resizeNextSectionEl = gapEl?.nextElementSibling || null;
  8820. this.resizeTimer = setTimeout(() => {
  8821. // 定时器触发后进入拖拽态,移除“取消等待”监听,避免误取消 by xu 20260122
  8822. document.removeEventListener("pointerup", cancelPendingResize, true);
  8823. document.removeEventListener(
  8824. "pointercancel",
  8825. cancelPendingResize,
  8826. true
  8827. );
  8828. this.resizing = true;
  8829. this.resizeIndex = index;
  8830. this.resizeStartY = startY;
  8831. this.resizeStartPrev = this.sectionHeights[index] ?? 190;
  8832. this.resizeStartNext = this.sectionHeights[index + 1] ?? 190;
  8833. gapEl?.classList?.add("is-active");
  8834. try {
  8835. if (gapEl?.setPointerCapture && pointerId != null)
  8836. gapEl.setPointerCapture(pointerId);
  8837. } catch (_) {} // 功能说明:捕获 pointer,避免拖拽过程中移出窗口导致 pointermove 丢失 by xu 20260122
  8838. // 功能说明:用 document+capture,确保拖拽时 pointermove/up 不会被中途 stopPropagation 影响 by xu 20260122
  8839. document.addEventListener(
  8840. "pointermove",
  8841. this.__resizeMoveHandler || this.onResizeMove,
  8842. { passive: false, capture: true }
  8843. );
  8844. document.addEventListener(
  8845. "pointerup",
  8846. this.__resizeEndHandler || this.endResize,
  8847. { passive: false, once: true, capture: true }
  8848. );
  8849. document.addEventListener(
  8850. "pointercancel",
  8851. this.__resizeCancelHandler || this.endResize,
  8852. { passive: false, once: true, capture: true }
  8853. ); // 功能说明:触控/手势取消时也要结束拖拽 by xu 20260122
  8854. }, 500);
  8855. },
  8856. onResizeMove(e) {
  8857. if (!this.resizing) return;
  8858. if (e?.preventDefault) e.preventDefault();
  8859. const dy = (e?.clientY ?? 0) - this.resizeStartY;
  8860. const minPanelHeight = 83; // header(35) + listMin(48) by xu 20260106
  8861. const prev = Math.max(minPanelHeight, this.resizeStartPrev + dy);
  8862. const next = Math.max(minPanelHeight, this.resizeStartNext - dy);
  8863. // 若其中一个达到最小值,则停止继续挤压 by xu 20260106
  8864. const adjustedDy = prev - this.resizeStartPrev;
  8865. const nextAdjusted = this.resizeStartNext - adjustedDy;
  8866. const appliedPrev = prev;
  8867. const appliedNext = Math.max(minPanelHeight, nextAdjusted);
  8868. this.sectionHeights.splice(this.resizeIndex, 1, appliedPrev);
  8869. this.sectionHeights.splice(this.resizeIndex + 1, 1, appliedNext);
  8870. // 功能说明:强制触发一次 sectionHeights 引用变化,避免某些运行时环境下 splice 未触发视图更新导致“拖拽没反应” by xu 20260122
  8871. this.sectionHeights = (this.sectionHeights || []).slice();
  8872. // 功能说明:兜底——直接写 DOM 的 height,确保视觉立即响应(用于排查/修复某些环境下 render 不更新) by xu 20260122
  8873. try {
  8874. if (this.__resizePrevSectionEl?.style)
  8875. this.__resizePrevSectionEl.style.height = appliedPrev + "px";
  8876. if (this.__resizeNextSectionEl?.style)
  8877. this.__resizeNextSectionEl.style.height = appliedNext + "px";
  8878. } catch (_) {}
  8879. },
  8880. endResize(e) {
  8881. clearTimeout(this.resizeTimer);
  8882. this.resizeTimer = null;
  8883. if (!this.resizing) return;
  8884. if (e?.preventDefault) e.preventDefault();
  8885. const activeGaps = document.querySelectorAll(
  8886. ".ss-sidebar-gap.is-active"
  8887. );
  8888. activeGaps.forEach((g) => g.classList.remove("is-active"));
  8889. this.resizing = false;
  8890. this.resizeIndex = -1;
  8891. this.__resizePrevSectionEl = null; // 功能说明:释放 DOM 引用,避免内存泄漏 by xu 20260122
  8892. this.__resizeNextSectionEl = null; // 功能说明:释放 DOM 引用,避免内存泄漏 by xu 20260122
  8893. document.removeEventListener(
  8894. "pointermove",
  8895. this.__resizeMoveHandler || this.onResizeMove,
  8896. true
  8897. );
  8898. document.removeEventListener(
  8899. "pointercancel",
  8900. this.__resizeCancelHandler || this.endResize,
  8901. true
  8902. ); // 功能说明:清理 cancel 监听,避免残留 by xu 20260122
  8903. },
  8904. },
  8905. watch: {
  8906. panels: {
  8907. handler(nextPanels) {
  8908. this.__syncSectionAutoCollapse(nextPanels);
  8909. },
  8910. deep: true,
  8911. immediate: true,
  8912. },
  8913. list: {
  8914. handler(nextList) {
  8915. if ((this.panels || []).length) return;
  8916. this.__syncSectionAutoCollapse(nextList);
  8917. },
  8918. deep: true,
  8919. immediate: true,
  8920. },
  8921. },
  8922. mounted() {
  8923. clearTimeout(this.resizeTimer);
  8924. this.resizeTimer = null;
  8925. // 功能说明:绑定拖拽事件 handler(用于 add/removeEventListener) by xu 20260122
  8926. if (!this.__resizeMoveHandler)
  8927. this.__resizeMoveHandler = (e) => this.onResizeMove?.(e);
  8928. if (!this.__resizeEndHandler)
  8929. this.__resizeEndHandler = (e) => this.endResize?.(e);
  8930. if (!this.__resizeCancelHandler)
  8931. this.__resizeCancelHandler = (e) => this.endResize?.(e);
  8932. // 功能说明:暂时回退为固定底部留白方案(CSS 控制),后续再定位遮挡根因 by xu 20260115
  8933. },
  8934. beforeUnmount() {
  8935. clearTimeout(this.resizeTimer);
  8936. this.resizeTimer = null;
  8937. document.removeEventListener(
  8938. "pointermove",
  8939. this.__resizeMoveHandler || this.onResizeMove,
  8940. true
  8941. );
  8942. document.removeEventListener(
  8943. "pointerup",
  8944. this.__resizeEndHandler || this.endResize,
  8945. true
  8946. );
  8947. document.removeEventListener(
  8948. "pointercancel",
  8949. this.__resizeCancelHandler || this.endResize,
  8950. true
  8951. );
  8952. },
  8953. render() {
  8954. const SsSidebarButtonsComp = Vue.resolveComponent("ss-sidebar-buttons");
  8955. const SsSidebarChartComp = Vue.resolveComponent("ss-sidebar-chart");
  8956. const SsSidebarListComp = Vue.resolveComponent("ss-sidebar-list");
  8957. const SsSidebarReportTableComp = Vue.resolveComponent(
  8958. "ss-sidebar-report-table"
  8959. );
  8960. const SsIcon = Vue.resolveComponent("ss-icon");
  8961. // 支持 panels(多分区),list/listMode 作为 legacy 兜底 by xu 20260106
  8962. const panels = (this.panels || []).length
  8963. ? this.panels
  8964. : this.list?.length
  8965. ? [
  8966. {
  8967. type: "list",
  8968. title: "已选",
  8969. icon: "",
  8970. mode: this.listMode,
  8971. items: this.list,
  8972. },
  8973. ]
  8974. : [];
  8975. // 功能说明:右侧栏强制移除“对象”tab(兼容后端返回 rbarObj/rbarobj 或直接返回中文“对象”标题) by xu 20260116
  8976. const panelsNoObj = (panels || []).filter((p) => {
  8977. const k = String(p?._tabKey ?? "")
  8978. .trim()
  8979. .toLowerCase();
  8980. const t = String(p?.title ?? "").trim();
  8981. if (k === "rbarobj") return false;
  8982. if (t === "对象") return false;
  8983. return true;
  8984. });
  8985. // 功能说明:report-table 作为底部报表区(放在统计图下面),不参与可拖拽 section 面板 by xu 20260115
  8986. const sectionPanels = panelsNoObj.filter(
  8987. (p) => p?.type !== "chart" && p?.type !== "report-table"
  8988. );
  8989. const chartPanels = panelsNoObj.filter((p) => p?.type === "chart");
  8990. const reportPanels = panelsNoObj.filter(
  8991. (p) => p?.type === "report-table"
  8992. );
  8993. this.ensureSectionHeights(sectionPanels.length);
  8994. // 功能说明:补齐 chart/report 折叠数组长度 by xu 20260116
  8995. this.chartCollapsed = Array.from(
  8996. { length: chartPanels.length },
  8997. (_, i) => !!this.chartCollapsed?.[i]
  8998. );
  8999. this.chartHeaderTitleDownAt = Array.from(
  9000. { length: chartPanels.length },
  9001. (_, i) => this.chartHeaderTitleDownAt?.[i] ?? 0
  9002. );
  9003. this.reportCollapsed = Array.from(
  9004. { length: reportPanels.length },
  9005. (_, i) => !!this.reportCollapsed?.[i]
  9006. );
  9007. return Vue.h("div", { class: "ss-sidebar" }, [
  9008. this.buttons?.length
  9009. ? Vue.h(SsSidebarButtonsComp, { items: this.buttons })
  9010. : null,
  9011. Vue.h(
  9012. "div",
  9013. { class: "ss-sidebar__inner" },
  9014. [
  9015. ...(this.charts || []).map((c) =>
  9016. Vue.h(SsSidebarChartComp, {
  9017. options: c?.options || {},
  9018. height: c?.height || "200px",
  9019. })
  9020. ),
  9021. // 可拖拽的业务面板容器 by xu 20260106
  9022. Vue.h(
  9023. "div",
  9024. { class: "ss-sidebar-sections", style: { flex: "0 0 auto" } },
  9025. sectionPanels.flatMap((p, idx) => {
  9026. const panelContent =
  9027. p?.type === "report-table"
  9028. ? Vue.h(SsSidebarReportTableComp, {
  9029. key: `ss-sidebar-report-in-section-${idx}-${
  9030. p?.title ?? ""
  9031. }`,
  9032. title: p?.title ?? "",
  9033. icon: p?.icon ?? "",
  9034. iconClass: p?.iconClass ?? "",
  9035. items: p?.items || [],
  9036. onOpen: (srv, ctx) => p?.onOpen?.(srv, ctx),
  9037. })
  9038. : Vue.h(SsSidebarListComp, {
  9039. key: `ss-sidebar-list-${idx}-${p?.title ?? ""}`,
  9040. title: p?.title ?? "",
  9041. icon: p?.icon ?? "",
  9042. count: p?.count ?? p?.items?.length ?? "",
  9043. closable: !!p?.closable,
  9044. searchable: !!p?.searchable,
  9045. searchInHeader: !!p?.searchInHeader,
  9046. headerFilters: p?.headerFilters || [],
  9047. headerSearchButton: !!p?.headerSearchButton,
  9048. searchPlaceholder: p?.searchPlaceholder ?? "搜索",
  9049. itemLayout: p?.itemLayout ?? "simple",
  9050. itemAction: p?.itemAction ?? true,
  9051. collapsible: true,
  9052. collapsed: !!this.sectionCollapsed?.[idx],
  9053. onToggleCollapse: () =>
  9054. this.toggleSectionCollapse?.(idx),
  9055. iconClass: p?.iconClass ?? "",
  9056. items: p?.items || [],
  9057. mode: p?.mode || "search",
  9058. onSelect: (item) => this.$emit("select", item),
  9059. onRemove: (item) => this.$emit("remove", item),
  9060. onClear: () => p?.onClear?.(),
  9061. onSearch: (payload) => p?.onSearch?.(payload),
  9062. });
  9063. const section = Vue.h(
  9064. "div",
  9065. {
  9066. class: {
  9067. "ss-sidebar-section": true,
  9068. "is-collapsed": !!this.sectionCollapsed?.[idx],
  9069. },
  9070. key: `ss-sidebar-section-${idx}-${p?.type ?? "list"}-${
  9071. p?.title ?? ""
  9072. }`,
  9073. style: {
  9074. height: (this.sectionHeights[idx] ?? 190) + "px",
  9075. flex: "0 0 auto",
  9076. },
  9077. },
  9078. [
  9079. Vue.h("div", { class: "ss-sidebar-section__content" }, [
  9080. panelContent,
  9081. ]),
  9082. ]
  9083. );
  9084. const gap =
  9085. idx < sectionPanels.length - 1
  9086. ? Vue.h("div", {
  9087. class: "ss-sidebar-gap",
  9088. onPointerdown: (e) => this.startResize(idx, e),
  9089. })
  9090. : null;
  9091. return gap ? [section, gap] : [section];
  9092. })
  9093. ),
  9094. // 图表区固定在底部(hover 弹出大图) by xu 20260106
  9095. ...chartPanels.map((p, chartIdx) =>
  9096. Vue.h(
  9097. "div",
  9098. {
  9099. class: {
  9100. "ss-sidebar-panel": true,
  9101. "ss-sidebar-chart-panel": true,
  9102. "is-collapsed": !!this.chartCollapsed?.[chartIdx],
  9103. },
  9104. style: { flex: "0 0 auto", minHeight: "37px" },
  9105. "data-chart-idx": chartIdx,
  9106. key: `ss-sidebar-chart-${chartIdx}-${p?.title ?? ""}`,
  9107. },
  9108. [
  9109. p?.title
  9110. ? Vue.h(
  9111. "div",
  9112. {
  9113. class: "ss-sidebar-panel__header",
  9114. onDblclick: (e) => {
  9115. e?.preventDefault?.();
  9116. e?.stopPropagation?.();
  9117. console.log("[SsSidebar] chart header dblclick", {
  9118. idx: chartIdx,
  9119. title: p?.title,
  9120. });
  9121. this.toggleChartCollapse?.(chartIdx);
  9122. },
  9123. },
  9124. [
  9125. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  9126. p?.iconClass
  9127. ? Vue.h(SsIcon, {
  9128. class:
  9129. p.iconClass + " ss-sidebar-panel__icon",
  9130. })
  9131. : p?.icon
  9132. ? Vue.h(SsIcon, {
  9133. name: p.icon,
  9134. size: "16px",
  9135. class: "ss-sidebar-panel__icon",
  9136. })
  9137. : null,
  9138. Vue.h("span", null, p.title),
  9139. ]),
  9140. Vue.h("div", { class: "ss-sidebar-panel__tools" }),
  9141. ]
  9142. )
  9143. : null,
  9144. this.chartCollapsed?.[chartIdx]
  9145. ? null
  9146. : Vue.h(Vue.resolveComponent("ss-sidebar-chart-hover"), {
  9147. title: p?.title ?? "",
  9148. iconClass: p?.iconClass ?? "",
  9149. icon: p?.icon ?? "",
  9150. options: p?.options || {},
  9151. height: p?.height || "240px",
  9152. }),
  9153. ]
  9154. )
  9155. ),
  9156. ...reportPanels.map((p, reportIdx) =>
  9157. Vue.h(
  9158. "div",
  9159. {
  9160. class: {
  9161. "ss-sidebar-report-panel-wrap": true,
  9162. "ss-sidebar-report-panel": true,
  9163. "is-collapsed": !!this.reportCollapsed?.[reportIdx],
  9164. },
  9165. style: { flex: "0 0 auto", minHeight: "37px" },
  9166. "data-report-idx": reportIdx,
  9167. key: `ss-sidebar-report-wrap-${reportIdx}-${p?.title ?? ""}`,
  9168. },
  9169. [
  9170. Vue.h(SsSidebarReportTableComp, {
  9171. key: `ss-sidebar-report-${reportIdx}-${p?.title ?? ""}`,
  9172. title: p?.title ?? "",
  9173. icon: p?.icon ?? "",
  9174. iconClass: p?.iconClass ?? "",
  9175. items: p?.items || [],
  9176. collapsible: true,
  9177. collapsed: !!this.reportCollapsed?.[reportIdx],
  9178. onToggleCollapse: () =>
  9179. this.toggleReportCollapse?.(reportIdx),
  9180. onOpen: (srv, ctx) => p?.onOpen?.(srv, ctx),
  9181. }),
  9182. ]
  9183. )
  9184. ),
  9185. ].filter(Boolean)
  9186. ),
  9187. ]);
  9188. },
  9189. };
  9190. // ss-folder-card 文件夹卡片
  9191. const SsFolderCard = {
  9192. name: "SsFolderCard",
  9193. props: {
  9194. item: {
  9195. type: Object,
  9196. required: true,
  9197. },
  9198. },
  9199. data() {
  9200. return {
  9201. showButtons: false,
  9202. };
  9203. },
  9204. emits: ["click", "change"],
  9205. setup(props, { emit }) {
  9206. const item = props.item;
  9207. const showChildren = ref(false);
  9208. const eventBus = window.parent.sharedEventBus;
  9209. const itemWidth = Vue.computed(() => {
  9210. // 功能说明:页面改为 grid 等分布局后,卡片宽度交给容器控制,这里固定 100% by xu 20260116
  9211. return "100%";
  9212. });
  9213. onMounted(() => {
  9214. eventBus.subscribe("folderPath", (path) => {
  9215. const currentPath = path || [];
  9216. // 如果当前文件夹不在路径中,则销毁视图
  9217. if (
  9218. !currentPath.some((item) => item.folder.title === props.item.title)
  9219. ) {
  9220. showChildren.value = false;
  9221. }
  9222. });
  9223. });
  9224. const onItemClick = (e) => {
  9225. if (e && e.stopPropagation) {
  9226. e.stopPropagation();
  9227. }
  9228. // 单击只处理 active 状态
  9229. if (e && e.currentTarget) {
  9230. const allListCards = document.querySelectorAll(
  9231. ".knowledge-item-container"
  9232. );
  9233. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  9234. allListCards.forEach((card) => card.classList.remove("active"));
  9235. allFolderCards.forEach((card) => card.classList.remove("active"));
  9236. e.currentTarget.classList.add("active");
  9237. } else {
  9238. // 如果是数据对象,需要找到对应的 DOM 元素
  9239. const allListCards = document.querySelectorAll(
  9240. ".knowledge-item-container"
  9241. );
  9242. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  9243. allListCards.forEach((card) => card.classList.remove("active"));
  9244. allFolderCards.forEach((card) => card.classList.remove("active"));
  9245. // 找到标题匹配的文件夹元素
  9246. const targetFolder = Array.from(allFolderCards).find((card) =>
  9247. card.textContent.includes(e.title)
  9248. );
  9249. if (targetFolder) {
  9250. targetFolder.classList.add("active");
  9251. }
  9252. }
  9253. emit("click", item);
  9254. };
  9255. // 修改双击处理函数
  9256. const handleFolderDblClick = (folder, e) => {
  9257. if (e) e.stopPropagation();
  9258. if (folder.children?.length) {
  9259. showChildren.value = true;
  9260. const pathInfo = {
  9261. title: folder.title,
  9262. folder: folder,
  9263. };
  9264. const currentPath = eventBus.getState("folderPath") || [];
  9265. if (!currentPath.some((item) => item.title === folder.title)) {
  9266. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  9267. }
  9268. }
  9269. };
  9270. const onItemChange = (e, icon, index) => {
  9271. e.stopPropagation();
  9272. props.item.buttons[0].onclick();
  9273. // emit("change", { item: props.item, icon, index });
  9274. };
  9275. return {
  9276. item,
  9277. itemWidth,
  9278. showChildren,
  9279. onItemClick,
  9280. onItemChange,
  9281. handleFolderDblClick,
  9282. };
  9283. },
  9284. render() {
  9285. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  9286. if (this.showChildren) {
  9287. return h(SsFolderCartView, {
  9288. folder: this.item,
  9289. });
  9290. }
  9291. return Vue.h(
  9292. "div",
  9293. {
  9294. class: { "ss-folder-list": true, active: this.item.active },
  9295. onClick: (e) => {
  9296. e.stopPropagation();
  9297. this.onItemClick(e);
  9298. },
  9299. onDblclick: (e) => this.handleFolderDblClick(this.item, e),
  9300. style: { width: this.itemWidth },
  9301. },
  9302. [
  9303. // 文件夹特有的装饰元素
  9304. Vue.h("div", { class: "ss-folder-list-trapezoid" }),
  9305. Vue.h("div", { class: "ss-folder-list-top-transparent" }),
  9306. Vue.h("div", { class: "ss-folder-list-top" }),
  9307. Vue.h("div", { class: "ss-folder-list-right" }),
  9308. // header 部分(按钮)
  9309. this.item?.buttons?.length > 0 &&
  9310. Vue.h(
  9311. "div",
  9312. {
  9313. class: "header",
  9314. onMouseenter: () => (this.showButtons = true),
  9315. onMouseleave: () => (this.showButtons = false),
  9316. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  9317. },
  9318. [
  9319. // this.item?.buttons?.length > 0 &&
  9320. Vue.h("div", {
  9321. class: "cart-list-setting cart-list-icon",
  9322. title: this.item?.buttons?.[0]?.title,
  9323. }),
  9324. // this.item?.buttons?.length > 0 &&
  9325. this.showButtons &&
  9326. this.item?.buttons?.length > 1 &&
  9327. Vue.h(
  9328. "div",
  9329. {
  9330. class: "cart-list-button-popup",
  9331. },
  9332. this.item.buttons.map((btn) =>
  9333. Vue.h(
  9334. "div",
  9335. {
  9336. onClick: (e) => {
  9337. e.stopPropagation();
  9338. btn.onclick?.();
  9339. },
  9340. },
  9341. [
  9342. btn.class &&
  9343. Vue.h(SsCartListIcon, {
  9344. class: [btn.class],
  9345. }),
  9346. Vue.h("span", null, btn.title),
  9347. ]
  9348. )
  9349. )
  9350. ),
  9351. ]
  9352. ),
  9353. // body 部分
  9354. Vue.h("div", { class: "body" }, [
  9355. Vue.h("div", { class: "box-header" }, [
  9356. Vue.h("div", null, this.item.title),
  9357. ]),
  9358. Vue.h(
  9359. "div",
  9360. {
  9361. class: !this.item.thumb ? "no-thumb box-body" : "box-body",
  9362. },
  9363. [
  9364. this.item.thumb
  9365. ? Vue.h("div", { class: "left" }, [
  9366. Vue.h("img", {
  9367. src: this.item.thumb,
  9368. alt: "Thumbnail",
  9369. class: "imgUnHandle",
  9370. style: {
  9371. "object-fit": "cover",
  9372. width: "100%",
  9373. height: "100%",
  9374. },
  9375. }),
  9376. ])
  9377. : null,
  9378. Vue.h("div", { class: "right" }, [
  9379. ...this.item.tags.map((tag) => {
  9380. const [key, value] = Object.entries(tag)[0];
  9381. return Vue.h(
  9382. "div",
  9383. {
  9384. class: "title",
  9385. title: `${key}: ${value}`,
  9386. },
  9387. `${key}: ${value}`
  9388. );
  9389. }),
  9390. ]),
  9391. ]
  9392. ),
  9393. ]),
  9394. ]
  9395. );
  9396. },
  9397. };
  9398. // SsFolderCartView 组件 - 用于显示文件夹内容
  9399. const SsFolderCartView = {
  9400. name: "SsFolderCartView",
  9401. props: {
  9402. folder: {
  9403. type: Object,
  9404. required: true,
  9405. },
  9406. },
  9407. emits: ["click"],
  9408. setup(props, { emit }) {
  9409. const eventBus = window.parent.sharedEventBus;
  9410. const currentFolder = ref(props.folder);
  9411. const showChildren = ref(false);
  9412. const onItemClick = (e) => {
  9413. if (e && e.stopPropagation) {
  9414. e.stopPropagation();
  9415. }
  9416. // 单击只处理 active 状态
  9417. if (e && e.currentTarget) {
  9418. const allListCards = document.querySelectorAll(
  9419. ".knowledge-item-container"
  9420. );
  9421. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  9422. allListCards.forEach((card) => card.classList.remove("active"));
  9423. allFolderCards.forEach((card) => card.classList.remove("active"));
  9424. e.currentTarget.classList.add("active");
  9425. } else {
  9426. // 如果是数据对象,需要找到对应的 DOM 元素
  9427. const allListCards = document.querySelectorAll(
  9428. ".knowledge-item-container"
  9429. );
  9430. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  9431. allListCards.forEach((card) => card.classList.remove("active"));
  9432. allFolderCards.forEach((card) => card.classList.remove("active"));
  9433. // 找到标题匹配的文件夹元素
  9434. const targetFolder = Array.from(allFolderCards).find((card) =>
  9435. card.textContent.includes(e.title)
  9436. );
  9437. if (targetFolder) {
  9438. targetFolder.classList.add("active");
  9439. }
  9440. }
  9441. emit("click", props.folder);
  9442. };
  9443. const handleFolderDblClick = (folder, e) => {
  9444. if (e) e.stopPropagation();
  9445. if (folder.children?.length) {
  9446. showChildren.value = true;
  9447. const pathInfo = {
  9448. title: folder.title,
  9449. folder: folder,
  9450. };
  9451. const currentPath = eventBus.getState("folderPath") || [];
  9452. if (!currentPath.some((item) => item.title === folder.title)) {
  9453. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  9454. currentFolder.value = folder;
  9455. }
  9456. }
  9457. };
  9458. const goBack = (targetFolder) => {
  9459. if (targetFolder === null) {
  9460. // 返回根目录
  9461. eventBus.publish("folderPath", []);
  9462. } else {
  9463. currentFolder.value = targetFolder;
  9464. }
  9465. };
  9466. return {
  9467. currentFolder,
  9468. showChildren,
  9469. onItemClick,
  9470. handleFolderDblClick,
  9471. goBack,
  9472. };
  9473. },
  9474. render() {
  9475. return h(
  9476. "div",
  9477. {
  9478. class: "page-container",
  9479. style: {
  9480. position: "fixed",
  9481. top: 0,
  9482. left: 0,
  9483. width: "100%",
  9484. height: "100%",
  9485. background: "var(--lightgray)",
  9486. padding: "20px 0",
  9487. zIndex: 1000,
  9488. },
  9489. },
  9490. [
  9491. // 搜索栏
  9492. h("div", { class: "search-bar" }, [
  9493. h("div", { class: "search-bar-container" }, [
  9494. h(SsBreadcrumb, {
  9495. level: {
  9496. onBack: this.goBack,
  9497. },
  9498. }),
  9499. ]),
  9500. ]),
  9501. // 内容区域
  9502. h(
  9503. "div",
  9504. {
  9505. class: "content-area item-content-area",
  9506. style: { gap: "20px" },
  9507. },
  9508. [
  9509. ...(this.currentFolder.children || []).map((child, index) =>
  9510. h(child.children ? SsFolderCard : SsListCard, {
  9511. key: index,
  9512. item: child,
  9513. onClick: (e) => this.onItemClick(e),
  9514. onDblclick: (e) => this.handleFolderDblClick(child, e),
  9515. })
  9516. ),
  9517. ]
  9518. ),
  9519. ]
  9520. );
  9521. },
  9522. };
  9523. // ss-page分页
  9524. const SsPage = {
  9525. name: "SsPage",
  9526. props: {
  9527. total: {
  9528. type: Number,
  9529. required: true,
  9530. },
  9531. size: {
  9532. type: Number,
  9533. default: 10,
  9534. },
  9535. page: {
  9536. type: Number,
  9537. default: 1,
  9538. },
  9539. onChange: {
  9540. type: Function,
  9541. default: () => {},
  9542. },
  9543. },
  9544. setup(props) {
  9545. const totalItems = ref(props.total); // 总条目数
  9546. const totalPages = ref(Math.ceil(props.total / props.size));
  9547. const currentPage = ref(props.page); // 当前页码
  9548. // 计算显示的信息
  9549. const pageInfo = ref(
  9550. `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`
  9551. );
  9552. // 上一页的逻辑
  9553. const goToPreviousPage = (e) => {
  9554. e.preventDefault(); // 阻止默认行为
  9555. if (currentPage.value > 1) {
  9556. currentPage.value -= 1;
  9557. updatePageInfo();
  9558. props.onChange?.({
  9559. pageNo: currentPage.value, // 当前页码
  9560. rowNumPer: props.size, // 每页条数
  9561. rowNum: props.total, // 总记录数
  9562. });
  9563. }
  9564. };
  9565. // 下一页的逻辑
  9566. const goToNextPage = (e) => {
  9567. e.preventDefault(); // 阻止默认行为
  9568. if (currentPage.value < totalPages.value) {
  9569. currentPage.value += 1;
  9570. updatePageInfo();
  9571. props.onChange?.({
  9572. pageNo: currentPage.value, // 当前页码
  9573. rowNumPer: props.size, // 每页条数
  9574. rowNum: props.total, // 总记录数
  9575. });
  9576. }
  9577. };
  9578. // 更新页码信息的函数
  9579. const updatePageInfo = () => {
  9580. pageInfo.value = `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`;
  9581. };
  9582. return {
  9583. pageInfo,
  9584. totalPages,
  9585. goToPreviousPage,
  9586. goToNextPage,
  9587. };
  9588. },
  9589. render(props, { slots, emit }) {
  9590. return Vue.h("div", { class: "pager-container" }, [
  9591. Vue.h("input", { type: "hidden", name: "rowNum", value: props.total }),
  9592. Vue.h("input", {
  9593. type: "hidden",
  9594. name: "rowNumPer",
  9595. value: props.size,
  9596. }),
  9597. Vue.h("input", {
  9598. type: "hidden",
  9599. name: "pageCount",
  9600. value: this.totalPages,
  9601. }),
  9602. Vue.h("input", { type: "hidden", name: "pageNo", value: props.page }),
  9603. Vue.h("div", { class: "pager-content" }, [
  9604. Vue.h("div", { class: "info" }, this.pageInfo),
  9605. Vue.h(
  9606. "div",
  9607. { class: "btn" },
  9608. Vue.h(
  9609. "button",
  9610. { onClick: (e) => this.goToPreviousPage(e) },
  9611. "上一页"
  9612. )
  9613. ),
  9614. Vue.h(
  9615. "div",
  9616. { class: "btn" },
  9617. Vue.h("button", { onClick: (e) => this.goToNextPage(e) }, "下一页")
  9618. ),
  9619. ]),
  9620. ]);
  9621. },
  9622. };
  9623. // ss-right-info 一级页面右边栏
  9624. const SSRightInfo = {
  9625. name: "SSRightInfo",
  9626. setup() {
  9627. // 初始化响应式数据
  9628. const item = ref({
  9629. thumb: "images/example/project-img.png", // 更换为适合你项目的实际路径
  9630. title: "工业和信息化产业高质量发展资金",
  9631. });
  9632. return {
  9633. item,
  9634. };
  9635. },
  9636. render() {
  9637. return Vue.h("div", { class: "info-container" }, [
  9638. Vue.h("div", { class: "header" }, [
  9639. Vue.h("div", [
  9640. Vue.h("img", {
  9641. src: this.item.thumb,
  9642. class: "imgUnHandle",
  9643. style: { "object-fit": "cover", width: "100%", height: "100%" },
  9644. }), // 将 ImageViewer 替换为 img 标签
  9645. ]),
  9646. Vue.h("div", [Vue.h("div", this.item.title)]),
  9647. ]),
  9648. Vue.h("div", { class: "section-container" }, [
  9649. Vue.h("div", { class: "section" }, [
  9650. Vue.h("div", { class: "title" }, "合同"),
  9651. Vue.h("div", { class: "text" }, "合同总金额:42,399,320"),
  9652. Vue.h(
  9653. "div",
  9654. { class: "a" },
  9655. "《工业和信息化产业高质量发展资金补助合同》"
  9656. ),
  9657. ]),
  9658. Vue.h("div", { class: "section" }, [
  9659. Vue.h("div", { class: "title" }, "发票"),
  9660. Vue.h("div", { class: "text" }, "应开发票总额:42,399,320"),
  9661. Vue.h("div", { class: "text" }, "已开发票金额:17,235,345"),
  9662. Vue.h("div", { class: "text" }, "未开发票金额:25,163,975"),
  9663. ]),
  9664. Vue.h("div", { class: "section" }, [
  9665. Vue.h("div", { class: "title" }, "项目组成员"),
  9666. Vue.h("div", { class: "text" }, "我司:3人"),
  9667. Vue.h("div", { class: "text" }, "对方:2人"),
  9668. Vue.h("div", { class: "text" }, "项目负责人:张三"),
  9669. ]),
  9670. Vue.h("div", { class: "section" }, [
  9671. Vue.h("div", { class: "title" }, "采购"),
  9672. Vue.h("div", { class: "text" }, "总额:999,320"),
  9673. Vue.h("div", { class: "text" }, "已付金额:335,345"),
  9674. Vue.h("div", { class: "text" }, "未付金额:663,975"),
  9675. ]),
  9676. ]),
  9677. ]);
  9678. },
  9679. };
  9680. //
  9681. const SsSuccessPopup = {
  9682. name: "SsSuccessPopup",
  9683. props: {
  9684. right: {
  9685. type: String,
  9686. default: "20px",
  9687. },
  9688. bottom: {
  9689. type: String,
  9690. default: "calc(100% + 5px)",
  9691. },
  9692. },
  9693. setup(props, { expose }) {
  9694. // 响应式状态:是否可见
  9695. const visible = ref(false);
  9696. // 计算样式
  9697. const style = computed(() => {
  9698. return {
  9699. "--message-dialog-right": props.right,
  9700. "--message-dialog-bottom": props.bottom,
  9701. };
  9702. });
  9703. // 显示对话框的方法
  9704. const show = () => {
  9705. visible.value = true;
  9706. };
  9707. // 隐藏对话框的方法
  9708. const hide = () => {
  9709. visible.value = false;
  9710. };
  9711. // 将方法暴露给外部使用
  9712. expose({ show, hide });
  9713. // 返回渲染函数
  9714. return () => {
  9715. if (!visible.value) return null;
  9716. const SsIcon = resolveComponent("ss-icon");
  9717. return h(
  9718. "div",
  9719. {
  9720. class: "success-popup",
  9721. style: style.value,
  9722. onClick: (e) => e.stopPropagation(),
  9723. },
  9724. [
  9725. h("div", { class: "left" }, [
  9726. h("div", { class: "icon" }, [
  9727. h(SsIcon, { name: "check", size: "36px" }),
  9728. ]),
  9729. ]),
  9730. h("div", { class: "right" }, [
  9731. h("div", { class: "title" }, "提交成功"),
  9732. h("div", { class: "desc" }, "您的信息已成功提交。"),
  9733. ]),
  9734. ]
  9735. );
  9736. };
  9737. },
  9738. };
  9739. const SsErrorDialog = {
  9740. name: "SsErrorDialog",
  9741. setup(props, { emit }) {
  9742. const visible = ref(false);
  9743. const style = computed(() => {
  9744. return {};
  9745. });
  9746. const show = () => {
  9747. visible.value = true;
  9748. };
  9749. const hide = () => {
  9750. visible.value = false;
  9751. };
  9752. const onBack = () => {
  9753. emit("back");
  9754. hide();
  9755. };
  9756. return {
  9757. visible,
  9758. style,
  9759. show,
  9760. hide,
  9761. onBack,
  9762. };
  9763. },
  9764. render() {
  9765. const SsIcon = resolveComponent("ss-icon");
  9766. return this.visible
  9767. ? h(
  9768. "div",
  9769. {
  9770. class: "errorDialog",
  9771. style: this.style,
  9772. onClick: (event) => event.stopPropagation(),
  9773. },
  9774. [
  9775. h("div", { class: "body" }, [
  9776. h("div", { class: "left" }, [
  9777. h("div", { class: "icon" }, [
  9778. h(SsIcon, { name: "close", size: "36px" }),
  9779. ]),
  9780. ]),
  9781. h("div", { class: "right" }, [
  9782. h("div", { class: "title" }, "操作失败"),
  9783. h("div", { class: "desc" }, "请点击返回以继续。"),
  9784. ]),
  9785. ]),
  9786. h("div", { class: "footer" }, [
  9787. h("div", { class: "left" }),
  9788. h("div", { class: "right" }, [
  9789. h(
  9790. "div",
  9791. {
  9792. class: "btn",
  9793. onClick: this.onBack,
  9794. },
  9795. [h(SsIcon, { name: "arrow-left-line" }), h("div", "返回")]
  9796. ),
  9797. ]),
  9798. ]),
  9799. ]
  9800. )
  9801. : null;
  9802. },
  9803. };
  9804. /**
  9805. * 审核链条
  9806. * <ss-verify
  9807. * @param { Array } verify-list 审核节点列表
  9808. * @property { Array } verify-list 审核节点列表
  9809. * @example <ss-verify :verify-list="verifyList"></ss-verify>
  9810. * verify-list [
  9811. * {
  9812. * groupName: "", // 群组名称
  9813. * open: true, // 默认是否展开
  9814. * children:[ //群组里的人员
  9815. * {
  9816. * thumb: "images/example/user-4.png", // 头像
  9817. * name: "李丽思 ", // 姓名
  9818. * role: "人事处处长", // 角色
  9819. * description: "同意。", // 审核意见
  9820. * time: "09:38 08/11", // 审核时间
  9821. * video: false, // false不显示/true显示 视频icon
  9822. * link: false, // false不显示/true显示 链接icon 后续应该是附件
  9823. * }
  9824. * ]
  9825. * }
  9826. * ]
  9827. */
  9828. const SsVerify = {
  9829. name: "SsVerify",
  9830. props: {
  9831. verifyList: {
  9832. type: Array,
  9833. required: true,
  9834. },
  9835. },
  9836. setup(props) {
  9837. const toggleOpen = (item) => {
  9838. item.open = !item.open;
  9839. };
  9840. onMounted(() => {
  9841. setTimeout(() => {
  9842. const lastOpenGroup = document.querySelector(".group-item-last-open");
  9843. console.log("lastOpenGroup", lastOpenGroup);
  9844. if (lastOpenGroup) {
  9845. const nodes = $(lastOpenGroup).find(".verify-node-container");
  9846. if (nodes.length) {
  9847. let totalHeight = 0;
  9848. const gudingHeight = 100;
  9849. if (nodes.length === 1) {
  9850. totalHeight = gudingHeight;
  9851. } else {
  9852. // 累加除最后一个节点外的所有节点高度
  9853. for (let i = 0; i < nodes.length - 1; i++) {
  9854. totalHeight += $(nodes[i]).outerHeight();
  9855. }
  9856. totalHeight += gudingHeight;
  9857. }
  9858. console.log("节点信息:", {
  9859. 节点总数: nodes.length,
  9860. 计算后的高度: totalHeight,
  9861. });
  9862. lastOpenGroup.style.setProperty(
  9863. "--group-line-height",
  9864. `${totalHeight}px`
  9865. );
  9866. }
  9867. }
  9868. }, 0);
  9869. });
  9870. return {
  9871. toggleOpen,
  9872. };
  9873. },
  9874. render() {
  9875. const SsIcon = resolveComponent("ss-icon");
  9876. const SsCommonIcon = resolveComponent("ss-common-icon");
  9877. const SsVerifyNode = resolveComponent("ss-verify-node");
  9878. return h(
  9879. "div",
  9880. { class: "verify-nodes" },
  9881. this.verifyList.map((item, i) =>
  9882. h(
  9883. "div",
  9884. {
  9885. key: i,
  9886. class: {
  9887. "group-item": true,
  9888. "group-item-last-open":
  9889. i === this.verifyList.length - 1 && item.open,
  9890. },
  9891. },
  9892. [
  9893. h(
  9894. "div",
  9895. {
  9896. class: "group-item-title",
  9897. onClick: () => this.toggleOpen(item),
  9898. },
  9899. [
  9900. h("div", { class: "icon" }, [
  9901. item.open
  9902. ? h(SsCommonIcon, { class: "common-icon-folder-open" })
  9903. : h(SsCommonIcon, { class: "common-icon-folder-close" }),
  9904. h(
  9905. "div",
  9906. {
  9907. class: "num",
  9908. style: { top: item.open ? "60%" : "55%" },
  9909. },
  9910. item.children?.length || 0
  9911. ),
  9912. ]),
  9913. h("div", { class: "name" }, item.groupName),
  9914. ]
  9915. ),
  9916. item.open && item.children?.length > 0
  9917. ? h(
  9918. "div",
  9919. { class: "group-item-children" },
  9920. item.children.map((citem, j) =>
  9921. h(SsVerifyNode, {
  9922. key: j,
  9923. item: citem,
  9924. // isGroup: i + 1 !== this.verifyList.length,
  9925. isGroup: true,
  9926. })
  9927. )
  9928. )
  9929. : null,
  9930. ]
  9931. )
  9932. )
  9933. );
  9934. },
  9935. };
  9936. /**
  9937. * 审核页面的审核节点
  9938. * <ss-verify-node
  9939. * @param {Object} item 审核节点信息
  9940. * @param {Boolean} isGroup 是否为分组节点
  9941. */
  9942. const SsVerifyNode = {
  9943. name: "SsVerifyNode",
  9944. props: {
  9945. item: {
  9946. type: Object,
  9947. required: true,
  9948. },
  9949. isGroup: {
  9950. type: Boolean,
  9951. default: false,
  9952. },
  9953. },
  9954. render() {
  9955. const SsIcon = resolveComponent("ss-icon");
  9956. const SsCommonIcon = resolveComponent("ss-common-icon");
  9957. return Vue.h("div", { class: "verify-node-container" }, [
  9958. Vue.h("div", { class: "info" }, [
  9959. Vue.h("div", { class: "avatar" }, [
  9960. Vue.h("img", {
  9961. src: this.item.thumb,
  9962. style: {
  9963. width: "50px",
  9964. height: "50px",
  9965. borderRadius: "50%",
  9966. },
  9967. }),
  9968. ]),
  9969. Vue.h("div", { class: "desc" }, [
  9970. Vue.h("div", this.item.name),
  9971. Vue.h("div", this.item.role),
  9972. ]),
  9973. Vue.h("div", { class: "link" }, [
  9974. Vue.h("div", [
  9975. this.item.video
  9976. ? Vue.h(SsCommonIcon, { class: "common-icon-video" })
  9977. : null,
  9978. this.item.link
  9979. ? Vue.h(SsCommonIcon, {
  9980. class: "common-icon-paper-clip",
  9981. })
  9982. : null,
  9983. ]),
  9984. ]),
  9985. ]),
  9986. Vue.h(
  9987. "div",
  9988. {
  9989. class: {
  9990. description: true,
  9991. link: this.isGroup,
  9992. },
  9993. attrs: { "data-num": "3" },
  9994. },
  9995. [Vue.h("div", this.item.description)]
  9996. ),
  9997. Vue.h("div", { class: "time" }, this.item.time),
  9998. ]);
  9999. },
  10000. };
  10001. /**
  10002. * 智能识别图片的左侧图片播放 可以放大缩小旋转图片
  10003. * <ss-orc-img-box
  10004. * @param { Object } image-obj 包含图片的url, 和图片的名称
  10005. *
  10006. */
  10007. const SsOrcImgBox = {
  10008. name: "SsOrcImgBox",
  10009. props: {
  10010. imageObj: {
  10011. type: Object,
  10012. required: true,
  10013. },
  10014. },
  10015. setup(props) {
  10016. const zoom = ref(1);
  10017. const rotation = ref(0);
  10018. const containerWidth = ref(0);
  10019. const containerHeight = ref(0);
  10020. const container = ref(null);
  10021. const imgPosition = ref({ x: 0, y: 0 });
  10022. const isDragging = ref(false);
  10023. const lastMousePosition = ref({ x: 0, y: 0 });
  10024. const imgStyle = computed(() => ({
  10025. width: `${zoom.value * 100}%`,
  10026. height: `${zoom.value * 100}%`,
  10027. transform: `rotate(${rotation.value}deg) translate(${imgPosition.value.x}px, ${imgPosition.value.y}px)`,
  10028. transformOrigin: "center center",
  10029. cursor: isDragging.value ? "grabbing" : "grab",
  10030. }));
  10031. const resetZoom = () => {
  10032. zoom.value = 1;
  10033. rotation.value = rotation.value + 90;
  10034. imgPosition.value = { x: 0, y: 0 };
  10035. };
  10036. const handleRangeChange = (event) => {
  10037. const value = event.target.value / 50; // 0 到 100 映射到 0 到 2 的缩放
  10038. zoom.value = Math.max(value, 0.1); // 设置最小缩放值为 0.1
  10039. };
  10040. const updateImgBoxDimensions = () => {
  10041. if (container.value) {
  10042. containerWidth.value = container.value.clientWidth;
  10043. containerHeight.value = container.value.clientHeight;
  10044. }
  10045. };
  10046. const onMouseDown = (event) => {
  10047. isDragging.value = true;
  10048. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  10049. };
  10050. const onMouseMove = (event) => {
  10051. if (isDragging.value) {
  10052. const dx = event.clientX - lastMousePosition.value.x;
  10053. const dy = event.clientY - lastMousePosition.value.y;
  10054. // 防止旋转后拖动的x,y反转
  10055. // 首先将当前旋转角度从度数转换为弧度,因为 JavaScript 的 Math 库使用弧度
  10056. const angle = rotation.value * (Math.PI / 180);
  10057. // 使用基本的二维旋转矩阵将原始位移 dx 和 dy 转换为旋转后的位移 rotatedDx 和 rotatedDy。
  10058. const rotatedDx = dx * Math.cos(angle) + dy * Math.sin(angle);
  10059. const rotatedDy = dy * Math.cos(angle) - dx * Math.sin(angle);
  10060. imgPosition.value = {
  10061. x: imgPosition.value.x + rotatedDx,
  10062. y: imgPosition.value.y + rotatedDy,
  10063. };
  10064. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  10065. }
  10066. };
  10067. const onMouseUp = () => {
  10068. isDragging.value = false;
  10069. };
  10070. onMounted(() => {
  10071. nextTick(() => {
  10072. updateImgBoxDimensions();
  10073. window.addEventListener("resize", updateImgBoxDimensions);
  10074. window.addEventListener("mousemove", onMouseMove);
  10075. window.addEventListener("mouseup", onMouseUp);
  10076. });
  10077. });
  10078. return {
  10079. zoom,
  10080. rotation,
  10081. container,
  10082. imgStyle,
  10083. resetZoom,
  10084. handleRangeChange,
  10085. containerWidth,
  10086. containerHeight,
  10087. onMouseDown,
  10088. imgPosition,
  10089. };
  10090. },
  10091. render() {
  10092. const SsIcon = resolveComponent("ss-icon");
  10093. return h("div", { class: "ocr-img-box" }, [
  10094. h("div", { class: "img-bar" }, [
  10095. h("div", this.imageObj.name),
  10096. h("div", { class: "action-bar" }, [
  10097. h("div", { class: "ocr-img-range-box" }, [
  10098. h("input", {
  10099. type: "range",
  10100. min: 0,
  10101. max: 100,
  10102. value: this.zoom * 50, // 初始位置为50
  10103. onInput: this.handleRangeChange,
  10104. }),
  10105. h("span", { class: "line" }),
  10106. ]),
  10107. h(SsIcon, {
  10108. name: "reset",
  10109. size: "26px",
  10110. onClick: this.resetZoom,
  10111. }),
  10112. ]),
  10113. ]),
  10114. h("div", { class: "img-viewer", ref: "container" }, [
  10115. h(
  10116. "div",
  10117. {
  10118. class: "img-box",
  10119. style: {
  10120. width: `${this.containerWidth}px`,
  10121. height: `${this.containerHeight}px`,
  10122. overflow: "hidden",
  10123. position: "relative",
  10124. },
  10125. },
  10126. [
  10127. h("img", {
  10128. src: this.imageObj.thumb,
  10129. style: this.imgStyle,
  10130. class: "zoomable-img",
  10131. onMousedown: this.onMouseDown,
  10132. }),
  10133. ]
  10134. ),
  10135. ]),
  10136. ]);
  10137. },
  10138. };
  10139. // 搜索输入框组件
  10140. const SsSearchInput = {
  10141. name: "SsSearchInput",
  10142. props: {
  10143. name: String,
  10144. placeholder: String,
  10145. width: {
  10146. type: String,
  10147. default: "100px",
  10148. },
  10149. modelValue: String,
  10150. },
  10151. emits: ["update:modelValue", "search"],
  10152. setup(props, { emit }) {
  10153. const handleInput = (e) => {
  10154. emit("update:modelValue", e.target.value);
  10155. };
  10156. const handleKeyup = (e) => {
  10157. if (e.key === "Enter") {
  10158. /* 再改,增加 @search= 入口参数 -- ddp 的父对象查询列表内容。Lin
  10159. * 与 <ss-ccp、<ss-objp 的对齐 -- <ss-search-input 里的 @search="savePobjSearchKeyByVue",会调用 savePobjSearchKey(val, desc, name)
  10160. emit("search");
  10161. */ emit("search", props.modelValue, null, props.name);
  10162. }
  10163. };
  10164. /// 增加,阻止按回车提交 <form。Lin
  10165. const handleKeydown = (e) => {
  10166. if (e.key === "Enter")
  10167. e.preventDefault(); // 阻止默认行为
  10168. };
  10169. ///
  10170. /// 再增加,增加失去焦点时也查询 -- ddp 的父对象查询列表内容。Lin
  10171. const onBlur = (event) => {
  10172. /* 再改,增加 @search= 入口参数 -- ddp 的父对象查询列表内容。Lin
  10173. * 与 <ss-ccp、<ss-objp 的对齐 -- <ss-search-input 里的 @search="savePobjSearchKeyByVue",会调用 savePobjSearchKey(val, desc, name)
  10174. emit("search");
  10175. */ emit("search", props.modelValue, null, props.name);
  10176. }
  10177. ///
  10178. return { handleInput, handleKeyup,
  10179. handleKeydown, // 增加,阻止按回车提交 <form。Lin
  10180. onBlur, // 再增加,增加失去焦点时也查询 -- ddp 的父对象查询列表内容。Lin
  10181. };
  10182. },
  10183. render() {
  10184. return h(
  10185. "div",
  10186. {
  10187. class: "input",
  10188. style: this.width ? { width: this.width } : undefined,
  10189. },
  10190. [
  10191. h("input", {
  10192. name: this.name,
  10193. placeholder: this.placeholder,
  10194. value: this.modelValue,
  10195. onInput: this.handleInput,
  10196. onKeyup: this.handleKeyup,
  10197. onKeydown: this.handleKeydown, // 增加,阻止按回车提交 <form。Lin
  10198. onBlur: this.onBlur, // 再增加,增加失去焦点时也查询 -- ddp 的父对象查询列表内容。Lin
  10199. }),
  10200. ]
  10201. );
  10202. },
  10203. };
  10204. ///// 再增加,增加数值拣选器 SsNump(<ss-nump) -- 抄自 SsSearchInput(<ss-search-input)。Lin
  10205. // 搜索输入框组件
  10206. const SsNump = {
  10207. name: "SsNump",
  10208. props: {
  10209. onchange: {
  10210. type: String,
  10211. required: false,
  10212. },
  10213. name: String,
  10214. defVal: {
  10215. type: Number,
  10216. default: 0,
  10217. },
  10218. minVal: Number,
  10219. maxVal: Number,
  10220. tabIndex: {
  10221. type: Number,
  10222. default: -1,
  10223. },
  10224. desc: String,
  10225. // placeholder: String, // 去掉,没用到。Lin
  10226. width: {
  10227. type: String,
  10228. default: "60px",
  10229. },
  10230. modelValue: Number,
  10231. /// 增加,增加 -1、+1 按钮 -- 抄自 SsSearchButton。Lin
  10232. decWidth: {
  10233. type: String,
  10234. required: false,
  10235. default: "45px",
  10236. },
  10237. incWidth: {
  10238. type: String,
  10239. required: false,
  10240. default: "45px",
  10241. },
  10242. ///
  10243. },
  10244. emits: ["update:modelValue", "update:inputValue", "update:localDefVal"],
  10245. setup(props, { emit }) {
  10246. const localDefVal = ref(props.defVal); // 再增加,提供 window.wrDefValsqljcxm1( 了。Lin
  10247. ///// 抄自 SsInput。Lin
  10248. const inputValue = ref(props.defVal);
  10249. // 功能说明:调用全局 onChange 回调 by xu 20260416
  10250. const callGlobalOnchg = (value) => {
  10251. if (props.onchange && typeof props.onchange === "string") {
  10252. if (
  10253. typeof window !== "undefined" &&
  10254. window[props.onchange] &&
  10255. typeof window[props.onchange] === "function"
  10256. ) {
  10257. try {
  10258. window[props.onchange](value);
  10259. } catch (error) {
  10260. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  10261. }
  10262. }
  10263. }
  10264. };
  10265. watch(
  10266. () => props.modelValue,
  10267. (newVal) => {
  10268. // inputValue.value = newVal; // 去掉,不需要再赋值。Lin
  10269. // 桥接 API 赋值时触发全局 onChange by xu 20260416
  10270. callGlobalOnchg(newVal);
  10271. }
  10272. );
  10273. /// 再增加,监听另一个变量 inputValue -- 上面的监听 props.modelValue 只是在初始化时触发一次,后面没有再被触发。Lin
  10274. watch(inputValue, (v) => {
  10275. // emit('update:modelValue', v)
  10276. callGlobalOnchg(v)
  10277. })
  10278. ///
  10279. // 挂载时的逻辑
  10280. onMounted(() => {
  10281. /// 再增加,在页面调用 window.ssnwjcxmm<项目码> 来设置默认值。Lin
  10282. /* 再改,改为 wrCurVal、wrCurValByMinVal、wrCurValByMaxVal、wrDefVal。Lin
  10283. window[props.name] = setDefVal;
  10284. */
  10285. window["wrCurVal"+ props.name] = wrCurVal; // 写当前值。Lin
  10286. window["wrCurValByMinVal"+ props.name] = wrCurValByMinVal; // 写当前值为最小值。Lin
  10287. window["wrCurValByMaxVal"+ props.name] = wrCurValByMaxVal; // 写当前值为最大值。Lin
  10288. window["wrDefVal"+ props.name] = wrDefVal; // 改写默认值。Lin
  10289. ///
  10290. // errMsg.value = props.errTip; // 去掉。Lin
  10291. inputValue.value = props.defVal;
  10292. localDefVal.value = props.defVal; // 再增加,提供 window.wrDefValsqljcxm1( 了。Lin
  10293. refreshNump();
  10294. emit("update:modelValue", inputValue.value);
  10295. emit("update:inputValue", inputValue.value);
  10296. emit("update:localDefVal", localDefVal.value); // 再增加,提供 window.wrDefValsqljcxm1( 了。Lin
  10297. });
  10298. /// 再增加,在页面调用 window.ssnwjcxmm<项目码> 来设置默认值。Lin
  10299. // 在组件卸载时移除全局变量
  10300. Vue.onUnmounted(() => {
  10301. let key = "wrCurVal"+ props.name;
  10302. if (window.hasOwnProperty(key)) {
  10303. delete window[key];
  10304. }
  10305. key = "wrCurValByMinVal"+ props.name;
  10306. if (window.hasOwnProperty(key)) {
  10307. delete window[key];
  10308. }
  10309. key = "wrCurValByMaxVal"+ props.name;
  10310. if (window.hasOwnProperty(key)) {
  10311. delete window[key];
  10312. }
  10313. key = "wrDefVal"+ props.name;
  10314. if (window.hasOwnProperty(key)) {
  10315. delete window[key];
  10316. }
  10317. })
  10318. const wrCurVal = (val) => {
  10319. let v;
  10320. if (val < props.minVal)
  10321. v = props.minVal;
  10322. else if (props.maxVal != null && val > props.maxVal)
  10323. v = props.maxVal;
  10324. else
  10325. v = val;
  10326. inputValue.value = v;
  10327. refreshNump();
  10328. emit("update:modelValue", inputValue.value);
  10329. }
  10330. const wrCurValByMinVal = () => {
  10331. inputValue.value = props.minVal;
  10332. refreshNump();
  10333. emit("update:modelValue", inputValue.value);
  10334. }
  10335. const wrCurValByMaxVal = () => {
  10336. inputValue.value = props.maxVal;
  10337. refreshNump();
  10338. emit("update:modelValue", inputValue.value);
  10339. }
  10340. const wrDefVal = (defVal) => {
  10341. let v;
  10342. if (defVal < props.minVal)
  10343. v = props.minVal;
  10344. else if (props.maxVal != null && defVal > props.maxVal)
  10345. v = props.maxVal;
  10346. else
  10347. v = defVal;
  10348. localDefVal.value = v;
  10349. inputValue.value = v;
  10350. refreshNump();
  10351. emit("update:modelValue", inputValue.value);
  10352. }
  10353. ///
  10354. // 定义事件处理函数
  10355. /* 去掉,不用 onInput,只用 onChange。Lin
  10356. const onInput = (event) => {
  10357. const newValue = event.target.value;
  10358. inputValue.value = newValue;
  10359. emit("update:modelValue", newValue);
  10360. };
  10361. */
  10362. const onChange = (event) => {
  10363. let val = parseInt(event.target.value, 10) || 0;
  10364. if (props.maxVal != null) { // 等价于 !== null && !== undefined,有指定 maxVal=。不能使用 (props.maxVal),0 会被判为不成立。Lin
  10365. if (val > props.maxVal)
  10366. val = props.maxVal;
  10367. }
  10368. if (props.minVal != null) { // 等价于 !== null && !== undefined,有指定 minVal=。不能使用 (props.minVal),0 会被判为不成立。Lin
  10369. if (val < props.minVal)
  10370. val = props.minVal;
  10371. }
  10372. inputValue.value = val;
  10373. refreshNump();
  10374. /* 改,不用 onInput,只用 onChange。Lin
  10375. emit("change", inputValue.value);
  10376. */ emit("update:modelValue", inputValue.value);
  10377. };
  10378. /////
  10379. /// 增加,增加 -1、+1 按钮 -- 抄自 SsSearchButton。Lin
  10380. const decClick = (e) => {
  10381. e.preventDefault();
  10382. if (props.minVal != null) { // 等价于 !== null && !== undefined,有指定 minVal=。不能使用 (props.minVal),0 会被判为不成立。Lin
  10383. if (inputValue.value > props.minVal)
  10384. inputValue.value -= 1;
  10385. } else {
  10386. inputValue.value -= 1;
  10387. }
  10388. refreshNump();
  10389. emit("update:modelValue", inputValue.value);
  10390. };
  10391. const incClick = (e) => {
  10392. e.preventDefault();
  10393. if (props.maxVal != null) { // 等价于 !== null && !== undefined,有指定 maxVal=。不能使用 (props.maxVal),0 会被判为不成立。Lin
  10394. if (inputValue.value < props.maxVal)
  10395. inputValue.value += 1;
  10396. } else {
  10397. inputValue.value += 1;
  10398. }
  10399. refreshNump();
  10400. emit("update:modelValue", inputValue.value);
  10401. };
  10402. ///
  10403. const refreshNump = () => {
  10404. document.getElementsByName(props.name)[0].value = inputValue.value;
  10405. if (localDefVal.value > inputValue.value) { // (props.defVal >。改为 localDefVal,提供 window.wrDefValsqljcxm1( 了。Lin
  10406. const decVal = localDefVal.value - inputValue.value; // = props.defVal -。改为 localDefVal,提供 window.wrDefValsqljcxm1( 了。Lin
  10407. document.getElementById("dec"+ props.name).innerText = "-"+ (decVal);
  10408. document.getElementById("inc"+ props.name).innerText = "+";
  10409. } else if (localDefVal.value < inputValue.value) { // (props.defVal <。改为 localDefVal,提供 window.wrDefValsqljcxm1( 了。Lin
  10410. const incVal = inputValue.value - localDefVal.value; // - props.defVal。改为 localDefVal,提供 window.wrDefValsqljcxm1( 了。Lin
  10411. document.getElementById("inc"+ props.name).innerText = "+"+ (incVal);
  10412. document.getElementById("dec"+ props.name).innerText = "-";
  10413. } else {
  10414. document.getElementById("dec"+ props.name).innerText = "-";
  10415. document.getElementById("inc"+ props.name).innerText = "+";
  10416. }
  10417. // document.getElementById("dec"+ props.name).innerText = "-"+ (decVal > 0? decVal : "");
  10418. // document.getElementById("inc"+ props.name).innerText = "+"; // 不需要改 -- 只有扣分。Lin
  10419. }
  10420. const handleKeyup = (e) => {
  10421. if (e.key === "Enter") {
  10422. e.preventDefault(); // 阻止默认行为
  10423. const nextIdx = document.activeElement.tabIndex +1; // 下一个 tabIndex 的值。Lin
  10424. let nextFocus = document.querySelector(`input[tabIndex="${nextIdx}"]`);
  10425. if (nextFocus) {
  10426. nextFocus.focus(); // 聚焦到找到的元素上
  10427. } else { // 没有下一个了。Lin
  10428. nextFocus = document.querySelector(`input[tabIndex="0"]`); // 跳到第一个。不然,不会触发录入框的 onChange 事件。Lin
  10429. if (nextFocus)
  10430. nextFocus.focus(); // 聚焦到第一个元素上。Lin
  10431. }
  10432. }
  10433. };
  10434. /// 增加,阻止按回车提交 <form。Lin
  10435. const handleKeydown = (e) => {
  10436. if (e.key === "Enter")
  10437. e.preventDefault(); // 阻止默认行为
  10438. };
  10439. ///
  10440. return {
  10441. inputValue, localDefVal, wrCurVal, wrCurValByMinVal, wrCurValByMaxVal, wrDefVal, refreshNump,
  10442. onChange, handleKeyup,
  10443. handleKeydown, // 增加,阻止按回车提交 <form。Lin
  10444. decClick, incClick, // 增加,增加 -1、+1 按钮。Lin
  10445. };
  10446. },
  10447. render() {
  10448. return h(
  10449. "div",
  10450. {
  10451. class: "nump-bar-container", // : "search-bar-container",。Lin
  10452. },
  10453. [
  10454. /* 再改,支持不指定 desc=。Lin
  10455. h("span", {style:{ paddingRight: "10px" }}, this.desc +"("+ this.maxVal +")"),
  10456. */ this.desc && h("span", { style: { paddingRight: "10px" } }, this.desc + (this.maxVal? `(${this.maxVal})` : '')),
  10457. h(
  10458. "button",
  10459. { class: "dec-button", // : "ss-drop-button",。Lin
  10460. type: "button",
  10461. style: { width: this.decWidth },
  10462. onClick: this.decClick // : handleClick,。Lin
  10463. },
  10464. [
  10465. // h("span", [h(SsLoginIcon, { class: this.class })]), // 去掉,不需要。Lin
  10466. h("span", {id: "dec"+ this.name}, "-"), // , getDisplayText())。Lin
  10467. ]
  10468. ),
  10469. /* 去掉,没必要套多一层。Lin
  10470. h("div",
  10471. {
  10472. class: "input",
  10473. style: this.width ? { width: this.width } : undefined,
  10474. },
  10475. [
  10476. */
  10477. h("input", {
  10478. name: this.name,
  10479. // maxVal: this.maxVal, // 去掉,改为 window.wrCurValByMaxValxxx()。Lin
  10480. // placeholder: this.placeholder, // 去掉,没用到。Lin
  10481. value: this.modelValue,
  10482. tabindex: this.tabIndex,
  10483. ...(this.tabIndex !== -1 && { tabindex: this.tabIndex }),
  10484. /* 改,不用 onInput,只用 onChange。Lin
  10485. onInput: this.this.handleInput,
  10486. */ onChange: this.onChange,
  10487. onKeyup: this.handleKeyup,
  10488. onKeydown: this.handleKeydown, // 增加,阻止按回车提交 <form。Lin
  10489. // class: "input", // 去掉,改用 .nump-bar-container input { -- 不是 .nump-bar-container .input {。Lin
  10490. style: { width: this.width },
  10491. }),
  10492. // ]), // 去掉,没必要套多一层。Lin
  10493. /// 增加,+1 按钮 -- 抄自 SsSearchButton。Lin
  10494. h(
  10495. "button",
  10496. { class: "inc-button", // : "ss-drop-button",。Lin
  10497. type: "button",
  10498. style: { width: this.incWidth },
  10499. onClick: this.incClick // : handleClick,。Lin
  10500. },
  10501. [
  10502. // h("span", [h(SsLoginIcon, { class: this.class })]), // 去掉,不需要。Lin
  10503. h("span", {id: "inc"+ this.name}, "+"), // , getDisplayText())。Lin
  10504. ]
  10505. ),
  10506. ///
  10507. ]
  10508. );
  10509. },
  10510. };
  10511. /////
  10512. // ss-search-date-picker 日期时间选择器组件
  10513. const SsSearchDatePicker = {
  10514. name: "SsSearchDatePicker",
  10515. props: {
  10516. modelValue: {
  10517. type: [String, Number, Date],
  10518. default: "",
  10519. },
  10520. name: {
  10521. type: String,
  10522. required: true,
  10523. },
  10524. type: {
  10525. type: String,
  10526. default: "date",
  10527. validator: (value) => ["date", "datetime", "time"].includes(value),
  10528. },
  10529. fmt: {
  10530. type: String,
  10531. default: null,
  10532. },
  10533. placeholder: {
  10534. type: String,
  10535. default: "",
  10536. },
  10537. width: {
  10538. type: String,
  10539. default: "100%",
  10540. },
  10541. },
  10542. emits: ["update:modelValue"],
  10543. setup(props, { emit }) {
  10544. const errMsg = ref("");
  10545. const validate = () => {
  10546. if (window.ssVm) {
  10547. const result = window.ssVm.validateField(props.name);
  10548. console.log("validate", window.ssVm.validateField(props.name));
  10549. errMsg.value = result.valid ? "" : result.message;
  10550. }
  10551. };
  10552. // 根据type确定默认格式
  10553. const defaultFormat = computed(() => {
  10554. switch (props.type) {
  10555. case "datetime":
  10556. return "YYYY-MM-DD HH:mm:ss";
  10557. case "date":
  10558. return "YYYY-MM-DD";
  10559. case "time":
  10560. return "HH:mm:ss";
  10561. }
  10562. });
  10563. const convertJavaFormatToElement = (javaFormat) => {
  10564. if (!javaFormat) return null;
  10565. return javaFormat
  10566. .replace("yyyy", "YYYY")
  10567. .replace("MM", "MM")
  10568. .replace("dd", "DD")
  10569. .replace("HH", "HH")
  10570. .replace("mm", "mm")
  10571. .replace("ss", "ss");
  10572. };
  10573. const finalFormat = computed(() => {
  10574. if (props.fmt) {
  10575. return convertJavaFormatToElement(props.fmt);
  10576. }
  10577. return defaultFormat.value;
  10578. });
  10579. // 使用 resolveComponent 获取组件
  10580. const ElDatePicker = resolveComponent("ElDatePicker");
  10581. const ElTimePicker = resolveComponent("ElTimePicker");
  10582. const SsFormIcon = resolveComponent("SsFormIcon");
  10583. const ElIcon = resolveComponent("ElIcon");
  10584. let useTimePicker = true;
  10585. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  10586. if (props.fmt) {
  10587. //有fmt属性,则以fmt属性优先判断类型
  10588. if (/[dMy]/.test(props.fmt)) {
  10589. //如果有传入日期格式,且含年月日
  10590. useTimePicker = false;
  10591. } else {
  10592. useTimePicker = true;
  10593. }
  10594. } else if (props.type !== "time") {
  10595. useTimePicker = false;
  10596. }
  10597. const dateType = computed(() => {
  10598. const fmt = props.fmt || "";
  10599. if (fmt.includes("HH:mm:ss")) {
  10600. return "datetime";
  10601. } else if (fmt.includes("HH:mm")) {
  10602. return "datetime";
  10603. } else if (fmt.includes("mm:ss")) {
  10604. return "time";
  10605. }
  10606. return "date";
  10607. });
  10608. const handleValueUpdate = (val) => {
  10609. emit("update:modelValue", val);
  10610. emit("change", val); // 同时触发 change 事件
  10611. setTimeout(() => {
  10612. validate();
  10613. }, 50);
  10614. };
  10615. return () =>
  10616. h(
  10617. "div",
  10618. { class: "ss-search-date-picker", style: { width: props.width } },
  10619. [
  10620. h("input", {
  10621. type: "hidden",
  10622. name: props.name,
  10623. value: props.modelValue,
  10624. }),
  10625. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  10626. modelValue: props.modelValue,
  10627. "onUpdate:modelValue": handleValueUpdate,
  10628. type: dateType.value,
  10629. format: finalFormat.value,
  10630. "value-format": finalFormat.value,
  10631. clearable: true,
  10632. placeholder: props.placeholder,
  10633. class: "custom-date-picker", // 用于自定义样式
  10634. "time-arrow-control": props.type === "datetime", // 修改这里
  10635. size: "large", // 添加这一行,改为 large 尺寸
  10636. style: { width: "100%" },
  10637. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  10638. }),
  10639. ]
  10640. );
  10641. },
  10642. };
  10643. // 搜索按钮组件(包含下拉按钮)
  10644. const SsSearchButton = {
  10645. name: "SsSearchButton",
  10646. props: {
  10647. text: {
  10648. type: String,
  10649. required: true,
  10650. },
  10651. iconClass: {
  10652. type: String,
  10653. required: false,
  10654. },
  10655. opt: {
  10656. type: Array,
  10657. default: () => [],
  10658. },
  10659. checkId: {
  10660. type: String,
  10661. default: "0",
  10662. },
  10663. width: {
  10664. //add by Ben(20251225)
  10665. type: String,
  10666. required: false,
  10667. },
  10668. id: {
  10669. //add by Ben(20251225)
  10670. type: String,
  10671. required: false,
  10672. },
  10673. },
  10674. emits: ["click"],
  10675. setup(props, { emit }) {
  10676. const currentId = ref(props.checkId || "0");
  10677. const showPopup = ref(false);
  10678. const handleMouseEnter = () => {
  10679. showPopup.value = true;
  10680. };
  10681. const handleMouseLeave = () => {
  10682. showPopup.value = false;
  10683. };
  10684. // 添加点击事件处理,阻止默认行为
  10685. const handleClick = (e) => {
  10686. e.preventDefault();
  10687. if (props.opt?.length > 0) {
  10688. const selectedOption =
  10689. currentId.value === "0"
  10690. ? props.opt[0]
  10691. : props.opt.find((opt) => opt.id === currentId.value);
  10692. if (selectedOption) {
  10693. selectedOption.callback?.();
  10694. }
  10695. } else {
  10696. emit("click", e);
  10697. }
  10698. };
  10699. // 获取显示文本
  10700. const getDisplayText = () => {
  10701. if (!props.opt?.length) return props.text;
  10702. const selectedOption =
  10703. currentId.value === "0"
  10704. ? props.opt[0]
  10705. : props.opt.find((opt) => opt.id === currentId.value);
  10706. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  10707. };
  10708. return () =>
  10709. h(
  10710. "button",
  10711. {
  10712. class:
  10713. props.opt?.length > 0
  10714. ? "ss-drop-button ss-drop-button-more"
  10715. : "ss-drop-button",
  10716. type: "button", // 明确指定按钮类型为 button
  10717. onMouseenter: handleMouseEnter,
  10718. onMouseleave: handleMouseLeave,
  10719. onClick: handleClick, // 添加点击事件处理
  10720. style: { width: props.width }, //add by Ben(20251225)
  10721. id: props.id, //add by Ben(20251225)
  10722. },
  10723. [
  10724. props.iconClass
  10725. ? h("span", {
  10726. class: props.iconClass,
  10727. style: { fontFamily: "iconfont", marginRight: "5px" },
  10728. })
  10729. : null,
  10730. h("span", getDisplayText()),
  10731. props.opt.length > 0 &&
  10732. showPopup.value &&
  10733. h(
  10734. "div",
  10735. {
  10736. class: "popup",
  10737. },
  10738. props.opt.map((item) =>
  10739. h(
  10740. "div",
  10741. {
  10742. onClick: (e) => {
  10743. e.preventDefault(); // 选项点击也阻止默认行为
  10744. e.stopPropagation(); // 阻止事件冒泡
  10745. currentId.value = item.id; // 更新当前选中的ID
  10746. item.callback();
  10747. showPopup.value = false; // 选择后关闭弹窗
  10748. },
  10749. },
  10750. item.desc
  10751. )
  10752. )
  10753. ),
  10754. ]
  10755. );
  10756. },
  10757. };
  10758. // 下拉按钮组件
  10759. const SsDropButton = {
  10760. name: "SsDropButton",
  10761. props: {
  10762. text: {
  10763. type: String,
  10764. required: true,
  10765. },
  10766. iconClass: {
  10767. type: String,
  10768. required: true,
  10769. },
  10770. opt: {
  10771. type: Array,
  10772. default: () => [],
  10773. },
  10774. checkId: {
  10775. type: String,
  10776. default: "0",
  10777. },
  10778. onclick: {
  10779. type: Function,
  10780. default: null,
  10781. },
  10782. },
  10783. setup(props) {
  10784. const currentId = ref(props.checkId || "0");
  10785. const showPopup = ref(false);
  10786. const handleMouseEnter = () => {
  10787. showPopup.value = true;
  10788. };
  10789. const handleMouseLeave = () => {
  10790. showPopup.value = false;
  10791. };
  10792. // 添加点击事件处理,阻止默认行为
  10793. const handleClick = (e) => {
  10794. e.preventDefault();
  10795. if (props.opt?.length > 0) {
  10796. const selectedOption =
  10797. currentId.value === "0"
  10798. ? props.opt[0]
  10799. : props.opt.find((opt) => opt.id === currentId.value);
  10800. if (selectedOption) {
  10801. selectedOption.callback?.();
  10802. }
  10803. } else if (props.onclick) {
  10804. props.onclick();
  10805. }
  10806. };
  10807. // 获取显示文本
  10808. const getDisplayText = () => {
  10809. if (!props.opt?.length) return props.text;
  10810. const selectedOption =
  10811. currentId.value === "0"
  10812. ? props.opt[0]
  10813. : props.opt.find((opt) => opt.id === currentId.value);
  10814. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  10815. };
  10816. return () =>
  10817. h(
  10818. "button",
  10819. {
  10820. class:
  10821. props.opt?.length > 0
  10822. ? "ss-drop-button ss-drop-button-more"
  10823. : "ss-drop-button",
  10824. type: "button", // 明确指定按钮类型为 button
  10825. onMouseenter: handleMouseEnter,
  10826. onMouseleave: handleMouseLeave,
  10827. onClick: handleClick, // 添加点击事件处理
  10828. },
  10829. [
  10830. h("span", {
  10831. class: props.iconClass,
  10832. style: { fontFamily: "iconfont" },
  10833. }),
  10834. h("span", getDisplayText()),
  10835. props.opt.length > 0 &&
  10836. showPopup.value &&
  10837. h(
  10838. "div",
  10839. {
  10840. class: "popup",
  10841. },
  10842. props.opt.map((item) =>
  10843. h(
  10844. "div",
  10845. {
  10846. onClick: (e) => {
  10847. e.preventDefault(); // 选项点击也阻止默认行为
  10848. e.stopPropagation(); // 阻止事件冒泡
  10849. currentId.value = item.id; // 更新当前选中的ID
  10850. item.callback();
  10851. showPopup.value = false; // 选择后关闭弹窗
  10852. },
  10853. },
  10854. item.desc
  10855. )
  10856. )
  10857. ),
  10858. ]
  10859. );
  10860. },
  10861. };
  10862. /**
  10863. * 二级页面标签组件
  10864. * <ss-sub-tab
  10865. * @description 用于展示二级页面的布局组件,包含左侧垂直标签导航(支持分组)和右侧iframe内容区
  10866. * @property {String} headerImage - 左侧顶部图片地址
  10867. * @property {Array} menuList - 菜单配置列表
  10868. * @property {Object} [activeMenu] - 当前选中的菜单项,不传则自动选择第一个可选菜单
  10869. * @property {Array} footerButtons - 底部按钮配置列表
  10870. */
  10871. /**
  10872. * SsSubTab 左侧菜单+iframe内容组件
  10873. * v3.0 改造:去掉顶部图片,改为图标+悬浮模式,iframe懒加载 by xu 20251216
  10874. */
  10875. const SsSubTab = {
  10876. name: "SsSubTab",
  10877. props: {
  10878. menuList: {
  10879. type: Array,
  10880. required: true,
  10881. },
  10882. activeMenu: {
  10883. type: String,
  10884. default: "",
  10885. },
  10886. footerButtons: {
  10887. type: Array,
  10888. default: () => [],
  10889. },
  10890. leftDisplay: {
  10891. type: Boolean,
  10892. default: true,
  10893. },
  10894. // v3.0 新增:菜单模式 collapse(悬浮展开) / fixed(始终收起) by xu 20251216
  10895. initialMode: {
  10896. type: String,
  10897. default: "collapse",
  10898. },
  10899. },
  10900. emits: ["menu-change", "footer-click"],
  10901. setup(props, { emit }) {
  10902. // v3.0 新增:默认图标映射,使用icon-biz图标 by xu 20251216
  10903. const defaultIcons = [
  10904. "icon-obj-ry", // 人员
  10905. "icon-obj-dw", // 单位
  10906. "icon-obj-gw", // 岗位
  10907. "icon-biz-rc", // 人才
  10908. "icon-biz-xc", // 巡查
  10909. "icon-biz-cl", // 材料
  10910. "icon-biz-men", // 门
  10911. "icon-obj-xy", // 协议
  10912. ];
  10913. //功能: SsSubTab 支持后端下发 iconName + pobj/cobj 两级菜单 by xu 20251222
  10914. const isTrue = (v) => v === true || v === "true" || v === 1 || v === "1"; //功能 by xu 20251222
  10915. const resolveIconClass = (iconNameOrClass, fallbackIndex) => {
  10916. //功能 by xu 20251222
  10917. const fallback = `menu-icon ${
  10918. defaultIcons[fallbackIndex % defaultIcons.length]
  10919. }`;
  10920. if (!iconNameOrClass) {
  10921. return fallback;
  10922. }
  10923. // 已经是完整 class(可能包含 menu-icon / menu-base-icon / 多个 class)
  10924. if (
  10925. typeof iconNameOrClass === "string" &&
  10926. iconNameOrClass.indexOf(" ") > -1
  10927. ) {
  10928. return iconNameOrClass;
  10929. }
  10930. const iconName = iconNameOrClass;
  10931. if (iconName === "menu-icon" || iconName === "menu-base-icon") {
  10932. return fallback;
  10933. }
  10934. // 业务图标库:icon-biz / icon-obj -> menu-icon
  10935. if (
  10936. typeof iconName === "string" &&
  10937. (iconName.indexOf("icon-obj-") === 0 ||
  10938. iconName.indexOf("icon-biz-") === 0)
  10939. ) {
  10940. return `menu-icon ${iconName}`;
  10941. }
  10942. // 默认认为是 icon-base 图标 -> menu-base-icon
  10943. return `menu-base-icon ${iconName}`;
  10944. };
  10945. const getMenuIcon = (item, index) => {
  10946. //功能 by xu 20251222
  10947. if (!item) {
  10948. return resolveIconClass(null, index);
  10949. }
  10950. //功能: 变动图标后端暂不正确,前端先写死为 icon-chg by xu 20251223
  10951. if (item.title === "变动" || item.name === "sys_bd") {
  10952. return resolveIconClass("icon-chg", index);
  10953. }
  10954. // 兼容旧字段 icon(优先使用)
  10955. if (item.icon) return resolveIconClass(item.icon, index);
  10956. // v3.0 使用后端下发 iconName
  10957. if (item.iconName) return resolveIconClass(item.iconName, index);
  10958. return resolveIconClass(null, index);
  10959. };
  10960. //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  10961. const getFooterIcon = (button) => {
  10962. //功能 by xu 20251224
  10963. if (!button) return "menu-base-icon icon-subm";
  10964. const iconNameOrClass =
  10965. button.iconClass || button.iconName || button.icon;
  10966. if (!iconNameOrClass) return "menu-base-icon icon-subm";
  10967. if (
  10968. typeof iconNameOrClass === "string" &&
  10969. iconNameOrClass.indexOf(" ") > -1
  10970. ) {
  10971. return iconNameOrClass;
  10972. }
  10973. return `menu-base-icon ${iconNameOrClass}`;
  10974. };
  10975. //功能: pobj/cobj 扁平结构转换为 children 树结构,兼容原 children 结构 by xu 20251222
  10976. const normalizeMenuList = (rawList) => {
  10977. if (!Array.isArray(rawList) || rawList.length === 0) {
  10978. return [];
  10979. }
  10980. const hasTree = rawList.some(
  10981. (it) => Array.isArray(it?.children) && it.children.length > 0
  10982. );
  10983. if (hasTree) {
  10984. return rawList.map((it) => ({
  10985. ...it,
  10986. __level: 1,
  10987. children: Array.isArray(it.children)
  10988. ? it.children.map((c) => ({ ...c, __level: 2 }))
  10989. : it.children,
  10990. }));
  10991. }
  10992. const hasMarker = rawList.some(
  10993. (it) => it && ("pobj" in it || "cobj" in it)
  10994. );
  10995. if (!hasMarker) {
  10996. return rawList.map((it) => ({ ...it, __level: 1 }));
  10997. }
  10998. const result = [];
  10999. let currentGroup = null;
  11000. for (const item of rawList) {
  11001. //功能: “变动”始终按一级处理(即使后端误传 pobj/cobj)by xu 20251223
  11002. const isChgItem =
  11003. item && (item.title === "变动" || item.name === "sys_bd");
  11004. if (isChgItem) {
  11005. result.push({ ...item, __level: 1 });
  11006. continue;
  11007. }
  11008. const isParent = isTrue(item?.pobj);
  11009. const isChild = isTrue(item?.cobj);
  11010. if (isParent) {
  11011. currentGroup = {
  11012. ...item,
  11013. __level: 1,
  11014. children: [],
  11015. };
  11016. result.push(currentGroup);
  11017. continue;
  11018. }
  11019. if (isChild && currentGroup) {
  11020. currentGroup.children.push({ ...item, __level: 2 });
  11021. continue;
  11022. }
  11023. //功能: 变动等无 pobj/cobj 的选项按一级展示(不挂到 children,也不打断当前分组)by xu 20251223
  11024. result.push({ ...item, __level: 1 });
  11025. }
  11026. return result;
  11027. };
  11028. const menuListComputed = computed(() =>
  11029. normalizeMenuList(props.menuList)
  11030. ); //功能 by xu 20251222
  11031. //功能: 分组展开状态(默认展开),避免 computed 生成对象导致 open 状态丢失 by xu 20251222
  11032. const groupOpenState = reactive({}); // { [key]: boolean }
  11033. const getGroupKey = (item) => item?.name || item?.title || ""; //功能 by xu 20251222
  11034. const isGroupOpen = (item) => {
  11035. //功能 by xu 20251222
  11036. const key = getGroupKey(item);
  11037. if (!key) return true;
  11038. return groupOpenState[key] !== false;
  11039. };
  11040. const toggleGroupOpen = (item) => {
  11041. //功能 by xu 20251222
  11042. const key = getGroupKey(item);
  11043. if (!key) return;
  11044. groupOpenState[key] = !isGroupOpen(item);
  11045. };
  11046. const getLevelClass = (item, fallbackLevel) => {
  11047. //功能 by xu 20251222
  11048. //功能: “变动”始终按一级样式处理 by xu 20251223
  11049. if (item && (item.title === "变动" || item.name === "sys_bd")) {
  11050. return "level-1";
  11051. }
  11052. const level = item?.__level || fallbackLevel || 1;
  11053. return level === 2 ? "level-2" : "level-1";
  11054. };
  11055. // v3.0 新增:菜单模式管理 by xu 20251216
  11056. const menuMode = ref(props.initialMode);
  11057. const isHovering = ref(false);
  11058. const toggleMenuMode = () => {
  11059. menuMode.value = menuMode.value === "collapse" ? "fixed" : "collapse";
  11060. };
  11061. //功能: 提供给旧UI弹窗顶部按钮调用的 API(替代点击 .menu-mode-toggle DOM)by xu 20251224
  11062. const registerSsSubTabApi = () => {
  11063. //功能 by xu 20251224
  11064. try {
  11065. window.SS = window.SS || {};
  11066. window.SS.dom = window.SS.dom || {};
  11067. //功能: 兼容小写 ss 命名空间(部分页面只引用 window.ss)by xu 20251224
  11068. window.ss = window.ss || window.SS;
  11069. window.ss.dom = window.ss.dom || window.SS.dom;
  11070. const api = {
  11071. toggleMenuMode,
  11072. getMenuMode: () => menuMode.value,
  11073. };
  11074. window.SS.dom.ssSubTabApi = api;
  11075. window.ss.dom.ssSubTabApi = api;
  11076. //功能: 多层弹窗(如 objPlay -> objInfo) 场景,将 API 注册到 topWindow 供按钮跨层调用 by xu 20251224
  11077. try {
  11078. const wdDialogId =
  11079. window.wd &&
  11080. wd.display &&
  11081. wd.display.getwdDialogId &&
  11082. wd.display.getwdDialogId();
  11083. if (wdDialogId && window.top) {
  11084. window.top.__ssSubTabApiMap = window.top.__ssSubTabApiMap || {};
  11085. window.top.__ssSubTabApiMap[wdDialogId] = api;
  11086. }
  11087. } catch (e) {}
  11088. try {
  11089. console.log(
  11090. "[SsSubTabApi] registered",
  11091. window.location && window.location.pathname
  11092. );
  11093. } catch (e) {}
  11094. } catch (e) {}
  11095. };
  11096. const unregisterSsSubTabApi = () => {
  11097. //功能 by xu 20251224
  11098. try {
  11099. //功能: 从 topWindow 解绑(避免弹窗关闭后残留)by xu 20251224
  11100. try {
  11101. const wdDialogId =
  11102. window.wd &&
  11103. wd.display &&
  11104. wd.display.getwdDialogId &&
  11105. wd.display.getwdDialogId();
  11106. if (
  11107. wdDialogId &&
  11108. window.top &&
  11109. window.top.__ssSubTabApiMap &&
  11110. window.top.__ssSubTabApiMap[wdDialogId]
  11111. ) {
  11112. delete window.top.__ssSubTabApiMap[wdDialogId];
  11113. }
  11114. } catch (e) {}
  11115. if (window.SS?.dom?.ssSubTabApi?.toggleMenuMode === toggleMenuMode) {
  11116. delete window.SS.dom.ssSubTabApi;
  11117. }
  11118. if (window.ss?.dom?.ssSubTabApi?.toggleMenuMode === toggleMenuMode) {
  11119. delete window.ss.dom.ssSubTabApi;
  11120. }
  11121. } catch (e) {}
  11122. };
  11123. //功能: 立即注册,避免 enable 早于 onMounted 导致“api not ready”by xu 20251224
  11124. registerSsSubTabApi(); //功能 by xu 20251224
  11125. onBeforeUnmount(unregisterSsSubTabApi); //功能 by xu 20251224
  11126. const onMouseEnter = () => {
  11127. if (menuMode.value === "collapse") {
  11128. isHovering.value = true;
  11129. }
  11130. };
  11131. const onMouseLeave = () => {
  11132. isHovering.value = false;
  11133. };
  11134. const isExpanded = computed(() => {
  11135. return menuMode.value === "collapse" && isHovering.value;
  11136. });
  11137. // v3.0 新增:iframe 懒加载,点击才加载 by xu 20251216
  11138. const loadedMenus = ref(new Set());
  11139. const isMenuLoaded = (menuName) => {
  11140. return loadedMenus.value.has(menuName);
  11141. };
  11142. // 根据标题找到对应的菜单项
  11143. const findMenuByTitle = (title) => {
  11144. for (const item of menuListComputed.value) {
  11145. //功能 by xu 20251222
  11146. if (item.children?.length > 0) {
  11147. const child = item.children.find((c) => c.title === title);
  11148. if (child) return child;
  11149. } else if (item.title === title) {
  11150. return item;
  11151. }
  11152. }
  11153. return null;
  11154. };
  11155. // 计算默认选中的菜单项
  11156. const defaultActiveMenu = computed(() => {
  11157. if (props.activeMenu) {
  11158. const menu = findMenuByTitle(props.activeMenu);
  11159. if (menu) return menu;
  11160. }
  11161. const firstItem = menuListComputed.value[0]; //功能 by xu 20251222
  11162. if (!firstItem) return null;
  11163. //功能: 默认选中第一个一级菜单(不默认跳到第一个二级)by xu 20251224
  11164. return firstItem;
  11165. });
  11166. const currentMenu = ref(defaultActiveMenu.value);
  11167. // 监听外部activeMenu变化
  11168. watch(
  11169. () => props.activeMenu,
  11170. (newTitle) => {
  11171. if (newTitle) {
  11172. const menu = findMenuByTitle(newTitle);
  11173. if (menu) {
  11174. currentMenu.value = menu;
  11175. }
  11176. }
  11177. }
  11178. );
  11179. // 初始化:默认选中项加入已加载集合
  11180. watch(
  11181. currentMenu,
  11182. (menu) => {
  11183. if (menu?.name) {
  11184. loadedMenus.value.add(menu.name);
  11185. }
  11186. },
  11187. { immediate: true }
  11188. );
  11189. // 选择菜单项时触发 menu-change 钩子
  11190. const selectItem = (item) => {
  11191. currentMenu.value = item;
  11192. // 标记为已加载
  11193. if (item.name) {
  11194. loadedMenus.value.add(item.name);
  11195. }
  11196. emit("menu-change", item);
  11197. };
  11198. // 处理底部按钮点击
  11199. const handleFooterClick = (button, index) => {
  11200. emit("footer-click", { button, index });
  11201. };
  11202. return {
  11203. menuListComputed, //功能 by xu 20251222
  11204. currentMenu,
  11205. selectItem,
  11206. handleFooterClick,
  11207. getFooterIcon, //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  11208. menuMode,
  11209. isHovering,
  11210. isExpanded,
  11211. toggleMenuMode,
  11212. onMouseEnter,
  11213. onMouseLeave,
  11214. isMenuLoaded,
  11215. getMenuIcon,
  11216. isGroupOpen, //功能 by xu 20251222
  11217. toggleGroupOpen, //功能 by xu 20251222
  11218. getLevelClass, //功能 by xu 20251222
  11219. };
  11220. },
  11221. template: `
  11222. <div class="project-edit-container">
  11223. <div class="left-side"
  11224. v-if="leftDisplay"
  11225. :data-mode="menuMode"
  11226. :class="{ 'is-expanded': isExpanded }"
  11227. @mouseenter="onMouseEnter"
  11228. @mouseleave="onMouseLeave">
  11229. <!-- 菜单内容 -->
  11230. <div class="menu-content">
  11231. <div class="scroll-view">
  11232. <template v-for="(menuItem, i) in menuListComputed" :key="i">
  11233. <!-- 分组菜单 -->
  11234. <div v-if="menuItem.children?.length > 0" class="group">
  11235. <!-- 功能: 一级(pobj)可点击进入,箭头仅控制展开/收起;二级点击不影响一级选中状态 by xu 20251223 -->
  11236. <div class="menu-item"
  11237. :class="[getLevelClass(menuItem, 1), { active: menuItem.name === currentMenu?.name }]"
  11238. @click="selectItem(menuItem)">
  11239. <ss-icon :class="getMenuIcon(menuItem, i)" />
  11240. <span class="menu-label">{{ menuItem.title }}</span>
  11241. <!-- 功能: 一级菜单有子项时显示 dot(参考全局左侧菜单)by xu 20251224 -->
  11242. <div class="has-children-dot"></div>
  11243. <div class="menu-tooltip">{{ menuItem.title }}</div>
  11244. </div>
  11245. <!-- 功能: 二级菜单始终展示,不做收缩展开 by xu 20251223 -->
  11246. <div class="group-detail">
  11247. <div v-for="(item, j) in menuItem.children"
  11248. :key="j"
  11249. class="menu-item"
  11250. :class="[getLevelClass(item, 2), { active: item.name === currentMenu?.name }]"
  11251. @click.stop="selectItem(item)">
  11252. <ss-icon :class="getMenuIcon(item, j)" />
  11253. <span class="menu-label">{{ item.title }}</span>
  11254. </div>
  11255. </div>
  11256. </div>
  11257. <!-- 普通菜单项 -->
  11258. <div v-else
  11259. class="menu-item"
  11260. :class="[getLevelClass(menuItem, 1), { active: menuItem.name === currentMenu?.name }]"
  11261. @click="selectItem(menuItem)">
  11262. <ss-icon :class="getMenuIcon(menuItem, i)" />
  11263. <span class="menu-label">{{ menuItem.title }}</span>
  11264. <div class="menu-tooltip">{{ menuItem.title }}</div>
  11265. </div>
  11266. </template>
  11267. </div>
  11268. </div>
  11269. <!-- 底部按钮 -->
  11270. <div v-if="footerButtons.length > 0"
  11271. class="sub-tab-menu-footer"
  11272. :class="{ 'has-text': !!footerButtons[0].text }"
  11273. @click="footerButtons[0].onclick">
  11274. <ss-icon :class="getFooterIcon(footerButtons[0])" />
  11275. <div class="footer-label" v-if="footerButtons[0].text">{{ footerButtons[0].text }}</div>
  11276. <ss-icon v-if="footerButtons.length > 1" class="footer-arrow" name="arrow-up" size="24px" />
  11277. <div v-if="footerButtons.length > 1" class="sub-tab-menu-popup">
  11278. <div v-for="(button, index) in footerButtons.slice(1)"
  11279. :key="index"
  11280. @click.stop="button.onclick">
  11281. {{ button.text }}
  11282. </div>
  11283. </div>
  11284. </div>
  11285. </div>
  11286. <!-- 右侧内容区域 - 懒加载 iframe -->
  11287. <div class="content-area fit-height-content" style="overflow: hidden;" :style="!leftDisplay ? { width: '100%' } : {}">
  11288. <template v-for="(menuItem, i) in menuList" :key="i">
  11289. <iframe
  11290. v-if="isMenuLoaded(menuItem.name)"
  11291. :src="menuItem.url"
  11292. style="height: 100%;width: 100%;"
  11293. frameborder="0"
  11294. class="sub-tab-iframe"
  11295. :id="i === 0 ? 'sub-tab-iframe' : ''"
  11296. v-show="currentMenu?.name === menuItem.name"
  11297. />
  11298. </template>
  11299. </div>
  11300. </div>
  11301. `,
  11302. };
  11303. // <iframe
  11304. // v-if="currentMenu?.url"
  11305. // :src="currentMenu.url"
  11306. // style="height: 100%;width: 100%;"
  11307. // frameborder="0"
  11308. // id="sub-tab-iframe"
  11309. // />
  11310. ///// 再增加,增加 SsCms(<ss-cms) -- 抄自上面的 SsSubTab。Lin
  11311. // 支持编辑、播放模式,支持 ccms 播放(不显示左侧栏)
  11312. // 去掉左侧栏的两级菜单,去掉 "分组菜单",只保留 "普通菜单项" -- cms 只需要一级
  11313. // 去掉鼠标进入展开左侧栏 -- 左侧栏增加显示名称 -- 点击后,窗口标题行显示完整名称
  11314. /**
  11315. * cms 播放器、编辑器组件
  11316. * <ss-cms
  11317. * @description 用于展示二级页面的布局组件,包含左侧垂直标签导航(支持分组)和右侧iframe内容区
  11318. * @property {String} headerImage - 左侧顶部图片地址
  11319. * @property {Array} menuList - 菜单配置列表
  11320. * @property {Object} [activeMenu] - 当前选中的菜单项,不传则自动选择第一个可选菜单
  11321. * @property {Array} footerButtons - 底部按钮配置列表
  11322. */
  11323. const SsCms = {
  11324. name: "SsCms",
  11325. props: {
  11326. menuList: {
  11327. type: Array,
  11328. required: true,
  11329. },
  11330. activeMenu: {
  11331. type: String,
  11332. default: "",
  11333. },
  11334. /* 再改,改为单个按钮。Lin
  11335. footerButtons: {
  11336. type: Array,
  11337. default: () => [],
  11338. },
  11339. */
  11340. footerButton: {
  11341. type: Object,
  11342. default: null,
  11343. },
  11344. leftDisplay: {
  11345. type: Boolean,
  11346. default: true,
  11347. },
  11348. },
  11349. emits: ["menu-change", "footer-click"],
  11350. setup(props, { emit }) {
  11351. // v3.0 新增:iframe 懒加载,点击才加载 by xu 20251216
  11352. const loadedMenus = ref(new Set());
  11353. const isMenuLoaded = (menuName) => {
  11354. return loadedMenus.value.has(menuName);
  11355. };
  11356. //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  11357. const getFooterIcon = (button) => {
  11358. //功能 by xu 20251224
  11359. if (!button) return "menu-base-icon icon-subm";
  11360. const iconNameOrClass =
  11361. button.iconClass || button.iconName || button.icon;
  11362. if (!iconNameOrClass) return "menu-base-icon icon-subm";
  11363. if (
  11364. typeof iconNameOrClass === "string" &&
  11365. iconNameOrClass.indexOf(" ") > -1
  11366. ) {
  11367. return iconNameOrClass;
  11368. }
  11369. return `menu-base-icon ${iconNameOrClass}`;
  11370. };
  11371. // 根据标题找到对应的菜单项
  11372. const findMenuByTitle = (title) => {
  11373. for (const item of props.menuList) { // of menuListComputed.value)。去掉左侧栏的两级菜单。Lin
  11374. //功能 by xu 20251222
  11375. if (item.children?.length > 0) {
  11376. const child = item.children.find((c) => c.title === title);
  11377. if (child) return child;
  11378. } else if (item.title === title) {
  11379. return item;
  11380. }
  11381. }
  11382. return null;
  11383. };
  11384. // 计算默认选中的菜单项
  11385. const defaultActiveMenu = computed(() => {
  11386. if (props.activeMenu) {
  11387. const menu = findMenuByTitle(props.activeMenu);
  11388. if (menu) return menu;
  11389. }
  11390. const firstItem = props.menuList[0]; // = menuListComputed.value[0];。去掉左侧栏的两级菜单。Lin
  11391. if (!firstItem) return null;
  11392. //功能: 默认选中第一个一级菜单(不默认跳到第一个二级)by xu 20251224
  11393. return firstItem;
  11394. });
  11395. const currentMenu = ref(defaultActiveMenu.value);
  11396. // 监听外部activeMenu变化
  11397. watch(
  11398. () => props.activeMenu,
  11399. (newTitle) => {
  11400. if (newTitle) {
  11401. const menu = findMenuByTitle(newTitle);
  11402. if (menu) {
  11403. currentMenu.value = menu;
  11404. }
  11405. }
  11406. }
  11407. );
  11408. // 初始化:默认选中项加入已加载集合
  11409. watch(
  11410. currentMenu,
  11411. (menu) => {
  11412. if (menu?.name) {
  11413. loadedMenus.value.add(menu.name);
  11414. }
  11415. },
  11416. { immediate: true }
  11417. );
  11418. // 选择菜单项时触发 menu-change 钩子
  11419. const selectItem = (item) => {
  11420. currentMenu.value = item;
  11421. // 标记为已加载
  11422. if (item.name) {
  11423. loadedMenus.value.add(item.name);
  11424. }
  11425. emit("menu-change", item);
  11426. };
  11427. // 处理底部按钮点击
  11428. const handleFooterClick = (button, index) => {
  11429. emit("footer-click", { button, index });
  11430. };
  11431. return {
  11432. currentMenu,
  11433. selectItem,
  11434. handleFooterClick,
  11435. getFooterIcon, //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  11436. isMenuLoaded,
  11437. };
  11438. },
  11439. template: `
  11440. <div class="cms-container"> <!-- ="project-edit-container"。Lin -->
  11441. <div class="left-side"
  11442. v-if="leftDisplay">
  11443. <!-- 菜单内容 -->
  11444. <div class="menu-content">
  11445. <div class="scroll-view">
  11446. <template v-for="(menuItem, i) in menuList" :key="i"> <!-- in menuListComputed" :。去掉左侧栏的两级菜单。Lin -->
  11447. <!-- 普通菜单项 -->
  11448. <div class="menu-item"
  11449. :class="[{ active: menuItem.name === currentMenu?.name }]"
  11450. @click="selectItem(menuItem)">
  11451. <ss-icon :class="['menu-icon', menuItem.iconName]" />
  11452. <span class="menu-label">{{ menuItem.title }}</span>
  11453. </div>
  11454. </template>
  11455. </div>
  11456. </div>
  11457. <!-- 底部按钮 -->
  11458. <div v-if="footerButton"
  11459. class="cms-menu-footer"
  11460. :class="{ 'has-text': !!footerButton.text }"
  11461. @click="footerButton.onclick">
  11462. <ss-icon :class="['menu-base-icon', footerButton.iconName]" />
  11463. <div class="footer-label" v-if="footerButton.text">{{ footerButton.text }}</div>
  11464. </div>
  11465. </div>
  11466. <!-- 右侧内容区域 - 懒加载 iframe -->
  11467. <div class="content-area fit-height-content" style="overflow: hidden;" :style="!leftDisplay ? { width: '100%' } : {}">
  11468. <template v-for="(menuItem, i) in menuList" :key="i">
  11469. <iframe
  11470. v-if="isMenuLoaded(menuItem.name)"
  11471. :src="menuItem.url"
  11472. style="height: 100%;width: 100%;"
  11473. frameborder="0"
  11474. class="sub-tab-iframe"
  11475. :id="i === 0 ? 'sub-tab-iframe' : ''"
  11476. v-show="currentMenu?.name === menuItem.name"
  11477. />
  11478. </template>
  11479. </div>
  11480. </div>
  11481. `,
  11482. };
  11483. /////
  11484. // ss-photo-upload 通用图片上传组件
  11485. const SsImgUpload = {
  11486. name: "SsImgUpload",
  11487. props: {
  11488. /// 再增加,增加支持上传成功后的回调 -- 抄自 SsObjp(<ss-objp)。Lin
  11489. onchange: {
  11490. //在此属性传入onChange的window全局回调函数,函数唯一参数是当前选中值 Ben(20251217)
  11491. type: String,
  11492. required: false,
  11493. },
  11494. ///
  11495. name: {
  11496. type: String,
  11497. required: true,
  11498. },
  11499. // 图片URL,用于回显
  11500. // url: {
  11501. // type: String,
  11502. // default: "",
  11503. // },
  11504. // 样式类名
  11505. class: {
  11506. type: String,
  11507. required: false, // : true,。没有 class= 时,为没有 缩略图 的上传。Lin
  11508. },
  11509. // 裁剪配置
  11510. cropperOpt: {
  11511. type: Object,
  11512. default: () => ({
  11513. width: 360,
  11514. height: 360,
  11515. aspectRatio: NaN, // : 1,。改,增加支持自由裁剪比例 -- 不锁定宽高比。Lin
  11516. }),
  11517. },
  11518. //上传图片url(未加图片名参数之前的部分)
  11519. ulUrl: {
  11520. type: String,
  11521. required: true,
  11522. },
  11523. //下载图片url(未加图片名参数之前的部分)
  11524. dlUrl: {
  11525. type: String,
  11526. required: true,
  11527. },
  11528. modelValue: [String, Number],
  11529. },
  11530. emits: ["update:modelValue"],
  11531. setup(props, { emit }) {
  11532. const inputId = Vue.computed(
  11533. () => `file_${Vue.getCurrentInstance().uid}`
  11534. );
  11535. //修改图片初始显示路径
  11536. let pathVal = ref(props.modelValue);
  11537. let srcBaseName = pathVal.value.split('_')[1]; // 再增加,增加上传的源文件名 0/<uuid>_<源文件名>.jpg -- 用于不显示图片或非图片时显示源文件名。Lin
  11538. let picUrl = ref("");
  11539. if (props.modelValue) {
  11540. picUrl.value = props.dlUrl + "&path=" + props.modelValue;
  11541. }
  11542. ///// 再增加,增加支持上传成功后的回调 -- 抄自 SsUpload(<ss-ul)。Lin。Lin
  11543. // 功能说明:封装 modelValue 变化后的联动逻辑,兼容用户点击和桥接 API 赋值 by xu 20260416
  11544. const handleModelValueChange = (newValue) => {
  11545. if (!props.onchange || typeof props.onchange !== "string" ||
  11546. typeof window === "undefined" || !window[props.onchange] || typeof window[props.onchange] !== "function")
  11547. return;
  11548. try {
  11549. window[props.onchange](newValue); // (value, desc)。Lin
  11550. } catch (error) {
  11551. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  11552. }
  11553. };
  11554. Vue.watch(() => props.modelValue, handleModelValueChange, { immediate: true });
  11555. /////
  11556. Vue.onMounted(() => {
  11557. window.SS.cropper.init({
  11558. el: $(`#${inputId.value}`),
  11559. photoSize: {
  11560. width: props.cropperOpt.width,
  11561. height: props.cropperOpt.height,
  11562. },
  11563. aspectRatio: props.cropperOpt.aspectRatio,
  11564. uploadUrl: props.ulUrl,
  11565. success: (path) => {
  11566. pathVal.value = path;
  11567. srcBaseName = path.split('_')[1]; // 再增加,增加上传的源文件名 0/<uuid>_<源文件名>.jpg -- 用于不显示图片或非图片时显示源文件名。Lin
  11568. picUrl.value = props.dlUrl + "&path=" + path;
  11569. emit("update:modelValue", path);
  11570. },
  11571. });
  11572. });
  11573. return () => {
  11574. /// 增加,支持没有缩略图的上传 -- 没有 class= 时,为没有 缩略图 的上传。Lin
  11575. // 没有缩略图:
  11576. // 点击整个 <td 框,就像点击 "名称" 的 <td 框一样
  11577. // 上传的文件名显示在 <td 里,就像显示名称一样
  11578. if (!props.class) {
  11579. return h("div", {style: "width: 100%;height: 100%;" }, [
  11580. h("input", {
  11581. type: "file",
  11582. accept: "image/*",
  11583. id: inputId.value,
  11584. style: { display: "none" },
  11585. }),
  11586. h("input", {
  11587. type: "hidden",
  11588. name: props.name,
  11589. value: pathVal.value,
  11590. }),
  11591. h(
  11592. "div",
  11593. {
  11594. style: {
  11595. width: "100%",
  11596. height: "100%",
  11597. alignContent: "center",
  11598. padding: "0 15px",
  11599. },
  11600. onClick: () => $(`#${inputId.value}`).click(),
  11601. },
  11602. srcBaseName
  11603. ),
  11604. ]);
  11605. }
  11606. ///
  11607. return h("div", {class: [props.class]}, [
  11608. h("input", {
  11609. type: "file",
  11610. accept: "image/*",
  11611. id: inputId.value,
  11612. style: {display: "none"},
  11613. }),
  11614. h("input", {
  11615. type: "hidden",
  11616. name: props.name,
  11617. value: pathVal.value,
  11618. }),
  11619. h(
  11620. "div",
  11621. {
  11622. style: {
  11623. width: "100%",
  11624. height: "100%",
  11625. },
  11626. onClick: () => $(`#${inputId.value}`).click(),
  11627. },
  11628. [
  11629. picUrl.value &&
  11630. h("img", {
  11631. src: picUrl.value,
  11632. style:
  11633. "width: 100%; height: 100%;object-fit: inherit;position: relative;z-index: 11;",
  11634. }),
  11635. ]
  11636. ),
  11637. ]);
  11638. }
  11639. },
  11640. };
  11641. ///// 再增加,增加 SsUpload(ss-ul)。抄自上面的 SsImgUpload(<ss-img)。Lin
  11642. // ss-photo-upload 通用图片上传组件
  11643. const SsUpload = {
  11644. name: "SsUpload",
  11645. props: {
  11646. /// 再增加,增加支持上传成功后的回调 -- 抄自 SsObjp(<ss-objp)。Lin
  11647. onchange: {
  11648. //在此属性传入onChange的window全局回调函数,函数唯一参数是当前选中值 Ben(20251217)
  11649. type: String,
  11650. required: false,
  11651. },
  11652. ///
  11653. name: {
  11654. type: String,
  11655. required: true,
  11656. },
  11657. class: {
  11658. type: String,
  11659. required: false, // : true,。没有 class= 时,为没有 缩略图 的上传。Lin
  11660. },
  11661. // 裁剪配置
  11662. cropperOpt: {
  11663. type: Object,
  11664. default: () => ({
  11665. width: 360,
  11666. height: 360,
  11667. aspectRatio: NaN, // : 1,。改,增加支持自由裁剪比例 -- 不锁定宽高比。Lin
  11668. }),
  11669. },
  11670. //上传图片url(未加图片名参数之前的部分)
  11671. ulUrl: {
  11672. type: String,
  11673. required: true,
  11674. },
  11675. //下载图片url(未加图片名参数之前的部分)
  11676. dlUrl: {
  11677. type: String,
  11678. required: true,
  11679. },
  11680. modelValue: [String, Number],
  11681. },
  11682. emits: ["update:modelValue"],
  11683. setup(props, { emit }) {
  11684. const inputId = Vue.computed(
  11685. () => `file_${Vue.getCurrentInstance().uid}`
  11686. );
  11687. //修改图片初始显示路径
  11688. let pathVal = ref(props.modelValue);
  11689. let srcBaseName = pathVal.value.split('_')[1]; // 再增加,增加上传的源文件名 0/<uuid>_<源文件名>.jpg -- 用于不显示图片或非图片时显示源文件名。Lin
  11690. let picUrl = ref("");
  11691. if (props.modelValue) {
  11692. picUrl.value = props.dlUrl + "&path=" + props.modelValue;
  11693. }
  11694. ///// 再增加,增加支持上传成功后的回调 -- 抄自 SsObjp(<ss-objp)。Lin。Lin
  11695. // 功能说明:封装 modelValue 变化后的联动逻辑,兼容用户点击和桥接 API 赋值 by xu 20260416
  11696. const handleModelValueChange = (newValue) => {
  11697. if (!props.onchange || typeof props.onchange !== "string" ||
  11698. typeof window === "undefined" || !window[props.onchange] || typeof window[props.onchange] !== "function")
  11699. return;
  11700. try {
  11701. window[props.onchange](newValue); // (value, desc)。Lin
  11702. } catch (error) {
  11703. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  11704. }
  11705. };
  11706. Vue.watch(() => props.modelValue, handleModelValueChange, { immediate: true });
  11707. /////
  11708. Vue.onMounted(() => {
  11709. window.SS.cropper.init({
  11710. el: $(`#${inputId.value}`),
  11711. photoSize: {
  11712. width: props.cropperOpt.width,
  11713. height: props.cropperOpt.height,
  11714. },
  11715. aspectRatio: props.cropperOpt.aspectRatio,
  11716. uploadUrl: props.ulUrl,
  11717. success: (path) => {
  11718. pathVal.value = path;
  11719. srcBaseName = path.split('_')[1]; // 再增加,增加上传的源文件名 0/<uuid>_<源文件名>.jpg -- 用于不显示图片或非图片时显示源文件名。Lin
  11720. picUrl.value = props.dlUrl + "&path=" + path;
  11721. emit("update:modelValue", path);
  11722. },
  11723. });
  11724. });
  11725. return () => {
  11726. /// 增加,支持没有缩略图的上传 -- 没有 class= 时,为没有 缩略图 的上传。Lin
  11727. // 没有缩略图:
  11728. // 点击整个 <td 框,就像点击 "名称" 的 <td 框一样
  11729. // 上传的文件名显示在 <td 里,就像显示名称一样
  11730. if (!props.class) {
  11731. return h("div", {style: "width: 100%;height: 100%;" }, [
  11732. h("input", {
  11733. type: "file",
  11734. // accept: "image/*", // 去掉,可以是其他文件。Lin
  11735. id: inputId.value,
  11736. style: { display: "none" },
  11737. }),
  11738. h("input", {
  11739. type: "hidden",
  11740. name: props.name,
  11741. value: pathVal.value,
  11742. }),
  11743. h(
  11744. "div",
  11745. {
  11746. style: {
  11747. width: "100%",
  11748. height: "100%",
  11749. alignContent: "center",
  11750. padding: "0 15px",
  11751. },
  11752. onClick: () => $(`#${inputId.value}`).click(),
  11753. },
  11754. srcBaseName
  11755. ),
  11756. ]);
  11757. }
  11758. ///
  11759. return h("div", { class: [props.class] }, [
  11760. h("input", {
  11761. type: "file",
  11762. accept: "image/*",
  11763. id: inputId.value,
  11764. style: { display: "none" },
  11765. }),
  11766. h("input", {
  11767. type: "hidden",
  11768. name: props.name,
  11769. value: pathVal.value,
  11770. }),
  11771. h(
  11772. "div",
  11773. {
  11774. style: {
  11775. width: "100%",
  11776. height: "100%",
  11777. },
  11778. onClick: () => $(`#${inputId.value}`).click(),
  11779. },
  11780. [
  11781. picUrl.value &&
  11782. h("img", {
  11783. src: picUrl.value,
  11784. style:
  11785. "width: 100%; height: 100%;object-fit: inherit;position: relative;z-index: 11;",
  11786. }),
  11787. ]
  11788. ),
  11789. ]);
  11790. }
  11791. },
  11792. };
  11793. /////
  11794. // 初始化函数,负责创建和挂载 Vue 应用
  11795. // window.SS = { dom: {} };
  11796. /**
  11797. * 获取当前窗口的父窗口
  11798. * @returns {Window} 父窗口对象
  11799. */
  11800. window.SS.topWin = (function (p, c) {
  11801. while (p != c) {
  11802. c = p;
  11803. p = p.parent;
  11804. }
  11805. return c;
  11806. })(window.parent, window);
  11807. window.SS.createSsDialogInstance = createSsDialogInstance;
  11808. /**
  11809. * 创建弹窗
  11810. * @param {Object} setting
  11811. * @param {Function} callbackEvent
  11812. */
  11813. window.SS.openDialog = function (setting, callbackEvent) {
  11814. if (setting.params) {
  11815. const encodedParams = encodeURIComponent(JSON.stringify(setting.params));
  11816. setting.src +=
  11817. (setting.src.includes("?") ? "&" : "?") + "params=" + encodedParams;
  11818. }
  11819. if (window.parent && window.parent !== window) {
  11820. window.parent.SS.createSsDialogInstance(setting, callbackEvent);
  11821. } else {
  11822. createSsDialogInstance(setting, callbackEvent);
  11823. }
  11824. };
  11825. //关闭弹窗
  11826. window.SS.closeDialog = function () {
  11827. console.log("关闭弹窗");
  11828. if (topWindow.dialogInstances.length > 0) {
  11829. const instance = topWindow.dialogInstances.pop();
  11830. console.log("instance", instance);
  11831. console.log("instance.callbackEvent", instance.callbackEvent);
  11832. console.log(
  11833. "instance.callbackEvent.end",
  11834. typeof instance.callbackEvent === "function"
  11835. );
  11836. if (instance.callbackEvent) {
  11837. // 判断是否有end回调并执行
  11838. if (typeof instance.callbackEvent === "function") {
  11839. instance.callbackEvent();
  11840. }
  11841. if (typeof instance.callbackEvent.end === "function") {
  11842. instance.callbackEvent.end();
  11843. }
  11844. }
  11845. instance.app.unmount(); // 卸载最后一个实例
  11846. if (instance.container && instance.container.parentNode) {
  11847. instance.container.parentNode.removeChild(instance.container); // 移除容器
  11848. }
  11849. }
  11850. };
  11851. /**
  11852. * 裁剪插件
  11853. */
  11854. window.SS.cropper = {
  11855. init: function (setting) {
  11856. if (!window.top.SS) window.top.SS = {};
  11857. // 重要:确保 cropper 对象的完整初始化
  11858. if (!window.top.SS.cropper) {
  11859. window.top.SS.cropper = {
  11860. settings: new Map(),
  11861. _backupSettings: {},
  11862. getSetting: this.getSetting,
  11863. clearSetting: this.clearSetting,
  11864. debug: this.debug,
  11865. };
  11866. } else if (!window.top.SS.cropper.settings) {
  11867. // 如果 cropper 存在但 settings 不存在,重新初始化 settings
  11868. window.top.SS.cropper.settings = new Map();
  11869. window.top.SS.cropper._backupSettings = {};
  11870. }
  11871. const uploaderId = `uploader_${Date.now()}_${Math.random()
  11872. .toString(36)
  11873. .substr(2, 9)}`;
  11874. window.top.SS.cropper.settings.set(uploaderId, setting);
  11875. window.top.SS.cropper._backupSettings[uploaderId] = setting;
  11876. setting.box = setting.box || "1";
  11877. var winSetting = {
  11878. headerTitle: "图片裁剪",
  11879. src: "/js/cropper/cropper.jsp", //原来在"/newUI/page/cropper.jsp" Ben(20251205)
  11880. width: "900",
  11881. height: "500",
  11882. };
  11883. $(setting.el).change(function () {
  11884. if (!window.SS.cropper.verify(setting)) {
  11885. $(setting.el).val(""); // 清空文件选择
  11886. return false;
  11887. }
  11888. var files = this.files;
  11889. if (files && files.length) {
  11890. if (!window.SS.cropper.verifySize($(setting.el)[0], 5)) {
  11891. $(setting.el).val(""); // 清空文件选择
  11892. alert("文件大小不能超过5M,请重新选择");
  11893. return false;
  11894. }
  11895. var URL = window.URL || window.webkitURL;
  11896. var file = files[0];
  11897. setting.file = file;
  11898. if (
  11899. /^image\/\w+$/.test(file.type) &&
  11900. /\.(jpg|jpeg|png|)$/i.test(file.name)
  11901. ) {
  11902. const uploadedImageURL = URL.createObjectURL(file);
  11903. /// 再增加,增加支持自由裁剪比例 -- 没有指定 width 和 height 时,不锁定比例。Lin
  11904. if (!setting.aspectRatio) { // 没有指定 width 和 height。Lin
  11905. const img = new Image();
  11906. img.onload = () => {
  11907. // URL.revokeObjectURL(uploadedImageURL); // 释放内存。先去掉,不释放。Lin
  11908. console.log("图片原始宽、高:" + img.width + "*" + img.height);
  11909. setting.photoSize.width = img.width;
  11910. setting.photoSize.height = img.height;
  11911. };
  11912. img.src = uploadedImageURL;
  11913. }
  11914. ///
  11915. setting.data = uploadedImageURL;
  11916. setting.fileName = file.name;
  11917. // console.log()
  11918. winSetting.params = {
  11919. ...setting,
  11920. uploaderId,
  11921. };
  11922. console.log("ss-componets中change之后的winSetting", winSetting);
  11923. SS.openDialog(winSetting, {
  11924. success: function (win) {
  11925. console.log("裁剪插件成功");
  11926. // win.cropperSetting = setting;
  11927. },
  11928. end: function () {
  11929. console.log("裁剪插件结束");
  11930. $(setting.el).val(""); // 清空文件选择
  11931. },
  11932. });
  11933. } else {
  11934. /* 再改,增加非图片时直接上传。Lin
  11935. alert("请选择图片文件,支持jpg、jpeg、png格式");
  11936. */
  11937. const reader = new FileReader();
  11938. reader.onload = (e) => {
  11939. const blob = new Blob([e.target.result], {type: 'application/octet-stream'});
  11940. /// 抄自 cropper.jsp 里的 getCroppedCanvas: function () { -- "获取上传裁剪图片"。Lin
  11941. const formData = new FormData();
  11942. formData.append('fileEdit', new File([blob], file.name)); // , setting.fileName))。Lin
  11943. formData.append("application", ""); // "如果没有这个,后台会报错"。Lin
  11944. // FtpServ.rdFileItemMapByReq() 里取不到 Map."true" -- Key = true 时,Value 为 fieldName = "application"。Lin
  11945. $.ajax(setting.uploadUrl, {
  11946. method: "POST",
  11947. data: formData,
  11948. processData: false,
  11949. contentType: false,
  11950. dataType: 'json',
  11951. success(data) {
  11952. if (data.fileList.length > 0) {
  11953. setting.success(data.fileList[0].path);
  11954. window.top.SS.cropper.clearSetting(uploaderId);
  11955. } else {
  11956. console.log('data.data[0].msg',data.data[0].msg);
  11957. }
  11958. },
  11959. error() {
  11960. alert('error');
  11961. }
  11962. });
  11963. ///
  11964. };
  11965. reader.readAsArrayBuffer(file);
  11966. }
  11967. }
  11968. });
  11969. return uploaderId;
  11970. },
  11971. verify: function (setting) {
  11972. if (!setting) {
  11973. console.error(" cropper setting is not undefined! ");
  11974. return false;
  11975. }
  11976. if (!setting.el) {
  11977. console.error(" cropper setting.el is not undefined! ");
  11978. return false;
  11979. }
  11980. if (setting.photoSize) {
  11981. if (
  11982. (!setting.photoSize.width && setting.photoSize.height) ||
  11983. (!setting.photoSize.height && setting.photoSize.width)
  11984. ) {
  11985. console.error(
  11986. " cropper setting.photoSize { width, height } is not undefined! "
  11987. );
  11988. return false;
  11989. }
  11990. }
  11991. if (!setting.box) {
  11992. setting.box = "1";
  11993. }
  11994. if (!setting.aspectRatio) {
  11995. setting.aspectRatio = NaN; // = 1 / 1;。改,增加支持自由裁剪比例 -- 不锁定宽高比。Lin
  11996. }
  11997. return true;
  11998. },
  11999. verifySize: function (fileEl, maxSize) {
  12000. // 判断是否为IE浏览器: /msie/i.test(navigator.userAgent) 为一个简单正则
  12001. var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  12002. var fileSize = 0;
  12003. if (isIE && !fileEl.files) {
  12004. // IE浏览器
  12005. var filePath = fileEl.value; // 获得上传文件的绝对路径
  12006. var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
  12007. var file = fileSystem.GetFile(filePath);
  12008. fileSize = file.Size; // 文件大小,单位:b
  12009. } else {
  12010. // 非IE浏览器
  12011. fileSize = fileEl.files[0].size;
  12012. }
  12013. var size = fileSize / 1024 / 1024;
  12014. return !(size > maxSize);
  12015. },
  12016. // 获取特定上传组件的setting
  12017. getSetting: function (uploaderId) {
  12018. if (!window.top.SS?.cropper) {
  12019. console.warn("顶层窗口中未找到 SS.cropper");
  12020. return null;
  12021. }
  12022. // 优先从 Map 中获取
  12023. let setting = window.top.SS.cropper.settings.get(uploaderId);
  12024. // 如果 Map 中没有,尝试从备份中获取
  12025. if (!setting && window.top.SS.cropper._backupSettings[uploaderId]) {
  12026. console.log("从备份中恢复 setting");
  12027. setting = window.top.SS.cropper._backupSettings[uploaderId];
  12028. // 恢复到 Map 中
  12029. window.top.SS.cropper.settings.set(uploaderId, setting);
  12030. }
  12031. return setting;
  12032. },
  12033. // 清理特定上传组件的setting
  12034. clearSetting: function (uploaderId) {
  12035. if (!window.top.SS?.cropper) return;
  12036. window.top.SS.cropper.settings.delete(uploaderId);
  12037. delete window.top.SS.cropper._backupSettings[uploaderId];
  12038. console.log(
  12039. "清理设置后的 Map size:",
  12040. window.top.SS.cropper.settings.size
  12041. );
  12042. },
  12043. };
  12044. /**
  12045. * 获取url中的参数
  12046. * @returns {Object}
  12047. */
  12048. window.SS.getQueryParams = function () {
  12049. const params = {};
  12050. const queryString = window.location.search.substring(1);
  12051. const pairs = queryString.split("&");
  12052. for (let i = 0; i < pairs.length; i++) {
  12053. const pair = pairs[i].split("=");
  12054. params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  12055. }
  12056. if (params.params) {
  12057. try {
  12058. params.params = JSON.parse(params.params);
  12059. } catch (e) {
  12060. console.error("Failed to parse params:", e);
  12061. }
  12062. }
  12063. return params;
  12064. };
  12065. /**
  12066. * 创建vue应用
  12067. * @param {Object} config 配置项
  12068. * @values {String} config.el 挂载的元素
  12069. * @values {Boolean} config.isDialogPage 是否是弹窗页面 决定了是否可以使用顶天立地
  12070. * @values {Object} config.vueOptions vue配置项
  12071. * @returns {Object} vue实例
  12072. */
  12073. window.ss = window.ss || window.SS;
  12074. window.ss.dom = window.ss.dom || window.SS.dom;
  12075. window.SS.dom._vueAppSeq =
  12076. window.SS.dom._vueAppSeq || window.ss.dom._vueAppSeq || 0;
  12077. window.SS.dom.vueApps = window.SS.dom.vueApps || window.ss.dom.vueApps || [];
  12078. window.ss.dom._vueAppSeq = window.SS.dom._vueAppSeq;
  12079. window.ss.dom.vueApps = window.SS.dom.vueApps;
  12080. window.SS.dom._registerVueApp = function ({ vm, el, appKey, scope, href }) {
  12081. if (!vm) return null;
  12082. const registry = window.SS.dom.vueApps || (window.SS.dom.vueApps = []);
  12083. const id = `vue-app-${++window.SS.dom._vueAppSeq}`;
  12084. const record = {
  12085. id,
  12086. el: el || "",
  12087. appKey: appKey || "",
  12088. scope: scope || "current",
  12089. href: href || window.location.href,
  12090. createdAt: Date.now(),
  12091. vm,
  12092. win: window,
  12093. };
  12094. registry.push(record);
  12095. window.SS.dom.currentApp = vm;
  12096. window.SS.dom.currentAppRecord = record;
  12097. if (window.ss && window.ss.dom) {
  12098. window.ss.dom.vueApps = registry;
  12099. window.ss.dom._vueAppSeq = window.SS.dom._vueAppSeq;
  12100. window.ss.dom.currentApp = vm;
  12101. window.ss.dom.currentAppRecord = record;
  12102. }
  12103. return record;
  12104. };
  12105. window.SS.dom._getVmData = function (vm) {
  12106. if (!vm) return null;
  12107. return vm.$data || vm;
  12108. };
  12109. window.SS.dom._hasVmKey = function (vm, key) {
  12110. if (!vm || !key) return false;
  12111. const data = window.SS.dom._getVmData(vm);
  12112. return key in vm || (!!data && key in data);
  12113. };
  12114. window.SS.dom._hasVmMethod = function (vm, methodName) {
  12115. return !!(vm && methodName && typeof vm[methodName] === "function");
  12116. };
  12117. window.SS.dom._normalizeBridgeOptions = function (
  12118. options = {},
  12119. defaults = {}
  12120. ) {
  12121. return {
  12122. scope: "chain",
  12123. ...defaults,
  12124. ...options,
  12125. };
  12126. };
  12127. window.SS.dom._matchVueRecord = function (record, options = {}) {
  12128. if (!record || !record.vm) return false;
  12129. if (options.appKey && record.appKey !== options.appKey) return false;
  12130. if (options.el && record.el !== options.el) return false;
  12131. if (options.id && record.id !== options.id) return false;
  12132. if (
  12133. options.dataKey &&
  12134. !window.SS.dom._hasVmKey(record.vm, options.dataKey)
  12135. ) {
  12136. return false;
  12137. }
  12138. if (
  12139. options.methodName &&
  12140. !window.SS.dom._hasVmMethod(record.vm, options.methodName)
  12141. ) {
  12142. return false;
  12143. }
  12144. if (typeof options.predicate === "function") {
  12145. try {
  12146. if (!options.predicate(record.vm, record)) {
  12147. return false;
  12148. }
  12149. } catch (e) {
  12150. return false;
  12151. }
  12152. }
  12153. return true;
  12154. };
  12155. window.SS.dom._getWindowVueRecord = function (targetWindow, options = {}) {
  12156. if (!targetWindow || !targetWindow.SS || !targetWindow.SS.dom) return null;
  12157. const registry = targetWindow.SS.dom.vueApps || [];
  12158. for (let i = registry.length - 1; i >= 0; i--) {
  12159. if (targetWindow.SS.dom._matchVueRecord(registry[i], options)) {
  12160. return registry[i];
  12161. }
  12162. }
  12163. const currentRecord = targetWindow.SS.dom.currentAppRecord;
  12164. if (targetWindow.SS.dom._matchVueRecord(currentRecord, options)) {
  12165. return currentRecord;
  12166. }
  12167. const currentVm = targetWindow.SS.dom.currentApp;
  12168. const fallbackRecord = currentVm
  12169. ? {
  12170. vm: currentVm,
  12171. win: targetWindow,
  12172. el: "",
  12173. appKey: "",
  12174. id: "",
  12175. }
  12176. : null;
  12177. if (targetWindow.SS.dom._matchVueRecord(fallbackRecord, options)) {
  12178. return fallbackRecord;
  12179. }
  12180. return null;
  12181. };
  12182. window.SS.dom.getVueAppRecord = function (options = {}) {
  12183. const scope = options.scope || "current";
  12184. if (scope === "current") {
  12185. return window.SS.dom._getWindowVueRecord(window, options);
  12186. }
  12187. if (scope === "top") {
  12188. try {
  12189. return window.SS.dom._getWindowVueRecord(window.top, options);
  12190. } catch (e) {
  12191. return null;
  12192. }
  12193. }
  12194. if (scope === "parent") {
  12195. try {
  12196. if (window.parent && window.parent !== window) {
  12197. return window.SS.dom._getWindowVueRecord(window.parent, options);
  12198. }
  12199. } catch (e) {
  12200. return null;
  12201. }
  12202. return null;
  12203. }
  12204. if (scope === "chain") {
  12205. let currentWindow = window;
  12206. while (currentWindow) {
  12207. try {
  12208. const record = window.SS.dom._getWindowVueRecord(
  12209. currentWindow,
  12210. options
  12211. );
  12212. if (record) {
  12213. return record;
  12214. }
  12215. } catch (e) {
  12216. return null;
  12217. }
  12218. if (currentWindow === currentWindow.parent) {
  12219. break;
  12220. }
  12221. currentWindow = currentWindow.parent;
  12222. }
  12223. return null;
  12224. }
  12225. return window.SS.dom._getWindowVueRecord(window, options);
  12226. };
  12227. window.SS.dom.getVueApp = function (options = {}) {
  12228. const record = window.SS.dom.getVueAppRecord(options);
  12229. return record ? record.vm : null;
  12230. };
  12231. window.SS.dom.getVmValue = function (key, options = {}) {
  12232. const vm = window.SS.dom.getVueApp(
  12233. window.SS.dom._normalizeBridgeOptions(options, { dataKey: key })
  12234. );
  12235. if (!vm) return undefined;
  12236. return vm[key];
  12237. };
  12238. window.SS.dom.setVmValue = function (key, value, options = {}) {
  12239. const vm = window.SS.dom.getVueApp(
  12240. window.SS.dom._normalizeBridgeOptions(options, { dataKey: key })
  12241. );
  12242. if (!vm) return false;
  12243. vm[key] = value;
  12244. return true;
  12245. };
  12246. window.SS.dom.callVmMethod = function (methodName, args = [], options = {}) {
  12247. const vm = window.SS.dom.getVueApp(
  12248. window.SS.dom._normalizeBridgeOptions(options, { methodName })
  12249. );
  12250. if (!vm || typeof vm[methodName] !== "function") {
  12251. return undefined;
  12252. }
  12253. return vm[methodName].apply(vm, args);
  12254. };
  12255. window.SS.dom.get = function (key, options = {}) {
  12256. return window.SS.dom.getVmValue(key, options);
  12257. };
  12258. window.SS.dom.set = function (key, value, options = {}) {
  12259. return window.SS.dom.setVmValue(key, value, options);
  12260. };
  12261. window.SS.dom.call = function (methodName, args = [], options = {}) {
  12262. return window.SS.dom.callVmMethod(methodName, args, options);
  12263. };
  12264. [
  12265. "_registerVueApp",
  12266. "_getVmData",
  12267. "_hasVmKey",
  12268. "_hasVmMethod",
  12269. "_normalizeBridgeOptions",
  12270. "_matchVueRecord",
  12271. "_getWindowVueRecord",
  12272. "getVueAppRecord",
  12273. "getVueApp",
  12274. "getVmValue",
  12275. "setVmValue",
  12276. "callVmMethod",
  12277. "get",
  12278. "set",
  12279. "call",
  12280. ].forEach((name) => {
  12281. window.ss.dom[name] = window.SS.dom[name];
  12282. });
  12283. window.SS.dom.initializeFormApp = function (config) {
  12284. const {
  12285. el,
  12286. isDialogPage = false,
  12287. appKey = "",
  12288. scope = "current",
  12289. ...vueOptions
  12290. } = config;
  12291. const app = createApp({
  12292. ...vueOptions,
  12293. });
  12294. if (isDialogPage) {
  12295. function checkScroll() {
  12296. const elements = document.querySelectorAll(".fit-height-content");
  12297. let hasScrollBar = false;
  12298. elements.forEach((el) => {
  12299. if (el.scrollHeight > el.clientHeight) {
  12300. hasScrollBar = true;
  12301. }
  12302. });
  12303. window.parent.postMessage({ hasScrollBar }, "*");
  12304. }
  12305. function addScrollListeners() {
  12306. const elements = document.querySelectorAll("div");
  12307. elements.forEach((el) => {
  12308. el.addEventListener("scroll", checkScroll);
  12309. });
  12310. }
  12311. const observer = new MutationObserver(() => {
  12312. addScrollListeners();
  12313. checkScroll();
  12314. });
  12315. observer.observe(document.body, {
  12316. childList: true,
  12317. subtree: true,
  12318. });
  12319. window.addEventListener("resize", checkScroll);
  12320. }
  12321. app.component("SsLoginIcon", SsLoginIcon);
  12322. app.component("SsMark", SsMark);
  12323. app.component("SsFullStyleHeader", SsFullStyleHeader);
  12324. app.component("SsDialog", SsDialog);
  12325. app.component("SsInp", SsInput);
  12326. app.component("SsObjp", SsObjp);
  12327. app.component("SsHidden", SsHidden);
  12328. app.component("SsCcp", SsCcp);
  12329. /* 再改,<ss-date-picker 改为 <ss-datep -- 规范命名。Lin
  12330. app.component("SsDatePicker", SsDatePicker);
  12331. */ app.component("ss-datep", SsDatePicker);
  12332. app.component("SsIcon", SsIcon);
  12333. app.component("SsCommonIcon", SsCommonIcon);
  12334. app.component("SsBreadcrumb", SsBreadcrumb);
  12335. app.component("SsEditor", SsEditor);
  12336. app.component("SsDialogIcon", SsDialogIcon);
  12337. /* 再改,<ss-bottom-button 改为 <ss-btn -- 考虑合并 <ss-search-xxx 到 <ss-xxx 里 -- 增加 mode: 属性。Lin
  12338. * <ss-bottom-button 对 <ss-search-button,<ss-inp 对 <ss-search-inp
  12339. app.component("SsBottomButton", SsBottomButton);
  12340. */ app.component("ss-btn", SsBottomButton);
  12341. app.component("SsNavIcon", SsNavIcon);
  12342. app.component("SsHeaderIcon", SsHeaderIcon);
  12343. app.component("SsGolbalMenuIcon", SsGolbalMenuIcon);
  12344. app.component("SsCartListIcon", SsCartListIcon);
  12345. app.component("SsQuickIcon", SsQuickIcon);
  12346. app.component("SsFormIcon", SsFormIcon);
  12347. app.component("SsBottomDivIcon", SsBottomDivIcon);
  12348. app.component("SsEditorIcon", SsEditorIcon);
  12349. app.component("SsValidate", SsValidate);
  12350. app.component("SsOnoff", SsOnoff); // , Ssonoff)。Lin
  12351. app.component("SsonoffArray", SsonoffArray);
  12352. app.component("SsTextarea", SsTextarea);
  12353. app.component("SsLoginInput", SsLoginInput);
  12354. app.component("SsLoginButton", SsLoginButton);
  12355. app.component("SsSearch", SsSearch);
  12356. app.component("SsCartItem", SsCartItem);
  12357. app.component("SsCartItem2", SsCartItem2);
  12358. app.component("SsListCard", SsListCard);
  12359. app.component("ss-cobj-card-list", SsCObjCardList);
  12360. app.component("SsFolderCard", SsFolderCard);
  12361. app.component("ss-sidebar", SsSidebar);
  12362. app.component("ss-sidebar-buttons", SsSidebarButtons);
  12363. app.component("ss-sidebar-chart", SsSidebarChart);
  12364. app.component("ss-sidebar-chart-hover", SsSidebarChartHover);
  12365. app.component("ss-sidebar-list", SsSidebarList);
  12366. app.component("ss-sidebar-report-table", SsSidebarReportTable);
  12367. app.component("SsFolderCartView", SsFolderCartView);
  12368. app.component("SsPage", SsPage);
  12369. app.component("SsRightInfo", SSRightInfo);
  12370. app.component("SsSuccessPopup", SsSuccessPopup);
  12371. app.component("SsErrorDialog", SsErrorDialog);
  12372. app.component("SsVerify", SsVerify);
  12373. app.component("SsVerifyNode", SsVerifyNode);
  12374. app.component("SsOrcImgBox", SsOrcImgBox);
  12375. app.component("ss-search-input", SsSearchInput);
  12376. app.component("ss-nump", SsNump);
  12377. app.component("ss-search-date-picker", SsSearchDatePicker);
  12378. app.component("ss-search-button", SsSearchButton);
  12379. app.component("ss-drop-button", SsDropButton);
  12380. app.component("ss-sub-tab", SsSubTab);
  12381. app.component("ss-cms", SsCms);
  12382. app.component("ss-img", SsImgUpload);
  12383. app.component("ss-ul", SsUpload);
  12384. app.use(ElementPlus, {
  12385. locale: ElementPlusLocaleZhCn,
  12386. });
  12387. for (const componentName in IndexComponents) {
  12388. app.component(componentName, IndexComponents[componentName]);
  12389. }
  12390. for (const componentName in EchartComponents) {
  12391. app.component(componentName, EchartComponents[componentName]);
  12392. }
  12393. let vm;
  12394. try {
  12395. vm = app.mount(el);
  12396. vm.data = vueOptions.data();
  12397. window.SS.dom._registerVueApp({
  12398. vm,
  12399. el,
  12400. appKey,
  12401. scope,
  12402. href: window.location.href,
  12403. });
  12404. console.log("vm:", vm);
  12405. console.log("vueOptions:", vueOptions);
  12406. } catch (error) {
  12407. console.log("Mount failed:" + error);
  12408. }
  12409. return vm;
  12410. };
  12411. })();