ss-components.js 386 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163
  1. import { ssIcon, commonIcon } from "./icon-config.js";
  2. import * as IndexComponents from "./ss-index-components.js";
  3. import * as EchartComponents from "./ss-echarts-compnents.js";
  4. import {
  5. isNum,
  6. toStyleStr,
  7. buildThumbUrl,
  8. openServiceDialog,
  9. pickSearchParams,
  10. } from "./tools.js"; // 功能说明:组件内统一构建缩略图URL、打开服务弹窗,减少 JSP 层字段转换 by xu 20260122
  11. import { EVEN_VAR } from "./EventBus.js";
  12. // import * as elements from "../lib/element-plus.js";
  13. (function () {
  14. const {
  15. createApp,
  16. ref,
  17. reactive,
  18. watch,
  19. onMounted,
  20. onBeforeUnmount,
  21. h,
  22. computed,
  23. resolveComponent,
  24. watchEffect,
  25. nextTick,
  26. onVnodeMounted,
  27. Teleport,
  28. inject,
  29. provide,
  30. } = Vue;
  31. // 弹窗默认遮罩z-index
  32. let currentZIndex = 100;
  33. // 目前已存在的弹窗
  34. const topWindow = window.top;
  35. topWindow.dialogInstances = topWindow.dialogInstances || [];
  36. // 新建弹窗
  37. function createSsDialogInstance(setting, callbackEvent) {
  38. currentZIndex += 10; // 动态提升 z-index
  39. const container = document.createElement("div");
  40. document.body.appendChild(container);
  41. const app = Vue.createApp({
  42. render() {
  43. return h(SsDialog, {
  44. ...setting,
  45. zIndex: currentZIndex,
  46. onClose() {
  47. document.body.removeChild(container); // 仅移除弹窗容器
  48. const index = topWindow.dialogInstances.indexOf(app);
  49. if (index > -1) {
  50. topWindow.dialogInstances.splice(index, 1); // 移除实例
  51. }
  52. // 关闭后的回调
  53. if (callbackEvent && typeof callbackEvent === "function") {
  54. callbackEvent();
  55. }
  56. app.unmount(); // 仅卸载弹窗实例
  57. if (container.parentNode) {
  58. container.parentNode.removeChild(container); // 确保移除容器
  59. }
  60. },
  61. });
  62. },
  63. });
  64. topWindow.dialogInstances.push({ app, callbackEvent, container });
  65. app.component("ss-mark", SsMark); // 注册 ss-mark 组件
  66. app.component("ss-icon", SsIcon);
  67. app.component("ss-full-style-header", SsFullStyleHeader); // 注册 ss-full-style-header 组件
  68. app.mount(container);
  69. }
  70. // ss-breadcrumb 一级菜单页面面包屑
  71. const SsBreadcrumb = {
  72. name: "SsBreadcrumb",
  73. props: {
  74. level: {
  75. type: Object,
  76. default: null,
  77. },
  78. },
  79. setup(props) {
  80. const currentMenu = ref(null);
  81. const folderPath = ref([]);
  82. const eventBus = window.parent.sharedEventBus;
  83. // 监听页面变化
  84. onMounted(() => {
  85. // 获取初始页面
  86. currentMenu.value = eventBus.getState(EVEN_VAR.currentPage);
  87. folderPath.value = eventBus.getState("folderPath") || [];
  88. // 订阅页面变化
  89. eventBus.subscribe(EVEN_VAR.currentPage, (page) => {
  90. currentMenu.value = page;
  91. });
  92. eventBus.subscribe("folderPath", (path) => {
  93. folderPath.value = path || [];
  94. });
  95. });
  96. // 修改点击处理函数
  97. const handlePathClick = (index) => {
  98. if (props.level?.onBack) {
  99. // 截取到点击的位置,后面的路径会被销毁
  100. const newPath = folderPath.value.slice(0, index + 1);
  101. eventBus.publish("folderPath", newPath);
  102. // 返回到对应层级
  103. const targetFolder = newPath[newPath.length - 1]?.folder || null;
  104. props.level.onBack(targetFolder);
  105. }
  106. };
  107. const SsCommonIcon = resolveComponent("SsCommonIcon");
  108. return () =>
  109. h("div", { class: "bread-crumb" }, [
  110. currentMenu.value &&
  111. h(
  112. "div",
  113. {
  114. onClick: () => {
  115. if (props.level?.onBack) {
  116. eventBus.publish("folderPath", []);
  117. props.level.onBack(null); // 返回到根目录
  118. } else {
  119. eventBus.publish(EVEN_VAR.currentPage, currentMenu.value);
  120. }
  121. },
  122. },
  123. currentMenu.value.label || currentMenu.value.name
  124. ),
  125. ...(folderPath.value || [])
  126. .map((folder, index) => [
  127. h(SsCommonIcon, { class: "common-icon-arrow-right" }),
  128. h(
  129. "div",
  130. {
  131. class: "bread-crumb-item",
  132. onClick: () => handlePathClick(index),
  133. style: { cursor: "pointer" },
  134. },
  135. folder.title
  136. ),
  137. ])
  138. .flat(),
  139. ]);
  140. },
  141. };
  142. // ss-input form表单的输入
  143. const SsInput = {
  144. name: "SsInp", //把SsInput改为SsInp Ben(20251225)
  145. inheritAttrs: false, // 不直接继承属性到组件根元素
  146. props: {
  147. name: {
  148. type: String,
  149. required: true,
  150. default: "",
  151. },
  152. // 接收 v-model 绑定的值
  153. errTip: {
  154. type: String,
  155. },
  156. required: {
  157. type: Boolean,
  158. default: false,
  159. },
  160. placeholder: {
  161. type: String,
  162. default: "请输入",
  163. },
  164. defaultValue: [String, Number],
  165. modelValue: [String, Number],
  166. // 新增:附件配置
  167. fj: {
  168. type: Object,
  169. default: null,
  170. },
  171. // 新增:param 配置(用于附件功能)
  172. param: {
  173. type: Object,
  174. default: null,
  175. },
  176. // 新增:高度配置
  177. height: {
  178. type: String,
  179. default: "",
  180. },
  181. // 功能说明:传 height 时允许回车换行(多行输入);未传 height 默认单行 by xu 20260204
  182. },
  183. emits: ["update:modelValue", "input", "blur", "change"], // 允许更新 v-model 绑定的值
  184. setup(props, { emit }) {
  185. const errMsg = ref("");
  186. const inputRef = ref(null);
  187. const textareaRef = ref(null);
  188. const inputValue = ref(props.modelValue || props.defaultValue || "");
  189. const contentFloatingDiv = ref(false); // 控制浮动 DIV 的显示
  190. const floatingDivPosition = ref("bottom"); // 'bottom' 或 'top'
  191. const isFocused = ref(false); // 跟踪焦点状态
  192. // 附件相关变量(仅在传入 param 时初始化)
  193. let fjid = ref(null);
  194. let fjName = null;
  195. let mode = null;
  196. if (props.param && props.param.button) {
  197. fjid = ref(props.param.button.val);
  198. fjName = props.param.button.desc;
  199. mode = props.param.mode;
  200. }
  201. // 功能说明:只有存在非空校验(notNull)且值为空时,才显示红线 by xu 20260402
  202. const hasNotNullRule = () => {
  203. const validations = window.ssVm?.validations?.get(props.name);
  204. if (!validations || validations.length === 0) return false;
  205. return validations.some(v => v.ruleName && v.ruleName.includes('notNull'));
  206. };
  207. const showRequired = computed(() => {
  208. const validations = window.ssVm?.validations?.get(props.name);
  209. if (!validations || validations.length === 0) return false;
  210. // 检查是否存在 notNull 规则
  211. const hasNotNull = validations.some(v => v.ruleName && v.ruleName.includes('notNull'));
  212. // 有非空规则且值为空时显示红线
  213. if (hasNotNull && !inputValue.value) {
  214. return true;
  215. }
  216. return false;
  217. });
  218. // 计算floatdiv应该向上还是向下展开
  219. const calculateFloatingDivPosition = () => {
  220. nextTick(() => {
  221. const textarea = inputRef.value;
  222. if (!textarea) return;
  223. const rect = textarea.getBoundingClientRect();
  224. const viewportHeight = window.innerHeight;
  225. // 预估floatdiv的高度(最多5行 * 20px + 上下padding + border)
  226. const estimatedFloatDivHeight = 20 * 5 + 10 + 2; // 5行 + padding + border = 112px
  227. // 检查下方空间
  228. const spaceBelow = viewportHeight - rect.bottom;
  229. // 如果下方空间不足,且上方空间足够,则向上展开
  230. if (
  231. spaceBelow < estimatedFloatDivHeight &&
  232. rect.top > estimatedFloatDivHeight
  233. ) {
  234. floatingDivPosition.value = "top";
  235. } else {
  236. floatingDivPosition.value = "bottom";
  237. }
  238. });
  239. };
  240. // 计算floatdiv的top偏移量
  241. const getFloatingDivTop = computed(() => {
  242. if (props.height) {
  243. // 有height时,padding是5px
  244. return "5px";
  245. } else {
  246. // 没有height时是单行居中,需要计算居中位置
  247. // 假设input-container高度是32px(或者从CSS读取),单行20px
  248. // 居中偏移 = (容器高度 - 行高) / 2 = (32 - 20) / 2 = 6px
  249. return "6px";
  250. }
  251. });
  252. const validate = () => {
  253. if (window.ssVm) {
  254. const result = window.ssVm.validateField(props.name);
  255. errMsg.value = result.valid ? "" : result.message;
  256. }
  257. };
  258. // 使用 watch 监听 props.errTip 和 props.modelValue 的变化
  259. watch(
  260. () => props.errTip,
  261. (newVal) => {
  262. errMsg.value = newVal;
  263. },
  264. { immediate: true }
  265. );
  266. watch(
  267. () => props.modelValue,
  268. (newVal) => {
  269. inputValue.value = newVal;
  270. }
  271. );
  272. // 挂载时的逻辑
  273. onMounted(() => {
  274. errMsg.value = props.errTip;
  275. inputValue.value = props.modelValue || props.defaultValue || "";
  276. });
  277. // 计算并调整textarea的高度
  278. const adjustHeight = () => {
  279. nextTick(() => {
  280. const textarea = textareaRef.value;
  281. if (!textarea) return;
  282. // floatDiv的textarea始终自动计算高度,不受props.height影响
  283. // 重置高度以获得正确的scrollHeight
  284. textarea.style.height = "auto";
  285. // 计算新高度 - 统一限制为5行
  286. const lineHeight = parseInt(
  287. getComputedStyle(textarea).lineHeight,
  288. 10
  289. );
  290. const maxHeight = lineHeight * 5; // 统一为5行
  291. const newHeight = Math.min(textarea.scrollHeight, maxHeight);
  292. textarea.style.height = `${newHeight}px`;
  293. });
  294. };
  295. // 检查是否应该显示浮动窗口(需要同时满足:有焦点 + 内容超出)
  296. // 修复新增页面点击就出现floatdiv的问题 by xu 20251212
  297. const checkShouldShowFloatingDiv = () => {
  298. const textarea = inputRef.value;
  299. if (!textarea) return false;
  300. // 首先检查是否有内容,没有内容时不显示floatdiv by xu 20251212
  301. if (!inputValue.value || inputValue.value.toString().trim() === "") {
  302. console.log("[floatdiv] 内容为空,不显示floatdiv");
  303. return false;
  304. }
  305. // 判断内容是否超出 by xu 20251212
  306. // 同时检查横向和纵向溢出,任一方向溢出都应显示floatdiv
  307. // 纵向溢出需要加容差值,避免padding/border导致的误判 by xu 20251212
  308. const verticalTolerance = 5; // 容差值5px
  309. const isHorizontalOverflow =
  310. textarea.scrollWidth > textarea.clientWidth;
  311. const isVerticalOverflow =
  312. textarea.scrollHeight > textarea.clientHeight + verticalTolerance;
  313. const isOverflow = isHorizontalOverflow || isVerticalOverflow;
  314. console.log(
  315. "[floatdiv] 溢出检测 - scrollWidth:",
  316. textarea.scrollWidth,
  317. "clientWidth:",
  318. textarea.clientWidth,
  319. "horizontalOverflow:",
  320. isHorizontalOverflow
  321. );
  322. console.log(
  323. "[floatdiv] 溢出检测 - scrollHeight:",
  324. textarea.scrollHeight,
  325. "clientHeight:",
  326. textarea.clientHeight,
  327. "tolerance:",
  328. verticalTolerance,
  329. "verticalOverflow:",
  330. isVerticalOverflow
  331. );
  332. const shouldShow = isFocused.value && isOverflow;
  333. console.log(
  334. "[floatdiv] 最终判断 - isFocused:",
  335. isFocused.value,
  336. "isOverflow:",
  337. isOverflow,
  338. "shouldShow:",
  339. shouldShow
  340. );
  341. // 需要同时满足:有焦点 + 内容超出
  342. return shouldShow;
  343. };
  344. // 定义事件处理函数
  345. const onInput = (event) => {
  346. const newValue = event.target.value;
  347. inputValue.value = newValue;
  348. emit("update:modelValue", newValue);
  349. validate(); // 输入时验证
  350. nextTick(() => {
  351. // 检查是否需要显示浮动div
  352. contentFloatingDiv.value = checkShouldShowFloatingDiv();
  353. // 如果需要显示floatdiv,计算其位置
  354. if (contentFloatingDiv.value) {
  355. calculateFloatingDivPosition();
  356. }
  357. });
  358. adjustHeight();
  359. };
  360. const onFocus = (event) => {
  361. // 设置焦点状态为true
  362. isFocused.value = true;
  363. adjustHeight();
  364. // 检查是否应该显示浮动窗口
  365. nextTick(() => {
  366. contentFloatingDiv.value = checkShouldShowFloatingDiv();
  367. if (contentFloatingDiv.value) {
  368. calculateFloatingDivPosition();
  369. }
  370. });
  371. };
  372. // 失去焦点时进行验证
  373. const onBlur = (event) => {
  374. emit("blur", event.target);
  375. validate(); // 失焦时验证
  376. nextTick(() => {
  377. // 如果焦点不在 textarea 上,则隐藏浮动 div
  378. if (!document.activeElement.classList.contains("input-control")) {
  379. isFocused.value = false;
  380. contentFloatingDiv.value = false;
  381. }
  382. });
  383. };
  384. const onChange = (event) => {
  385. inputValue.value = event.target.value || "";
  386. emit("change", inputValue.value);
  387. };
  388. const onMouseover = (event) => {
  389. nextTick(() => {
  390. // setTimeout(contentFloatingDiv.value = true, 500)
  391. });
  392. };
  393. const onMouseleave = (event) => {
  394. // contentFloatingDiv.value = false
  395. };
  396. // 功能说明:传了 height 视为多行允许回车;未传 height 拦截回车(单行表现) by xu 20260204
  397. const onKeydown = (event) => {
  398. const allowMultiline =
  399. typeof props.height === "string" && props.height.trim() !== "";
  400. if (!allowMultiline && event.key === "Enter") {
  401. event.preventDefault();
  402. }
  403. };
  404. // 附件按钮点击处理(从 SsEditor 搬运)
  405. const onAttachmentClick = (e) => {
  406. e.preventDefault();
  407. if (!props.param || !props.param.button) {
  408. console.warn("未配置 param 参数");
  409. return;
  410. }
  411. console.log("附件点击了");
  412. console.log("param", props.param);
  413. console.log("cmsAddUrl", props.param.button.cmsAddUrl);
  414. // 如果 fjid 为空,先调用 cmsAddUrl 创建
  415. if (fjid.value == null || fjid.value == "") {
  416. $.ajax({
  417. type: "post",
  418. url: props.param.button.cmsAddUrl,
  419. async: false,
  420. data: {
  421. name: "fjid",
  422. ssNrObjName: "sh",
  423. ssNrObjId: "",
  424. },
  425. success: function (_fjid) {
  426. console.log("cmsAddUrl success", _fjid);
  427. fjid.value = _fjid;
  428. },
  429. });
  430. }
  431. // 构建参数字符串
  432. var str =
  433. "&nrid=T-" +
  434. fjid.value +
  435. "&objectId=" +
  436. fjid.value +
  437. "&objectName=" +
  438. fjName +
  439. "&callback=" +
  440. (window["fjidCallbackName"] || "");
  441. console.log("str", str);
  442. // 打开附件编辑对话框
  443. SS.openDialog({
  444. src: props.param.button.cmsUpdUrl + str,
  445. headerTitle: "编辑",
  446. width: 900,
  447. high: 664,
  448. zIndex: 51,
  449. });
  450. };
  451. return {
  452. errMsg,
  453. inputValue,
  454. showRequired,
  455. onInput,
  456. onBlur,
  457. onChange,
  458. onMouseover,
  459. onMouseleave,
  460. onKeydown, // 新增:键盘事件处理 by xu 20251212
  461. contentFloatingDiv,
  462. floatingDivPosition,
  463. getFloatingDivTop,
  464. inputRef,
  465. textareaRef,
  466. onFocus,
  467. onAttachmentClick,
  468. fjid, // 附件 ID,用于隐藏字段
  469. };
  470. },
  471. render() {
  472. const { resolveComponent, h } = Vue;
  473. const SsIcon = resolveComponent("ss-icon");
  474. const SsEditorIcon = resolveComponent("SsEditorIcon");
  475. // 构建主textarea的样式
  476. const mainTextareaStyle = {};
  477. if (this.height) {
  478. mainTextareaStyle.height = "auto";
  479. // mainTextareaStyle.paddingTop = '5px'; // 有高度时加上padding-top
  480. // mainTextareaStyle.paddingBottom = '5px'; // 有高度时加上padding-bottom
  481. } else {
  482. // 没有指定height时,固定为单行高度
  483. mainTextareaStyle.height = "20px"; // 行高20px
  484. mainTextareaStyle.lineHeight = "20px"; // 确保单行垂直居中
  485. mainTextareaStyle.display = "flex";
  486. mainTextareaStyle.marginBottom = "5px";
  487. }
  488. // 如果有附件按钮,为按钮留出空间
  489. if (this.fj || (this.param && this.param.button)) {
  490. //加上&&this.param.button条件 Ben(20251221)
  491. mainTextareaStyle.paddingRight = "75px";
  492. }
  493. const mainTextareaRows = this.height
  494. ? Math.floor(parseFloat("80px") / 20)
  495. : 1;
  496. return h("div", { class: "input" }, [
  497. h("div", { class: "input-container" }, [
  498. h("div", { class: "input", style: "padding:5px 0" }, [
  499. h("textarea", {
  500. ref: "inputRef",
  501. class: "input-control",
  502. name: this.name,
  503. value: this.inputValue,
  504. onInput: this.onInput,
  505. onFocus: this.onFocus,
  506. onBlur: this.onBlur,
  507. onChange: this.onChange,
  508. onKeydown: this.onKeydown, // 新增:禁止回车换行 by xu 20251212
  509. placeholder: this.placeholder,
  510. onMouseover: this.onMouseover, // 监听鼠标悬停
  511. onMouseleave: this.onMouseleave, // 监听鼠标离开
  512. rows: mainTextareaRows,
  513. ...this.$attrs,
  514. style: mainTextareaStyle,
  515. autocomplete: "off",
  516. }),
  517. // 附件按钮(优先使用 param,兼容旧的 fj)
  518. this.fj || (this.param && this.param.button) //加上&&this.param.button条件 Ben(20251221)
  519. ? h(
  520. "button",
  521. {
  522. type: "button",
  523. class: "fj-button",
  524. onClick: this.param
  525. ? this.onAttachmentClick
  526. : (e) => {
  527. e.preventDefault();
  528. console.log("附件配置:", this.fj);
  529. },
  530. },
  531. [
  532. h(SsEditorIcon, {
  533. class: "editor-icon-link",
  534. }),
  535. h("span", { class: "fj-button-text" }, "附件"),
  536. ]
  537. )
  538. : null,
  539. ]),
  540. this.contentFloatingDiv || ""
  541. ? h(
  542. "div",
  543. {
  544. class: "floating-div",
  545. style:
  546. this.floatingDivPosition === "bottom"
  547. ? {
  548. // 向下展开: 覆盖原输入框,top对齐首行
  549. top: this.getFloatingDivTop,
  550. bottom: "auto",
  551. }
  552. : {
  553. // 向上展开: 同样覆盖原输入框,但从底部开始计算
  554. top: "auto",
  555. bottom: this.height ? "5px" : "6px", // 对齐到原textarea的底部padding位置
  556. },
  557. },
  558. [
  559. h("textarea", {
  560. ref: "textareaRef",
  561. class: "input-control",
  562. value: this.inputValue,
  563. onInput: this.onInput,
  564. onBlur: this.onBlur,
  565. onFocus: this.onFocus,
  566. onKeydown: this.onKeydown, // 新增:禁止回车换行 by xu 20251212
  567. onMouseover: this.onMouseover, // 监听鼠标悬停
  568. onMouseleave: this.onMouseleave, // 监听鼠标离开
  569. autocomplete: "off",
  570. onVnodeMounted: (vnode) => {
  571. vnode.el.focus();
  572. },
  573. }),
  574. ]
  575. )
  576. : null,
  577. // this.errMsg ? h(SsValidate, { errMsg: this.errMsg }) : null,
  578. ]),
  579. // 附件相关的隐藏字段(仅在有 param 时才渲染)
  580. this.param && [
  581. // fjid 隐藏字段(只有当 fjid 有值时才渲染)
  582. this.fjid &&
  583. this.fjid.value &&
  584. h("input", {
  585. type: "hidden",
  586. name: "fjid",
  587. value: this.fjid.value,
  588. }),
  589. // 其他隐藏字段根据 name 生成
  590. /* 去掉。文本框不需要(这是富文本才有的) Ben 20251205
  591. h("input", {
  592. type: "hidden",
  593. name: this.name.replace(/wj$/, "") + "Edit",
  594. value: this.inputValue
  595. }),
  596. */
  597. // h("input", {
  598. // type: "hidden",
  599. // name: this.name.replace(/wj$/, "") + "wj",
  600. // value: this.inputValue
  601. // }),
  602. /* 去掉。文本框不需要(这是富文本才有的) Ben 20251205
  603. h("input", {
  604. type: "hidden",
  605. name: "ueditorpath",
  606. value: this.name
  607. }),
  608. */
  609. ],
  610. ]);
  611. },
  612. };
  613. // ss-normal-input 登录输入
  614. const SsLoginInput = {
  615. name: "SsLoginInput",
  616. inheritAttrs: false,
  617. props: {
  618. errTip: {
  619. type: String,
  620. },
  621. type: {
  622. type: String,
  623. default: "text",
  624. },
  625. required: {
  626. type: Boolean,
  627. default: false,
  628. },
  629. placeholder: {
  630. type: String,
  631. default: "请输入",
  632. },
  633. name: {
  634. type: String,
  635. default: "",
  636. },
  637. defaultValue: [String, Number],
  638. modelValue: [String, Number],
  639. },
  640. emits: ["update:modelValue", "input", "blur", "change"], // 允许更新 v-model 绑定的值
  641. setup(props, { emit }) {
  642. const errMsg = ref("");
  643. const inputRef = ref(null);
  644. const textareaRef = ref(null);
  645. const inputValue = ref(props.modelValue || props.defaultValue || "");
  646. // 使用 watch 监听 props.errTip 和 props.modelValue 的变化
  647. watch(
  648. () => props.errTip,
  649. (newVal) => {
  650. errMsg.value = newVal;
  651. },
  652. { immediate: true }
  653. );
  654. watch(
  655. () => props.modelValue,
  656. (newVal) => {
  657. inputValue.value = newVal;
  658. }
  659. );
  660. // 挂载时的逻辑
  661. onMounted(() => {
  662. errMsg.value = props.errTip;
  663. inputValue.value = props.modelValue || props.defaultValue || "";
  664. });
  665. // 定义事件处理函数
  666. const onInput = (event) => {
  667. const newValue = event.target.value;
  668. inputValue.value = newValue;
  669. emit("update:modelValue", newValue);
  670. };
  671. return { inputValue, onInput, inputRef, textareaRef };
  672. },
  673. render() {
  674. return h("div", { class: "input" }, [
  675. h("div", { class: "input-container" }, [
  676. h("div", { class: "input" }, [
  677. h("input", {
  678. ref: "inputRef",
  679. class: "input-control",
  680. name: this.name,
  681. value: this.inputValue,
  682. onInput: this.onInput,
  683. type: this.type,
  684. placeholder: this.placeholder,
  685. required: this.required,
  686. ...this.$attrs,
  687. autocomplete: "off",
  688. }),
  689. ]),
  690. ]),
  691. ]);
  692. },
  693. };
  694. // ss-login-button
  695. const SsLoginButton = {
  696. name: "SsLoginButton",
  697. inheritAttrs: false,
  698. props: {
  699. class: {
  700. type: String,
  701. default: "",
  702. },
  703. text: {
  704. type: String,
  705. default: "",
  706. },
  707. type: {
  708. type: String,
  709. default: "button",
  710. },
  711. },
  712. emits: ["click"],
  713. setup(props, { emit }) {
  714. // 定义事件处理函数
  715. const onClick = (event) => {
  716. // 发射一个 'click' 事件,你可以传递所需的参数
  717. emit("click", event);
  718. };
  719. return { props, onClick };
  720. },
  721. render() {
  722. const SsIcon = resolveComponent("ss-icon");
  723. const SsLoginIcon = resolveComponent("ss-login-icon");
  724. return h(
  725. "button",
  726. { class: "login-button", type: this.type, onClick: this.onClick },
  727. [
  728. h("span", [h(SsLoginIcon, { class: this.class })]),
  729. h("span", {}, this.text),
  730. ]
  731. );
  732. },
  733. };
  734. // ss-objp 下拉选择
  735. const SsObjp = {
  736. name: "SsObjp",
  737. inheritAttrs: false,
  738. props: {
  739. onchange: {
  740. //在此属性传入onChange的window全局回调函数,函数唯一参数是当前选中值 Ben(20251217)
  741. type: String,
  742. required: false,
  743. },
  744. filter: {
  745. type: String,
  746. required: false,
  747. },
  748. filterfield: {
  749. type: String,
  750. required: false,
  751. },
  752. // filterField: {
  753. // //此属性为页面表单元素的name用逗号分隔,作用为在向后台查询下拉菜单选项时,会带上这些name的表单元素的value值 Ben(20260313)
  754. // type: String,
  755. // required: false,
  756. // },
  757. cb: {
  758. type: String,
  759. required: true,
  760. },
  761. url: {
  762. type: String,
  763. required: true,
  764. },
  765. name: {
  766. type: String,
  767. required: true,
  768. },
  769. width: {
  770. type: String,
  771. default: "100%",
  772. },
  773. placeholder: {
  774. type: String,
  775. default: "请选择",
  776. },
  777. inp: {
  778. type: Boolean,
  779. default: false,
  780. },
  781. opt: {
  782. type: Array,
  783. default: () => [],
  784. },
  785. errTip: String,
  786. defaultValue: [String, Number],
  787. modelValue: [String, Number],
  788. direction: {
  789. type: String,
  790. default: "bottom",
  791. },
  792. },
  793. emits: ["update:modelValue", "input", "blur", "change"],
  794. setup(props, { emit }) {
  795. const canInput = props.inp;
  796. const errMsg = Vue.ref(props.errTip);
  797. const selectItem = Vue.ref({});
  798. let inputText = Vue.ref(""); // 用于存储输入框的文本
  799. const popupWinVisible = Vue.ref(false);
  800. const filteredOptions = Vue.ref(props.opt);
  801. const popupDirection = Vue.ref("bottom");
  802. const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
  803. const popupContentAreaMaxHeight = Vue.computed(() => {
  804. if (!popupMaxHeight.value || popupMaxHeight.value === "none")
  805. return null;
  806. const maxHeightNum = Number.parseFloat(popupMaxHeight.value);
  807. if (!Number.isFinite(maxHeightNum)) return null;
  808. // 功能说明:滚动条统一落在 .content-area(CSS 默认如此),因此需要扣掉 popup-win padding-top(10) 与 popup-content padding(15*2) by xu 20260126
  809. const contentAreaMaxHeight = Math.max(60, maxHeightNum - 40);
  810. return `${contentAreaMaxHeight}px`;
  811. });
  812. // 修复表格内下拉弹层被 overflow 截断:popup 使用 Teleport 到 body + fixed 定位 by xu 20260126
  813. const selectContainerRef = Vue.ref(null);
  814. const popupRef = Vue.ref(null);
  815. const teleportRootStyle = Vue.ref({
  816. position: "fixed",
  817. left: "0",
  818. top: "0",
  819. width: "0",
  820. height: "0",
  821. zIndex: 9999,
  822. pointerEvents: "none",
  823. });
  824. const popupLayerStyle = Vue.ref({
  825. position: "fixed",
  826. left: "0",
  827. top: "0",
  828. bottom: "auto", // 功能说明:覆盖 .popup-win.top 的 bottom 定位,避免 fixed 场景被撑高/错位 by xu 20260126
  829. minWidth: "0",
  830. zIndex: 9999,
  831. pointerEvents: "auto",
  832. });
  833. // const showRequired = Vue.computed(() => {
  834. // const hasValidationRule = window.ssVm?.validations?.has(props.name);
  835. // if (!hasValidationRule) return false;
  836. // if (errMsg.value) return true;
  837. // if (!selectItem.value?.value) return true;
  838. // return false;
  839. // });
  840. const validate = () => {
  841. if (window.ssVm) {
  842. const result = window.ssVm.validateField(props.name);
  843. // console.log("validate", window.ssVm.validateField(props.name));
  844. errMsg.value = result.valid ? "" : result.message;
  845. }
  846. };
  847. //在objPicker界面,选中value对应的项
  848. const updateSelectItem = () => {
  849. // console.log(props.opt);
  850. const item = props.opt.find((it) => it.value === props.modelValue);
  851. if (item) {
  852. selectItem.value = item;
  853. inputText.value = item.label;
  854. } else {
  855. selectItem.value = { label: "", value: "" };
  856. inputText.value = "";
  857. }
  858. // validate();
  859. };
  860. Vue.watch(
  861. () => props.errTip,
  862. (newVal) => {
  863. errMsg.value = newVal;
  864. }
  865. );
  866. Vue.watch(() => props.modelValue, updateSelectItem, { immediate: true });
  867. Vue.watch(
  868. () => props.opt,
  869. (newVal) => {
  870. updateSelectItem();
  871. filteredOptions.value = [...newVal];
  872. // console.log("filteredOptions", filteredOptions.value);
  873. }
  874. );
  875. //初始化objPicker在页面刚打开时的默认值
  876. async function initDefaultValue() {
  877. try {
  878. if (props.url && props.cb && props.modelValue) {
  879. let objectPickerParam;
  880. let url = props.url;
  881. //如果有定义过滤器
  882. if (props.filter) {
  883. //包含HTML实体的JSON字符串转为JSON对象,如原字符串是{&quot;dwid&quot;:&quot;88&quot;},注意key也必需用单引号包着
  884. // const decodedString = props.filter.replace(/&quot;/g, '"'); // 转换为: {"dwid":"88"}
  885. // objectPickerParam = JSON.parse(decodedString); // 转为json对象
  886. const filterObj = props.filter; // 转为json对象
  887. for (let k in filterObj) {
  888. let v = filterObj[k];
  889. url += "&" + k + "=" + v;
  890. }
  891. objectPickerParam = props.filter; // 转为json对象
  892. objectPickerParam["input"] = props.inp;
  893. objectPickerParam["codebook"] = props.cb;
  894. // alert(url);
  895. } else {
  896. objectPickerParam = { input: props.inp, codebook: props.cb };
  897. }
  898. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  899. const params = new URLSearchParams();
  900. params.append("objectpickerparam", objectPickerParamStr);
  901. params.append("objectpickertype", "2");
  902. params.append("objectpickervalue", props.modelValue); //需回显的值
  903. // alert("1params:"+JSON.stringify(params));
  904. axios
  905. .post(props.url, params, {
  906. headers: {
  907. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  908. },
  909. })
  910. .then((response) => {
  911. // alert(JSON.stringify(response.data));
  912. if ("timeout" == response.data.statusText) {
  913. alert("网络超时!");
  914. return;
  915. }
  916. if (response.data.result) {
  917. const keys = Object.keys(response.data.result);
  918. if (keys.length === 1) {
  919. let code = keys[0];
  920. let desc = response.data.result[keys[0]];
  921. if (props.opt)
  922. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  923. else {
  924. props.opt = [];
  925. }
  926. props.opt.push({ label: desc, value: code });
  927. updateSelectItem();
  928. // alert('props.opt:'+JSON.stringify(props.opt));
  929. }
  930. }
  931. });
  932. }
  933. } catch (error) {
  934. // callback(null, error.message); // 失败回调,传递错误
  935. }
  936. }
  937. // Vue.onMounted(updateSelectItem);
  938. const doSelectItem = (item) => {
  939. emit("update:modelValue", item.value);
  940. selectItem.value = item;
  941. inputText.value = item.label;
  942. hidePopup();
  943. nextTick(() => {
  944. console.log(item.value + "@@@props.modelValue:" + props.modelValue);
  945. validate();
  946. if (window.ssVm) {
  947. // 遍历所有验证规则,找到依赖当前字段的规则
  948. for (const [field, rules] of window.ssVm.validations.entries()) {
  949. for (const rule of rules) {
  950. if (rule.opt?.relField === props.name) {
  951. // console.log("Found dependent field:", field); // 调试日志
  952. window.ssVm.validateField(field);
  953. }
  954. }
  955. }
  956. }
  957. });
  958. callGlobalOnchg(item.value, item.label); // 值变化时尝试调用全局onchange回调函数 Ben(20251217)
  959. };
  960. // 用于调用全局onchange回调函数 Ben(20251217)
  961. const callGlobalOnchg = (value, desc) => {
  962. // 检查 onchange 属性是否提供了有效的函数名
  963. if (props.onchange && typeof props.onchange === "string") {
  964. // 检查 window 对象上是否存在该函数
  965. if (
  966. typeof window !== "undefined" &&
  967. window[props.onchange] &&
  968. typeof window[props.onchange] === "function"
  969. ) {
  970. try {
  971. window[props.onchange](value, desc); // 调用全局函数,并传入当前选中值
  972. } catch (error) {
  973. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  974. }
  975. } else {
  976. console.warn(`全局函数 ${props.onchange} 未定义或不是一个函数。`);
  977. }
  978. }
  979. };
  980. //可录入的objPicker,更新下拉菜单选项
  981. async function updateOptionBYInputText(inpTxt) {
  982. try {
  983. let objectPickerParam;
  984. let url = props.url;
  985. if (props.url && props.cb) {
  986. //如果有定义过滤器
  987. if (props.filter || props.filterfield) {
  988. let filterObj = props.filter;
  989. if (!props.filter) filterObj = {};
  990. if (props.filter) {
  991. const filterObj = props.filter; // 转为json对象
  992. for (let k in filterObj) {
  993. let v = filterObj[k];
  994. url += "&" + k + "=" + v;
  995. }
  996. }
  997. if (props.filterfield) {
  998. //加上filterfield的值过滤
  999. let filterfieldArr = props.filterfield.split(",");
  1000. for (var i = 0; i < filterfieldArr.length; i++) {
  1001. let fieldName = filterfieldArr[i];
  1002. let fields = document.getElementsByName(fieldName);
  1003. if (!fields || fields.length < 1) {
  1004. alert("下拉菜单配置的过滤条件" + fieldName + "不存在!");
  1005. continue;
  1006. }
  1007. let v = null;
  1008. for (let j = 0; j < fields.length; j++) {
  1009. if (fields[j].value) {
  1010. v = fields[j].value;
  1011. break;
  1012. }
  1013. }
  1014. // let field = document.getElementsByName(fieldName)[0];
  1015. // let v = field.value;
  1016. if (v) {
  1017. url += "&" + fieldName + "=" + v;
  1018. filterObj[fieldName] = v;
  1019. }
  1020. }
  1021. console.log("filterfield url:" + url);
  1022. }
  1023. //包含HTML实体的JSON字符串转为JSON对象,如原字符串是{&quot;dwid&quot;:&quot;88&quot;},注意key也必需用单引号包着
  1024. // const decodedString = props.filter.replace(/&quot;/g, '"'); // 转换为: {"dwid":"88"}
  1025. // objectPickerParam = JSON.parse(decodedString); // 转为json对象
  1026. objectPickerParam = filterObj;
  1027. objectPickerParam["input"] = props.inp;
  1028. objectPickerParam["codebook"] = props.cb;
  1029. // alert(url);
  1030. } else {
  1031. objectPickerParam = { input: props.inp, codebook: props.cb };
  1032. }
  1033. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  1034. const params = new URLSearchParams();
  1035. params.append("objectpickerparam", objectPickerParamStr);
  1036. params.append("objectpickertype", "1");
  1037. if (props.inp && props.inp === true) {
  1038. //把"true"改为true Ben(20251209)
  1039. params.append("objectpickersearchAll", 0); //只查录入的值
  1040. params.append("objectpickerinput", inpTxt); //录入的值
  1041. // 功能说明:将输入值也加到 URL 参数,避免后端只读 URL 不读 body by xu 20250408
  1042. if (inpTxt) {
  1043. url += "&objectpickerinput=" + encodeURIComponent(inpTxt);
  1044. }
  1045. } else {
  1046. params.append("objectpickersearchAll", 1);
  1047. }
  1048. axios
  1049. .post(url, params, {
  1050. headers: {
  1051. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1052. },
  1053. })
  1054. .then((response) => {
  1055. if ("timeout" == response.data.statusText) {
  1056. alert("网络超时!");
  1057. return;
  1058. }
  1059. // 先清空选项 by xu 20251212
  1060. if (props.opt) {
  1061. props.opt.length = 0;
  1062. } else {
  1063. props.opt = [];
  1064. }
  1065. if (response.data.result) {
  1066. const keys = Object.keys(response.data.result);
  1067. // console.log("params:"+params+"@@response.data:"+JSON.stringify(response.data));
  1068. if (keys.length > 0) {
  1069. for (let k in response.data.result) {
  1070. props.opt.push({
  1071. label: response.data.result[k],
  1072. value: k,
  1073. });
  1074. }
  1075. // console.log('###inpTxt:'+inpTxt+';');
  1076. if (
  1077. props.inp &&
  1078. props.inp === true && //把"true"改为true Ben(20251209)
  1079. inpTxt.length > 0
  1080. ) {
  1081. //对于可录入的,用已录入的值作过滤
  1082. filteredOptions.value = props.opt.filter((option) =>
  1083. option.label
  1084. .toLowerCase()
  1085. .includes(inputText.value.toLowerCase())
  1086. );
  1087. // 可录入的objPicker,当搜索结果只有一项时,自动选中这一项 by xu 20251212
  1088. if (filteredOptions.value.length === 1) {
  1089. const autoSelectItem = filteredOptions.value[0];
  1090. console.log(
  1091. "[objp] 搜索结果只有一项,自动选中:",
  1092. autoSelectItem
  1093. );
  1094. doSelectItem(autoSelectItem);
  1095. return; // 自动选中后直接返回,不需要显示popup
  1096. }
  1097. filteredOptions.value.unshift({ label: "", value: "" });
  1098. // console.log('###做了过滤:'+inputText.value.toLowerCase()+';');
  1099. } else {
  1100. filteredOptions.value = props.opt;
  1101. filteredOptions.value.unshift({ label: "", value: "" });
  1102. }
  1103. console.log("props.opt11:" + JSON.stringify(props.opt));
  1104. } else {
  1105. // 没有数据时,清空过滤选项 by xu 20251212
  1106. filteredOptions.value = [];
  1107. console.log("[objp] 接口返回空数据");
  1108. }
  1109. } else {
  1110. // result不存在时,清空过滤选项 by xu 20251212
  1111. filteredOptions.value = [];
  1112. console.log("[objp] 接口返回无result");
  1113. }
  1114. // 无论是否有数据,都显示popup by xu 20251212
  1115. openPopup(); // Teleport 场景下统一打开并重定位 by xu 20260126
  1116. });
  1117. }
  1118. } catch (error) {
  1119. // callback(null, error.message); // 失败回调,传递错误
  1120. }
  1121. }
  1122. // 计算弹出方向和最大高度的方法 by xu 20251212
  1123. // 当空间不足时限制popup高度并显示滚动条
  1124. const calculatePopupDirection = () => {
  1125. const triggerEl =
  1126. selectContainerRef.value?.querySelector(".input") ||
  1127. selectContainerRef.value;
  1128. if (!triggerEl) return;
  1129. const selectRect = triggerEl.getBoundingClientRect();
  1130. const viewportHeight = window.innerHeight;
  1131. // 3. 计算上下可用空间
  1132. const spaceBelow = viewportHeight - selectRect.bottom - 10; // 减10px留边距
  1133. const spaceAbove = selectRect.top - 10; // 减10px留边距
  1134. // 4. popup预估高度(假设每项36px,最多显示8项 + padding)
  1135. const estimatedPopupHeight = 300;
  1136. const minPopupHeight = 100; // 最小高度
  1137. console.log(
  1138. "[popup] 空间计算 - spaceAbove:",
  1139. spaceAbove,
  1140. "spaceBelow:",
  1141. spaceBelow,
  1142. "estimatedHeight:",
  1143. estimatedPopupHeight
  1144. );
  1145. // 5. 判断方向和最大高度 by xu 20251212
  1146. if (spaceBelow >= estimatedPopupHeight) {
  1147. // 下方空间足够,向下展开,不限制高度
  1148. popupDirection.value = "bottom";
  1149. popupMaxHeight.value = "none";
  1150. console.log("[popup] 向下展开,空间充足");
  1151. } else if (spaceAbove >= estimatedPopupHeight) {
  1152. // 上方空间足够,向上展开,不限制高度
  1153. popupDirection.value = "top";
  1154. popupMaxHeight.value = "none";
  1155. console.log("[popup] 向上展开,空间充足");
  1156. } else {
  1157. // 上下空间都不足,选择空间大的方向,并限制高度出滚动条
  1158. if (spaceBelow >= spaceAbove) {
  1159. popupDirection.value = "bottom";
  1160. popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px";
  1161. console.log(
  1162. "[popup] 向下展开,空间不足,限制高度:",
  1163. popupMaxHeight.value
  1164. );
  1165. } else {
  1166. popupDirection.value = "top";
  1167. popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px";
  1168. console.log(
  1169. "[popup] 向上展开,空间不足,限制高度:",
  1170. popupMaxHeight.value
  1171. );
  1172. }
  1173. }
  1174. };
  1175. // Teleport popup 的定位(fixed) by xu 20260126
  1176. const updatePopupPosition = () => {
  1177. const triggerEl =
  1178. selectContainerRef.value?.querySelector(".input") ||
  1179. selectContainerRef.value;
  1180. if (!triggerEl) return;
  1181. const triggerRect = triggerEl.getBoundingClientRect();
  1182. const margin = 10;
  1183. const viewportWidth = window.innerWidth;
  1184. const viewportHeight = window.innerHeight;
  1185. const popupGap = 0; // 功能说明:定位不再做 -10 重叠,让 padding-top 自然形成间距 by xu 20260126
  1186. // 先给一个初始位置,确保下一帧可以测量弹层尺寸 by xu 20260126
  1187. popupLayerStyle.value = {
  1188. position: "fixed",
  1189. left: `${Math.max(margin, triggerRect.left)}px`,
  1190. top: `${Math.max(margin, triggerRect.bottom + popupGap)}px`, // 功能说明:与输入框底部对齐 by xu 20260126
  1191. bottom: "auto", // 功能说明:fixed 场景显式取消 bottom,避免与 top 同时生效 by xu 20260126
  1192. minWidth: `${Math.max(0, triggerRect.width)}px`,
  1193. zIndex: 9999,
  1194. pointerEvents: "auto",
  1195. };
  1196. Vue.nextTick(() => {
  1197. const popupEl = popupRef.value;
  1198. if (!popupEl) return;
  1199. const popupRect = popupEl.getBoundingClientRect();
  1200. const maxLeft = viewportWidth - popupRect.width - margin;
  1201. const left = Math.min(
  1202. Math.max(margin, triggerRect.left),
  1203. Math.max(margin, maxLeft)
  1204. );
  1205. let top;
  1206. if (popupDirection.value === "top") {
  1207. top = triggerRect.top - popupRect.height - popupGap; // 功能说明:向上展开时与输入框顶部对齐 by xu 20260126
  1208. top = Math.max(margin, top);
  1209. } else {
  1210. top = triggerRect.bottom + popupGap; // 功能说明:向下展开时与输入框底部对齐 by xu 20260126
  1211. if (top + popupRect.height > viewportHeight - margin) {
  1212. top = Math.max(
  1213. margin,
  1214. viewportHeight - popupRect.height - margin
  1215. );
  1216. }
  1217. }
  1218. popupLayerStyle.value = {
  1219. ...popupLayerStyle.value,
  1220. left: `${left}px`,
  1221. top: `${top}px`,
  1222. bottom: "auto", // 功能说明:无论 top/bottom 展开都用 top 定位,禁用 bottom by xu 20260126
  1223. };
  1224. });
  1225. };
  1226. const openPopup = () => {
  1227. if (!popupWinVisible.value) popupWinVisible.value = true;
  1228. Vue.nextTick(() => {
  1229. calculatePopupDirection();
  1230. updatePopupPosition();
  1231. });
  1232. };
  1233. // Teleport 场景下:滚动/缩放重定位 by xu 20260126
  1234. const handleViewportChange = () => {
  1235. if (!popupWinVisible.value) return;
  1236. calculatePopupDirection();
  1237. updatePopupPosition();
  1238. };
  1239. // Teleport 场景下:点击外部关闭 by xu 20260126
  1240. const onDocPointerDown = (event) => {
  1241. if (!popupWinVisible.value) return;
  1242. const target = event.target;
  1243. if (selectContainerRef.value?.contains(target)) return;
  1244. if (popupRef.value?.contains(target)) return;
  1245. hidePopup();
  1246. };
  1247. //点击下拉菜单的文本区域时,会触发的方法
  1248. function togglePopup() {
  1249. // 可录入的 objPicker,更新下拉菜单选项
  1250. updateOptionBYInputText(inputText.value);
  1251. // popupWinVisible.value = !popupWinVisible.value;
  1252. Vue.nextTick(() => {
  1253. calculatePopupDirection();
  1254. updatePopupPosition(); // Teleport 场景下同步定位 by xu 20260126
  1255. });
  1256. }
  1257. const hidePopup = () => {
  1258. popupWinVisible.value = false;
  1259. };
  1260. //点击下拉菜单的三角形时,会触发的方法
  1261. // 添加toggle逻辑,点击时切换显示/隐藏 by xu 20251212
  1262. const suffixClick = () => {
  1263. // 如果popup已显示,则关闭 by xu 20251212
  1264. if (popupWinVisible.value) {
  1265. hidePopup();
  1266. console.log("[objp] 点三角关闭popup");
  1267. return;
  1268. }
  1269. //可录入的objPicker,更新下拉菜单选项
  1270. updateOptionBYInputText("");
  1271. Vue.nextTick(() => {
  1272. calculatePopupDirection();
  1273. updatePopupPosition(); // Teleport 场景下同步定位 by xu 20260126
  1274. });
  1275. console.log("[objp] 点三角打开popup");
  1276. };
  1277. //可录入的objPicker,录入项变化时,会触发
  1278. async function handleInputChange(event) {
  1279. inputText.value = event.target.value;
  1280. if (!inputText.value) {
  1281. inputText.value = "";
  1282. }
  1283. //可录入的objPicker,更新下拉菜单选项
  1284. updateOptionBYInputText(inputText.value);
  1285. // filteredOptions.value = props.opt.filter((option) =>
  1286. // option.label.toLowerCase().includes(inputText.value.toLowerCase())
  1287. // );
  1288. // if (!popupWinVisible.value) {
  1289. // popupWinVisible.value = true; // 确保下拉框在输入时打开
  1290. // }
  1291. }
  1292. Vue.onMounted(() => {
  1293. initDefaultValue();
  1294. // Teleport 场景下:滚动/缩放需要重定位(scroll 用 capture 捕获容器滚动) by xu 20260126
  1295. window.addEventListener("resize", handleViewportChange);
  1296. window.addEventListener("scroll", handleViewportChange, true);
  1297. // 点击外部关闭(原本依赖 mouseleave,Teleport 后会误关) by xu 20260126
  1298. document.addEventListener("pointerdown", onDocPointerDown, true);
  1299. });
  1300. Vue.onUnmounted(() => {
  1301. window.removeEventListener("resize", handleViewportChange);
  1302. window.removeEventListener("scroll", handleViewportChange, true);
  1303. document.removeEventListener("pointerdown", onDocPointerDown, true);
  1304. });
  1305. return {
  1306. errMsg,
  1307. selectItem,
  1308. inputText,
  1309. canInput,
  1310. filteredOptions,
  1311. popupWinVisible,
  1312. popupDirection,
  1313. popupMaxHeight, // 添加popup最大高度 by xu 20251212
  1314. popupContentAreaMaxHeight,
  1315. selectContainerRef,
  1316. popupRef,
  1317. teleportRootStyle,
  1318. popupLayerStyle,
  1319. suffixClick,
  1320. togglePopup,
  1321. hidePopup,
  1322. doSelectItem,
  1323. handleInputChange,
  1324. };
  1325. },
  1326. template: `
  1327. <div class="input" style="position: relative" :style="{width: width}">
  1328. <div class="select-container" ref="selectContainerRef">
  1329. <div class="input" @click="togglePopup">
  1330. <input
  1331. type="hidden"
  1332. :name="name"
  1333. :value="selectItem.value"
  1334. .value="selectItem.value"
  1335. />
  1336. <input
  1337. v-model="inputText"
  1338. @input="handleInputChange"
  1339. v-if="canInput"
  1340. :placeholder="placeholder"
  1341. />
  1342. <input
  1343. v-else
  1344. :placeholder="placeholder"
  1345. :value="selectItem.label"
  1346. disabled
  1347. style="pointer-events: none;"
  1348. />
  1349. <div class="suffix" @click.stop="suffixClick">
  1350. <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
  1351. </div>
  1352. </div>
  1353. <!-- 修复表格内弹层被截断:popup Teleport 到 body by xu 20260126 -->
  1354. <teleport to="body">
  1355. <div v-show="popupWinVisible" class="select-container ss-objp-teleport-root" :style="teleportRootStyle">
  1356. <!-- popup弹出层,添加maxHeight和overflowY支持空间不足时滚动 by xu 20251212 -->
  1357. <div ref="popupRef" class="popup-win" :class="popupDirection" :style="[popupLayerStyle, { maxHeight: popupMaxHeight !== 'none' ? popupMaxHeight : 'none', overflowY: 'visible' }]">
  1358. <div v-if="opt && opt.length && filteredOptions.length > 0" class="popup-content">
  1359. <div class="content-area" :style="popupContentAreaMaxHeight ? { maxHeight: popupContentAreaMaxHeight, overflowY: 'auto' } : null">
  1360. <div v-for="(item, index) in filteredOptions" :key="index" @click="doSelectItem(item)" :class="{ active: item.value === selectItem.value }">
  1361. <span class="check-icon">
  1362. <ss-form-icon class="form-icon-select-checked" />
  1363. </span>
  1364. <span>{{ item.label }}</span>
  1365. </div>
  1366. </div>
  1367. </div>
  1368. <div v-else class="popup-content"><div class="content-area"><div class="content-area"> <span>无选项</span></div></div></div>
  1369. </div>
  1370. </div>
  1371. </teleport>
  1372. </div>
  1373. </div>
  1374. `,
  1375. };
  1376. // ss-hidden 隐藏字段组件
  1377. const SsHidden = {
  1378. name: "SsHidden",
  1379. props: {
  1380. modelValue: String,
  1381. name: {
  1382. type: String,
  1383. required: true,
  1384. },
  1385. rule: {
  1386. type: String,
  1387. required: true,
  1388. },
  1389. param: {
  1390. type: String,
  1391. required: true,
  1392. },
  1393. url: {
  1394. type: String,
  1395. required: true,
  1396. },
  1397. },
  1398. emits: ["update:modelValue"],
  1399. setup(props, { emit }) {
  1400. const errMsg = Vue.ref("");
  1401. const validate = () => {
  1402. if (window.ssVm) {
  1403. const result = window.ssVm.validateField(props.name);
  1404. console.log("validate", window.ssVm.validateField(props.name));
  1405. errMsg.value = result.valid ? "" : result.message;
  1406. }
  1407. };
  1408. Vue.onMounted(() => {
  1409. /**
  1410. * 初始化级联菜单值初始值思路:
  1411. * 1. 带隐藏字段(即带编码规则)的级联菜单
  1412. * 在隐藏字段这,可以取到要回显的值和编码规则,从而计算出各级下拉菜单要回显的值。
  1413. * 然后通过ajax取各级级联菜单的值回显。
  1414. * 2. 不带隐藏字段的级联,只能在各个下拉菜单的setup事件中通过ajax取回显值回显
  1415. */
  1416. // 当同组级联下拉菜单选中值变化时,会调用本隐藏字段下面这方法设置隐藏字段值
  1417. window.addEventListener(
  1418. "cascader-setHiddenVal-" + props.name,
  1419. (event) => {
  1420. const { value } = event.detail;
  1421. emit("update:modelValue", value);
  1422. console.log(value);
  1423. setTimeout(() => {
  1424. validate();
  1425. }, 50);
  1426. }
  1427. );
  1428. // 如果有初始值,触发回显过程
  1429. if (props.modelValue) {
  1430. console.log("级联隐藏字段,开始回显,初始值:", props.modelValue);
  1431. triggerCascaderEcho(props.modelValue);
  1432. validate();
  1433. }
  1434. });
  1435. // 触发级联回显
  1436. const triggerCascaderEcho = (code) => {
  1437. /**
  1438. * 开始回显,初始值: 440304
  1439. * 解析后的所有值: Array(3)0: "440000"1: "440300"2: "440304"length: 3[[Prototype]]: Array(0)
  1440. */
  1441. const values = parseHiddenCodeForAll(code, props.rule);
  1442. console.log("解析后的所有值:", values);
  1443. // 转换为 JSON 对象
  1444. // const paramObj = JSON.parse(props.param);
  1445. const paramObj = props.param;
  1446. let selectArr = paramObj.fieldOrd; //保存本组级联菜单项的数组,如:['hksheng','hkshi','hkxian']
  1447. if (selectArr.length != values.length) {
  1448. // alert('属性'+props.name+'的值'+code+'与级联菜单中下拉菜单的数目不匹配!');
  1449. return;
  1450. }
  1451. // 按顺序触发回显,并增加延迟确保数据加载
  1452. /**
  1453. * 通过隐藏字段的setup事件,
  1454. * 循环遍历各级下拉菜单,并触发定义在下拉菜单中的'cascader-echo'事件,
  1455. * 在此事件中完成每个下拉菜单回显值操作(只取当前要回显的键值对显示,
  1456. * 下拉菜单所有的值,在点击下拉菜单时,才通过ajax取)。
  1457. */
  1458. values.forEach((value, index) => {
  1459. if (value) {
  1460. setTimeout(() => {
  1461. let upperVal = undefined;
  1462. if (index != 0) {
  1463. upperVal = values[index - 1];
  1464. }
  1465. const echoEvent = new CustomEvent(
  1466. "cascader-echo-" + selectArr[index],
  1467. {
  1468. detail: {
  1469. name: props.name,
  1470. value: value,
  1471. // level: index + 1,
  1472. isAuto: true, // 标记为自动回显
  1473. upperVal: upperVal,
  1474. },
  1475. }
  1476. );
  1477. console.log(props.name + "--upperValue:" + upperVal);
  1478. window.dispatchEvent(echoEvent);
  1479. }, index * 500); // 每级增加500ms延迟
  1480. }
  1481. });
  1482. };
  1483. // 解析所有级别的代码
  1484. const parseHiddenCodeForAll = (code, rule) => {
  1485. if (!code || !rule) return [];
  1486. // 获取规则中每段的长度
  1487. const segments = [];
  1488. let currentChar = rule[0];
  1489. let currentLength = 1;
  1490. for (let i = 1; i < rule.length; i++) {
  1491. if (rule[i] === currentChar) {
  1492. currentLength++;
  1493. } else {
  1494. segments.push(currentLength);
  1495. currentChar = rule[i];
  1496. currentLength = 1;
  1497. }
  1498. }
  1499. segments.push(currentLength);
  1500. // 解析每一级的值
  1501. const values = [];
  1502. let position = 0;
  1503. segments.forEach((length, index) => {
  1504. const value = code
  1505. .substring(0, position + length)
  1506. .padEnd(rule.length, "0");
  1507. values.push(value);
  1508. position += length;
  1509. });
  1510. return values;
  1511. };
  1512. watchEffect(() => {});
  1513. return {};
  1514. },
  1515. template: `<input type="hidden" :name="name" :value="modelValue">`,
  1516. };
  1517. // ss-cascader 级联选择器
  1518. const SsCcp = {
  1519. name: "SsCcp",
  1520. inheritAttrs: false,
  1521. props: {
  1522. modelValue: String,
  1523. name: {
  1524. type: String,
  1525. required: true,
  1526. },
  1527. level: {
  1528. type: Number,
  1529. required: true,
  1530. },
  1531. opt: {
  1532. type: Array,
  1533. default: () => [],
  1534. },
  1535. placeholder: {
  1536. type: String,
  1537. default: "请选择",
  1538. },
  1539. width: {
  1540. type: String,
  1541. default: "150px",
  1542. },
  1543. direction: {
  1544. type: String,
  1545. default: "bottom",
  1546. },
  1547. mode: {
  1548. type: String,
  1549. default: "1",
  1550. },
  1551. //级联菜单配置参数,如果是数组,则代表本下拉菜单是多套级联菜单共用的第一级菜单。如果是对象,则只有一套级联菜单用此下拉菜单。
  1552. param: {
  1553. type: String,
  1554. required: true,
  1555. },
  1556. //向后台拿数据的url
  1557. url: {
  1558. type: String,
  1559. required: true,
  1560. },
  1561. },
  1562. emits: ["update:modelValue", "change"],
  1563. setup(props, { emit }) {
  1564. // alert('级联菜单初始化:'+props.name+':--:'+props.modelValue);
  1565. const selectItem = Vue.ref({ label: props.placeholder, value: "" });
  1566. const popupWinVisible = Vue.ref(false);
  1567. const isAutoEcho = Vue.ref(false); // 用于标记是否是自动回显
  1568. const upperValue = Vue.ref(""); //上级下拉菜单当前值,在初始化下拉菜单默认值时,和上级下拉菜单的值变化时,修改此upperValue变量
  1569. const popupDirection = Vue.ref("bottom");
  1570. const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
  1571. //有隐藏字段的下拉菜单,加载菜单项并展开事件
  1572. // 被上级下拉菜单选中值后,触发本下拉菜单刷新菜单项并弹出显示
  1573. window.addEventListener("cascader-open-" + props.name, async (event) => {
  1574. const { upperVal } = event.detail;
  1575. upperValue.value = upperVal;
  1576. console.log(
  1577. "22props.name:" +
  1578. props.name +
  1579. ",22props.upperValue:" +
  1580. upperValue.value
  1581. );
  1582. selectItem.value = ""; //清除本下拉菜单当前选中的值
  1583. emit("update:modelValue", ""); //通知父级
  1584. //清空下拉菜单,并设置第一项的值为placeholder
  1585. clearAndInit1stOpt();
  1586. //下个下拉菜单名
  1587. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1588. if (nextSelName) {
  1589. //清下个下拉菜单选中值和选项
  1590. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  1591. detail: {},
  1592. });
  1593. window.dispatchEvent(event);
  1594. }
  1595. showPopup();
  1596. });
  1597. //设置mode2的下级下拉菜单的上级菜单当前值
  1598. function setNextSelectUpperValue() {
  1599. //设置下级菜单的上级菜单当前值upperValue
  1600. let paramArr = undefined;
  1601. if (Array.isArray(props.param)) {
  1602. paramArr = props.param;
  1603. } else {
  1604. paramArr = [];
  1605. paramArr.push(props.param);
  1606. }
  1607. for (const oneParam of paramArr) {
  1608. //下个下拉菜单名
  1609. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  1610. if (nextSelName) {
  1611. setTimeout(() => {
  1612. const openNextEvent = new CustomEvent(
  1613. "cascade-setUpperVal-" + nextSelName,
  1614. {
  1615. detail: {
  1616. upperVal: props.modelValue,
  1617. },
  1618. }
  1619. );
  1620. window.dispatchEvent(openNextEvent);
  1621. }, 100);
  1622. }
  1623. } // end for
  1624. }
  1625. // 把上级 级联下拉菜单的值,设置进本组件的事件
  1626. window.addEventListener("cascade-setUpperVal-" + props.name, (event) => {
  1627. // alert('props.name:'+props.name+',props.upperValue:'+event.detail.upperVal);
  1628. const { upperVal } = event.detail;
  1629. upperValue.value = upperVal;
  1630. // console.log('props.name:'+props.name+',props.upperValue:'+upperValue.value);
  1631. });
  1632. //清空下拉菜单,并设置第一项的值为空
  1633. function clearAndInit1stOpt() {
  1634. if (props.opt)
  1635. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  1636. else {
  1637. props.opt = [];
  1638. }
  1639. props.opt.push({ label: "", value: "" });
  1640. }
  1641. //获取下一级下拉菜单,如果下一级下拉菜单不存在,则返回undefined
  1642. function getNextSel(selName, selNameArr) {
  1643. // 检查参数有效性
  1644. if (!Array.isArray(selNameArr) || selNameArr.length === 0) {
  1645. return undefined;
  1646. }
  1647. // 查找当前元素的索引
  1648. const currentIndex = selNameArr.indexOf(selName);
  1649. // 如果元素不存在或已经是最后一个元素,返回undefined
  1650. if (currentIndex === -1 || currentIndex === selNameArr.length - 1) {
  1651. return undefined;
  1652. }
  1653. // 返回下一个元素
  1654. return selNameArr[currentIndex + 1];
  1655. }
  1656. const validate = () => {
  1657. if (window.ssVm) {
  1658. return window.ssVm.validateField(props.name);
  1659. }
  1660. return { valid: true };
  1661. };
  1662. // 处理选择事件
  1663. const doSelectItem = (item) => {
  1664. selectItem.value = item;
  1665. emit("update:modelValue", item.value); //修改本下拉菜单在vue中保存的值
  1666. // alert('item.value:'+item.value);
  1667. if (props.mode === "1") {
  1668. // mode 1 模式:修改隐藏字段值
  1669. let event = new CustomEvent(
  1670. "cascader-setHiddenVal-" + props.param.combField,
  1671. {
  1672. detail: {
  1673. value: item.value,
  1674. },
  1675. }
  1676. );
  1677. window.dispatchEvent(event);
  1678. }
  1679. emit("change", item.value); //触发配置的change方法
  1680. nextTick(() => {
  1681. validate();
  1682. if (window.ssVm) {
  1683. for (const [field, rules] of window.ssVm.validations.entries()) {
  1684. for (const rule of rules) {
  1685. if (rule.options?.relField) {
  1686. const relFields = String(rule.options.relField)
  1687. .split(",")
  1688. .map((name) => name.trim())
  1689. .filter(Boolean);
  1690. if (relFields.includes(props.name)) {
  1691. window.ssVm.validateField(field);
  1692. }
  1693. }
  1694. }
  1695. }
  1696. }
  1697. });
  1698. //设置下级菜单的上级菜单当前值upperValue
  1699. let paramArr = undefined;
  1700. if (Array.isArray(props.param)) {
  1701. paramArr = props.param;
  1702. } else {
  1703. paramArr = [];
  1704. paramArr.push(props.param);
  1705. }
  1706. for (const oneParam of paramArr) {
  1707. //下个下拉菜单名
  1708. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  1709. if (nextSelName) {
  1710. setTimeout(() => {
  1711. const openNextEvent = new CustomEvent(
  1712. "cascader-open-" + nextSelName,
  1713. {
  1714. detail: {
  1715. upperVal: item.value,
  1716. },
  1717. }
  1718. );
  1719. window.dispatchEvent(openNextEvent);
  1720. }, 100);
  1721. }
  1722. } // end for
  1723. hidePopup();
  1724. //下个下拉菜单名
  1725. // let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1726. // if(nextSelName){
  1727. // // //设置下一级下拉菜单中保存的本下拉菜单值(upperValue)
  1728. // // event = new CustomEvent('cascade-setUpperVal-'+nextSelName, {
  1729. // // detail: {
  1730. // // value: item.value
  1731. // // }
  1732. // // });
  1733. // // window.dispatchEvent(event);
  1734. //
  1735. // //触发下一级下拉菜单,重新初始化下拉菜单项并弹出显示
  1736. // event = new CustomEvent('cascader-open-' +nextSelName, {
  1737. // detail: {
  1738. // upperVal: item.value
  1739. // }
  1740. // });
  1741. // window.dispatchEvent(event);
  1742. // }
  1743. // 只在手动选择时自动展开下一级
  1744. // if (!isAutoEcho.value) {
  1745. // const nextLevel = props.level + 1;
  1746. // setTimeout(() => {
  1747. // const openNextEvent = new CustomEvent('open-next-cascader', {
  1748. // detail: {
  1749. // name: props.name,
  1750. // level: nextLevel
  1751. // }
  1752. // });
  1753. // window.dispatchEvent(openNextEvent);
  1754. // }, 100);
  1755. // }
  1756. };
  1757. // 监听下一级展开事件 (仅 mode 2)
  1758. window.addEventListener("cascade-open", (event) => {
  1759. if (props.mode === "2") {
  1760. const { level } = event.detail;
  1761. if (level === props.level) {
  1762. popupWinVisible.value = true;
  1763. }
  1764. }
  1765. });
  1766. if (props.mode === "1") {
  1767. //如果是有隐藏字段的下拉菜单
  1768. // 监听回显事件
  1769. window.addEventListener(
  1770. "cascader-echo-" + props.name,
  1771. async (event) => {
  1772. const { name, value, isAuto, upperVal } = event.detail;
  1773. // level,
  1774. if (upperVal) {
  1775. upperValue.value = upperVal;
  1776. console.log(
  1777. "value:" +
  1778. value +
  1779. ",upperValue:" +
  1780. upperValue +
  1781. ",初始化级联组件时props.name:" +
  1782. props.name
  1783. );
  1784. }
  1785. // if (name === props.name && level === props.level) {
  1786. // 设置自动回显标记
  1787. isAutoEcho.value = true;
  1788. // if (props.opt.length === 0) {
  1789. // const loadDataEvent = new CustomEvent('cascader-load-data', {
  1790. // detail: {
  1791. // name: props.name,
  1792. // level: props.level,
  1793. // value: value
  1794. // }
  1795. // });
  1796. // window.dispatchEvent(loadDataEvent);
  1797. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  1798. //Vue.watch用于监听数据的变化,并在数据变化时执行特定的回调函数。
  1799. //这段代码使用了 Vue.js 的 watch API 来监听 props.opt 的变化,如果props.opt有变化,则自动
  1800. // const unwatch = Vue.watch(
  1801. // () => props.opt, // 监听的数据源(props.opt)
  1802. // (newOptions) => { // 回调函数
  1803. // if (newOptions.length > 0) { // 条件判断
  1804. // matchAndSelect(value); // 执行逻辑
  1805. // unwatch(); // 停止监听
  1806. // }
  1807. // },
  1808. // { immediate: true } // 配置:立即触发一次
  1809. // );
  1810. // } else {
  1811. // matchAndSelect(value);
  1812. // }
  1813. // 初始化级联菜单在页面刚打开时的默认值
  1814. async function initDefaultValue(value) {
  1815. try {
  1816. // alert(1);
  1817. if (
  1818. props.url &&
  1819. props.param
  1820. // && props.modelValue 对于有rule编码规则的级联菜单(即mode=1),modelValue一定是空的,所以注释掉,修复mode=1的级联菜单无法回显问题。Ben(20251124)
  1821. ) {
  1822. // alert(2);
  1823. /**
  1824. * let objectPickerParam=
  1825. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  1826. * "\"name\":\"hksheng\"," +
  1827. * "\"cascadingName\":\"dq\",\"cascadingInputsName\":\"hkdqm\"," +
  1828. * "\"codebook\":\"sheng\"}",
  1829. * "objectpickertype":2,
  1830. * "objectpickervalue":"440000"
  1831. * };
  1832. */
  1833. const objectPickerParam = {
  1834. input: "false",
  1835. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  1836. name: props.name, //本下拉菜单名
  1837. cascadingName: props.param.name, //级联菜单名
  1838. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  1839. codebook: props.param.codebook,
  1840. };
  1841. const objectPickerParamStr =
  1842. JSON.stringify(objectPickerParam);
  1843. const params = new URLSearchParams();
  1844. params.append("objectpickerparam", objectPickerParamStr);
  1845. params.append("objectpickertype", "2");
  1846. params.append("objectpickervalue", value); //需回显的值
  1847. axios
  1848. .post(props.url, params, {
  1849. headers: {
  1850. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1851. },
  1852. })
  1853. .then((response) => {
  1854. // alert(JSON.stringify(response.data));
  1855. if ("timeout" == response.data.statusText) {
  1856. alert("网络超时!");
  1857. return;
  1858. }
  1859. if (response.data.result) {
  1860. const keys = Object.keys(response.data.result);
  1861. if (keys.length === 1) {
  1862. let code = keys[0];
  1863. let desc = response.data.result[keys[0]];
  1864. clearAndInit1stOpt();
  1865. props.opt.push({ label: desc, value: code });
  1866. if (value) matchAndSelect(value);
  1867. // updateSelectItem();
  1868. // alert('props.opt:'+JSON.stringify(props.opt));
  1869. }
  1870. }
  1871. });
  1872. }
  1873. } catch (error) {
  1874. alert(error);
  1875. // callback(null, error.message); // 失败回调,传递错误
  1876. }
  1877. }
  1878. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  1879. initDefaultValue(value);
  1880. // 延迟重置自动回显标记
  1881. setTimeout(() => {
  1882. isAutoEcho.value = false;
  1883. }, 500);
  1884. }
  1885. );
  1886. // 被上级下拉菜单触发的,清除选中值和下拉菜单选项
  1887. window.addEventListener(
  1888. "cascader-cleanOpt-" + props.name,
  1889. async (event) => {
  1890. upperValue.value = "";
  1891. selectItem.value = ""; //清除本下拉菜单当前选中的值
  1892. emit("update:modelValue", ""); //通知父级
  1893. //清空所有下拉菜单项
  1894. if (props.opt) {
  1895. props.opt.length = 0;
  1896. } else {
  1897. props.opt = [];
  1898. }
  1899. //下个下拉菜单名
  1900. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1901. // alert('nextSelName:'+nextSelName+'--,props.name:'+props.name);
  1902. if (nextSelName) {
  1903. //清下个下拉菜单选中值和选项
  1904. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  1905. detail: {},
  1906. });
  1907. window.dispatchEvent(event);
  1908. }
  1909. }
  1910. );
  1911. } else if (props.mode === "2") {
  1912. //没隐藏字段的下拉菜单,在这初始化默认值
  1913. let needInitParam = undefined;
  1914. if (Array.isArray(props.param)) {
  1915. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  1916. console.log("needInitParam最后一项:" + JSON.stringify(needInitParam));
  1917. } else {
  1918. needInitParam = props.param;
  1919. }
  1920. // 初始化级联菜单在页面刚打开时的默认值
  1921. async function initDefaultValue(value, param) {
  1922. try {
  1923. // alert(1);
  1924. if (props.url && param && props.modelValue) {
  1925. // alert(2);
  1926. /**
  1927. * let param=
  1928. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"rylbm,gwid\"," +
  1929. * "\"name\":\"gwid\",\"cascadingName\":\"rylb_gw\"," +
  1930. * "\"codebook\":\"gwByRylb\"}",
  1931. * "objectpickertype":2,
  1932. * "objectpickervalue":"102121"};
  1933. */
  1934. // alert('props.name:'+props.name+',props.param.fieldOrd:'+props.param.fieldOrd);
  1935. const objectPickerParam = {
  1936. input: "false",
  1937. cascadingLevel: param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  1938. name: props.name, //本下拉菜单名
  1939. cascadingName: param.name, //级联菜单名
  1940. codebook: param.codebook,
  1941. };
  1942. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  1943. const sendParams = new URLSearchParams();
  1944. sendParams.append("objectpickerparam", objectPickerParamStr);
  1945. sendParams.append("objectpickertype", "2");
  1946. sendParams.append("objectpickervalue", value); //需回显的值
  1947. axios
  1948. .post(props.url, sendParams, {
  1949. headers: {
  1950. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1951. },
  1952. })
  1953. .then((response) => {
  1954. // alert(JSON.stringify(response.data));
  1955. if ("timeout" == response.data.statusText) {
  1956. alert("网络超时!");
  1957. return;
  1958. }
  1959. if (response.data.result) {
  1960. const keys = Object.keys(response.data.result);
  1961. console.log(
  1962. "name:" +
  1963. props.name +
  1964. ",@@级联初始化默认值value:" +
  1965. value +
  1966. "--param:" +
  1967. JSON.stringify(param) +
  1968. "--objectPickerParamStr:" +
  1969. objectPickerParamStr +
  1970. "--response.data:" +
  1971. JSON.stringify(response.data)
  1972. );
  1973. if (keys.length === 1) {
  1974. let code = keys[0];
  1975. let desc = response.data.result[keys[0]];
  1976. if (props.opt)
  1977. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  1978. else {
  1979. props.opt = [];
  1980. }
  1981. props.opt.push({ label: desc, value: code });
  1982. if (value) matchAndSelect(value);
  1983. console.log(
  1984. "GOOD mode2回显的默认值:" +
  1985. JSON.stringify({ label: desc, value: code }) +
  1986. "--props.param:" +
  1987. JSON.stringify(param)
  1988. );
  1989. // updateSelectItem();
  1990. // alert('props.opt:'+JSON.stringify(props.opt));
  1991. }
  1992. }
  1993. });
  1994. }
  1995. } catch (error) {
  1996. alert(error);
  1997. // callback(null, error.message); // 失败回调,传递错误
  1998. }
  1999. // 重置自动回显标记
  2000. isAutoEcho.value = false;
  2001. }
  2002. // 初始化级联菜单在页面刚打开时的默认值
  2003. initDefaultValue(props.modelValue, needInitParam);
  2004. //设置mode2的下级下拉菜单的上级菜单当前值
  2005. setNextSelectUpperValue();
  2006. }
  2007. //选中要回显的默认值
  2008. const matchAndSelect = (value) => {
  2009. const matchedOption = props.opt.find((opt) => opt.value === value);
  2010. if (matchedOption) {
  2011. selectItem.value = matchedOption;
  2012. emit("update:modelValue", value);
  2013. emit("change", value);
  2014. }
  2015. };
  2016. // 计算弹出方向和最大高度的方法 by xu 20251212
  2017. // 当空间不足时限制popup高度并显示滚动条
  2018. const calculatePopupDirection = () => {
  2019. // 1. 获取select容器元素
  2020. const selectEl = document.querySelector(
  2021. `[name="${props.name}"]`
  2022. )?.nextElementSibling;
  2023. console.log("selectEl:" + selectEl, props.name);
  2024. if (!selectEl) return;
  2025. // 2. 获取位置信息
  2026. const selectRect = selectEl.getBoundingClientRect();
  2027. const viewportHeight = window.innerHeight;
  2028. // 3. 计算上下可用空间 by xu 20251212
  2029. const spaceBelow = viewportHeight - selectRect.bottom - 10; // 减10px留边距
  2030. const spaceAbove = selectRect.top - 10; // 减10px留边距
  2031. // 4. popup预估高度(假设每项36px,最多显示8项 + padding)
  2032. const estimatedPopupHeight = 300;
  2033. const minPopupHeight = 100; // 最小高度
  2034. console.log(
  2035. "[popup] 空间计算 - spaceAbove:",
  2036. spaceAbove,
  2037. "spaceBelow:",
  2038. spaceBelow,
  2039. "estimatedHeight:",
  2040. estimatedPopupHeight
  2041. );
  2042. // 5. 判断方向和最大高度 by xu 20251212
  2043. if (spaceBelow >= estimatedPopupHeight) {
  2044. // 下方空间足够,向下展开,不限制高度
  2045. popupDirection.value = "bottom";
  2046. popupMaxHeight.value = "none";
  2047. console.log("[popup] 向下展开,空间充足");
  2048. } else if (spaceAbove >= estimatedPopupHeight) {
  2049. // 上方空间足够,向上展开,不限制高度
  2050. popupDirection.value = "top";
  2051. popupMaxHeight.value = "none";
  2052. console.log("[popup] 向上展开,空间充足");
  2053. } else {
  2054. // 上下空间都不足,选择空间大的方向,并限制高度出滚动条
  2055. if (spaceBelow >= spaceAbove) {
  2056. popupDirection.value = "bottom";
  2057. popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px";
  2058. console.log(
  2059. "[popup] 向下展开,空间不足,限制高度:",
  2060. popupMaxHeight.value
  2061. );
  2062. } else {
  2063. popupDirection.value = "top";
  2064. popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px";
  2065. console.log(
  2066. "[popup] 向上展开,空间不足,限制高度:",
  2067. popupMaxHeight.value
  2068. );
  2069. }
  2070. }
  2071. };
  2072. //级联菜单点击事件
  2073. const togglePopup = () => {
  2074. if (!popupWinVisible.value) {
  2075. //如果当前下拉菜单是隐藏的,先ajax重新加载下拉菜单项,再显示。
  2076. showPopup();
  2077. } else {
  2078. hidePopup();
  2079. }
  2080. };
  2081. //显示下拉菜单,在此之前先清除下拉菜单项
  2082. const showPopup = () => {
  2083. //清空下拉菜单,并设置第一项的值为空
  2084. clearAndInit1stOpt();
  2085. Vue.nextTick(() => {
  2086. calculatePopupDirection();
  2087. });
  2088. let url = props.url;
  2089. let filterObj = props.param.filter;
  2090. if (filterObj) {
  2091. for (let k in filterObj) {
  2092. let v = filterObj[k];
  2093. url += "&" + k + "=" + v;
  2094. }
  2095. }
  2096. if (props.mode === "1") {
  2097. //如果是有隐藏字段的下拉菜单
  2098. console.log("666url:" + url);
  2099. // alert('url:'+url);
  2100. // 获取级联菜单所有下拉菜单项
  2101. async function getSelectItems(value) {
  2102. try {
  2103. // alert(1);
  2104. if (props.url && props.param) {
  2105. // alert(2);
  2106. /**
  2107. * param={"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  2108. * "\"name\":\"hksheng\",\"cascadingName\":\"dq\"," +
  2109. * "\"cascadingInputsName\":\"hkdqm\",\"codebook\":\"sheng\"}",
  2110. * "objectpickertype":1,//2表示获取要回显的一项,1表示获取所有下拉菜单项
  2111. * "upperValue":"440000"
  2112. * };
  2113. */
  2114. const objectPickerParam = {
  2115. input: "false",
  2116. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2117. name: props.name, //本下拉菜单名
  2118. cascadingName: props.param.name, //级联菜单名
  2119. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  2120. codebook: props.param.codebook,
  2121. };
  2122. console.log("mode1 upperValue.value:" + upperValue.value);
  2123. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2124. const params = new URLSearchParams();
  2125. params.append("objectpickerparam", objectPickerParamStr);
  2126. params.append("objectpickertype", "1");
  2127. if (upperValue.value) {
  2128. params.append("upperValue", upperValue.value);
  2129. }
  2130. // params.append('objectpickervalue', value); //需回显的值
  2131. axios
  2132. .post(url, params, {
  2133. headers: {
  2134. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2135. },
  2136. })
  2137. .then((response) => {
  2138. if ("timeout" == response.data.statusText) {
  2139. alert("网络超时!");
  2140. return;
  2141. }
  2142. if (response.data.result) {
  2143. const keys = Object.keys(response.data.result);
  2144. console.log(
  2145. "params:" +
  2146. params +
  2147. "@@response.data:" +
  2148. JSON.stringify(response.data)
  2149. );
  2150. if (keys.length > 0) {
  2151. for (let k in response.data.result) {
  2152. props.opt.push({
  2153. label: response.data.result[k],
  2154. value: k,
  2155. });
  2156. }
  2157. console.log("props.opt11:" + JSON.stringify(props.opt));
  2158. } else {
  2159. // 没有数据时打印日志 by xu 20251212
  2160. console.log("[ccp mode1] 接口返回空数据");
  2161. }
  2162. } else {
  2163. // result不存在时打印日志 by xu 20251212
  2164. console.log("[ccp mode1] 接口返回无result");
  2165. }
  2166. // 无论是否有数据,都显示popup by xu 20251212
  2167. if (!popupWinVisible.value) {
  2168. popupWinVisible.value = true;
  2169. }
  2170. });
  2171. }
  2172. } catch (error) {
  2173. alert(error);
  2174. // callback(null, error.message); // 失败回调,传递错误
  2175. }
  2176. }
  2177. getSelectItems(props.modelValue);
  2178. } else if (props.mode === "2") {
  2179. //没隐藏字段的下拉菜单
  2180. let needInitParam = undefined;
  2181. if (Array.isArray(props.param)) {
  2182. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  2183. console.log(
  2184. "needInitParam最后一项:" + JSON.stringify(needInitParam)
  2185. );
  2186. } else {
  2187. needInitParam = props.param;
  2188. }
  2189. // 获取级联菜单所有下拉菜单项
  2190. async function getSelectItems(value, sendParam) {
  2191. try {
  2192. // alert(1);
  2193. if (props.url && sendParam) {
  2194. // alert(2);
  2195. /**
  2196. * param="{\"input\":\"false\",\"cascadingLevel\":\"dwid,sjryid\",
  2197. * \"ryid\":\"111121\",\"name\":\"sjryid\",
  2198. * \"cascadingName\":\"dw_sjry\",\"codebook\":\"sjryByDw\"}"
  2199. */
  2200. const objectPickerParam = {
  2201. input: "false",
  2202. cascadingLevel: sendParam.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2203. name: props.name, //本下拉菜单名
  2204. cascadingName: sendParam.name, //级联菜单名
  2205. codebook: sendParam.codebook,
  2206. };
  2207. console.log("mode2 upperValue.value:" + upperValue.value);
  2208. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2209. const params = new URLSearchParams();
  2210. params.append("objectpickerparam", objectPickerParamStr);
  2211. params.append("objectpickertype", "1");
  2212. if (upperValue.value) {
  2213. params.append("upperValue", upperValue.value);
  2214. }
  2215. // params.append('objectpickervalue', value); //需回显的值
  2216. axios
  2217. .post(url, params, {
  2218. headers: {
  2219. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2220. },
  2221. })
  2222. .then((response) => {
  2223. if ("timeout" == response.data.statusText) {
  2224. alert("网络超时!");
  2225. return;
  2226. }
  2227. if (response.data.result) {
  2228. const keys = Object.keys(response.data.result);
  2229. console.log(
  2230. "params:" +
  2231. params +
  2232. "@@response.data:" +
  2233. JSON.stringify(response.data)
  2234. );
  2235. if (keys.length > 0) {
  2236. for (let k in response.data.result) {
  2237. props.opt.push({
  2238. label: response.data.result[k],
  2239. value: k,
  2240. });
  2241. }
  2242. console.log("props.opt11:" + JSON.stringify(props.opt));
  2243. } else {
  2244. // 没有数据时打印日志 by xu 20251212
  2245. console.log("[ccp mode2] 接口返回空数据");
  2246. }
  2247. } else {
  2248. // result不存在时打印日志 by xu 20251212
  2249. console.log("[ccp mode2] 接口返回无result");
  2250. }
  2251. // 无论是否有数据,都显示popup by xu 20251212
  2252. if (!popupWinVisible.value) {
  2253. popupWinVisible.value = true;
  2254. }
  2255. });
  2256. }
  2257. } catch (error) {
  2258. alert(error);
  2259. // callback(null, error.message); // 失败回调,传递错误
  2260. }
  2261. }
  2262. getSelectItems(props.modelValue, needInitParam);
  2263. // popupWinVisible.value = !popupWinVisible.value;
  2264. }
  2265. };
  2266. const hidePopup = () => {
  2267. popupWinVisible.value = false;
  2268. };
  2269. // 合并所有的 onMounted 逻辑
  2270. Vue.onMounted(() => {
  2271. window.addEventListener("resize", calculatePopupDirection);
  2272. // 1. 监听展开下一级事件
  2273. window.addEventListener("open-next-cascader", (event) => {
  2274. const { name, level } = event.detail;
  2275. if (name === props.name && level === props.level) {
  2276. popupWinVisible.value = true;
  2277. }
  2278. });
  2279. // 2. 监听级联事件
  2280. window.addEventListener("cascader-change", (event) => {
  2281. const { name, level, value } = event.detail;
  2282. if (name === props.name && level < props.level) {
  2283. selectItem.value = { label: "", value: "" };
  2284. emit("update:modelValue", "");
  2285. if (ssHidden) {
  2286. ssHidden.updateValue(value);
  2287. }
  2288. }
  2289. });
  2290. });
  2291. Vue.onUnmounted(() => {
  2292. window.removeEventListener("resize", calculatePopupDirection);
  2293. });
  2294. // 监听值变化,处理回显 (mode 2)
  2295. Vue.watch(
  2296. () => props.modelValue,
  2297. (newVal) => {
  2298. if (props.mode === "2" && newVal) {
  2299. // 使用 watchEffect 替代嵌套的 watch
  2300. Vue.watchEffect(() => {
  2301. if (props.opt.length > 0) {
  2302. const matchedOption = props.opt.find(
  2303. (opt) => opt.value === newVal
  2304. );
  2305. if (matchedOption) {
  2306. selectItem.value = matchedOption;
  2307. }
  2308. }
  2309. });
  2310. } else {
  2311. // 原有的值变化处理
  2312. const item = props.opt.find((it) => it.value === newVal);
  2313. if (item) {
  2314. selectItem.value = item;
  2315. } else {
  2316. selectItem.value = { label: "", value: "" };
  2317. }
  2318. }
  2319. },
  2320. { immediate: true }
  2321. );
  2322. // 监听选项变化,当数据加载完成时进行匹配
  2323. Vue.watch(
  2324. () => props.opt,
  2325. (newOptions) => {
  2326. if (newOptions.length > 0) {
  2327. const matchedOption = newOptions.find(
  2328. (opt) => opt.value === selectItem.value.value
  2329. );
  2330. if (matchedOption) {
  2331. selectItem.value = matchedOption;
  2332. emit("update:modelValue", matchedOption.value);
  2333. emit("change", matchedOption.value);
  2334. }
  2335. }
  2336. }
  2337. );
  2338. return {
  2339. selectItem,
  2340. popupWinVisible,
  2341. popupDirection,
  2342. popupMaxHeight, // 添加popup最大高度 by xu 20251212
  2343. togglePopup,
  2344. hidePopup,
  2345. doSelectItem,
  2346. };
  2347. },
  2348. template: `
  2349. <div class="input ss-ccp-container" style="position: relative" :style="{width: width}">
  2350. <input type="hidden" :name="name" :value="modelValue">
  2351. <div class="select-container" @mouseleave="hidePopup">
  2352. <div class="input" @click="togglePopup">
  2353. <input
  2354. type="hidden"
  2355. :name="name"
  2356. :value="selectItem.value"
  2357. />
  2358. <input
  2359. :placeholder="placeholder"
  2360. :value="selectItem.label"
  2361. disabled
  2362. style="pointer-events: none;"
  2363. />
  2364. <div class="suffix">
  2365. <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
  2366. </div>
  2367. </div>
  2368. <!-- popup弹出层,添加maxHeight和overflowY支持空间不足时滚动 by xu 20251212 -->
  2369. <div v-show="popupWinVisible" class="popup-win " :class="popupDirection" :style="{ maxHeight: popupMaxHeight, overflowY: popupMaxHeight !== 'none' ? 'auto' : 'visible' }">
  2370. <div v-if="opt && opt.length > 0" class="popup-content">
  2371. <div class="content-area">
  2372. <div
  2373. v-for="(item, index) in opt"
  2374. :key="index"
  2375. @click="doSelectItem(item)"
  2376. :class="{ active: item.value === selectItem.value }"
  2377. >
  2378. <span class="check-icon">
  2379. <ss-form-icon class="form-icon-select-checked" />
  2380. </span>
  2381. <span>{{ item.label }}</span>
  2382. </div>
  2383. </div>
  2384. </div>
  2385. <div v-else class="popup-content">
  2386. <div class="content-area">
  2387. <div class="content-area">
  2388. <span>无选项</span>
  2389. </div>
  2390. </div>
  2391. </div>
  2392. </div>
  2393. </div>
  2394. </div>
  2395. `,
  2396. };
  2397. // ss-date-picker 日期时间选择器组件
  2398. const SsDatePicker = {
  2399. name: "SsDatePicker",
  2400. props: {
  2401. modelValue: {
  2402. type: [String, Number, Date],
  2403. default: "",
  2404. },
  2405. name: {
  2406. type: String,
  2407. required: true,
  2408. },
  2409. type: {
  2410. type: String,
  2411. default: "date",
  2412. validator: (value) => ["date", "datetime", "time"].includes(value),
  2413. },
  2414. fmt: {
  2415. type: String,
  2416. default: null,
  2417. },
  2418. placeholder: {
  2419. type: String,
  2420. default: "",
  2421. },
  2422. width: {
  2423. type: String,
  2424. default: "100%",
  2425. },
  2426. },
  2427. emits: ["update:modelValue"],
  2428. setup(props, { emit }) {
  2429. const errMsg = ref("");
  2430. const validate = () => {
  2431. if (window.ssVm) {
  2432. const result = window.ssVm.validateField(props.name);
  2433. console.log("validate", window.ssVm.validateField(props.name));
  2434. errMsg.value = result.valid ? "" : result.message;
  2435. }
  2436. };
  2437. // 根据type确定默认格式
  2438. const defaultFormat = computed(() => {
  2439. switch (props.type) {
  2440. case "datetime":
  2441. return "YYYY-MM-DD HH:mm:ss";
  2442. case "date":
  2443. return "YYYY-MM-DD";
  2444. case "time":
  2445. return "HH:mm:ss";
  2446. }
  2447. });
  2448. const convertJavaFormatToElement = (javaFormat) => {
  2449. if (!javaFormat) return null;
  2450. return javaFormat
  2451. .replace("yyyy", "YYYY")
  2452. .replace("MM", "MM")
  2453. .replace("dd", "DD")
  2454. .replace("HH", "HH")
  2455. .replace("mm", "mm")
  2456. .replace("ss", "ss");
  2457. };
  2458. const finalFormat = computed(() => {
  2459. if (props.fmt) {
  2460. return convertJavaFormatToElement(props.fmt);
  2461. }
  2462. return defaultFormat.value;
  2463. });
  2464. // 使用 resolveComponent 获取组件
  2465. const ElDatePicker = resolveComponent("ElDatePicker");
  2466. const ElTimePicker = resolveComponent("ElTimePicker");
  2467. const SsFormIcon = resolveComponent("SsFormIcon");
  2468. const ElIcon = resolveComponent("ElIcon");
  2469. const handleValueUpdate = (val) => {
  2470. emit("update:modelValue", val);
  2471. emit("change", val); // 同时触发 change 事件
  2472. setTimeout(() => {
  2473. validate();
  2474. }, 50);
  2475. };
  2476. const dateType = computed(() => {
  2477. const fmt = props.fmt || "";
  2478. if (fmt.includes("HH:mm:ss")) {
  2479. return "datetime";
  2480. } else if (fmt.includes("HH:mm")) {
  2481. return "datetime";
  2482. } else if (fmt.includes("mm:ss")) {
  2483. return "time";
  2484. }
  2485. return "date";
  2486. });
  2487. let useTimePicker = true;
  2488. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  2489. if (props.fmt) {
  2490. //有fmt属性,则以fmt属性优先判断类型
  2491. if (/[dMy]/.test(props.fmt)) {
  2492. //如果有传入日期格式,且含年月日
  2493. useTimePicker = false;
  2494. } else {
  2495. useTimePicker = true;
  2496. }
  2497. } else if (props.type !== "time") {
  2498. useTimePicker = false;
  2499. }
  2500. return () =>
  2501. h("div", { class: "ss-date-picker", style: { width: props.width } }, [
  2502. h("input", {
  2503. type: "hidden",
  2504. name: props.name,
  2505. value: props.modelValue,
  2506. }),
  2507. // 选择组件
  2508. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  2509. modelValue: props.modelValue,
  2510. "onUpdate:modelValue": handleValueUpdate,
  2511. type: dateType.value,
  2512. format: finalFormat.value,
  2513. "value-format": finalFormat.value,
  2514. clearable: true,
  2515. placeholder: props.placeholder,
  2516. class: "custom-date-picker", // 用于自定义样式
  2517. "time-arrow-control": props.type === "datetime", // 修改这里
  2518. size: "large", // 添加这一行,改为 large 尺寸
  2519. style: { width: "100%" },
  2520. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  2521. }),
  2522. ]);
  2523. },
  2524. };
  2525. // ss-icon 图标
  2526. // v3.0 增加 class 属性分支:有 class 走新逻辑,否则走 v1.0 逻辑 by xu 20251212
  2527. // v3.0 用法: <ss-icon class="icon-obj-ry menu-icon" />
  2528. // v1.0 用法: <ss-icon name="setting" size="20px" />
  2529. const SsIcon = {
  2530. name: "SsIcon",
  2531. // v3.0 禁用 class 透传,手动处理 by xu 20251215
  2532. inheritAttrs: false,
  2533. props: {
  2534. // v1.0: 以下为旧属性
  2535. name: { type: String },
  2536. size: { type: [Number, String], default: 16 },
  2537. unit: { type: String, default: "px" },
  2538. color: String,
  2539. type: {
  2540. type: String,
  2541. default: ssIcon.name,
  2542. validator: function (value) {
  2543. return [ssIcon, commonIcon].some((icon) => icon.name === value);
  2544. },
  2545. },
  2546. },
  2547. emits: ["update:modelValue", "input", "blur", "change"],
  2548. setup(props, { emit, attrs }) {
  2549. // v3.0 分支:有 class 属性时直接渲染(从 attrs 获取) by xu 20251215
  2550. if (attrs.class) {
  2551. return () =>
  2552. h("i", { ...attrs, class: attrs.class + " icon-container" });
  2553. }
  2554. // v1.0 分支:原有逻辑
  2555. const useIconType = computed(() => {
  2556. return [ssIcon, commonIcon].find(
  2557. (iconConfig) => iconConfig.name === props.type
  2558. );
  2559. });
  2560. const iconName = computed(() => {
  2561. const iconConfig = useIconType.value; // 注意:使用 .value 来访问响应式引用的值
  2562. if (!iconConfig) {
  2563. console.error(`Icon type "${props.type}" not found.`);
  2564. return "";
  2565. }
  2566. const iconType = iconConfig.types[props.name];
  2567. if (!iconType) {
  2568. console.error(
  2569. `Icon name "${props.name}" not found in type "${props.type}".`
  2570. );
  2571. return "";
  2572. }
  2573. return `${iconConfig.prefix}${iconType}`;
  2574. });
  2575. // 类似地,你可以计算 fontFamily 和 style
  2576. const fontFamily = computed(() => {
  2577. return useIconType.value ? useIconType.value.family : "";
  2578. });
  2579. // console.log(iconName.value,fontFamily.value)
  2580. const style = computed(() => {
  2581. const sizeStyle = isNum(props.size)
  2582. ? `${props.size}${props.unit}`
  2583. : props.size;
  2584. const styleObj = {
  2585. fontSize: sizeStyle,
  2586. color: props.color || "",
  2587. };
  2588. return toStyleStr(styleObj);
  2589. });
  2590. // 使用渲染函数定义模板逻辑
  2591. return () =>
  2592. h("i", {
  2593. class: ["icon-container", iconName.value, fontFamily.value],
  2594. style: style.value,
  2595. });
  2596. },
  2597. };
  2598. // 通用icon
  2599. const SsCommonIcon = {
  2600. name: "SsCommonIcon",
  2601. props: {
  2602. class: {
  2603. type: String,
  2604. required: true,
  2605. },
  2606. },
  2607. setup(props) {
  2608. return () =>
  2609. h("i", {
  2610. class: props.class + " common-icon",
  2611. });
  2612. },
  2613. };
  2614. // 登录页icon
  2615. const SsLoginIcon = {
  2616. name: "SsLoginIcon",
  2617. props: {
  2618. class: {
  2619. type: String,
  2620. required: true,
  2621. },
  2622. },
  2623. setup(props) {
  2624. return () =>
  2625. h("div", {
  2626. class: props.class + " login-icon",
  2627. });
  2628. },
  2629. };
  2630. // 弹窗icon
  2631. const SsDialogIcon = {
  2632. name: "SsDialogIcon",
  2633. props: {
  2634. class: {
  2635. type: String,
  2636. required: true,
  2637. },
  2638. },
  2639. setup(props) {
  2640. return () =>
  2641. h("i", {
  2642. class: props.class + " dialog-icon",
  2643. });
  2644. },
  2645. };
  2646. // 全局左侧导航图标组件
  2647. const SsNavIcon = {
  2648. name: "SsNavIcon",
  2649. props: {
  2650. class: {
  2651. type: String,
  2652. required: true,
  2653. },
  2654. },
  2655. setup(props) {
  2656. return () =>
  2657. h("div", {
  2658. class: props.class + " nav-icon",
  2659. });
  2660. },
  2661. };
  2662. // 顶部工具栏图标组件
  2663. const SsHeaderIcon = {
  2664. name: "SsHeaderIcon",
  2665. props: {
  2666. class: {
  2667. type: String,
  2668. required: true,
  2669. },
  2670. },
  2671. setup(props) {
  2672. return () =>
  2673. h("div", {
  2674. class: props.class + " header-icon",
  2675. });
  2676. },
  2677. };
  2678. // 全局菜单图标组件
  2679. const SsGolbalMenuIcon = {
  2680. name: "SsGolbalMenuIcon",
  2681. props: {
  2682. class: {
  2683. type: String,
  2684. required: true,
  2685. },
  2686. },
  2687. setup(props) {
  2688. return () =>
  2689. h("div", {
  2690. class: props.class + " global-menu-icon",
  2691. });
  2692. },
  2693. };
  2694. // 全局查询列表卡片图标
  2695. const SsCartListIcon = {
  2696. name: "SsCartListIcon",
  2697. props: {
  2698. class: {
  2699. type: String,
  2700. required: true,
  2701. },
  2702. },
  2703. setup(props) {
  2704. return () =>
  2705. h("div", {
  2706. class: props.class + " cart-list-icon",
  2707. });
  2708. },
  2709. };
  2710. // 全局底部工具栏图标组件
  2711. const SsQuickIcon = {
  2712. name: "SsQuickIcon",
  2713. props: {
  2714. class: {
  2715. type: String,
  2716. required: true,
  2717. },
  2718. },
  2719. setup(props) {
  2720. return () =>
  2721. h("div", {
  2722. class: props.class + " quick-icon",
  2723. });
  2724. },
  2725. };
  2726. // 表单组件icon
  2727. const SsFormIcon = {
  2728. name: "SsFormIcon",
  2729. props: {
  2730. class: {
  2731. type: String,
  2732. required: true,
  2733. },
  2734. },
  2735. setup(props) {
  2736. return () =>
  2737. h("div", {
  2738. class: props.class + " form-icon",
  2739. });
  2740. },
  2741. };
  2742. // 弹窗底部按钮icon
  2743. const SsBottomDivIcon = {
  2744. name: "SsBottomDivIcon",
  2745. props: {
  2746. class: {
  2747. type: String,
  2748. required: true,
  2749. },
  2750. },
  2751. setup(props) {
  2752. return () =>
  2753. h("div", {
  2754. class: props.class + " bottom-div-icon",
  2755. });
  2756. },
  2757. };
  2758. // editor组件icon
  2759. const SsEditorIcon = {
  2760. name: "SsEditorIcon",
  2761. props: {
  2762. class: {
  2763. type: String,
  2764. required: true,
  2765. },
  2766. },
  2767. setup(props) {
  2768. return () =>
  2769. h("i", {
  2770. class: props.class + " editor-icon",
  2771. });
  2772. },
  2773. };
  2774. // ss-validate校验器
  2775. const SsValidate = {
  2776. name: "SsValidate",
  2777. props: {
  2778. errMsg: { type: String },
  2779. textAlign: { type: String, default: "left" },
  2780. style: { type: Object, default: () => ({}) },
  2781. },
  2782. template: `<div class="validate-vline"></div>
  2783. <div class="validate-tip" :style="style">
  2784. <div class="tip" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  2785. <div class="tip-more" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  2786. </div>`,
  2787. };
  2788. // ss-onoff-array 多选按钮 数组形式
  2789. const SsonoffArray = {
  2790. name: "SsonoffArray",
  2791. props: {
  2792. name: {
  2793. type: String,
  2794. required: true,
  2795. },
  2796. opt: {
  2797. type: Array,
  2798. default: () => [],
  2799. },
  2800. defaultValue: [String, Number, Array],
  2801. modelValue: [String, Number, Array],
  2802. multiple: {
  2803. // 新增多选模式属性
  2804. type: Boolean,
  2805. default: false,
  2806. },
  2807. // 是否允许一项都不选,默认true允许 by xu 20251212
  2808. null: {
  2809. type: Boolean,
  2810. default: true,
  2811. },
  2812. },
  2813. emits: ["update:modelValue"], // 允许更新 v-model 绑定的值
  2814. setup(props, { emit }) {
  2815. console.log("多选按钮", props.opt);
  2816. // 使用数组来存储选中值
  2817. const checkedValue = ref(
  2818. props.multiple
  2819. ? Array.isArray(props.defaultValue)
  2820. ? props.defaultValue
  2821. : []
  2822. : props.defaultValue
  2823. );
  2824. const errMsg = ref(props.errTip);
  2825. // 生成icon名字
  2826. const genIconName = (itemValue) => {
  2827. if (props.multiple) {
  2828. return checkedValue.value.includes(itemValue)
  2829. ? "form-icon-onoff-checked"
  2830. : "form-icon-onoff-unchecked";
  2831. }
  2832. return checkedValue.value === itemValue
  2833. ? "form-icon-onoff-checked"
  2834. : "form-icon-onoff-unchecked";
  2835. };
  2836. // 选中项
  2837. const selectItem = (value) => {
  2838. if (props.multiple) {
  2839. // 多选模式
  2840. const index = checkedValue.value.indexOf(value);
  2841. if (index === -1) {
  2842. checkedValue.value = [...checkedValue.value, value];
  2843. } else {
  2844. // 取消选中当前项
  2845. const newValue = checkedValue.value.filter((v) => v !== value);
  2846. // 如果不允许为空且取消后为空,则阻止取消操作 by xu 20251212
  2847. if (!props.null && newValue.length === 0) {
  2848. return; // 阻止取消最后一项
  2849. }
  2850. checkedValue.value = newValue;
  2851. }
  2852. } else {
  2853. // 单选模式
  2854. // 如果点击的是当前已选中的项,判断是否允许取消 by xu 20251212
  2855. if (checkedValue.value === value) {
  2856. if (!props.null) {
  2857. return; // 不允许为空时,阻止取消
  2858. }
  2859. checkedValue.value = ""; // 允许为空时,取消选中
  2860. } else {
  2861. checkedValue.value = value;
  2862. }
  2863. }
  2864. emit("update:modelValue", checkedValue.value);
  2865. nextTick(() => {
  2866. // 触发验证
  2867. if (window.ssVm) {
  2868. window.ssVm.validateField(props.name);
  2869. }
  2870. });
  2871. };
  2872. return { checkedValue, genIconName, selectItem };
  2873. },
  2874. // 使用渲染函数定义模板逻辑
  2875. render() {
  2876. const SsFormIcon = resolveComponent("ss-form-icon");
  2877. return h("div", { class: "radio-container" }, [
  2878. // 根据情况创建 input
  2879. this.multiple
  2880. ? this.checkedValue.length
  2881. ? // 多选且有选中值:为选中项创建 input
  2882. this.checkedValue.map((value) =>
  2883. h("input", {
  2884. type: "checkbox",
  2885. name: this.name,
  2886. value: value,
  2887. checked: true,
  2888. style: { display: "none" },
  2889. })
  2890. )
  2891. : // 多选但没有选中值:创建一个空值 input
  2892. h("input", {
  2893. type: "hidden",
  2894. name: this.name,
  2895. value: "",
  2896. })
  2897. : // 单选模式:创建一个 input
  2898. h("input", {
  2899. type: "hidden",
  2900. name: this.name,
  2901. value: this.checkedValue || "",
  2902. }),
  2903. this.opt.map((item, i) =>
  2904. h(
  2905. "div",
  2906. {
  2907. key: i,
  2908. class: {
  2909. checked: this.multiple
  2910. ? this.checkedValue.includes(item.value)
  2911. : this.checkedValue === item.value,
  2912. },
  2913. style: { width: item.width },
  2914. onClick: () => this.selectItem(item.value),
  2915. },
  2916. [
  2917. h("span", null, item.label),
  2918. h("div", { class: "mark" }, [
  2919. h(SsFormIcon, {
  2920. class: this.genIconName(item.value),
  2921. }),
  2922. ]),
  2923. ]
  2924. )
  2925. ),
  2926. ]);
  2927. },
  2928. };
  2929. // ss-onoff 一个按钮
  2930. const Ssonoff = {
  2931. name: "Ssonoff",
  2932. props: {
  2933. name: {
  2934. type: String,
  2935. required: true,
  2936. },
  2937. label: {
  2938. type: String,
  2939. required: true,
  2940. },
  2941. value: {
  2942. type: [String, Number],
  2943. required: true,
  2944. },
  2945. width: {
  2946. type: String,
  2947. default: "",
  2948. },
  2949. onchange: {
  2950. // 在此属性传入 onChange 的 window 全局回调函数,第一参数是当前整组值 by Ben/xu(20260320)
  2951. type: String,
  2952. required: false,
  2953. },
  2954. modelValue: [String, Number, Array],
  2955. multiple: {
  2956. type: Boolean,
  2957. default: false,
  2958. },
  2959. null: {
  2960. type: Boolean,
  2961. default: true,
  2962. },
  2963. },
  2964. emits: ["update:modelValue", "change"],
  2965. setup(props, { emit }) {
  2966. const parseModelValue = (val) => {
  2967. if (Array.isArray(val)) {
  2968. return val
  2969. .map((item) => (item == null ? "" : item.toString()))
  2970. .filter(Boolean);
  2971. }
  2972. if (val == null || val === "") return [];
  2973. // 如果以逗号开头,去掉开头的逗号
  2974. const cleanValue = val.toString().replace(/^,+/, "");
  2975. if (!cleanValue) return [];
  2976. if (cleanValue.includes("|")) {
  2977. return cleanValue.split("|").filter(Boolean);
  2978. }
  2979. if (cleanValue.includes(",")) {
  2980. return cleanValue.split(",").filter(Boolean);
  2981. }
  2982. return [cleanValue];
  2983. };
  2984. const callGlobalOnchg = (groupValue) => {
  2985. if (props.onchange && typeof props.onchange === "string") {
  2986. if (
  2987. typeof window !== "undefined" &&
  2988. window[props.onchange] &&
  2989. typeof window[props.onchange] === "function"
  2990. ) {
  2991. try {
  2992. window[props.onchange](groupValue, props.value, props.label);
  2993. } catch (error) {
  2994. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  2995. }
  2996. } else {
  2997. console.warn(`全局函数 ${props.onchange} 未定义或不是一个函数。`);
  2998. }
  2999. }
  3000. };
  3001. // 判断当前按钮是否选中
  3002. const isChecked = computed(() => {
  3003. if (props.multiple) {
  3004. const currentValue = parseModelValue(props.modelValue);
  3005. return currentValue.includes(props.value.toString());
  3006. }
  3007. return props.modelValue + "" === props.value + ""; //强转为字符串类型再比较(改之前是数字类型和字符串类型作比较,永远为false) Ben 20251206
  3008. });
  3009. // 切换选中状态
  3010. const toggleSelect = () => {
  3011. let newModelValue;
  3012. if (props.multiple) {
  3013. const currentValue = parseModelValue(props.modelValue);
  3014. const currentButtonValue = props.value.toString();
  3015. const index = currentValue.indexOf(currentButtonValue);
  3016. let newValue;
  3017. if (index === -1) {
  3018. // 选中当前项
  3019. newValue = [...currentValue, currentButtonValue];
  3020. } else {
  3021. // 取消选中当前项
  3022. const filteredValue = currentValue.filter(
  3023. (value) => value !== currentButtonValue
  3024. );
  3025. // 如果不允许为空且取消后为空,则阻止取消操作
  3026. if (!props.null && filteredValue.length === 0) {
  3027. return; // 阻止取消最后一项
  3028. }
  3029. newValue = filteredValue;
  3030. }
  3031. newModelValue = newValue.join(",");
  3032. } else {
  3033. // 单选模式
  3034. const currentValue = parseModelValue(props.modelValue);
  3035. const isCurrentlySelected = currentValue.includes(
  3036. props.value.toString()
  3037. );
  3038. if (!isCurrentlySelected) {
  3039. // 选中当前项
  3040. newModelValue = props.value;
  3041. } else {
  3042. // 取消选中当前项
  3043. // 如果不允许为空且当前只有这一项被选中,则阻止取消操作
  3044. if (!props.null && currentValue.length === 1) {
  3045. return; // 阻止取消唯一选中项
  3046. }
  3047. newModelValue = "";
  3048. }
  3049. }
  3050. emit("update:modelValue", newModelValue);
  3051. emit("change", newModelValue, props.value, props.label);
  3052. callGlobalOnchg(newModelValue);
  3053. nextTick(() => {
  3054. // 触发验证
  3055. if (window.ssVm) {
  3056. window.ssVm.validateField(props.name);
  3057. }
  3058. });
  3059. };
  3060. return { isChecked, toggleSelect };
  3061. },
  3062. render() {
  3063. const SsFormIcon = resolveComponent("ss-form-icon");
  3064. return h("div", { class: "radio-container2" }, [
  3065. // 隐藏的表单元素
  3066. this.multiple
  3067. ? h("input", {
  3068. type: "hidden",
  3069. name: `${this.name}`, // 多选模式下使用数组形式的 name
  3070. value: this.isChecked ? this.value : "",
  3071. })
  3072. : this.isChecked &&
  3073. h("input", {
  3074. // 只有当前按钮被选中时才创建 input
  3075. type: "hidden",
  3076. name: this.name,
  3077. value: this.value,
  3078. }),
  3079. // 按钮显示
  3080. h(
  3081. "div",
  3082. {
  3083. class: { checked: this.isChecked },
  3084. style: { width: this.width },
  3085. onClick: this.toggleSelect,
  3086. },
  3087. [
  3088. h("span", null, this.label),
  3089. h("div", { class: "mark" }, [
  3090. h(SsFormIcon, {
  3091. class: this.isChecked
  3092. ? "form-icon-onoff-checked"
  3093. : "form-icon-onoff-unchecked",
  3094. }),
  3095. ]),
  3096. ]
  3097. ),
  3098. ]);
  3099. },
  3100. };
  3101. // ss-textarea
  3102. // ss-textarea
  3103. const SsTextarea = {
  3104. name: "SsTextarea",
  3105. props: {
  3106. name: {
  3107. type: String,
  3108. required: true,
  3109. },
  3110. placeholder: {
  3111. type: String,
  3112. default: "请输入",
  3113. },
  3114. defaultValue: [String, Number],
  3115. modelValue: [String, Number],
  3116. },
  3117. emits: ["update:modelValue"],
  3118. setup(props, { emit }) {
  3119. const inputValue = ref(props.modelValue || props.defaultValue || "");
  3120. // 监听 modelValue 变化
  3121. watch(
  3122. () => props.modelValue,
  3123. (newVal) => {
  3124. inputValue.value = newVal;
  3125. }
  3126. );
  3127. // 输入事件处理
  3128. const onInput = (event) => {
  3129. const newValue = event.target.value;
  3130. inputValue.value = newValue;
  3131. emit("update:modelValue", newValue);
  3132. // 触发验证
  3133. if (window.ssVm) {
  3134. window.ssVm.validateField(props.name);
  3135. }
  3136. };
  3137. // 失焦时验证
  3138. const onBlur = () => {
  3139. if (window.ssVm) {
  3140. window.ssVm.validateField(props.name);
  3141. }
  3142. };
  3143. return { inputValue, onInput, onBlur };
  3144. },
  3145. render() {
  3146. return h("div", { class: "textarea-container" }, [
  3147. h("div", { class: "textarea" }, [
  3148. h("input", {
  3149. type: "hidden",
  3150. name: this.name,
  3151. value: this.inputValue || "",
  3152. }),
  3153. h("textarea", {
  3154. placeholder: this.placeholder,
  3155. value: this.inputValue,
  3156. onInput: this.onInput,
  3157. onBlur: this.onBlur,
  3158. }),
  3159. ]),
  3160. ]);
  3161. },
  3162. };
  3163. // ss-editor 富文本编辑器 基于Jodit
  3164. const SsEditor = {
  3165. name: "SsEditor",
  3166. props: {
  3167. modelValue: {
  3168. type: String,
  3169. default: "",
  3170. },
  3171. html: {
  3172. type: String,
  3173. default: "",
  3174. },
  3175. name: {
  3176. type: String,
  3177. default: "",
  3178. },
  3179. url: {
  3180. type: String,
  3181. default: "",
  3182. },
  3183. height: {
  3184. type: [Number, String],
  3185. default: 400,
  3186. },
  3187. placeholder: {
  3188. type: String,
  3189. default: "请输入内容",
  3190. },
  3191. mode: {
  3192. type: String,
  3193. default: "edit", // 'edit' | 'play'
  3194. },
  3195. uploadUrl: {
  3196. type: String,
  3197. default: "/ulByHttp", //原值为“upload” Ben(20251205)
  3198. },
  3199. param: {
  3200. type: Object,
  3201. default: () => ({}),
  3202. },
  3203. },
  3204. emits: ["update:modelValue", "ready", "change"],
  3205. setup(props, { emit }) {
  3206. const editorRef = ref(null);
  3207. const editorContent = ref("");
  3208. const currentModelValue = ref(props.modelValue || "");
  3209. const uniqueId = "editor-" + Date.now();
  3210. const errMsg = Vue.ref("");
  3211. // button 支持对象(旧格式,单个附件按钮)或数组(新格式,多个按钮)by xu 20250331
  3212. const buttonConfigRaw = props.param && props.param.button ? props.param.button : null;
  3213. const buttonArray = Array.isArray(buttonConfigRaw)
  3214. ? buttonConfigRaw
  3215. : buttonConfigRaw
  3216. ? [buttonConfigRaw]
  3217. : [];
  3218. // 找到附件按钮配置(有 cmsAddUrl 的)
  3219. const fjButton = buttonArray.find(btn => btn.cmsAddUrl && btn.cmsUpdUrl) || {};
  3220. const fjid = ref(fjButton.val || null);
  3221. const fjName = fjButton.desc || "附件";
  3222. // 筛选出自定义按钮(有 func 的)
  3223. const customButtonsFromParam = buttonArray.filter(btn => btn.func).map(btn => ({
  3224. name: btn.name,
  3225. text: btn.desc || btn.text,
  3226. tooltip: btn.desc || btn.tooltip,
  3227. icon: btn.icon || 'editor-icon-file',
  3228. onClick: btn.func // 函数名字符串
  3229. }));
  3230. const mode = props.param ? props.param.mode : null;
  3231. const normalizeHtml = (rawHtml) => {
  3232. if (rawHtml == null) {
  3233. return "";
  3234. }
  3235. const html = String(rawHtml).trim();
  3236. if (!html) {
  3237. return "";
  3238. }
  3239. if (
  3240. /<html[\s>]/i.test(html) ||
  3241. /<body[\s>]/i.test(html) ||
  3242. /<!doctype/i.test(html)
  3243. ) {
  3244. try {
  3245. const doc = new DOMParser().parseFromString(html, "text/html");
  3246. if (doc && doc.body) {
  3247. return doc.body.innerHTML || "";
  3248. }
  3249. } catch (e) {
  3250. console.warn("ss-editor 解析完整HTML失败,回退原始内容:", e);
  3251. }
  3252. }
  3253. return html;
  3254. };
  3255. const syncHiddenContentInput = (html) => {
  3256. const contentElements = document.getElementsByName(
  3257. props.name.replace(/wj$/, "") + "Edit"
  3258. );
  3259. if (contentElements.length > 0) {
  3260. contentElements[0].value = html;
  3261. }
  3262. };
  3263. const setEditorHtml = (html) => {
  3264. const normalizedHtml = normalizeHtml(html);
  3265. editorContent.value = normalizedHtml;
  3266. syncHiddenContentInput(normalizedHtml);
  3267. if (editorRef.value && editorRef.value.value !== normalizedHtml) {
  3268. editorRef.value.value = normalizedHtml;
  3269. }
  3270. };
  3271. const resolveWindowFunction = (handlerName) => {
  3272. if (!handlerName || typeof handlerName !== "string") {
  3273. return null;
  3274. }
  3275. return handlerName.split(".").reduce((current, key) => {
  3276. return current && current[key] != null ? current[key] : null;
  3277. }, window);
  3278. };
  3279. const getCustomButtonKey = (button, index) => {
  3280. const baseName =
  3281. (button &&
  3282. (button.key || button.name || button.text || button.tooltip)) ||
  3283. `button${index + 1}`;
  3284. return `ssCustomButton_${String(baseName).replace(
  3285. /[^a-zA-Z0-9_-]/g,
  3286. "_"
  3287. )}_${index}`;
  3288. };
  3289. const normalizeCustomButtons = (buttons = []) => {
  3290. return Array.isArray(buttons)
  3291. ? buttons.filter(Boolean).map((button, index) => ({
  3292. ...button,
  3293. _buttonKey: getCustomButtonKey(button, index),
  3294. }))
  3295. : [];
  3296. };
  3297. const renderButtonIcon = (icon) => {
  3298. if (!icon) {
  3299. return null;
  3300. }
  3301. if (typeof icon === "string" && icon.trim().startsWith("<")) {
  3302. return icon;
  3303. }
  3304. return `<span class="editor-icon ${icon}"></span>`;
  3305. };
  3306. const buildCustomButtonRegistry = (buttons = []) => {
  3307. const controls = {};
  3308. const buttonNames = [];
  3309. const iconMap = {};
  3310. normalizeCustomButtons(buttons).forEach((button) => {
  3311. const buttonKey = button._buttonKey;
  3312. const handler =
  3313. button.onClick ||
  3314. button.click ||
  3315. button.handler ||
  3316. button.exec ||
  3317. null;
  3318. const tooltip =
  3319. button.tooltip ||
  3320. button.text ||
  3321. button.label ||
  3322. button.name ||
  3323. "自定义按钮";
  3324. buttonNames.push(buttonKey);
  3325. if (button.icon) {
  3326. iconMap[buttonKey] = button.icon;
  3327. }
  3328. controls[buttonKey] = {
  3329. name: button.name || buttonKey,
  3330. tooltip,
  3331. exec: function (editor) {
  3332. const context = {
  3333. editor,
  3334. button,
  3335. props,
  3336. value:
  3337. editor && typeof editor.value !== "undefined"
  3338. ? editor.value
  3339. : "",
  3340. setValue: (value) => setEditorHtml(value),
  3341. getValue: () =>
  3342. editor && typeof editor.value !== "undefined"
  3343. ? editor.value
  3344. : "",
  3345. emit,
  3346. currentModelValue: currentModelValue.value,
  3347. fjid: fjid.value,
  3348. };
  3349. if (typeof handler === "function") {
  3350. return handler(context);
  3351. }
  3352. if (typeof handler === "string") {
  3353. const windowHandler = resolveWindowFunction(handler);
  3354. if (typeof windowHandler === "function") {
  3355. return windowHandler(context);
  3356. }
  3357. console.warn("ss-editor 自定义按钮未找到点击事件:", handler);
  3358. return undefined;
  3359. }
  3360. console.warn("ss-editor 自定义按钮缺少点击事件配置:", button);
  3361. return undefined;
  3362. },
  3363. };
  3364. });
  3365. return {
  3366. controls,
  3367. buttonNames,
  3368. iconMap,
  3369. };
  3370. };
  3371. const validate = () => {
  3372. if (window.ssVm) {
  3373. const result = window.ssVm.validateField(props.name);
  3374. console.log("validate", window.ssVm.validateField(props.name));
  3375. errMsg.value = result.valid ? "" : result.message;
  3376. }
  3377. };
  3378. onMounted(() => {
  3379. validate();
  3380. // 只读模式下不初始化 Jodit,直接设置内容 by xu 20250402
  3381. if (props.mode === "play") {
  3382. if (props.html) {
  3383. setEditorHtml(props.html);
  3384. } else if (props.url) {
  3385. const params = new URLSearchParams();
  3386. if (mode) params.append("mode", mode);
  3387. if (props.modelValue) params.append("path", props.modelValue);
  3388. axios
  3389. .post(props.url, params, {
  3390. headers: {
  3391. "Content-Type": "application/x-www-form-urlencoded",
  3392. },
  3393. })
  3394. .then((response) => {
  3395. if ("timeout" == response.data.statusText) {
  3396. alert("网络超时!");
  3397. return;
  3398. }
  3399. const content = response.data.content;
  3400. if (content != null) {
  3401. setEditorHtml(content);
  3402. }
  3403. const filePath = response.data.path;
  3404. if (filePath) {
  3405. currentModelValue.value = filePath;
  3406. emit("update:modelValue", filePath);
  3407. }
  3408. });
  3409. } else {
  3410. setEditorHtml(props.html);
  3411. }
  3412. return;
  3413. }
  3414. // 读取按钮配置 by xu 20250408(移除废弃的 props.customButtons)
  3415. let buttonsToUse = [];
  3416. // 1. 优先从 param.button 数组中筛选(新格式)by xu 20250331
  3417. if (customButtonsFromParam && customButtonsFromParam.length > 0) {
  3418. buttonsToUse = customButtonsFromParam;
  3419. }
  3420. // 2. 尝试从 param.customButtons 读取(旧格式,兼容)
  3421. if (!buttonsToUse || buttonsToUse.length === 0) {
  3422. if (props.param && props.param.customButtons && props.param.customButtons.length > 0) {
  3423. buttonsToUse = props.param.customButtons;
  3424. }
  3425. }
  3426. // 3. 尝试通过桥接 API 读取
  3427. if (!buttonsToUse || buttonsToUse.length === 0) {
  3428. const vm = window.SS.dom.getVueApp({ scope: "chain" });
  3429. if (vm && vm.zwwjCustomButtons) {
  3430. buttonsToUse = vm.zwwjCustomButtons;
  3431. }
  3432. }
  3433. // 4. 从 formElemConfig 读取(兜底)
  3434. if (!buttonsToUse || buttonsToUse.length === 0) {
  3435. const zwwjConfig = window.SS.dom.formElemConfig?.zwwj;
  3436. if (zwwjConfig?.customButtons) {
  3437. buttonsToUse = zwwjConfig.customButtons;
  3438. } else {
  3439. buttonsToUse = window.SS.dom.formElemConfig?.zwwjCustomButtons;
  3440. }
  3441. }
  3442. const {
  3443. controls: customButtonControls,
  3444. buttonNames: customButtonNames,
  3445. iconMap: customButtonIconMap,
  3446. } = buildCustomButtonRegistry(buttonsToUse);
  3447. console.log(
  3448. "[SsEditor] 解析后的按钮:",
  3449. customButtonNames,
  3450. customButtonControls
  3451. );
  3452. const appendCustomButtons = (buttons = []) => {
  3453. if (!customButtonNames.length) {
  3454. return buttons;
  3455. }
  3456. const toolbarButtons = [...buttons];
  3457. const insertIndex = toolbarButtons.includes("dots")
  3458. ? toolbarButtons.indexOf("dots")
  3459. : toolbarButtons.includes("print")
  3460. ? toolbarButtons.indexOf("print")
  3461. : -1;
  3462. if (insertIndex >= 0) {
  3463. toolbarButtons.splice(insertIndex, 0, ...customButtonNames);
  3464. return toolbarButtons;
  3465. }
  3466. return [...toolbarButtons, ...customButtonNames];
  3467. };
  3468. const editor = Jodit.make(`#${uniqueId}`, {
  3469. height: props.height,
  3470. placeholder: props.placeholder,
  3471. readonly: props.mode === "play",
  3472. language: "zh_cn",
  3473. i18n: {
  3474. zh_cn: {
  3475. Link: "链接",
  3476. URL: "链接",
  3477. "No follow": "无跟踪",
  3478. "Class name": "类名",
  3479. Image: "图片",
  3480. File: "文件",
  3481. "Line height": "行高",
  3482. Alternative: "描述",
  3483. "Alternative text": "描述",
  3484. "Lower Alpha": "小写字母",
  3485. "Upper Alpha": "大写字母",
  3486. "Upper Roman": "大写罗马数字",
  3487. "Lower Roman": "小写罗马数字",
  3488. "Lower Greek": "小写希腊字母",
  3489. "Lower Letter": "小写字母",
  3490. "Upper Letter": "大写字母",
  3491. },
  3492. },
  3493. showXPathInStatusbar: false,
  3494. showCharsCounter: false,
  3495. showWordsCounter: false,
  3496. allowResizeY: false,
  3497. toolbarSticky: false,
  3498. statusbar: false,
  3499. uploader: {
  3500. url: props.uploadUrl,
  3501. format: "json",
  3502. method: "POST",
  3503. filesVariableName: function (i) {
  3504. return "imgs[" + i + "]";
  3505. },
  3506. headers: {
  3507. Accept: "application/json",
  3508. },
  3509. prepareData: function (formData) {
  3510. return formData;
  3511. },
  3512. isSuccess: function (resp) {
  3513. console.log("isSuccess resp:", resp);
  3514. return resp.code === 0;
  3515. },
  3516. getMessage: function (resp) {
  3517. console.log("getMessage resp:", resp);
  3518. return resp.msg || "上传失败";
  3519. },
  3520. process: function (resp) {
  3521. console.log("process resp:", resp);
  3522. return resp.data.url;
  3523. },
  3524. error: function (e) {
  3525. console.error("上传失败:", e.message);
  3526. },
  3527. defaultHandlerSuccess: function (resp) {
  3528. console.log("上传成功:", resp);
  3529. },
  3530. defaultHandlerError: function (err) {
  3531. console.error("上传错误:", err);
  3532. },
  3533. contentType: function () {
  3534. return false;
  3535. },
  3536. },
  3537. controls: {
  3538. font: {
  3539. list: {
  3540. Arial: "Arial",
  3541. SimSun: "宋体",
  3542. SimHei: "黑体",
  3543. "Microsoft YaHei": "微软雅黑",
  3544. KaiTi: "楷体",
  3545. FangSong: "仿宋",
  3546. "Times New Roman": "Times New Roman",
  3547. "Courier New": "Courier New",
  3548. },
  3549. },
  3550. customLinkButton: {
  3551. name: "link",
  3552. tooltip: "附件",
  3553. exec: function () {
  3554. if (!fjButton.cmsAddUrl || !fjButton.cmsUpdUrl) {
  3555. console.warn("ss-editor 未配置附件按钮地址,忽略附件操作");
  3556. return;
  3557. }
  3558. if (fjid.value == null || fjid.value === "") {
  3559. $.ajax({
  3560. type: "post",
  3561. url: fjButton.cmsAddUrl,
  3562. async: false,
  3563. data: {
  3564. name: "fjid",
  3565. ssNrObjName: "sh",
  3566. ssNrObjId: "",
  3567. },
  3568. success: function (_fjid) {
  3569. console.log("cmsAddUrl success", _fjid);
  3570. fjid.value = _fjid;
  3571. },
  3572. });
  3573. }
  3574. var str =
  3575. "&nrid=T-" +
  3576. fjid.value +
  3577. "&objectId=" +
  3578. fjid.value +
  3579. "&objectName=" +
  3580. fjName +
  3581. "&callback=" +
  3582. (window["fjidCallbackName"] || "");
  3583. console.log("str", str);
  3584. SS.openDialog({
  3585. src: buttonConfig.cmsUpdUrl + str,
  3586. headerTitle: "编辑",
  3587. width: 900,
  3588. high: 664,
  3589. zIndex: 51,
  3590. });
  3591. },
  3592. },
  3593. ...customButtonControls,
  3594. },
  3595. toolbarAdaptive: true,
  3596. // 调试:记录最终按钮配置
  3597. buttons: (() => {
  3598. const finalButtons = appendCustomButtons([
  3599. "fullsize",
  3600. "bold",
  3601. "italic",
  3602. "underline",
  3603. "strikethrough",
  3604. "eraser",
  3605. "|",
  3606. "font",
  3607. "fontsize",
  3608. "brush",
  3609. "paragraph",
  3610. "|",
  3611. "left",
  3612. "center",
  3613. "right",
  3614. "justify",
  3615. "|",
  3616. "ul",
  3617. "ol",
  3618. "indent",
  3619. "outdent",
  3620. "|",
  3621. "image",
  3622. "table",
  3623. "customLinkButton",
  3624. "print",
  3625. "|",
  3626. "undo",
  3627. "redo",
  3628. "find",
  3629. ]);
  3630. console.log("[SsEditor] 最终 buttons 配置:", finalButtons);
  3631. return finalButtons;
  3632. })(),
  3633. buttonsMD: appendCustomButtons([
  3634. "fullsize",
  3635. "bold",
  3636. "italic",
  3637. "underline",
  3638. "strikethrough",
  3639. "eraser",
  3640. "|",
  3641. "font",
  3642. "fontsize",
  3643. "brush",
  3644. "paragraph",
  3645. "|",
  3646. "font",
  3647. "fontsize",
  3648. "|",
  3649. "left",
  3650. "center",
  3651. "right",
  3652. "justify",
  3653. "|",
  3654. "image",
  3655. "customLinkButton",
  3656. "|",
  3657. "dots",
  3658. ]),
  3659. buttonsSM: appendCustomButtons([
  3660. "fullsize",
  3661. "bold",
  3662. "italic",
  3663. "|",
  3664. "image",
  3665. "|",
  3666. "dots",
  3667. ]),
  3668. buttonsXS: appendCustomButtons(["fullsize", "bold", "|", "dots"]),
  3669. sizeLG: 1024,
  3670. sizeMD: 768,
  3671. sizeSM: 576,
  3672. getIcon: function (name, clearName) {
  3673. const iconMap = {
  3674. bold: "editor-icon-bold",
  3675. italic: "editor-icon-italic",
  3676. underline: "editor-icon-underline",
  3677. strikethrough: "editor-icon-strikethrough",
  3678. eraser: "editor-icon-eraser",
  3679. copyformat: "editor-icon-copyformat",
  3680. font: "editor-icon-font",
  3681. fontsize: "editor-icon-fontsize",
  3682. brush: "editor-icon-brush",
  3683. paragraph: "editor-icon-paragraph",
  3684. left: "editor-icon-align-left",
  3685. center: "editor-icon-align-center",
  3686. right: "editor-icon-align-right",
  3687. justify: "editor-icon-align-justify",
  3688. ul: "editor-icon-ul",
  3689. ol: "editor-icon-ol",
  3690. indent: "editor-icon-indent",
  3691. outdent: "editor-icon-outdent",
  3692. image: "editor-icon-image",
  3693. file: "editor-icon-file",
  3694. video: "editor-icon-video",
  3695. table: "editor-icon-table",
  3696. link: "editor-icon-link",
  3697. source: "editor-icon-source",
  3698. eye: "editor-icon-preview",
  3699. fullsize: "editor-icon-fullsize",
  3700. shrink: "editor-icon-fullsize-exit",
  3701. print: "editor-icon-print",
  3702. undo: "editor-icon-undo",
  3703. redo: "editor-icon-redo",
  3704. search: "editor-icon-find",
  3705. selectall: "editor-icon-selectall",
  3706. };
  3707. const customIcon =
  3708. customButtonIconMap[clearName] || customButtonIconMap[name];
  3709. if (customIcon) {
  3710. return renderButtonIcon(customIcon);
  3711. }
  3712. const iconClass = iconMap[clearName] || iconMap[name];
  3713. if (iconClass) {
  3714. return renderButtonIcon(iconClass);
  3715. }
  3716. return null;
  3717. },
  3718. });
  3719. editorRef.value = editor;
  3720. editor.events.on("change", () => {
  3721. const html = editor.value || "";
  3722. editorContent.value = html;
  3723. syncHiddenContentInput(html);
  3724. emit("change", html);
  3725. setTimeout(() => {
  3726. validate();
  3727. }, 50);
  3728. });
  3729. emit("ready", editor);
  3730. if (props.html) {
  3731. setEditorHtml(props.html);
  3732. } else if (props.url) {
  3733. const params = new URLSearchParams();
  3734. if (mode) params.append("mode", mode);
  3735. if (props.modelValue) params.append("path", props.modelValue);
  3736. axios
  3737. .post(props.url, params, {
  3738. headers: {
  3739. "Content-Type": "application/x-www-form-urlencoded",
  3740. },
  3741. })
  3742. .then((response) => {
  3743. if ("timeout" == response.data.statusText) {
  3744. alert("网络超时!");
  3745. return;
  3746. }
  3747. const content = response.data.content;
  3748. if (content != null) {
  3749. setEditorHtml(content);
  3750. }
  3751. const filePath = response.data.path;
  3752. if (filePath) {
  3753. currentModelValue.value = filePath;
  3754. emit("update:modelValue", filePath);
  3755. }
  3756. });
  3757. } else {
  3758. setEditorHtml(props.html);
  3759. }
  3760. });
  3761. watch(
  3762. () => props.html,
  3763. (newValue) => {
  3764. setEditorHtml(newValue);
  3765. }
  3766. );
  3767. watch(
  3768. () => props.modelValue,
  3769. (newValue) => {
  3770. currentModelValue.value = newValue || "";
  3771. }
  3772. );
  3773. watch(
  3774. () => props.mode,
  3775. (newMode) => {
  3776. if (editorRef.value) {
  3777. editorRef.value.setReadOnly(newMode === "play");
  3778. }
  3779. }
  3780. );
  3781. onBeforeUnmount(() => {
  3782. if (editorRef.value) {
  3783. editorRef.value.destruct();
  3784. }
  3785. });
  3786. // 只读模式:打开附件弹窗 by xu 20250402
  3787. const openAttachmentDialog = () => {
  3788. if (!fjButton.cmsAddUrl || !fjButton.cmsUpdUrl) {
  3789. console.warn("ss-editor 未配置附件按钮地址,忽略附件操作");
  3790. return;
  3791. }
  3792. if (fjid.value == null || fjid.value === "") {
  3793. $.ajax({
  3794. type: "post",
  3795. url: fjButton.cmsAddUrl,
  3796. async: false,
  3797. data: {
  3798. name: "fjid",
  3799. ssNrObjName: "sh",
  3800. ssNrObjId: "",
  3801. },
  3802. success: function (_fjid) {
  3803. console.log("cmsAddUrl success", _fjid);
  3804. fjid.value = _fjid;
  3805. },
  3806. });
  3807. }
  3808. var str =
  3809. "&nrid=T-" +
  3810. fjid.value +
  3811. "&objectId=" +
  3812. fjid.value +
  3813. "&objectName=" +
  3814. fjName +
  3815. "&callback=" +
  3816. (window["fjidCallbackName"] || "");
  3817. console.log("str", str);
  3818. SS.openDialog({
  3819. src: fjButton.cmsUpdUrl + str,
  3820. headerTitle: "编辑",
  3821. width: 900,
  3822. high: 664,
  3823. zIndex: 51,
  3824. });
  3825. };
  3826. return () => {
  3827. // 只读模式:不初始化 Jodit,直接渲染 HTML + 附件按钮 by xu 20250402
  3828. if (props.mode === "play") {
  3829. return h("div", { class: "ss-editor-container ss-editor-readonly" }, [
  3830. fjid.value &&
  3831. h("input", {
  3832. type: "hidden",
  3833. name: "fjid",
  3834. value: fjid.value,
  3835. }),
  3836. h("input", {
  3837. type: "hidden",
  3838. name: props.name.replace(/wj$/, "") + "Edit",
  3839. value: editorContent.value,
  3840. }),
  3841. h("input", {
  3842. type: "hidden",
  3843. name: props.name.replace(/wj$/, "") + "wj",
  3844. value: currentModelValue.value,
  3845. }),
  3846. h("input", {
  3847. type: "hidden",
  3848. name: "ueditorpath",
  3849. value: "mswj",
  3850. }),
  3851. // 附件按钮(只读模式下仍显示)
  3852. fjButton.cmsAddUrl && fjButton.cmsUpdUrl &&
  3853. h("div", {
  3854. class: "ss-editor-attach-btn",
  3855. onClick: openAttachmentDialog,
  3856. }, [
  3857. h("span", { class: "editor-icon editor-icon-file" }),
  3858. h("span", { class: "ss-editor-attach-text" }, "附件")
  3859. ]),
  3860. // HTML 内容展示
  3861. h("div", {
  3862. class: "ss-editor-readonly-content",
  3863. innerHTML: editorContent.value,
  3864. }),
  3865. ]);
  3866. }
  3867. // 正常编辑模式:渲染 textarea 供 Jodit 初始化
  3868. return h("div", { class: "ss-editor-container" }, [
  3869. fjid.value &&
  3870. h("input", {
  3871. type: "hidden",
  3872. name: "fjid",
  3873. value: fjid.value,
  3874. }),
  3875. h("input", {
  3876. type: "hidden",
  3877. name: props.name.replace(/wj$/, "") + "Edit",
  3878. value: editorContent.value,
  3879. }),
  3880. h("input", {
  3881. type: "hidden",
  3882. name: props.name.replace(/wj$/, "") + "wj",
  3883. value: currentModelValue.value,
  3884. }),
  3885. h("input", {
  3886. type: "hidden",
  3887. name: "ueditorpath",
  3888. value: props.name.replace(/wj$/, "") + "wj",
  3889. }),
  3890. h("textarea", { id: uniqueId }),
  3891. ]);
  3892. };
  3893. },
  3894. };
  3895. // 弹窗右边图标
  3896. const SsFullStyleHeader = {
  3897. name: "SsFullStyleHeader",
  3898. props: {
  3899. title: {
  3900. type: String,
  3901. default: "标题",
  3902. },
  3903. },
  3904. emits: ["close"],
  3905. setup(props, { emit }) {
  3906. // console.log(props.title)
  3907. const onClose = () => {
  3908. emit("close");
  3909. };
  3910. const SsIcon = resolveComponent("ss-icon");
  3911. return () =>
  3912. h("div", { class: "header-container" }, [
  3913. h("div", { class: "title" }, props.title),
  3914. h("div", { class: "handle-bar" }, [
  3915. h("div", { class: "left-bar" }, [
  3916. h(SsDialogIcon, { class: "dialog-icon-download" }),
  3917. h(SsDialogIcon, { class: "dialog-icon-print" }),
  3918. h(SsDialogIcon, { class: "dialog-icon-setting" }),
  3919. h(SsDialogIcon, { class: "dialog-icon-collect" }),
  3920. h(SsDialogIcon, { class: "dialog-icon-help" }),
  3921. h(SsDialogIcon, { class: "dialog-icon-full-screen" }),
  3922. h(SsDialogIcon, { class: "dialog-icon-lock" }),
  3923. ]),
  3924. h("div", { class: "close-bar", onClick: onClose }, [
  3925. h(SsDialogIcon, { class: "dialog-icon-close" }),
  3926. ]),
  3927. ]),
  3928. ]);
  3929. },
  3930. };
  3931. // ss-dialog弹窗
  3932. const SsDialog = {
  3933. name: "SsDialog",
  3934. props: {
  3935. src: {
  3936. type: String,
  3937. },
  3938. headerTitle: {
  3939. type: String,
  3940. // required: true,
  3941. default: "弹窗",
  3942. },
  3943. width: {
  3944. type: String,
  3945. default: "1400",
  3946. },
  3947. height: {
  3948. type: String,
  3949. default: "600",
  3950. },
  3951. params: {
  3952. type: Object,
  3953. default: () => ({}),
  3954. },
  3955. zIndex: {
  3956. type: Number,
  3957. default: 1000,
  3958. },
  3959. },
  3960. emits: ["close"],
  3961. setup(props, { slots, emit }) {
  3962. // 关闭窗口方法
  3963. const onClose = () => {
  3964. emit("close");
  3965. };
  3966. const showHeader = ref(true);
  3967. const headerVisible = ref(false);
  3968. const popupHieght = ref(props.height);
  3969. // 状态:存储位置信息
  3970. const position = reactive({
  3971. // 页面居中
  3972. x: (window.innerWidth - props.width) / 2,
  3973. y: (window.innerHeight - popupHieght.value) / 2,
  3974. isDragging: false,
  3975. offsetX: 0,
  3976. offsetY: 0,
  3977. });
  3978. // 鼠标按下时设置起始坐标并开始拖拽
  3979. const startDrag = (event) => {
  3980. position.isDragging = true;
  3981. position.offsetX = event.clientX - position.x;
  3982. position.offsetY = event.clientY - position.y;
  3983. };
  3984. // 鼠标移动时更新位置
  3985. const onDrag = (event) => {
  3986. if (position.isDragging) {
  3987. position.x = event.clientX - position.offsetX;
  3988. position.y = event.clientY - position.offsetY;
  3989. }
  3990. };
  3991. // 鼠标放开时结束拖拽
  3992. const endDrag = () => {
  3993. position.isDragging = false;
  3994. };
  3995. // 监听来自 iframe 的消息
  3996. const handleMessage = (event) => {
  3997. // 顶天立地
  3998. if (event.data && typeof event.data.hasScrollBar !== "undefined") {
  3999. if (event.data.hasScrollBar) {
  4000. // console.log(event);
  4001. position.y = 10;
  4002. showHeader.value = false;
  4003. headerVisible.value = true;
  4004. popupHieght.value = window.innerHeight - 20;
  4005. // console.log(popupHieght.value);
  4006. document.querySelector(".body").style.height = "100%";
  4007. document.querySelector(".body").style.paddingTop = "30px";
  4008. document.querySelector(".header-container ").style.position =
  4009. "absolute";
  4010. document.querySelector(".header-container ").style.zIndex = "10";
  4011. }
  4012. }
  4013. };
  4014. // 鼠标移入关闭按钮区域时显示头部
  4015. const onMouseEnterCloseButton = () => {
  4016. headerVisible.value = false;
  4017. };
  4018. // 鼠标移出关闭按钮区域时隐藏头部
  4019. const onMouseLeaveCloseButton = () => {
  4020. headerVisible.value = true;
  4021. };
  4022. // 在组件挂载时添加全局事件监听器
  4023. Vue.onMounted(() => {
  4024. // 如果传过来的高度大于窗口高度,则设置为窗口高度减去20 否则保持传过来的高度
  4025. popupHieght.value =
  4026. popupHieght.value > window.innerHeight
  4027. ? window.innerHeight - 20
  4028. : popupHieght.value;
  4029. const container = document.querySelector(".header-container");
  4030. if (container) {
  4031. container.addEventListener("mousedown", startDrag);
  4032. }
  4033. document.addEventListener("mousemove", onDrag);
  4034. document.addEventListener("mouseup", endDrag);
  4035. window.addEventListener("message", handleMessage);
  4036. });
  4037. // 在组件卸载时移除全局事件监听器
  4038. Vue.onUnmounted(() => {
  4039. document.removeEventListener("mousemove", onDrag);
  4040. document.removeEventListener("mouseup", endDrag);
  4041. window.removeEventListener("message", handleMessage);
  4042. });
  4043. const SsMark = resolveComponent("ss-mark");
  4044. const SsFullStyleHeader = resolveComponent("ss-full-style-header");
  4045. // render函数定义组件结构
  4046. return () =>
  4047. h(
  4048. Teleport,
  4049. { to: "body" }, // 使用 Teleport 将弹窗内容挂载到 body
  4050. h(SsMark, {}, [
  4051. h(
  4052. "div",
  4053. {
  4054. class: "popup-container",
  4055. style: {
  4056. position: "absolute",
  4057. left: `${position.x}px`,
  4058. top: `${position.y}px`,
  4059. width: props.width + "px",
  4060. height: popupHieght.value + "px",
  4061. zIndex: props.zIndex, // 确保弹窗在最上层
  4062. },
  4063. },
  4064. [
  4065. h(SsFullStyleHeader, {
  4066. class: "header",
  4067. title: props.headerTitle,
  4068. onClose: onClose,
  4069. onMousedown: startDrag, // 绑定拖动事件
  4070. onMouseUp: endDrag,
  4071. ...(!showHeader.value && {
  4072. onMouseenter: onMouseEnterCloseButton,
  4073. onMouseleave: onMouseLeaveCloseButton,
  4074. }),
  4075. style: {
  4076. cursor: position.isDragging ? "grabbing" : "grab",
  4077. visibility: headerVisible.value ? "hidden" : "visible",
  4078. },
  4079. }),
  4080. h(
  4081. "div",
  4082. {
  4083. class: "body",
  4084. style: {},
  4085. },
  4086. [
  4087. h("iframe", {
  4088. src: props.src,
  4089. frameborder: 0,
  4090. style: { width: "100%", height: "100%" },
  4091. }),
  4092. ]
  4093. ),
  4094. headerVisible.value &&
  4095. h("div", {
  4096. class: "close-button",
  4097. onMouseenter: onMouseEnterCloseButton,
  4098. onMouseleave: onMouseLeaveCloseButton,
  4099. style: {
  4100. position: "absolute",
  4101. top: "0",
  4102. right: "0",
  4103. // background: 'black',
  4104. width: "60px",
  4105. height: "60px",
  4106. cursor: "pointer",
  4107. },
  4108. }),
  4109. ]
  4110. ),
  4111. ])
  4112. );
  4113. },
  4114. };
  4115. // ss-mark遮罩层
  4116. const SsMark = {
  4117. name: "SsMark",
  4118. setup(props, { slots, emit }) {
  4119. return () =>
  4120. h("div", { class: "dialog-container" }, [
  4121. h("div", { class: "mark-content" }, [
  4122. h("div", { class: "dialog-contianer" }, [
  4123. slots.default ? slots.default() : "",
  4124. ]),
  4125. ]),
  4126. ]);
  4127. },
  4128. };
  4129. // ss-bottom-button 底部按钮
  4130. // 修改支持更多按钮 by xu 20251211
  4131. const SsBottomButton = {
  4132. name: "SsBottomButton",
  4133. props: {
  4134. text: {
  4135. type: String,
  4136. required: false,
  4137. },
  4138. type: {
  4139. type: String,
  4140. default: "button",
  4141. },
  4142. iconClass: {
  4143. type: String,
  4144. },
  4145. class: {
  4146. type: String,
  4147. default: "",
  4148. },
  4149. onclick: {
  4150. type: [Function, String],
  4151. default: null,
  4152. },
  4153. // 修改支持更多按钮 by xu 20251211
  4154. more: {
  4155. type: [Boolean, String],
  4156. default: false,
  4157. },
  4158. },
  4159. setup(props, { emit }) {
  4160. const SsBottomDivIcon = Vue.resolveComponent("ss-bottom-div-icon");
  4161. const showDropdown = Vue.ref(false);
  4162. // 修改支持更多按钮 by xu 20251211
  4163. const moreKey = Vue.computed(() => {
  4164. const val = props.more;
  4165. if (val === false || val === null || typeof val === "undefined") {
  4166. return null;
  4167. }
  4168. if (val === true || val === "" || val === "true") {
  4169. return "moreChg";
  4170. }
  4171. return val;
  4172. });
  4173. // 从配置中读取按钮信息和下拉选项
  4174. const config = Vue.computed(() => {
  4175. if (
  4176. moreKey.value &&
  4177. window.ss &&
  4178. window.ss.dom &&
  4179. window.ss.dom.btnElemConfig
  4180. ) {
  4181. return window.ss.dom.btnElemConfig[moreKey.value] || {};
  4182. }
  4183. return {};
  4184. });
  4185. const buttonText = Vue.computed(() => {
  4186. return props.text || config.value.desc || "";
  4187. });
  4188. const dropOptions = Vue.computed(() => {
  4189. return config.value.dropOptions || [];
  4190. });
  4191. const hasDropdown = Vue.computed(() => {
  4192. return dropOptions.value.length > 0;
  4193. });
  4194. const handleMouseEnter = () => {
  4195. if (hasDropdown.value) {
  4196. showDropdown.value = true;
  4197. }
  4198. };
  4199. const handleMouseLeave = () => {
  4200. showDropdown.value = false;
  4201. };
  4202. const handleDropItemClick = (option) => {
  4203. if (option.callback && typeof option.callback === "function") {
  4204. option.callback();
  4205. }
  4206. showDropdown.value = false;
  4207. };
  4208. return () =>
  4209. h(
  4210. "div",
  4211. {
  4212. class: "ss-bottom-button-wrapper",
  4213. onMouseenter: handleMouseEnter,
  4214. onMouseleave: handleMouseLeave,
  4215. },
  4216. [
  4217. h(
  4218. "button",
  4219. {
  4220. class: props.class,
  4221. onClick: (e) => {
  4222. e.stopPropagation();
  4223. emit("click", e);
  4224. if (props.onclick) {
  4225. // 如果是函数直接调用
  4226. if (typeof props.onclick === "function") {
  4227. props.onclick(e);
  4228. } else if (typeof props.onclick === "string") {
  4229. // 如果是字符串,使用直接的方法执行
  4230. // 临时存储按钮元素到全局变量
  4231. window.__ss_current_button = e.currentTarget;
  4232. // 直接执行代码,使用eval以保留原始上下文
  4233. try {
  4234. eval(props.onclick);
  4235. } finally {
  4236. // 清理全局变量
  4237. delete window.__ss_current_button;
  4238. }
  4239. }
  4240. }
  4241. },
  4242. type: props.type,
  4243. },
  4244. [
  4245. h("span", null, [
  4246. h(SsBottomDivIcon, {
  4247. class: props.iconClass,
  4248. }),
  4249. ]),
  4250. h("span", null, buttonText.value),
  4251. ]
  4252. ),
  4253. // 渲染下拉菜单
  4254. hasDropdown.value && showDropdown.value
  4255. ? h(
  4256. "div",
  4257. {
  4258. class: "ss-bottom-button-dropdown",
  4259. },
  4260. dropOptions.value.map((option) =>
  4261. h(
  4262. "div",
  4263. {
  4264. class: "ss-bottom-button-dropdown-item",
  4265. onClick: (e) => {
  4266. e.stopPropagation();
  4267. handleDropItemClick(option);
  4268. },
  4269. },
  4270. option.desc
  4271. )
  4272. )
  4273. )
  4274. : null,
  4275. ]
  4276. );
  4277. },
  4278. };
  4279. // ss-search搜索框
  4280. const SsSearch = {
  4281. name: "SsSearch",
  4282. props: {
  4283. theme: {
  4284. type: String,
  4285. default: "light",
  4286. validator: function (value) {
  4287. return ["dark", "light"].includes(value);
  4288. },
  4289. },
  4290. placeholder: {
  4291. type: String,
  4292. default: "请输入搜索条件",
  4293. },
  4294. },
  4295. setup(props, { emit }) {
  4296. const onClick = () => {
  4297. console.log("Search clicked");
  4298. emit("click");
  4299. };
  4300. const SsIcon = Vue.resolveComponent("ss-icon");
  4301. return () =>
  4302. Vue.h(
  4303. "div",
  4304. {
  4305. class: ["search-container", props.theme],
  4306. onClick: onClick,
  4307. },
  4308. [
  4309. Vue.h("input", {
  4310. placeholder: props.placeholder,
  4311. disabled: true,
  4312. }),
  4313. Vue.h(SsIcon, {
  4314. name: "search-result",
  4315. size: "20px",
  4316. }),
  4317. ]
  4318. );
  4319. },
  4320. };
  4321. // ss-cart-item 菜单页面的卡片 左右结构
  4322. const SsCartItem = {
  4323. name: "SsCartItem",
  4324. props: {
  4325. active: Boolean,
  4326. item: {
  4327. type: Object,
  4328. default: () => ({
  4329. thumb: "images/example/project-img.png",
  4330. title: "广州(国际)科技成果转化天河基地专",
  4331. description: "佳能中国广州分公司",
  4332. all: 50,
  4333. finish: 5,
  4334. }),
  4335. },
  4336. },
  4337. setup(props, { emit }) {
  4338. const item = props.item;
  4339. const itemWidth = Vue.computed(() => {
  4340. const containerWidth =
  4341. document.body.clientWidth || document.body.scrollWidth - 520;
  4342. const halfWidth = containerWidth / 2;
  4343. if (halfWidth < 480) {
  4344. return Math.min(containerWidth, 702) + "px";
  4345. } else {
  4346. return Math.min(halfWidth, 702) + "px";
  4347. }
  4348. });
  4349. const onItemClick = (e) => {
  4350. emit("click", e);
  4351. };
  4352. return {
  4353. item,
  4354. itemWidth,
  4355. onItemClick,
  4356. };
  4357. },
  4358. render() {
  4359. const SsIcon = Vue.resolveComponent("ss-icon");
  4360. return Vue.h(
  4361. "div",
  4362. {
  4363. class: { "item-container": true, active: this.active },
  4364. onClick: this.onItemClick,
  4365. style: { width: this.itemWidth },
  4366. },
  4367. [
  4368. Vue.h("div", { class: "header" }, [
  4369. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  4370. ]),
  4371. Vue.h("div", { class: "body" }, [
  4372. Vue.h("div", { class: "left" }, [
  4373. Vue.h("img", {
  4374. src: this.item.thumb,
  4375. alt: "Thumbnail",
  4376. class: "imgUnHandle",
  4377. style: { "object-fit": "cover", width: "100%", height: "100%" },
  4378. }),
  4379. ]),
  4380. Vue.h("div", { class: "right" }, [
  4381. Vue.h("div", { class: "title" }, this.item.title),
  4382. Vue.h("div", { class: "desc" }, this.item.description),
  4383. Vue.h("div", { class: "progress" }, [
  4384. Vue.h(
  4385. "div",
  4386. {
  4387. style: {
  4388. width: `${(this.item.finish / this.item.all) * 100}%`,
  4389. },
  4390. },
  4391. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  4392. ),
  4393. ]),
  4394. ]),
  4395. ]),
  4396. ]
  4397. );
  4398. },
  4399. };
  4400. // ss-cart-item2 菜单页面的卡片 上下结构
  4401. const SsCartItem2 = {
  4402. name: "SsCartItem2",
  4403. props: {
  4404. active: Boolean,
  4405. item: {
  4406. type: Object,
  4407. default: () => ({
  4408. thumb: "images/example/project-img.png",
  4409. title: "广州(国际)科技成果转化天河基地专",
  4410. description: "佳能中国广州分公司",
  4411. all: 50,
  4412. finish: 5,
  4413. }),
  4414. },
  4415. },
  4416. setup(props, { emit }) {
  4417. const item = props.item;
  4418. const itemWidth = Vue.computed(() => {
  4419. const containerWidth =
  4420. document.body.clientWidth || document.body.scrollWidth - 520;
  4421. const halfWidth = containerWidth / 2;
  4422. if (halfWidth < 480) {
  4423. return Math.min(containerWidth, 702) + "px";
  4424. } else {
  4425. return Math.min(halfWidth, 702) + "px";
  4426. }
  4427. });
  4428. const onItemClick = (e) => {
  4429. emit("click", e);
  4430. };
  4431. return {
  4432. item,
  4433. itemWidth,
  4434. onItemClick,
  4435. };
  4436. },
  4437. render() {
  4438. const SsIcon = Vue.resolveComponent("ss-icon");
  4439. return Vue.h(
  4440. "div",
  4441. {
  4442. class: { "item-container2": true, active: this.active },
  4443. onClick: this.onItemClick,
  4444. style: { width: this.itemWidth },
  4445. },
  4446. [
  4447. Vue.h("div", { class: "action-bar" }, [
  4448. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  4449. ]),
  4450. Vue.h("div", { class: "header" }, [
  4451. Vue.h("div", { class: "title" }, `${this.item.title}`),
  4452. ]),
  4453. Vue.h("div", { class: "body" }, [
  4454. Vue.h("div", { class: "left" }, [
  4455. Vue.h("img", {
  4456. src: this.item.thumb,
  4457. alt: "Thumbnail",
  4458. class: "imgUnHandle",
  4459. style: { "object-fit": "cover", width: "100%", height: "100%" },
  4460. }),
  4461. ]),
  4462. Vue.h("div", { class: "right" }, [
  4463. Vue.h("div", { class: "content" }, this.item.description),
  4464. Vue.h("div", { class: "tip" }, [
  4465. Vue.h("div", { class: "progress" }, [
  4466. Vue.h(
  4467. "div",
  4468. {
  4469. style: {
  4470. width: `${(this.item.finish / this.item.all) * 100}%`,
  4471. },
  4472. },
  4473. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  4474. ),
  4475. ]),
  4476. ]),
  4477. ]),
  4478. ]),
  4479. ]
  4480. );
  4481. },
  4482. };
  4483. /**
  4484. * SsListCard - 列表卡片组件
  4485. *
  4486. * @description 用于显示列表项的卡片组件,支持缩略图、标签、状态、操作按钮和选择功能
  4487. *
  4488. * @prop {Object} item - 卡片数据对象
  4489. * @prop {String} item.title - 卡片标题
  4490. * @prop {String} [item.thumb] - 缩略图 URL(可选)
  4491. * @prop {String} [item.thumbType] - 缩略图类型:'thumbnail'(缩略图)或默认(证件照)
  4492. * @prop {String} [item.status] - 卡片状态:'available'(可用-绿色)、'unavailable'(不可用-黄色)、'disabled'(禁用-红色)
  4493. * @prop {Array} item.tags - 标签数组,格式:[{键: 值}, ...]
  4494. * @prop {Function} item.onclick - 点击卡片的回调函数
  4495. * @prop {Array} [item.buttons] - 操作按钮数组(可选),显示在右上角齿轮
  4496. * @prop {Array} [item.statusIcons] - 状态图标数组(可选),显示在右上角,格式:[{class: '图标类名', title: '提示文字'}, ...]
  4497. *
  4498. * @example
  4499. * // 基础用法
  4500. * const item = {
  4501. * title: "卡片标题",
  4502. * tags: [
  4503. * { 类型: '文档' },
  4504. * { 状态: '进行中' }
  4505. * ],
  4506. * onclick: () => console.log('点击了卡片')
  4507. * };
  4508. *
  4509. * @example
  4510. * // 带缩略图和状态
  4511. * const item = {
  4512. * title: "场地预定",
  4513. * thumbType: 'thumbnail',
  4514. * thumb: "https://example.com/image.jpg",
  4515. * status: "available", // 绿色背景
  4516. * tags: [{ 容量: '50人' }],
  4517. * onclick: () => {}
  4518. * };
  4519. *
  4520. * @example
  4521. * // 带操作按钮和状态图标
  4522. * const item = {
  4523. * title: "会议室A",
  4524. * tags: [{ 楼层: '3F' }],
  4525. * onclick: () => {},
  4526. * // 右上角操作按钮(齿轮)
  4527. * buttons: [{
  4528. * class: 'cart-list-setting',
  4529. * title: '编辑',
  4530. * onclick: () => console.log('编辑')
  4531. * }],
  4532. * // 右上角状态图标(在齿轮右边)
  4533. * statusIcons: [{
  4534. * class: 'icon-emoji',
  4535. * title: '清洁中'
  4536. * }]
  4537. * };
  4538. *
  4539. * @features
  4540. * - 卡片选择:鼠标悬停右下角显示选择角标,点击切换选中状态,选中后显示底部深灰色线条
  4541. * - 状态颜色:根据 status 字段显示不同背景色(可用/不可用/禁用)
  4542. * - 图片类型:支持证件照(73×100px)和缩略图(180×100px)两种尺寸
  4543. * - 操作按钮:右上角齿轮,hover 显示,支持多个按钮下拉菜单
  4544. * - 状态图标:右上角显示状态图标,齿轮会根据图标数量自动左移
  4545. *
  4546. * @author xu
  4547. * @date 20260105
  4548. */
  4549. // 组件文档补全(JSDoc) by xu 20260108
  4550. /**
  4551. * SsListCard(左侧对象卡片)
  4552. *
  4553. * 用途:
  4554. * - 渲染左侧卡片(标题 + tags)
  4555. * - 右下角“角标”用于选中/取消选中(不会触发卡片 click)
  4556. *
  4557. * 调用示例:
  4558. * ```html
  4559. * <ss-list-card :item="item" @toggle-select="handleToggleSelect" @click="openDetail"></ss-list-card>
  4560. * ```
  4561. *
  4562. * Props:
  4563. * - `item`:卡片数据对象(建议含 `id/title/tags[]`;内部会读写 `item._ssSelected` 作为选中态)
  4564. *
  4565. * Emits:
  4566. * - `toggle-select`:点击角标触发,参数 `{ item, selected }`
  4567. * - `click`:点击卡片主体触发(用于打开详情等)
  4568. */
  4569. const SsListCard = {
  4570. name: "SsListCard",
  4571. props: {
  4572. ssObjName: { type: String, default: "" }, // 功能:业务对象名(用于默认缩略图 icon) by xu 20260109
  4573. cardClickAction: { type: String, default: "view" }, // 功能:卡片主体点击动作(view=查看;single=单选互斥) by xu 20260109
  4574. item: {
  4575. type: Object,
  4576. required: true,
  4577. },
  4578. },
  4579. emits: ["click", "change", "toggle-select"],
  4580. setup(props, { emit }) {
  4581. const item = props.item;
  4582. // 移除 itemWidth 计算属性,不再需要 by xu 20260105
  4583. // 判断卡片类型 by xu 20260105
  4584. const cardType = Vue.computed(() => {
  4585. // 支持“无图但保留缩略图占位”(同一业务列表图片形态一致) by xu 20260109
  4586. if (!item.thumb && !item.thumbType) return ""; // 业务列表“无图”形态
  4587. // 根据 thumbType 字段判断,如果没有则默认为证件照
  4588. return item.thumbType === "thumbnail" ? "card-thumbnail" : "card-photo";
  4589. });
  4590. // 判断状态类型 - 场地预定状态 by xu 20260105
  4591. const statusClass = Vue.computed(() => {
  4592. if (!item.status) return ""; // 无状态,默认白色
  4593. // 映射状态值到 CSS 类名
  4594. const statusMap = {
  4595. available: "status-available",
  4596. unavailable: "status-unavailable",
  4597. disabled: "status-disabled",
  4598. };
  4599. return statusMap[item.status] || "";
  4600. });
  4601. const onItemClick = (e) => {
  4602. // 清除所有类型卡片的 active 状态(卡片主体点击仅做 active 高亮) by xu 20260109
  4603. const allListCards = document.querySelectorAll(
  4604. ".knowledge-item-container"
  4605. );
  4606. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  4607. allListCards.forEach((card) => card.classList.remove("active"));
  4608. allFolderCards.forEach((card) => card.classList.remove("active"));
  4609. // 设置当前项的 active 状态
  4610. e.currentTarget.classList.add("active");
  4611. // 卡片主体点击动作由页面级配置控制 by xu 20260109
  4612. if (props.cardClickAction === "view") {
  4613. props.item.onclick?.();
  4614. // 通知父级:卡片点击(查看) by xu 20260109
  4615. emit("click", props.item);
  4616. }
  4617. };
  4618. const onItemChange = (e, icon, index) => {
  4619. e.stopPropagation(); // 阻止事件冒泡到卡片
  4620. props.item.buttons[0].onclick();
  4621. // emit("change", { item: props.item, icon, index });
  4622. };
  4623. return {
  4624. item,
  4625. cardType,
  4626. statusClass,
  4627. onItemClick,
  4628. onItemChange,
  4629. };
  4630. },
  4631. data() {
  4632. return {
  4633. showButtons: false,
  4634. selected: false, // 选择状态 by xu 20260105
  4635. showTextPopover: false, // 功能:右侧文字区 hover 展示全量 by xu 20260108
  4636. textPopoverType: "", // second-summary / second-tags / third / third-full by xu 20260108
  4637. textPopoverBottom: 0, // 功能:popover 从当前省略行位置向上展开 by xu 20260108
  4638. hideTextPopoverTimer: null, // 功能:鼠标从省略行移到浮层的缓冲 by xu 20260108
  4639. textPopoverPayload: null, // { kind, text?, lines? } by xu 20260108
  4640. ellipsisVisible: {
  4641. // 功能:只在真实出现 ... 时才显示命中区/允许 goheight by xu 20260109
  4642. secondSummary: false,
  4643. secondTags: false,
  4644. third: false,
  4645. thirdFull: false,
  4646. },
  4647. };
  4648. },
  4649. methods: {
  4650. __allowSelect() {
  4651. // 功能说明:无 rbarObj 时禁用选中能力(隐藏右下角勾选并禁止 toggle) by xu 20260122
  4652. try {
  4653. if (this?.$root && this.$root.hasObjPanel === false) return false;
  4654. if (
  4655. typeof window !== "undefined" &&
  4656. window.__objListVm &&
  4657. window.__objListVm.hasObjPanel === false
  4658. )
  4659. return false;
  4660. } catch (_) {}
  4661. return true;
  4662. },
  4663. // 切换选择状态(对外 emit,支持方案A父级 state 中转) by xu 20260106
  4664. toggleSelect(e) {
  4665. e.stopPropagation();
  4666. if (!this.__allowSelect()) return; // 功能说明:无 rbarObj 时禁止选中 by xu 20260122
  4667. // 使用 item 上的状态,便于父级/右侧边栏反向同步 by xu 20260106
  4668. this.item._ssSelected = !this.item?._ssSelected;
  4669. this.$emit("toggle-select", {
  4670. item: this.item,
  4671. selected: !!this.item?._ssSelected,
  4672. });
  4673. },
  4674. // 卡片主体点击=单选互斥:只有“本次切到选中”才清理其他选中 by xu 20260109
  4675. toggleSelectExclusive(e) {
  4676. e?.stopPropagation?.();
  4677. if (!this.__allowSelect()) return; // 功能说明:无 rbarObj 时禁止选中 by xu 20260122
  4678. this.item._ssSelected = !this.item?._ssSelected;
  4679. const selected = !!this.item?._ssSelected;
  4680. this.$emit("toggle-select", {
  4681. item: this.item,
  4682. selected,
  4683. exclusive: true,
  4684. });
  4685. },
  4686. // 功能:无缩略图时,用业务对象 icon 做默认图(ss-icon + icon-obj-xx) by xu 20260109
  4687. getBizThumbIconClass() {
  4688. const name = String(
  4689. this.ssObjName ||
  4690. this.item?.ssObjName ||
  4691. this.$root?.ssObjName ||
  4692. window?.ss?.dom?.ssObjName ||
  4693. ""
  4694. ).trim();
  4695. if (!name) return "";
  4696. return `icon-obj-${name}`;
  4697. },
  4698. // 功能:构造右侧文字区 4 行(摘要/类目或标签/对象号) by xu 20260108
  4699. buildRightTextLines() {
  4700. const item = this.item || {};
  4701. const summary = String(item?.desc ?? "").trim(); // 后端字段后续映射 by xu 20260108
  4702. const objNum = String(item?.objNum ?? "").trim(); // 后端字段后续映射 by xu 20260108
  4703. const categoryArr = Array.isArray(item?.category) ? item.category : [];
  4704. const tagsArr = Array.isArray(item?.tags) ? item.tags : [];
  4705. const hasTags = tagsArr.length > 0;
  4706. const hasCategory = categoryArr.length > 0;
  4707. // 第二部分(L1-L3):摘要优先,其次物品参数 by xu 20260108
  4708. const secondKind = summary ? "summary" : hasTags ? "tags" : "";
  4709. const hasSecond = !!secondKind;
  4710. // 第三部分(L4):对象号优先,其次类目 by xu 20260108
  4711. const thirdKind = objNum ? "objNum" : hasCategory ? "category" : "";
  4712. const hasThird = !!thirdKind;
  4713. const thirdFull = !hasSecond && hasThird; // 第二部分为空则第三部分占满 4 行 by xu 20260108
  4714. const secondFull = hasSecond && !hasThird && secondKind === "tags"; // 仅标签时占满 4 行(不留空行) by xu 20260109
  4715. const toValueText = (obj) => {
  4716. // 功能说明:类目/物品参数回显展示 key: value(否则只显示值看不懂) by xu 20260114
  4717. const [k, v] = Object.entries(obj || {})[0] || ["", ""];
  4718. const key = k !== undefined && k !== null ? String(k).trim() : "";
  4719. const val = v !== undefined && v !== null ? String(v).trim() : "";
  4720. if (key && val) return `${key}:${val}`;
  4721. if (val) return val;
  4722. if (key) return key;
  4723. return "";
  4724. };
  4725. const toLineList = (arr) =>
  4726. (arr || [])
  4727. .map(toValueText)
  4728. .map((s) => String(s ?? "").trim())
  4729. .filter(Boolean);
  4730. const flat = (arr) => toLineList(arr).join(" ");
  4731. // 第二部分 tags:默认 3 行;仅标签时占满 4 行(避免底部空一行) by xu 20260109
  4732. const secondTagsMaxLines = secondFull ? 4 : 3;
  4733. const secondTagsLinesFull = toLineList(tagsArr);
  4734. const secondTagsHead = secondTagsLinesFull.slice(
  4735. 0,
  4736. Math.max(0, secondTagsMaxLines - 1)
  4737. );
  4738. const secondTagsTail = secondTagsLinesFull.slice(
  4739. Math.max(0, secondTagsMaxLines - 1)
  4740. );
  4741. const secondTagsLast =
  4742. secondTagsTail.length <= 1
  4743. ? secondTagsTail[0] || ""
  4744. : secondTagsTail.join(" "); // 功能:最后一行平铺剩余 by xu 20260108
  4745. // 第三部分类目:卡片上串成一行;goheight 展开时一条一行 by xu 20260109
  4746. const categoryLinesFull = toLineList(categoryArr);
  4747. const categoryLine = categoryLinesFull.join(" ");
  4748. const thirdText =
  4749. thirdKind === "objNum"
  4750. ? objNum
  4751. : thirdKind === "category"
  4752. ? categoryLine
  4753. : "";
  4754. return {
  4755. secondKind,
  4756. thirdKind,
  4757. hasSecond,
  4758. hasThird,
  4759. thirdFull,
  4760. secondFull,
  4761. summary,
  4762. secondTagsMaxLines,
  4763. secondTagsHead,
  4764. secondTagsLast,
  4765. secondTagsLinesFull,
  4766. objNum,
  4767. categoryLine,
  4768. categoryLinesFull,
  4769. thirdText,
  4770. };
  4771. },
  4772. measureTextOverflowByLines(text, maxLines, width) {
  4773. const w = Number(width) || 0;
  4774. if (!w || !text) return false;
  4775. const probe = document.createElement("div");
  4776. probe.style.position = "fixed";
  4777. probe.style.left = "-99999px";
  4778. probe.style.top = "0";
  4779. probe.style.width = w + "px";
  4780. probe.style.fontSize = "18px";
  4781. probe.style.lineHeight = "24px";
  4782. probe.style.whiteSpace = "normal";
  4783. probe.style.wordBreak = "break-word";
  4784. probe.style.visibility = "hidden";
  4785. probe.textContent = text;
  4786. document.body.appendChild(probe);
  4787. const h = probe.getBoundingClientRect().height || 0;
  4788. document.body.removeChild(probe);
  4789. return h > maxLines * 24 + 1;
  4790. },
  4791. measureSingleLineOverflow(text, width) {
  4792. const w = Number(width) || 0;
  4793. if (!w || !text) return false;
  4794. const probe = document.createElement("span");
  4795. probe.style.position = "fixed";
  4796. probe.style.left = "-99999px";
  4797. probe.style.top = "0";
  4798. probe.style.display = "inline-block";
  4799. probe.style.maxWidth = w + "px";
  4800. probe.style.fontSize = "18px";
  4801. probe.style.lineHeight = "24px";
  4802. probe.style.whiteSpace = "nowrap";
  4803. probe.style.visibility = "hidden";
  4804. probe.textContent = text;
  4805. document.body.appendChild(probe);
  4806. const overflow =
  4807. (probe.scrollWidth || 0) > (probe.clientWidth || w) + 1;
  4808. document.body.removeChild(probe);
  4809. return overflow;
  4810. },
  4811. // 功能:根据当前卡片宽度刷新「是否出现 ...」状态(用于控制命中区显示) by xu 20260109
  4812. refreshEllipsisVisible() {
  4813. try {
  4814. const right = this.$el?.querySelector?.(".right");
  4815. const rawWidth =
  4816. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  4817. const width = Math.max(0, Math.round(rawWidth)); // 修复:内容区不再使用 padding-right 预留,测量按真实宽度 by xu 20260109
  4818. const model = this.buildRightTextLines();
  4819. const next = {
  4820. secondSummary: false,
  4821. secondTags: false,
  4822. third: false,
  4823. thirdFull: false,
  4824. };
  4825. if (model.secondKind === "summary" && model.summary) {
  4826. next.secondSummary = this.measureTextOverflowByLines(
  4827. model.summary,
  4828. 3,
  4829. width
  4830. );
  4831. }
  4832. if (model.secondKind === "tags") {
  4833. // 功能说明:tags 采用「最后一行平铺剩余」策略,是否出现 ... 仅取决于最后一行是否溢出(数量多但平铺放得下不算溢出) by xu 20260114
  4834. next.secondTags = this.measureSingleLineOverflow(
  4835. model.secondTagsLast,
  4836. width
  4837. );
  4838. }
  4839. if (model.hasThird && !model.thirdFull) {
  4840. next.third = this.measureSingleLineOverflow(model.thirdText, width);
  4841. }
  4842. if (model.hasThird && model.thirdFull) {
  4843. next.thirdFull = this.measureTextOverflowByLines(
  4844. model.thirdText,
  4845. 4,
  4846. width
  4847. );
  4848. }
  4849. const prev = this.ellipsisVisible || {};
  4850. const changed =
  4851. prev.secondSummary !== next.secondSummary ||
  4852. prev.secondTags !== next.secondTags ||
  4853. prev.third !== next.third ||
  4854. prev.thirdFull !== next.thirdFull;
  4855. if (changed) this.ellipsisVisible = next;
  4856. } catch (e) {
  4857. // ignore by xu 20260109
  4858. }
  4859. },
  4860. showTextPopoverFor(el, kind) {
  4861. // 调试开关:window.__SS_LISTCARD_DEBUG__ = true 时打印 hover/溢出判断日志 by xu 20260108
  4862. const debug =
  4863. typeof window !== "undefined" && !!window.__SS_LISTCARD_DEBUG__;
  4864. if (debug) {
  4865. console.log("[SsListCard] ellipsis hover", {
  4866. kind,
  4867. el: el?.className,
  4868. });
  4869. }
  4870. const model = this.buildRightTextLines();
  4871. const lineEl = el?.closest?.(".ss-card-text__line") || el;
  4872. const right = lineEl?.closest?.(".right") || el?.closest?.(".right");
  4873. const rawWidth =
  4874. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  4875. const width = Math.max(0, Math.round(rawWidth)); // 修复:内容区不再预留 padding-right,测量按真实宽度 by xu 20260109
  4876. const textEl =
  4877. kind === "second-summary"
  4878. ? lineEl?.querySelector?.(".ss-card-text__secondSummary")
  4879. : kind === "second-tags"
  4880. ? lineEl?.querySelector?.(".ss-card-text__tagLineLast")
  4881. : kind === "third"
  4882. ? lineEl?.querySelector?.(".ss-card-text__thirdLine")
  4883. : lineEl?.querySelector?.(".ss-card-text__thirdFull");
  4884. let payload = null;
  4885. // 仅当真实会出现 ... 时才允许 goheight(避免“没超出也能出 goheight”) by xu 20260109
  4886. const overflowed =
  4887. kind === "second-summary"
  4888. ? this.measureTextOverflowByLines(model.summary, 3, width)
  4889. : kind === "second-tags"
  4890. ? this.measureSingleLineOverflow(model.secondTagsLast, width) // 功能说明:同 refreshEllipsisVisible,tags 仅看最后一行是否溢出 by xu 20260114
  4891. : kind === "third"
  4892. ? this.measureSingleLineOverflow(model.thirdText, width)
  4893. : this.measureTextOverflowByLines(model.thirdText, 4, width);
  4894. if (!overflowed) return;
  4895. if (kind === "second-summary") {
  4896. if (model.summary) payload = { kind, text: model.summary };
  4897. } else if (kind === "second-tags") {
  4898. if (
  4899. Array.isArray(model.secondTagsLinesFull) &&
  4900. model.secondTagsLinesFull.length
  4901. ) {
  4902. payload = { kind, lines: model.secondTagsLinesFull };
  4903. }
  4904. } else if (kind === "third") {
  4905. if (
  4906. model.thirdKind === "category" &&
  4907. Array.isArray(model.categoryLinesFull) &&
  4908. model.categoryLinesFull.length
  4909. ) {
  4910. payload = { kind, lines: model.categoryLinesFull }; // 功能:类目展开一条一行 by xu 20260109
  4911. } else if (model.thirdText) {
  4912. payload = { kind, text: model.thirdText };
  4913. }
  4914. } else if (kind === "third-full") {
  4915. if (
  4916. model.thirdKind === "category" &&
  4917. Array.isArray(model.categoryLinesFull) &&
  4918. model.categoryLinesFull.length
  4919. ) {
  4920. payload = { kind, lines: model.categoryLinesFull }; // 功能:类目占满模式展开一条一行 by xu 20260109
  4921. } else if (model.thirdText) {
  4922. payload = { kind, text: model.thirdText };
  4923. }
  4924. }
  4925. if (debug) {
  4926. console.log("[SsListCard] ellipsis decide", {
  4927. kind,
  4928. rawWidth: Math.round(rawWidth),
  4929. width,
  4930. hasPayload: !!payload,
  4931. textEl: textEl?.className,
  4932. textClient: textEl
  4933. ? {
  4934. cw: textEl.clientWidth,
  4935. ch: textEl.clientHeight,
  4936. sw: textEl.scrollWidth,
  4937. sh: textEl.scrollHeight,
  4938. }
  4939. : null,
  4940. });
  4941. }
  4942. if (!payload) return;
  4943. this.clearHideTextPopoverTimer();
  4944. const container = lineEl?.closest?.(".right");
  4945. const containerRect = container?.getBoundingClientRect?.();
  4946. const lineRect = lineEl?.getBoundingClientRect?.();
  4947. if (containerRect && lineRect) {
  4948. const bottom = Math.max(
  4949. 0,
  4950. Math.round(containerRect.bottom - lineRect.bottom)
  4951. );
  4952. this.textPopoverBottom = bottom;
  4953. } else {
  4954. this.textPopoverBottom = 0;
  4955. }
  4956. this.textPopoverPayload = payload;
  4957. this.textPopoverType = kind;
  4958. this.showTextPopover = true;
  4959. if (debug) console.log("[SsListCard] goheight show", payload);
  4960. },
  4961. isOverflowing(el) {
  4962. if (!el) return false;
  4963. // 单行/多行省略统一判断:scroll 尺寸大于 client 尺寸即认为有 ... by xu 20260108
  4964. return (
  4965. (el.scrollWidth &&
  4966. el.clientWidth &&
  4967. el.scrollWidth > el.clientWidth + 1) ||
  4968. (el.scrollHeight &&
  4969. el.clientHeight &&
  4970. el.scrollHeight > el.clientHeight + 1)
  4971. );
  4972. },
  4973. isSummaryOverflowing(el) {
  4974. if (!el) return false;
  4975. // -webkit-line-clamp 场景下 scrollHeight 不稳定,改用“无 clamp 的离屏测量”判断是否超过 2 行 by xu 20260108
  4976. const text = String(this.item?.desc ?? "").trim();
  4977. if (!text) return false;
  4978. const rect = el.getBoundingClientRect?.();
  4979. const width = rect?.width || el.clientWidth || 0;
  4980. if (!width) return false;
  4981. const probe = document.createElement("div");
  4982. probe.style.position = "fixed";
  4983. probe.style.left = "-99999px";
  4984. probe.style.top = "0";
  4985. probe.style.width = width + "px";
  4986. probe.style.fontSize = "18px";
  4987. probe.style.lineHeight = "24px";
  4988. probe.style.whiteSpace = "normal";
  4989. probe.style.wordBreak = "break-word";
  4990. probe.style.visibility = "hidden";
  4991. probe.textContent = text;
  4992. document.body.appendChild(probe);
  4993. const h = probe.getBoundingClientRect().height || 0;
  4994. document.body.removeChild(probe);
  4995. return h > 48 + 1;
  4996. },
  4997. clearHideTextPopoverTimer() {
  4998. if (this.hideTextPopoverTimer) {
  4999. clearTimeout(this.hideTextPopoverTimer);
  5000. this.hideTextPopoverTimer = null;
  5001. }
  5002. },
  5003. // 修复 goheight hover 无响应:移除重复方法覆盖,统一使用上面的 showTextPopoverFor(el, kind) by xu 20260109
  5004. hideTextPopoverLater() {
  5005. this.clearHideTextPopoverTimer();
  5006. this.hideTextPopoverTimer = setTimeout(() => {
  5007. this.showTextPopover = false;
  5008. this.textPopoverType = "";
  5009. this.textPopoverPayload = null;
  5010. }, 120);
  5011. },
  5012. hideTextPopover() {
  5013. this.clearHideTextPopoverTimer();
  5014. this.showTextPopover = false;
  5015. this.textPopoverType = "";
  5016. this.textPopoverPayload = null;
  5017. },
  5018. // 功能:新需求下不在 updated 内做测量,避免死循环 by xu 20260108
  5019. },
  5020. mounted() {
  5021. // 无需在 mounted/updated 里做 overflow 测量(避免死循环),只在 hover 触发时判断 by xu 20260108
  5022. // 仅用于控制“...命中区是否显示”,不会触发循环更新 by xu 20260109
  5023. this.$nextTick?.(() => {
  5024. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5025. });
  5026. this.__ssListCardResizeHandler = () => this.refreshEllipsisVisible?.(); // 功能:窗口变化时刷新 ... 显示 by xu 20260109
  5027. window.addEventListener?.("resize", this.__ssListCardResizeHandler);
  5028. },
  5029. updated() {
  5030. // 卡片数据更新后刷新一次 ... 显示状态(避免“宽度/内容变了但命中区不变”) by xu 20260109
  5031. this.$nextTick?.(() => {
  5032. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5033. });
  5034. },
  5035. beforeUnmount() {
  5036. // 清理 timer,避免残留导致异常 by xu 20260108
  5037. this.clearHideTextPopoverTimer?.();
  5038. if (this.__ssListCardResizeHandler) {
  5039. window.removeEventListener?.("resize", this.__ssListCardResizeHandler);
  5040. this.__ssListCardResizeHandler = null;
  5041. }
  5042. },
  5043. render() {
  5044. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  5045. const SsIcon = Vue.resolveComponent("ss-icon");
  5046. const hasThumbArea = !!(this.item?.thumb || this.item?.thumbType); // 功能:无图但有 thumbType 时仍保留占位 by xu 20260109
  5047. const thumbSrc = (() => {
  5048. // 功能说明:兼容 thumb 为 raw path 或 {val}/{value},组件内统一转为 dlByHttp URL by xu 20260122
  5049. const t = this.item?.thumb;
  5050. if (!t) return "";
  5051. if (typeof t === "string") {
  5052. const s = t.trim();
  5053. if (!s) return "";
  5054. // 已经是 URL/绝对路径则直接使用;否则按 path 构建 dlByHttp by xu 20260122
  5055. if (
  5056. /^https?:\/\//i.test(s) ||
  5057. s.startsWith("/service?") ||
  5058. s.startsWith("/")
  5059. )
  5060. return s;
  5061. return buildThumbUrl(s);
  5062. }
  5063. return buildThumbUrl(t);
  5064. })();
  5065. return Vue.h(
  5066. "div",
  5067. {
  5068. class: {
  5069. "knowledge-item-container": true,
  5070. active: this.item.active,
  5071. [this.cardType]: !!this.cardType, // 动态添加卡片类型类名 by xu 20260105
  5072. [this.statusClass]: !!this.statusClass,
  5073. },
  5074. onClick: (e) => {
  5075. this.onItemClick?.(e);
  5076. if (this.__allowSelect() && this.cardClickAction === "single") {
  5077. // 功能说明:无 rbarObj 时不允许单选互斥 by xu 20260122
  5078. this.toggleSelectExclusive?.(e);
  5079. }
  5080. }, // 功能:卡片主体点击动作(view/single) by xu 20260109
  5081. // 移除固定宽度,由 CSS min-width 控制 by xu 20260105
  5082. },
  5083. [
  5084. // 右上角状态图标区域 by xu 20260105
  5085. this.item?.statusIcons?.length > 0 &&
  5086. Vue.h(
  5087. "div",
  5088. { class: "card-status-icons" },
  5089. this.item.statusIcons.map((icon) =>
  5090. Vue.h(SsIcon, {
  5091. class: `status-icon ${icon.class}`,
  5092. title: icon.title,
  5093. })
  5094. )
  5095. ),
  5096. this.item?.buttons?.length > 0 &&
  5097. Vue.h(
  5098. "div",
  5099. {
  5100. class: "header",
  5101. style:
  5102. this.item?.statusIcons?.length > 0
  5103. ? {
  5104. right: `${this.item.statusIcons.length * 48}px`,
  5105. borderTopRightRadius: "0",
  5106. }
  5107. : {},
  5108. onMouseenter: () => (this.showButtons = true),
  5109. onMouseleave: () => (this.showButtons = false),
  5110. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  5111. },
  5112. [
  5113. // 只在有按钮时渲染设置图标
  5114. // this.item?.buttons?.length > 0 &&
  5115. Vue.h("div", {
  5116. class: "cart-list-setting cart-list-icon",
  5117. title: this.item?.buttons?.[0]?.title,
  5118. }),
  5119. // 鼠标移入时显示按钮列表,与图标同级
  5120. // this.item?.buttons?.length > 0 &&
  5121. this.showButtons &&
  5122. this.item?.buttons?.length > 1 &&
  5123. Vue.h(
  5124. "div",
  5125. {
  5126. class: "cart-list-button-popup",
  5127. },
  5128. this.item.buttons.map((btn) =>
  5129. Vue.h(
  5130. "div",
  5131. {
  5132. onClick: (e) => {
  5133. e.stopPropagation();
  5134. btn.onclick?.();
  5135. },
  5136. },
  5137. [
  5138. // 如果有 class,显示对应的图标
  5139. btn.class &&
  5140. Vue.h(SsCartListIcon, {
  5141. class: [btn.class],
  5142. }),
  5143. // 显示按钮文本
  5144. Vue.h("span", null, btn.title),
  5145. ]
  5146. )
  5147. )
  5148. ),
  5149. ]
  5150. ),
  5151. Vue.h("div", { class: "body" }, [
  5152. Vue.h("div", { class: "box-header" }, [
  5153. Vue.h("div", `${this.item.title}`),
  5154. ]),
  5155. Vue.h(
  5156. "div",
  5157. {
  5158. class: !hasThumbArea ? "no-thumb box-body" : "box-body",
  5159. },
  5160. [
  5161. hasThumbArea
  5162. ? thumbSrc
  5163. ? Vue.h("div", { class: "left" }, [
  5164. Vue.h("img", {
  5165. src: thumbSrc,
  5166. alt: "Thumbnail",
  5167. class: "imgUnHandle",
  5168. style: {
  5169. "object-fit": "cover",
  5170. width: "100%",
  5171. height: "100%",
  5172. },
  5173. }),
  5174. ])
  5175. : Vue.h(
  5176. // 功能:无图占位(ss-icon + biz icon,居中) by xu 20260109
  5177. "div",
  5178. { class: "left ss-objlist-thumbPlaceholder" },
  5179. [
  5180. Vue.h(SsIcon, {
  5181. class: `${this.getBizThumbIconClass()} ss-objlist-thumbIcon`,
  5182. }),
  5183. ]
  5184. )
  5185. : null,
  5186. Vue.h(
  5187. "div",
  5188. {
  5189. class: "right",
  5190. },
  5191. (() => {
  5192. const model = this.buildRightTextLines(); // 功能:右侧文字区新规则(第二部分/第三部分优先级) by xu 20260108
  5193. const hasAny = !!(model?.hasSecond || model?.hasThird);
  5194. if (!hasAny) return [];
  5195. const children = [];
  5196. // 第二部分:L1-L3(摘要优先,其次 tags;不足留空;超出 L3 ...) by xu 20260108
  5197. if (model.hasSecond) {
  5198. if (model.secondKind === "summary") {
  5199. children.push(
  5200. Vue.h(
  5201. "div",
  5202. {
  5203. class:
  5204. "ss-card-text__line ss-card-text__secondBlock",
  5205. },
  5206. [
  5207. Vue.h(
  5208. "div",
  5209. {
  5210. class: "ss-card-text__secondSummary",
  5211. title: model.summary,
  5212. },
  5213. model.summary
  5214. ),
  5215. Vue.h("span", {
  5216. class: [
  5217. "ss-card-text__ellipsisHit",
  5218. "ss-card-text__ellipsisHit--second",
  5219. this.ellipsisVisible?.secondSummary
  5220. ? "is-on"
  5221. : "",
  5222. ],
  5223. title: "查看完整摘要",
  5224. onMouseenter: (e) =>
  5225. this.showTextPopoverFor(
  5226. e?.currentTarget,
  5227. "second-summary"
  5228. ),
  5229. onClick: (e) => {
  5230. e?.stopPropagation?.();
  5231. this.showTextPopoverFor(
  5232. e?.currentTarget,
  5233. "second-summary"
  5234. );
  5235. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5236. onMouseleave: () => this.hideTextPopoverLater(),
  5237. }),
  5238. ]
  5239. )
  5240. );
  5241. } else if (model.secondKind === "tags") {
  5242. children.push(
  5243. Vue.h(
  5244. "div",
  5245. {
  5246. class: [
  5247. "ss-card-text__line",
  5248. model.secondFull
  5249. ? "ss-card-text__secondFullBlock"
  5250. : "ss-card-text__secondBlock",
  5251. ],
  5252. },
  5253. [
  5254. // 功能:仅标签时占满 4 行 by xu 20260109
  5255. Vue.h(
  5256. "div",
  5257. { class: "ss-card-text__secondTags" },
  5258. [
  5259. ...model.secondTagsHead.map((t) =>
  5260. Vue.h(
  5261. "div",
  5262. {
  5263. class: "ss-card-text__tagLine",
  5264. title: t,
  5265. },
  5266. t
  5267. )
  5268. ),
  5269. // 第三行:平铺剩余(可能为空) by xu 20260108
  5270. Vue.h(
  5271. "div",
  5272. {
  5273. class:
  5274. "ss-card-text__tagLine is-last ss-card-text__tagLineLast",
  5275. title: model.secondTagsLast,
  5276. },
  5277. model.secondTagsLast
  5278. ),
  5279. ].filter(Boolean)
  5280. ),
  5281. // 只在最后一行出现 ... 时才触发 goheight by xu 20260108
  5282. Vue.h("span", {
  5283. class: [
  5284. "ss-card-text__ellipsisHit",
  5285. "ss-card-text__ellipsisHit--second",
  5286. this.ellipsisVisible?.secondTags
  5287. ? "is-on"
  5288. : "",
  5289. ],
  5290. title: "查看完整物品参数",
  5291. onMouseenter: (e) =>
  5292. this.showTextPopoverFor(
  5293. e?.currentTarget,
  5294. "second-tags"
  5295. ),
  5296. onClick: (e) => {
  5297. e?.stopPropagation?.();
  5298. this.showTextPopoverFor(
  5299. e?.currentTarget,
  5300. "second-tags"
  5301. );
  5302. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5303. onMouseleave: () => this.hideTextPopoverLater(),
  5304. }),
  5305. ]
  5306. )
  5307. );
  5308. }
  5309. }
  5310. // 第三部分:默认 L4;第二部分为空则占满 L1-L4 by xu 20260108
  5311. if (model.hasThird) {
  5312. if (model.thirdFull) {
  5313. children.push(
  5314. Vue.h(
  5315. "div",
  5316. {
  5317. class:
  5318. "ss-card-text__line ss-card-text__thirdFullBlock",
  5319. },
  5320. [
  5321. Vue.h(
  5322. "div",
  5323. {
  5324. class: "ss-card-text__thirdFull",
  5325. title: model.thirdText,
  5326. },
  5327. model.thirdText
  5328. ),
  5329. Vue.h("span", {
  5330. class: [
  5331. "ss-card-text__ellipsisHit",
  5332. "ss-card-text__ellipsisHit--third",
  5333. this.ellipsisVisible?.thirdFull
  5334. ? "is-on"
  5335. : "",
  5336. ],
  5337. title: "查看完整信息",
  5338. onMouseenter: (e) =>
  5339. this.showTextPopoverFor(
  5340. e?.currentTarget,
  5341. "third-full"
  5342. ),
  5343. onClick: (e) => {
  5344. e?.stopPropagation?.();
  5345. this.showTextPopoverFor(
  5346. e?.currentTarget,
  5347. "third-full"
  5348. );
  5349. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5350. onMouseleave: () => this.hideTextPopoverLater(),
  5351. }),
  5352. ]
  5353. )
  5354. );
  5355. } else {
  5356. children.push(
  5357. Vue.h(
  5358. "div",
  5359. {
  5360. class:
  5361. "ss-card-text__line ss-card-text__thirdLineWrap",
  5362. },
  5363. [
  5364. Vue.h(
  5365. "div",
  5366. {
  5367. class: "ss-card-text__thirdLine",
  5368. title: model.thirdText,
  5369. },
  5370. model.thirdText
  5371. ),
  5372. Vue.h("span", {
  5373. class: [
  5374. "ss-card-text__ellipsisHit",
  5375. "ss-card-text__ellipsisHit--third",
  5376. this.ellipsisVisible?.third ? "is-on" : "",
  5377. ],
  5378. title: "查看完整信息",
  5379. onMouseenter: (e) =>
  5380. this.showTextPopoverFor(
  5381. e?.currentTarget,
  5382. "third"
  5383. ),
  5384. onClick: (e) => {
  5385. e?.stopPropagation?.();
  5386. this.showTextPopoverFor(
  5387. e?.currentTarget,
  5388. "third"
  5389. );
  5390. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5391. onMouseleave: () => this.hideTextPopoverLater(),
  5392. }),
  5393. ]
  5394. )
  5395. );
  5396. }
  5397. }
  5398. // hover 展开浮层:宽度=右侧文字区,底对齐向上展开,带阴影 by xu 20260108
  5399. // popover 作为 `.right` 的 sibling 渲染,避免被 `.ss-card-text{overflow:hidden}` 裁剪 by xu 20260108
  5400. const popover =
  5401. this.showTextPopover &&
  5402. Vue.h(
  5403. "div",
  5404. {
  5405. class: "ss-card-text-popover",
  5406. style: { bottom: this.textPopoverBottom + "px" },
  5407. onMouseenter: () => {
  5408. this.clearHideTextPopoverTimer();
  5409. this.showTextPopover = true;
  5410. },
  5411. onMouseleave: () => this.hideTextPopoverLater(),
  5412. },
  5413. (() => {
  5414. const p = this.textPopoverPayload || {};
  5415. if (p.kind === "second-summary" && p.text) {
  5416. return [
  5417. Vue.h(
  5418. "div",
  5419. { class: "ss-card-text-popover__summary" },
  5420. p.text
  5421. ),
  5422. ];
  5423. }
  5424. if (Array.isArray(p.lines)) {
  5425. return [
  5426. Vue.h(
  5427. "div",
  5428. { class: "ss-card-text-popover__kvlist" },
  5429. p.lines.map((t) =>
  5430. Vue.h(
  5431. "div",
  5432. { class: "ss-card-text-popover__kv" },
  5433. t
  5434. )
  5435. )
  5436. ),
  5437. ];
  5438. }
  5439. if (
  5440. (p.kind === "third" || p.kind === "third-full") &&
  5441. p.text
  5442. ) {
  5443. return [
  5444. Vue.h(
  5445. "div",
  5446. { class: "ss-card-text-popover__objno" },
  5447. p.text
  5448. ),
  5449. ];
  5450. }
  5451. return [];
  5452. })()
  5453. );
  5454. return [
  5455. Vue.h("div", { class: "ss-card-text" }, children),
  5456. popover,
  5457. ];
  5458. })()
  5459. ),
  5460. ]
  5461. ),
  5462. ]),
  5463. // 右下角卡片选择图标 by xu 20260105
  5464. this.__allowSelect()
  5465. ? Vue.h(SsIcon, {
  5466. class: this.item?._ssSelected
  5467. ? "card-icon icon-cardChk-on"
  5468. : "card-icon icon-cardChk",
  5469. onClick: this.toggleSelect,
  5470. })
  5471. : null,
  5472. // 选中后底部线条 by xu 20260105
  5473. this.__allowSelect() &&
  5474. this.item?._ssSelected &&
  5475. Vue.h("div", { class: "select-bottom-line" }),
  5476. ]
  5477. );
  5478. },
  5479. };
  5480. // 二级对象卡片:复用一级对象新卡片布局/省略浮层,但去掉勾选与 single 选中,仅支持点击查看 by xu 20260115
  5481. const SsCObjCardList = {
  5482. name: "SsCObjCardList",
  5483. props: {
  5484. ssObjName: { type: String, default: "" }, // 功能说明:业务对象名(用于默认缩略图 icon) by xu 20260115
  5485. dataType: { type: String, default: "" }, // 功能说明:页面类型(play=查看模式不显示右上角按钮) by xu 20250408
  5486. item: {
  5487. type: Object,
  5488. required: true,
  5489. },
  5490. },
  5491. emits: ["click", "change"],
  5492. setup(props, { emit }) {
  5493. const item = props.item;
  5494. const dataType = props.dataType; // 功能说明:页面类型 by xu 20250408
  5495. const cardType = Vue.computed(() => {
  5496. if (!item.thumb && !item.thumbType) return "";
  5497. return item.thumbType === "thumbnail" ? "card-thumbnail" : "card-photo";
  5498. });
  5499. const statusClass = Vue.computed(() => {
  5500. if (!item.status) return "";
  5501. const statusMap = {
  5502. available: "status-available",
  5503. unavailable: "status-unavailable",
  5504. disabled: "status-disabled",
  5505. };
  5506. return statusMap[item.status] || "";
  5507. });
  5508. const onItemClick = (e) => {
  5509. // 清除所有类型卡片的 active 状态(保持与一级对象一致) by xu 20260115
  5510. const allListCards = document.querySelectorAll(
  5511. ".knowledge-item-container"
  5512. );
  5513. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  5514. allListCards.forEach((card) => card.classList.remove("active"));
  5515. allFolderCards.forEach((card) => card.classList.remove("active"));
  5516. e.currentTarget.classList.add("active");
  5517. // 二级对象卡片:点击仅查看(调用 item.onclick) by xu 20260115
  5518. props.item.onclick?.();
  5519. emit("click", props.item);
  5520. };
  5521. const onItemChange = (e) => {
  5522. e.stopPropagation();
  5523. props.item.buttons?.[0]?.onclick?.();
  5524. };
  5525. return { item, dataType, cardType, statusClass, onItemClick, onItemChange };
  5526. },
  5527. data() {
  5528. return {
  5529. showButtons: false,
  5530. showTextPopover: false, // 功能:右侧文字区 hover 展示全量 by xu 20260115
  5531. textPopoverType: "", // second-summary / second-tags / third / third-full by xu 20260115
  5532. textPopoverBottom: 0, // 功能:popover 从当前省略行位置向上展开 by xu 20260115
  5533. hideTextPopoverTimer: null, // 功能:鼠标从省略行移到浮层的缓冲 by xu 20260115
  5534. textPopoverPayload: null, // { kind, text?, lines? } by xu 20260115
  5535. ellipsisVisible: {
  5536. secondSummary: false,
  5537. secondTags: false,
  5538. third: false,
  5539. thirdFull: false,
  5540. }, // 功能:只在真实出现 ... 时才显示命中区/允许 goheight by xu 20260115
  5541. };
  5542. },
  5543. methods: {
  5544. getBizThumbIconClass() {
  5545. // 功能:无缩略图时,用业务对象 icon 做默认图(ss-icon + icon-obj-xx) by xu 20260115
  5546. const name = String(
  5547. this.ssObjName ||
  5548. this.item?.ssObjName ||
  5549. this.$root?.ssObjName ||
  5550. window?.ss?.dom?.ssObjName ||
  5551. ""
  5552. ).trim();
  5553. if (!name) return "";
  5554. return "icon-obj-" + name;
  5555. },
  5556. buildRightTextLines() {
  5557. // 功能:沿用一级对象卡片右侧文字区规则 by xu 20260115
  5558. const item = this.item || {};
  5559. const summary = String(item?.desc ?? "").trim();
  5560. const objNum = String(item?.objNum ?? "").trim();
  5561. const categoryArr = Array.isArray(item?.category) ? item.category : [];
  5562. const tagsArr = Array.isArray(item?.tags) ? item.tags : [];
  5563. const hasTags = tagsArr.length > 0;
  5564. const hasCategory = categoryArr.length > 0;
  5565. const secondKind = summary ? "summary" : hasTags ? "tags" : "";
  5566. const hasSecond = !!secondKind;
  5567. const thirdKind = objNum ? "objNum" : hasCategory ? "category" : "";
  5568. const hasThird = !!thirdKind;
  5569. const thirdFull = !hasSecond && hasThird;
  5570. const secondFull = hasSecond && !hasThird && secondKind === "tags";
  5571. const toValueText = (obj) => {
  5572. // 功能说明:类目/物品参数回显展示 key: value(否则只显示值看不懂) by xu 20260115
  5573. const [k, v] = Object.entries(obj || {})[0] || ["", ""];
  5574. const key = k !== undefined && k !== null ? String(k).trim() : "";
  5575. const val = v !== undefined && v !== null ? String(v).trim() : "";
  5576. if (key && val) return key + ":" + val;
  5577. if (val) return val;
  5578. if (key) return key;
  5579. return "";
  5580. };
  5581. const toLineList = (arr) =>
  5582. (arr || [])
  5583. .map(toValueText)
  5584. .map((s) => String(s ?? "").trim())
  5585. .filter(Boolean);
  5586. const secondTagsMaxLines = secondFull ? 4 : 3;
  5587. const secondTagsLinesFull = toLineList(tagsArr);
  5588. const secondTagsHead = secondTagsLinesFull.slice(
  5589. 0,
  5590. Math.max(0, secondTagsMaxLines - 1)
  5591. );
  5592. const secondTagsTail = secondTagsLinesFull.slice(
  5593. Math.max(0, secondTagsMaxLines - 1)
  5594. );
  5595. const secondTagsLast =
  5596. secondTagsTail.length <= 1
  5597. ? secondTagsTail[0] || ""
  5598. : secondTagsTail.join(" ");
  5599. const categoryLinesFull = toLineList(categoryArr);
  5600. const categoryLine = categoryLinesFull.join(" ");
  5601. const thirdText =
  5602. thirdKind === "objNum"
  5603. ? objNum
  5604. : thirdKind === "category"
  5605. ? categoryLine
  5606. : "";
  5607. return {
  5608. secondKind,
  5609. thirdKind,
  5610. hasSecond,
  5611. hasThird,
  5612. thirdFull,
  5613. secondFull,
  5614. summary,
  5615. secondTagsMaxLines,
  5616. secondTagsHead,
  5617. secondTagsLast,
  5618. secondTagsLinesFull,
  5619. objNum,
  5620. categoryLine,
  5621. categoryLinesFull,
  5622. thirdText,
  5623. };
  5624. },
  5625. measureTextOverflowByLines(text, maxLines, width) {
  5626. const w = Number(width) || 0;
  5627. if (!w || !text) return false;
  5628. const probe = document.createElement("div");
  5629. probe.style.position = "fixed";
  5630. probe.style.left = "-99999px";
  5631. probe.style.top = "0";
  5632. probe.style.width = w + "px";
  5633. probe.style.fontSize = "18px";
  5634. probe.style.lineHeight = "24px";
  5635. probe.style.whiteSpace = "normal";
  5636. probe.style.wordBreak = "break-word";
  5637. probe.style.visibility = "hidden";
  5638. probe.textContent = text;
  5639. document.body.appendChild(probe);
  5640. const h = probe.getBoundingClientRect().height || 0;
  5641. document.body.removeChild(probe);
  5642. return h > maxLines * 24 + 1;
  5643. },
  5644. measureSingleLineOverflow(text, width) {
  5645. const w = Number(width) || 0;
  5646. if (!w || !text) return false;
  5647. const probe = document.createElement("span");
  5648. probe.style.position = "fixed";
  5649. probe.style.left = "-99999px";
  5650. probe.style.top = "0";
  5651. probe.style.display = "inline-block";
  5652. probe.style.maxWidth = w + "px";
  5653. probe.style.fontSize = "18px";
  5654. probe.style.lineHeight = "24px";
  5655. probe.style.whiteSpace = "nowrap";
  5656. probe.style.visibility = "hidden";
  5657. probe.textContent = text;
  5658. document.body.appendChild(probe);
  5659. const overflow =
  5660. (probe.scrollWidth || 0) > (probe.clientWidth || w) + 1;
  5661. document.body.removeChild(probe);
  5662. return overflow;
  5663. },
  5664. refreshEllipsisVisible() {
  5665. // 功能:刷新「是否出现 ...」状态(用于控制命中区显示) by xu 20260115
  5666. try {
  5667. const right = this.$el?.querySelector?.(".right");
  5668. const rawWidth =
  5669. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  5670. const width = Math.max(0, Math.round(rawWidth));
  5671. const model = this.buildRightTextLines();
  5672. const next = {
  5673. secondSummary: false,
  5674. secondTags: false,
  5675. third: false,
  5676. thirdFull: false,
  5677. };
  5678. if (model.secondKind === "summary" && model.summary) {
  5679. next.secondSummary = this.measureTextOverflowByLines(
  5680. model.summary,
  5681. 3,
  5682. width
  5683. );
  5684. }
  5685. if (model.secondKind === "tags") {
  5686. next.secondTags = this.measureSingleLineOverflow(
  5687. model.secondTagsLast,
  5688. width
  5689. ); // 功能说明:tags 仅看最后一行是否溢出 by xu 20260115
  5690. }
  5691. if (model.hasThird && !model.thirdFull) {
  5692. next.third = this.measureSingleLineOverflow(model.thirdText, width);
  5693. }
  5694. if (model.hasThird && model.thirdFull) {
  5695. next.thirdFull = this.measureTextOverflowByLines(
  5696. model.thirdText,
  5697. 4,
  5698. width
  5699. );
  5700. }
  5701. const prev = this.ellipsisVisible || {};
  5702. const changed =
  5703. prev.secondSummary !== next.secondSummary ||
  5704. prev.secondTags !== next.secondTags ||
  5705. prev.third !== next.third ||
  5706. prev.thirdFull !== next.thirdFull;
  5707. if (changed) this.ellipsisVisible = next;
  5708. } catch (e) {
  5709. // ignore by xu 20260115
  5710. }
  5711. },
  5712. clearHideTextPopoverTimer() {
  5713. if (this.hideTextPopoverTimer) {
  5714. clearTimeout(this.hideTextPopoverTimer);
  5715. this.hideTextPopoverTimer = null;
  5716. }
  5717. },
  5718. hideTextPopoverLater() {
  5719. this.clearHideTextPopoverTimer();
  5720. this.hideTextPopoverTimer = setTimeout(() => {
  5721. this.showTextPopover = false;
  5722. this.textPopoverType = "";
  5723. this.textPopoverPayload = null;
  5724. }, 120);
  5725. },
  5726. showTextPopoverFor(el, kind) {
  5727. const model = this.buildRightTextLines();
  5728. const lineEl = el?.closest?.(".ss-card-text__line") || el;
  5729. const right = lineEl?.closest?.(".right") || el?.closest?.(".right");
  5730. const rawWidth =
  5731. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  5732. const width = Math.max(0, Math.round(rawWidth));
  5733. const overflowed =
  5734. kind === "second-summary"
  5735. ? this.measureTextOverflowByLines(model.summary, 3, width)
  5736. : kind === "second-tags"
  5737. ? this.measureSingleLineOverflow(model.secondTagsLast, width)
  5738. : kind === "third"
  5739. ? this.measureSingleLineOverflow(model.thirdText, width)
  5740. : this.measureTextOverflowByLines(model.thirdText, 4, width);
  5741. if (!overflowed) return;
  5742. let payload = null;
  5743. if (kind === "second-summary") {
  5744. if (model.summary) payload = { kind, text: model.summary };
  5745. } else if (kind === "second-tags") {
  5746. if (
  5747. Array.isArray(model.secondTagsLinesFull) &&
  5748. model.secondTagsLinesFull.length
  5749. ) {
  5750. payload = { kind, lines: model.secondTagsLinesFull };
  5751. }
  5752. } else if (kind === "third") {
  5753. if (
  5754. model.thirdKind === "category" &&
  5755. Array.isArray(model.categoryLinesFull) &&
  5756. model.categoryLinesFull.length
  5757. ) {
  5758. payload = { kind, lines: model.categoryLinesFull };
  5759. } else if (model.thirdText) {
  5760. payload = { kind, text: model.thirdText };
  5761. }
  5762. } else if (kind === "third-full") {
  5763. if (
  5764. model.thirdKind === "category" &&
  5765. Array.isArray(model.categoryLinesFull) &&
  5766. model.categoryLinesFull.length
  5767. ) {
  5768. payload = { kind, lines: model.categoryLinesFull };
  5769. } else if (model.thirdText) {
  5770. payload = { kind, text: model.thirdText };
  5771. }
  5772. }
  5773. if (!payload) return;
  5774. this.clearHideTextPopoverTimer();
  5775. const container = lineEl?.closest?.(".right");
  5776. const containerRect = container?.getBoundingClientRect?.();
  5777. const lineRect = lineEl?.getBoundingClientRect?.();
  5778. if (containerRect && lineRect) {
  5779. const bottom = Math.max(
  5780. 0,
  5781. Math.round(containerRect.bottom - lineRect.bottom)
  5782. );
  5783. this.textPopoverBottom = bottom;
  5784. } else {
  5785. this.textPopoverBottom = 0;
  5786. }
  5787. this.textPopoverPayload = payload;
  5788. this.textPopoverType = kind;
  5789. this.showTextPopover = true;
  5790. },
  5791. },
  5792. mounted() {
  5793. this.$nextTick?.(() => {
  5794. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5795. });
  5796. this.__ssCObjCardResizeHandler = () => this.refreshEllipsisVisible?.(); // 功能说明:窗口变化时刷新 ... 显示 by xu 20260115
  5797. window.addEventListener?.("resize", this.__ssCObjCardResizeHandler);
  5798. },
  5799. updated() {
  5800. this.$nextTick?.(() => {
  5801. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5802. });
  5803. },
  5804. beforeUnmount() {
  5805. this.clearHideTextPopoverTimer?.();
  5806. if (this.__ssCObjCardResizeHandler) {
  5807. window.removeEventListener?.("resize", this.__ssCObjCardResizeHandler);
  5808. this.__ssCObjCardResizeHandler = null;
  5809. }
  5810. },
  5811. render() {
  5812. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  5813. const SsIcon = Vue.resolveComponent("ss-icon");
  5814. const hasThumbArea = !!(this.item?.thumb || this.item?.thumbType);
  5815. const thumbSrc = (() => {
  5816. // 功能说明:兼容 thumb 为 raw path 或 {val}/{value},组件内统一转为 dlByHttp URL by xu 20260122
  5817. const t = this.item?.thumb;
  5818. if (!t) return "";
  5819. if (typeof t === "string") {
  5820. const s = t.trim();
  5821. if (!s) return "";
  5822. if (
  5823. /^https?:\/\//i.test(s) ||
  5824. s.startsWith("/service?") ||
  5825. s.startsWith("/")
  5826. )
  5827. return s;
  5828. return buildThumbUrl(s);
  5829. }
  5830. return buildThumbUrl(t);
  5831. })();
  5832. return Vue.h(
  5833. "div",
  5834. {
  5835. class: {
  5836. "knowledge-item-container": true,
  5837. active: this.item.active,
  5838. [this.cardType]: !!this.cardType,
  5839. [this.statusClass]: !!this.statusClass,
  5840. },
  5841. onClick: (e) => this.onItemClick?.(e), // 功能说明:二级对象卡片点击仅查看 by xu 20260115
  5842. },
  5843. [
  5844. this.item?.statusIcons?.length > 0 &&
  5845. Vue.h(
  5846. "div",
  5847. { class: "card-status-icons" },
  5848. this.item.statusIcons.map((icon) =>
  5849. Vue.h(SsIcon, {
  5850. class: "status-icon " + icon.class,
  5851. title: icon.title,
  5852. })
  5853. )
  5854. ),
  5855. this.item?.buttons?.length > 0 && this.dataType !== "play" &&
  5856. Vue.h(
  5857. "div",
  5858. {
  5859. class: "header",
  5860. style:
  5861. this.item?.statusIcons?.length > 0
  5862. ? {
  5863. right: String(this.item.statusIcons.length * 48) + "px",
  5864. borderTopRightRadius: "0",
  5865. }
  5866. : {},
  5867. onMouseenter: () => (this.showButtons = true),
  5868. onMouseleave: () => (this.showButtons = false),
  5869. onClick: (e) => this.onItemChange(e),
  5870. },
  5871. [
  5872. Vue.h("div", {
  5873. class: "cart-list-setting cart-list-icon",
  5874. title: this.item?.buttons?.[0]?.title,
  5875. }),
  5876. this.showButtons &&
  5877. this.item?.buttons?.length > 1 &&
  5878. Vue.h(
  5879. "div",
  5880. { class: "cart-list-button-popup" },
  5881. this.item.buttons.map((btn) =>
  5882. Vue.h(
  5883. "div",
  5884. {
  5885. onClick: (e) => {
  5886. e.stopPropagation();
  5887. btn.onclick?.();
  5888. },
  5889. },
  5890. [
  5891. btn.class &&
  5892. Vue.h(SsCartListIcon, { class: [btn.class] }),
  5893. Vue.h("span", null, btn.title),
  5894. ]
  5895. )
  5896. )
  5897. ),
  5898. ]
  5899. ),
  5900. Vue.h("div", { class: "body" }, [
  5901. Vue.h("div", { class: "box-header" }, [
  5902. Vue.h("div", String(this.item.title || "")),
  5903. ]),
  5904. Vue.h(
  5905. "div",
  5906. { class: !hasThumbArea ? "no-thumb box-body" : "box-body" },
  5907. [
  5908. hasThumbArea
  5909. ? thumbSrc
  5910. ? Vue.h("div", { class: "left" }, [
  5911. Vue.h("img", {
  5912. src: thumbSrc,
  5913. alt: "Thumbnail",
  5914. class: "imgUnHandle",
  5915. style: {
  5916. "object-fit": "cover",
  5917. width: "100%",
  5918. height: "100%",
  5919. },
  5920. }),
  5921. ])
  5922. : Vue.h(
  5923. "div",
  5924. { class: "left ss-objlist-thumbPlaceholder" },
  5925. [
  5926. Vue.h(SsIcon, {
  5927. class:
  5928. this.getBizThumbIconClass() +
  5929. " ss-objlist-thumbIcon",
  5930. }),
  5931. ]
  5932. )
  5933. : null,
  5934. Vue.h(
  5935. "div",
  5936. { class: "right" },
  5937. (() => {
  5938. const model = this.buildRightTextLines();
  5939. const hasAny = !!(model?.hasSecond || model?.hasThird);
  5940. if (!hasAny) return [];
  5941. const children = [];
  5942. if (model.hasSecond && model.secondKind === "summary") {
  5943. children.push(
  5944. Vue.h(
  5945. "div",
  5946. {
  5947. class:
  5948. "ss-card-text__line ss-card-text__secondBlock",
  5949. },
  5950. [
  5951. Vue.h(
  5952. "div",
  5953. {
  5954. class: "ss-card-text__secondSummary",
  5955. title: model.summary,
  5956. },
  5957. model.summary
  5958. ),
  5959. Vue.h("span", {
  5960. class: [
  5961. "ss-card-text__ellipsisHit",
  5962. "ss-card-text__ellipsisHit--second",
  5963. this.ellipsisVisible?.secondSummary
  5964. ? "is-on"
  5965. : "",
  5966. ],
  5967. title: "查看完整信息",
  5968. onMouseenter: (e) =>
  5969. this.showTextPopoverFor(
  5970. e?.currentTarget,
  5971. "second-summary"
  5972. ),
  5973. onClick: (e) => {
  5974. e?.stopPropagation?.();
  5975. this.showTextPopoverFor(
  5976. e?.currentTarget,
  5977. "second-summary"
  5978. );
  5979. },
  5980. onMouseleave: () => this.hideTextPopoverLater(),
  5981. }),
  5982. ]
  5983. )
  5984. );
  5985. }
  5986. if (model.hasSecond && model.secondKind === "tags") {
  5987. children.push(
  5988. Vue.h(
  5989. "div",
  5990. {
  5991. class: [
  5992. "ss-card-text__line",
  5993. model.secondFull
  5994. ? "ss-card-text__secondFullBlock"
  5995. : "ss-card-text__secondBlock",
  5996. ],
  5997. },
  5998. [
  5999. Vue.h(
  6000. "div",
  6001. { class: "ss-card-text__secondTags" },
  6002. [
  6003. ...model.secondTagsHead.map((t) =>
  6004. Vue.h(
  6005. "div",
  6006. {
  6007. class: "ss-card-text__tagLine",
  6008. title: t,
  6009. },
  6010. t
  6011. )
  6012. ),
  6013. Vue.h(
  6014. "div",
  6015. {
  6016. class:
  6017. "ss-card-text__tagLine is-last ss-card-text__tagLineLast",
  6018. title: model.secondTagsLast,
  6019. },
  6020. model.secondTagsLast
  6021. ),
  6022. ]
  6023. ),
  6024. Vue.h("span", {
  6025. class: [
  6026. "ss-card-text__ellipsisHit",
  6027. "ss-card-text__ellipsisHit--second",
  6028. this.ellipsisVisible?.secondTags ? "is-on" : "",
  6029. ],
  6030. title: "查看完整信息",
  6031. onMouseenter: (e) =>
  6032. this.showTextPopoverFor(
  6033. e?.currentTarget,
  6034. "second-tags"
  6035. ),
  6036. onClick: (e) => {
  6037. e?.stopPropagation?.();
  6038. this.showTextPopoverFor(
  6039. e?.currentTarget,
  6040. "second-tags"
  6041. );
  6042. },
  6043. onMouseleave: () => this.hideTextPopoverLater(),
  6044. }),
  6045. ]
  6046. )
  6047. );
  6048. }
  6049. if (model.hasThird) {
  6050. if (model.thirdFull) {
  6051. children.push(
  6052. Vue.h(
  6053. "div",
  6054. {
  6055. class:
  6056. "ss-card-text__line ss-card-text__thirdFullBlock",
  6057. },
  6058. [
  6059. Vue.h(
  6060. "div",
  6061. {
  6062. class: "ss-card-text__thirdFull",
  6063. title: model.thirdText,
  6064. },
  6065. model.thirdText
  6066. ),
  6067. Vue.h("span", {
  6068. class: [
  6069. "ss-card-text__ellipsisHit",
  6070. "ss-card-text__ellipsisHit--third",
  6071. this.ellipsisVisible?.thirdFull
  6072. ? "is-on"
  6073. : "",
  6074. ],
  6075. title: "查看完整信息",
  6076. onMouseenter: (e) =>
  6077. this.showTextPopoverFor(
  6078. e?.currentTarget,
  6079. "third-full"
  6080. ),
  6081. onClick: (e) => {
  6082. e?.stopPropagation?.();
  6083. this.showTextPopoverFor(
  6084. e?.currentTarget,
  6085. "third-full"
  6086. );
  6087. },
  6088. onMouseleave: () => this.hideTextPopoverLater(),
  6089. }),
  6090. ]
  6091. )
  6092. );
  6093. } else {
  6094. children.push(
  6095. Vue.h(
  6096. "div",
  6097. {
  6098. class:
  6099. "ss-card-text__line ss-card-text__thirdLineWrap",
  6100. },
  6101. [
  6102. Vue.h(
  6103. "div",
  6104. {
  6105. class: "ss-card-text__thirdLine",
  6106. title: model.thirdText,
  6107. },
  6108. model.thirdText
  6109. ),
  6110. Vue.h("span", {
  6111. class: [
  6112. "ss-card-text__ellipsisHit",
  6113. "ss-card-text__ellipsisHit--third",
  6114. this.ellipsisVisible?.third ? "is-on" : "",
  6115. ],
  6116. title: "查看完整信息",
  6117. onMouseenter: (e) =>
  6118. this.showTextPopoverFor(
  6119. e?.currentTarget,
  6120. "third"
  6121. ),
  6122. onClick: (e) => {
  6123. e?.stopPropagation?.();
  6124. this.showTextPopoverFor(
  6125. e?.currentTarget,
  6126. "third"
  6127. );
  6128. },
  6129. onMouseleave: () => this.hideTextPopoverLater(),
  6130. }),
  6131. ]
  6132. )
  6133. );
  6134. }
  6135. }
  6136. const popover =
  6137. this.showTextPopover &&
  6138. Vue.h(
  6139. "div",
  6140. {
  6141. class: "ss-card-text-popover",
  6142. style: { bottom: this.textPopoverBottom + "px" },
  6143. onMouseenter: () => {
  6144. this.clearHideTextPopoverTimer();
  6145. this.showTextPopover = true;
  6146. },
  6147. onMouseleave: () => this.hideTextPopoverLater(),
  6148. },
  6149. (() => {
  6150. const p = this.textPopoverPayload || {};
  6151. if (p.kind === "second-summary" && p.text) {
  6152. return [
  6153. Vue.h(
  6154. "div",
  6155. { class: "ss-card-text-popover__summary" },
  6156. p.text
  6157. ),
  6158. ];
  6159. }
  6160. if (Array.isArray(p.lines)) {
  6161. return [
  6162. Vue.h(
  6163. "div",
  6164. { class: "ss-card-text-popover__kvlist" },
  6165. p.lines.map((t) =>
  6166. Vue.h(
  6167. "div",
  6168. { class: "ss-card-text-popover__kv" },
  6169. t
  6170. )
  6171. )
  6172. ),
  6173. ];
  6174. }
  6175. if (
  6176. (p.kind === "third" || p.kind === "third-full") &&
  6177. p.text
  6178. ) {
  6179. return [
  6180. Vue.h(
  6181. "div",
  6182. { class: "ss-card-text-popover__objno" },
  6183. p.text
  6184. ),
  6185. ];
  6186. }
  6187. return [];
  6188. })()
  6189. );
  6190. return [
  6191. Vue.h("div", { class: "ss-card-text" }, children),
  6192. popover,
  6193. ];
  6194. })()
  6195. ),
  6196. ]
  6197. ),
  6198. ]),
  6199. ]
  6200. );
  6201. },
  6202. };
  6203. // ss-sidebar 右侧边栏(容器 + 子组件),用于 objList 右侧区域 by xu 20260106
  6204. // 组件文档补全(JSDoc) by xu 20260108
  6205. /**
  6206. * SsSidebarButtons(右侧边栏顶部按钮栏)
  6207. *
  6208. * 用途:
  6209. * - 渲染 objList 右侧顶部快捷操作(预定/入住/退房/清洁...)
  6210. * - 内部复用 `ss-search-button`(项目现有按钮样式/交互)
  6211. *
  6212. * 调用示例:
  6213. * ```html
  6214. * <ss-sidebar-buttons :items="sidebarButtons" />
  6215. * ```
  6216. *
  6217. * Props:
  6218. * - `items`: 按钮配置数组
  6219. * - `{ id, text, icon?, onClick? }`
  6220. *
  6221. * Emits:
  6222. * - `click`:点击按钮时触发,参数为按钮对象
  6223. */
  6224. const SsSidebarButtons = {
  6225. name: "SsSidebarButtons",
  6226. props: {
  6227. items: { type: Array, default: () => [] },
  6228. },
  6229. emits: ["click"],
  6230. render() {
  6231. const SsSearchButton = Vue.resolveComponent("ss-search-button");
  6232. const items = this.items || [];
  6233. if (!items.length) return null;
  6234. return Vue.h(
  6235. "div",
  6236. { class: "ss-sidebar-actions" },
  6237. items.map((btn) =>
  6238. // 顶部操作按钮复用 ss-search-button(先 mock 固定按钮) by xu 20260106
  6239. Vue.h(SsSearchButton, {
  6240. text: btn?.text ?? "",
  6241. iconClass: btn?.iconClass ?? "",
  6242. opt: btn?.opt ?? [],
  6243. checkId: btn?.checkId ?? "0",
  6244. width: btn?.width,
  6245. id: btn?.id,
  6246. onClick: (e) => {
  6247. e?.stopPropagation?.();
  6248. btn?.onClick?.(btn);
  6249. this.$emit("click", btn);
  6250. },
  6251. })
  6252. )
  6253. );
  6254. },
  6255. };
  6256. // 组件文档补全(JSDoc) by xu 20260108
  6257. /**
  6258. * SsSidebarChart(ECharts 容器渲染)
  6259. *
  6260. * 用途:
  6261. * - 仅负责 echarts init / setOption / resize / dispose
  6262. * - 被 `ss-sidebar-chart-hover` 与图表面板复用
  6263. *
  6264. * 调用示例:
  6265. * ```html
  6266. * <ss-sidebar-chart :options="option" height="220px" />
  6267. * ```
  6268. *
  6269. * Props:
  6270. * - `options`:ECharts option(Object)
  6271. * - `height`:容器高度(String)
  6272. */
  6273. const SsSidebarChart = {
  6274. name: "SsSidebarChart",
  6275. props: {
  6276. options: { type: Object, default: () => ({}) },
  6277. height: { type: String, default: "200px" },
  6278. },
  6279. setup(props) {
  6280. const elRef = Vue.ref(null);
  6281. let chart = null;
  6282. const renderChart = () => {
  6283. if (!elRef.value || !window.echarts) return;
  6284. if (!chart) {
  6285. chart = window.echarts.init(elRef.value);
  6286. }
  6287. chart.setOption(props.options || {}, true);
  6288. };
  6289. const resizeChart = () => {
  6290. chart?.resize?.();
  6291. };
  6292. Vue.onMounted(() => {
  6293. renderChart();
  6294. window.addEventListener("resize", resizeChart);
  6295. });
  6296. Vue.onBeforeUnmount(() => {
  6297. window.removeEventListener("resize", resizeChart);
  6298. chart?.dispose?.();
  6299. chart = null;
  6300. });
  6301. Vue.watch(
  6302. () => props.options,
  6303. () => {
  6304. renderChart();
  6305. },
  6306. { deep: true }
  6307. );
  6308. return { elRef };
  6309. },
  6310. render() {
  6311. return Vue.h("div", {
  6312. ref: "elRef",
  6313. style: {
  6314. width: "100%",
  6315. height: this.height,
  6316. // 图表容器不加 padding/border,由外层布局控制 by xu 20260106
  6317. background: "transparent",
  6318. border: "none",
  6319. "border-radius": "0",
  6320. },
  6321. });
  6322. },
  6323. };
  6324. // ss-sidebar-chart-hover:hover 弹出左侧大图(支持图钉/全屏) by xu 20260106
  6325. // 组件文档补全(JSDoc) by xu 20260108
  6326. /**
  6327. * SsSidebarChartHover(小图 + hover 左侧大图预览 + 图钉固定 + 全屏)
  6328. *
  6329. * 用途:
  6330. * - 右侧统计图小卡片:hover 时在左侧弹出大图预览
  6331. * - 预览头部:左侧图标+标题;右侧固定/全屏按钮(icon-base)
  6332. * - 全屏:方案A(浏览器 Fullscreen API)
  6333. *
  6334. * 调用示例(由 ss-sidebar chart panel 内部调用):
  6335. * ```html
  6336. * <ss-sidebar-chart-hover
  6337. * title="校舍建筑面积和总体分布"
  6338. * icon-class="menu-icon icon-obj-jzw"
  6339. * :options="option"
  6340. * height="220px"
  6341. * />
  6342. * ```
  6343. *
  6344. * Props:
  6345. * - `title/iconClass/icon`:用于预览/全屏 header 显示(与面板 header 一致)
  6346. * - `options`:ECharts option
  6347. * - `height`:小图高度
  6348. * - `previewWidth/previewHeight`:预览建议尺寸(会按视口自适应)
  6349. */
  6350. const SsSidebarChartHover = {
  6351. name: "SsSidebarChartHover",
  6352. props: {
  6353. // hover 大图标题/图标(与小图面板 header 一致) by xu 20260108
  6354. title: { type: String, default: "" },
  6355. iconClass: { type: String, default: "" },
  6356. icon: { type: String, default: "" },
  6357. options: { type: Object, default: () => ({}) },
  6358. height: { type: String, default: "220px" },
  6359. // hover 弹窗建议尺寸:默认 1000x650(比例由逻辑统一管控),实际渲染会按比例自适应视口 by xu 20260115
  6360. previewWidth: { type: Number, default: 1000 },
  6361. previewHeight: { type: Number, default: 650 },
  6362. },
  6363. setup(props) {
  6364. const triggerRef = Vue.ref(null);
  6365. const fullscreenRef = Vue.ref(null);
  6366. const open = Vue.ref(false);
  6367. const pinned = Vue.ref(false);
  6368. const fullscreen = Vue.ref(false);
  6369. const hoveringTrigger = Vue.ref(false);
  6370. const hoveringPreview = Vue.ref(false);
  6371. const previewStyle = Vue.ref({});
  6372. let closeTimer = null;
  6373. const updatePreviewPosition = () => {
  6374. const el = triggerRef.value;
  6375. if (!el) return;
  6376. const rect = el.getBoundingClientRect();
  6377. // 功能说明:优先使用 visualViewport(避免浏览器 UI/缩放导致可视区与 innerHeight 偏差,出现预览被遮挡约 70px) by xu 20260116
  6378. const docEl = document.documentElement;
  6379. const vv = window.visualViewport;
  6380. let viewportLeft = Number(vv?.offsetLeft ?? 0) || 0;
  6381. let viewportTop = Number(vv?.offsetTop ?? 0) || 0;
  6382. let vw =
  6383. Number(vv?.width ?? 0) ||
  6384. Number(docEl?.clientWidth || 0) ||
  6385. window.innerWidth;
  6386. let vh =
  6387. Number(vv?.height ?? 0) ||
  6388. Number(docEl?.clientHeight || 0) ||
  6389. window.innerHeight;
  6390. // 功能说明:若页面在 iframe 内,父页面可能裁切 iframe 可见区域(overflow/弹窗容器),需要用“iframe可见区域”做二次约束 by xu 20260116
  6391. try {
  6392. const inIframe = window.top && window.top !== window;
  6393. const frameEl = window.frameElement;
  6394. if (inIframe && frameEl && window.top?.document) {
  6395. const topVv = window.top.visualViewport;
  6396. const topDocEl = window.top.document.documentElement;
  6397. const topVw =
  6398. Number(topVv?.width ?? 0) ||
  6399. Number(topDocEl?.clientWidth || 0) ||
  6400. window.top.innerWidth;
  6401. const topVh =
  6402. Number(topVv?.height ?? 0) ||
  6403. Number(topDocEl?.clientHeight || 0) ||
  6404. window.top.innerHeight;
  6405. const fr = frameEl.getBoundingClientRect?.();
  6406. if (fr && fr.width > 0 && fr.height > 0) {
  6407. const visibleW = Math.max(
  6408. 0,
  6409. Math.min(fr.right, topVw) - Math.max(fr.left, 0)
  6410. );
  6411. const visibleH = Math.max(
  6412. 0,
  6413. Math.min(fr.bottom, topVh) - Math.max(fr.top, 0)
  6414. );
  6415. if (visibleW > 0) {
  6416. vw = Math.min(vw, visibleW);
  6417. viewportLeft = Math.max(0, -fr.left); // iframe内坐标系偏移(左侧被裁切时) by xu 20260116
  6418. }
  6419. if (visibleH > 0) {
  6420. vh = Math.min(vh, visibleH);
  6421. viewportTop = Math.max(0, -fr.top); // iframe内坐标系偏移(顶部被裁切时) by xu 20260116
  6422. }
  6423. }
  6424. }
  6425. } catch (_) {}
  6426. // 预览窗尺寸:优先保证“完整可见”,其次再尽量对齐右侧 header 顶部 by xu 20260116
  6427. const viewportPaddingX = 40;
  6428. const viewportPaddingTop = 20;
  6429. const viewportPaddingBottom = 10;
  6430. // 功能说明:hover 预览框不要覆盖右侧栏,优先放在 ss-sidebar 左侧;必要时动态缩小宽度 by xu 20260115
  6431. const sidebarEl = el.closest ? el.closest(".ss-sidebar") : null;
  6432. const sidebarRect = sidebarEl?.getBoundingClientRect?.();
  6433. const maxWidthByViewport = Math.max(240, vw - viewportPaddingX);
  6434. const maxWidthByLeftSpace = sidebarRect
  6435. ? Math.max(
  6436. 240,
  6437. sidebarRect.left - viewportPaddingX - 14 /* gapFromSidebar */
  6438. )
  6439. : maxWidthByViewport;
  6440. // 功能说明:预览框尺寸按比例(默认 5:3)缩放,并提供最大/最小值约束 by xu 20260115
  6441. const ratio = 3 / 5;
  6442. const minWidth = 320;
  6443. const minHeight = 240;
  6444. const maxHeightByViewport = Math.max(
  6445. minHeight,
  6446. vh - viewportPaddingTop - viewportPaddingBottom
  6447. );
  6448. const maxWidthByProp = Number(props.previewWidth) || 1000;
  6449. const maxHeightByProp = Number(props.previewHeight) || 650;
  6450. // 优先按高度撑满可视区(保证预览完整可见),再根据左侧可用宽度回退 by xu 20260116
  6451. const maxHeight = Math.min(maxHeightByProp, maxHeightByViewport);
  6452. let height = Math.max(minHeight, maxHeight);
  6453. let width = Math.round(height / ratio);
  6454. width = Math.min(
  6455. width,
  6456. maxWidthByProp,
  6457. maxWidthByViewport,
  6458. maxWidthByLeftSpace
  6459. );
  6460. width = Math.max(minWidth, width);
  6461. height = Math.round(width * ratio);
  6462. if (height > maxHeight) {
  6463. height = maxHeight;
  6464. width = Math.round(height / ratio);
  6465. }
  6466. // 默认贴着小图左侧弹出,右边缘与小图左边缘轻微重叠,避免 1px 缝隙导致 hover 闪断 by xu 20260108
  6467. const overlap = 2;
  6468. const gapFromSidebar = 14; // 功能说明:弹窗与右侧边栏留出距离(更不贴近) by xu 20260108
  6469. // 优先:贴在 sidebar 左侧(不压住右侧栏内容) by xu 20260115
  6470. let left = sidebarRect
  6471. ? sidebarRect.left - gapFromSidebar - width + overlap
  6472. : rect.left - width - gapFromSidebar + overlap;
  6473. // 如果左侧空间不足,则贴右侧(兜底,同样重叠) by xu 20260108
  6474. if (left < 0) left = rect.right + gapFromSidebar - overlap;
  6475. left = Math.max(
  6476. viewportLeft,
  6477. Math.min(left, viewportLeft + vw - width)
  6478. );
  6479. // top:优先保证完整可见,然后才贴近 header 顶部 by xu 20260116
  6480. let headerEl = el;
  6481. while (headerEl && !headerEl.classList?.contains("ss-sidebar-panel")) {
  6482. headerEl = headerEl.parentElement;
  6483. }
  6484. let headerRect = headerEl
  6485. ?.querySelector(".ss-sidebar-panel__header")
  6486. ?.getBoundingClientRect();
  6487. let top = headerRect?.top ?? rect.top;
  6488. top = Math.max(
  6489. viewportTop + viewportPaddingTop,
  6490. Math.min(top, viewportTop + vh - height - viewportPaddingBottom)
  6491. );
  6492. previewStyle.value = {
  6493. position: "fixed",
  6494. left: `${Math.round(left)}px`,
  6495. top: `${Math.round(top)}px`,
  6496. width: `${width}px`,
  6497. height: `${height}px`,
  6498. zIndex: 2147483647, // 功能说明:提高层级到接近浏览器上限,避免仍被页面固定栏/弹窗遮挡 by xu 20260116
  6499. };
  6500. };
  6501. const clearCloseTimer = () => {
  6502. if (closeTimer) {
  6503. clearTimeout(closeTimer);
  6504. closeTimer = null;
  6505. }
  6506. };
  6507. const scheduleClose = () => {
  6508. clearCloseTimer();
  6509. if (pinned.value || fullscreen.value) return;
  6510. if (hoveringTrigger.value || hoveringPreview.value) return; // 功能:鼠标在小图/大图之间移动不关闭 by xu 20260108
  6511. closeTimer = setTimeout(() => {
  6512. open.value = false;
  6513. }, 100);
  6514. };
  6515. const openPreview = () => {
  6516. clearCloseTimer();
  6517. updatePreviewPosition();
  6518. open.value = true;
  6519. };
  6520. const togglePin = () => {
  6521. pinned.value = !pinned.value;
  6522. if (pinned.value) {
  6523. open.value = true;
  6524. updatePreviewPosition();
  6525. }
  6526. };
  6527. const toggleFullscreen = () => {
  6528. // 全屏:采用浏览器 Fullscreen API(方案A),不使用遮罩弹窗 by xu 20260108
  6529. if (!fullscreen.value) {
  6530. open.value = false; // 避免同时渲染预览与全屏 by xu 20260108
  6531. fullscreen.value = true;
  6532. Vue.nextTick(() => {
  6533. const el = fullscreenRef.value;
  6534. if (el?.requestFullscreen) {
  6535. el.requestFullscreen().catch(() => {
  6536. // requestFullscreen 失败则回退为非全屏状态 by xu 20260108
  6537. fullscreen.value = false;
  6538. });
  6539. } else {
  6540. fullscreen.value = false;
  6541. }
  6542. });
  6543. } else {
  6544. if (document?.exitFullscreen) {
  6545. document.exitFullscreen().catch(() => {});
  6546. }
  6547. }
  6548. };
  6549. const handleFullscreenChange = () => {
  6550. const isFs = !!document.fullscreenElement;
  6551. fullscreen.value = isFs; // 功能说明:同步 ESC/系统退出全屏状态 by xu 20260108
  6552. if (isFs) {
  6553. open.value = false;
  6554. clearCloseTimer();
  6555. return;
  6556. }
  6557. // 退出全屏后:若固定或仍 hover,则恢复预览,否则关闭 by xu 20260108
  6558. if (pinned.value || hoveringTrigger.value || hoveringPreview.value) {
  6559. open.value = true;
  6560. updatePreviewPosition();
  6561. } else {
  6562. open.value = false;
  6563. }
  6564. };
  6565. Vue.onMounted(() => {
  6566. window.addEventListener("resize", updatePreviewPosition);
  6567. window.addEventListener("scroll", updatePreviewPosition, true);
  6568. document.addEventListener("fullscreenchange", handleFullscreenChange); // 功能说明:监听全屏状态变化 by xu 20260108
  6569. });
  6570. Vue.onBeforeUnmount(() => {
  6571. clearCloseTimer();
  6572. window.removeEventListener("resize", updatePreviewPosition);
  6573. window.removeEventListener("scroll", updatePreviewPosition, true);
  6574. document.removeEventListener(
  6575. "fullscreenchange",
  6576. handleFullscreenChange
  6577. );
  6578. });
  6579. return {
  6580. triggerRef,
  6581. fullscreenRef,
  6582. open,
  6583. pinned,
  6584. fullscreen,
  6585. hoveringTrigger,
  6586. hoveringPreview,
  6587. previewStyle,
  6588. openPreview,
  6589. scheduleClose,
  6590. clearCloseTimer,
  6591. togglePin,
  6592. toggleFullscreen,
  6593. };
  6594. },
  6595. render() {
  6596. const SsIcon = Vue.resolveComponent("ss-icon");
  6597. const Chart = Vue.resolveComponent("ss-sidebar-chart");
  6598. const hasHeader = !!(this.title || this.iconClass || this.icon); // 功能:hover 大图显示左侧图标+标题 by xu 20260108
  6599. const previewContent = Vue.h(
  6600. "div",
  6601. {
  6602. class: { "ss-sidebar-chart-preview": true, "is-pinned": this.pinned },
  6603. style: this.previewStyle,
  6604. onMouseenter: () => {
  6605. this.hoveringPreview = true;
  6606. this.clearCloseTimer();
  6607. },
  6608. onMouseleave: () => {
  6609. this.hoveringPreview = false;
  6610. this.scheduleClose();
  6611. },
  6612. },
  6613. [
  6614. hasHeader
  6615. ? Vue.h(
  6616. "div",
  6617. {
  6618. class:
  6619. "ss-sidebar-panel__header ss-sidebar-chart-preview__header",
  6620. },
  6621. [
  6622. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  6623. this.iconClass
  6624. ? Vue.h(SsIcon, {
  6625. class: this.iconClass + " ss-sidebar-panel__icon",
  6626. })
  6627. : this.icon
  6628. ? Vue.h(SsIcon, {
  6629. name: this.icon,
  6630. size: "16px",
  6631. class: "ss-sidebar-panel__icon",
  6632. })
  6633. : null,
  6634. Vue.h("span", null, this.title || "统计图"),
  6635. ]),
  6636. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6637. Vue.h(
  6638. "button",
  6639. {
  6640. type: "button",
  6641. class: {
  6642. "ss-sidebar-chart-tool": true,
  6643. "is-active": this.pinned,
  6644. },
  6645. title: this.pinned ? "取消固定" : "固定",
  6646. onClick: (e) => {
  6647. e.stopPropagation();
  6648. this.togglePin();
  6649. },
  6650. },
  6651. // 功能说明:右侧栏 hover 工具图标使用 ss-sidebar-base-icon(不复用左侧 menu-base-icon) by xu 20260123
  6652. [
  6653. Vue.h(SsIcon, {
  6654. class: this.pinned
  6655. ? "ss-sidebar-base-icon icon-fix-bold"
  6656. : "ss-sidebar-base-icon icon-fix",
  6657. }),
  6658. ]
  6659. ),
  6660. Vue.h(
  6661. "button",
  6662. {
  6663. type: "button",
  6664. class: "ss-sidebar-chart-tool",
  6665. title: "全屏",
  6666. onClick: (e) => {
  6667. e.stopPropagation();
  6668. this.toggleFullscreen();
  6669. },
  6670. },
  6671. [
  6672. Vue.h(SsIcon, {
  6673. class: this.fullscreen
  6674. ? "ss-sidebar-base-icon icon-fs-exit"
  6675. : "ss-sidebar-base-icon icon-fs",
  6676. }),
  6677. ]
  6678. ),
  6679. ]),
  6680. ]
  6681. )
  6682. : Vue.h(
  6683. "div",
  6684. {
  6685. class:
  6686. "ss-sidebar-chart-preview__header ss-sidebar-chart-preview__header--simple",
  6687. },
  6688. [
  6689. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6690. Vue.h(
  6691. "button",
  6692. {
  6693. type: "button",
  6694. class: {
  6695. "ss-sidebar-chart-tool": true,
  6696. "is-active": this.pinned,
  6697. },
  6698. title: this.pinned ? "取消固定" : "固定",
  6699. onClick: (e) => {
  6700. e.stopPropagation();
  6701. this.togglePin();
  6702. },
  6703. },
  6704. [
  6705. Vue.h(SsIcon, {
  6706. class: this.pinned
  6707. ? "ss-sidebar-base-icon icon-fix-bold"
  6708. : "ss-sidebar-base-icon icon-fix",
  6709. }),
  6710. ]
  6711. ),
  6712. Vue.h(
  6713. "button",
  6714. {
  6715. type: "button",
  6716. class: "ss-sidebar-chart-tool",
  6717. title: "全屏",
  6718. onClick: (e) => {
  6719. e.stopPropagation();
  6720. this.toggleFullscreen();
  6721. },
  6722. },
  6723. [
  6724. Vue.h(SsIcon, {
  6725. class: this.fullscreen
  6726. ? "ss-sidebar-base-icon icon-chk-on"
  6727. : "ss-sidebar-base-icon icon-chk",
  6728. }),
  6729. ]
  6730. ),
  6731. ]),
  6732. ]
  6733. ),
  6734. Vue.h("div", { class: "ss-sidebar-chart-preview__body" }, [
  6735. Vue.h(Chart, { options: this.options, height: "100%" }),
  6736. ]),
  6737. ]
  6738. );
  6739. const fullscreenContent =
  6740. this.fullscreen &&
  6741. Vue.h(
  6742. "div",
  6743. {
  6744. ref: "fullscreenRef",
  6745. class: "ss-sidebar-chart-fullscreen",
  6746. },
  6747. [
  6748. Vue.h(
  6749. "div",
  6750. {
  6751. class:
  6752. "ss-sidebar-panel__header ss-sidebar-chart-fullscreen__header",
  6753. },
  6754. [
  6755. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  6756. this.iconClass
  6757. ? Vue.h(SsIcon, {
  6758. class: this.iconClass + " ss-sidebar-panel__icon",
  6759. })
  6760. : this.icon
  6761. ? Vue.h(SsIcon, {
  6762. name: this.icon,
  6763. size: "16px",
  6764. class: "ss-sidebar-panel__icon",
  6765. })
  6766. : null,
  6767. Vue.h("span", null, this.title || "统计图"),
  6768. ]),
  6769. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6770. Vue.h(
  6771. "button",
  6772. {
  6773. type: "button",
  6774. class: {
  6775. "ss-sidebar-chart-tool": true,
  6776. "is-active": this.pinned,
  6777. },
  6778. title: this.pinned ? "取消固定" : "固定",
  6779. onClick: (e) => {
  6780. e.stopPropagation();
  6781. this.togglePin();
  6782. },
  6783. },
  6784. [
  6785. Vue.h(SsIcon, {
  6786. class: this.pinned
  6787. ? "ss-sidebar-base-icon icon-fix-bold"
  6788. : "ss-sidebar-base-icon icon-fix",
  6789. }),
  6790. ]
  6791. ),
  6792. Vue.h(
  6793. "button",
  6794. {
  6795. type: "button",
  6796. class: "ss-sidebar-chart-tool",
  6797. title: "退出全屏",
  6798. onClick: (e) => {
  6799. e.stopPropagation();
  6800. this.toggleFullscreen();
  6801. },
  6802. },
  6803. [
  6804. Vue.h(SsIcon, {
  6805. class: "ss-sidebar-base-icon icon-fs-exit",
  6806. }),
  6807. ]
  6808. ),
  6809. ]),
  6810. ]
  6811. ),
  6812. Vue.h("div", { class: "ss-sidebar-chart-fullscreen__body" }, [
  6813. Vue.h(Chart, { options: this.options, height: "100%" }),
  6814. ]),
  6815. ]
  6816. );
  6817. return Vue.h("div", { class: "ss-sidebar-chart-hover" }, [
  6818. Vue.h(
  6819. "div",
  6820. {
  6821. ref: "triggerRef",
  6822. class: "ss-sidebar-chart-hover__trigger",
  6823. onMouseenter: () => {
  6824. this.hoveringTrigger = true;
  6825. this.openPreview();
  6826. },
  6827. onMouseleave: () => {
  6828. this.hoveringTrigger = false;
  6829. this.scheduleClose();
  6830. },
  6831. },
  6832. [Vue.h(Chart, { options: this.options, height: this.height })]
  6833. ),
  6834. (this.open || this.fullscreen) &&
  6835. Vue.h(Vue.Teleport, { to: "body" }, [
  6836. this.open ? previewContent : null,
  6837. fullscreenContent || null,
  6838. ]),
  6839. ]);
  6840. },
  6841. };
  6842. // 组件文档补全(JSDoc) by xu 20260108
  6843. /**
  6844. * SsSidebarList(右侧业务面板:人员/已选/服务/预定...)
  6845. *
  6846. * 用途:
  6847. * - 统一渲染面板 header(图标/标题/数量/右侧按钮)
  6848. * - 统一渲染 list(固定行高、hover、右侧移除按钮等)
  6849. *
  6850. * 调用示例(由 ss-sidebar 通过 panels 配置驱动):
  6851. * ```js
  6852. * { type:'list', title:'已选', iconClass:'menu-icon icon-obj-xcd', mode:'selected', items:selectedItems, closable:true }
  6853. * ```
  6854. *
  6855. * Props(核心):
  6856. * - `title`:header 标题
  6857. * - `iconClass/icon`:header 图标(优先 iconClass)
  6858. * - `count`:数量回显(图表面板可不传)
  6859. * - `closable`:是否显示“清空”按钮(触发 emit clear)
  6860. * - `headerFilters`:header 条件数组(组件名 + props),用于联调接口搜索
  6861. * - `headerSearchButton`:是否显示搜索按钮(触发 emit search)
  6862. * - `items`:列表数据
  6863. * - `mode`:`selected` 时右侧按钮语义为“移除”
  6864. * - `itemLayout`:`simple` / `person`(人员号槽位)
  6865. * - `itemAction`:是否显示 item 右侧操作按钮(hover 才出现)
  6866. *
  6867. * Emits:
  6868. * - `remove(item)`:点击 item 右侧移除
  6869. * - `clear()`:点击 header 清空
  6870. * - `search({keyword, filters})`:点击 header 搜索
  6871. */
  6872. const SsSidebarList = {
  6873. name: "SsSidebarList",
  6874. props: {
  6875. title: { type: String, default: "" },
  6876. // header 图标:优先使用 iconClass(走 ss-icon v3.0 class 分支) by xu 20260106
  6877. iconClass: { type: String, default: "" },
  6878. icon: { type: String, default: "" }, // 兼容旧写法(ss-icon name)
  6879. count: { type: [Number, String], default: "" },
  6880. // 选中类分区:右侧关闭按钮=清空分区数据 by xu 20260106
  6881. closable: { type: Boolean, default: false },
  6882. searchable: { type: Boolean, default: false },
  6883. // 搜索框是否放在 header 内(人员块需要该布局) by xu 20260106
  6884. searchInHeader: { type: Boolean, default: false },
  6885. // header 搜索:下拉条件 + 搜索按钮(适合“人员”块) by xu 20260106
  6886. headerFilters: { type: Array, default: () => [] },
  6887. headerSearchButton: { type: Boolean, default: false },
  6888. searchPlaceholder: { type: String, default: "搜索" },
  6889. // 列表项布局:simple(仅标题) / person(标题+人员号槽位) by xu 20260106
  6890. itemLayout: { type: String, default: "simple" },
  6891. itemAction: { type: Boolean, default: true },
  6892. collapsible: { type: Boolean, default: true }, // 功能说明:是否允许双击 header 折叠/展开 by xu 20260116
  6893. collapsed: { type: Boolean, default: false }, // 功能说明:折叠态仅展示 header by xu 20260116
  6894. items: { type: Array, default: () => [] },
  6895. mode: { type: String, default: "search" }, // search / selected
  6896. },
  6897. emits: ["select", "remove", "clear", "search", "toggle-collapse"],
  6898. data() {
  6899. return {
  6900. keyword: "",
  6901. filterValues: {},
  6902. }; // 功能说明:折叠状态完全由 props.collapsed 驱动,避免多面板复用导致状态不同步 by xu 20260116
  6903. },
  6904. created() {
  6905. // header 下拉条件默认值初始化 by xu 20260106
  6906. (this.headerFilters || []).forEach((f) => {
  6907. if (!f || !f.key) return;
  6908. if (this.filterValues[f.key] !== undefined) return;
  6909. const first = f?.options?.[0]?.value ?? "";
  6910. this.filterValues[f.key] = f.value !== undefined ? f.value : first;
  6911. });
  6912. },
  6913. methods: {
  6914. __shouldIgnoreHeaderToggle(e) {
  6915. // 功能说明:忽略工具区/输入区触发折叠,避免误触 by xu 20260116
  6916. const t = e?.target;
  6917. if (!t || !t.closest) return false;
  6918. if (t.closest(".ss-sidebar-panel__tools")) return true;
  6919. if (t.closest(".ss-sidebar-panel__filters")) return true;
  6920. if (t.closest("input,textarea,select,button")) return true;
  6921. return false;
  6922. },
  6923. __toggleCollapseInternal(e, source) {
  6924. if (!this.collapsible) return;
  6925. if (this.__shouldIgnoreHeaderToggle(e)) return;
  6926. const nextCollapsed = !this.collapsed;
  6927. console.log("[SsSidebarList] toggle emit", {
  6928. title: this.title,
  6929. source,
  6930. to: nextCollapsed,
  6931. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  6932. // 功能说明:由父组件(SsSidebar.toggleSectionCollapse)统一控制 section 高度与折叠数组 by xu 20260116
  6933. this.$emit("toggle-collapse");
  6934. },
  6935. },
  6936. render() {
  6937. const items = this.items || [];
  6938. const SsIcon = Vue.resolveComponent("ss-icon");
  6939. const isSelectedMode = this.mode === "selected";
  6940. const activeKeyword = this.filterValues?.keyword ?? this.keyword; // 功能:keyword 优先取 headerFilters.keyword by xu 20260106
  6941. const hasHeaderKeyword = (this.headerFilters || []).some(
  6942. (f) => f?.key === "keyword"
  6943. ); // 功能:header 内 keyword 过滤 by xu 20260106
  6944. const renderHeaderFilter = (f) => {
  6945. if (!f) return null;
  6946. const key = f.key;
  6947. const componentName = f.component;
  6948. if (!key || !componentName) return null;
  6949. const Comp = Vue.resolveComponent(componentName);
  6950. if (!Comp) return null;
  6951. const modelValue = this.filterValues[key];
  6952. const props = f.props || {};
  6953. return Vue.h(Comp, {
  6954. ...props,
  6955. modelValue,
  6956. "onUpdate:modelValue": (v) => {
  6957. this.filterValues[key] = v;
  6958. },
  6959. });
  6960. };
  6961. const filteredItems =
  6962. this.searchable && activeKeyword
  6963. ? items.filter((it) =>
  6964. String(it?.title ?? "")
  6965. .toLowerCase()
  6966. .includes(String(activeKeyword).toLowerCase())
  6967. )
  6968. : items;
  6969. if (!filteredItems.length && !this.title) return null;
  6970. if (this.collapsed) {
  6971. return Vue.h("div", { class: "ss-sidebar-panel" }, [
  6972. this.title
  6973. ? Vue.h(
  6974. "div",
  6975. {
  6976. class: "ss-sidebar-panel__header",
  6977. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  6978. onDblclick: (e) => {
  6979. e?.preventDefault?.();
  6980. e?.stopPropagation?.();
  6981. console.log("[SsSidebarList] header dblclick", {
  6982. title: this.title,
  6983. collapsed: true,
  6984. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  6985. this.__toggleCollapseInternal(e, "dblclick");
  6986. },
  6987. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  6988. },
  6989. [
  6990. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  6991. this.iconClass
  6992. ? Vue.h(SsIcon, {
  6993. class: this.iconClass + " ss-sidebar-panel__icon",
  6994. })
  6995. : this.icon
  6996. ? Vue.h(SsIcon, {
  6997. name: this.icon,
  6998. size: "16px",
  6999. class: "ss-sidebar-panel__icon",
  7000. })
  7001. : null,
  7002. Vue.h("span", null, this.title),
  7003. this.count !== ""
  7004. ? Vue.h(
  7005. "span",
  7006. { class: "ss-sidebar-panel__count" },
  7007. `(${this.count})`
  7008. )
  7009. : null,
  7010. ]),
  7011. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7012. this.closable
  7013. ? Vue.h(
  7014. "button",
  7015. {
  7016. type: "button",
  7017. class: "ss-sidebar-icon-btn ss-sidebar-header-btn",
  7018. title: "清空",
  7019. onClick: (e) => {
  7020. e.stopPropagation();
  7021. this.$emit("clear");
  7022. },
  7023. },
  7024. [
  7025. Vue.h(SsIcon, {
  7026. class: "ss-sidebar-base-icon icon-cl",
  7027. }),
  7028. ] // 功能说明:右侧栏“已选”清空按钮图标使用 ss-sidebar-base-icon by xu 20260123
  7029. )
  7030. : null,
  7031. ]),
  7032. ]
  7033. )
  7034. : null,
  7035. ]);
  7036. }
  7037. return Vue.h("div", { class: "ss-sidebar-panel" }, [
  7038. this.title
  7039. ? Vue.h(
  7040. "div",
  7041. {
  7042. class: "ss-sidebar-panel__header",
  7043. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  7044. onDblclick: (e) => {
  7045. e?.preventDefault?.();
  7046. e?.stopPropagation?.();
  7047. console.log("[SsSidebarList] header dblclick", {
  7048. title: this.title,
  7049. collapsed: false,
  7050. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7051. this.__toggleCollapseInternal(e, "dblclick");
  7052. },
  7053. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  7054. },
  7055. [
  7056. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7057. // 图标 + 标题(每个分区都有) by xu 20260106
  7058. this.iconClass
  7059. ? Vue.h(SsIcon, {
  7060. class: this.iconClass + " ss-sidebar-panel__icon",
  7061. })
  7062. : this.icon
  7063. ? Vue.h(SsIcon, {
  7064. name: this.icon,
  7065. size: "16px",
  7066. class: "ss-sidebar-panel__icon",
  7067. })
  7068. : null,
  7069. Vue.h("span", null, this.title),
  7070. // 数量回显:图表分区可不传 count by xu 20260106
  7071. this.count !== ""
  7072. ? Vue.h(
  7073. "span",
  7074. { class: "ss-sidebar-panel__count" },
  7075. `(${this.count})`
  7076. )
  7077. : null,
  7078. ]),
  7079. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7080. // header 条件(例如下拉框)+ 右侧搜索按钮 by xu 20260106
  7081. this.headerFilters?.length
  7082. ? Vue.h(
  7083. "div",
  7084. { class: "ss-sidebar-panel__filters" },
  7085. this.headerFilters
  7086. .map(renderHeaderFilter)
  7087. .filter(Boolean)
  7088. )
  7089. : null,
  7090. this.headerSearchButton
  7091. ? Vue.h(
  7092. "button",
  7093. {
  7094. type: "button",
  7095. class: "ss-sidebar-icon-btn",
  7096. title: "搜索",
  7097. onClick: (e) => {
  7098. e.stopPropagation();
  7099. this.$emit("search", {
  7100. // headerFilters 内也可能包含 keyword by xu 20260106
  7101. keyword: activeKeyword,
  7102. filters: { ...(this.filterValues || {}) },
  7103. });
  7104. },
  7105. },
  7106. [Vue.h(SsIcon, { name: "search", size: "14px" })]
  7107. )
  7108. : null,
  7109. // 人员块:搜索框在 header 内 by xu 20260106
  7110. this.searchable &&
  7111. this.searchInHeader &&
  7112. !this.headerSearchButton
  7113. ? Vue.h(
  7114. "div",
  7115. { class: "ss-sidebar-panel__searchInline" },
  7116. [
  7117. Vue.h(
  7118. "div",
  7119. { class: "ss-sidebar-search is-inline" },
  7120. [
  7121. Vue.h(SsIcon, {
  7122. name: "search",
  7123. size: "14px",
  7124. class: "ss-sidebar-search__prefix",
  7125. }),
  7126. Vue.h("input", {
  7127. class: "ss-sidebar-search__input",
  7128. value: this.keyword,
  7129. placeholder: this.searchPlaceholder,
  7130. onInput: (e) => {
  7131. this.keyword = e?.target?.value ?? "";
  7132. },
  7133. }),
  7134. ]
  7135. ),
  7136. ]
  7137. )
  7138. : null,
  7139. this.closable
  7140. ? Vue.h(
  7141. "button",
  7142. {
  7143. type: "button",
  7144. class: "ss-sidebar-icon-btn ss-sidebar-header-btn",
  7145. title: "清空",
  7146. onClick: (e) => {
  7147. e.stopPropagation();
  7148. this.$emit("clear");
  7149. },
  7150. },
  7151. // 清空按钮使用 icon-base 的 icon-cl by xu 20260106
  7152. [
  7153. Vue.h(SsIcon, {
  7154. class: "ss-sidebar-base-icon icon-cl",
  7155. }),
  7156. ] // 功能说明:右侧栏清空按钮图标使用 ss-sidebar-base-icon by xu 20260123
  7157. )
  7158. : null,
  7159. ]),
  7160. ]
  7161. )
  7162. : null,
  7163. // 非 header 内搜索:独立一行 by xu 20260106
  7164. // headerSearchButton/headerFilters 已覆盖搜索能力时,不再额外渲染独立搜索行 by xu 20260106
  7165. this.searchable &&
  7166. !this.searchInHeader &&
  7167. !this.headerSearchButton &&
  7168. !hasHeaderKeyword
  7169. ? Vue.h("div", { class: "ss-sidebar-panel__search" }, [
  7170. Vue.h("div", { class: "ss-sidebar-search" }, [
  7171. Vue.h(SsIcon, {
  7172. name: "search",
  7173. size: "14px",
  7174. class: "ss-sidebar-search__prefix",
  7175. }),
  7176. Vue.h("input", {
  7177. class: "ss-sidebar-search__input",
  7178. value: this.keyword,
  7179. placeholder: this.searchPlaceholder,
  7180. onInput: (e) => {
  7181. this.keyword = e?.target?.value ?? "";
  7182. },
  7183. }),
  7184. ]),
  7185. ])
  7186. : null,
  7187. Vue.h(
  7188. "div",
  7189. { class: "ss-sidebar-list" },
  7190. filteredItems.map((item, idx) => {
  7191. const title = item?.title ?? "";
  7192. const tags = item?.tags || [];
  7193. const isPersonLayout = this.itemLayout === "person";
  7194. const hasTags = !isPersonLayout && tags?.length > 0; // 列表项垂直对齐:有 tags 顶对齐 by xu 20260106
  7195. return Vue.h(
  7196. "div",
  7197. {
  7198. class: {
  7199. "ss-sidebar-list-item": true,
  7200. "is-first": idx === 0,
  7201. "is-person": isPersonLayout,
  7202. "has-tags": hasTags,
  7203. },
  7204. },
  7205. [
  7206. Vue.h("div", { class: "ss-sidebar-list-item__main" }, [
  7207. Vue.h(
  7208. "div",
  7209. { class: "ss-sidebar-list-item__title" },
  7210. Vue.h(
  7211. "span",
  7212. {
  7213. style: {
  7214. "white-space": "nowrap",
  7215. overflow: "hidden",
  7216. "text-overflow": "ellipsis",
  7217. },
  7218. },
  7219. title
  7220. )
  7221. ),
  7222. // 非人员布局才显示 tags by xu 20260106
  7223. !isPersonLayout && tags?.length
  7224. ? Vue.h(
  7225. "div",
  7226. { class: "ss-sidebar-list-item__tags" },
  7227. tags.map((tag) => {
  7228. const [k, v] = Object.entries(tag)[0] || ["", ""];
  7229. return Vue.h(
  7230. "span",
  7231. { class: "ss-sidebar-tag", title: `${k}: ${v}` },
  7232. `${k}: ${v}`
  7233. );
  7234. })
  7235. )
  7236. : null,
  7237. ]),
  7238. // 人员布局:中间保留“人员号”槽位 by xu 20260106
  7239. isPersonLayout
  7240. ? Vue.h(
  7241. "div",
  7242. {
  7243. class: "ss-sidebar-list-item__meta",
  7244. title: String(item?.meta ?? ""),
  7245. },
  7246. item?.meta ?? ""
  7247. )
  7248. : null,
  7249. this.itemAction
  7250. ? Vue.h(
  7251. "button",
  7252. {
  7253. type: "button",
  7254. class: {
  7255. // item 操作按钮:默认无背景/无边框,hover 才高亮 by xu 20260106
  7256. "ss-sidebar-item-btn": true,
  7257. },
  7258. title: isSelectedMode ? "移除" : "选择",
  7259. onClick: (e) => {
  7260. e.stopPropagation();
  7261. if (isSelectedMode) this.$emit("remove", item);
  7262. else this.$emit("select", item);
  7263. },
  7264. },
  7265. [
  7266. // item 移除图标使用 icon-base 的 icon-cl by xu 20260106
  7267. isSelectedMode
  7268. ? Vue.h(SsIcon, {
  7269. class: "ss-sidebar-base-icon icon-cl",
  7270. }) // 功能说明:右侧栏 item 移除图标使用 ss-sidebar-base-icon by xu 20260123
  7271. : Vue.h(SsIcon, { name: "check", size: "14px" }),
  7272. ]
  7273. )
  7274. : null,
  7275. ]
  7276. );
  7277. })
  7278. ),
  7279. ]);
  7280. },
  7281. };
  7282. // ss-sidebar-report-table:右侧“统计表/报表”面板(pstatList grtjlbm=51 聚拢渲染) by xu 20260115
  7283. const SsSidebarReportTable = {
  7284. name: "SsSidebarReportTable",
  7285. props: {
  7286. title: { type: String, default: "" },
  7287. iconClass: { type: String, default: "" },
  7288. icon: { type: String, default: "" },
  7289. items: { type: Array, default: () => [] }, // pstatList(grtjlbm=51) 数组
  7290. onOpen: { type: Function, default: null }, // (srv, ctx) => void
  7291. collapsible: { type: Boolean, default: true }, // 功能说明:是否允许双击 header 折叠/展开 by xu 20260116
  7292. collapsed: { type: Boolean, default: false }, // 功能说明:折叠态仅展示 header by xu 20260116
  7293. },
  7294. emits: ["open", "toggle-collapse"],
  7295. data() {
  7296. return {}; // 功能说明:折叠状态完全由 props.collapsed 驱动 by xu 20260116
  7297. },
  7298. methods: {
  7299. __toggleCollapseInternal(e, source) {
  7300. if (!this.collapsible) return;
  7301. const next = !this.collapsed;
  7302. console.log("[SsSidebarReportTable] toggle emit", {
  7303. title: this.title,
  7304. source,
  7305. to: next,
  7306. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7307. this.$emit("toggle-collapse");
  7308. },
  7309. },
  7310. render() {
  7311. const SsIcon = Vue.resolveComponent("ss-icon");
  7312. const list = this.items || [];
  7313. if (!this.title && !list.length) return null;
  7314. const header = this.title
  7315. ? Vue.h(
  7316. "div",
  7317. {
  7318. class: "ss-sidebar-panel__header",
  7319. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  7320. onDblclick: (e) => {
  7321. e?.preventDefault?.();
  7322. e?.stopPropagation?.();
  7323. console.log("[SsSidebarReportTable] header dblclick", {
  7324. title: this.title,
  7325. collapsed: this.collapsed,
  7326. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7327. this.__toggleCollapseInternal(e, "dblclick");
  7328. },
  7329. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  7330. },
  7331. [
  7332. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7333. this.iconClass
  7334. ? Vue.h(SsIcon, {
  7335. class: this.iconClass + " ss-sidebar-panel__icon",
  7336. })
  7337. : this.icon
  7338. ? Vue.h(SsIcon, {
  7339. name: this.icon,
  7340. size: "16px",
  7341. class: "ss-sidebar-panel__icon",
  7342. })
  7343. : null,
  7344. Vue.h("span", null, this.title),
  7345. ]),
  7346. Vue.h("div", { class: "ss-sidebar-panel__tools" }),
  7347. ]
  7348. )
  7349. : null;
  7350. const renderReport = (report) => {
  7351. const title = String(report?.mc ?? "");
  7352. const mx = Array.isArray(report?.grtjmxList) ? report.grtjmxList : [];
  7353. if (!title && !mx.length) return null;
  7354. // 功能说明:每个报表对象渲染为一个 table(有边框、无圆角、表间距10px;样式由 base.css 统一控制) by xu 20260115
  7355. const cols = Math.max(1, mx.length);
  7356. // 功能说明:table 外层包一层 wrap,子项过多时支持横向滚动 by xu 20260115
  7357. return Vue.h("div", { class: "ss-sidebar-report-table-wrap" }, [
  7358. Vue.h("table", { class: "ss-sidebar-report-table" }, [
  7359. Vue.h("thead", null, [
  7360. Vue.h("tr", null, [
  7361. Vue.h(
  7362. "th",
  7363. { class: "ss-sidebar-report-table__title", colspan: cols },
  7364. Vue.h(
  7365. "div",
  7366. { class: "ss-sidebar-report-table__title-content" },
  7367. [
  7368. Vue.h("span", { class: "ss-sidebar-report-table__dot" }),
  7369. Vue.h(
  7370. "span",
  7371. { class: "ss-sidebar-report-table__title-text", title },
  7372. title
  7373. ),
  7374. ]
  7375. )
  7376. ),
  7377. ]),
  7378. ]),
  7379. Vue.h("tbody", null, [
  7380. Vue.h(
  7381. "tr",
  7382. null,
  7383. mx.map((cell) => {
  7384. const text = String(cell?.mc ?? "");
  7385. const srv = {
  7386. servName: cell?.fwm ?? "",
  7387. dest: cell?.bjm ?? "",
  7388. title: text,
  7389. width: cell?.width,
  7390. height: cell?.height,
  7391. minHeight: cell?.height,
  7392. maxHeight: cell?.height,
  7393. showTitle: text,
  7394. };
  7395. return Vue.h(
  7396. "td",
  7397. {
  7398. class: "ss-sidebar-report-table__cell",
  7399. title: text,
  7400. onClick: (e) => {
  7401. e?.stopPropagation?.();
  7402. try {
  7403. this.onOpen?.(srv, { report, cell });
  7404. } catch (_) {}
  7405. this.$emit("open", { report, cell, srv });
  7406. },
  7407. },
  7408. text
  7409. );
  7410. })
  7411. ),
  7412. ]),
  7413. ]),
  7414. ]);
  7415. };
  7416. // 功能说明:报表面板增加独立 class,便于 base.css 统一控制 padding/间距 by xu 20260115
  7417. return Vue.h(
  7418. "div",
  7419. { class: "ss-sidebar-panel ss-sidebar-report-panel" },
  7420. [
  7421. header,
  7422. this.collapsed
  7423. ? null
  7424. : Vue.h(
  7425. "div",
  7426. // 功能说明:报表列表滚动/高度样式下沉到 base.css,避免写在 DOM 上 by xu 20260115
  7427. { class: "ss-sidebar-report__list" },
  7428. list.map(renderReport).filter(Boolean)
  7429. ),
  7430. ]
  7431. );
  7432. },
  7433. };
  7434. // 组件文档补全(JSDoc) by xu 20260108
  7435. /**
  7436. * SsSidebar(objList 右侧边栏容器)
  7437. *
  7438. * 用途:
  7439. * - 统一渲染顶部按钮栏(buttons)
  7440. * - 统一渲染中间业务面板(list panels,可拖拽调高度)
  7441. * - 统一渲染底部图表(chart panels,内部用 ss-sidebar-chart-hover)
  7442. *
  7443. * 调用示例:
  7444. * ```html
  7445. * <ss-sidebar :buttons="sidebarButtons" :panels="sidebarPanels" @remove="handleSidebarRemove" />
  7446. * ```
  7447. *
  7448. * Props:
  7449. * - `buttons`:顶部按钮配置数组
  7450. * - `panels`:分区配置数组(`type: 'list' | 'chart'`)
  7451. *
  7452. * Events(向外透传):
  7453. * - `remove(item)`:来自 list 面板移除
  7454. * - `select(item)`:来自 list 面板选择(如后续需要)
  7455. */
  7456. const SsSidebar = {
  7457. name: "SsSidebar",
  7458. props: {
  7459. buttons: { type: Array, default: () => [] },
  7460. charts: { type: Array, default: () => [] },
  7461. list: { type: Array, default: () => [] }, // legacy
  7462. listMode: { type: String, default: "search" }, // legacy
  7463. panels: { type: Array, default: () => [] },
  7464. },
  7465. emits: ["select", "remove"],
  7466. data() {
  7467. return {
  7468. // 业务面板高度(索引 -> px) by xu 20260106
  7469. sectionHeights: [],
  7470. sectionCollapsed: [], // 功能说明:面板折叠状态(sectionPanels 索引) by xu 20260116
  7471. sectionHeightsExpanded: [], // 功能说明:面板展开高度缓存(用于折叠后恢复) by xu 20260116
  7472. sectionLastItemCounts: [], // 功能说明:记录栏目数据量,供“无数据默认关闭/已选自动展开”规则复用 by xu 20260313
  7473. chartCollapsed: [], // 功能说明:图表面板折叠状态(chartPanels 索引) by xu 20260116
  7474. chartHeaderTitleDownAt: [], // 功能说明:双击检测绑定到 chart 标题区 by xu 20260116
  7475. reportCollapsed: [], // 功能说明:报表面板折叠状态(reportPanels 索引) by xu 20260116
  7476. resizeTimer: null,
  7477. resizing: false,
  7478. resizeIndex: -1,
  7479. resizeStartY: 0,
  7480. resizeStartPrev: 0,
  7481. resizeStartNext: 0,
  7482. __resizeMoveHandler: null, // 功能说明:显式绑定 this 的 pointermove handler,避免 addEventListener 场景 this 丢失导致拖拽无效 by xu 20260122
  7483. __resizeEndHandler: null, // 功能说明:显式绑定 this 的 pointerup handler,确保能正确结束拖拽 by xu 20260122
  7484. __resizeCancelHandler: null, // 功能说明:显式绑定 this 的 pointercancel handler,触控取消也能收尾 by xu 20260122
  7485. __resizePrevSectionEl: null, // 功能说明:拖拽时直接写 DOM 高度(修复响应式更新不生效) by xu 20260122
  7486. __resizeNextSectionEl: null, // 功能说明:拖拽时直接写 DOM 高度(修复响应式更新不生效) by xu 20260122
  7487. };
  7488. },
  7489. methods: {
  7490. // 初始化默认高度(只在第一次/面板数量变化时补齐) by xu 20260106
  7491. ensureSectionHeights(sectionCount) {
  7492. if (!Array.isArray(this.sectionHeights)) this.sectionHeights = [];
  7493. if (this.sectionHeights.length === sectionCount) return;
  7494. const next = [];
  7495. for (let i = 0; i < sectionCount; i++) {
  7496. next[i] = this.sectionHeights[i] ?? 190; // 默认高度 by xu 20260106
  7497. }
  7498. this.sectionHeights = next;
  7499. // 功能说明:面板数量变化时补齐折叠/缓存数组长度 by xu 20260116
  7500. this.sectionCollapsed = Array.from(
  7501. { length: sectionCount },
  7502. (_, i) => !!this.sectionCollapsed?.[i]
  7503. );
  7504. this.sectionHeightsExpanded = Array.from(
  7505. { length: sectionCount },
  7506. (_, i) => this.sectionHeightsExpanded?.[i] ?? null
  7507. );
  7508. this.sectionLastItemCounts = Array.from(
  7509. { length: sectionCount },
  7510. (_, i) => Number(this.sectionLastItemCounts?.[i] ?? 0) || 0
  7511. );
  7512. },
  7513. __getPanelsForSectionState(panelsInput) {
  7514. return (panelsInput || []).length
  7515. ? panelsInput
  7516. : this.list?.length
  7517. ? [
  7518. {
  7519. type: "list",
  7520. title: "已选",
  7521. icon: "",
  7522. mode: this.listMode,
  7523. items: this.list,
  7524. },
  7525. ]
  7526. : [];
  7527. },
  7528. __getSectionPanelsForState(panelsInput) {
  7529. return this.__getPanelsForSectionState(panelsInput)
  7530. .filter((p) => {
  7531. const k = String(p?._tabKey ?? "")
  7532. .trim()
  7533. .toLowerCase();
  7534. const t = String(p?.title ?? "").trim();
  7535. if (k === "rbarobj") return false;
  7536. if (t === "对象") return false;
  7537. return true;
  7538. })
  7539. .filter((p) => p?.type !== "chart" && p?.type !== "report-table");
  7540. },
  7541. __getSectionPanelCount(panel) {
  7542. const explicitCount = Number(panel?.count);
  7543. if (Number.isFinite(explicitCount)) return explicitCount;
  7544. return Array.isArray(panel?.items) ? panel.items.length : 0;
  7545. },
  7546. __setSectionCollapsedState(index, collapsed) {
  7547. const i = Number(index);
  7548. if (isNaN(i) || i < 0) return;
  7549. const nextCollapsed = !!collapsed;
  7550. const collapsedHeight = 37;
  7551. const cur = !!this.sectionCollapsed?.[i];
  7552. const currentHeight = Number(this.sectionHeights?.[i] ?? 190) || 190;
  7553. if (nextCollapsed === cur) {
  7554. if (nextCollapsed && currentHeight !== collapsedHeight) {
  7555. this.sectionHeights.splice(i, 1, collapsedHeight);
  7556. }
  7557. return;
  7558. }
  7559. if (nextCollapsed) {
  7560. this.sectionHeightsExpanded[i] =
  7561. currentHeight > collapsedHeight
  7562. ? currentHeight
  7563. : Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  7564. this.sectionHeights.splice(i, 1, collapsedHeight);
  7565. } else {
  7566. const restore =
  7567. Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  7568. this.sectionHeights.splice(i, 1, restore);
  7569. }
  7570. this.sectionCollapsed.splice(i, 1, nextCollapsed);
  7571. },
  7572. __syncSectionAutoCollapse(panelsInput) {
  7573. const sectionPanels = this.__getSectionPanelsForState(panelsInput);
  7574. const sectionCount = sectionPanels.length;
  7575. this.ensureSectionHeights(sectionCount);
  7576. const prevCounts = Array.isArray(this.sectionLastItemCounts)
  7577. ? this.sectionLastItemCounts.slice()
  7578. : [];
  7579. const nextCounts = Array.from({ length: sectionCount }, (_, i) =>
  7580. this.__getSectionPanelCount(sectionPanels[i])
  7581. );
  7582. this.sectionLastItemCounts = nextCounts;
  7583. sectionPanels.forEach((panel, index) => {
  7584. const count = Number(nextCounts[index] ?? 0) || 0;
  7585. const prevCount = Number(prevCounts[index] ?? 0) || 0;
  7586. const title = String(panel?.title ?? "").trim();
  7587. if (count <= 0) {
  7588. this.__setSectionCollapsedState(index, true);
  7589. return;
  7590. }
  7591. if (title === "已选" && count > prevCount) {
  7592. this.__setSectionCollapsedState(index, false);
  7593. }
  7594. });
  7595. },
  7596. toggleSectionCollapse(index) {
  7597. // 功能说明:双击 header 折叠/展开 section 面板(仅控制高度与内容渲染) by xu 20260116
  7598. const i = Number(index);
  7599. if (isNaN(i) || i < 0) return;
  7600. // 功能说明:加更细粒度日志,定位“多面板折叠无视觉效果”的根因(高度是否真的变、DOM 是否更新) by xu 20260116
  7601. const collapsedHeight = 37; // 功能说明:header(35) + panel 边框(2),避免 flex shrink 导致 header 变 25px by xu 20260116
  7602. const cur = !!this.sectionCollapsed?.[i];
  7603. console.log("[SsSidebar] toggleSectionCollapse", {
  7604. index: i,
  7605. to: !cur,
  7606. prevHeight: this.sectionHeights?.[i],
  7607. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7608. if (!cur) {
  7609. this.sectionHeightsExpanded[i] = this.sectionHeights[i] ?? 190;
  7610. this.sectionHeights.splice(i, 1, collapsedHeight);
  7611. } else {
  7612. const restore =
  7613. Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  7614. this.sectionHeights.splice(i, 1, restore);
  7615. }
  7616. this.sectionCollapsed.splice(i, 1, !cur);
  7617. console.log("[SsSidebar] section state(after)", {
  7618. index: i,
  7619. height: this.sectionHeights?.[i],
  7620. collapsed: this.sectionCollapsed?.[i],
  7621. allHeights: Array.from(this.sectionHeights || []),
  7622. allCollapsed: Array.from(this.sectionCollapsed || []),
  7623. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7624. Vue.nextTick(() => {
  7625. try {
  7626. const root = this.$el;
  7627. const sections = root?.querySelectorAll?.(".ss-sidebar-section");
  7628. const el = sections?.[i];
  7629. const rectH = el?.getBoundingClientRect?.().height;
  7630. console.log("[SsSidebar] section dom(beforeFix)", {
  7631. index: i,
  7632. styleHeight: el?.style?.height,
  7633. rectH,
  7634. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7635. // 功能说明:若渲染未把 height patch 到 DOM,则在 nextTick 强制同步一次(并打印) by xu 20260116
  7636. const targetH =
  7637. (Number(this.sectionHeights?.[i] ?? 190) || 190) + "px";
  7638. if (el && el.style && el.style.height !== targetH) {
  7639. el.style.height = targetH;
  7640. }
  7641. if (el?.classList) {
  7642. el.classList.toggle("is-collapsed", !!this.sectionCollapsed?.[i]);
  7643. }
  7644. const rectAfter = el?.getBoundingClientRect?.().height;
  7645. console.log("[SsSidebar] section dom(afterFix)", {
  7646. index: i,
  7647. styleHeight: el?.style?.height,
  7648. rectH: rectAfter,
  7649. targetH,
  7650. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7651. } catch (err) {
  7652. console.log("[SsSidebar] section dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7653. }
  7654. });
  7655. },
  7656. toggleChartCollapse(index) {
  7657. // 功能说明:双击 header 折叠/展开底部 chart 面板(隐藏/显示 chart-hover) by xu 20260116
  7658. const i = Number(index);
  7659. if (isNaN(i) || i < 0) return;
  7660. const cur = !!this.chartCollapsed?.[i];
  7661. console.log("[SsSidebar] toggleChartCollapse", { index: i, to: !cur }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7662. this.chartCollapsed.splice(i, 1, !cur);
  7663. console.log("[SsSidebar] chart state(after)", {
  7664. index: i,
  7665. collapsed: this.chartCollapsed?.[i],
  7666. allCollapsed: Array.from(this.chartCollapsed || []),
  7667. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7668. Vue.nextTick(() => {
  7669. try {
  7670. const root = this.$el;
  7671. const el = root?.querySelector?.(
  7672. `.ss-sidebar-chart-panel[data-chart-idx="${i}"]`
  7673. );
  7674. console.log("[SsSidebar] chart dom(beforeFix)", {
  7675. index: i,
  7676. found: !!el,
  7677. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7678. if (el?.classList)
  7679. el.classList.toggle("is-collapsed", !!this.chartCollapsed?.[i]);
  7680. console.log("[SsSidebar] chart dom(afterFix)", {
  7681. index: i,
  7682. collapsed: !!this.chartCollapsed?.[i],
  7683. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7684. } catch (err) {
  7685. console.log("[SsSidebar] chart dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7686. }
  7687. });
  7688. },
  7689. toggleReportCollapse(index) {
  7690. // 功能说明:双击 header 折叠/展开底部 report-table 面板(隐藏/显示表格) by xu 20260116
  7691. const i = Number(index);
  7692. if (isNaN(i) || i < 0) return;
  7693. const cur = !!this.reportCollapsed?.[i];
  7694. console.log("[SsSidebar] toggleReportCollapse", { index: i, to: !cur }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7695. this.reportCollapsed.splice(i, 1, !cur);
  7696. console.log("[SsSidebar] report state(after)", {
  7697. index: i,
  7698. collapsed: this.reportCollapsed?.[i],
  7699. allCollapsed: Array.from(this.reportCollapsed || []),
  7700. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7701. Vue.nextTick(() => {
  7702. try {
  7703. const root = this.$el;
  7704. const el = root?.querySelector?.(
  7705. `.ss-sidebar-report-panel[data-report-idx="${i}"]`
  7706. );
  7707. console.log("[SsSidebar] report dom(beforeFix)", {
  7708. index: i,
  7709. found: !!el,
  7710. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7711. if (el?.classList)
  7712. el.classList.toggle("is-collapsed", !!this.reportCollapsed?.[i]);
  7713. console.log("[SsSidebar] report dom(afterFix)", {
  7714. index: i,
  7715. collapsed: !!this.reportCollapsed?.[i],
  7716. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7717. } catch (err) {
  7718. console.log("[SsSidebar] report dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7719. }
  7720. });
  7721. },
  7722. startResize(index, e) {
  7723. if (e?.preventDefault) e.preventDefault();
  7724. if (e?.stopPropagation) e.stopPropagation();
  7725. if (this.resizing) return;
  7726. // 长按 0.5s 后才进入拖拽调高度 by xu 20260106
  7727. clearTimeout(this.resizeTimer);
  7728. // 功能说明:修复“长按拖拽偶发失效/卡死”——pointerup 早于 500ms 时必须取消 timer,否则 timer 触发后进入 resizing=true 且再也收不到 pointerup,导致后续都无法拖拽 by xu 20260122
  7729. const pointerId = e?.pointerId;
  7730. const cancelPendingResize = (ev) => {
  7731. try {
  7732. if (
  7733. pointerId != null &&
  7734. ev?.pointerId != null &&
  7735. ev.pointerId !== pointerId
  7736. )
  7737. return;
  7738. } catch (_) {}
  7739. clearTimeout(this.resizeTimer);
  7740. this.resizeTimer = null;
  7741. document.removeEventListener("pointerup", cancelPendingResize, true);
  7742. document.removeEventListener(
  7743. "pointercancel",
  7744. cancelPendingResize,
  7745. true
  7746. );
  7747. };
  7748. // 功能说明:用 document+capture 监听,避免 window 监听在部分容器/iframe 场景丢事件导致拖拽无响应 by xu 20260122
  7749. document.addEventListener("pointerup", cancelPendingResize, {
  7750. passive: false,
  7751. once: true,
  7752. capture: true,
  7753. });
  7754. document.addEventListener("pointercancel", cancelPendingResize, {
  7755. passive: false,
  7756. once: true,
  7757. capture: true,
  7758. });
  7759. const startY = e?.clientY ?? 0;
  7760. const gapEl = e?.currentTarget;
  7761. // 功能说明:记录 gap 前后 section 节点,拖拽过程中直接写入 style.height,避免某些环境下 Vue render 不刷新导致“拖拽无视觉变化” by xu 20260122
  7762. this.__resizePrevSectionEl = gapEl?.previousElementSibling || null;
  7763. this.__resizeNextSectionEl = gapEl?.nextElementSibling || null;
  7764. this.resizeTimer = setTimeout(() => {
  7765. // 定时器触发后进入拖拽态,移除“取消等待”监听,避免误取消 by xu 20260122
  7766. document.removeEventListener("pointerup", cancelPendingResize, true);
  7767. document.removeEventListener(
  7768. "pointercancel",
  7769. cancelPendingResize,
  7770. true
  7771. );
  7772. this.resizing = true;
  7773. this.resizeIndex = index;
  7774. this.resizeStartY = startY;
  7775. this.resizeStartPrev = this.sectionHeights[index] ?? 190;
  7776. this.resizeStartNext = this.sectionHeights[index + 1] ?? 190;
  7777. gapEl?.classList?.add("is-active");
  7778. try {
  7779. if (gapEl?.setPointerCapture && pointerId != null)
  7780. gapEl.setPointerCapture(pointerId);
  7781. } catch (_) {} // 功能说明:捕获 pointer,避免拖拽过程中移出窗口导致 pointermove 丢失 by xu 20260122
  7782. // 功能说明:用 document+capture,确保拖拽时 pointermove/up 不会被中途 stopPropagation 影响 by xu 20260122
  7783. document.addEventListener(
  7784. "pointermove",
  7785. this.__resizeMoveHandler || this.onResizeMove,
  7786. { passive: false, capture: true }
  7787. );
  7788. document.addEventListener(
  7789. "pointerup",
  7790. this.__resizeEndHandler || this.endResize,
  7791. { passive: false, once: true, capture: true }
  7792. );
  7793. document.addEventListener(
  7794. "pointercancel",
  7795. this.__resizeCancelHandler || this.endResize,
  7796. { passive: false, once: true, capture: true }
  7797. ); // 功能说明:触控/手势取消时也要结束拖拽 by xu 20260122
  7798. }, 500);
  7799. },
  7800. onResizeMove(e) {
  7801. if (!this.resizing) return;
  7802. if (e?.preventDefault) e.preventDefault();
  7803. const dy = (e?.clientY ?? 0) - this.resizeStartY;
  7804. const minPanelHeight = 83; // header(35) + listMin(48) by xu 20260106
  7805. const prev = Math.max(minPanelHeight, this.resizeStartPrev + dy);
  7806. const next = Math.max(minPanelHeight, this.resizeStartNext - dy);
  7807. // 若其中一个达到最小值,则停止继续挤压 by xu 20260106
  7808. const adjustedDy = prev - this.resizeStartPrev;
  7809. const nextAdjusted = this.resizeStartNext - adjustedDy;
  7810. const appliedPrev = prev;
  7811. const appliedNext = Math.max(minPanelHeight, nextAdjusted);
  7812. this.sectionHeights.splice(this.resizeIndex, 1, appliedPrev);
  7813. this.sectionHeights.splice(this.resizeIndex + 1, 1, appliedNext);
  7814. // 功能说明:强制触发一次 sectionHeights 引用变化,避免某些运行时环境下 splice 未触发视图更新导致“拖拽没反应” by xu 20260122
  7815. this.sectionHeights = (this.sectionHeights || []).slice();
  7816. // 功能说明:兜底——直接写 DOM 的 height,确保视觉立即响应(用于排查/修复某些环境下 render 不更新) by xu 20260122
  7817. try {
  7818. if (this.__resizePrevSectionEl?.style)
  7819. this.__resizePrevSectionEl.style.height = appliedPrev + "px";
  7820. if (this.__resizeNextSectionEl?.style)
  7821. this.__resizeNextSectionEl.style.height = appliedNext + "px";
  7822. } catch (_) {}
  7823. },
  7824. endResize(e) {
  7825. clearTimeout(this.resizeTimer);
  7826. this.resizeTimer = null;
  7827. if (!this.resizing) return;
  7828. if (e?.preventDefault) e.preventDefault();
  7829. const activeGaps = document.querySelectorAll(
  7830. ".ss-sidebar-gap.is-active"
  7831. );
  7832. activeGaps.forEach((g) => g.classList.remove("is-active"));
  7833. this.resizing = false;
  7834. this.resizeIndex = -1;
  7835. this.__resizePrevSectionEl = null; // 功能说明:释放 DOM 引用,避免内存泄漏 by xu 20260122
  7836. this.__resizeNextSectionEl = null; // 功能说明:释放 DOM 引用,避免内存泄漏 by xu 20260122
  7837. document.removeEventListener(
  7838. "pointermove",
  7839. this.__resizeMoveHandler || this.onResizeMove,
  7840. true
  7841. );
  7842. document.removeEventListener(
  7843. "pointercancel",
  7844. this.__resizeCancelHandler || this.endResize,
  7845. true
  7846. ); // 功能说明:清理 cancel 监听,避免残留 by xu 20260122
  7847. },
  7848. },
  7849. watch: {
  7850. panels: {
  7851. handler(nextPanels) {
  7852. this.__syncSectionAutoCollapse(nextPanels);
  7853. },
  7854. deep: true,
  7855. immediate: true,
  7856. },
  7857. list: {
  7858. handler(nextList) {
  7859. if ((this.panels || []).length) return;
  7860. this.__syncSectionAutoCollapse(nextList);
  7861. },
  7862. deep: true,
  7863. immediate: true,
  7864. },
  7865. },
  7866. mounted() {
  7867. clearTimeout(this.resizeTimer);
  7868. this.resizeTimer = null;
  7869. // 功能说明:绑定拖拽事件 handler(用于 add/removeEventListener) by xu 20260122
  7870. if (!this.__resizeMoveHandler)
  7871. this.__resizeMoveHandler = (e) => this.onResizeMove?.(e);
  7872. if (!this.__resizeEndHandler)
  7873. this.__resizeEndHandler = (e) => this.endResize?.(e);
  7874. if (!this.__resizeCancelHandler)
  7875. this.__resizeCancelHandler = (e) => this.endResize?.(e);
  7876. // 功能说明:暂时回退为固定底部留白方案(CSS 控制),后续再定位遮挡根因 by xu 20260115
  7877. },
  7878. beforeUnmount() {
  7879. clearTimeout(this.resizeTimer);
  7880. this.resizeTimer = null;
  7881. document.removeEventListener(
  7882. "pointermove",
  7883. this.__resizeMoveHandler || this.onResizeMove,
  7884. true
  7885. );
  7886. document.removeEventListener(
  7887. "pointerup",
  7888. this.__resizeEndHandler || this.endResize,
  7889. true
  7890. );
  7891. document.removeEventListener(
  7892. "pointercancel",
  7893. this.__resizeCancelHandler || this.endResize,
  7894. true
  7895. );
  7896. },
  7897. render() {
  7898. const SsSidebarButtonsComp = Vue.resolveComponent("ss-sidebar-buttons");
  7899. const SsSidebarChartComp = Vue.resolveComponent("ss-sidebar-chart");
  7900. const SsSidebarListComp = Vue.resolveComponent("ss-sidebar-list");
  7901. const SsSidebarReportTableComp = Vue.resolveComponent(
  7902. "ss-sidebar-report-table"
  7903. );
  7904. const SsIcon = Vue.resolveComponent("ss-icon");
  7905. // 支持 panels(多分区),list/listMode 作为 legacy 兜底 by xu 20260106
  7906. const panels = (this.panels || []).length
  7907. ? this.panels
  7908. : this.list?.length
  7909. ? [
  7910. {
  7911. type: "list",
  7912. title: "已选",
  7913. icon: "",
  7914. mode: this.listMode,
  7915. items: this.list,
  7916. },
  7917. ]
  7918. : [];
  7919. // 功能说明:右侧栏强制移除“对象”tab(兼容后端返回 rbarObj/rbarobj 或直接返回中文“对象”标题) by xu 20260116
  7920. const panelsNoObj = (panels || []).filter((p) => {
  7921. const k = String(p?._tabKey ?? "")
  7922. .trim()
  7923. .toLowerCase();
  7924. const t = String(p?.title ?? "").trim();
  7925. if (k === "rbarobj") return false;
  7926. if (t === "对象") return false;
  7927. return true;
  7928. });
  7929. // 功能说明:report-table 作为底部报表区(放在统计图下面),不参与可拖拽 section 面板 by xu 20260115
  7930. const sectionPanels = panelsNoObj.filter(
  7931. (p) => p?.type !== "chart" && p?.type !== "report-table"
  7932. );
  7933. const chartPanels = panelsNoObj.filter((p) => p?.type === "chart");
  7934. const reportPanels = panelsNoObj.filter(
  7935. (p) => p?.type === "report-table"
  7936. );
  7937. this.ensureSectionHeights(sectionPanels.length);
  7938. // 功能说明:补齐 chart/report 折叠数组长度 by xu 20260116
  7939. this.chartCollapsed = Array.from(
  7940. { length: chartPanels.length },
  7941. (_, i) => !!this.chartCollapsed?.[i]
  7942. );
  7943. this.chartHeaderTitleDownAt = Array.from(
  7944. { length: chartPanels.length },
  7945. (_, i) => this.chartHeaderTitleDownAt?.[i] ?? 0
  7946. );
  7947. this.reportCollapsed = Array.from(
  7948. { length: reportPanels.length },
  7949. (_, i) => !!this.reportCollapsed?.[i]
  7950. );
  7951. return Vue.h("div", { class: "ss-sidebar" }, [
  7952. this.buttons?.length
  7953. ? Vue.h(SsSidebarButtonsComp, { items: this.buttons })
  7954. : null,
  7955. Vue.h(
  7956. "div",
  7957. { class: "ss-sidebar__inner" },
  7958. [
  7959. ...(this.charts || []).map((c) =>
  7960. Vue.h(SsSidebarChartComp, {
  7961. options: c?.options || {},
  7962. height: c?.height || "200px",
  7963. })
  7964. ),
  7965. // 可拖拽的业务面板容器 by xu 20260106
  7966. Vue.h(
  7967. "div",
  7968. { class: "ss-sidebar-sections", style: { flex: "0 0 auto" } },
  7969. sectionPanels.flatMap((p, idx) => {
  7970. const panelContent =
  7971. p?.type === "report-table"
  7972. ? Vue.h(SsSidebarReportTableComp, {
  7973. key: `ss-sidebar-report-in-section-${idx}-${
  7974. p?.title ?? ""
  7975. }`,
  7976. title: p?.title ?? "",
  7977. icon: p?.icon ?? "",
  7978. iconClass: p?.iconClass ?? "",
  7979. items: p?.items || [],
  7980. onOpen: (srv, ctx) => p?.onOpen?.(srv, ctx),
  7981. })
  7982. : Vue.h(SsSidebarListComp, {
  7983. key: `ss-sidebar-list-${idx}-${p?.title ?? ""}`,
  7984. title: p?.title ?? "",
  7985. icon: p?.icon ?? "",
  7986. count: p?.count ?? p?.items?.length ?? "",
  7987. closable: !!p?.closable,
  7988. searchable: !!p?.searchable,
  7989. searchInHeader: !!p?.searchInHeader,
  7990. headerFilters: p?.headerFilters || [],
  7991. headerSearchButton: !!p?.headerSearchButton,
  7992. searchPlaceholder: p?.searchPlaceholder ?? "搜索",
  7993. itemLayout: p?.itemLayout ?? "simple",
  7994. itemAction: p?.itemAction ?? true,
  7995. collapsible: true,
  7996. collapsed: !!this.sectionCollapsed?.[idx],
  7997. onToggleCollapse: () =>
  7998. this.toggleSectionCollapse?.(idx),
  7999. iconClass: p?.iconClass ?? "",
  8000. items: p?.items || [],
  8001. mode: p?.mode || "search",
  8002. onSelect: (item) => this.$emit("select", item),
  8003. onRemove: (item) => this.$emit("remove", item),
  8004. onClear: () => p?.onClear?.(),
  8005. onSearch: (payload) => p?.onSearch?.(payload),
  8006. });
  8007. const section = Vue.h(
  8008. "div",
  8009. {
  8010. class: {
  8011. "ss-sidebar-section": true,
  8012. "is-collapsed": !!this.sectionCollapsed?.[idx],
  8013. },
  8014. key: `ss-sidebar-section-${idx}-${p?.type ?? "list"}-${
  8015. p?.title ?? ""
  8016. }`,
  8017. style: {
  8018. height: (this.sectionHeights[idx] ?? 190) + "px",
  8019. flex: "0 0 auto",
  8020. },
  8021. },
  8022. [
  8023. Vue.h("div", { class: "ss-sidebar-section__content" }, [
  8024. panelContent,
  8025. ]),
  8026. ]
  8027. );
  8028. const gap =
  8029. idx < sectionPanels.length - 1
  8030. ? Vue.h("div", {
  8031. class: "ss-sidebar-gap",
  8032. onPointerdown: (e) => this.startResize(idx, e),
  8033. })
  8034. : null;
  8035. return gap ? [section, gap] : [section];
  8036. })
  8037. ),
  8038. // 图表区固定在底部(hover 弹出大图) by xu 20260106
  8039. ...chartPanels.map((p, chartIdx) =>
  8040. Vue.h(
  8041. "div",
  8042. {
  8043. class: {
  8044. "ss-sidebar-panel": true,
  8045. "ss-sidebar-chart-panel": true,
  8046. "is-collapsed": !!this.chartCollapsed?.[chartIdx],
  8047. },
  8048. style: { flex: "0 0 auto", minHeight: "37px" },
  8049. "data-chart-idx": chartIdx,
  8050. key: `ss-sidebar-chart-${chartIdx}-${p?.title ?? ""}`,
  8051. },
  8052. [
  8053. p?.title
  8054. ? Vue.h(
  8055. "div",
  8056. {
  8057. class: "ss-sidebar-panel__header",
  8058. onDblclick: (e) => {
  8059. e?.preventDefault?.();
  8060. e?.stopPropagation?.();
  8061. console.log("[SsSidebar] chart header dblclick", {
  8062. idx: chartIdx,
  8063. title: p?.title,
  8064. });
  8065. this.toggleChartCollapse?.(chartIdx);
  8066. },
  8067. },
  8068. [
  8069. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  8070. p?.iconClass
  8071. ? Vue.h(SsIcon, {
  8072. class:
  8073. p.iconClass + " ss-sidebar-panel__icon",
  8074. })
  8075. : p?.icon
  8076. ? Vue.h(SsIcon, {
  8077. name: p.icon,
  8078. size: "16px",
  8079. class: "ss-sidebar-panel__icon",
  8080. })
  8081. : null,
  8082. Vue.h("span", null, p.title),
  8083. ]),
  8084. Vue.h("div", { class: "ss-sidebar-panel__tools" }),
  8085. ]
  8086. )
  8087. : null,
  8088. this.chartCollapsed?.[chartIdx]
  8089. ? null
  8090. : Vue.h(Vue.resolveComponent("ss-sidebar-chart-hover"), {
  8091. title: p?.title ?? "",
  8092. iconClass: p?.iconClass ?? "",
  8093. icon: p?.icon ?? "",
  8094. options: p?.options || {},
  8095. height: p?.height || "240px",
  8096. }),
  8097. ]
  8098. )
  8099. ),
  8100. ...reportPanels.map((p, reportIdx) =>
  8101. Vue.h(
  8102. "div",
  8103. {
  8104. class: {
  8105. "ss-sidebar-report-panel-wrap": true,
  8106. "ss-sidebar-report-panel": true,
  8107. "is-collapsed": !!this.reportCollapsed?.[reportIdx],
  8108. },
  8109. style: { flex: "0 0 auto", minHeight: "37px" },
  8110. "data-report-idx": reportIdx,
  8111. key: `ss-sidebar-report-wrap-${reportIdx}-${p?.title ?? ""}`,
  8112. },
  8113. [
  8114. Vue.h(SsSidebarReportTableComp, {
  8115. key: `ss-sidebar-report-${reportIdx}-${p?.title ?? ""}`,
  8116. title: p?.title ?? "",
  8117. icon: p?.icon ?? "",
  8118. iconClass: p?.iconClass ?? "",
  8119. items: p?.items || [],
  8120. collapsible: true,
  8121. collapsed: !!this.reportCollapsed?.[reportIdx],
  8122. onToggleCollapse: () =>
  8123. this.toggleReportCollapse?.(reportIdx),
  8124. onOpen: (srv, ctx) => p?.onOpen?.(srv, ctx),
  8125. }),
  8126. ]
  8127. )
  8128. ),
  8129. ].filter(Boolean)
  8130. ),
  8131. ]);
  8132. },
  8133. };
  8134. // ss-folder-card 文件夹卡片
  8135. const SsFolderCard = {
  8136. name: "SsFolderCard",
  8137. props: {
  8138. item: {
  8139. type: Object,
  8140. required: true,
  8141. },
  8142. },
  8143. data() {
  8144. return {
  8145. showButtons: false,
  8146. };
  8147. },
  8148. emits: ["click", "change"],
  8149. setup(props, { emit }) {
  8150. const item = props.item;
  8151. const showChildren = ref(false);
  8152. const eventBus = window.parent.sharedEventBus;
  8153. const itemWidth = Vue.computed(() => {
  8154. // 功能说明:页面改为 grid 等分布局后,卡片宽度交给容器控制,这里固定 100% by xu 20260116
  8155. return "100%";
  8156. });
  8157. onMounted(() => {
  8158. eventBus.subscribe("folderPath", (path) => {
  8159. const currentPath = path || [];
  8160. // 如果当前文件夹不在路径中,则销毁视图
  8161. if (
  8162. !currentPath.some((item) => item.folder.title === props.item.title)
  8163. ) {
  8164. showChildren.value = false;
  8165. }
  8166. });
  8167. });
  8168. const onItemClick = (e) => {
  8169. if (e && e.stopPropagation) {
  8170. e.stopPropagation();
  8171. }
  8172. // 单击只处理 active 状态
  8173. if (e && e.currentTarget) {
  8174. const allListCards = document.querySelectorAll(
  8175. ".knowledge-item-container"
  8176. );
  8177. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8178. allListCards.forEach((card) => card.classList.remove("active"));
  8179. allFolderCards.forEach((card) => card.classList.remove("active"));
  8180. e.currentTarget.classList.add("active");
  8181. } else {
  8182. // 如果是数据对象,需要找到对应的 DOM 元素
  8183. const allListCards = document.querySelectorAll(
  8184. ".knowledge-item-container"
  8185. );
  8186. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8187. allListCards.forEach((card) => card.classList.remove("active"));
  8188. allFolderCards.forEach((card) => card.classList.remove("active"));
  8189. // 找到标题匹配的文件夹元素
  8190. const targetFolder = Array.from(allFolderCards).find((card) =>
  8191. card.textContent.includes(e.title)
  8192. );
  8193. if (targetFolder) {
  8194. targetFolder.classList.add("active");
  8195. }
  8196. }
  8197. emit("click", item);
  8198. };
  8199. // 修改双击处理函数
  8200. const handleFolderDblClick = (folder, e) => {
  8201. if (e) e.stopPropagation();
  8202. if (folder.children?.length) {
  8203. showChildren.value = true;
  8204. const pathInfo = {
  8205. title: folder.title,
  8206. folder: folder,
  8207. };
  8208. const currentPath = eventBus.getState("folderPath") || [];
  8209. if (!currentPath.some((item) => item.title === folder.title)) {
  8210. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  8211. }
  8212. }
  8213. };
  8214. const onItemChange = (e, icon, index) => {
  8215. e.stopPropagation();
  8216. props.item.buttons[0].onclick();
  8217. // emit("change", { item: props.item, icon, index });
  8218. };
  8219. return {
  8220. item,
  8221. itemWidth,
  8222. showChildren,
  8223. onItemClick,
  8224. onItemChange,
  8225. handleFolderDblClick,
  8226. };
  8227. },
  8228. render() {
  8229. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  8230. if (this.showChildren) {
  8231. return h(SsFolderCartView, {
  8232. folder: this.item,
  8233. });
  8234. }
  8235. return Vue.h(
  8236. "div",
  8237. {
  8238. class: { "ss-folder-list": true, active: this.item.active },
  8239. onClick: (e) => {
  8240. e.stopPropagation();
  8241. this.onItemClick(e);
  8242. },
  8243. onDblclick: (e) => this.handleFolderDblClick(this.item, e),
  8244. style: { width: this.itemWidth },
  8245. },
  8246. [
  8247. // 文件夹特有的装饰元素
  8248. Vue.h("div", { class: "ss-folder-list-trapezoid" }),
  8249. Vue.h("div", { class: "ss-folder-list-top-transparent" }),
  8250. Vue.h("div", { class: "ss-folder-list-top" }),
  8251. Vue.h("div", { class: "ss-folder-list-right" }),
  8252. // header 部分(按钮)
  8253. this.item?.buttons?.length > 0 &&
  8254. Vue.h(
  8255. "div",
  8256. {
  8257. class: "header",
  8258. onMouseenter: () => (this.showButtons = true),
  8259. onMouseleave: () => (this.showButtons = false),
  8260. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  8261. },
  8262. [
  8263. // this.item?.buttons?.length > 0 &&
  8264. Vue.h("div", {
  8265. class: "cart-list-setting cart-list-icon",
  8266. title: this.item?.buttons?.[0]?.title,
  8267. }),
  8268. // this.item?.buttons?.length > 0 &&
  8269. this.showButtons &&
  8270. this.item?.buttons?.length > 1 &&
  8271. Vue.h(
  8272. "div",
  8273. {
  8274. class: "cart-list-button-popup",
  8275. },
  8276. this.item.buttons.map((btn) =>
  8277. Vue.h(
  8278. "div",
  8279. {
  8280. onClick: (e) => {
  8281. e.stopPropagation();
  8282. btn.onclick?.();
  8283. },
  8284. },
  8285. [
  8286. btn.class &&
  8287. Vue.h(SsCartListIcon, {
  8288. class: [btn.class],
  8289. }),
  8290. Vue.h("span", null, btn.title),
  8291. ]
  8292. )
  8293. )
  8294. ),
  8295. ]
  8296. ),
  8297. // body 部分
  8298. Vue.h("div", { class: "body" }, [
  8299. Vue.h("div", { class: "box-header" }, [
  8300. Vue.h("div", null, this.item.title),
  8301. ]),
  8302. Vue.h(
  8303. "div",
  8304. {
  8305. class: !this.item.thumb ? "no-thumb box-body" : "box-body",
  8306. },
  8307. [
  8308. this.item.thumb
  8309. ? Vue.h("div", { class: "left" }, [
  8310. Vue.h("img", {
  8311. src: this.item.thumb,
  8312. alt: "Thumbnail",
  8313. class: "imgUnHandle",
  8314. style: {
  8315. "object-fit": "cover",
  8316. width: "100%",
  8317. height: "100%",
  8318. },
  8319. }),
  8320. ])
  8321. : null,
  8322. Vue.h("div", { class: "right" }, [
  8323. ...this.item.tags.map((tag) => {
  8324. const [key, value] = Object.entries(tag)[0];
  8325. return Vue.h(
  8326. "div",
  8327. {
  8328. class: "title",
  8329. title: `${key}: ${value}`,
  8330. },
  8331. `${key}: ${value}`
  8332. );
  8333. }),
  8334. ]),
  8335. ]
  8336. ),
  8337. ]),
  8338. ]
  8339. );
  8340. },
  8341. };
  8342. // SsFolderCartView 组件 - 用于显示文件夹内容
  8343. const SsFolderCartView = {
  8344. name: "SsFolderCartView",
  8345. props: {
  8346. folder: {
  8347. type: Object,
  8348. required: true,
  8349. },
  8350. },
  8351. emits: ["click"],
  8352. setup(props, { emit }) {
  8353. const eventBus = window.parent.sharedEventBus;
  8354. const currentFolder = ref(props.folder);
  8355. const showChildren = ref(false);
  8356. const onItemClick = (e) => {
  8357. if (e && e.stopPropagation) {
  8358. e.stopPropagation();
  8359. }
  8360. // 单击只处理 active 状态
  8361. if (e && e.currentTarget) {
  8362. const allListCards = document.querySelectorAll(
  8363. ".knowledge-item-container"
  8364. );
  8365. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8366. allListCards.forEach((card) => card.classList.remove("active"));
  8367. allFolderCards.forEach((card) => card.classList.remove("active"));
  8368. e.currentTarget.classList.add("active");
  8369. } else {
  8370. // 如果是数据对象,需要找到对应的 DOM 元素
  8371. const allListCards = document.querySelectorAll(
  8372. ".knowledge-item-container"
  8373. );
  8374. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8375. allListCards.forEach((card) => card.classList.remove("active"));
  8376. allFolderCards.forEach((card) => card.classList.remove("active"));
  8377. // 找到标题匹配的文件夹元素
  8378. const targetFolder = Array.from(allFolderCards).find((card) =>
  8379. card.textContent.includes(e.title)
  8380. );
  8381. if (targetFolder) {
  8382. targetFolder.classList.add("active");
  8383. }
  8384. }
  8385. emit("click", props.folder);
  8386. };
  8387. const handleFolderDblClick = (folder, e) => {
  8388. if (e) e.stopPropagation();
  8389. if (folder.children?.length) {
  8390. showChildren.value = true;
  8391. const pathInfo = {
  8392. title: folder.title,
  8393. folder: folder,
  8394. };
  8395. const currentPath = eventBus.getState("folderPath") || [];
  8396. if (!currentPath.some((item) => item.title === folder.title)) {
  8397. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  8398. currentFolder.value = folder;
  8399. }
  8400. }
  8401. };
  8402. const goBack = (targetFolder) => {
  8403. if (targetFolder === null) {
  8404. // 返回根目录
  8405. eventBus.publish("folderPath", []);
  8406. } else {
  8407. currentFolder.value = targetFolder;
  8408. }
  8409. };
  8410. return {
  8411. currentFolder,
  8412. showChildren,
  8413. onItemClick,
  8414. handleFolderDblClick,
  8415. goBack,
  8416. };
  8417. },
  8418. render() {
  8419. return h(
  8420. "div",
  8421. {
  8422. class: "page-container",
  8423. style: {
  8424. position: "fixed",
  8425. top: 0,
  8426. left: 0,
  8427. width: "100%",
  8428. height: "100%",
  8429. background: "var(--lightgray)",
  8430. padding: "20px 0",
  8431. zIndex: 1000,
  8432. },
  8433. },
  8434. [
  8435. // 搜索栏
  8436. h("div", { class: "search-bar" }, [
  8437. h("div", { class: "search-bar-contaienr" }, [
  8438. h(SsBreadcrumb, {
  8439. level: {
  8440. onBack: this.goBack,
  8441. },
  8442. }),
  8443. ]),
  8444. ]),
  8445. // 内容区域
  8446. h(
  8447. "div",
  8448. {
  8449. class: "content-area item-content-area",
  8450. style: { gap: "20px" },
  8451. },
  8452. [
  8453. ...(this.currentFolder.children || []).map((child, index) =>
  8454. h(child.children ? SsFolderCard : SsListCard, {
  8455. key: index,
  8456. item: child,
  8457. onClick: (e) => this.onItemClick(e),
  8458. onDblclick: (e) => this.handleFolderDblClick(child, e),
  8459. })
  8460. ),
  8461. ]
  8462. ),
  8463. ]
  8464. );
  8465. },
  8466. };
  8467. // ss-page分页
  8468. const SsPage = {
  8469. name: "SsPage",
  8470. props: {
  8471. total: {
  8472. type: Number,
  8473. required: true,
  8474. },
  8475. size: {
  8476. type: Number,
  8477. default: 10,
  8478. },
  8479. page: {
  8480. type: Number,
  8481. default: 1,
  8482. },
  8483. onChange: {
  8484. type: Function,
  8485. default: () => {},
  8486. },
  8487. },
  8488. setup(props) {
  8489. const totalItems = ref(props.total); // 总条目数
  8490. const totalPages = ref(Math.ceil(props.total / props.size));
  8491. const currentPage = ref(props.page); // 当前页码
  8492. // 计算显示的信息
  8493. const pageInfo = ref(
  8494. `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`
  8495. );
  8496. // 上一页的逻辑
  8497. const goToPreviousPage = (e) => {
  8498. e.preventDefault(); // 阻止默认行为
  8499. if (currentPage.value > 1) {
  8500. currentPage.value -= 1;
  8501. updatePageInfo();
  8502. props.onChange?.({
  8503. pageNo: currentPage.value, // 当前页码
  8504. rowNumPer: props.size, // 每页条数
  8505. rowNum: props.total, // 总记录数
  8506. });
  8507. }
  8508. };
  8509. // 下一页的逻辑
  8510. const goToNextPage = (e) => {
  8511. e.preventDefault(); // 阻止默认行为
  8512. if (currentPage.value < totalPages.value) {
  8513. currentPage.value += 1;
  8514. updatePageInfo();
  8515. props.onChange?.({
  8516. pageNo: currentPage.value, // 当前页码
  8517. rowNumPer: props.size, // 每页条数
  8518. rowNum: props.total, // 总记录数
  8519. });
  8520. }
  8521. };
  8522. // 更新页码信息的函数
  8523. const updatePageInfo = () => {
  8524. pageInfo.value = `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`;
  8525. };
  8526. return {
  8527. pageInfo,
  8528. totalPages,
  8529. goToPreviousPage,
  8530. goToNextPage,
  8531. };
  8532. },
  8533. render(props, { slots, emit }) {
  8534. return Vue.h("div", { class: "pager-container" }, [
  8535. Vue.h("input", { type: "hidden", name: "rowNum", value: props.total }),
  8536. Vue.h("input", {
  8537. type: "hidden",
  8538. name: "rowNumPer",
  8539. value: props.size,
  8540. }),
  8541. Vue.h("input", {
  8542. type: "hidden",
  8543. name: "pageCount",
  8544. value: this.totalPages,
  8545. }),
  8546. Vue.h("input", { type: "hidden", name: "pageNo", value: props.page }),
  8547. Vue.h("div", { class: "pager-content" }, [
  8548. Vue.h("div", { class: "info" }, this.pageInfo),
  8549. Vue.h(
  8550. "div",
  8551. { class: "btn" },
  8552. Vue.h(
  8553. "button",
  8554. { onClick: (e) => this.goToPreviousPage(e) },
  8555. "上一页"
  8556. )
  8557. ),
  8558. Vue.h(
  8559. "div",
  8560. { class: "btn" },
  8561. Vue.h("button", { onClick: (e) => this.goToNextPage(e) }, "下一页")
  8562. ),
  8563. ]),
  8564. ]);
  8565. },
  8566. };
  8567. // ss-right-info 一级页面右边栏
  8568. const SSRightInfo = {
  8569. name: "SSRightInfo",
  8570. setup() {
  8571. // 初始化响应式数据
  8572. const item = ref({
  8573. thumb: "images/example/project-img.png", // 更换为适合你项目的实际路径
  8574. title: "工业和信息化产业高质量发展资金",
  8575. });
  8576. return {
  8577. item,
  8578. };
  8579. },
  8580. render() {
  8581. return Vue.h("div", { class: "info-container" }, [
  8582. Vue.h("div", { class: "header" }, [
  8583. Vue.h("div", [
  8584. Vue.h("img", {
  8585. src: this.item.thumb,
  8586. class: "imgUnHandle",
  8587. style: { "object-fit": "cover", width: "100%", height: "100%" },
  8588. }), // 将 ImageViewer 替换为 img 标签
  8589. ]),
  8590. Vue.h("div", [Vue.h("div", this.item.title)]),
  8591. ]),
  8592. Vue.h("div", { class: "section-container" }, [
  8593. Vue.h("div", { class: "section" }, [
  8594. Vue.h("div", { class: "title" }, "合同"),
  8595. Vue.h("div", { class: "text" }, "合同总金额:42,399,320"),
  8596. Vue.h(
  8597. "div",
  8598. { class: "a" },
  8599. "《工业和信息化产业高质量发展资金补助合同》"
  8600. ),
  8601. ]),
  8602. Vue.h("div", { class: "section" }, [
  8603. Vue.h("div", { class: "title" }, "发票"),
  8604. Vue.h("div", { class: "text" }, "应开发票总额:42,399,320"),
  8605. Vue.h("div", { class: "text" }, "已开发票金额:17,235,345"),
  8606. Vue.h("div", { class: "text" }, "未开发票金额:25,163,975"),
  8607. ]),
  8608. Vue.h("div", { class: "section" }, [
  8609. Vue.h("div", { class: "title" }, "项目组成员"),
  8610. Vue.h("div", { class: "text" }, "我司:3人"),
  8611. Vue.h("div", { class: "text" }, "对方:2人"),
  8612. Vue.h("div", { class: "text" }, "项目负责人:张三"),
  8613. ]),
  8614. Vue.h("div", { class: "section" }, [
  8615. Vue.h("div", { class: "title" }, "采购"),
  8616. Vue.h("div", { class: "text" }, "总额:999,320"),
  8617. Vue.h("div", { class: "text" }, "已付金额:335,345"),
  8618. Vue.h("div", { class: "text" }, "未付金额:663,975"),
  8619. ]),
  8620. ]),
  8621. ]);
  8622. },
  8623. };
  8624. //
  8625. const SsSuccessPopup = {
  8626. name: "SsSuccessPopup",
  8627. props: {
  8628. right: {
  8629. type: String,
  8630. default: "20px",
  8631. },
  8632. bottom: {
  8633. type: String,
  8634. default: "calc(100% + 5px)",
  8635. },
  8636. },
  8637. setup(props, { expose }) {
  8638. // 响应式状态:是否可见
  8639. const visible = ref(false);
  8640. // 计算样式
  8641. const style = computed(() => {
  8642. return {
  8643. "--message-dialog-right": props.right,
  8644. "--message-dialog-bottom": props.bottom,
  8645. };
  8646. });
  8647. // 显示对话框的方法
  8648. const show = () => {
  8649. visible.value = true;
  8650. };
  8651. // 隐藏对话框的方法
  8652. const hide = () => {
  8653. visible.value = false;
  8654. };
  8655. // 将方法暴露给外部使用
  8656. expose({ show, hide });
  8657. // 返回渲染函数
  8658. return () => {
  8659. if (!visible.value) return null;
  8660. const SsIcon = resolveComponent("ss-icon");
  8661. return h(
  8662. "div",
  8663. {
  8664. class: "success-popup",
  8665. style: style.value,
  8666. onClick: (e) => e.stopPropagation(),
  8667. },
  8668. [
  8669. h("div", { class: "left" }, [
  8670. h("div", { class: "icon" }, [
  8671. h(SsIcon, { name: "check", size: "36px" }),
  8672. ]),
  8673. ]),
  8674. h("div", { class: "right" }, [
  8675. h("div", { class: "title" }, "提交成功"),
  8676. h("div", { class: "desc" }, "您的信息已成功提交。"),
  8677. ]),
  8678. ]
  8679. );
  8680. };
  8681. },
  8682. };
  8683. const SsErrorDialog = {
  8684. name: "SsErrorDialog",
  8685. setup(props, { emit }) {
  8686. const visible = ref(false);
  8687. const style = computed(() => {
  8688. return {};
  8689. });
  8690. const show = () => {
  8691. visible.value = true;
  8692. };
  8693. const hide = () => {
  8694. visible.value = false;
  8695. };
  8696. const onBack = () => {
  8697. emit("back");
  8698. hide();
  8699. };
  8700. return {
  8701. visible,
  8702. style,
  8703. show,
  8704. hide,
  8705. onBack,
  8706. };
  8707. },
  8708. render() {
  8709. const SsIcon = resolveComponent("ss-icon");
  8710. return this.visible
  8711. ? h(
  8712. "div",
  8713. {
  8714. class: "errorDialog",
  8715. style: this.style,
  8716. onClick: (event) => event.stopPropagation(),
  8717. },
  8718. [
  8719. h("div", { class: "body" }, [
  8720. h("div", { class: "left" }, [
  8721. h("div", { class: "icon" }, [
  8722. h(SsIcon, { name: "close", size: "36px" }),
  8723. ]),
  8724. ]),
  8725. h("div", { class: "right" }, [
  8726. h("div", { class: "title" }, "操作失败"),
  8727. h("div", { class: "desc" }, "请点击返回以继续。"),
  8728. ]),
  8729. ]),
  8730. h("div", { class: "footer" }, [
  8731. h("div", { class: "left" }),
  8732. h("div", { class: "right" }, [
  8733. h(
  8734. "div",
  8735. {
  8736. class: "btn",
  8737. onClick: this.onBack,
  8738. },
  8739. [h(SsIcon, { name: "arrow-left-line" }), h("div", "返回")]
  8740. ),
  8741. ]),
  8742. ]),
  8743. ]
  8744. )
  8745. : null;
  8746. },
  8747. };
  8748. /**
  8749. * 审核链条
  8750. * @name ss-verify
  8751. * @param { Array } verify-list 审核节点列表
  8752. * @property { Array } verify-list 审核节点列表
  8753. * @example <ss-verify :verify-list="verifyList"></ss-verify>
  8754. * verify-list [
  8755. * {
  8756. * groupName: "", // 群组名称
  8757. * open: true, // 默认是否展开
  8758. * children:[ //群组里的人员
  8759. * {
  8760. * thumb: "images/example/user-4.png", // 头像
  8761. * name: "李丽思 ", // 姓名
  8762. * role: "人事处处长", // 角色
  8763. * description: "同意。", // 审核意见
  8764. * time: "09:38 08/11", // 审核时间
  8765. * video: false, // false不显示/true显示 视频icon
  8766. * link: false, // false不显示/true显示 链接icon 后续应该是附件
  8767. * }
  8768. * ]
  8769. * }
  8770. * ]
  8771. */
  8772. const SsVerify = {
  8773. name: "SsVerify",
  8774. props: {
  8775. verifyList: {
  8776. type: Array,
  8777. required: true,
  8778. },
  8779. },
  8780. setup(props) {
  8781. const toggleOpen = (item) => {
  8782. item.open = !item.open;
  8783. };
  8784. onMounted(() => {
  8785. setTimeout(() => {
  8786. const lastOpenGroup = document.querySelector(".group-item-last-open");
  8787. console.log("lastOpenGroup", lastOpenGroup);
  8788. if (lastOpenGroup) {
  8789. const nodes = $(lastOpenGroup).find(".verify-node-container");
  8790. if (nodes.length) {
  8791. let totalHeight = 0;
  8792. const gudingHeight = 100;
  8793. if (nodes.length === 1) {
  8794. totalHeight = gudingHeight;
  8795. } else {
  8796. // 累加除最后一个节点外的所有节点高度
  8797. for (let i = 0; i < nodes.length - 1; i++) {
  8798. totalHeight += $(nodes[i]).outerHeight();
  8799. }
  8800. totalHeight += gudingHeight;
  8801. }
  8802. console.log("节点信息:", {
  8803. 节点总数: nodes.length,
  8804. 计算后的高度: totalHeight,
  8805. });
  8806. lastOpenGroup.style.setProperty(
  8807. "--group-line-height",
  8808. `${totalHeight}px`
  8809. );
  8810. }
  8811. }
  8812. }, 0);
  8813. });
  8814. return {
  8815. toggleOpen,
  8816. };
  8817. },
  8818. render() {
  8819. const SsIcon = resolveComponent("ss-icon");
  8820. const SsCommonIcon = resolveComponent("ss-common-icon");
  8821. const SsVerifyNode = resolveComponent("ss-verify-node");
  8822. return h(
  8823. "div",
  8824. { class: "verify-nodes" },
  8825. this.verifyList.map((item, i) =>
  8826. h(
  8827. "div",
  8828. {
  8829. key: i,
  8830. class: {
  8831. "group-item": true,
  8832. "group-item-last-open":
  8833. i === this.verifyList.length - 1 && item.open,
  8834. },
  8835. },
  8836. [
  8837. h(
  8838. "div",
  8839. {
  8840. class: "group-item-title",
  8841. onClick: () => this.toggleOpen(item),
  8842. },
  8843. [
  8844. h("div", { class: "icon" }, [
  8845. item.open
  8846. ? h(SsCommonIcon, { class: "common-icon-folder-open" })
  8847. : h(SsCommonIcon, { class: "common-icon-folder-close" }),
  8848. h(
  8849. "div",
  8850. {
  8851. class: "num",
  8852. style: { top: item.open ? "60%" : "55%" },
  8853. },
  8854. item.children?.length || 0
  8855. ),
  8856. ]),
  8857. h("div", { class: "name" }, item.groupName),
  8858. ]
  8859. ),
  8860. item.open && item.children?.length > 0
  8861. ? h(
  8862. "div",
  8863. { class: "group-item-children" },
  8864. item.children.map((citem, j) =>
  8865. h(SsVerifyNode, {
  8866. key: j,
  8867. item: citem,
  8868. // isGroup: i + 1 !== this.verifyList.length,
  8869. isGroup: true,
  8870. })
  8871. )
  8872. )
  8873. : null,
  8874. ]
  8875. )
  8876. )
  8877. );
  8878. },
  8879. };
  8880. /**
  8881. * 审核页面的审核节点
  8882. * @name ss-verify-node
  8883. * @param {Object} item 审核节点信息
  8884. * @param {Boolean} isGroup 是否为分组节点
  8885. */
  8886. const SsVerifyNode = {
  8887. name: "SsVerifyNode",
  8888. props: {
  8889. item: {
  8890. type: Object,
  8891. required: true,
  8892. },
  8893. isGroup: {
  8894. type: Boolean,
  8895. default: false,
  8896. },
  8897. },
  8898. render() {
  8899. const SsIcon = resolveComponent("ss-icon");
  8900. const SsCommonIcon = resolveComponent("ss-common-icon");
  8901. return Vue.h("div", { class: "verify-node-container" }, [
  8902. Vue.h("div", { class: "info" }, [
  8903. Vue.h("div", { class: "avatar" }, [
  8904. Vue.h("img", {
  8905. src: this.item.thumb,
  8906. style: {
  8907. width: "50px",
  8908. height: "50px",
  8909. borderRadius: "50%",
  8910. },
  8911. }),
  8912. ]),
  8913. Vue.h("div", { class: "desc" }, [
  8914. Vue.h("div", this.item.name),
  8915. Vue.h("div", this.item.role),
  8916. ]),
  8917. Vue.h("div", { class: "link" }, [
  8918. Vue.h("div", [
  8919. this.item.video
  8920. ? Vue.h(SsCommonIcon, { class: "common-icon-video" })
  8921. : null,
  8922. this.item.link
  8923. ? Vue.h(SsCommonIcon, {
  8924. class: "common-icon-paper-clip",
  8925. })
  8926. : null,
  8927. ]),
  8928. ]),
  8929. ]),
  8930. Vue.h(
  8931. "div",
  8932. {
  8933. class: {
  8934. description: true,
  8935. link: this.isGroup,
  8936. },
  8937. attrs: { "data-num": "3" },
  8938. },
  8939. [Vue.h("div", this.item.description)]
  8940. ),
  8941. Vue.h("div", { class: "time" }, this.item.time),
  8942. ]);
  8943. },
  8944. };
  8945. /**
  8946. * 智能识别图片的左侧图片播放 可以放大缩小旋转图片
  8947. * @name ss-orc-img-box
  8948. * @param { Object } image-obj 包含图片的url, 和图片的名称
  8949. *
  8950. */
  8951. const SsOrcImgBox = {
  8952. name: "SsOrcImgBox",
  8953. props: {
  8954. imageObj: {
  8955. type: Object,
  8956. required: true,
  8957. },
  8958. },
  8959. setup(props) {
  8960. const zoom = ref(1);
  8961. const rotation = ref(0);
  8962. const containerWidth = ref(0);
  8963. const containerHeight = ref(0);
  8964. const container = ref(null);
  8965. const imgPosition = ref({ x: 0, y: 0 });
  8966. const isDragging = ref(false);
  8967. const lastMousePosition = ref({ x: 0, y: 0 });
  8968. const imgStyle = computed(() => ({
  8969. width: `${zoom.value * 100}%`,
  8970. height: `${zoom.value * 100}%`,
  8971. transform: `rotate(${rotation.value}deg) translate(${imgPosition.value.x}px, ${imgPosition.value.y}px)`,
  8972. transformOrigin: "center center",
  8973. cursor: isDragging.value ? "grabbing" : "grab",
  8974. }));
  8975. const resetZoom = () => {
  8976. zoom.value = 1;
  8977. rotation.value = rotation.value + 90;
  8978. imgPosition.value = { x: 0, y: 0 };
  8979. };
  8980. const handleRangeChange = (event) => {
  8981. const value = event.target.value / 50; // 0 到 100 映射到 0 到 2 的缩放
  8982. zoom.value = Math.max(value, 0.1); // 设置最小缩放值为 0.1
  8983. };
  8984. const updateImgBoxDimensions = () => {
  8985. if (container.value) {
  8986. containerWidth.value = container.value.clientWidth;
  8987. containerHeight.value = container.value.clientHeight;
  8988. }
  8989. };
  8990. const onMouseDown = (event) => {
  8991. isDragging.value = true;
  8992. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  8993. };
  8994. const onMouseMove = (event) => {
  8995. if (isDragging.value) {
  8996. const dx = event.clientX - lastMousePosition.value.x;
  8997. const dy = event.clientY - lastMousePosition.value.y;
  8998. // 防止旋转后拖动的x,y反转
  8999. // 首先将当前旋转角度从度数转换为弧度,因为 JavaScript 的 Math 库使用弧度
  9000. const angle = rotation.value * (Math.PI / 180);
  9001. // 使用基本的二维旋转矩阵将原始位移 dx 和 dy 转换为旋转后的位移 rotatedDx 和 rotatedDy。
  9002. const rotatedDx = dx * Math.cos(angle) + dy * Math.sin(angle);
  9003. const rotatedDy = dy * Math.cos(angle) - dx * Math.sin(angle);
  9004. imgPosition.value = {
  9005. x: imgPosition.value.x + rotatedDx,
  9006. y: imgPosition.value.y + rotatedDy,
  9007. };
  9008. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  9009. }
  9010. };
  9011. const onMouseUp = () => {
  9012. isDragging.value = false;
  9013. };
  9014. onMounted(() => {
  9015. nextTick(() => {
  9016. updateImgBoxDimensions();
  9017. window.addEventListener("resize", updateImgBoxDimensions);
  9018. window.addEventListener("mousemove", onMouseMove);
  9019. window.addEventListener("mouseup", onMouseUp);
  9020. });
  9021. });
  9022. return {
  9023. zoom,
  9024. rotation,
  9025. container,
  9026. imgStyle,
  9027. resetZoom,
  9028. handleRangeChange,
  9029. containerWidth,
  9030. containerHeight,
  9031. onMouseDown,
  9032. imgPosition,
  9033. };
  9034. },
  9035. render() {
  9036. const SsIcon = resolveComponent("ss-icon");
  9037. return h("div", { class: "ocr-img-box" }, [
  9038. h("div", { class: "img-bar" }, [
  9039. h("div", this.imageObj.name),
  9040. h("div", { class: "action-bar" }, [
  9041. h("div", { class: "ocr-img-range-box" }, [
  9042. h("input", {
  9043. type: "range",
  9044. min: 0,
  9045. max: 100,
  9046. value: this.zoom * 50, // 初始位置为50
  9047. onInput: this.handleRangeChange,
  9048. }),
  9049. h("span", { class: "line" }),
  9050. ]),
  9051. h(SsIcon, {
  9052. name: "reset",
  9053. size: "26px",
  9054. onClick: this.resetZoom,
  9055. }),
  9056. ]),
  9057. ]),
  9058. h("div", { class: "img-viewer", ref: "container" }, [
  9059. h(
  9060. "div",
  9061. {
  9062. class: "img-box",
  9063. style: {
  9064. width: `${this.containerWidth}px`,
  9065. height: `${this.containerHeight}px`,
  9066. overflow: "hidden",
  9067. position: "relative",
  9068. },
  9069. },
  9070. [
  9071. h("img", {
  9072. src: this.imageObj.thumb,
  9073. style: this.imgStyle,
  9074. class: "zoomable-img",
  9075. onMousedown: this.onMouseDown,
  9076. }),
  9077. ]
  9078. ),
  9079. ]),
  9080. ]);
  9081. },
  9082. };
  9083. // 搜索输入框组件
  9084. const SsSearchInput = {
  9085. name: "SsSearchInput",
  9086. props: {
  9087. name: String,
  9088. placeholder: String,
  9089. width: {
  9090. type: String,
  9091. default: "100px",
  9092. },
  9093. modelValue: String,
  9094. },
  9095. emits: ["update:modelValue", "search"],
  9096. setup(props, { emit }) {
  9097. const handleInput = (e) => {
  9098. emit("update:modelValue", e.target.value);
  9099. };
  9100. const handleKeyup = (e) => {
  9101. if (e.key === "Enter") {
  9102. emit("search");
  9103. }
  9104. };
  9105. return { handleInput, handleKeyup };
  9106. },
  9107. render() {
  9108. return h(
  9109. "div",
  9110. {
  9111. class: "input",
  9112. style: this.width ? { width: this.width } : undefined,
  9113. },
  9114. [
  9115. h("input", {
  9116. name: this.name,
  9117. placeholder: this.placeholder,
  9118. value: this.modelValue,
  9119. onInput: this.handleInput,
  9120. onKeyup: this.handleKeyup,
  9121. }),
  9122. ]
  9123. );
  9124. },
  9125. };
  9126. // ss-search-date-picker 日期时间选择器组件
  9127. const SsSearchDatePicker = {
  9128. name: "SsSearchDatePicker",
  9129. props: {
  9130. modelValue: {
  9131. type: [String, Number, Date],
  9132. default: "",
  9133. },
  9134. name: {
  9135. type: String,
  9136. required: true,
  9137. },
  9138. type: {
  9139. type: String,
  9140. default: "date",
  9141. validator: (value) => ["date", "datetime", "time"].includes(value),
  9142. },
  9143. fmt: {
  9144. type: String,
  9145. default: null,
  9146. },
  9147. placeholder: {
  9148. type: String,
  9149. default: "",
  9150. },
  9151. width: {
  9152. type: String,
  9153. default: "100%",
  9154. },
  9155. },
  9156. emits: ["update:modelValue"],
  9157. setup(props, { emit }) {
  9158. const errMsg = ref("");
  9159. const validate = () => {
  9160. if (window.ssVm) {
  9161. const result = window.ssVm.validateField(props.name);
  9162. console.log("validate", window.ssVm.validateField(props.name));
  9163. errMsg.value = result.valid ? "" : result.message;
  9164. }
  9165. };
  9166. // 根据type确定默认格式
  9167. const defaultFormat = computed(() => {
  9168. switch (props.type) {
  9169. case "datetime":
  9170. return "YYYY-MM-DD HH:mm:ss";
  9171. case "date":
  9172. return "YYYY-MM-DD";
  9173. case "time":
  9174. return "HH:mm:ss";
  9175. }
  9176. });
  9177. const convertJavaFormatToElement = (javaFormat) => {
  9178. if (!javaFormat) return null;
  9179. return javaFormat
  9180. .replace("yyyy", "YYYY")
  9181. .replace("MM", "MM")
  9182. .replace("dd", "DD")
  9183. .replace("HH", "HH")
  9184. .replace("mm", "mm")
  9185. .replace("ss", "ss");
  9186. };
  9187. const finalFormat = computed(() => {
  9188. if (props.fmt) {
  9189. return convertJavaFormatToElement(props.fmt);
  9190. }
  9191. return defaultFormat.value;
  9192. });
  9193. // 使用 resolveComponent 获取组件
  9194. const ElDatePicker = resolveComponent("ElDatePicker");
  9195. const ElTimePicker = resolveComponent("ElTimePicker");
  9196. const SsFormIcon = resolveComponent("SsFormIcon");
  9197. const ElIcon = resolveComponent("ElIcon");
  9198. let useTimePicker = true;
  9199. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  9200. if (props.fmt) {
  9201. //有fmt属性,则以fmt属性优先判断类型
  9202. if (/[dMy]/.test(props.fmt)) {
  9203. //如果有传入日期格式,且含年月日
  9204. useTimePicker = false;
  9205. } else {
  9206. useTimePicker = true;
  9207. }
  9208. } else if (props.type !== "time") {
  9209. useTimePicker = false;
  9210. }
  9211. const dateType = computed(() => {
  9212. const fmt = props.fmt || "";
  9213. if (fmt.includes("HH:mm:ss")) {
  9214. return "datetime";
  9215. } else if (fmt.includes("HH:mm")) {
  9216. return "datetime";
  9217. } else if (fmt.includes("mm:ss")) {
  9218. return "time";
  9219. }
  9220. return "date";
  9221. });
  9222. const handleValueUpdate = (val) => {
  9223. emit("update:modelValue", val);
  9224. emit("change", val); // 同时触发 change 事件
  9225. setTimeout(() => {
  9226. validate();
  9227. }, 50);
  9228. };
  9229. return () =>
  9230. h(
  9231. "div",
  9232. { class: "ss-search-date-picker", style: { width: props.width } },
  9233. [
  9234. h("input", {
  9235. type: "hidden",
  9236. name: props.name,
  9237. value: props.modelValue,
  9238. }),
  9239. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  9240. modelValue: props.modelValue,
  9241. "onUpdate:modelValue": handleValueUpdate,
  9242. type: dateType.value,
  9243. format: finalFormat.value,
  9244. "value-format": finalFormat.value,
  9245. clearable: true,
  9246. placeholder: props.placeholder,
  9247. class: "custom-date-picker", // 用于自定义样式
  9248. "time-arrow-control": props.type === "datetime", // 修改这里
  9249. size: "large", // 添加这一行,改为 large 尺寸
  9250. style: { width: "100%" },
  9251. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  9252. }),
  9253. ]
  9254. );
  9255. },
  9256. };
  9257. // 搜索按钮组件(包含下拉按钮)
  9258. const SsSearchButton = {
  9259. name: "SsSearchButton",
  9260. props: {
  9261. text: {
  9262. type: String,
  9263. required: true,
  9264. },
  9265. iconClass: {
  9266. type: String,
  9267. required: false,
  9268. },
  9269. opt: {
  9270. type: Array,
  9271. default: () => [],
  9272. },
  9273. checkId: {
  9274. type: String,
  9275. default: "0",
  9276. },
  9277. width: {
  9278. //add by Ben(20251225)
  9279. type: String,
  9280. required: false,
  9281. },
  9282. id: {
  9283. //add by Ben(20251225)
  9284. type: String,
  9285. required: false,
  9286. },
  9287. },
  9288. emits: ["click"],
  9289. setup(props, { emit }) {
  9290. const currentId = ref(props.checkId || "0");
  9291. const showPopup = ref(false);
  9292. const handleMouseEnter = () => {
  9293. showPopup.value = true;
  9294. };
  9295. const handleMouseLeave = () => {
  9296. showPopup.value = false;
  9297. };
  9298. // 添加点击事件处理,阻止默认行为
  9299. const handleClick = (e) => {
  9300. e.preventDefault();
  9301. if (props.opt?.length > 0) {
  9302. const selectedOption =
  9303. currentId.value === "0"
  9304. ? props.opt[0]
  9305. : props.opt.find((opt) => opt.id === currentId.value);
  9306. if (selectedOption) {
  9307. selectedOption.callback?.();
  9308. }
  9309. } else {
  9310. emit("click", e);
  9311. }
  9312. };
  9313. // 获取显示文本
  9314. const getDisplayText = () => {
  9315. if (!props.opt?.length) return props.text;
  9316. const selectedOption =
  9317. currentId.value === "0"
  9318. ? props.opt[0]
  9319. : props.opt.find((opt) => opt.id === currentId.value);
  9320. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  9321. };
  9322. return () =>
  9323. h(
  9324. "button",
  9325. {
  9326. class:
  9327. props.opt?.length > 0
  9328. ? "ss-drop-button ss-drop-button-more"
  9329. : "ss-drop-button",
  9330. type: "button", // 明确指定按钮类型为 button
  9331. onMouseenter: handleMouseEnter,
  9332. onMouseleave: handleMouseLeave,
  9333. onClick: handleClick, // 添加点击事件处理
  9334. style: { width: props.width }, //add by Ben(20251225)
  9335. id: props.id, //add by Ben(20251225)
  9336. },
  9337. [
  9338. props.iconClass
  9339. ? h("span", {
  9340. class: props.iconClass,
  9341. style: { fontFamily: "iconfont", marginRight: "5px" },
  9342. })
  9343. : null,
  9344. h("span", getDisplayText()),
  9345. props.opt.length > 0 &&
  9346. showPopup.value &&
  9347. h(
  9348. "div",
  9349. {
  9350. class: "popup",
  9351. },
  9352. props.opt.map((item) =>
  9353. h(
  9354. "div",
  9355. {
  9356. onClick: (e) => {
  9357. e.preventDefault(); // 选项点击也阻止默认行为
  9358. e.stopPropagation(); // 阻止事件冒泡
  9359. currentId.value = item.id; // 更新当前选中的ID
  9360. item.callback();
  9361. showPopup.value = false; // 选择后关闭弹窗
  9362. },
  9363. },
  9364. item.desc
  9365. )
  9366. )
  9367. ),
  9368. ]
  9369. );
  9370. },
  9371. };
  9372. // 下拉按钮组件
  9373. const SsDropButton = {
  9374. name: "SsDropButton",
  9375. props: {
  9376. text: {
  9377. type: String,
  9378. required: true,
  9379. },
  9380. iconClass: {
  9381. type: String,
  9382. required: true,
  9383. },
  9384. opt: {
  9385. type: Array,
  9386. default: () => [],
  9387. },
  9388. checkId: {
  9389. type: String,
  9390. default: "0",
  9391. },
  9392. onclick: {
  9393. type: Function,
  9394. default: null,
  9395. },
  9396. },
  9397. setup(props) {
  9398. const currentId = ref(props.checkId || "0");
  9399. const showPopup = ref(false);
  9400. const handleMouseEnter = () => {
  9401. showPopup.value = true;
  9402. };
  9403. const handleMouseLeave = () => {
  9404. showPopup.value = false;
  9405. };
  9406. // 添加点击事件处理,阻止默认行为
  9407. const handleClick = (e) => {
  9408. e.preventDefault();
  9409. if (props.opt?.length > 0) {
  9410. const selectedOption =
  9411. currentId.value === "0"
  9412. ? props.opt[0]
  9413. : props.opt.find((opt) => opt.id === currentId.value);
  9414. if (selectedOption) {
  9415. selectedOption.callback?.();
  9416. }
  9417. } else if (props.onclick) {
  9418. props.onclick();
  9419. }
  9420. };
  9421. // 获取显示文本
  9422. const getDisplayText = () => {
  9423. if (!props.opt?.length) return props.text;
  9424. const selectedOption =
  9425. currentId.value === "0"
  9426. ? props.opt[0]
  9427. : props.opt.find((opt) => opt.id === currentId.value);
  9428. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  9429. };
  9430. return () =>
  9431. h(
  9432. "button",
  9433. {
  9434. class:
  9435. props.opt?.length > 0
  9436. ? "ss-drop-button ss-drop-button-more"
  9437. : "ss-drop-button",
  9438. type: "button", // 明确指定按钮类型为 button
  9439. onMouseenter: handleMouseEnter,
  9440. onMouseleave: handleMouseLeave,
  9441. onClick: handleClick, // 添加点击事件处理
  9442. },
  9443. [
  9444. h("span", {
  9445. class: props.iconClass,
  9446. style: { fontFamily: "iconfont" },
  9447. }),
  9448. h("span", getDisplayText()),
  9449. props.opt.length > 0 &&
  9450. showPopup.value &&
  9451. h(
  9452. "div",
  9453. {
  9454. class: "popup",
  9455. },
  9456. props.opt.map((item) =>
  9457. h(
  9458. "div",
  9459. {
  9460. onClick: (e) => {
  9461. e.preventDefault(); // 选项点击也阻止默认行为
  9462. e.stopPropagation(); // 阻止事件冒泡
  9463. currentId.value = item.id; // 更新当前选中的ID
  9464. item.callback();
  9465. showPopup.value = false; // 选择后关闭弹窗
  9466. },
  9467. },
  9468. item.desc
  9469. )
  9470. )
  9471. ),
  9472. ]
  9473. );
  9474. },
  9475. };
  9476. /**
  9477. * 二级页面标签组件
  9478. * @name ss-sub-tab
  9479. * @description 用于展示二级页面的布局组件,包含左侧垂直标签导航(支持分组)和右侧iframe内容区
  9480. * @property {String} headerImage - 左侧顶部图片地址
  9481. * @property {Array} menuList - 菜单配置列表
  9482. * @property {Object} [activeMenu] - 当前选中的菜单项,不传则自动选择第一个可选菜单
  9483. * @property {Array} footerButtons - 底部按钮配置列表
  9484. */
  9485. /**
  9486. * SsSubTab 左侧菜单+iframe内容组件
  9487. * v3.0 改造:去掉顶部图片,改为图标+悬浮模式,iframe懒加载 by xu 20251216
  9488. */
  9489. const SsSubTab = {
  9490. name: "SsSubTab",
  9491. props: {
  9492. menuList: {
  9493. type: Array,
  9494. required: true,
  9495. },
  9496. activeMenu: {
  9497. type: String,
  9498. default: "",
  9499. },
  9500. footerButtons: {
  9501. type: Array,
  9502. default: () => [],
  9503. },
  9504. leftDisplay: {
  9505. type: Boolean,
  9506. default: true,
  9507. },
  9508. // v3.0 新增:菜单模式 collapse(悬浮展开) / fixed(始终收起) by xu 20251216
  9509. initialMode: {
  9510. type: String,
  9511. default: "collapse",
  9512. },
  9513. },
  9514. emits: ["menu-change", "footer-click"],
  9515. setup(props, { emit }) {
  9516. // v3.0 新增:默认图标映射,使用icon-biz图标 by xu 20251216
  9517. const defaultIcons = [
  9518. "icon-obj-ry", // 人员
  9519. "icon-obj-dw", // 单位
  9520. "icon-obj-gw", // 岗位
  9521. "icon-biz-rc", // 人才
  9522. "icon-biz-xc", // 巡查
  9523. "icon-biz-cl", // 材料
  9524. "icon-biz-men", // 门
  9525. "icon-obj-xy", // 协议
  9526. ];
  9527. //功能: SsSubTab 支持后端下发 iconName + pobj/cobj 两级菜单 by xu 20251222
  9528. const isTrue = (v) => v === true || v === "true" || v === 1 || v === "1"; //功能 by xu 20251222
  9529. const resolveIconClass = (iconNameOrClass, fallbackIndex) => {
  9530. //功能 by xu 20251222
  9531. const fallback = `menu-icon ${
  9532. defaultIcons[fallbackIndex % defaultIcons.length]
  9533. }`;
  9534. if (!iconNameOrClass) {
  9535. return fallback;
  9536. }
  9537. // 已经是完整 class(可能包含 menu-icon / menu-base-icon / 多个 class)
  9538. if (
  9539. typeof iconNameOrClass === "string" &&
  9540. iconNameOrClass.indexOf(" ") > -1
  9541. ) {
  9542. return iconNameOrClass;
  9543. }
  9544. const iconName = iconNameOrClass;
  9545. if (iconName === "menu-icon" || iconName === "menu-base-icon") {
  9546. return fallback;
  9547. }
  9548. // 业务图标库:icon-biz / icon-obj -> menu-icon
  9549. if (
  9550. typeof iconName === "string" &&
  9551. (iconName.indexOf("icon-obj-") === 0 ||
  9552. iconName.indexOf("icon-biz-") === 0)
  9553. ) {
  9554. return `menu-icon ${iconName}`;
  9555. }
  9556. // 默认认为是 icon-base 图标 -> menu-base-icon
  9557. return `menu-base-icon ${iconName}`;
  9558. };
  9559. const getMenuIcon = (item, index) => {
  9560. //功能 by xu 20251222
  9561. if (!item) {
  9562. return resolveIconClass(null, index);
  9563. }
  9564. //功能: 变动图标后端暂不正确,前端先写死为 icon-chg by xu 20251223
  9565. if (item.title === "变动" || item.name === "sys_bd") {
  9566. return resolveIconClass("icon-chg", index);
  9567. }
  9568. // 兼容旧字段 icon(优先使用)
  9569. if (item.icon) return resolveIconClass(item.icon, index);
  9570. // v3.0 使用后端下发 iconName
  9571. if (item.iconName) return resolveIconClass(item.iconName, index);
  9572. return resolveIconClass(null, index);
  9573. };
  9574. //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  9575. const getFooterIcon = (button) => {
  9576. //功能 by xu 20251224
  9577. if (!button) return "menu-base-icon icon-subm";
  9578. const iconNameOrClass =
  9579. button.iconClass || button.iconName || button.icon;
  9580. if (!iconNameOrClass) return "menu-base-icon icon-subm";
  9581. if (
  9582. typeof iconNameOrClass === "string" &&
  9583. iconNameOrClass.indexOf(" ") > -1
  9584. ) {
  9585. return iconNameOrClass;
  9586. }
  9587. return `menu-base-icon ${iconNameOrClass}`;
  9588. };
  9589. //功能: pobj/cobj 扁平结构转换为 children 树结构,兼容原 children 结构 by xu 20251222
  9590. const normalizeMenuList = (rawList) => {
  9591. if (!Array.isArray(rawList) || rawList.length === 0) {
  9592. return [];
  9593. }
  9594. const hasTree = rawList.some(
  9595. (it) => Array.isArray(it?.children) && it.children.length > 0
  9596. );
  9597. if (hasTree) {
  9598. return rawList.map((it) => ({
  9599. ...it,
  9600. __level: 1,
  9601. children: Array.isArray(it.children)
  9602. ? it.children.map((c) => ({ ...c, __level: 2 }))
  9603. : it.children,
  9604. }));
  9605. }
  9606. const hasMarker = rawList.some(
  9607. (it) => it && ("pobj" in it || "cobj" in it)
  9608. );
  9609. if (!hasMarker) {
  9610. return rawList.map((it) => ({ ...it, __level: 1 }));
  9611. }
  9612. const result = [];
  9613. let currentGroup = null;
  9614. for (const item of rawList) {
  9615. //功能: “变动”始终按一级处理(即使后端误传 pobj/cobj)by xu 20251223
  9616. const isChgItem =
  9617. item && (item.title === "变动" || item.name === "sys_bd");
  9618. if (isChgItem) {
  9619. result.push({ ...item, __level: 1 });
  9620. continue;
  9621. }
  9622. const isParent = isTrue(item?.pobj);
  9623. const isChild = isTrue(item?.cobj);
  9624. if (isParent) {
  9625. currentGroup = {
  9626. ...item,
  9627. __level: 1,
  9628. children: [],
  9629. };
  9630. result.push(currentGroup);
  9631. continue;
  9632. }
  9633. if (isChild && currentGroup) {
  9634. currentGroup.children.push({ ...item, __level: 2 });
  9635. continue;
  9636. }
  9637. //功能: 变动等无 pobj/cobj 的选项按一级展示(不挂到 children,也不打断当前分组)by xu 20251223
  9638. result.push({ ...item, __level: 1 });
  9639. }
  9640. return result;
  9641. };
  9642. const menuListComputed = computed(() =>
  9643. normalizeMenuList(props.menuList)
  9644. ); //功能 by xu 20251222
  9645. //功能: 分组展开状态(默认展开),避免 computed 生成对象导致 open 状态丢失 by xu 20251222
  9646. const groupOpenState = reactive({}); // { [key]: boolean }
  9647. const getGroupKey = (item) => item?.name || item?.title || ""; //功能 by xu 20251222
  9648. const isGroupOpen = (item) => {
  9649. //功能 by xu 20251222
  9650. const key = getGroupKey(item);
  9651. if (!key) return true;
  9652. return groupOpenState[key] !== false;
  9653. };
  9654. const toggleGroupOpen = (item) => {
  9655. //功能 by xu 20251222
  9656. const key = getGroupKey(item);
  9657. if (!key) return;
  9658. groupOpenState[key] = !isGroupOpen(item);
  9659. };
  9660. const getLevelClass = (item, fallbackLevel) => {
  9661. //功能 by xu 20251222
  9662. //功能: “变动”始终按一级样式处理 by xu 20251223
  9663. if (item && (item.title === "变动" || item.name === "sys_bd")) {
  9664. return "level-1";
  9665. }
  9666. const level = item?.__level || fallbackLevel || 1;
  9667. return level === 2 ? "level-2" : "level-1";
  9668. };
  9669. // v3.0 新增:菜单模式管理 by xu 20251216
  9670. const menuMode = ref(props.initialMode);
  9671. const isHovering = ref(false);
  9672. const toggleMenuMode = () => {
  9673. menuMode.value = menuMode.value === "collapse" ? "fixed" : "collapse";
  9674. };
  9675. //功能: 提供给旧UI弹窗顶部按钮调用的 API(替代点击 .menu-mode-toggle DOM)by xu 20251224
  9676. const registerSsSubTabApi = () => {
  9677. //功能 by xu 20251224
  9678. try {
  9679. window.SS = window.SS || {};
  9680. window.SS.dom = window.SS.dom || {};
  9681. //功能: 兼容小写 ss 命名空间(部分页面只引用 window.ss)by xu 20251224
  9682. window.ss = window.ss || window.SS;
  9683. window.ss.dom = window.ss.dom || window.SS.dom;
  9684. const api = {
  9685. toggleMenuMode,
  9686. getMenuMode: () => menuMode.value,
  9687. };
  9688. window.SS.dom.ssSubTabApi = api;
  9689. window.ss.dom.ssSubTabApi = api;
  9690. //功能: 多层弹窗(如 objPlay -> objInfo) 场景,将 API 注册到 topWindow 供按钮跨层调用 by xu 20251224
  9691. try {
  9692. const wdDialogId =
  9693. window.wd &&
  9694. wd.display &&
  9695. wd.display.getwdDialogId &&
  9696. wd.display.getwdDialogId();
  9697. if (wdDialogId && window.top) {
  9698. window.top.__ssSubTabApiMap = window.top.__ssSubTabApiMap || {};
  9699. window.top.__ssSubTabApiMap[wdDialogId] = api;
  9700. }
  9701. } catch (e) {}
  9702. try {
  9703. console.log(
  9704. "[SsSubTabApi] registered",
  9705. window.location && window.location.pathname
  9706. );
  9707. } catch (e) {}
  9708. } catch (e) {}
  9709. };
  9710. const unregisterSsSubTabApi = () => {
  9711. //功能 by xu 20251224
  9712. try {
  9713. //功能: 从 topWindow 解绑(避免弹窗关闭后残留)by xu 20251224
  9714. try {
  9715. const wdDialogId =
  9716. window.wd &&
  9717. wd.display &&
  9718. wd.display.getwdDialogId &&
  9719. wd.display.getwdDialogId();
  9720. if (
  9721. wdDialogId &&
  9722. window.top &&
  9723. window.top.__ssSubTabApiMap &&
  9724. window.top.__ssSubTabApiMap[wdDialogId]
  9725. ) {
  9726. delete window.top.__ssSubTabApiMap[wdDialogId];
  9727. }
  9728. } catch (e) {}
  9729. if (window.SS?.dom?.ssSubTabApi?.toggleMenuMode === toggleMenuMode) {
  9730. delete window.SS.dom.ssSubTabApi;
  9731. }
  9732. if (window.ss?.dom?.ssSubTabApi?.toggleMenuMode === toggleMenuMode) {
  9733. delete window.ss.dom.ssSubTabApi;
  9734. }
  9735. } catch (e) {}
  9736. };
  9737. //功能: 立即注册,避免 enable 早于 onMounted 导致“api not ready”by xu 20251224
  9738. registerSsSubTabApi(); //功能 by xu 20251224
  9739. onBeforeUnmount(unregisterSsSubTabApi); //功能 by xu 20251224
  9740. const onMouseEnter = () => {
  9741. if (menuMode.value === "collapse") {
  9742. isHovering.value = true;
  9743. }
  9744. };
  9745. const onMouseLeave = () => {
  9746. isHovering.value = false;
  9747. };
  9748. const isExpanded = computed(() => {
  9749. return menuMode.value === "collapse" && isHovering.value;
  9750. });
  9751. // v3.0 新增:iframe 懒加载,点击才加载 by xu 20251216
  9752. const loadedMenus = ref(new Set());
  9753. const isMenuLoaded = (menuName) => {
  9754. return loadedMenus.value.has(menuName);
  9755. };
  9756. // 根据标题找到对应的菜单项
  9757. const findMenuByTitle = (title) => {
  9758. for (const item of menuListComputed.value) {
  9759. //功能 by xu 20251222
  9760. if (item.children?.length > 0) {
  9761. const child = item.children.find((c) => c.title === title);
  9762. if (child) return child;
  9763. } else if (item.title === title) {
  9764. return item;
  9765. }
  9766. }
  9767. return null;
  9768. };
  9769. // 计算默认选中的菜单项
  9770. const defaultActiveMenu = computed(() => {
  9771. if (props.activeMenu) {
  9772. const menu = findMenuByTitle(props.activeMenu);
  9773. if (menu) return menu;
  9774. }
  9775. const firstItem = menuListComputed.value[0]; //功能 by xu 20251222
  9776. if (!firstItem) return null;
  9777. //功能: 默认选中第一个一级菜单(不默认跳到第一个二级)by xu 20251224
  9778. return firstItem;
  9779. });
  9780. const currentMenu = ref(defaultActiveMenu.value);
  9781. // 监听外部activeMenu变化
  9782. watch(
  9783. () => props.activeMenu,
  9784. (newTitle) => {
  9785. if (newTitle) {
  9786. const menu = findMenuByTitle(newTitle);
  9787. if (menu) {
  9788. currentMenu.value = menu;
  9789. }
  9790. }
  9791. }
  9792. );
  9793. // 初始化:默认选中项加入已加载集合
  9794. watch(
  9795. currentMenu,
  9796. (menu) => {
  9797. if (menu?.name) {
  9798. loadedMenus.value.add(menu.name);
  9799. }
  9800. },
  9801. { immediate: true }
  9802. );
  9803. // 选择菜单项时触发 menu-change 钩子
  9804. const selectItem = (item) => {
  9805. currentMenu.value = item;
  9806. // 标记为已加载
  9807. if (item.name) {
  9808. loadedMenus.value.add(item.name);
  9809. }
  9810. emit("menu-change", item);
  9811. };
  9812. // 处理底部按钮点击
  9813. const handleFooterClick = (button, index) => {
  9814. emit("footer-click", { button, index });
  9815. };
  9816. return {
  9817. menuListComputed, //功能 by xu 20251222
  9818. currentMenu,
  9819. selectItem,
  9820. handleFooterClick,
  9821. getFooterIcon, //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  9822. menuMode,
  9823. isHovering,
  9824. isExpanded,
  9825. toggleMenuMode,
  9826. onMouseEnter,
  9827. onMouseLeave,
  9828. isMenuLoaded,
  9829. getMenuIcon,
  9830. isGroupOpen, //功能 by xu 20251222
  9831. toggleGroupOpen, //功能 by xu 20251222
  9832. getLevelClass, //功能 by xu 20251222
  9833. };
  9834. },
  9835. template: `
  9836. <div class="project-edit-container">
  9837. <div class="left-side"
  9838. v-if="leftDisplay"
  9839. :data-mode="menuMode"
  9840. :class="{ 'is-expanded': isExpanded }"
  9841. @mouseenter="onMouseEnter"
  9842. @mouseleave="onMouseLeave">
  9843. <!-- 菜单内容 -->
  9844. <div class="menu-content">
  9845. <div class="scroll-view">
  9846. <template v-for="(menuItem, i) in menuListComputed" :key="i">
  9847. <!-- 分组菜单 -->
  9848. <div v-if="menuItem.children?.length > 0" class="group">
  9849. <!-- 功能: 一级(pobj)可点击进入,箭头仅控制展开/收起;二级点击不影响一级选中状态 by xu 20251223 -->
  9850. <div class="menu-item"
  9851. :class="[getLevelClass(menuItem, 1), { active: menuItem.name === currentMenu?.name }]"
  9852. @click="selectItem(menuItem)">
  9853. <ss-icon :class="getMenuIcon(menuItem, i)" />
  9854. <span class="menu-label">{{ menuItem.title }}</span>
  9855. <!-- 功能: 一级菜单有子项时显示 dot(参考全局左侧菜单)by xu 20251224 -->
  9856. <div class="has-children-dot"></div>
  9857. <div class="menu-tooltip">{{ menuItem.title }}</div>
  9858. </div>
  9859. <!-- 功能: 二级菜单始终展示,不做收缩展开 by xu 20251223 -->
  9860. <div class="group-detail">
  9861. <div v-for="(item, j) in menuItem.children"
  9862. :key="j"
  9863. class="menu-item"
  9864. :class="[getLevelClass(item, 2), { active: item.name === currentMenu?.name }]"
  9865. @click.stop="selectItem(item)">
  9866. <ss-icon :class="getMenuIcon(item, j)" />
  9867. <span class="menu-label">{{ item.title }}</span>
  9868. </div>
  9869. </div>
  9870. </div>
  9871. <!-- 普通菜单项 -->
  9872. <div v-else
  9873. class="menu-item"
  9874. :class="[getLevelClass(menuItem, 1), { active: menuItem.name === currentMenu?.name }]"
  9875. @click="selectItem(menuItem)">
  9876. <ss-icon :class="getMenuIcon(menuItem, i)" />
  9877. <span class="menu-label">{{ menuItem.title }}</span>
  9878. <div class="menu-tooltip">{{ menuItem.title }}</div>
  9879. </div>
  9880. </template>
  9881. </div>
  9882. </div>
  9883. <!-- 底部按钮 -->
  9884. <div v-if="footerButtons.length > 0"
  9885. class="sub-tab-menu-footer"
  9886. :class="{ 'has-text': !!footerButtons[0].text }"
  9887. @click="footerButtons[0].onclick">
  9888. <ss-icon :class="getFooterIcon(footerButtons[0])" />
  9889. <div class="footer-label" v-if="footerButtons[0].text">{{ footerButtons[0].text }}</div>
  9890. <ss-icon v-if="footerButtons.length > 1" class="footer-arrow" name="arrow-up" size="24px" />
  9891. <div v-if="footerButtons.length > 1" class="sub-tab-menu-popup">
  9892. <div v-for="(button, index) in footerButtons.slice(1)"
  9893. :key="index"
  9894. @click.stop="button.onclick">
  9895. {{ button.text }}
  9896. </div>
  9897. </div>
  9898. </div>
  9899. </div>
  9900. <!-- 右侧内容区域 - 懒加载 iframe -->
  9901. <div class="content-area fit-height-content" style="overflow: hidden;" :style="!leftDisplay ? { width: '100%' } : {}">
  9902. <template v-for="(menuItem, i) in menuList" :key="i">
  9903. <iframe
  9904. v-if="isMenuLoaded(menuItem.name)"
  9905. :src="menuItem.url"
  9906. style="height: 100%;width: 100%;"
  9907. frameborder="0"
  9908. class="sub-tab-iframe"
  9909. :id="i === 0 ? 'sub-tab-iframe' : ''"
  9910. v-show="currentMenu?.name === menuItem.name"
  9911. />
  9912. </template>
  9913. </div>
  9914. </div>
  9915. `,
  9916. };
  9917. // <iframe
  9918. // v-if="currentMenu?.url"
  9919. // :src="currentMenu.url"
  9920. // style="height: 100%;width: 100%;"
  9921. // frameborder="0"
  9922. // id="sub-tab-iframe"
  9923. // />
  9924. // ss-photo-upload 通用图片上传组件
  9925. const SsImgUpload = {
  9926. name: "SsImgUpload",
  9927. props: {
  9928. name: {
  9929. type: String,
  9930. required: true,
  9931. },
  9932. // 图片URL,用于回显
  9933. // url: {
  9934. // type: String,
  9935. // default: "",
  9936. // },
  9937. // 样式类名
  9938. class: {
  9939. type: String,
  9940. required: true,
  9941. },
  9942. // 裁剪配置
  9943. cropperOpt: {
  9944. type: Object,
  9945. default: () => ({
  9946. width: 360,
  9947. height: 360,
  9948. aspectRatio: 1,
  9949. }),
  9950. },
  9951. //上传图片url(未加图片名参数之前的部分)
  9952. ulUrl: {
  9953. type: String,
  9954. required: true,
  9955. },
  9956. //下载图片url(未加图片名参数之前的部分)
  9957. dlUrl: {
  9958. type: String,
  9959. required: true,
  9960. },
  9961. modelValue: [String, Number],
  9962. },
  9963. emits: ["update:modelValue"],
  9964. setup(props, { emit }) {
  9965. const inputId = Vue.computed(
  9966. () => `file_${Vue.getCurrentInstance().uid}`
  9967. );
  9968. //修改图片初始显示路径
  9969. let pathVal = ref(props.modelValue);
  9970. let picUrl = ref("");
  9971. if (props.modelValue) {
  9972. picUrl.value = props.dlUrl + "&path=" + props.modelValue;
  9973. }
  9974. Vue.onMounted(() => {
  9975. window.SS.cropper.init({
  9976. el: $(`#${inputId.value}`),
  9977. photoSize: {
  9978. width: props.cropperOpt.width,
  9979. height: props.cropperOpt.height,
  9980. },
  9981. aspectRatio: props.cropperOpt.aspectRatio,
  9982. uploadUrl: props.ulUrl,
  9983. success: (path) => {
  9984. pathVal.value = path;
  9985. picUrl.value = props.dlUrl + "&path=" + path;
  9986. emit("update:modelValue", path);
  9987. },
  9988. });
  9989. });
  9990. return () =>
  9991. h("div", { class: [props.class] }, [
  9992. h("input", {
  9993. type: "file",
  9994. accept: "image/*",
  9995. id: inputId.value,
  9996. style: { display: "none" },
  9997. }),
  9998. h("input", {
  9999. type: "hidden",
  10000. name: props.name,
  10001. value: pathVal.value,
  10002. }),
  10003. h(
  10004. "div",
  10005. {
  10006. style: {
  10007. width: "100%",
  10008. height: "100%",
  10009. },
  10010. onClick: () => $(`#${inputId.value}`).click(),
  10011. },
  10012. [
  10013. picUrl.value &&
  10014. h("img", {
  10015. src: picUrl.value,
  10016. style:
  10017. "width: 100%; height: 100%;object-fit: inherit;position: relative;z-index: 11;",
  10018. }),
  10019. ]
  10020. ),
  10021. ]);
  10022. },
  10023. };
  10024. // 初始化函数,负责创建和挂载 Vue 应用
  10025. // window.SS = { dom: {} };
  10026. /**
  10027. * 获取当前窗口的父窗口
  10028. * @returns {Window} 父窗口对象
  10029. */
  10030. window.SS.topWin = (function (p, c) {
  10031. while (p != c) {
  10032. c = p;
  10033. p = p.parent;
  10034. }
  10035. return c;
  10036. })(window.parent, window);
  10037. window.SS.createSsDialogInstance = createSsDialogInstance;
  10038. /**
  10039. * 创建弹窗
  10040. * @param {Object} setting
  10041. * @param {Function} callbackEvent
  10042. */
  10043. window.SS.openDialog = function (setting, callbackEvent) {
  10044. if (setting.params) {
  10045. const encodedParams = encodeURIComponent(JSON.stringify(setting.params));
  10046. setting.src +=
  10047. (setting.src.includes("?") ? "&" : "?") + "params=" + encodedParams;
  10048. }
  10049. if (window.parent && window.parent !== window) {
  10050. window.parent.SS.createSsDialogInstance(setting, callbackEvent);
  10051. } else {
  10052. createSsDialogInstance(setting, callbackEvent);
  10053. }
  10054. };
  10055. //关闭弹窗
  10056. window.SS.closeDialog = function () {
  10057. console.log("关闭弹窗");
  10058. if (topWindow.dialogInstances.length > 0) {
  10059. const instance = topWindow.dialogInstances.pop();
  10060. console.log("instance", instance);
  10061. console.log("instance.callbackEvent", instance.callbackEvent);
  10062. console.log(
  10063. "instance.callbackEvent.end",
  10064. typeof instance.callbackEvent === "function"
  10065. );
  10066. if (instance.callbackEvent) {
  10067. // 判断是否有end回调并执行
  10068. if (typeof instance.callbackEvent === "function") {
  10069. instance.callbackEvent();
  10070. }
  10071. if (typeof instance.callbackEvent.end === "function") {
  10072. instance.callbackEvent.end();
  10073. }
  10074. }
  10075. instance.app.unmount(); // 卸载最后一个实例
  10076. if (instance.container && instance.container.parentNode) {
  10077. instance.container.parentNode.removeChild(instance.container); // 移除容器
  10078. }
  10079. }
  10080. };
  10081. /**
  10082. * 裁剪插件
  10083. */
  10084. window.SS.cropper = {
  10085. init: function (setting) {
  10086. if (!window.top.SS) window.top.SS = {};
  10087. // 重要:确保 cropper 对象的完整初始化
  10088. if (!window.top.SS.cropper) {
  10089. window.top.SS.cropper = {
  10090. settings: new Map(),
  10091. _backupSettings: {},
  10092. getSetting: this.getSetting,
  10093. clearSetting: this.clearSetting,
  10094. debug: this.debug,
  10095. };
  10096. } else if (!window.top.SS.cropper.settings) {
  10097. // 如果 cropper 存在但 settings 不存在,重新初始化 settings
  10098. window.top.SS.cropper.settings = new Map();
  10099. window.top.SS.cropper._backupSettings = {};
  10100. }
  10101. const uploaderId = `uploader_${Date.now()}_${Math.random()
  10102. .toString(36)
  10103. .substr(2, 9)}`;
  10104. window.top.SS.cropper.settings.set(uploaderId, setting);
  10105. window.top.SS.cropper._backupSettings[uploaderId] = setting;
  10106. setting.box = setting.box || "1";
  10107. var winSetting = {
  10108. headerTitle: "图片裁剪",
  10109. src: "/js/cropper/cropper.jsp", //原来在"/newUI/page/cropper.jsp" Ben(20251205)
  10110. width: "900",
  10111. height: "500",
  10112. };
  10113. $(setting.el).change(function () {
  10114. if (!window.SS.cropper.verify(setting)) {
  10115. $(setting.el).val(""); // 清空文件选择
  10116. return false;
  10117. }
  10118. var files = this.files;
  10119. if (files && files.length) {
  10120. if (!window.SS.cropper.verifySize($(setting.el)[0], 5)) {
  10121. $(setting.el).val(""); // 清空文件选择
  10122. alert("文件大小不能超过5M,请重新选择");
  10123. return false;
  10124. }
  10125. var URL = window.URL || window.webkitURL;
  10126. var file = files[0];
  10127. setting.file = file;
  10128. if (
  10129. /^image\/\w+$/.test(file.type) &&
  10130. /\.(jpg|jpeg|png|)$/i.test(file.name)
  10131. ) {
  10132. var uploadedImageURL = URL.createObjectURL(file);
  10133. setting.data = uploadedImageURL;
  10134. setting.fileName = file.name;
  10135. // console.log()
  10136. winSetting.params = {
  10137. ...setting,
  10138. uploaderId,
  10139. };
  10140. console.log("ss-componets中change之后的winSetting", winSetting);
  10141. SS.openDialog(winSetting, {
  10142. success: function (win) {
  10143. console.log("裁剪插件成功");
  10144. // win.cropperSetting = setting;
  10145. },
  10146. end: function () {
  10147. console.log("裁剪插件结束");
  10148. $(setting.el).val(""); // 清空文件选择
  10149. },
  10150. });
  10151. } else {
  10152. alert("请选择图片文件,支持jpg、jpeg、png格式");
  10153. }
  10154. }
  10155. });
  10156. return uploaderId;
  10157. },
  10158. verify: function (setting) {
  10159. if (!setting) {
  10160. console.error(" cropper setting is not undefined! ");
  10161. return false;
  10162. }
  10163. if (!setting.el) {
  10164. console.error(" cropper setting.el is not undefined! ");
  10165. return false;
  10166. }
  10167. if (setting.photoSize) {
  10168. if (
  10169. (!setting.photoSize.width && setting.photoSize.height) ||
  10170. (!setting.photoSize.height && setting.photoSize.width)
  10171. ) {
  10172. console.error(
  10173. " cropper setting.photoSize { width, height } is not undefined! "
  10174. );
  10175. return false;
  10176. }
  10177. }
  10178. if (!setting.box) {
  10179. setting.box = "1";
  10180. }
  10181. if (!setting.aspectRatio) {
  10182. setting.aspectRatio = 1 / 1;
  10183. }
  10184. return true;
  10185. },
  10186. verifySize: function (fileEl, maxSize) {
  10187. // 判断是否为IE浏览器: /msie/i.test(navigator.userAgent) 为一个简单正则
  10188. var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  10189. var fileSize = 0;
  10190. if (isIE && !fileEl.files) {
  10191. // IE浏览器
  10192. var filePath = fileEl.value; // 获得上传文件的绝对路径
  10193. var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
  10194. var file = fileSystem.GetFile(filePath);
  10195. fileSize = file.Size; // 文件大小,单位:b
  10196. } else {
  10197. // 非IE浏览器
  10198. fileSize = fileEl.files[0].size;
  10199. }
  10200. var size = fileSize / 1024 / 1024;
  10201. return !(size > maxSize);
  10202. },
  10203. // 获取特定上传组件的setting
  10204. getSetting: function (uploaderId) {
  10205. if (!window.top.SS?.cropper) {
  10206. console.warn("顶层窗口中未找到 SS.cropper");
  10207. return null;
  10208. }
  10209. // 优先从 Map 中获取
  10210. let setting = window.top.SS.cropper.settings.get(uploaderId);
  10211. // 如果 Map 中没有,尝试从备份中获取
  10212. if (!setting && window.top.SS.cropper._backupSettings[uploaderId]) {
  10213. console.log("从备份中恢复 setting");
  10214. setting = window.top.SS.cropper._backupSettings[uploaderId];
  10215. // 恢复到 Map 中
  10216. window.top.SS.cropper.settings.set(uploaderId, setting);
  10217. }
  10218. return setting;
  10219. },
  10220. // 清理特定上传组件的setting
  10221. clearSetting: function (uploaderId) {
  10222. if (!window.top.SS?.cropper) return;
  10223. window.top.SS.cropper.settings.delete(uploaderId);
  10224. delete window.top.SS.cropper._backupSettings[uploaderId];
  10225. console.log(
  10226. "清理设置后的 Map size:",
  10227. window.top.SS.cropper.settings.size
  10228. );
  10229. },
  10230. };
  10231. /**
  10232. * 获取url中的参数
  10233. * @returns {Object}
  10234. */
  10235. window.SS.getQueryParams = function () {
  10236. const params = {};
  10237. const queryString = window.location.search.substring(1);
  10238. const pairs = queryString.split("&");
  10239. for (let i = 0; i < pairs.length; i++) {
  10240. const pair = pairs[i].split("=");
  10241. params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  10242. }
  10243. if (params.params) {
  10244. try {
  10245. params.params = JSON.parse(params.params);
  10246. } catch (e) {
  10247. console.error("Failed to parse params:", e);
  10248. }
  10249. }
  10250. return params;
  10251. };
  10252. /**
  10253. * 创建vue应用
  10254. * @param {Object} config 配置项
  10255. * @values {String} config.el 挂载的元素
  10256. * @values {Boolean} config.isDialogPage 是否是弹窗页面 决定了是否可以使用顶天立地
  10257. * @values {Object} config.vueOptions vue配置项
  10258. * @returns {Object} vue实例
  10259. */
  10260. window.ss = window.ss || window.SS;
  10261. window.ss.dom = window.ss.dom || window.SS.dom;
  10262. window.SS.dom._vueAppSeq =
  10263. window.SS.dom._vueAppSeq || window.ss.dom._vueAppSeq || 0;
  10264. window.SS.dom.vueApps = window.SS.dom.vueApps || window.ss.dom.vueApps || [];
  10265. window.ss.dom._vueAppSeq = window.SS.dom._vueAppSeq;
  10266. window.ss.dom.vueApps = window.SS.dom.vueApps;
  10267. window.SS.dom._registerVueApp = function ({ vm, el, appKey, scope, href }) {
  10268. if (!vm) return null;
  10269. const registry = window.SS.dom.vueApps || (window.SS.dom.vueApps = []);
  10270. const id = `vue-app-${++window.SS.dom._vueAppSeq}`;
  10271. const record = {
  10272. id,
  10273. el: el || "",
  10274. appKey: appKey || "",
  10275. scope: scope || "current",
  10276. href: href || window.location.href,
  10277. createdAt: Date.now(),
  10278. vm,
  10279. win: window,
  10280. };
  10281. registry.push(record);
  10282. window.SS.dom.currentApp = vm;
  10283. window.SS.dom.currentAppRecord = record;
  10284. if (window.ss && window.ss.dom) {
  10285. window.ss.dom.vueApps = registry;
  10286. window.ss.dom._vueAppSeq = window.SS.dom._vueAppSeq;
  10287. window.ss.dom.currentApp = vm;
  10288. window.ss.dom.currentAppRecord = record;
  10289. }
  10290. return record;
  10291. };
  10292. window.SS.dom._getVmData = function (vm) {
  10293. if (!vm) return null;
  10294. return vm.$data || vm;
  10295. };
  10296. window.SS.dom._hasVmKey = function (vm, key) {
  10297. if (!vm || !key) return false;
  10298. const data = window.SS.dom._getVmData(vm);
  10299. return key in vm || (!!data && key in data);
  10300. };
  10301. window.SS.dom._hasVmMethod = function (vm, methodName) {
  10302. return !!(vm && methodName && typeof vm[methodName] === "function");
  10303. };
  10304. window.SS.dom._normalizeBridgeOptions = function (
  10305. options = {},
  10306. defaults = {}
  10307. ) {
  10308. return {
  10309. scope: "chain",
  10310. ...defaults,
  10311. ...options,
  10312. };
  10313. };
  10314. window.SS.dom._matchVueRecord = function (record, options = {}) {
  10315. if (!record || !record.vm) return false;
  10316. if (options.appKey && record.appKey !== options.appKey) return false;
  10317. if (options.el && record.el !== options.el) return false;
  10318. if (options.id && record.id !== options.id) return false;
  10319. if (
  10320. options.dataKey &&
  10321. !window.SS.dom._hasVmKey(record.vm, options.dataKey)
  10322. ) {
  10323. return false;
  10324. }
  10325. if (
  10326. options.methodName &&
  10327. !window.SS.dom._hasVmMethod(record.vm, options.methodName)
  10328. ) {
  10329. return false;
  10330. }
  10331. if (typeof options.predicate === "function") {
  10332. try {
  10333. if (!options.predicate(record.vm, record)) {
  10334. return false;
  10335. }
  10336. } catch (e) {
  10337. return false;
  10338. }
  10339. }
  10340. return true;
  10341. };
  10342. window.SS.dom._getWindowVueRecord = function (targetWindow, options = {}) {
  10343. if (!targetWindow || !targetWindow.SS || !targetWindow.SS.dom) return null;
  10344. const registry = targetWindow.SS.dom.vueApps || [];
  10345. for (let i = registry.length - 1; i >= 0; i--) {
  10346. if (targetWindow.SS.dom._matchVueRecord(registry[i], options)) {
  10347. return registry[i];
  10348. }
  10349. }
  10350. const currentRecord = targetWindow.SS.dom.currentAppRecord;
  10351. if (targetWindow.SS.dom._matchVueRecord(currentRecord, options)) {
  10352. return currentRecord;
  10353. }
  10354. const currentVm = targetWindow.SS.dom.currentApp;
  10355. const fallbackRecord = currentVm
  10356. ? {
  10357. vm: currentVm,
  10358. win: targetWindow,
  10359. el: "",
  10360. appKey: "",
  10361. id: "",
  10362. }
  10363. : null;
  10364. if (targetWindow.SS.dom._matchVueRecord(fallbackRecord, options)) {
  10365. return fallbackRecord;
  10366. }
  10367. return null;
  10368. };
  10369. window.SS.dom.getVueAppRecord = function (options = {}) {
  10370. const scope = options.scope || "current";
  10371. if (scope === "current") {
  10372. return window.SS.dom._getWindowVueRecord(window, options);
  10373. }
  10374. if (scope === "top") {
  10375. try {
  10376. return window.SS.dom._getWindowVueRecord(window.top, options);
  10377. } catch (e) {
  10378. return null;
  10379. }
  10380. }
  10381. if (scope === "parent") {
  10382. try {
  10383. if (window.parent && window.parent !== window) {
  10384. return window.SS.dom._getWindowVueRecord(window.parent, options);
  10385. }
  10386. } catch (e) {
  10387. return null;
  10388. }
  10389. return null;
  10390. }
  10391. if (scope === "chain") {
  10392. let currentWindow = window;
  10393. while (currentWindow) {
  10394. try {
  10395. const record = window.SS.dom._getWindowVueRecord(
  10396. currentWindow,
  10397. options
  10398. );
  10399. if (record) {
  10400. return record;
  10401. }
  10402. } catch (e) {
  10403. return null;
  10404. }
  10405. if (currentWindow === currentWindow.parent) {
  10406. break;
  10407. }
  10408. currentWindow = currentWindow.parent;
  10409. }
  10410. return null;
  10411. }
  10412. return window.SS.dom._getWindowVueRecord(window, options);
  10413. };
  10414. window.SS.dom.getVueApp = function (options = {}) {
  10415. const record = window.SS.dom.getVueAppRecord(options);
  10416. return record ? record.vm : null;
  10417. };
  10418. window.SS.dom.getVmValue = function (key, options = {}) {
  10419. const vm = window.SS.dom.getVueApp(
  10420. window.SS.dom._normalizeBridgeOptions(options, { dataKey: key })
  10421. );
  10422. if (!vm) return undefined;
  10423. return vm[key];
  10424. };
  10425. window.SS.dom.setVmValue = function (key, value, options = {}) {
  10426. const vm = window.SS.dom.getVueApp(
  10427. window.SS.dom._normalizeBridgeOptions(options, { dataKey: key })
  10428. );
  10429. if (!vm) return false;
  10430. vm[key] = value;
  10431. return true;
  10432. };
  10433. window.SS.dom.callVmMethod = function (methodName, args = [], options = {}) {
  10434. const vm = window.SS.dom.getVueApp(
  10435. window.SS.dom._normalizeBridgeOptions(options, { methodName })
  10436. );
  10437. if (!vm || typeof vm[methodName] !== "function") {
  10438. return undefined;
  10439. }
  10440. return vm[methodName].apply(vm, args);
  10441. };
  10442. window.SS.dom.get = function (key, options = {}) {
  10443. return window.SS.dom.getVmValue(key, options);
  10444. };
  10445. window.SS.dom.set = function (key, value, options = {}) {
  10446. return window.SS.dom.setVmValue(key, value, options);
  10447. };
  10448. window.SS.dom.call = function (methodName, args = [], options = {}) {
  10449. return window.SS.dom.callVmMethod(methodName, args, options);
  10450. };
  10451. [
  10452. "_registerVueApp",
  10453. "_getVmData",
  10454. "_hasVmKey",
  10455. "_hasVmMethod",
  10456. "_normalizeBridgeOptions",
  10457. "_matchVueRecord",
  10458. "_getWindowVueRecord",
  10459. "getVueAppRecord",
  10460. "getVueApp",
  10461. "getVmValue",
  10462. "setVmValue",
  10463. "callVmMethod",
  10464. "get",
  10465. "set",
  10466. "call",
  10467. ].forEach((name) => {
  10468. window.ss.dom[name] = window.SS.dom[name];
  10469. });
  10470. window.SS.dom.initializeFormApp = function (config) {
  10471. const {
  10472. el,
  10473. isDialogPage = false,
  10474. appKey = "",
  10475. scope = "current",
  10476. ...vueOptions
  10477. } = config;
  10478. const app = createApp({
  10479. ...vueOptions,
  10480. });
  10481. if (isDialogPage) {
  10482. function checkScroll() {
  10483. const elements = document.querySelectorAll(".fit-height-content");
  10484. let hasScrollBar = false;
  10485. elements.forEach((el) => {
  10486. if (el.scrollHeight > el.clientHeight) {
  10487. hasScrollBar = true;
  10488. }
  10489. });
  10490. window.parent.postMessage({ hasScrollBar }, "*");
  10491. }
  10492. function addScrollListeners() {
  10493. const elements = document.querySelectorAll("div");
  10494. elements.forEach((el) => {
  10495. el.addEventListener("scroll", checkScroll);
  10496. });
  10497. }
  10498. const observer = new MutationObserver(() => {
  10499. addScrollListeners();
  10500. checkScroll();
  10501. });
  10502. observer.observe(document.body, {
  10503. childList: true,
  10504. subtree: true,
  10505. });
  10506. window.addEventListener("resize", checkScroll);
  10507. }
  10508. app.component("SsLoginIcon", SsLoginIcon);
  10509. app.component("SsMark", SsMark);
  10510. app.component("SsFullStyleHeader", SsFullStyleHeader);
  10511. app.component("SsDialog", SsDialog);
  10512. app.component("SsInp", SsInput);
  10513. app.component("SsObjp", SsObjp);
  10514. app.component("SsHidden", SsHidden);
  10515. app.component("SsCcp", SsCcp);
  10516. app.component("SsDatePicker", SsDatePicker);
  10517. app.component("SsIcon", SsIcon);
  10518. app.component("SsCommonIcon", SsCommonIcon);
  10519. app.component("SsBreadcrumb", SsBreadcrumb);
  10520. app.component("SsEditor", SsEditor);
  10521. app.component("SsDialogIcon", SsDialogIcon);
  10522. app.component("SsBottomButton", SsBottomButton);
  10523. app.component("SsNavIcon", SsNavIcon);
  10524. app.component("SsHeaderIcon", SsHeaderIcon);
  10525. app.component("SsGolbalMenuIcon", SsGolbalMenuIcon);
  10526. app.component("SsCartListIcon", SsCartListIcon);
  10527. app.component("SsQuickIcon", SsQuickIcon);
  10528. app.component("SsFormIcon", SsFormIcon);
  10529. app.component("SsBottomDivIcon", SsBottomDivIcon);
  10530. app.component("SsEditorIcon", SsEditorIcon);
  10531. app.component("SsValidate", SsValidate);
  10532. app.component("SsOnoff", Ssonoff);
  10533. app.component("SsonoffArray", SsonoffArray);
  10534. app.component("SsTextarea", SsTextarea);
  10535. app.component("SsLoginInput", SsLoginInput);
  10536. app.component("SsLoginButton", SsLoginButton);
  10537. app.component("SsSearch", SsSearch);
  10538. app.component("SsCartItem", SsCartItem);
  10539. app.component("SsCartItem2", SsCartItem2);
  10540. app.component("SsListCard", SsListCard);
  10541. app.component("ss-cobj-card-list", SsCObjCardList);
  10542. app.component("SsFolderCard", SsFolderCard);
  10543. app.component("ss-sidebar", SsSidebar);
  10544. app.component("ss-sidebar-buttons", SsSidebarButtons);
  10545. app.component("ss-sidebar-chart", SsSidebarChart);
  10546. app.component("ss-sidebar-chart-hover", SsSidebarChartHover);
  10547. app.component("ss-sidebar-list", SsSidebarList);
  10548. app.component("ss-sidebar-report-table", SsSidebarReportTable);
  10549. app.component("SsFolderCartView", SsFolderCartView);
  10550. app.component("SsPage", SsPage);
  10551. app.component("SsRightInfo", SSRightInfo);
  10552. app.component("SsSuccessPopup", SsSuccessPopup);
  10553. app.component("SsErrorDialog", SsErrorDialog);
  10554. app.component("SsVerify", SsVerify);
  10555. app.component("SsVerifyNode", SsVerifyNode);
  10556. app.component("SsOrcImgBox", SsOrcImgBox);
  10557. app.component("ss-search-input", SsSearchInput);
  10558. app.component("ss-search-date-picker", SsSearchDatePicker);
  10559. app.component("ss-search-button", SsSearchButton);
  10560. app.component("ss-drop-button", SsDropButton);
  10561. app.component("ss-sub-tab", SsSubTab);
  10562. app.component("ss-img", SsImgUpload);
  10563. app.use(ElementPlus, {
  10564. locale: ElementPlusLocaleZhCn,
  10565. });
  10566. for (const componentName in IndexComponents) {
  10567. app.component(componentName, IndexComponents[componentName]);
  10568. }
  10569. for (const componentName in EchartComponents) {
  10570. app.component(componentName, EchartComponents[componentName]);
  10571. }
  10572. let vm;
  10573. try {
  10574. vm = app.mount(el);
  10575. vm.data = vueOptions.data();
  10576. window.SS.dom._registerVueApp({
  10577. vm,
  10578. el,
  10579. appKey,
  10580. scope,
  10581. href: window.location.href,
  10582. });
  10583. console.log("vm:", vm);
  10584. console.log("vueOptions:", vueOptions);
  10585. } catch (error) {
  10586. console.log("Mount failed:" + error);
  10587. }
  10588. return vm;
  10589. };
  10590. })();