ss-components.js 404 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679
  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. // 功能说明:onChange 全局回调 prop,桥接 API 赋值时自动触发 by xu 20260416
  183. onchange: {
  184. type: String,
  185. required: false,
  186. },
  187. },
  188. emits: ["update:modelValue", "input", "blur", "change"], // 允许更新 v-model 绑定的值
  189. setup(props, { emit }) {
  190. const errMsg = ref("");
  191. const inputRef = ref(null);
  192. const textareaRef = ref(null);
  193. const inputValue = ref(props.modelValue || props.defaultValue || "");
  194. const contentFloatingDiv = ref(false); // 控制浮动 DIV 的显示
  195. const floatingDivPosition = ref("bottom"); // 'bottom' 或 'top'
  196. const isFocused = ref(false); // 跟踪焦点状态
  197. // 附件相关变量(仅在传入 param 时初始化)
  198. const buttonConfigRaw = props.param && props.param.button ? props.param.button : null;
  199. const buttonArray = Array.isArray(buttonConfigRaw)
  200. ? buttonConfigRaw
  201. : buttonConfigRaw
  202. ? [buttonConfigRaw]
  203. : [];
  204. const attachmentButton =
  205. buttonArray.find((btn) => btn && btn.cmsAddUrl && btn.cmsUpdUrl) || null;
  206. const hasAttachmentButton = !!attachmentButton;
  207. const attachmentFieldName =
  208. attachmentButton?.name || (props.fj && props.fj.name) || "fjid";
  209. const attachmentButtonText =
  210. attachmentButton?.desc ||
  211. attachmentButton?.text ||
  212. props.fj?.desc ||
  213. props.fj?.text ||
  214. "附件";
  215. const resolvePageSearchParam = (key) => {
  216. try {
  217. return new URL(window.location.href).searchParams.get(key) || "";
  218. } catch (error) {
  219. return "";
  220. }
  221. };
  222. const resolveAttachmentObjName = () =>
  223. props.param?.obj ||
  224. props.param?.ssObjName ||
  225. document.querySelector("[name='ssObjName']")?.value ||
  226. window?.ss?.dom?.ssObjName ||
  227. resolvePageSearchParam("ssObjName") ||
  228. "";
  229. const resolveAttachmentObjId = () =>
  230. props.param?.ssObjId ||
  231. props.param?.objId ||
  232. document.querySelector("[name='ssObjId']")?.value ||
  233. resolvePageSearchParam("ssObjId") ||
  234. "";
  235. const buildAttachmentCreatePayload = () => ({
  236. name: attachmentFieldName,
  237. ssNrObjName: resolveAttachmentObjName(),
  238. ssNrObjId: resolveAttachmentObjId(),
  239. });
  240. const buildAttachmentDialogQuery = () =>
  241. "&nrid=T-" +
  242. fjid.value +
  243. "&objectId=" +
  244. fjid.value +
  245. "&objectName=" +
  246. attachmentFieldName +
  247. "&callback=" +
  248. (window[attachmentFieldName + "CallbackName"] || "");
  249. let fjid = ref(attachmentButton?.val || null);
  250. let mode = props.param ? props.param.mode : null;
  251. // 功能说明:只有存在非空校验(notNull)且值为空时,才显示红线 by xu 20260402
  252. const hasNotNullRule = () => {
  253. const validations = window.ssVm?.validations?.get(props.name);
  254. if (!validations || validations.length === 0) return false;
  255. return validations.some(v => v.ruleName && v.ruleName.includes('notNull'));
  256. };
  257. const showRequired = computed(() => {
  258. const validations = window.ssVm?.validations?.get(props.name);
  259. if (!validations || validations.length === 0) return false;
  260. // 检查是否存在 notNull 规则
  261. const hasNotNull = validations.some(v => v.ruleName && v.ruleName.includes('notNull'));
  262. // 有非空规则且值为空时显示红线
  263. if (hasNotNull && !inputValue.value) {
  264. return true;
  265. }
  266. return false;
  267. });
  268. // 计算floatdiv应该向上还是向下展开
  269. const calculateFloatingDivPosition = () => {
  270. nextTick(() => {
  271. const textarea = inputRef.value;
  272. if (!textarea) return;
  273. const rect = textarea.getBoundingClientRect();
  274. const viewportHeight = window.innerHeight;
  275. // 预估floatdiv的高度(最多5行 * 20px + 上下padding + border)
  276. const estimatedFloatDivHeight = 20 * 5 + 10 + 2; // 5行 + padding + border = 112px
  277. // 检查下方空间
  278. const spaceBelow = viewportHeight - rect.bottom;
  279. // 如果下方空间不足,且上方空间足够,则向上展开
  280. if (
  281. spaceBelow < estimatedFloatDivHeight &&
  282. rect.top > estimatedFloatDivHeight
  283. ) {
  284. floatingDivPosition.value = "top";
  285. } else {
  286. floatingDivPosition.value = "bottom";
  287. }
  288. });
  289. };
  290. // 计算floatdiv的top偏移量
  291. const getFloatingDivTop = computed(() => {
  292. if (props.height) {
  293. // 有height时,padding是5px
  294. return "5px";
  295. } else {
  296. // 没有height时是单行居中,需要计算居中位置
  297. // 假设input-container高度是32px(或者从CSS读取),单行20px
  298. // 居中偏移 = (容器高度 - 行高) / 2 = (32 - 20) / 2 = 6px
  299. return "6px";
  300. }
  301. });
  302. const validate = () => {
  303. if (window.ssVm) {
  304. const result = window.ssVm.validateField(props.name);
  305. errMsg.value = result.valid ? "" : result.message;
  306. }
  307. };
  308. // 功能说明:调用全局 onChange 回调 by xu 20260416
  309. const callGlobalOnchg = (value) => {
  310. if (props.onchange && typeof props.onchange === "string") {
  311. if (
  312. typeof window !== "undefined" &&
  313. window[props.onchange] &&
  314. typeof window[props.onchange] === "function"
  315. ) {
  316. try {
  317. window[props.onchange](value);
  318. } catch (error) {
  319. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  320. }
  321. }
  322. }
  323. };
  324. // 使用 watch 监听 props.errTip 和 props.modelValue 的变化
  325. watch(
  326. () => props.errTip,
  327. (newVal) => {
  328. errMsg.value = newVal;
  329. },
  330. { immediate: true }
  331. );
  332. watch(
  333. () => props.modelValue,
  334. (newVal) => {
  335. inputValue.value = newVal;
  336. // 桥接 API 赋值时触发全局 onChange by xu 20260416
  337. callGlobalOnchg(newVal);
  338. }
  339. );
  340. // 挂载时的逻辑
  341. onMounted(() => {
  342. errMsg.value = props.errTip;
  343. inputValue.value = props.modelValue || props.defaultValue || "";
  344. });
  345. // 计算并调整textarea的高度
  346. const adjustHeight = () => {
  347. nextTick(() => {
  348. const textarea = textareaRef.value;
  349. if (!textarea) return;
  350. // floatDiv的textarea始终自动计算高度,不受props.height影响
  351. // 重置高度以获得正确的scrollHeight
  352. textarea.style.height = "auto";
  353. // 计算新高度 - 统一限制为5行
  354. const lineHeight = parseInt(
  355. getComputedStyle(textarea).lineHeight,
  356. 10
  357. );
  358. const maxHeight = lineHeight * 5; // 统一为5行
  359. const newHeight = Math.min(textarea.scrollHeight, maxHeight);
  360. textarea.style.height = `${newHeight}px`;
  361. });
  362. };
  363. // 检查是否应该显示浮动窗口(需要同时满足:有焦点 + 内容超出)
  364. // 修复新增页面点击就出现floatdiv的问题 by xu 20251212
  365. const checkShouldShowFloatingDiv = () => {
  366. const textarea = inputRef.value;
  367. if (!textarea) return false;
  368. // 首先检查是否有内容,没有内容时不显示floatdiv by xu 20251212
  369. if (!inputValue.value || inputValue.value.toString().trim() === "") {
  370. console.log("[floatdiv] 内容为空,不显示floatdiv");
  371. return false;
  372. }
  373. // 判断内容是否超出 by xu 20251212
  374. // 同时检查横向和纵向溢出,任一方向溢出都应显示floatdiv
  375. // 纵向溢出需要加容差值,避免padding/border导致的误判 by xu 20251212
  376. const verticalTolerance = 5; // 容差值5px
  377. const isHorizontalOverflow =
  378. textarea.scrollWidth > textarea.clientWidth;
  379. const isVerticalOverflow =
  380. textarea.scrollHeight > textarea.clientHeight + verticalTolerance;
  381. const isOverflow = isHorizontalOverflow || isVerticalOverflow;
  382. console.log(
  383. "[floatdiv] 溢出检测 - scrollWidth:",
  384. textarea.scrollWidth,
  385. "clientWidth:",
  386. textarea.clientWidth,
  387. "horizontalOverflow:",
  388. isHorizontalOverflow
  389. );
  390. console.log(
  391. "[floatdiv] 溢出检测 - scrollHeight:",
  392. textarea.scrollHeight,
  393. "clientHeight:",
  394. textarea.clientHeight,
  395. "tolerance:",
  396. verticalTolerance,
  397. "verticalOverflow:",
  398. isVerticalOverflow
  399. );
  400. const shouldShow = isFocused.value && isOverflow;
  401. console.log(
  402. "[floatdiv] 最终判断 - isFocused:",
  403. isFocused.value,
  404. "isOverflow:",
  405. isOverflow,
  406. "shouldShow:",
  407. shouldShow
  408. );
  409. // 需要同时满足:有焦点 + 内容超出
  410. return shouldShow;
  411. };
  412. // 定义事件处理函数
  413. const onInput = (event) => {
  414. const newValue = event.target.value;
  415. inputValue.value = newValue;
  416. emit("update:modelValue", newValue);
  417. validate(); // 输入时验证
  418. nextTick(() => {
  419. // 检查是否需要显示浮动div
  420. contentFloatingDiv.value = checkShouldShowFloatingDiv();
  421. // 如果需要显示floatdiv,计算其位置
  422. if (contentFloatingDiv.value) {
  423. calculateFloatingDivPosition();
  424. }
  425. });
  426. adjustHeight();
  427. };
  428. const onFocus = (event) => {
  429. // 设置焦点状态为true
  430. isFocused.value = true;
  431. adjustHeight();
  432. // 检查是否应该显示浮动窗口
  433. nextTick(() => {
  434. contentFloatingDiv.value = checkShouldShowFloatingDiv();
  435. if (contentFloatingDiv.value) {
  436. calculateFloatingDivPosition();
  437. }
  438. });
  439. };
  440. // 失去焦点时进行验证
  441. const onBlur = (event) => {
  442. emit("blur", event.target);
  443. validate(); // 失焦时验证
  444. nextTick(() => {
  445. // 如果焦点不在 textarea 上,则隐藏浮动 div
  446. if (!document.activeElement.classList.contains("input-control")) {
  447. isFocused.value = false;
  448. contentFloatingDiv.value = false;
  449. }
  450. });
  451. };
  452. const onChange = (event) => {
  453. inputValue.value = event.target.value || "";
  454. emit("change", inputValue.value);
  455. };
  456. const onMouseover = (event) => {
  457. nextTick(() => {
  458. // setTimeout(contentFloatingDiv.value = true, 500)
  459. });
  460. };
  461. const onMouseleave = (event) => {
  462. // contentFloatingDiv.value = false
  463. };
  464. // 功能说明:传了 height 视为多行允许回车;未传 height 拦截回车(单行表现) by xu 20260204
  465. const onKeydown = (event) => {
  466. const allowMultiline =
  467. typeof props.height === "string" && props.height.trim() !== "";
  468. if (!allowMultiline && event.key === "Enter") {
  469. event.preventDefault();
  470. }
  471. };
  472. // 附件按钮点击处理(从 SsEditor 搬运)
  473. const onAttachmentClick = (e) => {
  474. e.preventDefault();
  475. if (!hasAttachmentButton || !attachmentButton) {
  476. console.warn("未配置 param 参数");
  477. return;
  478. }
  479. console.log("附件点击了");
  480. console.log("param", props.param);
  481. console.log("cmsAddUrl", attachmentButton.cmsAddUrl);
  482. // 如果 fjid 为空,先调用 cmsAddUrl 创建
  483. if (fjid.value == null || fjid.value == "") {
  484. $.ajax({
  485. type: "post",
  486. url: attachmentButton.cmsAddUrl,
  487. async: false,
  488. data: buildAttachmentCreatePayload(),
  489. success: function (_fjid) {
  490. console.log("cmsAddUrl success", _fjid);
  491. fjid.value = _fjid;
  492. },
  493. });
  494. }
  495. // 构建参数字符串
  496. const str = buildAttachmentDialogQuery();
  497. console.log("str", str);
  498. // 打开附件编辑对话框
  499. SS.openDialog({
  500. src: attachmentButton.cmsUpdUrl + str,
  501. headerTitle: "编辑",
  502. width: 900,
  503. high: 664,
  504. zIndex: 51,
  505. });
  506. };
  507. return {
  508. errMsg,
  509. inputValue,
  510. showRequired,
  511. onInput,
  512. onBlur,
  513. onChange,
  514. onMouseover,
  515. onMouseleave,
  516. onKeydown, // 新增:键盘事件处理 by xu 20251212
  517. contentFloatingDiv,
  518. floatingDivPosition,
  519. getFloatingDivTop,
  520. inputRef,
  521. textareaRef,
  522. onFocus,
  523. onAttachmentClick,
  524. attachmentFieldName,
  525. attachmentButtonText,
  526. hasAttachmentButton,
  527. fjid, // 附件 ID,用于隐藏字段
  528. };
  529. },
  530. render() {
  531. const { resolveComponent, h } = Vue;
  532. const SsIcon = resolveComponent("ss-icon");
  533. const SsEditorIcon = resolveComponent("SsEditorIcon");
  534. // 构建主textarea的样式
  535. const mainTextareaStyle = {};
  536. if (this.height) {
  537. mainTextareaStyle.height = "auto";
  538. // mainTextareaStyle.paddingTop = '5px'; // 有高度时加上padding-top
  539. // mainTextareaStyle.paddingBottom = '5px'; // 有高度时加上padding-bottom
  540. } else {
  541. // 没有指定height时,固定为单行高度
  542. mainTextareaStyle.height = "20px"; // 行高20px
  543. mainTextareaStyle.lineHeight = "20px"; // 确保单行垂直居中
  544. mainTextareaStyle.display = "flex";
  545. mainTextareaStyle.marginBottom = "5px";
  546. }
  547. // 如果有附件按钮,为按钮留出空间
  548. if (this.fj || this.hasAttachmentButton) {
  549. //加上&&this.param.button条件 Ben(20251221)
  550. mainTextareaStyle.paddingRight = "75px";
  551. }
  552. const mainTextareaRows = this.height
  553. ? Math.floor(parseFloat("80px") / 20)
  554. : 1;
  555. return h("div", { class: "input" }, [
  556. h("div", { class: "input-container" }, [
  557. h("div", { class: "input", style: "padding:5px 0" }, [
  558. h("textarea", {
  559. ref: "inputRef",
  560. class: "input-control",
  561. name: this.name,
  562. value: this.inputValue,
  563. onInput: this.onInput,
  564. onFocus: this.onFocus,
  565. onBlur: this.onBlur,
  566. onChange: this.onChange,
  567. onKeydown: this.onKeydown, // 新增:禁止回车换行 by xu 20251212
  568. placeholder: this.placeholder,
  569. onMouseover: this.onMouseover, // 监听鼠标悬停
  570. onMouseleave: this.onMouseleave, // 监听鼠标离开
  571. rows: mainTextareaRows,
  572. ...this.$attrs,
  573. style: mainTextareaStyle,
  574. autocomplete: "off",
  575. }),
  576. // 附件按钮(优先使用 param,兼容旧的 fj)
  577. this.fj || this.hasAttachmentButton //加上&&this.param.button条件 Ben(20251221)
  578. ? h(
  579. "button",
  580. {
  581. type: "button",
  582. class: "fj-button",
  583. onClick: this.hasAttachmentButton
  584. ? this.onAttachmentClick
  585. : (e) => {
  586. e.preventDefault();
  587. console.log("附件配置:", this.fj);
  588. },
  589. },
  590. [
  591. h(SsEditorIcon, {
  592. class: "editor-icon-link",
  593. }),
  594. h("span", { class: "fj-button-text" }, this.attachmentButtonText || "附件"),
  595. ]
  596. )
  597. : null,
  598. ]),
  599. this.contentFloatingDiv || ""
  600. ? h(
  601. "div",
  602. {
  603. class: "floating-div",
  604. style:
  605. this.floatingDivPosition === "bottom"
  606. ? {
  607. // 向下展开: 覆盖原输入框,top对齐首行
  608. top: this.getFloatingDivTop,
  609. bottom: "auto",
  610. }
  611. : {
  612. // 向上展开: 同样覆盖原输入框,但从底部开始计算
  613. top: "auto",
  614. bottom: this.height ? "5px" : "6px", // 对齐到原textarea的底部padding位置
  615. },
  616. },
  617. [
  618. h("textarea", {
  619. ref: "textareaRef",
  620. class: "input-control",
  621. value: this.inputValue,
  622. onInput: this.onInput,
  623. onBlur: this.onBlur,
  624. onFocus: this.onFocus,
  625. onKeydown: this.onKeydown, // 新增:禁止回车换行 by xu 20251212
  626. onMouseover: this.onMouseover, // 监听鼠标悬停
  627. onMouseleave: this.onMouseleave, // 监听鼠标离开
  628. autocomplete: "off",
  629. onVnodeMounted: (vnode) => {
  630. vnode.el.focus();
  631. },
  632. }),
  633. ]
  634. )
  635. : null,
  636. // this.errMsg ? h(SsValidate, { errMsg: this.errMsg }) : null,
  637. ]),
  638. // 附件相关的隐藏字段(仅在有 param 时才渲染)
  639. this.param && [
  640. // fjid 隐藏字段(只有当 fjid 有值时才渲染)
  641. this.fjid &&
  642. h("input", {
  643. type: "hidden",
  644. name: this.attachmentFieldName || "fjid",
  645. value: this.fjid,
  646. }),
  647. // 其他隐藏字段根据 name 生成
  648. /* 去掉。文本框不需要(这是富文本才有的) Ben 20251205
  649. h("input", {
  650. type: "hidden",
  651. name: this.name.replace(/wj$/, "") + "Edit",
  652. value: this.inputValue
  653. }),
  654. */
  655. // h("input", {
  656. // type: "hidden",
  657. // name: this.name.replace(/wj$/, "") + "wj",
  658. // value: this.inputValue
  659. // }),
  660. /* 去掉。文本框不需要(这是富文本才有的) Ben 20251205
  661. h("input", {
  662. type: "hidden",
  663. name: "ueditorpath",
  664. value: this.name
  665. }),
  666. */
  667. ],
  668. ]);
  669. },
  670. };
  671. // ss-normal-input 登录输入
  672. const SsLoginInput = {
  673. name: "SsLoginInput",
  674. inheritAttrs: false,
  675. props: {
  676. errTip: {
  677. type: String,
  678. },
  679. type: {
  680. type: String,
  681. default: "text",
  682. },
  683. required: {
  684. type: Boolean,
  685. default: false,
  686. },
  687. placeholder: {
  688. type: String,
  689. default: "请输入",
  690. },
  691. name: {
  692. type: String,
  693. default: "",
  694. },
  695. defaultValue: [String, Number],
  696. modelValue: [String, Number],
  697. },
  698. emits: ["update:modelValue", "input", "blur", "change"], // 允许更新 v-model 绑定的值
  699. setup(props, { emit }) {
  700. const errMsg = ref("");
  701. const inputRef = ref(null);
  702. const textareaRef = ref(null);
  703. const inputValue = ref(props.modelValue || props.defaultValue || "");
  704. // 使用 watch 监听 props.errTip 和 props.modelValue 的变化
  705. watch(
  706. () => props.errTip,
  707. (newVal) => {
  708. errMsg.value = newVal;
  709. },
  710. { immediate: true }
  711. );
  712. watch(
  713. () => props.modelValue,
  714. (newVal) => {
  715. inputValue.value = newVal;
  716. }
  717. );
  718. // 挂载时的逻辑
  719. onMounted(() => {
  720. errMsg.value = props.errTip;
  721. inputValue.value = props.modelValue || props.defaultValue || "";
  722. });
  723. // 定义事件处理函数
  724. const onInput = (event) => {
  725. const newValue = event.target.value;
  726. inputValue.value = newValue;
  727. emit("update:modelValue", newValue);
  728. };
  729. return { inputValue, onInput, inputRef, textareaRef };
  730. },
  731. render() {
  732. return h("div", { class: "input" }, [
  733. h("div", { class: "input-container" }, [
  734. h("div", { class: "input" }, [
  735. h("input", {
  736. ref: "inputRef",
  737. class: "input-control",
  738. name: this.name,
  739. value: this.inputValue,
  740. onInput: this.onInput,
  741. type: this.type,
  742. placeholder: this.placeholder,
  743. required: this.required,
  744. ...this.$attrs,
  745. autocomplete: "off",
  746. }),
  747. ]),
  748. ]),
  749. ]);
  750. },
  751. };
  752. // ss-login-button
  753. const SsLoginButton = {
  754. name: "SsLoginButton",
  755. inheritAttrs: false,
  756. props: {
  757. class: {
  758. type: String,
  759. default: "",
  760. },
  761. text: {
  762. type: String,
  763. default: "",
  764. },
  765. type: {
  766. type: String,
  767. default: "button",
  768. },
  769. },
  770. emits: ["click"],
  771. setup(props, { emit }) {
  772. // 定义事件处理函数
  773. const onClick = (event) => {
  774. // 发射一个 'click' 事件,你可以传递所需的参数
  775. emit("click", event);
  776. };
  777. return { props, onClick };
  778. },
  779. render() {
  780. const SsIcon = resolveComponent("ss-icon");
  781. const SsLoginIcon = resolveComponent("ss-login-icon");
  782. return h(
  783. "button",
  784. { class: "login-button", type: this.type, onClick: this.onClick },
  785. [
  786. h("span", [h(SsLoginIcon, { class: this.class })]),
  787. h("span", {}, this.text),
  788. ]
  789. );
  790. },
  791. };
  792. // ss-objp 下拉选择
  793. const SsObjp = {
  794. name: "SsObjp",
  795. inheritAttrs: false,
  796. props: {
  797. onchange: {
  798. //在此属性传入onChange的window全局回调函数,函数唯一参数是当前选中值 Ben(20251217)
  799. type: String,
  800. required: false,
  801. },
  802. filter: {
  803. type: String,
  804. required: false,
  805. },
  806. filterfield: {
  807. type: String,
  808. required: false,
  809. },
  810. // filterField: {
  811. // //此属性为页面表单元素的name用逗号分隔,作用为在向后台查询下拉菜单选项时,会带上这些name的表单元素的value值 Ben(20260313)
  812. // type: String,
  813. // required: false,
  814. // },
  815. cb: {
  816. type: String,
  817. required: true,
  818. },
  819. url: {
  820. type: String,
  821. required: true,
  822. },
  823. name: {
  824. type: String,
  825. required: true,
  826. },
  827. width: {
  828. type: String,
  829. default: "100%",
  830. },
  831. placeholder: {
  832. type: String,
  833. default: "请选择",
  834. },
  835. inp: {
  836. type: Boolean,
  837. default: false,
  838. },
  839. opt: {
  840. type: Array,
  841. default: () => [],
  842. },
  843. errTip: String,
  844. defaultValue: [String, Number],
  845. modelValue: [String, Number],
  846. direction: {
  847. type: String,
  848. default: "bottom",
  849. },
  850. },
  851. emits: ["update:modelValue", "input", "blur", "change"],
  852. setup(props, { emit }) {
  853. const canInput = props.inp;
  854. const errMsg = Vue.ref(props.errTip);
  855. const selectItem = Vue.ref({});
  856. let inputText = Vue.ref(""); // 用于存储输入框的文本
  857. const popupWinVisible = Vue.ref(false);
  858. const filteredOptions = Vue.ref(props.opt);
  859. const popupDirection = Vue.ref("bottom");
  860. const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
  861. const popupContentAreaMaxHeight = Vue.computed(() => {
  862. if (!popupMaxHeight.value || popupMaxHeight.value === "none")
  863. return null;
  864. const maxHeightNum = Number.parseFloat(popupMaxHeight.value);
  865. if (!Number.isFinite(maxHeightNum)) return null;
  866. // 功能说明:滚动条统一落在 .content-area(CSS 默认如此),因此需要扣掉 popup-win padding-top(10) 与 popup-content padding(15*2) by xu 20260126
  867. const contentAreaMaxHeight = Math.max(60, maxHeightNum - 40);
  868. return `${contentAreaMaxHeight}px`;
  869. });
  870. // 修复表格内下拉弹层被 overflow 截断:popup 使用 Teleport 到 body + fixed 定位 by xu 20260126
  871. const selectContainerRef = Vue.ref(null);
  872. const popupRef = Vue.ref(null);
  873. const teleportRootStyle = Vue.ref({
  874. position: "fixed",
  875. left: "0",
  876. top: "0",
  877. width: "0",
  878. height: "0",
  879. zIndex: 9999,
  880. pointerEvents: "none",
  881. });
  882. const popupLayerStyle = Vue.ref({
  883. position: "fixed",
  884. left: "0",
  885. top: "0",
  886. bottom: "auto", // 功能说明:覆盖 .popup-win.top 的 bottom 定位,避免 fixed 场景被撑高/错位 by xu 20260126
  887. minWidth: "0",
  888. zIndex: 9999,
  889. pointerEvents: "auto",
  890. });
  891. // const showRequired = Vue.computed(() => {
  892. // const hasValidationRule = window.ssVm?.validations?.has(props.name);
  893. // if (!hasValidationRule) return false;
  894. // if (errMsg.value) return true;
  895. // if (!selectItem.value?.value) return true;
  896. // return false;
  897. // });
  898. const validate = () => {
  899. if (window.ssVm) {
  900. const result = window.ssVm.validateField(props.name);
  901. // console.log("validate", window.ssVm.validateField(props.name));
  902. errMsg.value = result.valid ? "" : result.message;
  903. }
  904. };
  905. //在objPicker界面,选中value对应的项
  906. const updateSelectItem = () => {
  907. // console.log(props.opt);
  908. const item = props.opt.find((it) => it.value === props.modelValue);
  909. if (item) {
  910. selectItem.value = item;
  911. inputText.value = item.label;
  912. } else {
  913. selectItem.value = { label: "", value: "" };
  914. inputText.value = "";
  915. }
  916. // validate();
  917. };
  918. Vue.watch(
  919. () => props.errTip,
  920. (newVal) => {
  921. errMsg.value = newVal;
  922. }
  923. );
  924. // 功能说明:调用全局 onChange 回调,必须在 handleModelValueChange 之前定义 by xu 20260416
  925. const callGlobalOnchg = (value, desc) => {
  926. if (props.onchange && typeof props.onchange === "string") {
  927. if (
  928. typeof window !== "undefined" &&
  929. window[props.onchange] &&
  930. typeof window[props.onchange] === "function"
  931. ) {
  932. try {
  933. window[props.onchange](value, desc);
  934. } catch (error) {
  935. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  936. }
  937. }
  938. }
  939. };
  940. const normalizeObjpResult = (result) => {
  941. const normalized = [];
  942. if (!result) return normalized;
  943. if (Array.isArray(result)) {
  944. result.forEach((item) => {
  945. if (!item || typeof item !== "object") return;
  946. const entry = Object.entries(item)[0];
  947. if (!entry) return;
  948. normalized.push({ label: entry[1], value: entry[0] });
  949. });
  950. return normalized;
  951. }
  952. Object.keys(result).forEach((key) => {
  953. normalized.push({ label: result[key], value: key });
  954. });
  955. return normalized;
  956. };
  957. // 功能说明:封装 modelValue 变化后的联动逻辑,兼容用户点击和桥接 API 赋值 by xu 20260416
  958. const handleModelValueChange = (newValue) => {
  959. updateSelectItem();
  960. if (newValue) {
  961. // 如果当前 options 里没有对应项,去服务端请求回显
  962. const exists = props.opt.some((it) => it.value === newValue);
  963. if (!exists && props.url && props.cb) {
  964. let url = props.url;
  965. if (props.filter) {
  966. const filterObj = props.filter;
  967. for (let k in filterObj) {
  968. url += "&" + k + "=" + filterObj[k];
  969. }
  970. }
  971. const params = new URLSearchParams();
  972. params.append("objectpickerparam", JSON.stringify({ input: props.inp, codebook: props.cb }));
  973. params.append("objectpickertype", "2");
  974. params.append("objectpickervalue", newValue);
  975. axios.post(url, params, {
  976. headers: { "Content-Type": "application/x-www-form-urlencoded" }
  977. }).then((response) => {
  978. if ("timeout" == response.data.statusText) {
  979. alert("网络超时!");
  980. return;
  981. }
  982. if (response.data.result) {
  983. const normalizedResult = normalizeObjpResult(response.data.result);
  984. if (normalizedResult.length === 1) {
  985. let code = normalizedResult[0].value;
  986. let desc = normalizedResult[0].label;
  987. props.opt.length = 0;
  988. props.opt.push({ label: desc, value: code });
  989. updateSelectItem();
  990. callGlobalOnchg(code, desc);
  991. }
  992. }
  993. });
  994. } else if (selectItem.value && selectItem.value.value) {
  995. // options 里有对应项,触发 onChange
  996. callGlobalOnchg(selectItem.value.value, selectItem.value.label);
  997. }
  998. } else {
  999. // 值为空时清空选中
  1000. callGlobalOnchg("", "");
  1001. }
  1002. };
  1003. Vue.watch(() => props.modelValue, handleModelValueChange, { immediate: true });
  1004. Vue.watch(
  1005. () => props.opt,
  1006. (newVal) => {
  1007. updateSelectItem();
  1008. filteredOptions.value = [...newVal];
  1009. // console.log("filteredOptions", filteredOptions.value);
  1010. }
  1011. );
  1012. //初始化objPicker在页面刚打开时的默认值
  1013. async function initDefaultValue() {
  1014. try {
  1015. if (props.url && props.cb && props.modelValue) {
  1016. let objectPickerParam;
  1017. let url = props.url;
  1018. //如果有定义过滤器
  1019. if (props.filter) {
  1020. //包含HTML实体的JSON字符串转为JSON对象,如原字符串是{&quot;dwid&quot;:&quot;88&quot;},注意key也必需用单引号包着
  1021. // const decodedString = props.filter.replace(/&quot;/g, '"'); // 转换为: {"dwid":"88"}
  1022. // objectPickerParam = JSON.parse(decodedString); // 转为json对象
  1023. const filterObj = props.filter; // 转为json对象
  1024. for (let k in filterObj) {
  1025. let v = filterObj[k];
  1026. url += "&" + k + "=" + v;
  1027. }
  1028. objectPickerParam = props.filter; // 转为json对象
  1029. objectPickerParam["input"] = props.inp;
  1030. objectPickerParam["codebook"] = props.cb;
  1031. // alert(url);
  1032. } else {
  1033. objectPickerParam = { input: props.inp, codebook: props.cb };
  1034. }
  1035. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  1036. const params = new URLSearchParams();
  1037. params.append("objectpickerparam", objectPickerParamStr);
  1038. params.append("objectpickertype", "2");
  1039. params.append("objectpickervalue", props.modelValue); //需回显的值
  1040. // alert("1params:"+JSON.stringify(params));
  1041. axios
  1042. .post(props.url, params, {
  1043. headers: {
  1044. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1045. },
  1046. })
  1047. .then((response) => {
  1048. // alert(JSON.stringify(response.data));
  1049. if ("timeout" == response.data.statusText) {
  1050. alert("网络超时!");
  1051. return;
  1052. }
  1053. if (response.data.result) {
  1054. const normalizedResult = normalizeObjpResult(response.data.result);
  1055. if (normalizedResult.length === 1) {
  1056. let code = normalizedResult[0].value;
  1057. let desc = normalizedResult[0].label;
  1058. if (props.opt)
  1059. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  1060. else {
  1061. props.opt = [];
  1062. }
  1063. props.opt.push({ label: desc, value: code });
  1064. updateSelectItem();
  1065. // alert('props.opt:'+JSON.stringify(props.opt));
  1066. }
  1067. }
  1068. });
  1069. }
  1070. } catch (error) {
  1071. // callback(null, error.message); // 失败回调,传递错误
  1072. }
  1073. }
  1074. // Vue.onMounted(updateSelectItem);
  1075. const doSelectItem = (item) => {
  1076. emit("update:modelValue", item.value);
  1077. selectItem.value = item;
  1078. inputText.value = item.label;
  1079. hidePopup();
  1080. nextTick(() => {
  1081. console.log(item.value + "@@@props.modelValue:" + props.modelValue);
  1082. validate();
  1083. if (window.ssVm) {
  1084. // 遍历所有验证规则,找到依赖当前字段的规则
  1085. for (const [field, rules] of window.ssVm.validations.entries()) {
  1086. for (const rule of rules) {
  1087. if (rule.opt?.relField === props.name) {
  1088. // console.log("Found dependent field:", field); // 调试日志
  1089. window.ssVm.validateField(field);
  1090. }
  1091. }
  1092. }
  1093. }
  1094. });
  1095. // callGlobalOnchg 已移到 handleModelValueChange 统一处理,避免用户点击和桥接 API 赋值行为不一致 by xu 20260416
  1096. };
  1097. //可录入的objPicker,更新下拉菜单选项
  1098. async function updateOptionBYInputText(inpTxt) {
  1099. try {
  1100. let objectPickerParam;
  1101. let url = props.url;
  1102. if (props.url && props.cb) {
  1103. //如果有定义过滤器
  1104. if (props.filter || props.filterfield) {
  1105. let filterObj = props.filter;
  1106. if (!props.filter) filterObj = {};
  1107. if (props.filter) {
  1108. const filterObj = props.filter; // 转为json对象
  1109. for (let k in filterObj) {
  1110. let v = filterObj[k];
  1111. url += "&" + k + "=" + v;
  1112. }
  1113. }
  1114. if (props.filterfield) {
  1115. //加上filterfield的值过滤
  1116. let filterfieldArr = props.filterfield.split(",");
  1117. for (var i = 0; i < filterfieldArr.length; i++) {
  1118. let fieldName = filterfieldArr[i];
  1119. let fields = document.getElementsByName(fieldName);
  1120. if (!fields || fields.length < 1) {
  1121. alert("下拉菜单配置的过滤条件" + fieldName + "不存在!");
  1122. continue;
  1123. }
  1124. let v = null;
  1125. for (let j = 0; j < fields.length; j++) {
  1126. if (fields[j].value) {
  1127. v = fields[j].value;
  1128. break;
  1129. }
  1130. }
  1131. // let field = document.getElementsByName(fieldName)[0];
  1132. // let v = field.value;
  1133. if (v) {
  1134. url += "&" + fieldName + "=" + v;
  1135. filterObj[fieldName] = v;
  1136. }
  1137. }
  1138. console.log("filterfield url:" + url);
  1139. }
  1140. //包含HTML实体的JSON字符串转为JSON对象,如原字符串是{&quot;dwid&quot;:&quot;88&quot;},注意key也必需用单引号包着
  1141. // const decodedString = props.filter.replace(/&quot;/g, '"'); // 转换为: {"dwid":"88"}
  1142. // objectPickerParam = JSON.parse(decodedString); // 转为json对象
  1143. objectPickerParam = filterObj;
  1144. objectPickerParam["input"] = props.inp;
  1145. objectPickerParam["codebook"] = props.cb;
  1146. // alert(url);
  1147. } else {
  1148. objectPickerParam = { input: props.inp, codebook: props.cb };
  1149. }
  1150. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  1151. const params = new URLSearchParams();
  1152. params.append("objectpickerparam", objectPickerParamStr);
  1153. params.append("objectpickertype", "1");
  1154. if (props.inp && props.inp === true) {
  1155. //把"true"改为true Ben(20251209)
  1156. params.append("objectpickersearchAll", 0); //只查录入的值
  1157. params.append("objectpickerinput", inpTxt); //录入的值
  1158. // 功能说明:将输入值也加到 URL 参数,避免后端只读 URL 不读 body by xu 20250408
  1159. if (inpTxt) {
  1160. url += "&objectpickerinput=" + encodeURIComponent(inpTxt);
  1161. }
  1162. } else {
  1163. params.append("objectpickersearchAll", 1);
  1164. }
  1165. axios
  1166. .post(url, params, {
  1167. headers: {
  1168. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1169. },
  1170. })
  1171. .then((response) => {
  1172. if ("timeout" == response.data.statusText) {
  1173. alert("网络超时!");
  1174. return;
  1175. }
  1176. // 先清空选项 by xu 20251212
  1177. if (props.opt) {
  1178. props.opt.length = 0;
  1179. } else {
  1180. props.opt = [];
  1181. }
  1182. if (response.data.result) {
  1183. const normalizedResult = normalizeObjpResult(response.data.result);
  1184. // console.log("params:"+params+"@@response.data:"+JSON.stringify(response.data));
  1185. if (normalizedResult.length > 0) {
  1186. normalizedResult.forEach((option) => {
  1187. props.opt.push(option);
  1188. });
  1189. // console.log('###inpTxt:'+inpTxt+';');
  1190. if (
  1191. props.inp &&
  1192. props.inp === true && //把"true"改为true Ben(20251209)
  1193. inpTxt.length > 0
  1194. ) {
  1195. //对于可录入的,用已录入的值作过滤
  1196. filteredOptions.value = props.opt.filter((option) =>
  1197. option.label
  1198. .toLowerCase()
  1199. .includes(inputText.value.toLowerCase())
  1200. );
  1201. // 可录入的objPicker,当搜索结果只有一项时,自动选中这一项 by xu 20251212
  1202. if (filteredOptions.value.length === 1) {
  1203. const autoSelectItem = filteredOptions.value[0];
  1204. console.log(
  1205. "[objp] 搜索结果只有一项,自动选中:",
  1206. autoSelectItem
  1207. );
  1208. doSelectItem(autoSelectItem);
  1209. return; // 自动选中后直接返回,不需要显示popup
  1210. }
  1211. filteredOptions.value.unshift({ label: "", value: "" });
  1212. // console.log('###做了过滤:'+inputText.value.toLowerCase()+';');
  1213. } else {
  1214. filteredOptions.value = props.opt;
  1215. filteredOptions.value.unshift({ label: "", value: "" });
  1216. }
  1217. console.log("props.opt11:" + JSON.stringify(props.opt));
  1218. } else {
  1219. // 没有数据时,清空过滤选项 by xu 20251212
  1220. filteredOptions.value = [];
  1221. console.log("[objp] 接口返回空数据");
  1222. }
  1223. } else {
  1224. // result不存在时,清空过滤选项 by xu 20251212
  1225. filteredOptions.value = [];
  1226. console.log("[objp] 接口返回无result");
  1227. }
  1228. // 无论是否有数据,都显示popup by xu 20251212
  1229. openPopup(); // Teleport 场景下统一打开并重定位 by xu 20260126
  1230. });
  1231. }
  1232. } catch (error) {
  1233. // callback(null, error.message); // 失败回调,传递错误
  1234. }
  1235. }
  1236. // 计算弹出方向和最大高度的方法 by xu 20251212
  1237. // 当空间不足时限制popup高度并显示滚动条
  1238. const calculatePopupDirection = () => {
  1239. const triggerEl =
  1240. selectContainerRef.value?.querySelector(".input") ||
  1241. selectContainerRef.value;
  1242. if (!triggerEl) return;
  1243. const selectRect = triggerEl.getBoundingClientRect();
  1244. const viewportHeight = window.innerHeight;
  1245. // 3. 计算上下可用空间
  1246. const spaceBelow = viewportHeight - selectRect.bottom - 10; // 减10px留边距
  1247. const spaceAbove = selectRect.top - 10; // 减10px留边距
  1248. // 4. popup预估高度(假设每项36px,最多显示8项 + padding)
  1249. const estimatedPopupHeight = 300;
  1250. const minPopupHeight = 100; // 最小高度
  1251. console.log(
  1252. "[popup] 空间计算 - spaceAbove:",
  1253. spaceAbove,
  1254. "spaceBelow:",
  1255. spaceBelow,
  1256. "estimatedHeight:",
  1257. estimatedPopupHeight
  1258. );
  1259. // 5. 判断方向和最大高度 by xu 20251212
  1260. if (spaceBelow >= estimatedPopupHeight) {
  1261. // 下方空间足够,向下展开,不限制高度
  1262. popupDirection.value = "bottom";
  1263. popupMaxHeight.value = "none";
  1264. console.log("[popup] 向下展开,空间充足");
  1265. } else if (spaceAbove >= estimatedPopupHeight) {
  1266. // 上方空间足够,向上展开,不限制高度
  1267. popupDirection.value = "top";
  1268. popupMaxHeight.value = "none";
  1269. console.log("[popup] 向上展开,空间充足");
  1270. } else {
  1271. // 上下空间都不足,选择空间大的方向,并限制高度出滚动条
  1272. if (spaceBelow >= spaceAbove) {
  1273. popupDirection.value = "bottom";
  1274. popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px";
  1275. console.log(
  1276. "[popup] 向下展开,空间不足,限制高度:",
  1277. popupMaxHeight.value
  1278. );
  1279. } else {
  1280. popupDirection.value = "top";
  1281. popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px";
  1282. console.log(
  1283. "[popup] 向上展开,空间不足,限制高度:",
  1284. popupMaxHeight.value
  1285. );
  1286. }
  1287. }
  1288. };
  1289. // Teleport popup 的定位(fixed) by xu 20260126
  1290. const updatePopupPosition = () => {
  1291. const triggerEl =
  1292. selectContainerRef.value?.querySelector(".input") ||
  1293. selectContainerRef.value;
  1294. if (!triggerEl) return;
  1295. const triggerRect = triggerEl.getBoundingClientRect();
  1296. const margin = 10;
  1297. const viewportWidth = window.innerWidth;
  1298. const viewportHeight = window.innerHeight;
  1299. const popupGap = 0; // 功能说明:定位不再做 -10 重叠,让 padding-top 自然形成间距 by xu 20260126
  1300. // 先给一个初始位置,确保下一帧可以测量弹层尺寸 by xu 20260126
  1301. popupLayerStyle.value = {
  1302. position: "fixed",
  1303. left: `${Math.max(margin, triggerRect.left)}px`,
  1304. top: `${Math.max(margin, triggerRect.bottom + popupGap)}px`, // 功能说明:与输入框底部对齐 by xu 20260126
  1305. bottom: "auto", // 功能说明:fixed 场景显式取消 bottom,避免与 top 同时生效 by xu 20260126
  1306. minWidth: `${Math.max(0, triggerRect.width)}px`,
  1307. zIndex: 9999,
  1308. pointerEvents: "auto",
  1309. };
  1310. Vue.nextTick(() => {
  1311. const popupEl = popupRef.value;
  1312. if (!popupEl) return;
  1313. const popupRect = popupEl.getBoundingClientRect();
  1314. const maxLeft = viewportWidth - popupRect.width - margin;
  1315. const left = Math.min(
  1316. Math.max(margin, triggerRect.left),
  1317. Math.max(margin, maxLeft)
  1318. );
  1319. let top;
  1320. if (popupDirection.value === "top") {
  1321. top = triggerRect.top - popupRect.height - popupGap; // 功能说明:向上展开时与输入框顶部对齐 by xu 20260126
  1322. top = Math.max(margin, top);
  1323. } else {
  1324. top = triggerRect.bottom + popupGap; // 功能说明:向下展开时与输入框底部对齐 by xu 20260126
  1325. if (top + popupRect.height > viewportHeight - margin) {
  1326. top = Math.max(
  1327. margin,
  1328. viewportHeight - popupRect.height - margin
  1329. );
  1330. }
  1331. }
  1332. popupLayerStyle.value = {
  1333. ...popupLayerStyle.value,
  1334. left: `${left}px`,
  1335. top: `${top}px`,
  1336. bottom: "auto", // 功能说明:无论 top/bottom 展开都用 top 定位,禁用 bottom by xu 20260126
  1337. };
  1338. });
  1339. };
  1340. const openPopup = () => {
  1341. if (!popupWinVisible.value) popupWinVisible.value = true;
  1342. Vue.nextTick(() => {
  1343. calculatePopupDirection();
  1344. updatePopupPosition();
  1345. });
  1346. };
  1347. // Teleport 场景下:滚动/缩放重定位 by xu 20260126
  1348. const handleViewportChange = () => {
  1349. if (!popupWinVisible.value) return;
  1350. calculatePopupDirection();
  1351. updatePopupPosition();
  1352. };
  1353. // Teleport 场景下:点击外部关闭 by xu 20260126
  1354. const onDocPointerDown = (event) => {
  1355. if (!popupWinVisible.value) return;
  1356. const target = event.target;
  1357. if (selectContainerRef.value?.contains(target)) return;
  1358. if (popupRef.value?.contains(target)) return;
  1359. hidePopup();
  1360. };
  1361. //点击下拉菜单的文本区域时,会触发的方法
  1362. function togglePopup() {
  1363. // 可录入的 objPicker,更新下拉菜单选项
  1364. updateOptionBYInputText(inputText.value);
  1365. // popupWinVisible.value = !popupWinVisible.value;
  1366. Vue.nextTick(() => {
  1367. calculatePopupDirection();
  1368. updatePopupPosition(); // Teleport 场景下同步定位 by xu 20260126
  1369. });
  1370. }
  1371. const hidePopup = () => {
  1372. popupWinVisible.value = false;
  1373. };
  1374. //点击下拉菜单的三角形时,会触发的方法
  1375. // 添加toggle逻辑,点击时切换显示/隐藏 by xu 20251212
  1376. const suffixClick = () => {
  1377. // 如果popup已显示,则关闭 by xu 20251212
  1378. if (popupWinVisible.value) {
  1379. hidePopup();
  1380. console.log("[objp] 点三角关闭popup");
  1381. return;
  1382. }
  1383. //可录入的objPicker,更新下拉菜单选项
  1384. updateOptionBYInputText("");
  1385. Vue.nextTick(() => {
  1386. calculatePopupDirection();
  1387. updatePopupPosition(); // Teleport 场景下同步定位 by xu 20260126
  1388. });
  1389. console.log("[objp] 点三角打开popup");
  1390. };
  1391. //可录入的objPicker,录入项变化时,会触发
  1392. async function handleInputChange(event) {
  1393. inputText.value = event.target.value;
  1394. if (!inputText.value) {
  1395. inputText.value = "";
  1396. }
  1397. //可录入的objPicker,更新下拉菜单选项
  1398. updateOptionBYInputText(inputText.value);
  1399. // filteredOptions.value = props.opt.filter((option) =>
  1400. // option.label.toLowerCase().includes(inputText.value.toLowerCase())
  1401. // );
  1402. // if (!popupWinVisible.value) {
  1403. // popupWinVisible.value = true; // 确保下拉框在输入时打开
  1404. // }
  1405. }
  1406. Vue.onMounted(() => {
  1407. initDefaultValue();
  1408. // Teleport 场景下:滚动/缩放需要重定位(scroll 用 capture 捕获容器滚动) by xu 20260126
  1409. window.addEventListener("resize", handleViewportChange);
  1410. window.addEventListener("scroll", handleViewportChange, true);
  1411. // 点击外部关闭(原本依赖 mouseleave,Teleport 后会误关) by xu 20260126
  1412. document.addEventListener("pointerdown", onDocPointerDown, true);
  1413. });
  1414. Vue.onUnmounted(() => {
  1415. window.removeEventListener("resize", handleViewportChange);
  1416. window.removeEventListener("scroll", handleViewportChange, true);
  1417. document.removeEventListener("pointerdown", onDocPointerDown, true);
  1418. });
  1419. return {
  1420. errMsg,
  1421. selectItem,
  1422. inputText,
  1423. canInput,
  1424. filteredOptions,
  1425. popupWinVisible,
  1426. popupDirection,
  1427. popupMaxHeight, // 添加popup最大高度 by xu 20251212
  1428. popupContentAreaMaxHeight,
  1429. selectContainerRef,
  1430. popupRef,
  1431. teleportRootStyle,
  1432. popupLayerStyle,
  1433. suffixClick,
  1434. togglePopup,
  1435. hidePopup,
  1436. doSelectItem,
  1437. handleInputChange,
  1438. };
  1439. },
  1440. template: `
  1441. <div class="input" style="position: relative" :style="{width: width}">
  1442. <div class="select-container" ref="selectContainerRef">
  1443. <div class="input" @click="togglePopup">
  1444. <input
  1445. type="hidden"
  1446. :name="name"
  1447. :value="selectItem.value"
  1448. .value="selectItem.value"
  1449. />
  1450. <input
  1451. v-model="inputText"
  1452. @input="handleInputChange"
  1453. v-if="canInput"
  1454. :placeholder="placeholder"
  1455. />
  1456. <input
  1457. v-else
  1458. :placeholder="placeholder"
  1459. :value="selectItem.label"
  1460. disabled
  1461. style="pointer-events: none;"
  1462. />
  1463. <div class="suffix" @click.stop="suffixClick">
  1464. <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
  1465. </div>
  1466. </div>
  1467. <!-- 修复表格内弹层被截断:popup Teleport 到 body by xu 20260126 -->
  1468. <teleport to="body">
  1469. <div v-show="popupWinVisible" class="select-container ss-objp-teleport-root" :style="teleportRootStyle">
  1470. <!-- popup弹出层,添加maxHeight和overflowY支持空间不足时滚动 by xu 20251212 -->
  1471. <div ref="popupRef" class="popup-win" :class="popupDirection" :style="[popupLayerStyle, { maxHeight: popupMaxHeight !== 'none' ? popupMaxHeight : 'none', overflowY: 'visible' }]">
  1472. <div v-if="opt && opt.length && filteredOptions.length > 0" class="popup-content">
  1473. <div class="content-area" :style="popupContentAreaMaxHeight ? { maxHeight: popupContentAreaMaxHeight, overflowY: 'auto' } : null">
  1474. <div v-for="(item, index) in filteredOptions" :key="index" @click="doSelectItem(item)" :class="{ active: item.value === selectItem.value }">
  1475. <span class="check-icon">
  1476. <ss-form-icon class="form-icon-select-checked" />
  1477. </span>
  1478. <span>{{ item.label }}</span>
  1479. </div>
  1480. </div>
  1481. </div>
  1482. <div v-else class="popup-content"><div class="content-area"><div class="content-area"> <span>无选项</span></div></div></div>
  1483. </div>
  1484. </div>
  1485. </teleport>
  1486. </div>
  1487. </div>
  1488. `,
  1489. };
  1490. // ss-hidden 隐藏字段组件
  1491. const SsHidden = {
  1492. name: "SsHidden",
  1493. props: {
  1494. modelValue: String,
  1495. name: {
  1496. type: String,
  1497. required: true,
  1498. },
  1499. rule: {
  1500. type: String,
  1501. required: false,//因为要单独发布非级联用的隐藏字段,改为非必需
  1502. },
  1503. param: {
  1504. type: String,
  1505. required: false,//因为要单独发布非级联用的隐藏字段,改为非必需
  1506. },
  1507. url: {
  1508. type: String,
  1509. required: false,//因为要单独发布非级联用的隐藏字段,改为非必需
  1510. },
  1511. },
  1512. emits: ["update:modelValue"],
  1513. setup(props, { emit }) {
  1514. const errMsg = Vue.ref("");
  1515. const validate = () => {
  1516. if (window.ssVm) {
  1517. const result = window.ssVm.validateField(props.name);
  1518. console.log("validate", window.ssVm.validateField(props.name));
  1519. errMsg.value = result.valid ? "" : result.message;
  1520. }
  1521. };
  1522. Vue.onMounted(() => {
  1523. /**
  1524. * 初始化级联菜单值初始值思路:
  1525. * 1. 带隐藏字段(即带编码规则)的级联菜单
  1526. * 在隐藏字段这,可以取到要回显的值和编码规则,从而计算出各级下拉菜单要回显的值。
  1527. * 然后通过ajax取各级级联菜单的值回显。
  1528. * 2. 不带隐藏字段的级联,只能在各个下拉菜单的setup事件中通过ajax取回显值回显
  1529. */
  1530. // 当同组级联下拉菜单选中值变化时,会调用本隐藏字段下面这方法设置隐藏字段值
  1531. window.addEventListener(
  1532. "cascader-setHiddenVal-" + props.name,
  1533. (event) => {
  1534. const { value } = event.detail;
  1535. emit("update:modelValue", value);
  1536. console.log(value);
  1537. setTimeout(() => {
  1538. validate();
  1539. }, 50);
  1540. }
  1541. );
  1542. // 如果有初始值,触发回显过程
  1543. if (props.modelValue&&props.param) {//增加props.param非空判断,非级联的hidden没props.param Ben(20260414)
  1544. console.log("级联隐藏字段,开始回显,初始值:", props.modelValue);
  1545. triggerCascaderEcho(props.modelValue);
  1546. validate();
  1547. }
  1548. });
  1549. // 触发级联回显
  1550. const triggerCascaderEcho = (code) => {
  1551. /**
  1552. * 开始回显,初始值: 440304
  1553. * 解析后的所有值: Array(3)0: "440000"1: "440300"2: "440304"length: 3[[Prototype]]: Array(0)
  1554. */
  1555. const values = parseHiddenCodeForAll(code, props.rule);
  1556. console.log("解析后的所有值:", values);
  1557. // 转换为 JSON 对象
  1558. // const paramObj = JSON.parse(props.param);
  1559. const paramObj = props.param;
  1560. let selectArr = paramObj.fieldOrd; //保存本组级联菜单项的数组,如:['hksheng','hkshi','hkxian']
  1561. if (selectArr.length != values.length) {
  1562. // alert('属性'+props.name+'的值'+code+'与级联菜单中下拉菜单的数目不匹配!');
  1563. return;
  1564. }
  1565. // 按顺序触发回显,并增加延迟确保数据加载
  1566. /**
  1567. * 通过隐藏字段的setup事件,
  1568. * 循环遍历各级下拉菜单,并触发定义在下拉菜单中的'cascader-echo'事件,
  1569. * 在此事件中完成每个下拉菜单回显值操作(只取当前要回显的键值对显示,
  1570. * 下拉菜单所有的值,在点击下拉菜单时,才通过ajax取)。
  1571. */
  1572. values.forEach((value, index) => {
  1573. if (value) {
  1574. setTimeout(() => {
  1575. let upperVal = undefined;
  1576. if (index != 0) {
  1577. upperVal = values[index - 1];
  1578. }
  1579. const echoEvent = new CustomEvent(
  1580. "cascader-echo-" + selectArr[index],
  1581. {
  1582. detail: {
  1583. name: props.name,
  1584. value: value,
  1585. // level: index + 1,
  1586. isAuto: true, // 标记为自动回显
  1587. upperVal: upperVal,
  1588. },
  1589. }
  1590. );
  1591. console.log(props.name + "--upperValue:" + upperVal);
  1592. window.dispatchEvent(echoEvent);
  1593. }, index * 500); // 每级增加500ms延迟
  1594. }
  1595. });
  1596. };
  1597. // 解析所有级别的代码
  1598. const parseHiddenCodeForAll = (code, rule) => {
  1599. if (!code || !rule) return [];
  1600. // 获取规则中每段的长度
  1601. const segments = [];
  1602. let currentChar = rule[0];
  1603. let currentLength = 1;
  1604. for (let i = 1; i < rule.length; i++) {
  1605. if (rule[i] === currentChar) {
  1606. currentLength++;
  1607. } else {
  1608. segments.push(currentLength);
  1609. currentChar = rule[i];
  1610. currentLength = 1;
  1611. }
  1612. }
  1613. segments.push(currentLength);
  1614. // 解析每一级的值
  1615. const values = [];
  1616. let position = 0;
  1617. segments.forEach((length, index) => {
  1618. const value = code
  1619. .substring(0, position + length)
  1620. .padEnd(rule.length, "0");
  1621. values.push(value);
  1622. position += length;
  1623. });
  1624. return values;
  1625. };
  1626. watchEffect(() => {});
  1627. return {};
  1628. },
  1629. template: `<input type="hidden" :name="name" :value="modelValue">`,
  1630. };
  1631. // ss-cascader 级联选择器
  1632. const SsCcp = {
  1633. name: "SsCcp",
  1634. inheritAttrs: false,
  1635. props: {
  1636. modelValue: String,
  1637. name: {
  1638. type: String,
  1639. required: true,
  1640. },
  1641. level: {
  1642. type: Number,
  1643. required: true,
  1644. },
  1645. opt: {
  1646. type: Array,
  1647. default: () => [],
  1648. },
  1649. placeholder: {
  1650. type: String,
  1651. default: "请选择",
  1652. },
  1653. width: {
  1654. type: String,
  1655. default: "150px",
  1656. },
  1657. direction: {
  1658. type: String,
  1659. default: "bottom",
  1660. },
  1661. mode: {
  1662. type: String,
  1663. default: "1",
  1664. },
  1665. inp: {
  1666. type: Boolean,
  1667. default: false,
  1668. },
  1669. //级联菜单配置参数,如果是数组,则代表本下拉菜单是多套级联菜单共用的第一级菜单。如果是对象,则只有一套级联菜单用此下拉菜单。
  1670. param: {
  1671. type: String,
  1672. required: true,
  1673. },
  1674. //向后台拿数据的url
  1675. url: {
  1676. type: String,
  1677. required: true,
  1678. },
  1679. },
  1680. emits: ["update:modelValue", "change"],
  1681. setup(props, { emit }) {
  1682. const canInput = props.inp === true;
  1683. const inputText = Vue.ref("");
  1684. const filteredOptions = Vue.ref(props.opt);
  1685. const visibleOptions = Vue.computed(() =>
  1686. canInput ? filteredOptions.value : props.opt
  1687. );
  1688. let inputRequestId = 0;
  1689. // alert('级联菜单初始化:'+props.name+':--:'+props.modelValue);
  1690. const selectItem = Vue.ref({ label: props.placeholder, value: "" });
  1691. const popupWinVisible = Vue.ref(false);
  1692. const isAutoEcho = Vue.ref(false); // 用于标记是否是自动回显
  1693. const upperValue = Vue.ref(""); //上级下拉菜单当前值,在初始化下拉菜单默认值时,和上级下拉菜单的值变化时,修改此upperValue变量
  1694. const popupDirection = Vue.ref("bottom");
  1695. const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
  1696. const selectContainerRef = Vue.ref(null);
  1697. const popupRef = Vue.ref(null);
  1698. const teleportRootStyle = Vue.ref({
  1699. position: "fixed",
  1700. left: "0",
  1701. top: "0",
  1702. width: "0",
  1703. height: "0",
  1704. zIndex: 9999,
  1705. pointerEvents: "none",
  1706. });
  1707. const popupLayerStyle = Vue.ref({
  1708. position: "fixed",
  1709. left: "0",
  1710. top: "0",
  1711. bottom: "auto",
  1712. minWidth: "0",
  1713. zIndex: 9999,
  1714. pointerEvents: "auto",
  1715. });
  1716. //有隐藏字段的下拉菜单,加载菜单项并展开事件
  1717. // 被上级下拉菜单选中值后,触发本下拉菜单刷新菜单项并弹出显示
  1718. window.addEventListener("cascader-open-" + props.name, async (event) => {
  1719. const { upperVal } = event.detail;
  1720. upperValue.value = upperVal;
  1721. console.log(
  1722. "22props.name:" +
  1723. props.name +
  1724. ",22props.upperValue:" +
  1725. upperValue.value
  1726. );
  1727. selectItem.value = ""; //清除本下拉菜单当前选中的值
  1728. inputText.value = "";
  1729. filteredOptions.value = props.opt;
  1730. emit("update:modelValue", ""); //通知父级
  1731. //清空下拉菜单,并设置第一项的值为placeholder
  1732. clearAndInit1stOpt();
  1733. //下个下拉菜单名
  1734. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1735. if (nextSelName) {
  1736. //清下个下拉菜单选中值和选项
  1737. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  1738. detail: {},
  1739. });
  1740. window.dispatchEvent(event);
  1741. }
  1742. showPopup();
  1743. });
  1744. //设置mode2的下级下拉菜单的上级菜单当前值
  1745. function setNextSelectUpperValue() {
  1746. //设置下级菜单的上级菜单当前值upperValue
  1747. let paramArr = undefined;
  1748. if (Array.isArray(props.param)) {
  1749. paramArr = props.param;
  1750. } else {
  1751. paramArr = [];
  1752. paramArr.push(props.param);
  1753. }
  1754. for (const oneParam of paramArr) {
  1755. //下个下拉菜单名
  1756. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  1757. if (nextSelName) {
  1758. setTimeout(() => {
  1759. const openNextEvent = new CustomEvent(
  1760. "cascade-setUpperVal-" + nextSelName,
  1761. {
  1762. detail: {
  1763. upperVal: props.modelValue,
  1764. },
  1765. }
  1766. );
  1767. window.dispatchEvent(openNextEvent);
  1768. }, 100);
  1769. }
  1770. } // end for
  1771. }
  1772. // 把上级 级联下拉菜单的值,设置进本组件的事件
  1773. window.addEventListener("cascade-setUpperVal-" + props.name, (event) => {
  1774. // alert('props.name:'+props.name+',props.upperValue:'+event.detail.upperVal);
  1775. const { upperVal } = event.detail;
  1776. upperValue.value = upperVal;
  1777. // console.log('props.name:'+props.name+',props.upperValue:'+upperValue.value);
  1778. });
  1779. //清空下拉菜单,并设置第一项的值为空
  1780. function clearAndInit1stOpt() {
  1781. if (props.opt)
  1782. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  1783. else {
  1784. props.opt = [];
  1785. }
  1786. props.opt.push({ label: "", value: "" });
  1787. }
  1788. // 兼容旧版 Map 结果和新版 List<Map> 结果,避免下拉项显示为 [object Object]
  1789. function normalizeCcpResult(result) {
  1790. const normalized = [];
  1791. if (!result) {
  1792. return normalized;
  1793. }
  1794. if (Array.isArray(result)) {
  1795. result.forEach((item) => {
  1796. if (!item || typeof item !== "object") {
  1797. return;
  1798. }
  1799. const entry = Object.entries(item)[0];
  1800. if (!entry) {
  1801. return;
  1802. }
  1803. normalized.push({
  1804. label: entry[1],
  1805. value: entry[0],
  1806. });
  1807. });
  1808. return normalized;
  1809. }
  1810. Object.keys(result).forEach((key) => {
  1811. normalized.push({
  1812. label: result[key],
  1813. value: key,
  1814. });
  1815. });
  1816. return normalized;
  1817. }
  1818. //获取下一级下拉菜单,如果下一级下拉菜单不存在,则返回undefined
  1819. function getNextSel(selName, selNameArr) {
  1820. // 检查参数有效性
  1821. if (!Array.isArray(selNameArr) || selNameArr.length === 0) {
  1822. return undefined;
  1823. }
  1824. // 查找当前元素的索引
  1825. const currentIndex = selNameArr.indexOf(selName);
  1826. // 如果元素不存在或已经是最后一个元素,返回undefined
  1827. if (currentIndex === -1 || currentIndex === selNameArr.length - 1) {
  1828. return undefined;
  1829. }
  1830. // 返回下一个元素
  1831. return selNameArr[currentIndex + 1];
  1832. }
  1833. const validate = () => {
  1834. if (window.ssVm) {
  1835. return window.ssVm.validateField(props.name);
  1836. }
  1837. return { valid: true };
  1838. };
  1839. const updateSelectItem = () => {
  1840. const item = props.opt.find((it) => it.value === props.modelValue);
  1841. if (item) {
  1842. selectItem.value = item;
  1843. inputText.value = item.label;
  1844. } else {
  1845. selectItem.value = { label: "", value: "" };
  1846. inputText.value = "";
  1847. }
  1848. };
  1849. // 处理选择事件
  1850. const doSelectItem = (item) => {
  1851. selectItem.value = item;
  1852. inputText.value = item.label;
  1853. emit("update:modelValue", item.value); //修改本下拉菜单在vue中保存的值
  1854. // alert('item.value:'+item.value);
  1855. if (props.mode === "1") {
  1856. // mode 1 模式:修改隐藏字段值
  1857. let event = new CustomEvent(
  1858. "cascader-setHiddenVal-" + props.param.combField,
  1859. {
  1860. detail: {
  1861. value: item.value,
  1862. },
  1863. }
  1864. );
  1865. window.dispatchEvent(event);
  1866. }
  1867. emit("change", item.value); //触发配置的change方法
  1868. nextTick(() => {
  1869. validate();
  1870. if (window.ssVm) {
  1871. for (const [field, rules] of window.ssVm.validations.entries()) {
  1872. for (const rule of rules) {
  1873. if (rule.options?.relField) {
  1874. const relFields = String(rule.options.relField)
  1875. .split(",")
  1876. .map((name) => name.trim())
  1877. .filter(Boolean);
  1878. if (relFields.includes(props.name)) {
  1879. window.ssVm.validateField(field);
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. });
  1886. //设置下级菜单的上级菜单当前值upperValue
  1887. let paramArr = undefined;
  1888. if (Array.isArray(props.param)) {
  1889. paramArr = props.param;
  1890. } else {
  1891. paramArr = [];
  1892. paramArr.push(props.param);
  1893. }
  1894. for (const oneParam of paramArr) {
  1895. //下个下拉菜单名
  1896. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  1897. if (nextSelName) {
  1898. setTimeout(() => {
  1899. const openNextEvent = new CustomEvent(
  1900. "cascader-open-" + nextSelName,
  1901. {
  1902. detail: {
  1903. upperVal: item.value,
  1904. },
  1905. }
  1906. );
  1907. window.dispatchEvent(openNextEvent);
  1908. }, 100);
  1909. }
  1910. } // end for
  1911. hidePopup();
  1912. //下个下拉菜单名
  1913. // let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1914. // if(nextSelName){
  1915. // // //设置下一级下拉菜单中保存的本下拉菜单值(upperValue)
  1916. // // event = new CustomEvent('cascade-setUpperVal-'+nextSelName, {
  1917. // // detail: {
  1918. // // value: item.value
  1919. // // }
  1920. // // });
  1921. // // window.dispatchEvent(event);
  1922. //
  1923. // //触发下一级下拉菜单,重新初始化下拉菜单项并弹出显示
  1924. // event = new CustomEvent('cascader-open-' +nextSelName, {
  1925. // detail: {
  1926. // upperVal: item.value
  1927. // }
  1928. // });
  1929. // window.dispatchEvent(event);
  1930. // }
  1931. // 只在手动选择时自动展开下一级
  1932. // if (!isAutoEcho.value) {
  1933. // const nextLevel = props.level + 1;
  1934. // setTimeout(() => {
  1935. // const openNextEvent = new CustomEvent('open-next-cascader', {
  1936. // detail: {
  1937. // name: props.name,
  1938. // level: nextLevel
  1939. // }
  1940. // });
  1941. // window.dispatchEvent(openNextEvent);
  1942. // }, 100);
  1943. // }
  1944. };
  1945. // 监听下一级展开事件 (仅 mode 2)
  1946. window.addEventListener("cascade-open", (event) => {
  1947. if (props.mode === "2") {
  1948. const { level } = event.detail;
  1949. if (level === props.level) {
  1950. popupWinVisible.value = true;
  1951. }
  1952. }
  1953. });
  1954. if (props.mode === "1") {
  1955. //如果是有隐藏字段的下拉菜单
  1956. // 监听回显事件
  1957. window.addEventListener(
  1958. "cascader-echo-" + props.name,
  1959. async (event) => {
  1960. const { name, value, isAuto, upperVal } = event.detail;
  1961. // level,
  1962. if (upperVal) {
  1963. upperValue.value = upperVal;
  1964. console.log(
  1965. "value:" +
  1966. value +
  1967. ",upperValue:" +
  1968. upperValue +
  1969. ",初始化级联组件时props.name:" +
  1970. props.name
  1971. );
  1972. }
  1973. // if (name === props.name && level === props.level) {
  1974. // 设置自动回显标记
  1975. isAutoEcho.value = true;
  1976. // if (props.opt.length === 0) {
  1977. // const loadDataEvent = new CustomEvent('cascader-load-data', {
  1978. // detail: {
  1979. // name: props.name,
  1980. // level: props.level,
  1981. // value: value
  1982. // }
  1983. // });
  1984. // window.dispatchEvent(loadDataEvent);
  1985. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  1986. //Vue.watch用于监听数据的变化,并在数据变化时执行特定的回调函数。
  1987. //这段代码使用了 Vue.js 的 watch API 来监听 props.opt 的变化,如果props.opt有变化,则自动
  1988. // const unwatch = Vue.watch(
  1989. // () => props.opt, // 监听的数据源(props.opt)
  1990. // (newOptions) => { // 回调函数
  1991. // if (newOptions.length > 0) { // 条件判断
  1992. // matchAndSelect(value); // 执行逻辑
  1993. // unwatch(); // 停止监听
  1994. // }
  1995. // },
  1996. // { immediate: true } // 配置:立即触发一次
  1997. // );
  1998. // } else {
  1999. // matchAndSelect(value);
  2000. // }
  2001. // 初始化级联菜单在页面刚打开时的默认值
  2002. async function initDefaultValue(value) {
  2003. try {
  2004. // alert(1);
  2005. if (
  2006. props.url &&
  2007. props.param
  2008. // && props.modelValue 对于有rule编码规则的级联菜单(即mode=1),modelValue一定是空的,所以注释掉,修复mode=1的级联菜单无法回显问题。Ben(20251124)
  2009. ) {
  2010. // alert(2);
  2011. /**
  2012. * let objectPickerParam=
  2013. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  2014. * "\"name\":\"hksheng\"," +
  2015. * "\"cascadingName\":\"dq\",\"cascadingInputsName\":\"hkdqm\"," +
  2016. * "\"codebook\":\"sheng\"}",
  2017. * "objectpickertype":2,
  2018. * "objectpickervalue":"440000"
  2019. * };
  2020. */
  2021. const objectPickerParam = {
  2022. input: "false",
  2023. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2024. name: props.name, //本下拉菜单名
  2025. cascadingName: props.param.name, //级联菜单名
  2026. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  2027. codebook: props.param.codebook,
  2028. };
  2029. const objectPickerParamStr =
  2030. JSON.stringify(objectPickerParam);
  2031. const params = new URLSearchParams();
  2032. params.append("objectpickerparam", objectPickerParamStr);
  2033. params.append("objectpickertype", "2");
  2034. params.append("objectpickervalue", value); //需回显的值
  2035. axios
  2036. .post(props.url, params, {
  2037. headers: {
  2038. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2039. },
  2040. })
  2041. .then((response) => {
  2042. // alert(JSON.stringify(response.data));
  2043. if ("timeout" == response.data.statusText) {
  2044. alert("网络超时!");
  2045. return;
  2046. }
  2047. if (response.data.result) {
  2048. const normalizedResult = normalizeCcpResult(
  2049. response.data.result
  2050. );
  2051. if (normalizedResult.length === 1) {
  2052. const option = normalizedResult[0];
  2053. clearAndInit1stOpt();
  2054. props.opt.push(option);
  2055. if (value) matchAndSelect(value);
  2056. // updateSelectItem();
  2057. // alert('props.opt:'+JSON.stringify(props.opt));
  2058. }
  2059. }
  2060. });
  2061. }
  2062. } catch (error) {
  2063. alert(error);
  2064. // callback(null, error.message); // 失败回调,传递错误
  2065. }
  2066. }
  2067. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  2068. initDefaultValue(value);
  2069. // 延迟重置自动回显标记
  2070. setTimeout(() => {
  2071. isAutoEcho.value = false;
  2072. }, 500);
  2073. }
  2074. );
  2075. // 被上级下拉菜单触发的,清除选中值和下拉菜单选项
  2076. window.addEventListener(
  2077. "cascader-cleanOpt-" + props.name,
  2078. async (event) => {
  2079. upperValue.value = "";
  2080. selectItem.value = ""; //清除本下拉菜单当前选中的值
  2081. inputText.value = "";
  2082. filteredOptions.value = props.opt;
  2083. emit("update:modelValue", ""); //通知父级
  2084. //清空所有下拉菜单项
  2085. if (props.opt) {
  2086. props.opt.length = 0;
  2087. } else {
  2088. props.opt = [];
  2089. }
  2090. //下个下拉菜单名
  2091. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  2092. // alert('nextSelName:'+nextSelName+'--,props.name:'+props.name);
  2093. if (nextSelName) {
  2094. //清下个下拉菜单选中值和选项
  2095. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  2096. detail: {},
  2097. });
  2098. window.dispatchEvent(event);
  2099. }
  2100. }
  2101. );
  2102. } else if (props.mode === "2") {
  2103. //没隐藏字段的下拉菜单,在这初始化默认值
  2104. let needInitParam = undefined;
  2105. if (Array.isArray(props.param)) {
  2106. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  2107. console.log("needInitParam最后一项:" + JSON.stringify(needInitParam));
  2108. } else {
  2109. needInitParam = props.param;
  2110. }
  2111. // 初始化级联菜单在页面刚打开时的默认值
  2112. async function initDefaultValue(value, param) {
  2113. try {
  2114. // alert(1);
  2115. if (props.url && param && props.modelValue) {
  2116. // alert(2);
  2117. /**
  2118. * let param=
  2119. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"rylbm,gwid\"," +
  2120. * "\"name\":\"gwid\",\"cascadingName\":\"rylb_gw\"," +
  2121. * "\"codebook\":\"gwByRylb\"}",
  2122. * "objectpickertype":2,
  2123. * "objectpickervalue":"102121"};
  2124. */
  2125. // alert('props.name:'+props.name+',props.param.fieldOrd:'+props.param.fieldOrd);
  2126. const objectPickerParam = {
  2127. input: "false",
  2128. cascadingLevel: param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2129. name: props.name, //本下拉菜单名
  2130. cascadingName: param.name, //级联菜单名
  2131. codebook: param.codebook,
  2132. };
  2133. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2134. const sendParams = new URLSearchParams();
  2135. sendParams.append("objectpickerparam", objectPickerParamStr);
  2136. sendParams.append("objectpickertype", "2");
  2137. sendParams.append("objectpickervalue", value); //需回显的值
  2138. axios
  2139. .post(props.url, sendParams, {
  2140. headers: {
  2141. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2142. },
  2143. })
  2144. .then((response) => {
  2145. // alert(JSON.stringify(response.data));
  2146. if ("timeout" == response.data.statusText) {
  2147. alert("网络超时!");
  2148. return;
  2149. }
  2150. if (response.data.result) {
  2151. const normalizedResult = normalizeCcpResult(
  2152. response.data.result
  2153. );
  2154. console.log(
  2155. "name:" +
  2156. props.name +
  2157. ",@@级联初始化默认值value:" +
  2158. value +
  2159. "--param:" +
  2160. JSON.stringify(param) +
  2161. "--objectPickerParamStr:" +
  2162. objectPickerParamStr +
  2163. "--response.data:" +
  2164. JSON.stringify(response.data)
  2165. );
  2166. if (normalizedResult.length === 1) {
  2167. const option = normalizedResult[0];
  2168. if (props.opt)
  2169. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  2170. else {
  2171. props.opt = [];
  2172. }
  2173. props.opt.push(option);
  2174. if (value) matchAndSelect(value);
  2175. console.log(
  2176. "GOOD mode2回显的默认值:" +
  2177. JSON.stringify(option) +
  2178. "--props.param:" +
  2179. JSON.stringify(param)
  2180. );
  2181. // updateSelectItem();
  2182. // alert('props.opt:'+JSON.stringify(props.opt));
  2183. }
  2184. }
  2185. });
  2186. }
  2187. } catch (error) {
  2188. alert(error);
  2189. // callback(null, error.message); // 失败回调,传递错误
  2190. }
  2191. // 重置自动回显标记
  2192. isAutoEcho.value = false;
  2193. }
  2194. // 初始化级联菜单在页面刚打开时的默认值
  2195. initDefaultValue(props.modelValue, needInitParam);
  2196. //设置mode2的下级下拉菜单的上级菜单当前值
  2197. setNextSelectUpperValue();
  2198. }
  2199. //选中要回显的默认值
  2200. const matchAndSelect = (value) => {
  2201. const matchedOption = props.opt.find((opt) => opt.value === value);
  2202. if (matchedOption) {
  2203. selectItem.value = matchedOption;
  2204. inputText.value = matchedOption.label;
  2205. emit("update:modelValue", value);
  2206. emit("change", value);
  2207. }
  2208. };
  2209. async function updateOptionBYInputText(inputValue) {
  2210. const pickerParam = Array.isArray(props.param)
  2211. ? props.param[props.param.length - 1]
  2212. : props.param;
  2213. if (!props.url || !pickerParam || !pickerParam.codebook) return;
  2214. const requestId = ++inputRequestId;
  2215. const searchText = inputValue || "";
  2216. const searchAll = searchText.trim().length === 0;
  2217. let url = props.url;
  2218. const filterObj = {
  2219. ...(pickerParam.filter && typeof pickerParam.filter === "object"
  2220. ? pickerParam.filter
  2221. : {}),
  2222. };
  2223. Object.keys(filterObj).forEach((key) => {
  2224. url += "&" + key + "=" + encodeURIComponent(filterObj[key]);
  2225. });
  2226. if (pickerParam.filterfield) {
  2227. const filterFields = String(pickerParam.filterfield).split(",");
  2228. filterFields.forEach((fieldName) => {
  2229. const fields = document.getElementsByName(fieldName);
  2230. if (!fields || fields.length < 1) {
  2231. console.warn("下拉菜单配置的过滤条件" + fieldName + "不存在");
  2232. return;
  2233. }
  2234. const field = Array.from(fields).find((item) => item.value);
  2235. if (field) {
  2236. url += "&" + fieldName + "=" + encodeURIComponent(field.value);
  2237. filterObj[fieldName] = field.value;
  2238. }
  2239. });
  2240. }
  2241. const objectPickerParam = {
  2242. ...filterObj,
  2243. input: props.inp,
  2244. codebook: pickerParam.codebook,
  2245. cascadingLevel: Array.isArray(pickerParam.fieldOrd)
  2246. ? pickerParam.fieldOrd.join(",")
  2247. : pickerParam.fieldOrd || "",
  2248. name: props.name,
  2249. cascadingName: pickerParam.name,
  2250. };
  2251. if (pickerParam.combField) {
  2252. objectPickerParam.cascadingInputsName = pickerParam.combField;
  2253. }
  2254. const params = new URLSearchParams();
  2255. params.append("objectpickerparam", JSON.stringify(objectPickerParam));
  2256. params.append("objectpickertype", "1");
  2257. params.append("objectpickersearchAll", searchAll ? "1" : "0");
  2258. params.append("objectpickerinput", searchAll ? "" : searchText);
  2259. if (!searchAll) {
  2260. url += "&objectpickerinput=" + encodeURIComponent(searchText);
  2261. }
  2262. if (upperValue.value) {
  2263. params.append("upperValue", upperValue.value);
  2264. }
  2265. try {
  2266. const response = await axios.post(url, params, {
  2267. headers: {
  2268. "Content-Type": "application/x-www-form-urlencoded",
  2269. },
  2270. });
  2271. if (requestId !== inputRequestId) return;
  2272. if (response.data.statusText === "timeout") {
  2273. alert("网络超时!");
  2274. return;
  2275. }
  2276. const normalizedResult = normalizeCcpResult(response.data.result);
  2277. props.opt.length = 0;
  2278. normalizedResult.forEach((option) => props.opt.push(option));
  2279. const matchedOptions = searchAll
  2280. ? normalizedResult
  2281. : normalizedResult.filter((option) =>
  2282. String(option.label)
  2283. .toLowerCase()
  2284. .includes(searchText.toLowerCase())
  2285. );
  2286. filteredOptions.value = matchedOptions.length
  2287. ? [{ label: "", value: "" }, ...matchedOptions]
  2288. : [];
  2289. openPopup();
  2290. } catch (error) {
  2291. console.error("[SsCcp] 输入筛选失败:", error);
  2292. }
  2293. }
  2294. // 计算弹出方向和最大高度的方法 by xu 20251212
  2295. // 当空间不足时限制popup高度并显示滚动条
  2296. const calculatePopupDirection = () => {
  2297. const triggerEl =
  2298. selectContainerRef.value?.querySelector(".input") ||
  2299. selectContainerRef.value;
  2300. if (!triggerEl) return;
  2301. // 2. 获取位置信息
  2302. const selectRect = triggerEl.getBoundingClientRect();
  2303. const viewportHeight = window.innerHeight;
  2304. // 3. 计算上下可用空间 by xu 20251212
  2305. const spaceBelow = viewportHeight - selectRect.bottom - 10; // 减10px留边距
  2306. const spaceAbove = selectRect.top - 10; // 减10px留边距
  2307. // 4. popup预估高度(假设每项36px,最多显示8项 + padding)
  2308. const estimatedPopupHeight = 300;
  2309. const minPopupHeight = 100; // 最小高度
  2310. console.log(
  2311. "[popup] 空间计算 - spaceAbove:",
  2312. spaceAbove,
  2313. "spaceBelow:",
  2314. spaceBelow,
  2315. "estimatedHeight:",
  2316. estimatedPopupHeight
  2317. );
  2318. // 5. 判断方向和最大高度 by xu 20251212
  2319. if (spaceBelow >= estimatedPopupHeight) {
  2320. // 下方空间足够,向下展开,不限制高度
  2321. popupDirection.value = "bottom";
  2322. popupMaxHeight.value = "none";
  2323. console.log("[popup] 向下展开,空间充足");
  2324. } else if (spaceAbove >= estimatedPopupHeight) {
  2325. // 上方空间足够,向上展开,不限制高度
  2326. popupDirection.value = "top";
  2327. popupMaxHeight.value = "none";
  2328. console.log("[popup] 向上展开,空间充足");
  2329. } else {
  2330. // 上下空间都不足,选择空间大的方向,并限制高度出滚动条
  2331. if (spaceBelow >= spaceAbove) {
  2332. popupDirection.value = "bottom";
  2333. popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px";
  2334. console.log(
  2335. "[popup] 向下展开,空间不足,限制高度:",
  2336. popupMaxHeight.value
  2337. );
  2338. } else {
  2339. popupDirection.value = "top";
  2340. popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px";
  2341. console.log(
  2342. "[popup] 向上展开,空间不足,限制高度:",
  2343. popupMaxHeight.value
  2344. );
  2345. }
  2346. }
  2347. };
  2348. const updatePopupPosition = () => {
  2349. const triggerEl =
  2350. selectContainerRef.value?.querySelector(".input") ||
  2351. selectContainerRef.value;
  2352. if (!triggerEl) return;
  2353. const triggerRect = triggerEl.getBoundingClientRect();
  2354. const margin = 10;
  2355. const viewportWidth = window.innerWidth;
  2356. const viewportHeight = window.innerHeight;
  2357. const popupGap = 0;
  2358. popupLayerStyle.value = {
  2359. position: "fixed",
  2360. left: `${Math.max(margin, triggerRect.left)}px`,
  2361. top: `${Math.max(margin, triggerRect.bottom + popupGap)}px`,
  2362. bottom: "auto",
  2363. minWidth: `${Math.max(0, triggerRect.width)}px`,
  2364. zIndex: 9999,
  2365. pointerEvents: "auto",
  2366. };
  2367. Vue.nextTick(() => {
  2368. const popupEl = popupRef.value;
  2369. if (!popupEl) return;
  2370. const popupRect = popupEl.getBoundingClientRect();
  2371. const maxLeft = viewportWidth - popupRect.width - margin;
  2372. const left = Math.min(
  2373. Math.max(margin, triggerRect.left),
  2374. Math.max(margin, maxLeft)
  2375. );
  2376. let top;
  2377. if (popupDirection.value === "top") {
  2378. top = triggerRect.top - popupRect.height - popupGap;
  2379. top = Math.max(margin, top);
  2380. } else {
  2381. top = triggerRect.bottom + popupGap;
  2382. if (top + popupRect.height > viewportHeight - margin) {
  2383. top = Math.max(
  2384. margin,
  2385. viewportHeight - popupRect.height - margin
  2386. );
  2387. }
  2388. }
  2389. popupLayerStyle.value = {
  2390. ...popupLayerStyle.value,
  2391. left: `${left}px`,
  2392. top: `${top}px`,
  2393. bottom: "auto",
  2394. };
  2395. });
  2396. };
  2397. const openPopup = () => {
  2398. if (!popupWinVisible.value) popupWinVisible.value = true;
  2399. Vue.nextTick(() => {
  2400. calculatePopupDirection();
  2401. updatePopupPosition();
  2402. });
  2403. };
  2404. const handleViewportChange = () => {
  2405. if (!popupWinVisible.value) return;
  2406. calculatePopupDirection();
  2407. updatePopupPosition();
  2408. };
  2409. const onDocPointerDown = (event) => {
  2410. if (!popupWinVisible.value) return;
  2411. const target = event.target;
  2412. if (selectContainerRef.value?.contains(target)) return;
  2413. if (popupRef.value?.contains(target)) return;
  2414. hidePopup();
  2415. };
  2416. let hidePopupTimer = null;
  2417. let keepPopupTimer = null;
  2418. const leaveInput = () => {
  2419. clearTimeout(hidePopupTimer);
  2420. hidePopupTimer = setTimeout(() => {
  2421. popupWinVisible.value = false;
  2422. }, 200);
  2423. };
  2424. const enterInput = () => {
  2425. clearTimeout(hidePopupTimer);
  2426. if (popupWinVisible.value) {
  2427. clearTimeout(keepPopupTimer);
  2428. }
  2429. };
  2430. const enterPopup = () => {
  2431. clearTimeout(hidePopupTimer);
  2432. popupWinVisible.value = true;
  2433. };
  2434. const leavePopup = () => {
  2435. clearTimeout(keepPopupTimer);
  2436. keepPopupTimer = setTimeout(() => {
  2437. popupWinVisible.value = false;
  2438. }, 200);
  2439. };
  2440. //级联菜单点击事件
  2441. const togglePopup = () => {
  2442. if (canInput) {
  2443. updateOptionBYInputText(inputText.value);
  2444. return;
  2445. }
  2446. if (!popupWinVisible.value) {
  2447. //如果当前下拉菜单是隐藏的,先ajax重新加载下拉菜单项,再显示。
  2448. showPopup();
  2449. } else {
  2450. hidePopup();
  2451. }
  2452. };
  2453. //显示下拉菜单,在此之前先清除下拉菜单项
  2454. const showPopup = () => {
  2455. //清空下拉菜单,并设置第一项的值为空
  2456. if (canInput) filteredOptions.value = props.opt;
  2457. clearAndInit1stOpt();
  2458. Vue.nextTick(() => {
  2459. calculatePopupDirection();
  2460. });
  2461. let url = props.url;
  2462. let filterObj = props.param.filter;
  2463. if (filterObj) {
  2464. for (let k in filterObj) {
  2465. let v = filterObj[k];
  2466. url += "&" + k + "=" + v;
  2467. }
  2468. }
  2469. if (props.mode === "1") {
  2470. //如果是有隐藏字段的下拉菜单
  2471. console.log("666url:" + url);
  2472. // alert('url:'+url);
  2473. // 获取级联菜单所有下拉菜单项
  2474. async function getSelectItems(value) {
  2475. try {
  2476. // alert(1);
  2477. if (props.url && props.param) {
  2478. // alert(2);
  2479. /**
  2480. * param={"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  2481. * "\"name\":\"hksheng\",\"cascadingName\":\"dq\"," +
  2482. * "\"cascadingInputsName\":\"hkdqm\",\"codebook\":\"sheng\"}",
  2483. * "objectpickertype":1,//2表示获取要回显的一项,1表示获取所有下拉菜单项
  2484. * "upperValue":"440000"
  2485. * };
  2486. */
  2487. const objectPickerParam = {
  2488. input: "false",
  2489. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2490. name: props.name, //本下拉菜单名
  2491. cascadingName: props.param.name, //级联菜单名
  2492. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  2493. codebook: props.param.codebook,
  2494. };
  2495. console.log("mode1 upperValue.value:" + upperValue.value);
  2496. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2497. const params = new URLSearchParams();
  2498. params.append("objectpickerparam", objectPickerParamStr);
  2499. params.append("objectpickertype", "1");
  2500. if (upperValue.value) {
  2501. params.append("upperValue", upperValue.value);
  2502. }
  2503. // params.append('objectpickervalue', value); //需回显的值
  2504. axios
  2505. .post(url, params, {
  2506. headers: {
  2507. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2508. },
  2509. })
  2510. .then((response) => {
  2511. if ("timeout" == response.data.statusText) {
  2512. alert("网络超时!");
  2513. return;
  2514. }
  2515. if (response.data.result) {
  2516. const normalizedResult = normalizeCcpResult(
  2517. response.data.result
  2518. );
  2519. console.log(
  2520. "params:" +
  2521. params +
  2522. "@@response.data:" +
  2523. JSON.stringify(response.data)
  2524. );
  2525. if (normalizedResult.length > 0) {
  2526. normalizedResult.forEach((option) => {
  2527. props.opt.push(option);
  2528. });
  2529. console.log("props.opt11:" + JSON.stringify(props.opt));
  2530. } else {
  2531. // 没有数据时打印日志 by xu 20251212
  2532. console.log("[ccp mode1] 接口返回空数据");
  2533. }
  2534. } else {
  2535. // result不存在时打印日志 by xu 20251212
  2536. console.log("[ccp mode1] 接口返回无result");
  2537. }
  2538. // 无论是否有数据,都显示popup by xu 20251212
  2539. openPopup();
  2540. });
  2541. }
  2542. } catch (error) {
  2543. alert(error);
  2544. // callback(null, error.message); // 失败回调,传递错误
  2545. }
  2546. }
  2547. getSelectItems(props.modelValue);
  2548. } else if (props.mode === "2") {
  2549. //没隐藏字段的下拉菜单
  2550. let needInitParam = undefined;
  2551. if (Array.isArray(props.param)) {
  2552. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  2553. console.log(
  2554. "needInitParam最后一项:" + JSON.stringify(needInitParam)
  2555. );
  2556. } else {
  2557. needInitParam = props.param;
  2558. }
  2559. // 获取级联菜单所有下拉菜单项
  2560. async function getSelectItems(value, sendParam) {
  2561. try {
  2562. // alert(1);
  2563. if (props.url && sendParam) {
  2564. // alert(2);
  2565. /**
  2566. * param="{\"input\":\"false\",\"cascadingLevel\":\"dwid,sjryid\",
  2567. * \"ryid\":\"111121\",\"name\":\"sjryid\",
  2568. * \"cascadingName\":\"dw_sjry\",\"codebook\":\"sjryByDw\"}"
  2569. */
  2570. const objectPickerParam = {
  2571. input: "false",
  2572. cascadingLevel: sendParam.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2573. name: props.name, //本下拉菜单名
  2574. cascadingName: sendParam.name, //级联菜单名
  2575. codebook: sendParam.codebook,
  2576. };
  2577. console.log("mode2 upperValue.value:" + upperValue.value);
  2578. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2579. const params = new URLSearchParams();
  2580. params.append("objectpickerparam", objectPickerParamStr);
  2581. params.append("objectpickertype", "1");
  2582. if (upperValue.value) {
  2583. params.append("upperValue", upperValue.value);
  2584. }
  2585. // params.append('objectpickervalue', value); //需回显的值
  2586. axios
  2587. .post(url, params, {
  2588. headers: {
  2589. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2590. },
  2591. })
  2592. .then((response) => {
  2593. if ("timeout" == response.data.statusText) {
  2594. alert("网络超时!");
  2595. return;
  2596. }
  2597. if (response.data.result) {
  2598. const normalizedResult = normalizeCcpResult(
  2599. response.data.result
  2600. );
  2601. console.log(
  2602. "params:" +
  2603. params +
  2604. "@@response.data:" +
  2605. JSON.stringify(response.data)
  2606. );
  2607. if (normalizedResult.length > 0) {
  2608. normalizedResult.forEach((option) => {
  2609. props.opt.push(option);
  2610. });
  2611. console.log("props.opt11:" + JSON.stringify(props.opt));
  2612. } else {
  2613. // 没有数据时打印日志 by xu 20251212
  2614. console.log("[ccp mode2] 接口返回空数据");
  2615. }
  2616. } else {
  2617. // result不存在时打印日志 by xu 20251212
  2618. console.log("[ccp mode2] 接口返回无result");
  2619. }
  2620. // 无论是否有数据,都显示popup by xu 20251212
  2621. openPopup();
  2622. });
  2623. }
  2624. } catch (error) {
  2625. alert(error);
  2626. // callback(null, error.message); // 失败回调,传递错误
  2627. }
  2628. }
  2629. getSelectItems(props.modelValue, needInitParam);
  2630. // popupWinVisible.value = !popupWinVisible.value;
  2631. }
  2632. };
  2633. const hidePopup = () => {
  2634. popupWinVisible.value = false;
  2635. };
  2636. const suffixClick = () => {
  2637. if (popupWinVisible.value) {
  2638. hidePopup();
  2639. return;
  2640. }
  2641. if (canInput) {
  2642. updateOptionBYInputText("");
  2643. } else {
  2644. showPopup();
  2645. }
  2646. };
  2647. const handleInputChange = (event) => {
  2648. inputText.value = event.target.value || "";
  2649. updateOptionBYInputText(inputText.value);
  2650. };
  2651. // 合并所有的 onMounted 逻辑
  2652. Vue.onMounted(() => {
  2653. window.addEventListener("resize", handleViewportChange);
  2654. window.addEventListener("scroll", handleViewportChange, true);
  2655. document.addEventListener("pointerdown", onDocPointerDown);
  2656. // 1. 监听展开下一级事件
  2657. window.addEventListener("open-next-cascader", (event) => {
  2658. const { name, level } = event.detail;
  2659. if (name === props.name && level === props.level) {
  2660. popupWinVisible.value = true;
  2661. }
  2662. });
  2663. // 2. 监听级联事件
  2664. window.addEventListener("cascader-change", (event) => {
  2665. const { name, level, value } = event.detail;
  2666. if (name === props.name && level < props.level) {
  2667. selectItem.value = { label: "", value: "" };
  2668. emit("update:modelValue", "");
  2669. if (ssHidden) {
  2670. ssHidden.updateValue(value);
  2671. }
  2672. }
  2673. });
  2674. });
  2675. Vue.onUnmounted(() => {
  2676. window.removeEventListener("resize", handleViewportChange);
  2677. window.removeEventListener("scroll", handleViewportChange, true);
  2678. document.removeEventListener("pointerdown", onDocPointerDown);
  2679. clearTimeout(hidePopupTimer);
  2680. clearTimeout(keepPopupTimer);
  2681. });
  2682. // 监听值变化,处理回显 (mode 2)
  2683. Vue.watch(
  2684. () => props.modelValue,
  2685. (newVal) => {
  2686. if (props.mode === "2" && newVal) {
  2687. // 使用 watchEffect 替代嵌套的 watch
  2688. Vue.watchEffect(() => {
  2689. if (props.opt.length > 0) {
  2690. const matchedOption = props.opt.find(
  2691. (opt) => opt.value === newVal
  2692. );
  2693. if (matchedOption) {
  2694. selectItem.value = matchedOption;
  2695. inputText.value = matchedOption.label;
  2696. }
  2697. }
  2698. });
  2699. } else {
  2700. // 原有的值变化处理
  2701. const item = props.opt.find((it) => it.value === newVal);
  2702. if (item) {
  2703. selectItem.value = item;
  2704. inputText.value = item.label;
  2705. } else {
  2706. selectItem.value = { label: "", value: "" };
  2707. inputText.value = "";
  2708. }
  2709. }
  2710. },
  2711. { immediate: true }
  2712. );
  2713. // 监听选项变化,当数据加载完成时进行匹配
  2714. Vue.watch(
  2715. () => props.opt,
  2716. (newOptions) => {
  2717. if (newOptions.length > 0) {
  2718. const matchedOption = newOptions.find(
  2719. (opt) => opt.value === selectItem.value.value
  2720. );
  2721. if (matchedOption) {
  2722. selectItem.value = matchedOption;
  2723. emit("update:modelValue", matchedOption.value);
  2724. emit("change", matchedOption.value);
  2725. }
  2726. }
  2727. }
  2728. );
  2729. return {
  2730. selectItem,
  2731. popupWinVisible,
  2732. popupDirection,
  2733. popupMaxHeight, // 添加popup最大高度 by xu 20251212
  2734. togglePopup,
  2735. hidePopup,
  2736. doSelectItem,
  2737. leaveInput,
  2738. enterInput,
  2739. leavePopup,
  2740. enterPopup,
  2741. selectContainerRef,
  2742. popupRef,
  2743. teleportRootStyle,
  2744. popupLayerStyle,
  2745. canInput,
  2746. inputText,
  2747. visibleOptions,
  2748. suffixClick,
  2749. handleInputChange,
  2750. };
  2751. },
  2752. template: `
  2753. <div class="input ss-ccp-container" style="position: relative" :style="{width: width}">
  2754. <input type="hidden" :name="name" :value="modelValue">
  2755. <div class="select-container" ref="selectContainerRef" @mouseleave="leaveInput" @mouseenter="enterInput">
  2756. <div class="input" @click="togglePopup">
  2757. <input
  2758. type="hidden"
  2759. :name="name"
  2760. :value="selectItem.value"
  2761. />
  2762. <input
  2763. v-if="canInput"
  2764. v-model="inputText"
  2765. @input="handleInputChange"
  2766. :placeholder="placeholder"
  2767. />
  2768. <input
  2769. v-else
  2770. :placeholder="placeholder"
  2771. :value="selectItem.label"
  2772. disabled
  2773. style="pointer-events: none;"
  2774. />
  2775. <div class="suffix" @click.stop="suffixClick">
  2776. <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
  2777. </div>
  2778. </div>
  2779. </div>
  2780. <teleport to="body">
  2781. <div
  2782. v-show="popupWinVisible"
  2783. class="select-container ss-ccp-teleport-root"
  2784. :style="teleportRootStyle"
  2785. @mouseleave="leavePopup"
  2786. @mouseenter="enterPopup"
  2787. >
  2788. <div
  2789. ref="popupRef"
  2790. class="popup-win"
  2791. :style="[popupLayerStyle, { maxHeight: popupMaxHeight !== 'none' ? popupMaxHeight : 'none', overflowY: popupMaxHeight !== 'none' ? 'auto' : 'visible' }]"
  2792. >
  2793. <div v-if="visibleOptions && visibleOptions.length > 0" class="popup-content">
  2794. <div class="content-area">
  2795. <div
  2796. v-for="(item, index) in visibleOptions"
  2797. :key="index"
  2798. @click="doSelectItem(item)"
  2799. :class="{ active: item.value === selectItem.value }"
  2800. >
  2801. <span class="check-icon">
  2802. <ss-form-icon class="form-icon-select-checked" />
  2803. </span>
  2804. <span>{{ item.label }}</span>
  2805. </div>
  2806. </div>
  2807. </div>
  2808. <div v-else class="popup-content">
  2809. <div class="content-area">
  2810. <div class="content-area">
  2811. <span>无选项</span>
  2812. </div>
  2813. </div>
  2814. </div>
  2815. </div>
  2816. </div>
  2817. </teleport>
  2818. </div>
  2819. `,
  2820. };
  2821. // ss-date-picker 日期时间选择器组件
  2822. const SsDatePicker = {
  2823. name: "SsDatePicker",
  2824. props: {
  2825. modelValue: {
  2826. type: [String, Number, Date],
  2827. default: "",
  2828. },
  2829. name: {
  2830. type: String,
  2831. required: true,
  2832. },
  2833. type: {
  2834. type: String,
  2835. default: "date",
  2836. validator: (value) => ["date", "datetime", "time"].includes(value),
  2837. },
  2838. fmt: {
  2839. type: String,
  2840. default: null,
  2841. },
  2842. placeholder: {
  2843. type: String,
  2844. default: "",
  2845. },
  2846. width: {
  2847. type: String,
  2848. default: "100%",
  2849. },
  2850. },
  2851. emits: ["update:modelValue"],
  2852. setup(props, { emit }) {
  2853. const errMsg = ref("");
  2854. const validate = () => {
  2855. if (window.ssVm) {
  2856. const result = window.ssVm.validateField(props.name);
  2857. console.log("validate", window.ssVm.validateField(props.name));
  2858. errMsg.value = result.valid ? "" : result.message;
  2859. }
  2860. };
  2861. // 根据type确定默认格式
  2862. const defaultFormat = computed(() => {
  2863. switch (props.type) {
  2864. case "datetime":
  2865. return "YYYY-MM-DD HH:mm:ss";
  2866. case "date":
  2867. return "YYYY-MM-DD";
  2868. case "time":
  2869. return "HH:mm:ss";
  2870. }
  2871. });
  2872. const convertJavaFormatToElement = (javaFormat) => {
  2873. if (!javaFormat) return null;
  2874. return javaFormat
  2875. .replace("yyyy", "YYYY")
  2876. .replace("MM", "MM")
  2877. .replace("dd", "DD")
  2878. .replace("HH", "HH")
  2879. .replace("mm", "mm")
  2880. .replace("ss", "ss");
  2881. };
  2882. const finalFormat = computed(() => {
  2883. if (props.fmt) {
  2884. return convertJavaFormatToElement(props.fmt);
  2885. }
  2886. return defaultFormat.value;
  2887. });
  2888. // 使用 resolveComponent 获取组件
  2889. const ElDatePicker = resolveComponent("ElDatePicker");
  2890. const ElTimePicker = resolveComponent("ElTimePicker");
  2891. const SsFormIcon = resolveComponent("SsFormIcon");
  2892. const ElIcon = resolveComponent("ElIcon");
  2893. const handleValueUpdate = (val) => {
  2894. emit("update:modelValue", val);
  2895. emit("change", val); // 同时触发 change 事件
  2896. setTimeout(() => {
  2897. validate();
  2898. }, 50);
  2899. };
  2900. const dateType = computed(() => {
  2901. const fmt = props.fmt || "";
  2902. if (fmt.includes("HH:mm:ss")) {
  2903. return "datetime";
  2904. } else if (fmt.includes("HH:mm")) {
  2905. return "datetime";
  2906. } else if (fmt.includes("mm:ss")) {
  2907. return "time";
  2908. }
  2909. return "date";
  2910. });
  2911. let useTimePicker = true;
  2912. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  2913. if (props.fmt) {
  2914. //有fmt属性,则以fmt属性优先判断类型
  2915. if (/[dMy]/.test(props.fmt)) {
  2916. //如果有传入日期格式,且含年月日
  2917. useTimePicker = false;
  2918. } else {
  2919. useTimePicker = true;
  2920. }
  2921. } else if (props.type !== "time") {
  2922. useTimePicker = false;
  2923. }
  2924. return () =>
  2925. h("div", { class: "ss-date-picker", style: { width: props.width } }, [
  2926. h("input", {
  2927. type: "hidden",
  2928. name: props.name,
  2929. value: props.modelValue,
  2930. }),
  2931. // 选择组件
  2932. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  2933. modelValue: props.modelValue,
  2934. "onUpdate:modelValue": handleValueUpdate,
  2935. type: dateType.value,
  2936. format: finalFormat.value,
  2937. "value-format": finalFormat.value,
  2938. clearable: true,
  2939. placeholder: props.placeholder,
  2940. class: "custom-date-picker", // 用于自定义样式
  2941. "time-arrow-control": props.type === "datetime", // 修改这里
  2942. size: "large", // 添加这一行,改为 large 尺寸
  2943. style: { width: "100%" },
  2944. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  2945. }),
  2946. ]);
  2947. },
  2948. };
  2949. // ss-icon 图标
  2950. // v3.0 增加 class 属性分支:有 class 走新逻辑,否则走 v1.0 逻辑 by xu 20251212
  2951. // v3.0 用法: <ss-icon class="icon-obj-ry menu-icon" />
  2952. // v1.0 用法: <ss-icon name="setting" size="20px" />
  2953. const SsIcon = {
  2954. name: "SsIcon",
  2955. // v3.0 禁用 class 透传,手动处理 by xu 20251215
  2956. inheritAttrs: false,
  2957. props: {
  2958. // v1.0: 以下为旧属性
  2959. name: { type: String },
  2960. size: { type: [Number, String], default: 16 },
  2961. unit: { type: String, default: "px" },
  2962. color: String,
  2963. type: {
  2964. type: String,
  2965. default: ssIcon.name,
  2966. validator: function (value) {
  2967. return [ssIcon, commonIcon].some((icon) => icon.name === value);
  2968. },
  2969. },
  2970. },
  2971. emits: ["update:modelValue", "input", "blur", "change"],
  2972. setup(props, { emit, attrs }) {
  2973. // v3.0 分支:有 class 属性时直接渲染(从 attrs 获取) by xu 20251215
  2974. if (attrs.class) {
  2975. return () =>
  2976. h("i", { ...attrs, class: attrs.class + " icon-container" });
  2977. }
  2978. // v1.0 分支:原有逻辑
  2979. const useIconType = computed(() => {
  2980. return [ssIcon, commonIcon].find(
  2981. (iconConfig) => iconConfig.name === props.type
  2982. );
  2983. });
  2984. const iconName = computed(() => {
  2985. const iconConfig = useIconType.value; // 注意:使用 .value 来访问响应式引用的值
  2986. if (!iconConfig) {
  2987. console.error(`Icon type "${props.type}" not found.`);
  2988. return "";
  2989. }
  2990. const iconType = iconConfig.types[props.name];
  2991. if (!iconType) {
  2992. console.error(
  2993. `Icon name "${props.name}" not found in type "${props.type}".`
  2994. );
  2995. return "";
  2996. }
  2997. return `${iconConfig.prefix}${iconType}`;
  2998. });
  2999. // 类似地,你可以计算 fontFamily 和 style
  3000. const fontFamily = computed(() => {
  3001. return useIconType.value ? useIconType.value.family : "";
  3002. });
  3003. // console.log(iconName.value,fontFamily.value)
  3004. const style = computed(() => {
  3005. const sizeStyle = isNum(props.size)
  3006. ? `${props.size}${props.unit}`
  3007. : props.size;
  3008. const styleObj = {
  3009. fontSize: sizeStyle,
  3010. color: props.color || "",
  3011. };
  3012. return toStyleStr(styleObj);
  3013. });
  3014. // 使用渲染函数定义模板逻辑
  3015. return () =>
  3016. h("i", {
  3017. class: ["icon-container", iconName.value, fontFamily.value],
  3018. style: style.value,
  3019. });
  3020. },
  3021. };
  3022. // 通用icon
  3023. const SsCommonIcon = {
  3024. name: "SsCommonIcon",
  3025. props: {
  3026. class: {
  3027. type: String,
  3028. required: true,
  3029. },
  3030. },
  3031. setup(props) {
  3032. return () =>
  3033. h("i", {
  3034. class: props.class + " common-icon",
  3035. });
  3036. },
  3037. };
  3038. // 登录页icon
  3039. const SsLoginIcon = {
  3040. name: "SsLoginIcon",
  3041. props: {
  3042. class: {
  3043. type: String,
  3044. required: true,
  3045. },
  3046. },
  3047. setup(props) {
  3048. return () =>
  3049. h("div", {
  3050. class: props.class + " login-icon",
  3051. });
  3052. },
  3053. };
  3054. // 弹窗icon
  3055. const SsDialogIcon = {
  3056. name: "SsDialogIcon",
  3057. props: {
  3058. class: {
  3059. type: String,
  3060. required: true,
  3061. },
  3062. },
  3063. setup(props) {
  3064. return () =>
  3065. h("i", {
  3066. class: props.class + " dialog-icon",
  3067. });
  3068. },
  3069. };
  3070. // 全局左侧导航图标组件
  3071. const SsNavIcon = {
  3072. name: "SsNavIcon",
  3073. props: {
  3074. class: {
  3075. type: String,
  3076. required: true,
  3077. },
  3078. },
  3079. setup(props) {
  3080. return () =>
  3081. h("div", {
  3082. class: props.class + " nav-icon",
  3083. });
  3084. },
  3085. };
  3086. // 顶部工具栏图标组件
  3087. const SsHeaderIcon = {
  3088. name: "SsHeaderIcon",
  3089. props: {
  3090. class: {
  3091. type: String,
  3092. required: true,
  3093. },
  3094. },
  3095. setup(props) {
  3096. return () =>
  3097. h("div", {
  3098. class: props.class + " header-icon",
  3099. });
  3100. },
  3101. };
  3102. // 全局菜单图标组件
  3103. const SsGolbalMenuIcon = {
  3104. name: "SsGolbalMenuIcon",
  3105. props: {
  3106. class: {
  3107. type: String,
  3108. required: true,
  3109. },
  3110. },
  3111. setup(props) {
  3112. return () =>
  3113. h("div", {
  3114. class: props.class + " global-menu-icon",
  3115. });
  3116. },
  3117. };
  3118. // 全局查询列表卡片图标
  3119. const SsCartListIcon = {
  3120. name: "SsCartListIcon",
  3121. props: {
  3122. class: {
  3123. type: String,
  3124. required: true,
  3125. },
  3126. },
  3127. setup(props) {
  3128. return () =>
  3129. h("div", {
  3130. class: props.class + " cart-list-icon",
  3131. });
  3132. },
  3133. };
  3134. // 全局底部工具栏图标组件
  3135. const SsQuickIcon = {
  3136. name: "SsQuickIcon",
  3137. props: {
  3138. class: {
  3139. type: String,
  3140. required: true,
  3141. },
  3142. },
  3143. setup(props) {
  3144. return () =>
  3145. h("div", {
  3146. class: props.class + " quick-icon",
  3147. });
  3148. },
  3149. };
  3150. // 表单组件icon
  3151. const SsFormIcon = {
  3152. name: "SsFormIcon",
  3153. props: {
  3154. class: {
  3155. type: String,
  3156. required: true,
  3157. },
  3158. },
  3159. setup(props) {
  3160. return () =>
  3161. h("div", {
  3162. class: props.class + " form-icon",
  3163. });
  3164. },
  3165. };
  3166. // 弹窗底部按钮icon
  3167. const SsBottomDivIcon = {
  3168. name: "SsBottomDivIcon",
  3169. props: {
  3170. class: {
  3171. type: String,
  3172. required: true,
  3173. },
  3174. },
  3175. setup(props) {
  3176. return () =>
  3177. h("div", {
  3178. class: props.class + " bottom-div-icon",
  3179. });
  3180. },
  3181. };
  3182. // editor组件icon
  3183. const SsEditorIcon = {
  3184. name: "SsEditorIcon",
  3185. props: {
  3186. class: {
  3187. type: String,
  3188. required: true,
  3189. },
  3190. },
  3191. setup(props) {
  3192. return () =>
  3193. h("i", {
  3194. class: props.class + " editor-icon",
  3195. });
  3196. },
  3197. };
  3198. // ss-validate校验器
  3199. const SsValidate = {
  3200. name: "SsValidate",
  3201. props: {
  3202. errMsg: { type: String },
  3203. textAlign: { type: String, default: "left" },
  3204. style: { type: Object, default: () => ({}) },
  3205. },
  3206. template: `<div class="validate-vline"></div>
  3207. <div class="validate-tip" :style="style">
  3208. <div class="tip" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  3209. <div class="tip-more" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  3210. </div>`,
  3211. };
  3212. // ss-onoff-array 多选按钮 数组形式
  3213. const SsonoffArray = {
  3214. name: "SsonoffArray",
  3215. props: {
  3216. name: {
  3217. type: String,
  3218. required: true,
  3219. },
  3220. opt: {
  3221. type: Array,
  3222. default: () => [],
  3223. },
  3224. defaultValue: [String, Number, Array],
  3225. modelValue: [String, Number, Array],
  3226. multiple: {
  3227. // 新增多选模式属性
  3228. type: Boolean,
  3229. default: false,
  3230. },
  3231. // 是否允许一项都不选,默认true允许 by xu 20251212
  3232. null: {
  3233. type: Boolean,
  3234. default: true,
  3235. },
  3236. },
  3237. emits: ["update:modelValue"], // 允许更新 v-model 绑定的值
  3238. setup(props, { emit }) {
  3239. console.log("多选按钮", props.opt);
  3240. // 使用数组来存储选中值
  3241. const checkedValue = ref(
  3242. props.multiple
  3243. ? Array.isArray(props.defaultValue)
  3244. ? props.defaultValue
  3245. : []
  3246. : props.defaultValue
  3247. );
  3248. const errMsg = ref(props.errTip);
  3249. // 生成icon名字
  3250. const genIconName = (itemValue) => {
  3251. if (props.multiple) {
  3252. return checkedValue.value.includes(itemValue)
  3253. ? "form-icon-onoff-checked"
  3254. : "form-icon-onoff-unchecked";
  3255. }
  3256. return checkedValue.value === itemValue
  3257. ? "form-icon-onoff-checked"
  3258. : "form-icon-onoff-unchecked";
  3259. };
  3260. // 选中项
  3261. const selectItem = (value) => {
  3262. if (props.multiple) {
  3263. // 多选模式
  3264. const index = checkedValue.value.indexOf(value);
  3265. if (index === -1) {
  3266. checkedValue.value = [...checkedValue.value, value];
  3267. } else {
  3268. // 取消选中当前项
  3269. const newValue = checkedValue.value.filter((v) => v !== value);
  3270. // 如果不允许为空且取消后为空,则阻止取消操作 by xu 20251212
  3271. if (!props.null && newValue.length === 0) {
  3272. return; // 阻止取消最后一项
  3273. }
  3274. checkedValue.value = newValue;
  3275. }
  3276. } else {
  3277. // 单选模式
  3278. // 如果点击的是当前已选中的项,判断是否允许取消 by xu 20251212
  3279. if (checkedValue.value === value) {
  3280. if (!props.null) {
  3281. return; // 不允许为空时,阻止取消
  3282. }
  3283. checkedValue.value = ""; // 允许为空时,取消选中
  3284. } else {
  3285. checkedValue.value = value;
  3286. }
  3287. }
  3288. emit("update:modelValue", checkedValue.value);
  3289. nextTick(() => {
  3290. // 触发验证
  3291. if (window.ssVm) {
  3292. window.ssVm.validateField(props.name);
  3293. }
  3294. });
  3295. };
  3296. return { checkedValue, genIconName, selectItem };
  3297. },
  3298. // 使用渲染函数定义模板逻辑
  3299. render() {
  3300. const SsFormIcon = resolveComponent("ss-form-icon");
  3301. return h("div", { class: "radio-container" }, [
  3302. // 根据情况创建 input
  3303. this.multiple
  3304. ? this.checkedValue.length
  3305. ? // 多选且有选中值:为选中项创建 input
  3306. this.checkedValue.map((value) =>
  3307. h("input", {
  3308. type: "checkbox",
  3309. name: this.name,
  3310. value: value,
  3311. checked: true,
  3312. style: { display: "none" },
  3313. })
  3314. )
  3315. : // 多选但没有选中值:创建一个空值 input
  3316. h("input", {
  3317. type: "hidden",
  3318. name: this.name,
  3319. value: "",
  3320. })
  3321. : // 单选模式:创建一个 input
  3322. h("input", {
  3323. type: "hidden",
  3324. name: this.name,
  3325. value: this.checkedValue || "",
  3326. }),
  3327. this.opt.map((item, i) =>
  3328. h(
  3329. "div",
  3330. {
  3331. key: i,
  3332. class: {
  3333. checked: this.multiple
  3334. ? this.checkedValue.includes(item.value)
  3335. : this.checkedValue === item.value,
  3336. },
  3337. style: { width: item.width },
  3338. onClick: () => this.selectItem(item.value),
  3339. },
  3340. [
  3341. h("span", null, item.label),
  3342. h("div", { class: "mark" }, [
  3343. h(SsFormIcon, {
  3344. class: this.genIconName(item.value),
  3345. }),
  3346. ]),
  3347. ]
  3348. )
  3349. ),
  3350. ]);
  3351. },
  3352. };
  3353. // ss-onoff 一个按钮
  3354. const Ssonoff = {
  3355. name: "Ssonoff",
  3356. props: {
  3357. name: {
  3358. type: String,
  3359. required: true,
  3360. },
  3361. label: {
  3362. type: String,
  3363. required: true,
  3364. },
  3365. value: {
  3366. type: [String, Number],
  3367. required: true,
  3368. },
  3369. width: {
  3370. type: String,
  3371. default: "",
  3372. },
  3373. onchange: {
  3374. // 在此属性传入 onChange 的 window 全局回调函数,第一参数是当前整组值 by Ben/xu(20260320)
  3375. type: String,
  3376. required: false,
  3377. },
  3378. modelValue: [String, Number, Array],
  3379. multiple: {
  3380. type: Boolean,
  3381. default: false,
  3382. },
  3383. null: {
  3384. type: Boolean,
  3385. default: true,
  3386. },
  3387. },
  3388. emits: ["update:modelValue", "change"],
  3389. setup(props, { emit }) {
  3390. const parseModelValue = (val) => {
  3391. if (Array.isArray(val)) {
  3392. return val
  3393. .map((item) => (item == null ? "" : item.toString()))
  3394. .filter(Boolean);
  3395. }
  3396. if (val == null || val === "") return [];
  3397. // 如果以逗号开头,去掉开头的逗号
  3398. const cleanValue = val.toString().replace(/^,+/, "");
  3399. if (!cleanValue) return [];
  3400. if (cleanValue.includes("|")) {
  3401. return cleanValue.split("|").filter(Boolean);
  3402. }
  3403. if (cleanValue.includes(",")) {
  3404. return cleanValue.split(",").filter(Boolean);
  3405. }
  3406. return [cleanValue];
  3407. };
  3408. const callGlobalOnchg = (groupValue) => {
  3409. if (props.onchange && typeof props.onchange === "string") {
  3410. if (
  3411. typeof window !== "undefined" &&
  3412. window[props.onchange] &&
  3413. typeof window[props.onchange] === "function"
  3414. ) {
  3415. try {
  3416. window[props.onchange](groupValue, props.value, props.label);
  3417. } catch (error) {
  3418. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  3419. }
  3420. } else {
  3421. console.warn(`全局函数 ${props.onchange} 未定义或不是一个函数。`);
  3422. }
  3423. }
  3424. };
  3425. // 判断当前按钮是否选中
  3426. const isChecked = computed(() => {
  3427. if (props.multiple) {
  3428. const currentValue = parseModelValue(props.modelValue);
  3429. return currentValue.includes(props.value.toString());
  3430. }
  3431. return props.modelValue + "" === props.value + ""; //强转为字符串类型再比较(改之前是数字类型和字符串类型作比较,永远为false) Ben 20251206
  3432. });
  3433. // 功能说明:watch modelValue 变化,兼容桥接 API 赋值触发 onChange by xu 20260416
  3434. let isToggleTriggering = false; // 避免 toggleSelect 内部 emit 重复触发
  3435. Vue.watch(
  3436. () => props.modelValue,
  3437. (newVal) => {
  3438. if (isToggleTriggering) return;
  3439. callGlobalOnchg(newVal);
  3440. }
  3441. );
  3442. // 切换选中状态
  3443. const toggleSelect = () => {
  3444. let newModelValue;
  3445. if (props.multiple) {
  3446. const currentValue = parseModelValue(props.modelValue);
  3447. const currentButtonValue = props.value.toString();
  3448. const index = currentValue.indexOf(currentButtonValue);
  3449. let newValue;
  3450. if (index === -1) {
  3451. // 选中当前项
  3452. newValue = [...currentValue, currentButtonValue];
  3453. } else {
  3454. // 取消选中当前项
  3455. const filteredValue = currentValue.filter(
  3456. (value) => value !== currentButtonValue
  3457. );
  3458. // 如果不允许为空且取消后为空,则阻止取消操作
  3459. if (!props.null && filteredValue.length === 0) {
  3460. return; // 阻止取消最后一项
  3461. }
  3462. newValue = filteredValue;
  3463. }
  3464. newModelValue = newValue.join(",");
  3465. } else {
  3466. // 单选模式
  3467. const currentValue = parseModelValue(props.modelValue);
  3468. const isCurrentlySelected = currentValue.includes(
  3469. props.value.toString()
  3470. );
  3471. if (!isCurrentlySelected) {
  3472. // 选中当前项
  3473. newModelValue = props.value;
  3474. } else {
  3475. // 取消选中当前项
  3476. // 如果不允许为空且当前只有这一项被选中,则阻止取消操作
  3477. if (!props.null && currentValue.length === 1) {
  3478. return; // 阻止取消唯一选中项
  3479. }
  3480. newModelValue = "";
  3481. }
  3482. }
  3483. isToggleTriggering = true; // emit 前设置,避免 watch 重复触发 onChange by xu 20260416
  3484. emit("update:modelValue", newModelValue);
  3485. emit("change", newModelValue, props.value, props.label);
  3486. nextTick(() => {
  3487. isToggleTriggering = false; // 重置标志,允许后续桥接 API 赋值触发 onChange by xu 20260416
  3488. // 触发验证
  3489. if (window.ssVm) {
  3490. window.ssVm.validateField(props.name);
  3491. }
  3492. });
  3493. };
  3494. return { isChecked, toggleSelect };
  3495. },
  3496. render() {
  3497. const SsFormIcon = resolveComponent("ss-form-icon");
  3498. return h("div", { class: "radio-container2" }, [
  3499. // 隐藏的表单元素
  3500. this.multiple
  3501. ? h("input", {
  3502. type: "hidden",
  3503. name: `${this.name}`, // 多选模式下使用数组形式的 name
  3504. value: this.isChecked ? this.value : "",
  3505. })
  3506. : this.isChecked &&
  3507. h("input", {
  3508. // 只有当前按钮被选中时才创建 input
  3509. type: "hidden",
  3510. name: this.name,
  3511. value: this.value,
  3512. }),
  3513. // 按钮显示
  3514. h(
  3515. "div",
  3516. {
  3517. class: { checked: this.isChecked },
  3518. style: { width: this.width },
  3519. onClick: this.toggleSelect,
  3520. },
  3521. [
  3522. h("span", null, this.label),
  3523. h("div", { class: "mark" }, [
  3524. h(SsFormIcon, {
  3525. class: this.isChecked
  3526. ? "form-icon-onoff-checked"
  3527. : "form-icon-onoff-unchecked",
  3528. }),
  3529. ]),
  3530. ]
  3531. ),
  3532. ]);
  3533. },
  3534. };
  3535. // ss-textarea
  3536. // ss-textarea
  3537. const SsTextarea = {
  3538. name: "SsTextarea",
  3539. props: {
  3540. name: {
  3541. type: String,
  3542. required: true,
  3543. },
  3544. placeholder: {
  3545. type: String,
  3546. default: "请输入",
  3547. },
  3548. defaultValue: [String, Number],
  3549. modelValue: [String, Number],
  3550. // 功能说明:onChange 全局回调 prop,桥接 API 赋值时自动触发 by xu 20260416
  3551. onchange: {
  3552. type: String,
  3553. required: false,
  3554. },
  3555. },
  3556. emits: ["update:modelValue"],
  3557. setup(props, { emit }) {
  3558. const inputValue = ref(props.modelValue || props.defaultValue || "");
  3559. // 功能说明:调用全局 onChange 回调 by xu 20260416
  3560. const callGlobalOnchg = (value) => {
  3561. if (props.onchange && typeof props.onchange === "string") {
  3562. if (
  3563. typeof window !== "undefined" &&
  3564. window[props.onchange] &&
  3565. typeof window[props.onchange] === "function"
  3566. ) {
  3567. try {
  3568. window[props.onchange](value);
  3569. } catch (error) {
  3570. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  3571. }
  3572. }
  3573. }
  3574. };
  3575. // 监听 modelValue 变化
  3576. watch(
  3577. () => props.modelValue,
  3578. (newVal) => {
  3579. inputValue.value = newVal;
  3580. callGlobalOnchg(newVal);
  3581. }
  3582. );
  3583. // 输入事件处理
  3584. const onInput = (event) => {
  3585. const newValue = event.target.value;
  3586. inputValue.value = newValue;
  3587. emit("update:modelValue", newValue);
  3588. // 触发验证
  3589. if (window.ssVm) {
  3590. window.ssVm.validateField(props.name);
  3591. }
  3592. };
  3593. // 失焦时验证
  3594. const onBlur = () => {
  3595. if (window.ssVm) {
  3596. window.ssVm.validateField(props.name);
  3597. }
  3598. };
  3599. return { inputValue, onInput, onBlur };
  3600. },
  3601. render() {
  3602. return h("div", { class: "textarea-container" }, [
  3603. h("div", { class: "textarea" }, [
  3604. h("input", {
  3605. type: "hidden",
  3606. name: this.name,
  3607. value: this.inputValue || "",
  3608. }),
  3609. h("textarea", {
  3610. placeholder: this.placeholder,
  3611. value: this.inputValue,
  3612. onInput: this.onInput,
  3613. onBlur: this.onBlur,
  3614. }),
  3615. ]),
  3616. ]);
  3617. },
  3618. };
  3619. // ss-editor 富文本编辑器 基于Jodit
  3620. const SsEditor = {
  3621. name: "SsEditor",
  3622. props: {
  3623. modelValue: {
  3624. type: String,
  3625. default: "",
  3626. },
  3627. html: {
  3628. type: String,
  3629. default: "",
  3630. },
  3631. htmlname: {
  3632. type: String,
  3633. default: "",
  3634. },
  3635. storename: {
  3636. type: String,
  3637. default: "",
  3638. },
  3639. name: {
  3640. type: String,
  3641. default: "",
  3642. },
  3643. url: {
  3644. type: String,
  3645. default: "",
  3646. },
  3647. height: {
  3648. type: [Number, String],
  3649. default: 400,
  3650. },
  3651. placeholder: {
  3652. type: String,
  3653. default: "请输入内容",
  3654. },
  3655. mode: {
  3656. type: String,
  3657. default: "edit", // 'edit' | 'play'
  3658. },
  3659. uploadUrl: {
  3660. type: String,
  3661. default: "/ulByHttp", //原值为“upload” Ben(20251205)
  3662. },
  3663. param: {
  3664. type: Object,
  3665. default: () => ({}),
  3666. },
  3667. },
  3668. emits: ["update:modelValue", "ready", "change"],
  3669. setup(props, { emit }) {
  3670. const editorRef = ref(null);
  3671. const editorContent = ref("");
  3672. const currentModelValue = ref(props.modelValue || "");
  3673. const uniqueId = "editor-" + Date.now();
  3674. const errMsg = Vue.ref("");
  3675. // button 支持对象(旧格式,单个附件按钮)或数组(新格式,多个按钮)by xu 20250331
  3676. const buttonConfigRaw = props.param && props.param.button ? props.param.button : null;
  3677. const buttonArray = Array.isArray(buttonConfigRaw)
  3678. ? buttonConfigRaw
  3679. : buttonConfigRaw
  3680. ? [buttonConfigRaw]
  3681. : [];
  3682. // 找到附件按钮配置(有 cmsAddUrl 的)
  3683. const fjButton = buttonArray.find(btn => btn && btn.cmsAddUrl && btn.cmsUpdUrl) || {};
  3684. const fjid = ref(fjButton.val || null);
  3685. const attachmentFieldName = fjButton.name || "fjid";
  3686. const attachmentLabel = fjButton.desc || fjButton.text || "附件";
  3687. const resolveStoreFieldName = () => {
  3688. if (props.storename) {
  3689. return props.storename;
  3690. }
  3691. if (!props.name) {
  3692. return "";
  3693. }
  3694. return /wj$/i.test(props.name) ? props.name : props.name + "wj";
  3695. };
  3696. const resolveHtmlFieldName = () => {
  3697. if (props.htmlname) {
  3698. return props.htmlname;
  3699. }
  3700. const storeFieldName = resolveStoreFieldName();
  3701. if (storeFieldName && /wj$/i.test(storeFieldName)) {
  3702. return storeFieldName.replace(/wj$/i, "") + "Edit";
  3703. }
  3704. if (!props.name) {
  3705. return "";
  3706. }
  3707. return props.name.replace(/wj$/i, "") + "Edit";
  3708. };
  3709. const resolvePageSearchParam = (key) => {
  3710. try {
  3711. return new URL(window.location.href).searchParams.get(key) || "";
  3712. } catch (error) {
  3713. return "";
  3714. }
  3715. };
  3716. const resolveAttachmentObjName = () =>
  3717. props.param?.obj ||
  3718. props.param?.ssObjName ||
  3719. document.querySelector("[name='ssObjName']")?.value ||
  3720. window?.ss?.dom?.ssObjName ||
  3721. resolvePageSearchParam("ssObjName") ||
  3722. "";
  3723. const resolveAttachmentObjId = () =>
  3724. props.param?.ssObjId ||
  3725. props.param?.objId ||
  3726. document.querySelector("[name='ssObjId']")?.value ||
  3727. resolvePageSearchParam("ssObjId") ||
  3728. "";
  3729. const buildAttachmentCreatePayload = () => ({
  3730. name: attachmentFieldName,
  3731. ssNrObjName: resolveAttachmentObjName(),
  3732. ssNrObjId: resolveAttachmentObjId(),
  3733. });
  3734. const buildAttachmentDialogQuery = () =>
  3735. "&nrid=T-" +
  3736. fjid.value +
  3737. "&objectId=" +
  3738. fjid.value +
  3739. "&objectName=" +
  3740. attachmentFieldName +
  3741. "&callback=" +
  3742. (window[attachmentFieldName + "CallbackName"] || "");
  3743. const ensureAttachmentId = () => {
  3744. if (fjid.value != null && fjid.value !== "") {
  3745. return true;
  3746. }
  3747. if (!fjButton.cmsAddUrl) {
  3748. console.warn("ss-editor 未配置附件创建地址,无法初始化附件记录");
  3749. return false;
  3750. }
  3751. $.ajax({
  3752. type: "post",
  3753. url: fjButton.cmsAddUrl,
  3754. async: false,
  3755. data: buildAttachmentCreatePayload(),
  3756. success: function (_fjid) {
  3757. console.log("cmsAddUrl success", _fjid);
  3758. fjid.value = _fjid;
  3759. },
  3760. });
  3761. return fjid.value != null && fjid.value !== "";
  3762. };
  3763. const openAttachmentDialog = () => {
  3764. if (!fjButton.cmsUpdUrl) {
  3765. console.warn("ss-editor 未配置附件编辑地址,忽略附件操作");
  3766. return;
  3767. }
  3768. if (!ensureAttachmentId()) {
  3769. return;
  3770. }
  3771. const str = buildAttachmentDialogQuery();
  3772. console.log("str", str);
  3773. SS.openDialog({
  3774. src: fjButton.cmsUpdUrl + str,
  3775. headerTitle: "编辑",
  3776. width: 900,
  3777. high: 664,
  3778. zIndex: 51,
  3779. });
  3780. };
  3781. // 筛选出自定义按钮(有 func 的)
  3782. const customButtonsFromParam = buttonArray.filter(btn => btn.func).map(btn => ({
  3783. name: btn.name,
  3784. text: btn.desc || btn.text,
  3785. tooltip: btn.desc || btn.tooltip,
  3786. icon: btn.icon || 'editor-icon-file',
  3787. onClick: btn.func // 函数名字符串
  3788. }));
  3789. const mode = props.param ? props.param.mode : null;
  3790. const normalizeHtml = (rawHtml) => {
  3791. if (rawHtml == null) {
  3792. return "";
  3793. }
  3794. const html = String(rawHtml).trim();
  3795. if (!html) {
  3796. return "";
  3797. }
  3798. if (
  3799. /<html[\s>]/i.test(html) ||
  3800. /<body[\s>]/i.test(html) ||
  3801. /<!doctype/i.test(html)
  3802. ) {
  3803. try {
  3804. const doc = new DOMParser().parseFromString(html, "text/html");
  3805. if (doc && doc.body) {
  3806. return doc.body.innerHTML || "";
  3807. }
  3808. } catch (e) {
  3809. console.warn("ss-editor 解析完整HTML失败,回退原始内容:", e);
  3810. }
  3811. }
  3812. return html;
  3813. };
  3814. const syncHiddenContentInput = (html) => {
  3815. const contentElements = document.getElementsByName(resolveHtmlFieldName());
  3816. if (contentElements.length > 0) {
  3817. contentElements[0].value = html;
  3818. }
  3819. };
  3820. const setEditorHtml = (html) => {
  3821. const normalizedHtml = normalizeHtml(html);
  3822. editorContent.value = normalizedHtml;
  3823. syncHiddenContentInput(normalizedHtml);
  3824. if (editorRef.value && editorRef.value.value !== normalizedHtml) {
  3825. editorRef.value.value = normalizedHtml;
  3826. }
  3827. };
  3828. const resolveWindowFunction = (handlerName) => {
  3829. if (!handlerName || typeof handlerName !== "string") {
  3830. return null;
  3831. }
  3832. return handlerName.split(".").reduce((current, key) => {
  3833. return current && current[key] != null ? current[key] : null;
  3834. }, window);
  3835. };
  3836. const getCustomButtonKey = (button, index) => {
  3837. const baseName =
  3838. (button &&
  3839. (button.key || button.name || button.text || button.tooltip)) ||
  3840. `button${index + 1}`;
  3841. return `ssCustomButton_${String(baseName).replace(
  3842. /[^a-zA-Z0-9_-]/g,
  3843. "_"
  3844. )}_${index}`;
  3845. };
  3846. const normalizeCustomButtons = (buttons = []) => {
  3847. return Array.isArray(buttons)
  3848. ? buttons.filter(Boolean).map((button, index) => ({
  3849. ...button,
  3850. _buttonKey: getCustomButtonKey(button, index),
  3851. }))
  3852. : [];
  3853. };
  3854. const renderButtonIcon = (icon) => {
  3855. if (!icon) {
  3856. return null;
  3857. }
  3858. if (typeof icon === "string" && icon.trim().startsWith("<")) {
  3859. return icon;
  3860. }
  3861. return `<span class="editor-icon ${icon}"></span>`;
  3862. };
  3863. const buildCustomButtonRegistry = (buttons = []) => {
  3864. const controls = {};
  3865. const buttonNames = [];
  3866. const iconMap = {};
  3867. normalizeCustomButtons(buttons).forEach((button) => {
  3868. const buttonKey = button._buttonKey;
  3869. const handler =
  3870. button.onClick ||
  3871. button.click ||
  3872. button.handler ||
  3873. button.exec ||
  3874. null;
  3875. const tooltip =
  3876. button.tooltip ||
  3877. button.text ||
  3878. button.label ||
  3879. button.name ||
  3880. "自定义按钮";
  3881. buttonNames.push(buttonKey);
  3882. if (button.icon) {
  3883. iconMap[buttonKey] = button.icon;
  3884. }
  3885. controls[buttonKey] = {
  3886. name: button.name || buttonKey,
  3887. tooltip,
  3888. exec: function (editor) {
  3889. const context = {
  3890. editor,
  3891. button,
  3892. props,
  3893. value:
  3894. editor && typeof editor.value !== "undefined"
  3895. ? editor.value
  3896. : "",
  3897. setValue: (value) => setEditorHtml(value),
  3898. getValue: () =>
  3899. editor && typeof editor.value !== "undefined"
  3900. ? editor.value
  3901. : "",
  3902. emit,
  3903. currentModelValue: currentModelValue.value,
  3904. fjid: fjid.value,
  3905. };
  3906. if (typeof handler === "function") {
  3907. return handler(context);
  3908. }
  3909. if (typeof handler === "string") {
  3910. const windowHandler = resolveWindowFunction(handler);
  3911. if (typeof windowHandler === "function") {
  3912. return windowHandler(context);
  3913. }
  3914. console.warn("ss-editor 自定义按钮未找到点击事件:", handler);
  3915. return undefined;
  3916. }
  3917. console.warn("ss-editor 自定义按钮缺少点击事件配置:", button);
  3918. return undefined;
  3919. },
  3920. };
  3921. });
  3922. return {
  3923. controls,
  3924. buttonNames,
  3925. iconMap,
  3926. };
  3927. };
  3928. const validate = () => {
  3929. if (window.ssVm) {
  3930. const result = window.ssVm.validateField(props.name);
  3931. console.log("validate", window.ssVm.validateField(props.name));
  3932. errMsg.value = result.valid ? "" : result.message;
  3933. }
  3934. };
  3935. onMounted(() => {
  3936. validate();
  3937. // 只读模式下不初始化 Jodit,直接设置内容 by xu 20250402
  3938. if (props.mode === "play") {
  3939. if (props.html) {
  3940. setEditorHtml(props.html);
  3941. } else if (props.url) {
  3942. const params = new URLSearchParams();
  3943. if (mode) params.append("mode", mode);
  3944. if (props.modelValue) params.append("path", props.modelValue);
  3945. axios
  3946. .post(props.url, params, {
  3947. headers: {
  3948. "Content-Type": "application/x-www-form-urlencoded",
  3949. },
  3950. })
  3951. .then((response) => {
  3952. if ("timeout" == response.data.statusText) {
  3953. alert("网络超时!");
  3954. return;
  3955. }
  3956. const content = response.data.content;
  3957. if (content != null) {
  3958. setEditorHtml(content);
  3959. }
  3960. const filePath = response.data.path;
  3961. if (filePath) {
  3962. currentModelValue.value = filePath;
  3963. emit("update:modelValue", filePath);
  3964. }
  3965. });
  3966. } else {
  3967. setEditorHtml(props.html);
  3968. }
  3969. return;
  3970. }
  3971. // 读取按钮配置 by xu 20250408(移除废弃的 props.customButtons)
  3972. let buttonsToUse = [];
  3973. // 1. 优先从 param.button 数组中筛选(新格式)by xu 20250331
  3974. if (customButtonsFromParam && customButtonsFromParam.length > 0) {
  3975. buttonsToUse = customButtonsFromParam;
  3976. }
  3977. // 2. 尝试从 param.customButtons 读取(旧格式,兼容)
  3978. if (!buttonsToUse || buttonsToUse.length === 0) {
  3979. if (props.param && props.param.customButtons && props.param.customButtons.length > 0) {
  3980. buttonsToUse = props.param.customButtons;
  3981. }
  3982. }
  3983. // 3. 尝试通过桥接 API 读取
  3984. if (!buttonsToUse || buttonsToUse.length === 0) {
  3985. const vm = window.SS.dom.getVueApp({ scope: "chain" });
  3986. if (vm && vm.zwwjCustomButtons) {
  3987. buttonsToUse = vm.zwwjCustomButtons;
  3988. }
  3989. }
  3990. // 4. 从 formElemConfig 读取(兜底)
  3991. if (!buttonsToUse || buttonsToUse.length === 0) {
  3992. const zwwjConfig = window.SS.dom.formElemConfig?.zwwj;
  3993. if (zwwjConfig?.customButtons) {
  3994. buttonsToUse = zwwjConfig.customButtons;
  3995. } else {
  3996. buttonsToUse = window.SS.dom.formElemConfig?.zwwjCustomButtons;
  3997. }
  3998. }
  3999. const {
  4000. controls: customButtonControls,
  4001. buttonNames: customButtonNames,
  4002. iconMap: customButtonIconMap,
  4003. } = buildCustomButtonRegistry(buttonsToUse);
  4004. console.log(
  4005. "[SsEditor] 解析后的按钮:",
  4006. customButtonNames,
  4007. customButtonControls
  4008. );
  4009. const appendCustomButtons = (buttons = []) => {
  4010. if (!customButtonNames.length) {
  4011. return buttons;
  4012. }
  4013. const toolbarButtons = [...buttons];
  4014. const insertIndex = toolbarButtons.includes("dots")
  4015. ? toolbarButtons.indexOf("dots")
  4016. : toolbarButtons.includes("print")
  4017. ? toolbarButtons.indexOf("print")
  4018. : -1;
  4019. if (insertIndex >= 0) {
  4020. toolbarButtons.splice(insertIndex, 0, ...customButtonNames);
  4021. return toolbarButtons;
  4022. }
  4023. return [...toolbarButtons, ...customButtonNames];
  4024. };
  4025. const editor = Jodit.make(`#${uniqueId}`, {
  4026. height: props.height,
  4027. placeholder: props.placeholder,
  4028. readonly: props.mode === "play",
  4029. language: "zh_cn",
  4030. i18n: {
  4031. zh_cn: {
  4032. Link: "链接",
  4033. URL: "链接",
  4034. "No follow": "无跟踪",
  4035. "Class name": "类名",
  4036. Image: "图片",
  4037. File: "文件",
  4038. "Line height": "行高",
  4039. Alternative: "描述",
  4040. "Alternative text": "描述",
  4041. "Lower Alpha": "小写字母",
  4042. "Upper Alpha": "大写字母",
  4043. "Upper Roman": "大写罗马数字",
  4044. "Lower Roman": "小写罗马数字",
  4045. "Lower Greek": "小写希腊字母",
  4046. "Lower Letter": "小写字母",
  4047. "Upper Letter": "大写字母",
  4048. },
  4049. },
  4050. showXPathInStatusbar: false,
  4051. showCharsCounter: false,
  4052. showWordsCounter: false,
  4053. allowResizeY: false,
  4054. toolbarSticky: false,
  4055. statusbar: false,
  4056. uploader: {
  4057. url: props.uploadUrl,
  4058. format: "json",
  4059. method: "POST",
  4060. filesVariableName: function (i) {
  4061. return "imgs[" + i + "]";
  4062. },
  4063. headers: {
  4064. Accept: "application/json",
  4065. },
  4066. prepareData: function (formData) {
  4067. return formData;
  4068. },
  4069. isSuccess: function (resp) {
  4070. console.log("isSuccess resp:", resp);
  4071. return resp.code === 0;
  4072. },
  4073. getMessage: function (resp) {
  4074. console.log("getMessage resp:", resp);
  4075. return resp.msg || "上传失败";
  4076. },
  4077. process: function (resp) {
  4078. console.log("process resp:", resp);
  4079. return resp.data.url;
  4080. },
  4081. error: function (e) {
  4082. console.error("上传失败:", e.message);
  4083. },
  4084. defaultHandlerSuccess: function (resp) {
  4085. console.log("上传成功:", resp);
  4086. },
  4087. defaultHandlerError: function (err) {
  4088. console.error("上传错误:", err);
  4089. },
  4090. contentType: function () {
  4091. return false;
  4092. },
  4093. },
  4094. controls: {
  4095. font: {
  4096. list: {
  4097. Arial: "Arial",
  4098. SimSun: "宋体",
  4099. SimHei: "黑体",
  4100. "Microsoft YaHei": "微软雅黑",
  4101. KaiTi: "楷体",
  4102. FangSong: "仿宋",
  4103. "Times New Roman": "Times New Roman",
  4104. "Courier New": "Courier New",
  4105. },
  4106. },
  4107. customLinkButton: {
  4108. name: "link",
  4109. tooltip: attachmentLabel,
  4110. exec: function () {
  4111. openAttachmentDialog();
  4112. },
  4113. },
  4114. ...customButtonControls,
  4115. },
  4116. toolbarAdaptive: true,
  4117. // 调试:记录最终按钮配置
  4118. buttons: (() => {
  4119. const finalButtons = appendCustomButtons([
  4120. "fullsize",
  4121. "bold",
  4122. "italic",
  4123. "underline",
  4124. "strikethrough",
  4125. "eraser",
  4126. "|",
  4127. "font",
  4128. "fontsize",
  4129. "brush",
  4130. "paragraph",
  4131. "|",
  4132. "left",
  4133. "center",
  4134. "right",
  4135. "justify",
  4136. "|",
  4137. "ul",
  4138. "ol",
  4139. "indent",
  4140. "outdent",
  4141. "|",
  4142. "image",
  4143. "table",
  4144. "customLinkButton",
  4145. "print",
  4146. "|",
  4147. "undo",
  4148. "redo",
  4149. "find",
  4150. ]);
  4151. console.log("[SsEditor] 最终 buttons 配置:", finalButtons);
  4152. return finalButtons;
  4153. })(),
  4154. buttonsMD: appendCustomButtons([
  4155. "fullsize",
  4156. "bold",
  4157. "italic",
  4158. "underline",
  4159. "strikethrough",
  4160. "eraser",
  4161. "|",
  4162. "font",
  4163. "fontsize",
  4164. "brush",
  4165. "paragraph",
  4166. "|",
  4167. "font",
  4168. "fontsize",
  4169. "|",
  4170. "left",
  4171. "center",
  4172. "right",
  4173. "justify",
  4174. "|",
  4175. "image",
  4176. "customLinkButton",
  4177. "|",
  4178. "dots",
  4179. ]),
  4180. buttonsSM: appendCustomButtons([
  4181. "fullsize",
  4182. "bold",
  4183. "italic",
  4184. "|",
  4185. "image",
  4186. "|",
  4187. "dots",
  4188. ]),
  4189. buttonsXS: appendCustomButtons(["fullsize", "bold", "|", "dots"]),
  4190. sizeLG: 1024,
  4191. sizeMD: 768,
  4192. sizeSM: 576,
  4193. getIcon: function (name, clearName) {
  4194. const iconMap = {
  4195. bold: "editor-icon-bold",
  4196. italic: "editor-icon-italic",
  4197. underline: "editor-icon-underline",
  4198. strikethrough: "editor-icon-strikethrough",
  4199. eraser: "editor-icon-eraser",
  4200. copyformat: "editor-icon-copyformat",
  4201. font: "editor-icon-font",
  4202. fontsize: "editor-icon-fontsize",
  4203. brush: "editor-icon-brush",
  4204. paragraph: "editor-icon-paragraph",
  4205. left: "editor-icon-align-left",
  4206. center: "editor-icon-align-center",
  4207. right: "editor-icon-align-right",
  4208. justify: "editor-icon-align-justify",
  4209. ul: "editor-icon-ul",
  4210. ol: "editor-icon-ol",
  4211. indent: "editor-icon-indent",
  4212. outdent: "editor-icon-outdent",
  4213. image: "editor-icon-image",
  4214. file: "editor-icon-file",
  4215. video: "editor-icon-video",
  4216. table: "editor-icon-table",
  4217. link: "editor-icon-link",
  4218. source: "editor-icon-source",
  4219. eye: "editor-icon-preview",
  4220. fullsize: "editor-icon-fullsize",
  4221. shrink: "editor-icon-fullsize-exit",
  4222. print: "editor-icon-print",
  4223. undo: "editor-icon-undo",
  4224. redo: "editor-icon-redo",
  4225. search: "editor-icon-find",
  4226. selectall: "editor-icon-selectall",
  4227. };
  4228. const customIcon =
  4229. customButtonIconMap[clearName] || customButtonIconMap[name];
  4230. if (customIcon) {
  4231. return renderButtonIcon(customIcon);
  4232. }
  4233. const iconClass = iconMap[clearName] || iconMap[name];
  4234. if (iconClass) {
  4235. return renderButtonIcon(iconClass);
  4236. }
  4237. return null;
  4238. },
  4239. });
  4240. editorRef.value = editor;
  4241. editor.events.on("change", () => {
  4242. const html = editor.value || "";
  4243. editorContent.value = html;
  4244. syncHiddenContentInput(html);
  4245. emit("change", html);
  4246. setTimeout(() => {
  4247. validate();
  4248. }, 50);
  4249. });
  4250. emit("ready", editor);
  4251. if (props.html) {
  4252. setEditorHtml(props.html);
  4253. } else if (props.url) {
  4254. const params = new URLSearchParams();
  4255. if (mode) params.append("mode", mode);
  4256. if (props.modelValue) params.append("path", props.modelValue);
  4257. axios
  4258. .post(props.url, params, {
  4259. headers: {
  4260. "Content-Type": "application/x-www-form-urlencoded",
  4261. },
  4262. })
  4263. .then((response) => {
  4264. if ("timeout" == response.data.statusText) {
  4265. alert("网络超时!");
  4266. return;
  4267. }
  4268. const content = response.data.content;
  4269. if (content != null) {
  4270. setEditorHtml(content);
  4271. }
  4272. const filePath = response.data.path;
  4273. if (filePath) {
  4274. currentModelValue.value = filePath;
  4275. emit("update:modelValue", filePath);
  4276. }
  4277. });
  4278. } else {
  4279. setEditorHtml(props.html);
  4280. }
  4281. });
  4282. watch(
  4283. () => props.html,
  4284. (newValue) => {
  4285. setEditorHtml(newValue);
  4286. }
  4287. );
  4288. watch(
  4289. () => props.modelValue,
  4290. (newValue) => {
  4291. currentModelValue.value = newValue || "";
  4292. }
  4293. );
  4294. watch(
  4295. () => props.mode,
  4296. (newMode) => {
  4297. if (editorRef.value) {
  4298. editorRef.value.setReadOnly(newMode === "play");
  4299. }
  4300. }
  4301. );
  4302. onBeforeUnmount(() => {
  4303. if (editorRef.value) {
  4304. editorRef.value.destruct();
  4305. }
  4306. });
  4307. return () => {
  4308. const htmlFieldName = resolveHtmlFieldName();
  4309. const storeFieldName = resolveStoreFieldName();
  4310. const editorPathField = storeFieldName || props.name || "";
  4311. // 只读模式:不初始化 Jodit,直接渲染 HTML + 附件按钮 by xu 20250402
  4312. if (props.mode === "play") {
  4313. return h("div", { class: "ss-editor-container ss-editor-readonly" }, [
  4314. fjid.value &&
  4315. h("input", {
  4316. type: "hidden",
  4317. name: attachmentFieldName,
  4318. value: fjid.value,
  4319. }),
  4320. h("input", {
  4321. type: "hidden",
  4322. name: htmlFieldName,
  4323. value: editorContent.value,
  4324. }),
  4325. h("input", {
  4326. type: "hidden",
  4327. name: storeFieldName,
  4328. value: currentModelValue.value,
  4329. }),
  4330. h("input", {
  4331. type: "hidden",
  4332. name: "ueditorpath",
  4333. value: editorPathField,
  4334. }),
  4335. // 附件按钮(只读模式下仍显示)
  4336. fjButton.cmsAddUrl && fjButton.cmsUpdUrl &&
  4337. h("div", {
  4338. class: "ss-editor-attach-btn",
  4339. onClick: openAttachmentDialog,
  4340. }, [
  4341. h("span", { class: "editor-icon editor-icon-file" }),
  4342. h("span", { class: "ss-editor-attach-text" }, attachmentLabel)
  4343. ]),
  4344. // HTML 内容展示
  4345. h("div", {
  4346. class: "ss-editor-readonly-content",
  4347. innerHTML: editorContent.value,
  4348. }),
  4349. ]);
  4350. }
  4351. // 正常编辑模式:渲染 textarea 供 Jodit 初始化
  4352. return h("div", { class: "ss-editor-container" }, [
  4353. fjid.value &&
  4354. h("input", {
  4355. type: "hidden",
  4356. name: attachmentFieldName,
  4357. value: fjid.value,
  4358. }),
  4359. h("input", {
  4360. type: "hidden",
  4361. name: htmlFieldName,
  4362. value: editorContent.value,
  4363. }),
  4364. h("input", {
  4365. type: "hidden",
  4366. name: storeFieldName,
  4367. value: currentModelValue.value,
  4368. }),
  4369. h("input", {
  4370. type: "hidden",
  4371. name: "ueditorpath",
  4372. value: editorPathField,
  4373. }),
  4374. h("textarea", { id: uniqueId }),
  4375. ]);
  4376. };
  4377. },
  4378. };
  4379. // 弹窗右边图标
  4380. const SsFullStyleHeader = {
  4381. name: "SsFullStyleHeader",
  4382. props: {
  4383. title: {
  4384. type: String,
  4385. default: "标题",
  4386. },
  4387. },
  4388. emits: ["close"],
  4389. setup(props, { emit }) {
  4390. // console.log(props.title)
  4391. const onClose = () => {
  4392. emit("close");
  4393. };
  4394. const SsIcon = resolveComponent("ss-icon");
  4395. return () =>
  4396. h("div", { class: "header-container" }, [
  4397. h("div", { class: "title" }, props.title),
  4398. h("div", { class: "handle-bar" }, [
  4399. h("div", { class: "left-bar" }, [
  4400. h(SsDialogIcon, { class: "dialog-icon-download" }),
  4401. h(SsDialogIcon, { class: "dialog-icon-print" }),
  4402. h(SsDialogIcon, { class: "dialog-icon-setting" }),
  4403. h(SsDialogIcon, { class: "dialog-icon-collect" }),
  4404. h(SsDialogIcon, { class: "dialog-icon-help" }),
  4405. h(SsDialogIcon, { class: "dialog-icon-full-screen" }),
  4406. h(SsDialogIcon, { class: "dialog-icon-lock" }),
  4407. ]),
  4408. h("div", { class: "close-bar", onClick: onClose }, [
  4409. h(SsDialogIcon, { class: "dialog-icon-close" }),
  4410. ]),
  4411. ]),
  4412. ]);
  4413. },
  4414. };
  4415. // ss-dialog弹窗
  4416. const SsDialog = {
  4417. name: "SsDialog",
  4418. props: {
  4419. src: {
  4420. type: String,
  4421. },
  4422. headerTitle: {
  4423. type: String,
  4424. // required: true,
  4425. default: "弹窗",
  4426. },
  4427. width: {
  4428. type: String,
  4429. default: "1400",
  4430. },
  4431. height: {
  4432. type: String,
  4433. default: "600",
  4434. },
  4435. params: {
  4436. type: Object,
  4437. default: () => ({}),
  4438. },
  4439. zIndex: {
  4440. type: Number,
  4441. default: 1000,
  4442. },
  4443. },
  4444. emits: ["close"],
  4445. setup(props, { slots, emit }) {
  4446. // 关闭窗口方法
  4447. const onClose = () => {
  4448. emit("close");
  4449. };
  4450. const showHeader = ref(true);
  4451. const headerVisible = ref(false);
  4452. const popupHieght = ref(props.height);
  4453. // 状态:存储位置信息
  4454. const position = reactive({
  4455. // 页面居中
  4456. x: (window.innerWidth - props.width) / 2,
  4457. y: (window.innerHeight - popupHieght.value) / 2,
  4458. isDragging: false,
  4459. offsetX: 0,
  4460. offsetY: 0,
  4461. });
  4462. // 鼠标按下时设置起始坐标并开始拖拽
  4463. const startDrag = (event) => {
  4464. position.isDragging = true;
  4465. position.offsetX = event.clientX - position.x;
  4466. position.offsetY = event.clientY - position.y;
  4467. };
  4468. // 鼠标移动时更新位置
  4469. const onDrag = (event) => {
  4470. if (position.isDragging) {
  4471. position.x = event.clientX - position.offsetX;
  4472. position.y = event.clientY - position.offsetY;
  4473. }
  4474. };
  4475. // 鼠标放开时结束拖拽
  4476. const endDrag = () => {
  4477. position.isDragging = false;
  4478. };
  4479. // 监听来自 iframe 的消息
  4480. const handleMessage = (event) => {
  4481. // 顶天立地
  4482. if (event.data && typeof event.data.hasScrollBar !== "undefined") {
  4483. if (event.data.hasScrollBar) {
  4484. // console.log(event);
  4485. position.y = 10;
  4486. showHeader.value = false;
  4487. headerVisible.value = true;
  4488. popupHieght.value = window.innerHeight - 20;
  4489. // console.log(popupHieght.value);
  4490. document.querySelector(".body").style.height = "100%";
  4491. document.querySelector(".body").style.paddingTop = "30px";
  4492. document.querySelector(".header-container ").style.position =
  4493. "absolute";
  4494. document.querySelector(".header-container ").style.zIndex = "10";
  4495. }
  4496. }
  4497. };
  4498. // 鼠标移入关闭按钮区域时显示头部
  4499. const onMouseEnterCloseButton = () => {
  4500. headerVisible.value = false;
  4501. };
  4502. // 鼠标移出关闭按钮区域时隐藏头部
  4503. const onMouseLeaveCloseButton = () => {
  4504. headerVisible.value = true;
  4505. };
  4506. // 在组件挂载时添加全局事件监听器
  4507. Vue.onMounted(() => {
  4508. // 如果传过来的高度大于窗口高度,则设置为窗口高度减去20 否则保持传过来的高度
  4509. popupHieght.value =
  4510. popupHieght.value > window.innerHeight
  4511. ? window.innerHeight - 20
  4512. : popupHieght.value;
  4513. const container = document.querySelector(".header-container");
  4514. if (container) {
  4515. container.addEventListener("mousedown", startDrag);
  4516. }
  4517. document.addEventListener("mousemove", onDrag);
  4518. document.addEventListener("mouseup", endDrag);
  4519. window.addEventListener("message", handleMessage);
  4520. });
  4521. // 在组件卸载时移除全局事件监听器
  4522. Vue.onUnmounted(() => {
  4523. document.removeEventListener("mousemove", onDrag);
  4524. document.removeEventListener("mouseup", endDrag);
  4525. window.removeEventListener("message", handleMessage);
  4526. });
  4527. const SsMark = resolveComponent("ss-mark");
  4528. const SsFullStyleHeader = resolveComponent("ss-full-style-header");
  4529. // render函数定义组件结构
  4530. return () =>
  4531. h(
  4532. Teleport,
  4533. { to: "body" }, // 使用 Teleport 将弹窗内容挂载到 body
  4534. h(SsMark, {}, [
  4535. h(
  4536. "div",
  4537. {
  4538. class: "popup-container",
  4539. style: {
  4540. position: "absolute",
  4541. left: `${position.x}px`,
  4542. top: `${position.y}px`,
  4543. width: props.width + "px",
  4544. height: popupHieght.value + "px",
  4545. zIndex: props.zIndex, // 确保弹窗在最上层
  4546. },
  4547. },
  4548. [
  4549. h(SsFullStyleHeader, {
  4550. class: "header",
  4551. title: props.headerTitle,
  4552. onClose: onClose,
  4553. onMousedown: startDrag, // 绑定拖动事件
  4554. onMouseUp: endDrag,
  4555. ...(!showHeader.value && {
  4556. onMouseenter: onMouseEnterCloseButton,
  4557. onMouseleave: onMouseLeaveCloseButton,
  4558. }),
  4559. style: {
  4560. cursor: position.isDragging ? "grabbing" : "grab",
  4561. visibility: headerVisible.value ? "hidden" : "visible",
  4562. },
  4563. }),
  4564. h(
  4565. "div",
  4566. {
  4567. class: "body",
  4568. style: {},
  4569. },
  4570. [
  4571. h("iframe", {
  4572. src: props.src,
  4573. frameborder: 0,
  4574. style: { width: "100%", height: "100%" },
  4575. }),
  4576. ]
  4577. ),
  4578. headerVisible.value &&
  4579. h("div", {
  4580. class: "close-button",
  4581. onMouseenter: onMouseEnterCloseButton,
  4582. onMouseleave: onMouseLeaveCloseButton,
  4583. style: {
  4584. position: "absolute",
  4585. top: "0",
  4586. right: "0",
  4587. // background: 'black',
  4588. width: "60px",
  4589. height: "60px",
  4590. cursor: "pointer",
  4591. },
  4592. }),
  4593. ]
  4594. ),
  4595. ])
  4596. );
  4597. },
  4598. };
  4599. // ss-mark遮罩层
  4600. const SsMark = {
  4601. name: "SsMark",
  4602. setup(props, { slots, emit }) {
  4603. return () =>
  4604. h("div", { class: "dialog-container" }, [
  4605. h("div", { class: "mark-content" }, [
  4606. h("div", { class: "dialog-contianer" }, [
  4607. slots.default ? slots.default() : "",
  4608. ]),
  4609. ]),
  4610. ]);
  4611. },
  4612. };
  4613. // ss-bottom-button 底部按钮
  4614. // 修改支持更多按钮 by xu 20251211
  4615. const SsBottomButton = {
  4616. name: "SsBottomButton",
  4617. props: {
  4618. text: {
  4619. type: String,
  4620. required: false,
  4621. },
  4622. type: {
  4623. type: String,
  4624. default: "button",
  4625. },
  4626. iconClass: {
  4627. type: String,
  4628. },
  4629. class: {
  4630. type: String,
  4631. default: "",
  4632. },
  4633. onclick: {
  4634. type: [Function, String],
  4635. default: null,
  4636. },
  4637. // 修改支持更多按钮 by xu 20251211
  4638. more: {
  4639. type: [Boolean, String],
  4640. default: false,
  4641. },
  4642. },
  4643. setup(props, { emit }) {
  4644. const SsBottomDivIcon = Vue.resolveComponent("ss-bottom-div-icon");
  4645. const showDropdown = Vue.ref(false);
  4646. // 修改支持更多按钮 by xu 20251211
  4647. const moreKey = Vue.computed(() => {
  4648. const val = props.more;
  4649. if (val === false || val === null || typeof val === "undefined") {
  4650. return null;
  4651. }
  4652. if (val === true || val === "" || val === "true") {
  4653. return "moreChg";
  4654. }
  4655. return val;
  4656. });
  4657. // 从配置中读取按钮信息和下拉选项
  4658. const config = Vue.computed(() => {
  4659. if (
  4660. moreKey.value &&
  4661. window.ss &&
  4662. window.ss.dom &&
  4663. window.ss.dom.btnElemConfig
  4664. ) {
  4665. return window.ss.dom.btnElemConfig[moreKey.value] || {};
  4666. }
  4667. return {};
  4668. });
  4669. const buttonText = Vue.computed(() => {
  4670. return props.text || config.value.desc || "";
  4671. });
  4672. const dropOptions = Vue.computed(() => {
  4673. return config.value.dropOptions || [];
  4674. });
  4675. const hasDropdown = Vue.computed(() => {
  4676. return dropOptions.value.length > 0;
  4677. });
  4678. const handleMouseEnter = () => {
  4679. if (hasDropdown.value) {
  4680. showDropdown.value = true;
  4681. }
  4682. };
  4683. const handleMouseLeave = () => {
  4684. showDropdown.value = false;
  4685. };
  4686. const handleDropItemClick = (option) => {
  4687. if (option.callback && typeof option.callback === "function") {
  4688. option.callback();
  4689. }
  4690. showDropdown.value = false;
  4691. };
  4692. return () =>
  4693. h(
  4694. "div",
  4695. {
  4696. class: "ss-bottom-button-wrapper",
  4697. onMouseenter: handleMouseEnter,
  4698. onMouseleave: handleMouseLeave,
  4699. },
  4700. [
  4701. h(
  4702. "button",
  4703. {
  4704. class: props.class,
  4705. onClick: (e) => {
  4706. e.stopPropagation();
  4707. emit("click", e);
  4708. if (props.onclick) {
  4709. // 如果是函数直接调用
  4710. if (typeof props.onclick === "function") {
  4711. props.onclick(e);
  4712. } else if (typeof props.onclick === "string") {
  4713. // 如果是字符串,使用直接的方法执行
  4714. // 临时存储按钮元素到全局变量
  4715. window.__ss_current_button = e.currentTarget;
  4716. // 直接执行代码,使用eval以保留原始上下文
  4717. try {
  4718. eval(props.onclick);
  4719. } finally {
  4720. // 清理全局变量
  4721. delete window.__ss_current_button;
  4722. }
  4723. }
  4724. }
  4725. },
  4726. type: props.type,
  4727. },
  4728. [
  4729. h("span", null, [
  4730. h(SsBottomDivIcon, {
  4731. class: props.iconClass,
  4732. }),
  4733. ]),
  4734. h("span", null, buttonText.value),
  4735. ]
  4736. ),
  4737. // 渲染下拉菜单
  4738. hasDropdown.value && showDropdown.value
  4739. ? h(
  4740. "div",
  4741. {
  4742. class: "ss-bottom-button-dropdown",
  4743. },
  4744. dropOptions.value.map((option) =>
  4745. h(
  4746. "div",
  4747. {
  4748. class: "ss-bottom-button-dropdown-item",
  4749. onClick: (e) => {
  4750. e.stopPropagation();
  4751. handleDropItemClick(option);
  4752. },
  4753. },
  4754. option.desc
  4755. )
  4756. )
  4757. )
  4758. : null,
  4759. ]
  4760. );
  4761. },
  4762. };
  4763. // ss-search搜索框
  4764. const SsSearch = {
  4765. name: "SsSearch",
  4766. props: {
  4767. theme: {
  4768. type: String,
  4769. default: "light",
  4770. validator: function (value) {
  4771. return ["dark", "light"].includes(value);
  4772. },
  4773. },
  4774. placeholder: {
  4775. type: String,
  4776. default: "请输入搜索条件",
  4777. },
  4778. },
  4779. setup(props, { emit }) {
  4780. const onClick = () => {
  4781. console.log("Search clicked");
  4782. emit("click");
  4783. };
  4784. const SsIcon = Vue.resolveComponent("ss-icon");
  4785. return () =>
  4786. Vue.h(
  4787. "div",
  4788. {
  4789. class: ["search-container", props.theme],
  4790. onClick: onClick,
  4791. },
  4792. [
  4793. Vue.h("input", {
  4794. placeholder: props.placeholder,
  4795. disabled: true,
  4796. }),
  4797. Vue.h(SsIcon, {
  4798. name: "search-result",
  4799. size: "20px",
  4800. }),
  4801. ]
  4802. );
  4803. },
  4804. };
  4805. // ss-cart-item 菜单页面的卡片 左右结构
  4806. const SsCartItem = {
  4807. name: "SsCartItem",
  4808. props: {
  4809. active: Boolean,
  4810. item: {
  4811. type: Object,
  4812. default: () => ({
  4813. thumb: "images/example/project-img.png",
  4814. title: "广州(国际)科技成果转化天河基地专",
  4815. description: "佳能中国广州分公司",
  4816. all: 50,
  4817. finish: 5,
  4818. }),
  4819. },
  4820. },
  4821. setup(props, { emit }) {
  4822. const item = props.item;
  4823. const itemWidth = Vue.computed(() => {
  4824. const containerWidth =
  4825. document.body.clientWidth || document.body.scrollWidth - 520;
  4826. const halfWidth = containerWidth / 2;
  4827. if (halfWidth < 480) {
  4828. return Math.min(containerWidth, 702) + "px";
  4829. } else {
  4830. return Math.min(halfWidth, 702) + "px";
  4831. }
  4832. });
  4833. const onItemClick = (e) => {
  4834. emit("click", e);
  4835. };
  4836. return {
  4837. item,
  4838. itemWidth,
  4839. onItemClick,
  4840. };
  4841. },
  4842. render() {
  4843. const SsIcon = Vue.resolveComponent("ss-icon");
  4844. return Vue.h(
  4845. "div",
  4846. {
  4847. class: { "item-container": true, active: this.active },
  4848. onClick: this.onItemClick,
  4849. style: { width: this.itemWidth },
  4850. },
  4851. [
  4852. Vue.h("div", { class: "header" }, [
  4853. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  4854. ]),
  4855. Vue.h("div", { class: "body" }, [
  4856. Vue.h("div", { class: "left" }, [
  4857. Vue.h("img", {
  4858. src: this.item.thumb,
  4859. alt: "Thumbnail",
  4860. class: "imgUnHandle",
  4861. style: { "object-fit": "cover", width: "100%", height: "100%" },
  4862. }),
  4863. ]),
  4864. Vue.h("div", { class: "right" }, [
  4865. Vue.h("div", { class: "title" }, this.item.title),
  4866. Vue.h("div", { class: "desc" }, this.item.description),
  4867. Vue.h("div", { class: "progress" }, [
  4868. Vue.h(
  4869. "div",
  4870. {
  4871. style: {
  4872. width: `${(this.item.finish / this.item.all) * 100}%`,
  4873. },
  4874. },
  4875. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  4876. ),
  4877. ]),
  4878. ]),
  4879. ]),
  4880. ]
  4881. );
  4882. },
  4883. };
  4884. // ss-cart-item2 菜单页面的卡片 上下结构
  4885. const SsCartItem2 = {
  4886. name: "SsCartItem2",
  4887. props: {
  4888. active: Boolean,
  4889. item: {
  4890. type: Object,
  4891. default: () => ({
  4892. thumb: "images/example/project-img.png",
  4893. title: "广州(国际)科技成果转化天河基地专",
  4894. description: "佳能中国广州分公司",
  4895. all: 50,
  4896. finish: 5,
  4897. }),
  4898. },
  4899. },
  4900. setup(props, { emit }) {
  4901. const item = props.item;
  4902. const itemWidth = Vue.computed(() => {
  4903. const containerWidth =
  4904. document.body.clientWidth || document.body.scrollWidth - 520;
  4905. const halfWidth = containerWidth / 2;
  4906. if (halfWidth < 480) {
  4907. return Math.min(containerWidth, 702) + "px";
  4908. } else {
  4909. return Math.min(halfWidth, 702) + "px";
  4910. }
  4911. });
  4912. const onItemClick = (e) => {
  4913. emit("click", e);
  4914. };
  4915. return {
  4916. item,
  4917. itemWidth,
  4918. onItemClick,
  4919. };
  4920. },
  4921. render() {
  4922. const SsIcon = Vue.resolveComponent("ss-icon");
  4923. return Vue.h(
  4924. "div",
  4925. {
  4926. class: { "item-container2": true, active: this.active },
  4927. onClick: this.onItemClick,
  4928. style: { width: this.itemWidth },
  4929. },
  4930. [
  4931. Vue.h("div", { class: "action-bar" }, [
  4932. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  4933. ]),
  4934. Vue.h("div", { class: "header" }, [
  4935. Vue.h("div", { class: "title" }, `${this.item.title}`),
  4936. ]),
  4937. Vue.h("div", { class: "body" }, [
  4938. Vue.h("div", { class: "left" }, [
  4939. Vue.h("img", {
  4940. src: this.item.thumb,
  4941. alt: "Thumbnail",
  4942. class: "imgUnHandle",
  4943. style: { "object-fit": "cover", width: "100%", height: "100%" },
  4944. }),
  4945. ]),
  4946. Vue.h("div", { class: "right" }, [
  4947. Vue.h("div", { class: "content" }, this.item.description),
  4948. Vue.h("div", { class: "tip" }, [
  4949. Vue.h("div", { class: "progress" }, [
  4950. Vue.h(
  4951. "div",
  4952. {
  4953. style: {
  4954. width: `${(this.item.finish / this.item.all) * 100}%`,
  4955. },
  4956. },
  4957. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  4958. ),
  4959. ]),
  4960. ]),
  4961. ]),
  4962. ]),
  4963. ]
  4964. );
  4965. },
  4966. };
  4967. /**
  4968. * SsListCard - 列表卡片组件
  4969. *
  4970. * @description 用于显示列表项的卡片组件,支持缩略图、标签、状态、操作按钮和选择功能
  4971. *
  4972. * @prop {Object} item - 卡片数据对象
  4973. * @prop {String} item.title - 卡片标题
  4974. * @prop {String} [item.thumb] - 缩略图 URL(可选)
  4975. * @prop {String} [item.thumbType] - 缩略图类型:'thumbnail'(缩略图)或默认(证件照)
  4976. * @prop {String} [item.status] - 卡片状态:'available'(可用-绿色)、'unavailable'(不可用-黄色)、'disabled'(禁用-红色)
  4977. * @prop {Array} item.tags - 标签数组,格式:[{键: 值}, ...]
  4978. * @prop {Function} item.onclick - 点击卡片的回调函数
  4979. * @prop {Array} [item.buttons] - 操作按钮数组(可选),显示在右上角齿轮
  4980. * @prop {Array} [item.statusIcons] - 状态图标数组(可选),显示在右上角,格式:[{class: '图标类名', title: '提示文字'}, ...]
  4981. *
  4982. * @example
  4983. * // 基础用法
  4984. * const item = {
  4985. * title: "卡片标题",
  4986. * tags: [
  4987. * { 类型: '文档' },
  4988. * { 状态: '进行中' }
  4989. * ],
  4990. * onclick: () => console.log('点击了卡片')
  4991. * };
  4992. *
  4993. * @example
  4994. * // 带缩略图和状态
  4995. * const item = {
  4996. * title: "场地预定",
  4997. * thumbType: 'thumbnail',
  4998. * thumb: "https://example.com/image.jpg",
  4999. * status: "available", // 绿色背景
  5000. * tags: [{ 容量: '50人' }],
  5001. * onclick: () => {}
  5002. * };
  5003. *
  5004. * @example
  5005. * // 带操作按钮和状态图标
  5006. * const item = {
  5007. * title: "会议室A",
  5008. * tags: [{ 楼层: '3F' }],
  5009. * onclick: () => {},
  5010. * // 右上角操作按钮(齿轮)
  5011. * buttons: [{
  5012. * class: 'cart-list-setting',
  5013. * title: '编辑',
  5014. * onclick: () => console.log('编辑')
  5015. * }],
  5016. * // 右上角状态图标(在齿轮右边)
  5017. * statusIcons: [{
  5018. * class: 'icon-emoji',
  5019. * title: '清洁中'
  5020. * }]
  5021. * };
  5022. *
  5023. * @features
  5024. * - 卡片选择:鼠标悬停右下角显示选择角标,点击切换选中状态,选中后显示底部深灰色线条
  5025. * - 状态颜色:根据 status 字段显示不同背景色(可用/不可用/禁用)
  5026. * - 图片类型:支持证件照(73×100px)和缩略图(180×100px)两种尺寸
  5027. * - 操作按钮:右上角齿轮,hover 显示,支持多个按钮下拉菜单
  5028. * - 状态图标:右上角显示状态图标,齿轮会根据图标数量自动左移
  5029. *
  5030. * @author xu
  5031. * @date 20260105
  5032. */
  5033. // 组件文档补全(JSDoc) by xu 20260108
  5034. /**
  5035. * SsListCard(左侧对象卡片)
  5036. *
  5037. * 用途:
  5038. * - 渲染左侧卡片(标题 + tags)
  5039. * - 右下角“角标”用于选中/取消选中(不会触发卡片 click)
  5040. *
  5041. * 调用示例:
  5042. * ```html
  5043. * <ss-list-card :item="item" @toggle-select="handleToggleSelect" @click="openDetail"></ss-list-card>
  5044. * ```
  5045. *
  5046. * Props:
  5047. * - `item`:卡片数据对象(建议含 `id/title/tags[]`;内部会读写 `item._ssSelected` 作为选中态)
  5048. *
  5049. * Emits:
  5050. * - `toggle-select`:点击角标触发,参数 `{ item, selected }`
  5051. * - `click`:点击卡片主体触发(用于打开详情等)
  5052. */
  5053. const SsListCard = {
  5054. name: "SsListCard",
  5055. props: {
  5056. ssObjName: { type: String, default: "" }, // 功能:业务对象名(用于默认缩略图 icon) by xu 20260109
  5057. cardClickAction: { type: String, default: "view" }, // 功能:卡片主体点击动作(view=查看;single=单选互斥) by xu 20260109
  5058. item: {
  5059. type: Object,
  5060. required: true,
  5061. },
  5062. },
  5063. emits: ["click", "change", "toggle-select"],
  5064. setup(props, { emit }) {
  5065. const item = props.item;
  5066. // 移除 itemWidth 计算属性,不再需要 by xu 20260105
  5067. // 判断卡片类型 by xu 20260105
  5068. const cardType = Vue.computed(() => {
  5069. // 支持“无图但保留缩略图占位”(同一业务列表图片形态一致) by xu 20260109
  5070. if (!item.thumb && !item.thumbType) return ""; // 业务列表“无图”形态
  5071. // 根据 thumbType 字段判断,如果没有则默认为证件照
  5072. return item.thumbType === "thumbnail" ? "card-thumbnail" : "card-photo";
  5073. });
  5074. // 判断状态类型 - 场地预定状态 by xu 20260105
  5075. const statusClass = Vue.computed(() => {
  5076. if (!item.status) return ""; // 无状态,默认白色
  5077. // 映射状态值到 CSS 类名
  5078. const statusMap = {
  5079. available: "status-available",
  5080. unavailable: "status-unavailable",
  5081. disabled: "status-disabled",
  5082. };
  5083. return statusMap[item.status] || "";
  5084. });
  5085. const onItemClick = (e) => {
  5086. // 清除所有类型卡片的 active 状态(卡片主体点击仅做 active 高亮) by xu 20260109
  5087. const allListCards = document.querySelectorAll(
  5088. ".knowledge-item-container"
  5089. );
  5090. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  5091. allListCards.forEach((card) => card.classList.remove("active"));
  5092. allFolderCards.forEach((card) => card.classList.remove("active"));
  5093. // 设置当前项的 active 状态
  5094. e.currentTarget.classList.add("active");
  5095. // 卡片主体点击动作由页面级配置控制 by xu 20260109
  5096. if (props.cardClickAction === "view") {
  5097. props.item.onclick?.();
  5098. // 通知父级:卡片点击(查看) by xu 20260109
  5099. emit("click", props.item);
  5100. }
  5101. };
  5102. const onItemChange = (e, icon, index) => {
  5103. e.stopPropagation(); // 阻止事件冒泡到卡片
  5104. props.item.buttons[0].onclick();
  5105. // emit("change", { item: props.item, icon, index });
  5106. };
  5107. return {
  5108. item,
  5109. cardType,
  5110. statusClass,
  5111. onItemClick,
  5112. onItemChange,
  5113. };
  5114. },
  5115. data() {
  5116. return {
  5117. showButtons: false,
  5118. selected: false, // 选择状态 by xu 20260105
  5119. showTextPopover: false, // 功能:右侧文字区 hover 展示全量 by xu 20260108
  5120. textPopoverType: "", // second-summary / second-tags / third / third-full by xu 20260108
  5121. textPopoverBottom: 0, // 功能:popover 从当前省略行位置向上展开 by xu 20260108
  5122. hideTextPopoverTimer: null, // 功能:鼠标从省略行移到浮层的缓冲 by xu 20260108
  5123. textPopoverPayload: null, // { kind, text?, lines? } by xu 20260108
  5124. ellipsisVisible: {
  5125. // 功能:只在真实出现 ... 时才显示命中区/允许 goheight by xu 20260109
  5126. secondSummary: false,
  5127. secondTags: false,
  5128. third: false,
  5129. thirdFull: false,
  5130. },
  5131. };
  5132. },
  5133. methods: {
  5134. __allowSelect() {
  5135. // 功能说明:无 rbarObj 时禁用选中能力(隐藏右下角勾选并禁止 toggle) by xu 20260122
  5136. try {
  5137. if (this?.$root && this.$root.hasObjPanel === false) return false;
  5138. if (
  5139. typeof window !== "undefined" &&
  5140. window.__objListVm &&
  5141. window.__objListVm.hasObjPanel === false
  5142. )
  5143. return false;
  5144. } catch (_) {}
  5145. return true;
  5146. },
  5147. // 切换选择状态(对外 emit,支持方案A父级 state 中转) by xu 20260106
  5148. toggleSelect(e) {
  5149. e.stopPropagation();
  5150. if (!this.__allowSelect()) return; // 功能说明:无 rbarObj 时禁止选中 by xu 20260122
  5151. // 使用 item 上的状态,便于父级/右侧边栏反向同步 by xu 20260106
  5152. this.item._ssSelected = !this.item?._ssSelected;
  5153. this.$emit("toggle-select", {
  5154. item: this.item,
  5155. selected: !!this.item?._ssSelected,
  5156. });
  5157. },
  5158. // 卡片主体点击=单选互斥:只有“本次切到选中”才清理其他选中 by xu 20260109
  5159. toggleSelectExclusive(e) {
  5160. e?.stopPropagation?.();
  5161. if (!this.__allowSelect()) return; // 功能说明:无 rbarObj 时禁止选中 by xu 20260122
  5162. this.item._ssSelected = !this.item?._ssSelected;
  5163. const selected = !!this.item?._ssSelected;
  5164. this.$emit("toggle-select", {
  5165. item: this.item,
  5166. selected,
  5167. exclusive: true,
  5168. });
  5169. },
  5170. // 功能:无缩略图时,用业务对象 icon 做默认图(ss-icon + icon-obj-xx) by xu 20260109
  5171. getBizThumbIconClass() {
  5172. const name = String(
  5173. this.ssObjName ||
  5174. this.item?.ssObjName ||
  5175. this.$root?.ssObjName ||
  5176. window?.ss?.dom?.ssObjName ||
  5177. ""
  5178. ).trim();
  5179. if (!name) return "";
  5180. return `icon-obj-${name}`;
  5181. },
  5182. // 功能:构造右侧文字区 4 行(摘要/类目或标签/对象号) by xu 20260108
  5183. buildRightTextLines() {
  5184. const item = this.item || {};
  5185. const summary = String(item?.desc ?? "").trim(); // 后端字段后续映射 by xu 20260108
  5186. const objNum = String(item?.objNum ?? "").trim(); // 后端字段后续映射 by xu 20260108
  5187. const categoryArr = Array.isArray(item?.category) ? item.category : [];
  5188. const tagsArr = Array.isArray(item?.tags) ? item.tags : [];
  5189. const hasTags = tagsArr.length > 0;
  5190. const hasCategory = categoryArr.length > 0;
  5191. // 第二部分(L1-L3):摘要优先,其次物品参数 by xu 20260108
  5192. const secondKind = summary ? "summary" : hasTags ? "tags" : "";
  5193. const hasSecond = !!secondKind;
  5194. // 第三部分(L4):对象号优先,其次类目 by xu 20260108
  5195. const thirdKind = objNum ? "objNum" : hasCategory ? "category" : "";
  5196. const hasThird = !!thirdKind;
  5197. const thirdFull = !hasSecond && hasThird; // 第二部分为空则第三部分占满 4 行 by xu 20260108
  5198. const secondFull = hasSecond && !hasThird && secondKind === "tags"; // 仅标签时占满 4 行(不留空行) by xu 20260109
  5199. const toValueText = (obj) => {
  5200. // 功能说明:类目/物品参数回显展示 key: value(否则只显示值看不懂) by xu 20260114
  5201. const [k, v] = Object.entries(obj || {})[0] || ["", ""];
  5202. const key = k !== undefined && k !== null ? String(k).trim() : "";
  5203. const val = v !== undefined && v !== null ? String(v).trim() : "";
  5204. if (key && val) return `${key}:${val}`;
  5205. if (val) return val;
  5206. if (key) return key;
  5207. return "";
  5208. };
  5209. const toLineList = (arr) =>
  5210. (arr || [])
  5211. .map(toValueText)
  5212. .map((s) => String(s ?? "").trim())
  5213. .filter(Boolean);
  5214. const flat = (arr) => toLineList(arr).join(" ");
  5215. // 第二部分 tags:默认 3 行;仅标签时占满 4 行(避免底部空一行) by xu 20260109
  5216. const secondTagsMaxLines = secondFull ? 4 : 3;
  5217. const secondTagsLinesFull = toLineList(tagsArr);
  5218. const secondTagsHead = secondTagsLinesFull.slice(
  5219. 0,
  5220. Math.max(0, secondTagsMaxLines - 1)
  5221. );
  5222. const secondTagsTail = secondTagsLinesFull.slice(
  5223. Math.max(0, secondTagsMaxLines - 1)
  5224. );
  5225. const secondTagsLast =
  5226. secondTagsTail.length <= 1
  5227. ? secondTagsTail[0] || ""
  5228. : secondTagsTail.join(" "); // 功能:最后一行平铺剩余 by xu 20260108
  5229. // 第三部分类目:卡片上串成一行;goheight 展开时一条一行 by xu 20260109
  5230. const categoryLinesFull = toLineList(categoryArr);
  5231. const categoryLine = categoryLinesFull.join(" ");
  5232. const thirdText =
  5233. thirdKind === "objNum"
  5234. ? objNum
  5235. : thirdKind === "category"
  5236. ? categoryLine
  5237. : "";
  5238. return {
  5239. secondKind,
  5240. thirdKind,
  5241. hasSecond,
  5242. hasThird,
  5243. thirdFull,
  5244. secondFull,
  5245. summary,
  5246. secondTagsMaxLines,
  5247. secondTagsHead,
  5248. secondTagsLast,
  5249. secondTagsLinesFull,
  5250. objNum,
  5251. categoryLine,
  5252. categoryLinesFull,
  5253. thirdText,
  5254. };
  5255. },
  5256. measureTextOverflowByLines(text, maxLines, width) {
  5257. const w = Number(width) || 0;
  5258. if (!w || !text) return false;
  5259. const probe = document.createElement("div");
  5260. probe.style.position = "fixed";
  5261. probe.style.left = "-99999px";
  5262. probe.style.top = "0";
  5263. probe.style.width = w + "px";
  5264. probe.style.fontSize = "18px";
  5265. probe.style.lineHeight = "24px";
  5266. probe.style.whiteSpace = "normal";
  5267. probe.style.wordBreak = "break-word";
  5268. probe.style.visibility = "hidden";
  5269. probe.textContent = text;
  5270. document.body.appendChild(probe);
  5271. const h = probe.getBoundingClientRect().height || 0;
  5272. document.body.removeChild(probe);
  5273. return h > maxLines * 24 + 1;
  5274. },
  5275. measureSingleLineOverflow(text, width) {
  5276. const w = Number(width) || 0;
  5277. if (!w || !text) return false;
  5278. const probe = document.createElement("span");
  5279. probe.style.position = "fixed";
  5280. probe.style.left = "-99999px";
  5281. probe.style.top = "0";
  5282. probe.style.display = "inline-block";
  5283. probe.style.maxWidth = w + "px";
  5284. probe.style.fontSize = "18px";
  5285. probe.style.lineHeight = "24px";
  5286. probe.style.whiteSpace = "nowrap";
  5287. probe.style.visibility = "hidden";
  5288. probe.textContent = text;
  5289. document.body.appendChild(probe);
  5290. const overflow =
  5291. (probe.scrollWidth || 0) > (probe.clientWidth || w) + 1;
  5292. document.body.removeChild(probe);
  5293. return overflow;
  5294. },
  5295. // 功能:根据当前卡片宽度刷新「是否出现 ...」状态(用于控制命中区显示) by xu 20260109
  5296. refreshEllipsisVisible() {
  5297. try {
  5298. const right = this.$el?.querySelector?.(".right");
  5299. const rawWidth =
  5300. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  5301. const width = Math.max(0, Math.round(rawWidth)); // 修复:内容区不再使用 padding-right 预留,测量按真实宽度 by xu 20260109
  5302. const model = this.buildRightTextLines();
  5303. const next = {
  5304. secondSummary: false,
  5305. secondTags: false,
  5306. third: false,
  5307. thirdFull: false,
  5308. };
  5309. if (model.secondKind === "summary" && model.summary) {
  5310. next.secondSummary = this.measureTextOverflowByLines(
  5311. model.summary,
  5312. 3,
  5313. width
  5314. );
  5315. }
  5316. if (model.secondKind === "tags") {
  5317. // 功能说明:tags 采用「最后一行平铺剩余」策略,是否出现 ... 仅取决于最后一行是否溢出(数量多但平铺放得下不算溢出) by xu 20260114
  5318. next.secondTags = this.measureSingleLineOverflow(
  5319. model.secondTagsLast,
  5320. width
  5321. );
  5322. }
  5323. if (model.hasThird && !model.thirdFull) {
  5324. next.third = this.measureSingleLineOverflow(model.thirdText, width);
  5325. }
  5326. if (model.hasThird && model.thirdFull) {
  5327. next.thirdFull = this.measureTextOverflowByLines(
  5328. model.thirdText,
  5329. 4,
  5330. width
  5331. );
  5332. }
  5333. const prev = this.ellipsisVisible || {};
  5334. const changed =
  5335. prev.secondSummary !== next.secondSummary ||
  5336. prev.secondTags !== next.secondTags ||
  5337. prev.third !== next.third ||
  5338. prev.thirdFull !== next.thirdFull;
  5339. if (changed) this.ellipsisVisible = next;
  5340. } catch (e) {
  5341. // ignore by xu 20260109
  5342. }
  5343. },
  5344. showTextPopoverFor(el, kind) {
  5345. // 调试开关:window.__SS_LISTCARD_DEBUG__ = true 时打印 hover/溢出判断日志 by xu 20260108
  5346. const debug =
  5347. typeof window !== "undefined" && !!window.__SS_LISTCARD_DEBUG__;
  5348. if (debug) {
  5349. console.log("[SsListCard] ellipsis hover", {
  5350. kind,
  5351. el: el?.className,
  5352. });
  5353. }
  5354. const model = this.buildRightTextLines();
  5355. const lineEl = el?.closest?.(".ss-card-text__line") || el;
  5356. const right = lineEl?.closest?.(".right") || el?.closest?.(".right");
  5357. const rawWidth =
  5358. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  5359. const width = Math.max(0, Math.round(rawWidth)); // 修复:内容区不再预留 padding-right,测量按真实宽度 by xu 20260109
  5360. const textEl =
  5361. kind === "second-summary"
  5362. ? lineEl?.querySelector?.(".ss-card-text__secondSummary")
  5363. : kind === "second-tags"
  5364. ? lineEl?.querySelector?.(".ss-card-text__tagLineLast")
  5365. : kind === "third"
  5366. ? lineEl?.querySelector?.(".ss-card-text__thirdLine")
  5367. : lineEl?.querySelector?.(".ss-card-text__thirdFull");
  5368. let payload = null;
  5369. // 仅当真实会出现 ... 时才允许 goheight(避免“没超出也能出 goheight”) by xu 20260109
  5370. const overflowed =
  5371. kind === "second-summary"
  5372. ? this.measureTextOverflowByLines(model.summary, 3, width)
  5373. : kind === "second-tags"
  5374. ? this.measureSingleLineOverflow(model.secondTagsLast, width) // 功能说明:同 refreshEllipsisVisible,tags 仅看最后一行是否溢出 by xu 20260114
  5375. : kind === "third"
  5376. ? this.measureSingleLineOverflow(model.thirdText, width)
  5377. : this.measureTextOverflowByLines(model.thirdText, 4, width);
  5378. if (!overflowed) return;
  5379. if (kind === "second-summary") {
  5380. if (model.summary) payload = { kind, text: model.summary };
  5381. } else if (kind === "second-tags") {
  5382. if (
  5383. Array.isArray(model.secondTagsLinesFull) &&
  5384. model.secondTagsLinesFull.length
  5385. ) {
  5386. payload = { kind, lines: model.secondTagsLinesFull };
  5387. }
  5388. } else if (kind === "third") {
  5389. if (
  5390. model.thirdKind === "category" &&
  5391. Array.isArray(model.categoryLinesFull) &&
  5392. model.categoryLinesFull.length
  5393. ) {
  5394. payload = { kind, lines: model.categoryLinesFull }; // 功能:类目展开一条一行 by xu 20260109
  5395. } else if (model.thirdText) {
  5396. payload = { kind, text: model.thirdText };
  5397. }
  5398. } else if (kind === "third-full") {
  5399. if (
  5400. model.thirdKind === "category" &&
  5401. Array.isArray(model.categoryLinesFull) &&
  5402. model.categoryLinesFull.length
  5403. ) {
  5404. payload = { kind, lines: model.categoryLinesFull }; // 功能:类目占满模式展开一条一行 by xu 20260109
  5405. } else if (model.thirdText) {
  5406. payload = { kind, text: model.thirdText };
  5407. }
  5408. }
  5409. if (debug) {
  5410. console.log("[SsListCard] ellipsis decide", {
  5411. kind,
  5412. rawWidth: Math.round(rawWidth),
  5413. width,
  5414. hasPayload: !!payload,
  5415. textEl: textEl?.className,
  5416. textClient: textEl
  5417. ? {
  5418. cw: textEl.clientWidth,
  5419. ch: textEl.clientHeight,
  5420. sw: textEl.scrollWidth,
  5421. sh: textEl.scrollHeight,
  5422. }
  5423. : null,
  5424. });
  5425. }
  5426. if (!payload) return;
  5427. this.clearHideTextPopoverTimer();
  5428. const container = lineEl?.closest?.(".right");
  5429. const containerRect = container?.getBoundingClientRect?.();
  5430. const lineRect = lineEl?.getBoundingClientRect?.();
  5431. if (containerRect && lineRect) {
  5432. const bottom = Math.max(
  5433. 0,
  5434. Math.round(containerRect.bottom - lineRect.bottom)
  5435. );
  5436. this.textPopoverBottom = bottom;
  5437. } else {
  5438. this.textPopoverBottom = 0;
  5439. }
  5440. this.textPopoverPayload = payload;
  5441. this.textPopoverType = kind;
  5442. this.showTextPopover = true;
  5443. if (debug) console.log("[SsListCard] goheight show", payload);
  5444. },
  5445. isOverflowing(el) {
  5446. if (!el) return false;
  5447. // 单行/多行省略统一判断:scroll 尺寸大于 client 尺寸即认为有 ... by xu 20260108
  5448. return (
  5449. (el.scrollWidth &&
  5450. el.clientWidth &&
  5451. el.scrollWidth > el.clientWidth + 1) ||
  5452. (el.scrollHeight &&
  5453. el.clientHeight &&
  5454. el.scrollHeight > el.clientHeight + 1)
  5455. );
  5456. },
  5457. isSummaryOverflowing(el) {
  5458. if (!el) return false;
  5459. // -webkit-line-clamp 场景下 scrollHeight 不稳定,改用“无 clamp 的离屏测量”判断是否超过 2 行 by xu 20260108
  5460. const text = String(this.item?.desc ?? "").trim();
  5461. if (!text) return false;
  5462. const rect = el.getBoundingClientRect?.();
  5463. const width = rect?.width || el.clientWidth || 0;
  5464. if (!width) return false;
  5465. const probe = document.createElement("div");
  5466. probe.style.position = "fixed";
  5467. probe.style.left = "-99999px";
  5468. probe.style.top = "0";
  5469. probe.style.width = width + "px";
  5470. probe.style.fontSize = "18px";
  5471. probe.style.lineHeight = "24px";
  5472. probe.style.whiteSpace = "normal";
  5473. probe.style.wordBreak = "break-word";
  5474. probe.style.visibility = "hidden";
  5475. probe.textContent = text;
  5476. document.body.appendChild(probe);
  5477. const h = probe.getBoundingClientRect().height || 0;
  5478. document.body.removeChild(probe);
  5479. return h > 48 + 1;
  5480. },
  5481. clearHideTextPopoverTimer() {
  5482. if (this.hideTextPopoverTimer) {
  5483. clearTimeout(this.hideTextPopoverTimer);
  5484. this.hideTextPopoverTimer = null;
  5485. }
  5486. },
  5487. // 修复 goheight hover 无响应:移除重复方法覆盖,统一使用上面的 showTextPopoverFor(el, kind) by xu 20260109
  5488. hideTextPopoverLater() {
  5489. this.clearHideTextPopoverTimer();
  5490. this.hideTextPopoverTimer = setTimeout(() => {
  5491. this.showTextPopover = false;
  5492. this.textPopoverType = "";
  5493. this.textPopoverPayload = null;
  5494. }, 120);
  5495. },
  5496. hideTextPopover() {
  5497. this.clearHideTextPopoverTimer();
  5498. this.showTextPopover = false;
  5499. this.textPopoverType = "";
  5500. this.textPopoverPayload = null;
  5501. },
  5502. // 功能:新需求下不在 updated 内做测量,避免死循环 by xu 20260108
  5503. },
  5504. mounted() {
  5505. // 无需在 mounted/updated 里做 overflow 测量(避免死循环),只在 hover 触发时判断 by xu 20260108
  5506. // 仅用于控制“...命中区是否显示”,不会触发循环更新 by xu 20260109
  5507. this.$nextTick?.(() => {
  5508. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5509. });
  5510. this.__ssListCardResizeHandler = () => this.refreshEllipsisVisible?.(); // 功能:窗口变化时刷新 ... 显示 by xu 20260109
  5511. window.addEventListener?.("resize", this.__ssListCardResizeHandler);
  5512. },
  5513. updated() {
  5514. // 卡片数据更新后刷新一次 ... 显示状态(避免“宽度/内容变了但命中区不变”) by xu 20260109
  5515. this.$nextTick?.(() => {
  5516. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5517. });
  5518. },
  5519. beforeUnmount() {
  5520. // 清理 timer,避免残留导致异常 by xu 20260108
  5521. this.clearHideTextPopoverTimer?.();
  5522. if (this.__ssListCardResizeHandler) {
  5523. window.removeEventListener?.("resize", this.__ssListCardResizeHandler);
  5524. this.__ssListCardResizeHandler = null;
  5525. }
  5526. },
  5527. render() {
  5528. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  5529. const SsIcon = Vue.resolveComponent("ss-icon");
  5530. const hasThumbArea = !!(this.item?.thumb || this.item?.thumbType); // 功能:无图但有 thumbType 时仍保留占位 by xu 20260109
  5531. const thumbSrc = (() => {
  5532. // 功能说明:兼容 thumb 为 raw path 或 {val}/{value},组件内统一转为 dlByHttp URL by xu 20260122
  5533. const t = this.item?.thumb;
  5534. if (!t) return "";
  5535. if (typeof t === "string") {
  5536. const s = t.trim();
  5537. if (!s) return "";
  5538. // 已经是 URL/绝对路径则直接使用;否则按 path 构建 dlByHttp by xu 20260122
  5539. if (
  5540. /^https?:\/\//i.test(s) ||
  5541. s.startsWith("/service?") ||
  5542. s.startsWith("/")
  5543. )
  5544. return s;
  5545. return buildThumbUrl(s);
  5546. }
  5547. return buildThumbUrl(t);
  5548. })();
  5549. return Vue.h(
  5550. "div",
  5551. {
  5552. class: {
  5553. "knowledge-item-container": true,
  5554. active: this.item.active,
  5555. [this.cardType]: !!this.cardType, // 动态添加卡片类型类名 by xu 20260105
  5556. [this.statusClass]: !!this.statusClass,
  5557. },
  5558. onClick: (e) => {
  5559. this.onItemClick?.(e);
  5560. if (this.__allowSelect() && this.cardClickAction === "single") {
  5561. // 功能说明:无 rbarObj 时不允许单选互斥 by xu 20260122
  5562. this.toggleSelectExclusive?.(e);
  5563. }
  5564. }, // 功能:卡片主体点击动作(view/single) by xu 20260109
  5565. // 移除固定宽度,由 CSS min-width 控制 by xu 20260105
  5566. },
  5567. [
  5568. // 右上角状态图标区域 by xu 20260105
  5569. this.item?.statusIcons?.length > 0 &&
  5570. Vue.h(
  5571. "div",
  5572. { class: "card-status-icons" },
  5573. this.item.statusIcons.map((icon) =>
  5574. Vue.h(SsIcon, {
  5575. class: `status-icon ${icon.class}`,
  5576. title: icon.title,
  5577. })
  5578. )
  5579. ),
  5580. this.item?.buttons?.length > 0 &&
  5581. Vue.h(
  5582. "div",
  5583. {
  5584. class: "header",
  5585. style:
  5586. this.item?.statusIcons?.length > 0
  5587. ? {
  5588. right: `${this.item.statusIcons.length * 48}px`,
  5589. borderTopRightRadius: "0",
  5590. }
  5591. : {},
  5592. onMouseenter: () => (this.showButtons = true),
  5593. onMouseleave: () => (this.showButtons = false),
  5594. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  5595. },
  5596. [
  5597. // 只在有按钮时渲染设置图标
  5598. // this.item?.buttons?.length > 0 &&
  5599. Vue.h("div", {
  5600. class: "cart-list-setting cart-list-icon",
  5601. title: this.item?.buttons?.[0]?.title,
  5602. }),
  5603. // 鼠标移入时显示按钮列表,与图标同级
  5604. // this.item?.buttons?.length > 0 &&
  5605. this.showButtons &&
  5606. this.item?.buttons?.length > 1 &&
  5607. Vue.h(
  5608. "div",
  5609. {
  5610. class: "cart-list-button-popup",
  5611. },
  5612. this.item.buttons.map((btn) =>
  5613. Vue.h(
  5614. "div",
  5615. {
  5616. onClick: (e) => {
  5617. e.stopPropagation();
  5618. btn.onclick?.();
  5619. },
  5620. },
  5621. [
  5622. // 如果有 class,显示对应的图标
  5623. btn.class &&
  5624. Vue.h(SsCartListIcon, {
  5625. class: [btn.class],
  5626. }),
  5627. // 显示按钮文本
  5628. Vue.h("span", null, btn.title),
  5629. ]
  5630. )
  5631. )
  5632. ),
  5633. ]
  5634. ),
  5635. Vue.h("div", { class: "body" }, [
  5636. Vue.h("div", { class: "box-header" }, [
  5637. Vue.h("div", `${this.item.title}`),
  5638. ]),
  5639. Vue.h(
  5640. "div",
  5641. {
  5642. class: !hasThumbArea ? "no-thumb box-body" : "box-body",
  5643. },
  5644. [
  5645. hasThumbArea
  5646. ? thumbSrc
  5647. ? Vue.h("div", { class: "left" }, [
  5648. Vue.h("img", {
  5649. src: thumbSrc,
  5650. alt: "Thumbnail",
  5651. class: "imgUnHandle",
  5652. style: {
  5653. "object-fit": "cover",
  5654. width: "100%",
  5655. height: "100%",
  5656. },
  5657. }),
  5658. ])
  5659. : Vue.h(
  5660. // 功能:无图占位(ss-icon + biz icon,居中) by xu 20260109
  5661. "div",
  5662. { class: "left ss-objlist-thumbPlaceholder" },
  5663. [
  5664. Vue.h(SsIcon, {
  5665. class: `${this.getBizThumbIconClass()} ss-objlist-thumbIcon`,
  5666. }),
  5667. ]
  5668. )
  5669. : null,
  5670. Vue.h(
  5671. "div",
  5672. {
  5673. class: "right",
  5674. },
  5675. (() => {
  5676. const model = this.buildRightTextLines(); // 功能:右侧文字区新规则(第二部分/第三部分优先级) by xu 20260108
  5677. const hasAny = !!(model?.hasSecond || model?.hasThird);
  5678. if (!hasAny) return [];
  5679. const children = [];
  5680. // 第二部分:L1-L3(摘要优先,其次 tags;不足留空;超出 L3 ...) by xu 20260108
  5681. if (model.hasSecond) {
  5682. if (model.secondKind === "summary") {
  5683. children.push(
  5684. Vue.h(
  5685. "div",
  5686. {
  5687. class:
  5688. "ss-card-text__line ss-card-text__secondBlock",
  5689. },
  5690. [
  5691. Vue.h(
  5692. "div",
  5693. {
  5694. class: "ss-card-text__secondSummary",
  5695. title: model.summary,
  5696. },
  5697. model.summary
  5698. ),
  5699. Vue.h("span", {
  5700. class: [
  5701. "ss-card-text__ellipsisHit",
  5702. "ss-card-text__ellipsisHit--second",
  5703. this.ellipsisVisible?.secondSummary
  5704. ? "is-on"
  5705. : "",
  5706. ],
  5707. title: "查看完整摘要",
  5708. onMouseenter: (e) =>
  5709. this.showTextPopoverFor(
  5710. e?.currentTarget,
  5711. "second-summary"
  5712. ),
  5713. onClick: (e) => {
  5714. e?.stopPropagation?.();
  5715. this.showTextPopoverFor(
  5716. e?.currentTarget,
  5717. "second-summary"
  5718. );
  5719. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5720. onMouseleave: () => this.hideTextPopoverLater(),
  5721. }),
  5722. ]
  5723. )
  5724. );
  5725. } else if (model.secondKind === "tags") {
  5726. children.push(
  5727. Vue.h(
  5728. "div",
  5729. {
  5730. class: [
  5731. "ss-card-text__line",
  5732. model.secondFull
  5733. ? "ss-card-text__secondFullBlock"
  5734. : "ss-card-text__secondBlock",
  5735. ],
  5736. },
  5737. [
  5738. // 功能:仅标签时占满 4 行 by xu 20260109
  5739. Vue.h(
  5740. "div",
  5741. { class: "ss-card-text__secondTags" },
  5742. [
  5743. ...model.secondTagsHead.map((t) =>
  5744. Vue.h(
  5745. "div",
  5746. {
  5747. class: "ss-card-text__tagLine",
  5748. title: t,
  5749. },
  5750. t
  5751. )
  5752. ),
  5753. // 第三行:平铺剩余(可能为空) by xu 20260108
  5754. Vue.h(
  5755. "div",
  5756. {
  5757. class:
  5758. "ss-card-text__tagLine is-last ss-card-text__tagLineLast",
  5759. title: model.secondTagsLast,
  5760. },
  5761. model.secondTagsLast
  5762. ),
  5763. ].filter(Boolean)
  5764. ),
  5765. // 只在最后一行出现 ... 时才触发 goheight by xu 20260108
  5766. Vue.h("span", {
  5767. class: [
  5768. "ss-card-text__ellipsisHit",
  5769. "ss-card-text__ellipsisHit--second",
  5770. this.ellipsisVisible?.secondTags
  5771. ? "is-on"
  5772. : "",
  5773. ],
  5774. title: "查看完整物品参数",
  5775. onMouseenter: (e) =>
  5776. this.showTextPopoverFor(
  5777. e?.currentTarget,
  5778. "second-tags"
  5779. ),
  5780. onClick: (e) => {
  5781. e?.stopPropagation?.();
  5782. this.showTextPopoverFor(
  5783. e?.currentTarget,
  5784. "second-tags"
  5785. );
  5786. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5787. onMouseleave: () => this.hideTextPopoverLater(),
  5788. }),
  5789. ]
  5790. )
  5791. );
  5792. }
  5793. }
  5794. // 第三部分:默认 L4;第二部分为空则占满 L1-L4 by xu 20260108
  5795. if (model.hasThird) {
  5796. if (model.thirdFull) {
  5797. children.push(
  5798. Vue.h(
  5799. "div",
  5800. {
  5801. class:
  5802. "ss-card-text__line ss-card-text__thirdFullBlock",
  5803. },
  5804. [
  5805. Vue.h(
  5806. "div",
  5807. {
  5808. class: "ss-card-text__thirdFull",
  5809. title: model.thirdText,
  5810. },
  5811. model.thirdText
  5812. ),
  5813. Vue.h("span", {
  5814. class: [
  5815. "ss-card-text__ellipsisHit",
  5816. "ss-card-text__ellipsisHit--third",
  5817. this.ellipsisVisible?.thirdFull
  5818. ? "is-on"
  5819. : "",
  5820. ],
  5821. title: "查看完整信息",
  5822. onMouseenter: (e) =>
  5823. this.showTextPopoverFor(
  5824. e?.currentTarget,
  5825. "third-full"
  5826. ),
  5827. onClick: (e) => {
  5828. e?.stopPropagation?.();
  5829. this.showTextPopoverFor(
  5830. e?.currentTarget,
  5831. "third-full"
  5832. );
  5833. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5834. onMouseleave: () => this.hideTextPopoverLater(),
  5835. }),
  5836. ]
  5837. )
  5838. );
  5839. } else {
  5840. children.push(
  5841. Vue.h(
  5842. "div",
  5843. {
  5844. class:
  5845. "ss-card-text__line ss-card-text__thirdLineWrap",
  5846. },
  5847. [
  5848. Vue.h(
  5849. "div",
  5850. {
  5851. class: "ss-card-text__thirdLine",
  5852. title: model.thirdText,
  5853. },
  5854. model.thirdText
  5855. ),
  5856. Vue.h("span", {
  5857. class: [
  5858. "ss-card-text__ellipsisHit",
  5859. "ss-card-text__ellipsisHit--third",
  5860. this.ellipsisVisible?.third ? "is-on" : "",
  5861. ],
  5862. title: "查看完整信息",
  5863. onMouseenter: (e) =>
  5864. this.showTextPopoverFor(
  5865. e?.currentTarget,
  5866. "third"
  5867. ),
  5868. onClick: (e) => {
  5869. e?.stopPropagation?.();
  5870. this.showTextPopoverFor(
  5871. e?.currentTarget,
  5872. "third"
  5873. );
  5874. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5875. onMouseleave: () => this.hideTextPopoverLater(),
  5876. }),
  5877. ]
  5878. )
  5879. );
  5880. }
  5881. }
  5882. // hover 展开浮层:宽度=右侧文字区,底对齐向上展开,带阴影 by xu 20260108
  5883. // popover 作为 `.right` 的 sibling 渲染,避免被 `.ss-card-text{overflow:hidden}` 裁剪 by xu 20260108
  5884. const popover =
  5885. this.showTextPopover &&
  5886. Vue.h(
  5887. "div",
  5888. {
  5889. class: "ss-card-text-popover",
  5890. style: { bottom: this.textPopoverBottom + "px" },
  5891. onMouseenter: () => {
  5892. this.clearHideTextPopoverTimer();
  5893. this.showTextPopover = true;
  5894. },
  5895. onMouseleave: () => this.hideTextPopoverLater(),
  5896. },
  5897. (() => {
  5898. const p = this.textPopoverPayload || {};
  5899. if (p.kind === "second-summary" && p.text) {
  5900. return [
  5901. Vue.h(
  5902. "div",
  5903. { class: "ss-card-text-popover__summary" },
  5904. p.text
  5905. ),
  5906. ];
  5907. }
  5908. if (Array.isArray(p.lines)) {
  5909. return [
  5910. Vue.h(
  5911. "div",
  5912. { class: "ss-card-text-popover__kvlist" },
  5913. p.lines.map((t) =>
  5914. Vue.h(
  5915. "div",
  5916. { class: "ss-card-text-popover__kv" },
  5917. t
  5918. )
  5919. )
  5920. ),
  5921. ];
  5922. }
  5923. if (
  5924. (p.kind === "third" || p.kind === "third-full") &&
  5925. p.text
  5926. ) {
  5927. return [
  5928. Vue.h(
  5929. "div",
  5930. { class: "ss-card-text-popover__objno" },
  5931. p.text
  5932. ),
  5933. ];
  5934. }
  5935. return [];
  5936. })()
  5937. );
  5938. return [
  5939. Vue.h("div", { class: "ss-card-text" }, children),
  5940. popover,
  5941. ];
  5942. })()
  5943. ),
  5944. ]
  5945. ),
  5946. ]),
  5947. // 右下角卡片选择图标 by xu 20260105
  5948. this.__allowSelect()
  5949. ? Vue.h(SsIcon, {
  5950. class: this.item?._ssSelected
  5951. ? "card-icon icon-cardChk-on"
  5952. : "card-icon icon-cardChk",
  5953. onClick: this.toggleSelect,
  5954. })
  5955. : null,
  5956. // 选中后底部线条 by xu 20260105
  5957. this.__allowSelect() &&
  5958. this.item?._ssSelected &&
  5959. Vue.h("div", { class: "select-bottom-line" }),
  5960. ]
  5961. );
  5962. },
  5963. };
  5964. // 二级对象卡片:复用一级对象新卡片布局/省略浮层,但去掉勾选与 single 选中,仅支持点击查看 by xu 20260115
  5965. const SsCObjCardList = {
  5966. name: "SsCObjCardList",
  5967. props: {
  5968. ssObjName: { type: String, default: "" }, // 功能说明:业务对象名(用于默认缩略图 icon) by xu 20260115
  5969. dataType: { type: String, default: "" }, // 功能说明:页面类型(play=查看模式不显示右上角按钮) by xu 20250408
  5970. item: {
  5971. type: Object,
  5972. required: true,
  5973. },
  5974. },
  5975. emits: ["click", "change"],
  5976. setup(props, { emit }) {
  5977. const item = props.item;
  5978. const dataType = props.dataType; // 功能说明:页面类型 by xu 20250408
  5979. const cardType = Vue.computed(() => {
  5980. if (!item.thumb && !item.thumbType) return "";
  5981. return item.thumbType === "thumbnail" ? "card-thumbnail" : "card-photo";
  5982. });
  5983. const statusClass = Vue.computed(() => {
  5984. if (!item.status) return "";
  5985. const statusMap = {
  5986. available: "status-available",
  5987. unavailable: "status-unavailable",
  5988. disabled: "status-disabled",
  5989. };
  5990. return statusMap[item.status] || "";
  5991. });
  5992. const onItemClick = (e) => {
  5993. // 清除所有类型卡片的 active 状态(保持与一级对象一致) by xu 20260115
  5994. const allListCards = document.querySelectorAll(
  5995. ".knowledge-item-container"
  5996. );
  5997. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  5998. allListCards.forEach((card) => card.classList.remove("active"));
  5999. allFolderCards.forEach((card) => card.classList.remove("active"));
  6000. e.currentTarget.classList.add("active");
  6001. // 二级对象卡片:点击仅查看(调用 item.onclick) by xu 20260115
  6002. props.item.onclick?.();
  6003. emit("click", props.item);
  6004. };
  6005. const onItemChange = (e) => {
  6006. e.stopPropagation();
  6007. props.item.buttons?.[0]?.onclick?.();
  6008. };
  6009. return { item, dataType, cardType, statusClass, onItemClick, onItemChange };
  6010. },
  6011. data() {
  6012. return {
  6013. showButtons: false,
  6014. showTextPopover: false, // 功能:右侧文字区 hover 展示全量 by xu 20260115
  6015. textPopoverType: "", // second-summary / second-tags / third / third-full by xu 20260115
  6016. textPopoverBottom: 0, // 功能:popover 从当前省略行位置向上展开 by xu 20260115
  6017. hideTextPopoverTimer: null, // 功能:鼠标从省略行移到浮层的缓冲 by xu 20260115
  6018. textPopoverPayload: null, // { kind, text?, lines? } by xu 20260115
  6019. ellipsisVisible: {
  6020. secondSummary: false,
  6021. secondTags: false,
  6022. third: false,
  6023. thirdFull: false,
  6024. }, // 功能:只在真实出现 ... 时才显示命中区/允许 goheight by xu 20260115
  6025. };
  6026. },
  6027. methods: {
  6028. getBizThumbIconClass() {
  6029. // 功能:无缩略图时,用业务对象 icon 做默认图(ss-icon + icon-obj-xx) by xu 20260115
  6030. const name = String(
  6031. this.ssObjName ||
  6032. this.item?.ssObjName ||
  6033. this.$root?.ssObjName ||
  6034. window?.ss?.dom?.ssObjName ||
  6035. ""
  6036. ).trim();
  6037. if (!name) return "";
  6038. return "icon-obj-" + name;
  6039. },
  6040. buildRightTextLines() {
  6041. // 功能:沿用一级对象卡片右侧文字区规则 by xu 20260115
  6042. const item = this.item || {};
  6043. const summary = String(item?.desc ?? "").trim();
  6044. const objNum = String(item?.objNum ?? "").trim();
  6045. const categoryArr = Array.isArray(item?.category) ? item.category : [];
  6046. const tagsArr = Array.isArray(item?.tags) ? item.tags : [];
  6047. const hasTags = tagsArr.length > 0;
  6048. const hasCategory = categoryArr.length > 0;
  6049. const secondKind = summary ? "summary" : hasTags ? "tags" : "";
  6050. const hasSecond = !!secondKind;
  6051. const thirdKind = objNum ? "objNum" : hasCategory ? "category" : "";
  6052. const hasThird = !!thirdKind;
  6053. const thirdFull = !hasSecond && hasThird;
  6054. const secondFull = hasSecond && !hasThird && secondKind === "tags";
  6055. const toValueText = (obj) => {
  6056. // 功能说明:类目/物品参数回显展示 key: value(否则只显示值看不懂) by xu 20260115
  6057. const [k, v] = Object.entries(obj || {})[0] || ["", ""];
  6058. const key = k !== undefined && k !== null ? String(k).trim() : "";
  6059. const val = v !== undefined && v !== null ? String(v).trim() : "";
  6060. if (key && val) return key + ":" + val;
  6061. if (val) return val;
  6062. if (key) return key;
  6063. return "";
  6064. };
  6065. const toLineList = (arr) =>
  6066. (arr || [])
  6067. .map(toValueText)
  6068. .map((s) => String(s ?? "").trim())
  6069. .filter(Boolean);
  6070. const secondTagsMaxLines = secondFull ? 4 : 3;
  6071. const secondTagsLinesFull = toLineList(tagsArr);
  6072. const secondTagsHead = secondTagsLinesFull.slice(
  6073. 0,
  6074. Math.max(0, secondTagsMaxLines - 1)
  6075. );
  6076. const secondTagsTail = secondTagsLinesFull.slice(
  6077. Math.max(0, secondTagsMaxLines - 1)
  6078. );
  6079. const secondTagsLast =
  6080. secondTagsTail.length <= 1
  6081. ? secondTagsTail[0] || ""
  6082. : secondTagsTail.join(" ");
  6083. const categoryLinesFull = toLineList(categoryArr);
  6084. const categoryLine = categoryLinesFull.join(" ");
  6085. const thirdText =
  6086. thirdKind === "objNum"
  6087. ? objNum
  6088. : thirdKind === "category"
  6089. ? categoryLine
  6090. : "";
  6091. return {
  6092. secondKind,
  6093. thirdKind,
  6094. hasSecond,
  6095. hasThird,
  6096. thirdFull,
  6097. secondFull,
  6098. summary,
  6099. secondTagsMaxLines,
  6100. secondTagsHead,
  6101. secondTagsLast,
  6102. secondTagsLinesFull,
  6103. objNum,
  6104. categoryLine,
  6105. categoryLinesFull,
  6106. thirdText,
  6107. };
  6108. },
  6109. measureTextOverflowByLines(text, maxLines, width) {
  6110. const w = Number(width) || 0;
  6111. if (!w || !text) return false;
  6112. const probe = document.createElement("div");
  6113. probe.style.position = "fixed";
  6114. probe.style.left = "-99999px";
  6115. probe.style.top = "0";
  6116. probe.style.width = w + "px";
  6117. probe.style.fontSize = "18px";
  6118. probe.style.lineHeight = "24px";
  6119. probe.style.whiteSpace = "normal";
  6120. probe.style.wordBreak = "break-word";
  6121. probe.style.visibility = "hidden";
  6122. probe.textContent = text;
  6123. document.body.appendChild(probe);
  6124. const h = probe.getBoundingClientRect().height || 0;
  6125. document.body.removeChild(probe);
  6126. return h > maxLines * 24 + 1;
  6127. },
  6128. measureSingleLineOverflow(text, width) {
  6129. const w = Number(width) || 0;
  6130. if (!w || !text) return false;
  6131. const probe = document.createElement("span");
  6132. probe.style.position = "fixed";
  6133. probe.style.left = "-99999px";
  6134. probe.style.top = "0";
  6135. probe.style.display = "inline-block";
  6136. probe.style.maxWidth = w + "px";
  6137. probe.style.fontSize = "18px";
  6138. probe.style.lineHeight = "24px";
  6139. probe.style.whiteSpace = "nowrap";
  6140. probe.style.visibility = "hidden";
  6141. probe.textContent = text;
  6142. document.body.appendChild(probe);
  6143. const overflow =
  6144. (probe.scrollWidth || 0) > (probe.clientWidth || w) + 1;
  6145. document.body.removeChild(probe);
  6146. return overflow;
  6147. },
  6148. refreshEllipsisVisible() {
  6149. // 功能:刷新「是否出现 ...」状态(用于控制命中区显示) by xu 20260115
  6150. try {
  6151. const right = this.$el?.querySelector?.(".right");
  6152. const rawWidth =
  6153. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  6154. const width = Math.max(0, Math.round(rawWidth));
  6155. const model = this.buildRightTextLines();
  6156. const next = {
  6157. secondSummary: false,
  6158. secondTags: false,
  6159. third: false,
  6160. thirdFull: false,
  6161. };
  6162. if (model.secondKind === "summary" && model.summary) {
  6163. next.secondSummary = this.measureTextOverflowByLines(
  6164. model.summary,
  6165. 3,
  6166. width
  6167. );
  6168. }
  6169. if (model.secondKind === "tags") {
  6170. next.secondTags = this.measureSingleLineOverflow(
  6171. model.secondTagsLast,
  6172. width
  6173. ); // 功能说明:tags 仅看最后一行是否溢出 by xu 20260115
  6174. }
  6175. if (model.hasThird && !model.thirdFull) {
  6176. next.third = this.measureSingleLineOverflow(model.thirdText, width);
  6177. }
  6178. if (model.hasThird && model.thirdFull) {
  6179. next.thirdFull = this.measureTextOverflowByLines(
  6180. model.thirdText,
  6181. 4,
  6182. width
  6183. );
  6184. }
  6185. const prev = this.ellipsisVisible || {};
  6186. const changed =
  6187. prev.secondSummary !== next.secondSummary ||
  6188. prev.secondTags !== next.secondTags ||
  6189. prev.third !== next.third ||
  6190. prev.thirdFull !== next.thirdFull;
  6191. if (changed) this.ellipsisVisible = next;
  6192. } catch (e) {
  6193. // ignore by xu 20260115
  6194. }
  6195. },
  6196. clearHideTextPopoverTimer() {
  6197. if (this.hideTextPopoverTimer) {
  6198. clearTimeout(this.hideTextPopoverTimer);
  6199. this.hideTextPopoverTimer = null;
  6200. }
  6201. },
  6202. hideTextPopoverLater() {
  6203. this.clearHideTextPopoverTimer();
  6204. this.hideTextPopoverTimer = setTimeout(() => {
  6205. this.showTextPopover = false;
  6206. this.textPopoverType = "";
  6207. this.textPopoverPayload = null;
  6208. }, 120);
  6209. },
  6210. showTextPopoverFor(el, kind) {
  6211. const model = this.buildRightTextLines();
  6212. const lineEl = el?.closest?.(".ss-card-text__line") || el;
  6213. const right = lineEl?.closest?.(".right") || el?.closest?.(".right");
  6214. const rawWidth =
  6215. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  6216. const width = Math.max(0, Math.round(rawWidth));
  6217. const overflowed =
  6218. kind === "second-summary"
  6219. ? this.measureTextOverflowByLines(model.summary, 3, width)
  6220. : kind === "second-tags"
  6221. ? this.measureSingleLineOverflow(model.secondTagsLast, width)
  6222. : kind === "third"
  6223. ? this.measureSingleLineOverflow(model.thirdText, width)
  6224. : this.measureTextOverflowByLines(model.thirdText, 4, width);
  6225. if (!overflowed) return;
  6226. let payload = null;
  6227. if (kind === "second-summary") {
  6228. if (model.summary) payload = { kind, text: model.summary };
  6229. } else if (kind === "second-tags") {
  6230. if (
  6231. Array.isArray(model.secondTagsLinesFull) &&
  6232. model.secondTagsLinesFull.length
  6233. ) {
  6234. payload = { kind, lines: model.secondTagsLinesFull };
  6235. }
  6236. } else if (kind === "third") {
  6237. if (
  6238. model.thirdKind === "category" &&
  6239. Array.isArray(model.categoryLinesFull) &&
  6240. model.categoryLinesFull.length
  6241. ) {
  6242. payload = { kind, lines: model.categoryLinesFull };
  6243. } else if (model.thirdText) {
  6244. payload = { kind, text: model.thirdText };
  6245. }
  6246. } else if (kind === "third-full") {
  6247. if (
  6248. model.thirdKind === "category" &&
  6249. Array.isArray(model.categoryLinesFull) &&
  6250. model.categoryLinesFull.length
  6251. ) {
  6252. payload = { kind, lines: model.categoryLinesFull };
  6253. } else if (model.thirdText) {
  6254. payload = { kind, text: model.thirdText };
  6255. }
  6256. }
  6257. if (!payload) return;
  6258. this.clearHideTextPopoverTimer();
  6259. const container = lineEl?.closest?.(".right");
  6260. const containerRect = container?.getBoundingClientRect?.();
  6261. const lineRect = lineEl?.getBoundingClientRect?.();
  6262. if (containerRect && lineRect) {
  6263. const bottom = Math.max(
  6264. 0,
  6265. Math.round(containerRect.bottom - lineRect.bottom)
  6266. );
  6267. this.textPopoverBottom = bottom;
  6268. } else {
  6269. this.textPopoverBottom = 0;
  6270. }
  6271. this.textPopoverPayload = payload;
  6272. this.textPopoverType = kind;
  6273. this.showTextPopover = true;
  6274. },
  6275. },
  6276. mounted() {
  6277. this.$nextTick?.(() => {
  6278. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  6279. });
  6280. this.__ssCObjCardResizeHandler = () => this.refreshEllipsisVisible?.(); // 功能说明:窗口变化时刷新 ... 显示 by xu 20260115
  6281. window.addEventListener?.("resize", this.__ssCObjCardResizeHandler);
  6282. },
  6283. updated() {
  6284. this.$nextTick?.(() => {
  6285. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  6286. });
  6287. },
  6288. beforeUnmount() {
  6289. this.clearHideTextPopoverTimer?.();
  6290. if (this.__ssCObjCardResizeHandler) {
  6291. window.removeEventListener?.("resize", this.__ssCObjCardResizeHandler);
  6292. this.__ssCObjCardResizeHandler = null;
  6293. }
  6294. },
  6295. render() {
  6296. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  6297. const SsIcon = Vue.resolveComponent("ss-icon");
  6298. const hasThumbArea = !!(this.item?.thumb || this.item?.thumbType);
  6299. const thumbSrc = (() => {
  6300. // 功能说明:兼容 thumb 为 raw path 或 {val}/{value},组件内统一转为 dlByHttp URL by xu 20260122
  6301. const t = this.item?.thumb;
  6302. if (!t) return "";
  6303. if (typeof t === "string") {
  6304. const s = t.trim();
  6305. if (!s) return "";
  6306. if (
  6307. /^https?:\/\//i.test(s) ||
  6308. s.startsWith("/service?") ||
  6309. s.startsWith("/")
  6310. )
  6311. return s;
  6312. return buildThumbUrl(s);
  6313. }
  6314. return buildThumbUrl(t);
  6315. })();
  6316. return Vue.h(
  6317. "div",
  6318. {
  6319. class: {
  6320. "knowledge-item-container": true,
  6321. active: this.item.active,
  6322. [this.cardType]: !!this.cardType,
  6323. [this.statusClass]: !!this.statusClass,
  6324. },
  6325. onClick: (e) => this.onItemClick?.(e), // 功能说明:二级对象卡片点击仅查看 by xu 20260115
  6326. },
  6327. [
  6328. this.item?.statusIcons?.length > 0 &&
  6329. Vue.h(
  6330. "div",
  6331. { class: "card-status-icons" },
  6332. this.item.statusIcons.map((icon) =>
  6333. Vue.h(SsIcon, {
  6334. class: "status-icon " + icon.class,
  6335. title: icon.title,
  6336. })
  6337. )
  6338. ),
  6339. this.item?.buttons?.length > 0 && this.dataType !== "play" &&
  6340. Vue.h(
  6341. "div",
  6342. {
  6343. class: "header",
  6344. style:
  6345. this.item?.statusIcons?.length > 0
  6346. ? {
  6347. right: String(this.item.statusIcons.length * 48) + "px",
  6348. borderTopRightRadius: "0",
  6349. }
  6350. : {},
  6351. onMouseenter: () => (this.showButtons = true),
  6352. onMouseleave: () => (this.showButtons = false),
  6353. onClick: (e) => this.onItemChange(e),
  6354. },
  6355. [
  6356. Vue.h("div", {
  6357. class: "cart-list-setting cart-list-icon",
  6358. title: this.item?.buttons?.[0]?.title,
  6359. }),
  6360. this.showButtons &&
  6361. this.item?.buttons?.length > 1 &&
  6362. Vue.h(
  6363. "div",
  6364. { class: "cart-list-button-popup" },
  6365. this.item.buttons.map((btn) =>
  6366. Vue.h(
  6367. "div",
  6368. {
  6369. onClick: (e) => {
  6370. e.stopPropagation();
  6371. btn.onclick?.();
  6372. },
  6373. },
  6374. [
  6375. btn.class &&
  6376. Vue.h(SsCartListIcon, { class: [btn.class] }),
  6377. Vue.h("span", null, btn.title),
  6378. ]
  6379. )
  6380. )
  6381. ),
  6382. ]
  6383. ),
  6384. Vue.h("div", { class: "body" }, [
  6385. Vue.h("div", { class: "box-header" }, [
  6386. Vue.h("div", String(this.item.title || "")),
  6387. ]),
  6388. Vue.h(
  6389. "div",
  6390. { class: !hasThumbArea ? "no-thumb box-body" : "box-body" },
  6391. [
  6392. hasThumbArea
  6393. ? thumbSrc
  6394. ? Vue.h("div", { class: "left" }, [
  6395. Vue.h("img", {
  6396. src: thumbSrc,
  6397. alt: "Thumbnail",
  6398. class: "imgUnHandle",
  6399. style: {
  6400. "object-fit": "cover",
  6401. width: "100%",
  6402. height: "100%",
  6403. },
  6404. }),
  6405. ])
  6406. : Vue.h(
  6407. "div",
  6408. { class: "left ss-objlist-thumbPlaceholder" },
  6409. [
  6410. Vue.h(SsIcon, {
  6411. class:
  6412. this.getBizThumbIconClass() +
  6413. " ss-objlist-thumbIcon",
  6414. }),
  6415. ]
  6416. )
  6417. : null,
  6418. Vue.h(
  6419. "div",
  6420. { class: "right" },
  6421. (() => {
  6422. const model = this.buildRightTextLines();
  6423. const hasAny = !!(model?.hasSecond || model?.hasThird);
  6424. if (!hasAny) return [];
  6425. const children = [];
  6426. if (model.hasSecond && model.secondKind === "summary") {
  6427. children.push(
  6428. Vue.h(
  6429. "div",
  6430. {
  6431. class:
  6432. "ss-card-text__line ss-card-text__secondBlock",
  6433. },
  6434. [
  6435. Vue.h(
  6436. "div",
  6437. {
  6438. class: "ss-card-text__secondSummary",
  6439. title: model.summary,
  6440. },
  6441. model.summary
  6442. ),
  6443. Vue.h("span", {
  6444. class: [
  6445. "ss-card-text__ellipsisHit",
  6446. "ss-card-text__ellipsisHit--second",
  6447. this.ellipsisVisible?.secondSummary
  6448. ? "is-on"
  6449. : "",
  6450. ],
  6451. title: "查看完整信息",
  6452. onMouseenter: (e) =>
  6453. this.showTextPopoverFor(
  6454. e?.currentTarget,
  6455. "second-summary"
  6456. ),
  6457. onClick: (e) => {
  6458. e?.stopPropagation?.();
  6459. this.showTextPopoverFor(
  6460. e?.currentTarget,
  6461. "second-summary"
  6462. );
  6463. },
  6464. onMouseleave: () => this.hideTextPopoverLater(),
  6465. }),
  6466. ]
  6467. )
  6468. );
  6469. }
  6470. if (model.hasSecond && model.secondKind === "tags") {
  6471. children.push(
  6472. Vue.h(
  6473. "div",
  6474. {
  6475. class: [
  6476. "ss-card-text__line",
  6477. model.secondFull
  6478. ? "ss-card-text__secondFullBlock"
  6479. : "ss-card-text__secondBlock",
  6480. ],
  6481. },
  6482. [
  6483. Vue.h(
  6484. "div",
  6485. { class: "ss-card-text__secondTags" },
  6486. [
  6487. ...model.secondTagsHead.map((t) =>
  6488. Vue.h(
  6489. "div",
  6490. {
  6491. class: "ss-card-text__tagLine",
  6492. title: t,
  6493. },
  6494. t
  6495. )
  6496. ),
  6497. Vue.h(
  6498. "div",
  6499. {
  6500. class:
  6501. "ss-card-text__tagLine is-last ss-card-text__tagLineLast",
  6502. title: model.secondTagsLast,
  6503. },
  6504. model.secondTagsLast
  6505. ),
  6506. ]
  6507. ),
  6508. Vue.h("span", {
  6509. class: [
  6510. "ss-card-text__ellipsisHit",
  6511. "ss-card-text__ellipsisHit--second",
  6512. this.ellipsisVisible?.secondTags ? "is-on" : "",
  6513. ],
  6514. title: "查看完整信息",
  6515. onMouseenter: (e) =>
  6516. this.showTextPopoverFor(
  6517. e?.currentTarget,
  6518. "second-tags"
  6519. ),
  6520. onClick: (e) => {
  6521. e?.stopPropagation?.();
  6522. this.showTextPopoverFor(
  6523. e?.currentTarget,
  6524. "second-tags"
  6525. );
  6526. },
  6527. onMouseleave: () => this.hideTextPopoverLater(),
  6528. }),
  6529. ]
  6530. )
  6531. );
  6532. }
  6533. if (model.hasThird) {
  6534. if (model.thirdFull) {
  6535. children.push(
  6536. Vue.h(
  6537. "div",
  6538. {
  6539. class:
  6540. "ss-card-text__line ss-card-text__thirdFullBlock",
  6541. },
  6542. [
  6543. Vue.h(
  6544. "div",
  6545. {
  6546. class: "ss-card-text__thirdFull",
  6547. title: model.thirdText,
  6548. },
  6549. model.thirdText
  6550. ),
  6551. Vue.h("span", {
  6552. class: [
  6553. "ss-card-text__ellipsisHit",
  6554. "ss-card-text__ellipsisHit--third",
  6555. this.ellipsisVisible?.thirdFull
  6556. ? "is-on"
  6557. : "",
  6558. ],
  6559. title: "查看完整信息",
  6560. onMouseenter: (e) =>
  6561. this.showTextPopoverFor(
  6562. e?.currentTarget,
  6563. "third-full"
  6564. ),
  6565. onClick: (e) => {
  6566. e?.stopPropagation?.();
  6567. this.showTextPopoverFor(
  6568. e?.currentTarget,
  6569. "third-full"
  6570. );
  6571. },
  6572. onMouseleave: () => this.hideTextPopoverLater(),
  6573. }),
  6574. ]
  6575. )
  6576. );
  6577. } else {
  6578. children.push(
  6579. Vue.h(
  6580. "div",
  6581. {
  6582. class:
  6583. "ss-card-text__line ss-card-text__thirdLineWrap",
  6584. },
  6585. [
  6586. Vue.h(
  6587. "div",
  6588. {
  6589. class: "ss-card-text__thirdLine",
  6590. title: model.thirdText,
  6591. },
  6592. model.thirdText
  6593. ),
  6594. Vue.h("span", {
  6595. class: [
  6596. "ss-card-text__ellipsisHit",
  6597. "ss-card-text__ellipsisHit--third",
  6598. this.ellipsisVisible?.third ? "is-on" : "",
  6599. ],
  6600. title: "查看完整信息",
  6601. onMouseenter: (e) =>
  6602. this.showTextPopoverFor(
  6603. e?.currentTarget,
  6604. "third"
  6605. ),
  6606. onClick: (e) => {
  6607. e?.stopPropagation?.();
  6608. this.showTextPopoverFor(
  6609. e?.currentTarget,
  6610. "third"
  6611. );
  6612. },
  6613. onMouseleave: () => this.hideTextPopoverLater(),
  6614. }),
  6615. ]
  6616. )
  6617. );
  6618. }
  6619. }
  6620. const popover =
  6621. this.showTextPopover &&
  6622. Vue.h(
  6623. "div",
  6624. {
  6625. class: "ss-card-text-popover",
  6626. style: { bottom: this.textPopoverBottom + "px" },
  6627. onMouseenter: () => {
  6628. this.clearHideTextPopoverTimer();
  6629. this.showTextPopover = true;
  6630. },
  6631. onMouseleave: () => this.hideTextPopoverLater(),
  6632. },
  6633. (() => {
  6634. const p = this.textPopoverPayload || {};
  6635. if (p.kind === "second-summary" && p.text) {
  6636. return [
  6637. Vue.h(
  6638. "div",
  6639. { class: "ss-card-text-popover__summary" },
  6640. p.text
  6641. ),
  6642. ];
  6643. }
  6644. if (Array.isArray(p.lines)) {
  6645. return [
  6646. Vue.h(
  6647. "div",
  6648. { class: "ss-card-text-popover__kvlist" },
  6649. p.lines.map((t) =>
  6650. Vue.h(
  6651. "div",
  6652. { class: "ss-card-text-popover__kv" },
  6653. t
  6654. )
  6655. )
  6656. ),
  6657. ];
  6658. }
  6659. if (
  6660. (p.kind === "third" || p.kind === "third-full") &&
  6661. p.text
  6662. ) {
  6663. return [
  6664. Vue.h(
  6665. "div",
  6666. { class: "ss-card-text-popover__objno" },
  6667. p.text
  6668. ),
  6669. ];
  6670. }
  6671. return [];
  6672. })()
  6673. );
  6674. return [
  6675. Vue.h("div", { class: "ss-card-text" }, children),
  6676. popover,
  6677. ];
  6678. })()
  6679. ),
  6680. ]
  6681. ),
  6682. ]),
  6683. ]
  6684. );
  6685. },
  6686. };
  6687. // ss-sidebar 右侧边栏(容器 + 子组件),用于 objList 右侧区域 by xu 20260106
  6688. // 组件文档补全(JSDoc) by xu 20260108
  6689. /**
  6690. * SsSidebarButtons(右侧边栏顶部按钮栏)
  6691. *
  6692. * 用途:
  6693. * - 渲染 objList 右侧顶部快捷操作(预定/入住/退房/清洁...)
  6694. * - 内部复用 `ss-search-button`(项目现有按钮样式/交互)
  6695. *
  6696. * 调用示例:
  6697. * ```html
  6698. * <ss-sidebar-buttons :items="sidebarButtons" />
  6699. * ```
  6700. *
  6701. * Props:
  6702. * - `items`: 按钮配置数组
  6703. * - `{ id, text, icon?, onClick? }`
  6704. *
  6705. * Emits:
  6706. * - `click`:点击按钮时触发,参数为按钮对象
  6707. */
  6708. const SsSidebarButtons = {
  6709. name: "SsSidebarButtons",
  6710. props: {
  6711. items: { type: Array, default: () => [] },
  6712. },
  6713. emits: ["click"],
  6714. render() {
  6715. const SsSearchButton = Vue.resolveComponent("ss-search-button");
  6716. const items = this.items || [];
  6717. if (!items.length) return null;
  6718. return Vue.h(
  6719. "div",
  6720. { class: "ss-sidebar-actions" },
  6721. items.map((btn) =>
  6722. // 顶部操作按钮复用 ss-search-button(先 mock 固定按钮) by xu 20260106
  6723. Vue.h(SsSearchButton, {
  6724. text: btn?.text ?? "",
  6725. iconClass: btn?.iconClass ?? "",
  6726. opt: btn?.opt ?? [],
  6727. checkId: btn?.checkId ?? "0",
  6728. width: btn?.width,
  6729. id: btn?.id,
  6730. onClick: (e) => {
  6731. e?.stopPropagation?.();
  6732. btn?.onClick?.(btn);
  6733. this.$emit("click", btn);
  6734. },
  6735. })
  6736. )
  6737. );
  6738. },
  6739. };
  6740. // 组件文档补全(JSDoc) by xu 20260108
  6741. /**
  6742. * SsSidebarChart(ECharts 容器渲染)
  6743. *
  6744. * 用途:
  6745. * - 仅负责 echarts init / setOption / resize / dispose
  6746. * - 被 `ss-sidebar-chart-hover` 与图表面板复用
  6747. *
  6748. * 调用示例:
  6749. * ```html
  6750. * <ss-sidebar-chart :options="option" height="220px" />
  6751. * ```
  6752. *
  6753. * Props:
  6754. * - `options`:ECharts option(Object)
  6755. * - `height`:容器高度(String)
  6756. */
  6757. const SsSidebarChart = {
  6758. name: "SsSidebarChart",
  6759. props: {
  6760. options: { type: Object, default: () => ({}) },
  6761. height: { type: String, default: "200px" },
  6762. },
  6763. setup(props) {
  6764. const elRef = Vue.ref(null);
  6765. let chart = null;
  6766. const renderChart = () => {
  6767. if (!elRef.value || !window.echarts) return;
  6768. if (!chart) {
  6769. chart = window.echarts.init(elRef.value);
  6770. }
  6771. chart.setOption(props.options || {}, true);
  6772. };
  6773. const resizeChart = () => {
  6774. chart?.resize?.();
  6775. };
  6776. Vue.onMounted(() => {
  6777. renderChart();
  6778. window.addEventListener("resize", resizeChart);
  6779. });
  6780. Vue.onBeforeUnmount(() => {
  6781. window.removeEventListener("resize", resizeChart);
  6782. chart?.dispose?.();
  6783. chart = null;
  6784. });
  6785. Vue.watch(
  6786. () => props.options,
  6787. () => {
  6788. renderChart();
  6789. },
  6790. { deep: true }
  6791. );
  6792. return { elRef };
  6793. },
  6794. render() {
  6795. return Vue.h("div", {
  6796. ref: "elRef",
  6797. style: {
  6798. width: "100%",
  6799. height: this.height,
  6800. // 图表容器不加 padding/border,由外层布局控制 by xu 20260106
  6801. background: "transparent",
  6802. border: "none",
  6803. "border-radius": "0",
  6804. },
  6805. });
  6806. },
  6807. };
  6808. // ss-sidebar-chart-hover:hover 弹出左侧大图(支持图钉/全屏) by xu 20260106
  6809. // 组件文档补全(JSDoc) by xu 20260108
  6810. /**
  6811. * SsSidebarChartHover(小图 + hover 左侧大图预览 + 图钉固定 + 全屏)
  6812. *
  6813. * 用途:
  6814. * - 右侧统计图小卡片:hover 时在左侧弹出大图预览
  6815. * - 预览头部:左侧图标+标题;右侧固定/全屏按钮(icon-base)
  6816. * - 全屏:方案A(浏览器 Fullscreen API)
  6817. *
  6818. * 调用示例(由 ss-sidebar chart panel 内部调用):
  6819. * ```html
  6820. * <ss-sidebar-chart-hover
  6821. * title="校舍建筑面积和总体分布"
  6822. * icon-class="menu-icon icon-obj-jzw"
  6823. * :options="option"
  6824. * height="220px"
  6825. * />
  6826. * ```
  6827. *
  6828. * Props:
  6829. * - `title/iconClass/icon`:用于预览/全屏 header 显示(与面板 header 一致)
  6830. * - `options`:ECharts option
  6831. * - `height`:小图高度
  6832. * - `previewWidth/previewHeight`:预览建议尺寸(会按视口自适应)
  6833. */
  6834. const SsSidebarChartHover = {
  6835. name: "SsSidebarChartHover",
  6836. props: {
  6837. // hover 大图标题/图标(与小图面板 header 一致) by xu 20260108
  6838. title: { type: String, default: "" },
  6839. iconClass: { type: String, default: "" },
  6840. icon: { type: String, default: "" },
  6841. options: { type: Object, default: () => ({}) },
  6842. height: { type: String, default: "220px" },
  6843. // hover 弹窗建议尺寸:默认 1000x650(比例由逻辑统一管控),实际渲染会按比例自适应视口 by xu 20260115
  6844. previewWidth: { type: Number, default: 1000 },
  6845. previewHeight: { type: Number, default: 650 },
  6846. },
  6847. setup(props) {
  6848. const triggerRef = Vue.ref(null);
  6849. const fullscreenRef = Vue.ref(null);
  6850. const open = Vue.ref(false);
  6851. const pinned = Vue.ref(false);
  6852. const fullscreen = Vue.ref(false);
  6853. const hoveringTrigger = Vue.ref(false);
  6854. const hoveringPreview = Vue.ref(false);
  6855. const previewStyle = Vue.ref({});
  6856. let closeTimer = null;
  6857. const updatePreviewPosition = () => {
  6858. const el = triggerRef.value;
  6859. if (!el) return;
  6860. const rect = el.getBoundingClientRect();
  6861. // 功能说明:优先使用 visualViewport(避免浏览器 UI/缩放导致可视区与 innerHeight 偏差,出现预览被遮挡约 70px) by xu 20260116
  6862. const docEl = document.documentElement;
  6863. const vv = window.visualViewport;
  6864. let viewportLeft = Number(vv?.offsetLeft ?? 0) || 0;
  6865. let viewportTop = Number(vv?.offsetTop ?? 0) || 0;
  6866. let vw =
  6867. Number(vv?.width ?? 0) ||
  6868. Number(docEl?.clientWidth || 0) ||
  6869. window.innerWidth;
  6870. let vh =
  6871. Number(vv?.height ?? 0) ||
  6872. Number(docEl?.clientHeight || 0) ||
  6873. window.innerHeight;
  6874. // 功能说明:若页面在 iframe 内,父页面可能裁切 iframe 可见区域(overflow/弹窗容器),需要用“iframe可见区域”做二次约束 by xu 20260116
  6875. try {
  6876. const inIframe = window.top && window.top !== window;
  6877. const frameEl = window.frameElement;
  6878. if (inIframe && frameEl && window.top?.document) {
  6879. const topVv = window.top.visualViewport;
  6880. const topDocEl = window.top.document.documentElement;
  6881. const topVw =
  6882. Number(topVv?.width ?? 0) ||
  6883. Number(topDocEl?.clientWidth || 0) ||
  6884. window.top.innerWidth;
  6885. const topVh =
  6886. Number(topVv?.height ?? 0) ||
  6887. Number(topDocEl?.clientHeight || 0) ||
  6888. window.top.innerHeight;
  6889. const fr = frameEl.getBoundingClientRect?.();
  6890. if (fr && fr.width > 0 && fr.height > 0) {
  6891. const visibleW = Math.max(
  6892. 0,
  6893. Math.min(fr.right, topVw) - Math.max(fr.left, 0)
  6894. );
  6895. const visibleH = Math.max(
  6896. 0,
  6897. Math.min(fr.bottom, topVh) - Math.max(fr.top, 0)
  6898. );
  6899. if (visibleW > 0) {
  6900. vw = Math.min(vw, visibleW);
  6901. viewportLeft = Math.max(0, -fr.left); // iframe内坐标系偏移(左侧被裁切时) by xu 20260116
  6902. }
  6903. if (visibleH > 0) {
  6904. vh = Math.min(vh, visibleH);
  6905. viewportTop = Math.max(0, -fr.top); // iframe内坐标系偏移(顶部被裁切时) by xu 20260116
  6906. }
  6907. }
  6908. }
  6909. } catch (_) {}
  6910. // 预览窗尺寸:优先保证“完整可见”,其次再尽量对齐右侧 header 顶部 by xu 20260116
  6911. const viewportPaddingX = 40;
  6912. const viewportPaddingTop = 20;
  6913. const viewportPaddingBottom = 10;
  6914. // 功能说明:hover 预览框不要覆盖右侧栏,优先放在 ss-sidebar 左侧;必要时动态缩小宽度 by xu 20260115
  6915. const sidebarEl = el.closest ? el.closest(".ss-sidebar") : null;
  6916. const sidebarRect = sidebarEl?.getBoundingClientRect?.();
  6917. const maxWidthByViewport = Math.max(240, vw - viewportPaddingX);
  6918. const maxWidthByLeftSpace = sidebarRect
  6919. ? Math.max(
  6920. 240,
  6921. sidebarRect.left - viewportPaddingX - 14 /* gapFromSidebar */
  6922. )
  6923. : maxWidthByViewport;
  6924. // 功能说明:预览框尺寸按比例(默认 5:3)缩放,并提供最大/最小值约束 by xu 20260115
  6925. const ratio = 3 / 5;
  6926. const minWidth = 320;
  6927. const minHeight = 240;
  6928. const maxHeightByViewport = Math.max(
  6929. minHeight,
  6930. vh - viewportPaddingTop - viewportPaddingBottom
  6931. );
  6932. const maxWidthByProp = Number(props.previewWidth) || 1000;
  6933. const maxHeightByProp = Number(props.previewHeight) || 650;
  6934. // 优先按高度撑满可视区(保证预览完整可见),再根据左侧可用宽度回退 by xu 20260116
  6935. const maxHeight = Math.min(maxHeightByProp, maxHeightByViewport);
  6936. let height = Math.max(minHeight, maxHeight);
  6937. let width = Math.round(height / ratio);
  6938. width = Math.min(
  6939. width,
  6940. maxWidthByProp,
  6941. maxWidthByViewport,
  6942. maxWidthByLeftSpace
  6943. );
  6944. width = Math.max(minWidth, width);
  6945. height = Math.round(width * ratio);
  6946. if (height > maxHeight) {
  6947. height = maxHeight;
  6948. width = Math.round(height / ratio);
  6949. }
  6950. // 默认贴着小图左侧弹出,右边缘与小图左边缘轻微重叠,避免 1px 缝隙导致 hover 闪断 by xu 20260108
  6951. const overlap = 2;
  6952. const gapFromSidebar = 14; // 功能说明:弹窗与右侧边栏留出距离(更不贴近) by xu 20260108
  6953. // 优先:贴在 sidebar 左侧(不压住右侧栏内容) by xu 20260115
  6954. let left = sidebarRect
  6955. ? sidebarRect.left - gapFromSidebar - width + overlap
  6956. : rect.left - width - gapFromSidebar + overlap;
  6957. // 如果左侧空间不足,则贴右侧(兜底,同样重叠) by xu 20260108
  6958. if (left < 0) left = rect.right + gapFromSidebar - overlap;
  6959. left = Math.max(
  6960. viewportLeft,
  6961. Math.min(left, viewportLeft + vw - width)
  6962. );
  6963. // top:优先保证完整可见,然后才贴近 header 顶部 by xu 20260116
  6964. let headerEl = el;
  6965. while (headerEl && !headerEl.classList?.contains("ss-sidebar-panel")) {
  6966. headerEl = headerEl.parentElement;
  6967. }
  6968. let headerRect = headerEl
  6969. ?.querySelector(".ss-sidebar-panel__header")
  6970. ?.getBoundingClientRect();
  6971. let top = headerRect?.top ?? rect.top;
  6972. top = Math.max(
  6973. viewportTop + viewportPaddingTop,
  6974. Math.min(top, viewportTop + vh - height - viewportPaddingBottom)
  6975. );
  6976. previewStyle.value = {
  6977. position: "fixed",
  6978. left: `${Math.round(left)}px`,
  6979. top: `${Math.round(top)}px`,
  6980. width: `${width}px`,
  6981. height: `${height}px`,
  6982. zIndex: 2147483647, // 功能说明:提高层级到接近浏览器上限,避免仍被页面固定栏/弹窗遮挡 by xu 20260116
  6983. };
  6984. };
  6985. const clearCloseTimer = () => {
  6986. if (closeTimer) {
  6987. clearTimeout(closeTimer);
  6988. closeTimer = null;
  6989. }
  6990. };
  6991. const scheduleClose = () => {
  6992. clearCloseTimer();
  6993. if (pinned.value || fullscreen.value) return;
  6994. if (hoveringTrigger.value || hoveringPreview.value) return; // 功能:鼠标在小图/大图之间移动不关闭 by xu 20260108
  6995. closeTimer = setTimeout(() => {
  6996. open.value = false;
  6997. }, 100);
  6998. };
  6999. const openPreview = () => {
  7000. clearCloseTimer();
  7001. updatePreviewPosition();
  7002. open.value = true;
  7003. };
  7004. const togglePin = () => {
  7005. pinned.value = !pinned.value;
  7006. if (pinned.value) {
  7007. open.value = true;
  7008. updatePreviewPosition();
  7009. }
  7010. };
  7011. const toggleFullscreen = () => {
  7012. // 全屏:采用浏览器 Fullscreen API(方案A),不使用遮罩弹窗 by xu 20260108
  7013. if (!fullscreen.value) {
  7014. open.value = false; // 避免同时渲染预览与全屏 by xu 20260108
  7015. fullscreen.value = true;
  7016. Vue.nextTick(() => {
  7017. const el = fullscreenRef.value;
  7018. if (el?.requestFullscreen) {
  7019. el.requestFullscreen().catch(() => {
  7020. // requestFullscreen 失败则回退为非全屏状态 by xu 20260108
  7021. fullscreen.value = false;
  7022. });
  7023. } else {
  7024. fullscreen.value = false;
  7025. }
  7026. });
  7027. } else {
  7028. if (document?.exitFullscreen) {
  7029. document.exitFullscreen().catch(() => {});
  7030. }
  7031. }
  7032. };
  7033. const handleFullscreenChange = () => {
  7034. const isFs = !!document.fullscreenElement;
  7035. fullscreen.value = isFs; // 功能说明:同步 ESC/系统退出全屏状态 by xu 20260108
  7036. if (isFs) {
  7037. open.value = false;
  7038. clearCloseTimer();
  7039. return;
  7040. }
  7041. // 退出全屏后:若固定或仍 hover,则恢复预览,否则关闭 by xu 20260108
  7042. if (pinned.value || hoveringTrigger.value || hoveringPreview.value) {
  7043. open.value = true;
  7044. updatePreviewPosition();
  7045. } else {
  7046. open.value = false;
  7047. }
  7048. };
  7049. Vue.onMounted(() => {
  7050. window.addEventListener("resize", updatePreviewPosition);
  7051. window.addEventListener("scroll", updatePreviewPosition, true);
  7052. document.addEventListener("fullscreenchange", handleFullscreenChange); // 功能说明:监听全屏状态变化 by xu 20260108
  7053. });
  7054. Vue.onBeforeUnmount(() => {
  7055. clearCloseTimer();
  7056. window.removeEventListener("resize", updatePreviewPosition);
  7057. window.removeEventListener("scroll", updatePreviewPosition, true);
  7058. document.removeEventListener(
  7059. "fullscreenchange",
  7060. handleFullscreenChange
  7061. );
  7062. });
  7063. return {
  7064. triggerRef,
  7065. fullscreenRef,
  7066. open,
  7067. pinned,
  7068. fullscreen,
  7069. hoveringTrigger,
  7070. hoveringPreview,
  7071. previewStyle,
  7072. openPreview,
  7073. scheduleClose,
  7074. clearCloseTimer,
  7075. togglePin,
  7076. toggleFullscreen,
  7077. };
  7078. },
  7079. render() {
  7080. const SsIcon = Vue.resolveComponent("ss-icon");
  7081. const Chart = Vue.resolveComponent("ss-sidebar-chart");
  7082. const hasHeader = !!(this.title || this.iconClass || this.icon); // 功能:hover 大图显示左侧图标+标题 by xu 20260108
  7083. const previewContent = Vue.h(
  7084. "div",
  7085. {
  7086. class: { "ss-sidebar-chart-preview": true, "is-pinned": this.pinned },
  7087. style: this.previewStyle,
  7088. onMouseenter: () => {
  7089. this.hoveringPreview = true;
  7090. this.clearCloseTimer();
  7091. },
  7092. onMouseleave: () => {
  7093. this.hoveringPreview = false;
  7094. this.scheduleClose();
  7095. },
  7096. },
  7097. [
  7098. hasHeader
  7099. ? Vue.h(
  7100. "div",
  7101. {
  7102. class:
  7103. "ss-sidebar-panel__header ss-sidebar-chart-preview__header",
  7104. },
  7105. [
  7106. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7107. this.iconClass
  7108. ? Vue.h(SsIcon, {
  7109. class: this.iconClass + " ss-sidebar-panel__icon",
  7110. })
  7111. : this.icon
  7112. ? Vue.h(SsIcon, {
  7113. name: this.icon,
  7114. size: "16px",
  7115. class: "ss-sidebar-panel__icon",
  7116. })
  7117. : null,
  7118. Vue.h("span", null, this.title || "统计图"),
  7119. ]),
  7120. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7121. Vue.h(
  7122. "button",
  7123. {
  7124. type: "button",
  7125. class: {
  7126. "ss-sidebar-chart-tool": true,
  7127. "is-active": this.pinned,
  7128. },
  7129. title: this.pinned ? "取消固定" : "固定",
  7130. onClick: (e) => {
  7131. e.stopPropagation();
  7132. this.togglePin();
  7133. },
  7134. },
  7135. // 功能说明:右侧栏 hover 工具图标使用 ss-sidebar-base-icon(不复用左侧 menu-base-icon) by xu 20260123
  7136. [
  7137. Vue.h(SsIcon, {
  7138. class: this.pinned
  7139. ? "ss-sidebar-base-icon icon-fix-bold"
  7140. : "ss-sidebar-base-icon icon-fix",
  7141. }),
  7142. ]
  7143. ),
  7144. Vue.h(
  7145. "button",
  7146. {
  7147. type: "button",
  7148. class: "ss-sidebar-chart-tool",
  7149. title: "全屏",
  7150. onClick: (e) => {
  7151. e.stopPropagation();
  7152. this.toggleFullscreen();
  7153. },
  7154. },
  7155. [
  7156. Vue.h(SsIcon, {
  7157. class: this.fullscreen
  7158. ? "ss-sidebar-base-icon icon-fs-exit"
  7159. : "ss-sidebar-base-icon icon-fs",
  7160. }),
  7161. ]
  7162. ),
  7163. ]),
  7164. ]
  7165. )
  7166. : Vue.h(
  7167. "div",
  7168. {
  7169. class:
  7170. "ss-sidebar-chart-preview__header ss-sidebar-chart-preview__header--simple",
  7171. },
  7172. [
  7173. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7174. Vue.h(
  7175. "button",
  7176. {
  7177. type: "button",
  7178. class: {
  7179. "ss-sidebar-chart-tool": true,
  7180. "is-active": this.pinned,
  7181. },
  7182. title: this.pinned ? "取消固定" : "固定",
  7183. onClick: (e) => {
  7184. e.stopPropagation();
  7185. this.togglePin();
  7186. },
  7187. },
  7188. [
  7189. Vue.h(SsIcon, {
  7190. class: this.pinned
  7191. ? "ss-sidebar-base-icon icon-fix-bold"
  7192. : "ss-sidebar-base-icon icon-fix",
  7193. }),
  7194. ]
  7195. ),
  7196. Vue.h(
  7197. "button",
  7198. {
  7199. type: "button",
  7200. class: "ss-sidebar-chart-tool",
  7201. title: "全屏",
  7202. onClick: (e) => {
  7203. e.stopPropagation();
  7204. this.toggleFullscreen();
  7205. },
  7206. },
  7207. [
  7208. Vue.h(SsIcon, {
  7209. class: this.fullscreen
  7210. ? "ss-sidebar-base-icon icon-chk-on"
  7211. : "ss-sidebar-base-icon icon-chk",
  7212. }),
  7213. ]
  7214. ),
  7215. ]),
  7216. ]
  7217. ),
  7218. Vue.h("div", { class: "ss-sidebar-chart-preview__body" }, [
  7219. Vue.h(Chart, { options: this.options, height: "100%" }),
  7220. ]),
  7221. ]
  7222. );
  7223. const fullscreenContent =
  7224. this.fullscreen &&
  7225. Vue.h(
  7226. "div",
  7227. {
  7228. ref: "fullscreenRef",
  7229. class: "ss-sidebar-chart-fullscreen",
  7230. },
  7231. [
  7232. Vue.h(
  7233. "div",
  7234. {
  7235. class:
  7236. "ss-sidebar-panel__header ss-sidebar-chart-fullscreen__header",
  7237. },
  7238. [
  7239. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7240. this.iconClass
  7241. ? Vue.h(SsIcon, {
  7242. class: this.iconClass + " ss-sidebar-panel__icon",
  7243. })
  7244. : this.icon
  7245. ? Vue.h(SsIcon, {
  7246. name: this.icon,
  7247. size: "16px",
  7248. class: "ss-sidebar-panel__icon",
  7249. })
  7250. : null,
  7251. Vue.h("span", null, this.title || "统计图"),
  7252. ]),
  7253. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7254. Vue.h(
  7255. "button",
  7256. {
  7257. type: "button",
  7258. class: {
  7259. "ss-sidebar-chart-tool": true,
  7260. "is-active": this.pinned,
  7261. },
  7262. title: this.pinned ? "取消固定" : "固定",
  7263. onClick: (e) => {
  7264. e.stopPropagation();
  7265. this.togglePin();
  7266. },
  7267. },
  7268. [
  7269. Vue.h(SsIcon, {
  7270. class: this.pinned
  7271. ? "ss-sidebar-base-icon icon-fix-bold"
  7272. : "ss-sidebar-base-icon icon-fix",
  7273. }),
  7274. ]
  7275. ),
  7276. Vue.h(
  7277. "button",
  7278. {
  7279. type: "button",
  7280. class: "ss-sidebar-chart-tool",
  7281. title: "退出全屏",
  7282. onClick: (e) => {
  7283. e.stopPropagation();
  7284. this.toggleFullscreen();
  7285. },
  7286. },
  7287. [
  7288. Vue.h(SsIcon, {
  7289. class: "ss-sidebar-base-icon icon-fs-exit",
  7290. }),
  7291. ]
  7292. ),
  7293. ]),
  7294. ]
  7295. ),
  7296. Vue.h("div", { class: "ss-sidebar-chart-fullscreen__body" }, [
  7297. Vue.h(Chart, { options: this.options, height: "100%" }),
  7298. ]),
  7299. ]
  7300. );
  7301. return Vue.h("div", { class: "ss-sidebar-chart-hover" }, [
  7302. Vue.h(
  7303. "div",
  7304. {
  7305. ref: "triggerRef",
  7306. class: "ss-sidebar-chart-hover__trigger",
  7307. onMouseenter: () => {
  7308. this.hoveringTrigger = true;
  7309. this.openPreview();
  7310. },
  7311. onMouseleave: () => {
  7312. this.hoveringTrigger = false;
  7313. this.scheduleClose();
  7314. },
  7315. },
  7316. [Vue.h(Chart, { options: this.options, height: this.height })]
  7317. ),
  7318. (this.open || this.fullscreen) &&
  7319. Vue.h(Vue.Teleport, { to: "body" }, [
  7320. this.open ? previewContent : null,
  7321. fullscreenContent || null,
  7322. ]),
  7323. ]);
  7324. },
  7325. };
  7326. // 组件文档补全(JSDoc) by xu 20260108
  7327. /**
  7328. * SsSidebarList(右侧业务面板:人员/已选/服务/预定...)
  7329. *
  7330. * 用途:
  7331. * - 统一渲染面板 header(图标/标题/数量/右侧按钮)
  7332. * - 统一渲染 list(固定行高、hover、右侧移除按钮等)
  7333. *
  7334. * 调用示例(由 ss-sidebar 通过 panels 配置驱动):
  7335. * ```js
  7336. * { type:'list', title:'已选', iconClass:'menu-icon icon-obj-xcd', mode:'selected', items:selectedItems, closable:true }
  7337. * ```
  7338. *
  7339. * Props(核心):
  7340. * - `title`:header 标题
  7341. * - `iconClass/icon`:header 图标(优先 iconClass)
  7342. * - `count`:数量回显(图表面板可不传)
  7343. * - `closable`:是否显示“清空”按钮(触发 emit clear)
  7344. * - `headerFilters`:header 条件数组(组件名 + props),用于联调接口搜索
  7345. * - `headerSearchButton`:是否显示搜索按钮(触发 emit search)
  7346. * - `items`:列表数据
  7347. * - `mode`:`selected` 时右侧按钮语义为“移除”
  7348. * - `itemLayout`:`simple` / `person`(人员号槽位)
  7349. * - `itemAction`:是否显示 item 右侧操作按钮(hover 才出现)
  7350. *
  7351. * Emits:
  7352. * - `remove(item)`:点击 item 右侧移除
  7353. * - `clear()`:点击 header 清空
  7354. * - `search({keyword, filters})`:点击 header 搜索
  7355. */
  7356. const SsSidebarList = {
  7357. name: "SsSidebarList",
  7358. props: {
  7359. title: { type: String, default: "" },
  7360. // header 图标:优先使用 iconClass(走 ss-icon v3.0 class 分支) by xu 20260106
  7361. iconClass: { type: String, default: "" },
  7362. icon: { type: String, default: "" }, // 兼容旧写法(ss-icon name)
  7363. count: { type: [Number, String], default: "" },
  7364. // 选中类分区:右侧关闭按钮=清空分区数据 by xu 20260106
  7365. closable: { type: Boolean, default: false },
  7366. searchable: { type: Boolean, default: false },
  7367. // 搜索框是否放在 header 内(人员块需要该布局) by xu 20260106
  7368. searchInHeader: { type: Boolean, default: false },
  7369. // header 搜索:下拉条件 + 搜索按钮(适合“人员”块) by xu 20260106
  7370. headerFilters: { type: Array, default: () => [] },
  7371. headerSearchButton: { type: Boolean, default: false },
  7372. searchPlaceholder: { type: String, default: "搜索" },
  7373. // 列表项布局:simple(仅标题) / person(标题+人员号槽位) by xu 20260106
  7374. itemLayout: { type: String, default: "simple" },
  7375. itemAction: { type: Boolean, default: true },
  7376. collapsible: { type: Boolean, default: true }, // 功能说明:是否允许双击 header 折叠/展开 by xu 20260116
  7377. collapsed: { type: Boolean, default: false }, // 功能说明:折叠态仅展示 header by xu 20260116
  7378. items: { type: Array, default: () => [] },
  7379. mode: { type: String, default: "search" }, // search / selected
  7380. },
  7381. emits: ["select", "remove", "clear", "search", "toggle-collapse"],
  7382. data() {
  7383. return {
  7384. keyword: "",
  7385. filterValues: {},
  7386. }; // 功能说明:折叠状态完全由 props.collapsed 驱动,避免多面板复用导致状态不同步 by xu 20260116
  7387. },
  7388. created() {
  7389. // header 下拉条件默认值初始化 by xu 20260106
  7390. (this.headerFilters || []).forEach((f) => {
  7391. if (!f || !f.key) return;
  7392. if (this.filterValues[f.key] !== undefined) return;
  7393. const first = f?.options?.[0]?.value ?? "";
  7394. this.filterValues[f.key] = f.value !== undefined ? f.value : first;
  7395. });
  7396. },
  7397. methods: {
  7398. __shouldIgnoreHeaderToggle(e) {
  7399. // 功能说明:忽略工具区/输入区触发折叠,避免误触 by xu 20260116
  7400. const t = e?.target;
  7401. if (!t || !t.closest) return false;
  7402. if (t.closest(".ss-sidebar-panel__tools")) return true;
  7403. if (t.closest(".ss-sidebar-panel__filters")) return true;
  7404. if (t.closest("input,textarea,select,button")) return true;
  7405. return false;
  7406. },
  7407. __toggleCollapseInternal(e, source) {
  7408. if (!this.collapsible) return;
  7409. if (this.__shouldIgnoreHeaderToggle(e)) return;
  7410. const nextCollapsed = !this.collapsed;
  7411. console.log("[SsSidebarList] toggle emit", {
  7412. title: this.title,
  7413. source,
  7414. to: nextCollapsed,
  7415. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7416. // 功能说明:由父组件(SsSidebar.toggleSectionCollapse)统一控制 section 高度与折叠数组 by xu 20260116
  7417. this.$emit("toggle-collapse");
  7418. },
  7419. },
  7420. render() {
  7421. const items = this.items || [];
  7422. const SsIcon = Vue.resolveComponent("ss-icon");
  7423. const isSelectedMode = this.mode === "selected";
  7424. const activeKeyword = this.filterValues?.keyword ?? this.keyword; // 功能:keyword 优先取 headerFilters.keyword by xu 20260106
  7425. const hasHeaderKeyword = (this.headerFilters || []).some(
  7426. (f) => f?.key === "keyword"
  7427. ); // 功能:header 内 keyword 过滤 by xu 20260106
  7428. const renderHeaderFilter = (f) => {
  7429. if (!f) return null;
  7430. const key = f.key;
  7431. const componentName = f.component;
  7432. if (!key || !componentName) return null;
  7433. const Comp = Vue.resolveComponent(componentName);
  7434. if (!Comp) return null;
  7435. const modelValue = this.filterValues[key];
  7436. const props = f.props || {};
  7437. return Vue.h(Comp, {
  7438. ...props,
  7439. modelValue,
  7440. "onUpdate:modelValue": (v) => {
  7441. this.filterValues[key] = v;
  7442. },
  7443. });
  7444. };
  7445. const filteredItems =
  7446. this.searchable && activeKeyword
  7447. ? items.filter((it) =>
  7448. String(it?.title ?? "")
  7449. .toLowerCase()
  7450. .includes(String(activeKeyword).toLowerCase())
  7451. )
  7452. : items;
  7453. if (!filteredItems.length && !this.title) return null;
  7454. if (this.collapsed) {
  7455. return Vue.h("div", { class: "ss-sidebar-panel" }, [
  7456. this.title
  7457. ? Vue.h(
  7458. "div",
  7459. {
  7460. class: "ss-sidebar-panel__header",
  7461. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  7462. onDblclick: (e) => {
  7463. e?.preventDefault?.();
  7464. e?.stopPropagation?.();
  7465. console.log("[SsSidebarList] header dblclick", {
  7466. title: this.title,
  7467. collapsed: true,
  7468. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7469. this.__toggleCollapseInternal(e, "dblclick");
  7470. },
  7471. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  7472. },
  7473. [
  7474. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7475. this.iconClass
  7476. ? Vue.h(SsIcon, {
  7477. class: this.iconClass + " ss-sidebar-panel__icon",
  7478. })
  7479. : this.icon
  7480. ? Vue.h(SsIcon, {
  7481. name: this.icon,
  7482. size: "16px",
  7483. class: "ss-sidebar-panel__icon",
  7484. })
  7485. : null,
  7486. Vue.h("span", null, this.title),
  7487. this.count !== ""
  7488. ? Vue.h(
  7489. "span",
  7490. { class: "ss-sidebar-panel__count" },
  7491. `(${this.count})`
  7492. )
  7493. : null,
  7494. ]),
  7495. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7496. this.closable
  7497. ? Vue.h(
  7498. "button",
  7499. {
  7500. type: "button",
  7501. class: "ss-sidebar-icon-btn ss-sidebar-header-btn",
  7502. title: "清空",
  7503. onClick: (e) => {
  7504. e.stopPropagation();
  7505. this.$emit("clear");
  7506. },
  7507. },
  7508. [
  7509. Vue.h(SsIcon, {
  7510. class: "ss-sidebar-base-icon icon-cl",
  7511. }),
  7512. ] // 功能说明:右侧栏“已选”清空按钮图标使用 ss-sidebar-base-icon by xu 20260123
  7513. )
  7514. : null,
  7515. ]),
  7516. ]
  7517. )
  7518. : null,
  7519. ]);
  7520. }
  7521. return Vue.h("div", { class: "ss-sidebar-panel" }, [
  7522. this.title
  7523. ? Vue.h(
  7524. "div",
  7525. {
  7526. class: "ss-sidebar-panel__header",
  7527. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  7528. onDblclick: (e) => {
  7529. e?.preventDefault?.();
  7530. e?.stopPropagation?.();
  7531. console.log("[SsSidebarList] header dblclick", {
  7532. title: this.title,
  7533. collapsed: false,
  7534. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7535. this.__toggleCollapseInternal(e, "dblclick");
  7536. },
  7537. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  7538. },
  7539. [
  7540. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7541. // 图标 + 标题(每个分区都有) by xu 20260106
  7542. this.iconClass
  7543. ? Vue.h(SsIcon, {
  7544. class: this.iconClass + " ss-sidebar-panel__icon",
  7545. })
  7546. : this.icon
  7547. ? Vue.h(SsIcon, {
  7548. name: this.icon,
  7549. size: "16px",
  7550. class: "ss-sidebar-panel__icon",
  7551. })
  7552. : null,
  7553. Vue.h("span", null, this.title),
  7554. // 数量回显:图表分区可不传 count by xu 20260106
  7555. this.count !== ""
  7556. ? Vue.h(
  7557. "span",
  7558. { class: "ss-sidebar-panel__count" },
  7559. `(${this.count})`
  7560. )
  7561. : null,
  7562. ]),
  7563. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7564. // header 条件(例如下拉框)+ 右侧搜索按钮 by xu 20260106
  7565. this.headerFilters?.length
  7566. ? Vue.h(
  7567. "div",
  7568. { class: "ss-sidebar-panel__filters" },
  7569. this.headerFilters
  7570. .map(renderHeaderFilter)
  7571. .filter(Boolean)
  7572. )
  7573. : null,
  7574. this.headerSearchButton
  7575. ? Vue.h(
  7576. "button",
  7577. {
  7578. type: "button",
  7579. class: "ss-sidebar-icon-btn",
  7580. title: "搜索",
  7581. onClick: (e) => {
  7582. e.stopPropagation();
  7583. this.$emit("search", {
  7584. // headerFilters 内也可能包含 keyword by xu 20260106
  7585. keyword: activeKeyword,
  7586. filters: { ...(this.filterValues || {}) },
  7587. });
  7588. },
  7589. },
  7590. [Vue.h(SsIcon, { name: "search", size: "14px" })]
  7591. )
  7592. : null,
  7593. // 人员块:搜索框在 header 内 by xu 20260106
  7594. this.searchable &&
  7595. this.searchInHeader &&
  7596. !this.headerSearchButton
  7597. ? Vue.h(
  7598. "div",
  7599. { class: "ss-sidebar-panel__searchInline" },
  7600. [
  7601. Vue.h(
  7602. "div",
  7603. { class: "ss-sidebar-search is-inline" },
  7604. [
  7605. Vue.h(SsIcon, {
  7606. name: "search",
  7607. size: "14px",
  7608. class: "ss-sidebar-search__prefix",
  7609. }),
  7610. Vue.h("input", {
  7611. class: "ss-sidebar-search__input",
  7612. value: this.keyword,
  7613. placeholder: this.searchPlaceholder,
  7614. onInput: (e) => {
  7615. this.keyword = e?.target?.value ?? "";
  7616. },
  7617. }),
  7618. ]
  7619. ),
  7620. ]
  7621. )
  7622. : null,
  7623. this.closable
  7624. ? Vue.h(
  7625. "button",
  7626. {
  7627. type: "button",
  7628. class: "ss-sidebar-icon-btn ss-sidebar-header-btn",
  7629. title: "清空",
  7630. onClick: (e) => {
  7631. e.stopPropagation();
  7632. this.$emit("clear");
  7633. },
  7634. },
  7635. // 清空按钮使用 icon-base 的 icon-cl by xu 20260106
  7636. [
  7637. Vue.h(SsIcon, {
  7638. class: "ss-sidebar-base-icon icon-cl",
  7639. }),
  7640. ] // 功能说明:右侧栏清空按钮图标使用 ss-sidebar-base-icon by xu 20260123
  7641. )
  7642. : null,
  7643. ]),
  7644. ]
  7645. )
  7646. : null,
  7647. // 非 header 内搜索:独立一行 by xu 20260106
  7648. // headerSearchButton/headerFilters 已覆盖搜索能力时,不再额外渲染独立搜索行 by xu 20260106
  7649. this.searchable &&
  7650. !this.searchInHeader &&
  7651. !this.headerSearchButton &&
  7652. !hasHeaderKeyword
  7653. ? Vue.h("div", { class: "ss-sidebar-panel__search" }, [
  7654. Vue.h("div", { class: "ss-sidebar-search" }, [
  7655. Vue.h(SsIcon, {
  7656. name: "search",
  7657. size: "14px",
  7658. class: "ss-sidebar-search__prefix",
  7659. }),
  7660. Vue.h("input", {
  7661. class: "ss-sidebar-search__input",
  7662. value: this.keyword,
  7663. placeholder: this.searchPlaceholder,
  7664. onInput: (e) => {
  7665. this.keyword = e?.target?.value ?? "";
  7666. },
  7667. }),
  7668. ]),
  7669. ])
  7670. : null,
  7671. Vue.h(
  7672. "div",
  7673. { class: "ss-sidebar-list" },
  7674. filteredItems.map((item, idx) => {
  7675. const title = item?.title ?? "";
  7676. const tags = item?.tags || [];
  7677. const isPersonLayout = this.itemLayout === "person";
  7678. const hasTags = !isPersonLayout && tags?.length > 0; // 列表项垂直对齐:有 tags 顶对齐 by xu 20260106
  7679. return Vue.h(
  7680. "div",
  7681. {
  7682. class: {
  7683. "ss-sidebar-list-item": true,
  7684. "is-first": idx === 0,
  7685. "is-person": isPersonLayout,
  7686. "has-tags": hasTags,
  7687. },
  7688. },
  7689. [
  7690. Vue.h("div", { class: "ss-sidebar-list-item__main" }, [
  7691. Vue.h(
  7692. "div",
  7693. { class: "ss-sidebar-list-item__title" },
  7694. Vue.h(
  7695. "span",
  7696. {
  7697. style: {
  7698. "white-space": "nowrap",
  7699. overflow: "hidden",
  7700. "text-overflow": "ellipsis",
  7701. },
  7702. },
  7703. title
  7704. )
  7705. ),
  7706. // 非人员布局才显示 tags by xu 20260106
  7707. !isPersonLayout && tags?.length
  7708. ? Vue.h(
  7709. "div",
  7710. { class: "ss-sidebar-list-item__tags" },
  7711. tags.map((tag) => {
  7712. const [k, v] = Object.entries(tag)[0] || ["", ""];
  7713. return Vue.h(
  7714. "span",
  7715. { class: "ss-sidebar-tag", title: `${k}: ${v}` },
  7716. `${k}: ${v}`
  7717. );
  7718. })
  7719. )
  7720. : null,
  7721. ]),
  7722. // 人员布局:中间保留“人员号”槽位 by xu 20260106
  7723. isPersonLayout
  7724. ? Vue.h(
  7725. "div",
  7726. {
  7727. class: "ss-sidebar-list-item__meta",
  7728. title: String(item?.meta ?? ""),
  7729. },
  7730. item?.meta ?? ""
  7731. )
  7732. : null,
  7733. this.itemAction
  7734. ? Vue.h(
  7735. "button",
  7736. {
  7737. type: "button",
  7738. class: {
  7739. // item 操作按钮:默认无背景/无边框,hover 才高亮 by xu 20260106
  7740. "ss-sidebar-item-btn": true,
  7741. },
  7742. title: isSelectedMode ? "移除" : "选择",
  7743. onClick: (e) => {
  7744. e.stopPropagation();
  7745. if (isSelectedMode) this.$emit("remove", item);
  7746. else this.$emit("select", item);
  7747. },
  7748. },
  7749. [
  7750. // item 移除图标使用 icon-base 的 icon-cl by xu 20260106
  7751. isSelectedMode
  7752. ? Vue.h(SsIcon, {
  7753. class: "ss-sidebar-base-icon icon-cl",
  7754. }) // 功能说明:右侧栏 item 移除图标使用 ss-sidebar-base-icon by xu 20260123
  7755. : Vue.h(SsIcon, { name: "check", size: "14px" }),
  7756. ]
  7757. )
  7758. : null,
  7759. ]
  7760. );
  7761. })
  7762. ),
  7763. ]);
  7764. },
  7765. };
  7766. // ss-sidebar-report-table:右侧“统计表/报表”面板(pstatList grtjlbm=51 聚拢渲染) by xu 20260115
  7767. const SsSidebarReportTable = {
  7768. name: "SsSidebarReportTable",
  7769. props: {
  7770. title: { type: String, default: "" },
  7771. iconClass: { type: String, default: "" },
  7772. icon: { type: String, default: "" },
  7773. items: { type: Array, default: () => [] }, // pstatList(grtjlbm=51) 数组
  7774. onOpen: { type: Function, default: null }, // (srv, ctx) => void
  7775. collapsible: { type: Boolean, default: true }, // 功能说明:是否允许双击 header 折叠/展开 by xu 20260116
  7776. collapsed: { type: Boolean, default: false }, // 功能说明:折叠态仅展示 header by xu 20260116
  7777. },
  7778. emits: ["open", "toggle-collapse"],
  7779. data() {
  7780. return {}; // 功能说明:折叠状态完全由 props.collapsed 驱动 by xu 20260116
  7781. },
  7782. methods: {
  7783. __toggleCollapseInternal(e, source) {
  7784. if (!this.collapsible) return;
  7785. const next = !this.collapsed;
  7786. console.log("[SsSidebarReportTable] toggle emit", {
  7787. title: this.title,
  7788. source,
  7789. to: next,
  7790. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7791. this.$emit("toggle-collapse");
  7792. },
  7793. },
  7794. render() {
  7795. const SsIcon = Vue.resolveComponent("ss-icon");
  7796. const list = this.items || [];
  7797. if (!this.title && !list.length) return null;
  7798. const header = this.title
  7799. ? Vue.h(
  7800. "div",
  7801. {
  7802. class: "ss-sidebar-panel__header",
  7803. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  7804. onDblclick: (e) => {
  7805. e?.preventDefault?.();
  7806. e?.stopPropagation?.();
  7807. console.log("[SsSidebarReportTable] header dblclick", {
  7808. title: this.title,
  7809. collapsed: this.collapsed,
  7810. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7811. this.__toggleCollapseInternal(e, "dblclick");
  7812. },
  7813. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  7814. },
  7815. [
  7816. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7817. this.iconClass
  7818. ? Vue.h(SsIcon, {
  7819. class: this.iconClass + " ss-sidebar-panel__icon",
  7820. })
  7821. : this.icon
  7822. ? Vue.h(SsIcon, {
  7823. name: this.icon,
  7824. size: "16px",
  7825. class: "ss-sidebar-panel__icon",
  7826. })
  7827. : null,
  7828. Vue.h("span", null, this.title),
  7829. ]),
  7830. Vue.h("div", { class: "ss-sidebar-panel__tools" }),
  7831. ]
  7832. )
  7833. : null;
  7834. const renderReport = (report) => {
  7835. const title = String(report?.mc ?? "");
  7836. const mx = Array.isArray(report?.grtjmxList) ? report.grtjmxList : [];
  7837. if (!title && !mx.length) return null;
  7838. // 功能说明:每个报表对象渲染为一个 table(有边框、无圆角、表间距10px;样式由 base.css 统一控制) by xu 20260115
  7839. const cols = Math.max(1, mx.length);
  7840. // 功能说明:table 外层包一层 wrap,子项过多时支持横向滚动 by xu 20260115
  7841. return Vue.h("div", { class: "ss-sidebar-report-table-wrap" }, [
  7842. Vue.h("table", { class: "ss-sidebar-report-table" }, [
  7843. Vue.h("thead", null, [
  7844. Vue.h("tr", null, [
  7845. Vue.h(
  7846. "th",
  7847. { class: "ss-sidebar-report-table__title", colspan: cols },
  7848. Vue.h(
  7849. "div",
  7850. { class: "ss-sidebar-report-table__title-content" },
  7851. [
  7852. Vue.h("span", { class: "ss-sidebar-report-table__dot" }),
  7853. Vue.h(
  7854. "span",
  7855. { class: "ss-sidebar-report-table__title-text", title },
  7856. title
  7857. ),
  7858. ]
  7859. )
  7860. ),
  7861. ]),
  7862. ]),
  7863. Vue.h("tbody", null, [
  7864. Vue.h(
  7865. "tr",
  7866. null,
  7867. mx.map((cell) => {
  7868. const text = String(cell?.mc ?? "");
  7869. const srv = {
  7870. servName: cell?.fwm ?? "",
  7871. dest: cell?.bjm ?? "",
  7872. title: text,
  7873. width: cell?.width,
  7874. height: cell?.height,
  7875. minHeight: cell?.height,
  7876. maxHeight: cell?.height,
  7877. showTitle: text,
  7878. };
  7879. return Vue.h(
  7880. "td",
  7881. {
  7882. class: "ss-sidebar-report-table__cell",
  7883. title: text,
  7884. onClick: (e) => {
  7885. e?.stopPropagation?.();
  7886. try {
  7887. this.onOpen?.(srv, { report, cell });
  7888. } catch (_) {}
  7889. this.$emit("open", { report, cell, srv });
  7890. },
  7891. },
  7892. text
  7893. );
  7894. })
  7895. ),
  7896. ]),
  7897. ]),
  7898. ]);
  7899. };
  7900. // 功能说明:报表面板增加独立 class,便于 base.css 统一控制 padding/间距 by xu 20260115
  7901. return Vue.h(
  7902. "div",
  7903. { class: "ss-sidebar-panel ss-sidebar-report-panel" },
  7904. [
  7905. header,
  7906. this.collapsed
  7907. ? null
  7908. : Vue.h(
  7909. "div",
  7910. // 功能说明:报表列表滚动/高度样式下沉到 base.css,避免写在 DOM 上 by xu 20260115
  7911. { class: "ss-sidebar-report__list" },
  7912. list.map(renderReport).filter(Boolean)
  7913. ),
  7914. ]
  7915. );
  7916. },
  7917. };
  7918. // 组件文档补全(JSDoc) by xu 20260108
  7919. /**
  7920. * SsSidebar(objList 右侧边栏容器)
  7921. *
  7922. * 用途:
  7923. * - 统一渲染顶部按钮栏(buttons)
  7924. * - 统一渲染中间业务面板(list panels,可拖拽调高度)
  7925. * - 统一渲染底部图表(chart panels,内部用 ss-sidebar-chart-hover)
  7926. *
  7927. * 调用示例:
  7928. * ```html
  7929. * <ss-sidebar :buttons="sidebarButtons" :panels="sidebarPanels" @remove="handleSidebarRemove" />
  7930. * ```
  7931. *
  7932. * Props:
  7933. * - `buttons`:顶部按钮配置数组
  7934. * - `panels`:分区配置数组(`type: 'list' | 'chart'`)
  7935. *
  7936. * Events(向外透传):
  7937. * - `remove(item)`:来自 list 面板移除
  7938. * - `select(item)`:来自 list 面板选择(如后续需要)
  7939. */
  7940. const SsSidebar = {
  7941. name: "SsSidebar",
  7942. props: {
  7943. buttons: { type: Array, default: () => [] },
  7944. charts: { type: Array, default: () => [] },
  7945. list: { type: Array, default: () => [] }, // legacy
  7946. listMode: { type: String, default: "search" }, // legacy
  7947. panels: { type: Array, default: () => [] },
  7948. },
  7949. emits: ["select", "remove"],
  7950. data() {
  7951. return {
  7952. // 业务面板高度(索引 -> px) by xu 20260106
  7953. sectionHeights: [],
  7954. sectionCollapsed: [], // 功能说明:面板折叠状态(sectionPanels 索引) by xu 20260116
  7955. sectionHeightsExpanded: [], // 功能说明:面板展开高度缓存(用于折叠后恢复) by xu 20260116
  7956. sectionLastItemCounts: [], // 功能说明:记录栏目数据量,供“无数据默认关闭/已选自动展开”规则复用 by xu 20260313
  7957. chartCollapsed: [], // 功能说明:图表面板折叠状态(chartPanels 索引) by xu 20260116
  7958. chartHeaderTitleDownAt: [], // 功能说明:双击检测绑定到 chart 标题区 by xu 20260116
  7959. reportCollapsed: [], // 功能说明:报表面板折叠状态(reportPanels 索引) by xu 20260116
  7960. resizeTimer: null,
  7961. resizing: false,
  7962. resizeIndex: -1,
  7963. resizeStartY: 0,
  7964. resizeStartPrev: 0,
  7965. resizeStartNext: 0,
  7966. __resizeMoveHandler: null, // 功能说明:显式绑定 this 的 pointermove handler,避免 addEventListener 场景 this 丢失导致拖拽无效 by xu 20260122
  7967. __resizeEndHandler: null, // 功能说明:显式绑定 this 的 pointerup handler,确保能正确结束拖拽 by xu 20260122
  7968. __resizeCancelHandler: null, // 功能说明:显式绑定 this 的 pointercancel handler,触控取消也能收尾 by xu 20260122
  7969. __resizePrevSectionEl: null, // 功能说明:拖拽时直接写 DOM 高度(修复响应式更新不生效) by xu 20260122
  7970. __resizeNextSectionEl: null, // 功能说明:拖拽时直接写 DOM 高度(修复响应式更新不生效) by xu 20260122
  7971. };
  7972. },
  7973. methods: {
  7974. // 初始化默认高度(只在第一次/面板数量变化时补齐) by xu 20260106
  7975. ensureSectionHeights(sectionCount) {
  7976. if (!Array.isArray(this.sectionHeights)) this.sectionHeights = [];
  7977. if (this.sectionHeights.length === sectionCount) return;
  7978. const next = [];
  7979. for (let i = 0; i < sectionCount; i++) {
  7980. next[i] = this.sectionHeights[i] ?? 190; // 默认高度 by xu 20260106
  7981. }
  7982. this.sectionHeights = next;
  7983. // 功能说明:面板数量变化时补齐折叠/缓存数组长度 by xu 20260116
  7984. this.sectionCollapsed = Array.from(
  7985. { length: sectionCount },
  7986. (_, i) => !!this.sectionCollapsed?.[i]
  7987. );
  7988. this.sectionHeightsExpanded = Array.from(
  7989. { length: sectionCount },
  7990. (_, i) => this.sectionHeightsExpanded?.[i] ?? null
  7991. );
  7992. this.sectionLastItemCounts = Array.from(
  7993. { length: sectionCount },
  7994. (_, i) => Number(this.sectionLastItemCounts?.[i] ?? 0) || 0
  7995. );
  7996. },
  7997. __getPanelsForSectionState(panelsInput) {
  7998. return (panelsInput || []).length
  7999. ? panelsInput
  8000. : this.list?.length
  8001. ? [
  8002. {
  8003. type: "list",
  8004. title: "已选",
  8005. icon: "",
  8006. mode: this.listMode,
  8007. items: this.list,
  8008. },
  8009. ]
  8010. : [];
  8011. },
  8012. __getSectionPanelsForState(panelsInput) {
  8013. return this.__getPanelsForSectionState(panelsInput)
  8014. .filter((p) => {
  8015. const k = String(p?._tabKey ?? "")
  8016. .trim()
  8017. .toLowerCase();
  8018. const t = String(p?.title ?? "").trim();
  8019. if (k === "rbarobj") return false;
  8020. if (t === "对象") return false;
  8021. return true;
  8022. })
  8023. .filter((p) => p?.type !== "chart" && p?.type !== "report-table");
  8024. },
  8025. __getSectionPanelCount(panel) {
  8026. const explicitCount = Number(panel?.count);
  8027. if (Number.isFinite(explicitCount)) return explicitCount;
  8028. return Array.isArray(panel?.items) ? panel.items.length : 0;
  8029. },
  8030. __setSectionCollapsedState(index, collapsed) {
  8031. const i = Number(index);
  8032. if (isNaN(i) || i < 0) return;
  8033. const nextCollapsed = !!collapsed;
  8034. const collapsedHeight = 37;
  8035. const cur = !!this.sectionCollapsed?.[i];
  8036. const currentHeight = Number(this.sectionHeights?.[i] ?? 190) || 190;
  8037. if (nextCollapsed === cur) {
  8038. if (nextCollapsed && currentHeight !== collapsedHeight) {
  8039. this.sectionHeights.splice(i, 1, collapsedHeight);
  8040. }
  8041. return;
  8042. }
  8043. if (nextCollapsed) {
  8044. this.sectionHeightsExpanded[i] =
  8045. currentHeight > collapsedHeight
  8046. ? currentHeight
  8047. : Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  8048. this.sectionHeights.splice(i, 1, collapsedHeight);
  8049. } else {
  8050. const restore =
  8051. Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  8052. this.sectionHeights.splice(i, 1, restore);
  8053. }
  8054. this.sectionCollapsed.splice(i, 1, nextCollapsed);
  8055. },
  8056. __syncSectionAutoCollapse(panelsInput) {
  8057. const sectionPanels = this.__getSectionPanelsForState(panelsInput);
  8058. const sectionCount = sectionPanels.length;
  8059. this.ensureSectionHeights(sectionCount);
  8060. const prevCounts = Array.isArray(this.sectionLastItemCounts)
  8061. ? this.sectionLastItemCounts.slice()
  8062. : [];
  8063. const nextCounts = Array.from({ length: sectionCount }, (_, i) =>
  8064. this.__getSectionPanelCount(sectionPanels[i])
  8065. );
  8066. this.sectionLastItemCounts = nextCounts;
  8067. sectionPanels.forEach((panel, index) => {
  8068. const count = Number(nextCounts[index] ?? 0) || 0;
  8069. const prevCount = Number(prevCounts[index] ?? 0) || 0;
  8070. const title = String(panel?.title ?? "").trim();
  8071. if (count <= 0) {
  8072. this.__setSectionCollapsedState(index, true);
  8073. return;
  8074. }
  8075. if (title === "已选" && count > prevCount) {
  8076. this.__setSectionCollapsedState(index, false);
  8077. }
  8078. });
  8079. },
  8080. toggleSectionCollapse(index) {
  8081. // 功能说明:双击 header 折叠/展开 section 面板(仅控制高度与内容渲染) by xu 20260116
  8082. const i = Number(index);
  8083. if (isNaN(i) || i < 0) return;
  8084. // 功能说明:加更细粒度日志,定位“多面板折叠无视觉效果”的根因(高度是否真的变、DOM 是否更新) by xu 20260116
  8085. const collapsedHeight = 37; // 功能说明:header(35) + panel 边框(2),避免 flex shrink 导致 header 变 25px by xu 20260116
  8086. const cur = !!this.sectionCollapsed?.[i];
  8087. console.log("[SsSidebar] toggleSectionCollapse", {
  8088. index: i,
  8089. to: !cur,
  8090. prevHeight: this.sectionHeights?.[i],
  8091. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8092. if (!cur) {
  8093. this.sectionHeightsExpanded[i] = this.sectionHeights[i] ?? 190;
  8094. this.sectionHeights.splice(i, 1, collapsedHeight);
  8095. } else {
  8096. const restore =
  8097. Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  8098. this.sectionHeights.splice(i, 1, restore);
  8099. }
  8100. this.sectionCollapsed.splice(i, 1, !cur);
  8101. console.log("[SsSidebar] section state(after)", {
  8102. index: i,
  8103. height: this.sectionHeights?.[i],
  8104. collapsed: this.sectionCollapsed?.[i],
  8105. allHeights: Array.from(this.sectionHeights || []),
  8106. allCollapsed: Array.from(this.sectionCollapsed || []),
  8107. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8108. Vue.nextTick(() => {
  8109. try {
  8110. const root = this.$el;
  8111. const sections = root?.querySelectorAll?.(".ss-sidebar-section");
  8112. const el = sections?.[i];
  8113. const rectH = el?.getBoundingClientRect?.().height;
  8114. console.log("[SsSidebar] section dom(beforeFix)", {
  8115. index: i,
  8116. styleHeight: el?.style?.height,
  8117. rectH,
  8118. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8119. // 功能说明:若渲染未把 height patch 到 DOM,则在 nextTick 强制同步一次(并打印) by xu 20260116
  8120. const targetH =
  8121. (Number(this.sectionHeights?.[i] ?? 190) || 190) + "px";
  8122. if (el && el.style && el.style.height !== targetH) {
  8123. el.style.height = targetH;
  8124. }
  8125. if (el?.classList) {
  8126. el.classList.toggle("is-collapsed", !!this.sectionCollapsed?.[i]);
  8127. }
  8128. const rectAfter = el?.getBoundingClientRect?.().height;
  8129. console.log("[SsSidebar] section dom(afterFix)", {
  8130. index: i,
  8131. styleHeight: el?.style?.height,
  8132. rectH: rectAfter,
  8133. targetH,
  8134. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8135. } catch (err) {
  8136. console.log("[SsSidebar] section dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8137. }
  8138. });
  8139. },
  8140. toggleChartCollapse(index) {
  8141. // 功能说明:双击 header 折叠/展开底部 chart 面板(隐藏/显示 chart-hover) by xu 20260116
  8142. const i = Number(index);
  8143. if (isNaN(i) || i < 0) return;
  8144. const cur = !!this.chartCollapsed?.[i];
  8145. console.log("[SsSidebar] toggleChartCollapse", { index: i, to: !cur }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8146. this.chartCollapsed.splice(i, 1, !cur);
  8147. console.log("[SsSidebar] chart state(after)", {
  8148. index: i,
  8149. collapsed: this.chartCollapsed?.[i],
  8150. allCollapsed: Array.from(this.chartCollapsed || []),
  8151. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8152. Vue.nextTick(() => {
  8153. try {
  8154. const root = this.$el;
  8155. const el = root?.querySelector?.(
  8156. `.ss-sidebar-chart-panel[data-chart-idx="${i}"]`
  8157. );
  8158. console.log("[SsSidebar] chart dom(beforeFix)", {
  8159. index: i,
  8160. found: !!el,
  8161. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8162. if (el?.classList)
  8163. el.classList.toggle("is-collapsed", !!this.chartCollapsed?.[i]);
  8164. console.log("[SsSidebar] chart dom(afterFix)", {
  8165. index: i,
  8166. collapsed: !!this.chartCollapsed?.[i],
  8167. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8168. } catch (err) {
  8169. console.log("[SsSidebar] chart dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8170. }
  8171. });
  8172. },
  8173. toggleReportCollapse(index) {
  8174. // 功能说明:双击 header 折叠/展开底部 report-table 面板(隐藏/显示表格) by xu 20260116
  8175. const i = Number(index);
  8176. if (isNaN(i) || i < 0) return;
  8177. const cur = !!this.reportCollapsed?.[i];
  8178. console.log("[SsSidebar] toggleReportCollapse", { index: i, to: !cur }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8179. this.reportCollapsed.splice(i, 1, !cur);
  8180. console.log("[SsSidebar] report state(after)", {
  8181. index: i,
  8182. collapsed: this.reportCollapsed?.[i],
  8183. allCollapsed: Array.from(this.reportCollapsed || []),
  8184. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8185. Vue.nextTick(() => {
  8186. try {
  8187. const root = this.$el;
  8188. const el = root?.querySelector?.(
  8189. `.ss-sidebar-report-panel[data-report-idx="${i}"]`
  8190. );
  8191. console.log("[SsSidebar] report dom(beforeFix)", {
  8192. index: i,
  8193. found: !!el,
  8194. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8195. if (el?.classList)
  8196. el.classList.toggle("is-collapsed", !!this.reportCollapsed?.[i]);
  8197. console.log("[SsSidebar] report dom(afterFix)", {
  8198. index: i,
  8199. collapsed: !!this.reportCollapsed?.[i],
  8200. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8201. } catch (err) {
  8202. console.log("[SsSidebar] report dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8203. }
  8204. });
  8205. },
  8206. startResize(index, e) {
  8207. if (e?.preventDefault) e.preventDefault();
  8208. if (e?.stopPropagation) e.stopPropagation();
  8209. if (this.resizing) return;
  8210. // 长按 0.5s 后才进入拖拽调高度 by xu 20260106
  8211. clearTimeout(this.resizeTimer);
  8212. // 功能说明:修复“长按拖拽偶发失效/卡死”——pointerup 早于 500ms 时必须取消 timer,否则 timer 触发后进入 resizing=true 且再也收不到 pointerup,导致后续都无法拖拽 by xu 20260122
  8213. const pointerId = e?.pointerId;
  8214. const cancelPendingResize = (ev) => {
  8215. try {
  8216. if (
  8217. pointerId != null &&
  8218. ev?.pointerId != null &&
  8219. ev.pointerId !== pointerId
  8220. )
  8221. return;
  8222. } catch (_) {}
  8223. clearTimeout(this.resizeTimer);
  8224. this.resizeTimer = null;
  8225. document.removeEventListener("pointerup", cancelPendingResize, true);
  8226. document.removeEventListener(
  8227. "pointercancel",
  8228. cancelPendingResize,
  8229. true
  8230. );
  8231. };
  8232. // 功能说明:用 document+capture 监听,避免 window 监听在部分容器/iframe 场景丢事件导致拖拽无响应 by xu 20260122
  8233. document.addEventListener("pointerup", cancelPendingResize, {
  8234. passive: false,
  8235. once: true,
  8236. capture: true,
  8237. });
  8238. document.addEventListener("pointercancel", cancelPendingResize, {
  8239. passive: false,
  8240. once: true,
  8241. capture: true,
  8242. });
  8243. const startY = e?.clientY ?? 0;
  8244. const gapEl = e?.currentTarget;
  8245. // 功能说明:记录 gap 前后 section 节点,拖拽过程中直接写入 style.height,避免某些环境下 Vue render 不刷新导致“拖拽无视觉变化” by xu 20260122
  8246. this.__resizePrevSectionEl = gapEl?.previousElementSibling || null;
  8247. this.__resizeNextSectionEl = gapEl?.nextElementSibling || null;
  8248. this.resizeTimer = setTimeout(() => {
  8249. // 定时器触发后进入拖拽态,移除“取消等待”监听,避免误取消 by xu 20260122
  8250. document.removeEventListener("pointerup", cancelPendingResize, true);
  8251. document.removeEventListener(
  8252. "pointercancel",
  8253. cancelPendingResize,
  8254. true
  8255. );
  8256. this.resizing = true;
  8257. this.resizeIndex = index;
  8258. this.resizeStartY = startY;
  8259. this.resizeStartPrev = this.sectionHeights[index] ?? 190;
  8260. this.resizeStartNext = this.sectionHeights[index + 1] ?? 190;
  8261. gapEl?.classList?.add("is-active");
  8262. try {
  8263. if (gapEl?.setPointerCapture && pointerId != null)
  8264. gapEl.setPointerCapture(pointerId);
  8265. } catch (_) {} // 功能说明:捕获 pointer,避免拖拽过程中移出窗口导致 pointermove 丢失 by xu 20260122
  8266. // 功能说明:用 document+capture,确保拖拽时 pointermove/up 不会被中途 stopPropagation 影响 by xu 20260122
  8267. document.addEventListener(
  8268. "pointermove",
  8269. this.__resizeMoveHandler || this.onResizeMove,
  8270. { passive: false, capture: true }
  8271. );
  8272. document.addEventListener(
  8273. "pointerup",
  8274. this.__resizeEndHandler || this.endResize,
  8275. { passive: false, once: true, capture: true }
  8276. );
  8277. document.addEventListener(
  8278. "pointercancel",
  8279. this.__resizeCancelHandler || this.endResize,
  8280. { passive: false, once: true, capture: true }
  8281. ); // 功能说明:触控/手势取消时也要结束拖拽 by xu 20260122
  8282. }, 500);
  8283. },
  8284. onResizeMove(e) {
  8285. if (!this.resizing) return;
  8286. if (e?.preventDefault) e.preventDefault();
  8287. const dy = (e?.clientY ?? 0) - this.resizeStartY;
  8288. const minPanelHeight = 83; // header(35) + listMin(48) by xu 20260106
  8289. const prev = Math.max(minPanelHeight, this.resizeStartPrev + dy);
  8290. const next = Math.max(minPanelHeight, this.resizeStartNext - dy);
  8291. // 若其中一个达到最小值,则停止继续挤压 by xu 20260106
  8292. const adjustedDy = prev - this.resizeStartPrev;
  8293. const nextAdjusted = this.resizeStartNext - adjustedDy;
  8294. const appliedPrev = prev;
  8295. const appliedNext = Math.max(minPanelHeight, nextAdjusted);
  8296. this.sectionHeights.splice(this.resizeIndex, 1, appliedPrev);
  8297. this.sectionHeights.splice(this.resizeIndex + 1, 1, appliedNext);
  8298. // 功能说明:强制触发一次 sectionHeights 引用变化,避免某些运行时环境下 splice 未触发视图更新导致“拖拽没反应” by xu 20260122
  8299. this.sectionHeights = (this.sectionHeights || []).slice();
  8300. // 功能说明:兜底——直接写 DOM 的 height,确保视觉立即响应(用于排查/修复某些环境下 render 不更新) by xu 20260122
  8301. try {
  8302. if (this.__resizePrevSectionEl?.style)
  8303. this.__resizePrevSectionEl.style.height = appliedPrev + "px";
  8304. if (this.__resizeNextSectionEl?.style)
  8305. this.__resizeNextSectionEl.style.height = appliedNext + "px";
  8306. } catch (_) {}
  8307. },
  8308. endResize(e) {
  8309. clearTimeout(this.resizeTimer);
  8310. this.resizeTimer = null;
  8311. if (!this.resizing) return;
  8312. if (e?.preventDefault) e.preventDefault();
  8313. const activeGaps = document.querySelectorAll(
  8314. ".ss-sidebar-gap.is-active"
  8315. );
  8316. activeGaps.forEach((g) => g.classList.remove("is-active"));
  8317. this.resizing = false;
  8318. this.resizeIndex = -1;
  8319. this.__resizePrevSectionEl = null; // 功能说明:释放 DOM 引用,避免内存泄漏 by xu 20260122
  8320. this.__resizeNextSectionEl = null; // 功能说明:释放 DOM 引用,避免内存泄漏 by xu 20260122
  8321. document.removeEventListener(
  8322. "pointermove",
  8323. this.__resizeMoveHandler || this.onResizeMove,
  8324. true
  8325. );
  8326. document.removeEventListener(
  8327. "pointercancel",
  8328. this.__resizeCancelHandler || this.endResize,
  8329. true
  8330. ); // 功能说明:清理 cancel 监听,避免残留 by xu 20260122
  8331. },
  8332. },
  8333. watch: {
  8334. panels: {
  8335. handler(nextPanels) {
  8336. this.__syncSectionAutoCollapse(nextPanels);
  8337. },
  8338. deep: true,
  8339. immediate: true,
  8340. },
  8341. list: {
  8342. handler(nextList) {
  8343. if ((this.panels || []).length) return;
  8344. this.__syncSectionAutoCollapse(nextList);
  8345. },
  8346. deep: true,
  8347. immediate: true,
  8348. },
  8349. },
  8350. mounted() {
  8351. clearTimeout(this.resizeTimer);
  8352. this.resizeTimer = null;
  8353. // 功能说明:绑定拖拽事件 handler(用于 add/removeEventListener) by xu 20260122
  8354. if (!this.__resizeMoveHandler)
  8355. this.__resizeMoveHandler = (e) => this.onResizeMove?.(e);
  8356. if (!this.__resizeEndHandler)
  8357. this.__resizeEndHandler = (e) => this.endResize?.(e);
  8358. if (!this.__resizeCancelHandler)
  8359. this.__resizeCancelHandler = (e) => this.endResize?.(e);
  8360. // 功能说明:暂时回退为固定底部留白方案(CSS 控制),后续再定位遮挡根因 by xu 20260115
  8361. },
  8362. beforeUnmount() {
  8363. clearTimeout(this.resizeTimer);
  8364. this.resizeTimer = null;
  8365. document.removeEventListener(
  8366. "pointermove",
  8367. this.__resizeMoveHandler || this.onResizeMove,
  8368. true
  8369. );
  8370. document.removeEventListener(
  8371. "pointerup",
  8372. this.__resizeEndHandler || this.endResize,
  8373. true
  8374. );
  8375. document.removeEventListener(
  8376. "pointercancel",
  8377. this.__resizeCancelHandler || this.endResize,
  8378. true
  8379. );
  8380. },
  8381. render() {
  8382. const SsSidebarButtonsComp = Vue.resolveComponent("ss-sidebar-buttons");
  8383. const SsSidebarChartComp = Vue.resolveComponent("ss-sidebar-chart");
  8384. const SsSidebarListComp = Vue.resolveComponent("ss-sidebar-list");
  8385. const SsSidebarReportTableComp = Vue.resolveComponent(
  8386. "ss-sidebar-report-table"
  8387. );
  8388. const SsIcon = Vue.resolveComponent("ss-icon");
  8389. // 支持 panels(多分区),list/listMode 作为 legacy 兜底 by xu 20260106
  8390. const panels = (this.panels || []).length
  8391. ? this.panels
  8392. : this.list?.length
  8393. ? [
  8394. {
  8395. type: "list",
  8396. title: "已选",
  8397. icon: "",
  8398. mode: this.listMode,
  8399. items: this.list,
  8400. },
  8401. ]
  8402. : [];
  8403. // 功能说明:右侧栏强制移除“对象”tab(兼容后端返回 rbarObj/rbarobj 或直接返回中文“对象”标题) by xu 20260116
  8404. const panelsNoObj = (panels || []).filter((p) => {
  8405. const k = String(p?._tabKey ?? "")
  8406. .trim()
  8407. .toLowerCase();
  8408. const t = String(p?.title ?? "").trim();
  8409. if (k === "rbarobj") return false;
  8410. if (t === "对象") return false;
  8411. return true;
  8412. });
  8413. // 功能说明:report-table 作为底部报表区(放在统计图下面),不参与可拖拽 section 面板 by xu 20260115
  8414. const sectionPanels = panelsNoObj.filter(
  8415. (p) => p?.type !== "chart" && p?.type !== "report-table"
  8416. );
  8417. const chartPanels = panelsNoObj.filter((p) => p?.type === "chart");
  8418. const reportPanels = panelsNoObj.filter(
  8419. (p) => p?.type === "report-table"
  8420. );
  8421. this.ensureSectionHeights(sectionPanels.length);
  8422. // 功能说明:补齐 chart/report 折叠数组长度 by xu 20260116
  8423. this.chartCollapsed = Array.from(
  8424. { length: chartPanels.length },
  8425. (_, i) => !!this.chartCollapsed?.[i]
  8426. );
  8427. this.chartHeaderTitleDownAt = Array.from(
  8428. { length: chartPanels.length },
  8429. (_, i) => this.chartHeaderTitleDownAt?.[i] ?? 0
  8430. );
  8431. this.reportCollapsed = Array.from(
  8432. { length: reportPanels.length },
  8433. (_, i) => !!this.reportCollapsed?.[i]
  8434. );
  8435. return Vue.h("div", { class: "ss-sidebar" }, [
  8436. this.buttons?.length
  8437. ? Vue.h(SsSidebarButtonsComp, { items: this.buttons })
  8438. : null,
  8439. Vue.h(
  8440. "div",
  8441. { class: "ss-sidebar__inner" },
  8442. [
  8443. ...(this.charts || []).map((c) =>
  8444. Vue.h(SsSidebarChartComp, {
  8445. options: c?.options || {},
  8446. height: c?.height || "200px",
  8447. })
  8448. ),
  8449. // 可拖拽的业务面板容器 by xu 20260106
  8450. Vue.h(
  8451. "div",
  8452. { class: "ss-sidebar-sections", style: { flex: "0 0 auto" } },
  8453. sectionPanels.flatMap((p, idx) => {
  8454. const panelContent =
  8455. p?.type === "report-table"
  8456. ? Vue.h(SsSidebarReportTableComp, {
  8457. key: `ss-sidebar-report-in-section-${idx}-${
  8458. p?.title ?? ""
  8459. }`,
  8460. title: p?.title ?? "",
  8461. icon: p?.icon ?? "",
  8462. iconClass: p?.iconClass ?? "",
  8463. items: p?.items || [],
  8464. onOpen: (srv, ctx) => p?.onOpen?.(srv, ctx),
  8465. })
  8466. : Vue.h(SsSidebarListComp, {
  8467. key: `ss-sidebar-list-${idx}-${p?.title ?? ""}`,
  8468. title: p?.title ?? "",
  8469. icon: p?.icon ?? "",
  8470. count: p?.count ?? p?.items?.length ?? "",
  8471. closable: !!p?.closable,
  8472. searchable: !!p?.searchable,
  8473. searchInHeader: !!p?.searchInHeader,
  8474. headerFilters: p?.headerFilters || [],
  8475. headerSearchButton: !!p?.headerSearchButton,
  8476. searchPlaceholder: p?.searchPlaceholder ?? "搜索",
  8477. itemLayout: p?.itemLayout ?? "simple",
  8478. itemAction: p?.itemAction ?? true,
  8479. collapsible: true,
  8480. collapsed: !!this.sectionCollapsed?.[idx],
  8481. onToggleCollapse: () =>
  8482. this.toggleSectionCollapse?.(idx),
  8483. iconClass: p?.iconClass ?? "",
  8484. items: p?.items || [],
  8485. mode: p?.mode || "search",
  8486. onSelect: (item) => this.$emit("select", item),
  8487. onRemove: (item) => this.$emit("remove", item),
  8488. onClear: () => p?.onClear?.(),
  8489. onSearch: (payload) => p?.onSearch?.(payload),
  8490. });
  8491. const section = Vue.h(
  8492. "div",
  8493. {
  8494. class: {
  8495. "ss-sidebar-section": true,
  8496. "is-collapsed": !!this.sectionCollapsed?.[idx],
  8497. },
  8498. key: `ss-sidebar-section-${idx}-${p?.type ?? "list"}-${
  8499. p?.title ?? ""
  8500. }`,
  8501. style: {
  8502. height: (this.sectionHeights[idx] ?? 190) + "px",
  8503. flex: "0 0 auto",
  8504. },
  8505. },
  8506. [
  8507. Vue.h("div", { class: "ss-sidebar-section__content" }, [
  8508. panelContent,
  8509. ]),
  8510. ]
  8511. );
  8512. const gap =
  8513. idx < sectionPanels.length - 1
  8514. ? Vue.h("div", {
  8515. class: "ss-sidebar-gap",
  8516. onPointerdown: (e) => this.startResize(idx, e),
  8517. })
  8518. : null;
  8519. return gap ? [section, gap] : [section];
  8520. })
  8521. ),
  8522. // 图表区固定在底部(hover 弹出大图) by xu 20260106
  8523. ...chartPanels.map((p, chartIdx) =>
  8524. Vue.h(
  8525. "div",
  8526. {
  8527. class: {
  8528. "ss-sidebar-panel": true,
  8529. "ss-sidebar-chart-panel": true,
  8530. "is-collapsed": !!this.chartCollapsed?.[chartIdx],
  8531. },
  8532. style: { flex: "0 0 auto", minHeight: "37px" },
  8533. "data-chart-idx": chartIdx,
  8534. key: `ss-sidebar-chart-${chartIdx}-${p?.title ?? ""}`,
  8535. },
  8536. [
  8537. p?.title
  8538. ? Vue.h(
  8539. "div",
  8540. {
  8541. class: "ss-sidebar-panel__header",
  8542. onDblclick: (e) => {
  8543. e?.preventDefault?.();
  8544. e?.stopPropagation?.();
  8545. console.log("[SsSidebar] chart header dblclick", {
  8546. idx: chartIdx,
  8547. title: p?.title,
  8548. });
  8549. this.toggleChartCollapse?.(chartIdx);
  8550. },
  8551. },
  8552. [
  8553. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  8554. p?.iconClass
  8555. ? Vue.h(SsIcon, {
  8556. class:
  8557. p.iconClass + " ss-sidebar-panel__icon",
  8558. })
  8559. : p?.icon
  8560. ? Vue.h(SsIcon, {
  8561. name: p.icon,
  8562. size: "16px",
  8563. class: "ss-sidebar-panel__icon",
  8564. })
  8565. : null,
  8566. Vue.h("span", null, p.title),
  8567. ]),
  8568. Vue.h("div", { class: "ss-sidebar-panel__tools" }),
  8569. ]
  8570. )
  8571. : null,
  8572. this.chartCollapsed?.[chartIdx]
  8573. ? null
  8574. : Vue.h(Vue.resolveComponent("ss-sidebar-chart-hover"), {
  8575. title: p?.title ?? "",
  8576. iconClass: p?.iconClass ?? "",
  8577. icon: p?.icon ?? "",
  8578. options: p?.options || {},
  8579. height: p?.height || "240px",
  8580. }),
  8581. ]
  8582. )
  8583. ),
  8584. ...reportPanels.map((p, reportIdx) =>
  8585. Vue.h(
  8586. "div",
  8587. {
  8588. class: {
  8589. "ss-sidebar-report-panel-wrap": true,
  8590. "ss-sidebar-report-panel": true,
  8591. "is-collapsed": !!this.reportCollapsed?.[reportIdx],
  8592. },
  8593. style: { flex: "0 0 auto", minHeight: "37px" },
  8594. "data-report-idx": reportIdx,
  8595. key: `ss-sidebar-report-wrap-${reportIdx}-${p?.title ?? ""}`,
  8596. },
  8597. [
  8598. Vue.h(SsSidebarReportTableComp, {
  8599. key: `ss-sidebar-report-${reportIdx}-${p?.title ?? ""}`,
  8600. title: p?.title ?? "",
  8601. icon: p?.icon ?? "",
  8602. iconClass: p?.iconClass ?? "",
  8603. items: p?.items || [],
  8604. collapsible: true,
  8605. collapsed: !!this.reportCollapsed?.[reportIdx],
  8606. onToggleCollapse: () =>
  8607. this.toggleReportCollapse?.(reportIdx),
  8608. onOpen: (srv, ctx) => p?.onOpen?.(srv, ctx),
  8609. }),
  8610. ]
  8611. )
  8612. ),
  8613. ].filter(Boolean)
  8614. ),
  8615. ]);
  8616. },
  8617. };
  8618. // ss-folder-card 文件夹卡片
  8619. const SsFolderCard = {
  8620. name: "SsFolderCard",
  8621. props: {
  8622. item: {
  8623. type: Object,
  8624. required: true,
  8625. },
  8626. },
  8627. data() {
  8628. return {
  8629. showButtons: false,
  8630. };
  8631. },
  8632. emits: ["click", "change"],
  8633. setup(props, { emit }) {
  8634. const item = props.item;
  8635. const showChildren = ref(false);
  8636. const eventBus = window.parent.sharedEventBus;
  8637. const itemWidth = Vue.computed(() => {
  8638. // 功能说明:页面改为 grid 等分布局后,卡片宽度交给容器控制,这里固定 100% by xu 20260116
  8639. return "100%";
  8640. });
  8641. onMounted(() => {
  8642. eventBus.subscribe("folderPath", (path) => {
  8643. const currentPath = path || [];
  8644. // 如果当前文件夹不在路径中,则销毁视图
  8645. if (
  8646. !currentPath.some((item) => item.folder.title === props.item.title)
  8647. ) {
  8648. showChildren.value = false;
  8649. }
  8650. });
  8651. });
  8652. const onItemClick = (e) => {
  8653. if (e && e.stopPropagation) {
  8654. e.stopPropagation();
  8655. }
  8656. // 单击只处理 active 状态
  8657. if (e && e.currentTarget) {
  8658. const allListCards = document.querySelectorAll(
  8659. ".knowledge-item-container"
  8660. );
  8661. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8662. allListCards.forEach((card) => card.classList.remove("active"));
  8663. allFolderCards.forEach((card) => card.classList.remove("active"));
  8664. e.currentTarget.classList.add("active");
  8665. } else {
  8666. // 如果是数据对象,需要找到对应的 DOM 元素
  8667. const allListCards = document.querySelectorAll(
  8668. ".knowledge-item-container"
  8669. );
  8670. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8671. allListCards.forEach((card) => card.classList.remove("active"));
  8672. allFolderCards.forEach((card) => card.classList.remove("active"));
  8673. // 找到标题匹配的文件夹元素
  8674. const targetFolder = Array.from(allFolderCards).find((card) =>
  8675. card.textContent.includes(e.title)
  8676. );
  8677. if (targetFolder) {
  8678. targetFolder.classList.add("active");
  8679. }
  8680. }
  8681. emit("click", item);
  8682. };
  8683. // 修改双击处理函数
  8684. const handleFolderDblClick = (folder, e) => {
  8685. if (e) e.stopPropagation();
  8686. if (folder.children?.length) {
  8687. showChildren.value = true;
  8688. const pathInfo = {
  8689. title: folder.title,
  8690. folder: folder,
  8691. };
  8692. const currentPath = eventBus.getState("folderPath") || [];
  8693. if (!currentPath.some((item) => item.title === folder.title)) {
  8694. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  8695. }
  8696. }
  8697. };
  8698. const onItemChange = (e, icon, index) => {
  8699. e.stopPropagation();
  8700. props.item.buttons[0].onclick();
  8701. // emit("change", { item: props.item, icon, index });
  8702. };
  8703. return {
  8704. item,
  8705. itemWidth,
  8706. showChildren,
  8707. onItemClick,
  8708. onItemChange,
  8709. handleFolderDblClick,
  8710. };
  8711. },
  8712. render() {
  8713. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  8714. if (this.showChildren) {
  8715. return h(SsFolderCartView, {
  8716. folder: this.item,
  8717. });
  8718. }
  8719. return Vue.h(
  8720. "div",
  8721. {
  8722. class: { "ss-folder-list": true, active: this.item.active },
  8723. onClick: (e) => {
  8724. e.stopPropagation();
  8725. this.onItemClick(e);
  8726. },
  8727. onDblclick: (e) => this.handleFolderDblClick(this.item, e),
  8728. style: { width: this.itemWidth },
  8729. },
  8730. [
  8731. // 文件夹特有的装饰元素
  8732. Vue.h("div", { class: "ss-folder-list-trapezoid" }),
  8733. Vue.h("div", { class: "ss-folder-list-top-transparent" }),
  8734. Vue.h("div", { class: "ss-folder-list-top" }),
  8735. Vue.h("div", { class: "ss-folder-list-right" }),
  8736. // header 部分(按钮)
  8737. this.item?.buttons?.length > 0 &&
  8738. Vue.h(
  8739. "div",
  8740. {
  8741. class: "header",
  8742. onMouseenter: () => (this.showButtons = true),
  8743. onMouseleave: () => (this.showButtons = false),
  8744. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  8745. },
  8746. [
  8747. // this.item?.buttons?.length > 0 &&
  8748. Vue.h("div", {
  8749. class: "cart-list-setting cart-list-icon",
  8750. title: this.item?.buttons?.[0]?.title,
  8751. }),
  8752. // this.item?.buttons?.length > 0 &&
  8753. this.showButtons &&
  8754. this.item?.buttons?.length > 1 &&
  8755. Vue.h(
  8756. "div",
  8757. {
  8758. class: "cart-list-button-popup",
  8759. },
  8760. this.item.buttons.map((btn) =>
  8761. Vue.h(
  8762. "div",
  8763. {
  8764. onClick: (e) => {
  8765. e.stopPropagation();
  8766. btn.onclick?.();
  8767. },
  8768. },
  8769. [
  8770. btn.class &&
  8771. Vue.h(SsCartListIcon, {
  8772. class: [btn.class],
  8773. }),
  8774. Vue.h("span", null, btn.title),
  8775. ]
  8776. )
  8777. )
  8778. ),
  8779. ]
  8780. ),
  8781. // body 部分
  8782. Vue.h("div", { class: "body" }, [
  8783. Vue.h("div", { class: "box-header" }, [
  8784. Vue.h("div", null, this.item.title),
  8785. ]),
  8786. Vue.h(
  8787. "div",
  8788. {
  8789. class: !this.item.thumb ? "no-thumb box-body" : "box-body",
  8790. },
  8791. [
  8792. this.item.thumb
  8793. ? Vue.h("div", { class: "left" }, [
  8794. Vue.h("img", {
  8795. src: this.item.thumb,
  8796. alt: "Thumbnail",
  8797. class: "imgUnHandle",
  8798. style: {
  8799. "object-fit": "cover",
  8800. width: "100%",
  8801. height: "100%",
  8802. },
  8803. }),
  8804. ])
  8805. : null,
  8806. Vue.h("div", { class: "right" }, [
  8807. ...this.item.tags.map((tag) => {
  8808. const [key, value] = Object.entries(tag)[0];
  8809. return Vue.h(
  8810. "div",
  8811. {
  8812. class: "title",
  8813. title: `${key}: ${value}`,
  8814. },
  8815. `${key}: ${value}`
  8816. );
  8817. }),
  8818. ]),
  8819. ]
  8820. ),
  8821. ]),
  8822. ]
  8823. );
  8824. },
  8825. };
  8826. // SsFolderCartView 组件 - 用于显示文件夹内容
  8827. const SsFolderCartView = {
  8828. name: "SsFolderCartView",
  8829. props: {
  8830. folder: {
  8831. type: Object,
  8832. required: true,
  8833. },
  8834. },
  8835. emits: ["click"],
  8836. setup(props, { emit }) {
  8837. const eventBus = window.parent.sharedEventBus;
  8838. const currentFolder = ref(props.folder);
  8839. const showChildren = ref(false);
  8840. const onItemClick = (e) => {
  8841. if (e && e.stopPropagation) {
  8842. e.stopPropagation();
  8843. }
  8844. // 单击只处理 active 状态
  8845. if (e && e.currentTarget) {
  8846. const allListCards = document.querySelectorAll(
  8847. ".knowledge-item-container"
  8848. );
  8849. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8850. allListCards.forEach((card) => card.classList.remove("active"));
  8851. allFolderCards.forEach((card) => card.classList.remove("active"));
  8852. e.currentTarget.classList.add("active");
  8853. } else {
  8854. // 如果是数据对象,需要找到对应的 DOM 元素
  8855. const allListCards = document.querySelectorAll(
  8856. ".knowledge-item-container"
  8857. );
  8858. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8859. allListCards.forEach((card) => card.classList.remove("active"));
  8860. allFolderCards.forEach((card) => card.classList.remove("active"));
  8861. // 找到标题匹配的文件夹元素
  8862. const targetFolder = Array.from(allFolderCards).find((card) =>
  8863. card.textContent.includes(e.title)
  8864. );
  8865. if (targetFolder) {
  8866. targetFolder.classList.add("active");
  8867. }
  8868. }
  8869. emit("click", props.folder);
  8870. };
  8871. const handleFolderDblClick = (folder, e) => {
  8872. if (e) e.stopPropagation();
  8873. if (folder.children?.length) {
  8874. showChildren.value = true;
  8875. const pathInfo = {
  8876. title: folder.title,
  8877. folder: folder,
  8878. };
  8879. const currentPath = eventBus.getState("folderPath") || [];
  8880. if (!currentPath.some((item) => item.title === folder.title)) {
  8881. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  8882. currentFolder.value = folder;
  8883. }
  8884. }
  8885. };
  8886. const goBack = (targetFolder) => {
  8887. if (targetFolder === null) {
  8888. // 返回根目录
  8889. eventBus.publish("folderPath", []);
  8890. } else {
  8891. currentFolder.value = targetFolder;
  8892. }
  8893. };
  8894. return {
  8895. currentFolder,
  8896. showChildren,
  8897. onItemClick,
  8898. handleFolderDblClick,
  8899. goBack,
  8900. };
  8901. },
  8902. render() {
  8903. return h(
  8904. "div",
  8905. {
  8906. class: "page-container",
  8907. style: {
  8908. position: "fixed",
  8909. top: 0,
  8910. left: 0,
  8911. width: "100%",
  8912. height: "100%",
  8913. background: "var(--lightgray)",
  8914. padding: "20px 0",
  8915. zIndex: 1000,
  8916. },
  8917. },
  8918. [
  8919. // 搜索栏
  8920. h("div", { class: "search-bar" }, [
  8921. h("div", { class: "search-bar-contaienr" }, [
  8922. h(SsBreadcrumb, {
  8923. level: {
  8924. onBack: this.goBack,
  8925. },
  8926. }),
  8927. ]),
  8928. ]),
  8929. // 内容区域
  8930. h(
  8931. "div",
  8932. {
  8933. class: "content-area item-content-area",
  8934. style: { gap: "20px" },
  8935. },
  8936. [
  8937. ...(this.currentFolder.children || []).map((child, index) =>
  8938. h(child.children ? SsFolderCard : SsListCard, {
  8939. key: index,
  8940. item: child,
  8941. onClick: (e) => this.onItemClick(e),
  8942. onDblclick: (e) => this.handleFolderDblClick(child, e),
  8943. })
  8944. ),
  8945. ]
  8946. ),
  8947. ]
  8948. );
  8949. },
  8950. };
  8951. // ss-page分页
  8952. const SsPage = {
  8953. name: "SsPage",
  8954. props: {
  8955. total: {
  8956. type: Number,
  8957. required: true,
  8958. },
  8959. size: {
  8960. type: Number,
  8961. default: 10,
  8962. },
  8963. page: {
  8964. type: Number,
  8965. default: 1,
  8966. },
  8967. onChange: {
  8968. type: Function,
  8969. default: () => {},
  8970. },
  8971. },
  8972. setup(props) {
  8973. const totalItems = ref(props.total); // 总条目数
  8974. const totalPages = ref(Math.ceil(props.total / props.size));
  8975. const currentPage = ref(props.page); // 当前页码
  8976. // 计算显示的信息
  8977. const pageInfo = ref(
  8978. `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`
  8979. );
  8980. // 上一页的逻辑
  8981. const goToPreviousPage = (e) => {
  8982. e.preventDefault(); // 阻止默认行为
  8983. if (currentPage.value > 1) {
  8984. currentPage.value -= 1;
  8985. updatePageInfo();
  8986. props.onChange?.({
  8987. pageNo: currentPage.value, // 当前页码
  8988. rowNumPer: props.size, // 每页条数
  8989. rowNum: props.total, // 总记录数
  8990. });
  8991. }
  8992. };
  8993. // 下一页的逻辑
  8994. const goToNextPage = (e) => {
  8995. e.preventDefault(); // 阻止默认行为
  8996. if (currentPage.value < totalPages.value) {
  8997. currentPage.value += 1;
  8998. updatePageInfo();
  8999. props.onChange?.({
  9000. pageNo: currentPage.value, // 当前页码
  9001. rowNumPer: props.size, // 每页条数
  9002. rowNum: props.total, // 总记录数
  9003. });
  9004. }
  9005. };
  9006. // 更新页码信息的函数
  9007. const updatePageInfo = () => {
  9008. pageInfo.value = `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`;
  9009. };
  9010. return {
  9011. pageInfo,
  9012. totalPages,
  9013. goToPreviousPage,
  9014. goToNextPage,
  9015. };
  9016. },
  9017. render(props, { slots, emit }) {
  9018. return Vue.h("div", { class: "pager-container" }, [
  9019. Vue.h("input", { type: "hidden", name: "rowNum", value: props.total }),
  9020. Vue.h("input", {
  9021. type: "hidden",
  9022. name: "rowNumPer",
  9023. value: props.size,
  9024. }),
  9025. Vue.h("input", {
  9026. type: "hidden",
  9027. name: "pageCount",
  9028. value: this.totalPages,
  9029. }),
  9030. Vue.h("input", { type: "hidden", name: "pageNo", value: props.page }),
  9031. Vue.h("div", { class: "pager-content" }, [
  9032. Vue.h("div", { class: "info" }, this.pageInfo),
  9033. Vue.h(
  9034. "div",
  9035. { class: "btn" },
  9036. Vue.h(
  9037. "button",
  9038. { onClick: (e) => this.goToPreviousPage(e) },
  9039. "上一页"
  9040. )
  9041. ),
  9042. Vue.h(
  9043. "div",
  9044. { class: "btn" },
  9045. Vue.h("button", { onClick: (e) => this.goToNextPage(e) }, "下一页")
  9046. ),
  9047. ]),
  9048. ]);
  9049. },
  9050. };
  9051. // ss-right-info 一级页面右边栏
  9052. const SSRightInfo = {
  9053. name: "SSRightInfo",
  9054. setup() {
  9055. // 初始化响应式数据
  9056. const item = ref({
  9057. thumb: "images/example/project-img.png", // 更换为适合你项目的实际路径
  9058. title: "工业和信息化产业高质量发展资金",
  9059. });
  9060. return {
  9061. item,
  9062. };
  9063. },
  9064. render() {
  9065. return Vue.h("div", { class: "info-container" }, [
  9066. Vue.h("div", { class: "header" }, [
  9067. Vue.h("div", [
  9068. Vue.h("img", {
  9069. src: this.item.thumb,
  9070. class: "imgUnHandle",
  9071. style: { "object-fit": "cover", width: "100%", height: "100%" },
  9072. }), // 将 ImageViewer 替换为 img 标签
  9073. ]),
  9074. Vue.h("div", [Vue.h("div", this.item.title)]),
  9075. ]),
  9076. Vue.h("div", { class: "section-container" }, [
  9077. Vue.h("div", { class: "section" }, [
  9078. Vue.h("div", { class: "title" }, "合同"),
  9079. Vue.h("div", { class: "text" }, "合同总金额:42,399,320"),
  9080. Vue.h(
  9081. "div",
  9082. { class: "a" },
  9083. "《工业和信息化产业高质量发展资金补助合同》"
  9084. ),
  9085. ]),
  9086. Vue.h("div", { class: "section" }, [
  9087. Vue.h("div", { class: "title" }, "发票"),
  9088. Vue.h("div", { class: "text" }, "应开发票总额:42,399,320"),
  9089. Vue.h("div", { class: "text" }, "已开发票金额:17,235,345"),
  9090. Vue.h("div", { class: "text" }, "未开发票金额:25,163,975"),
  9091. ]),
  9092. Vue.h("div", { class: "section" }, [
  9093. Vue.h("div", { class: "title" }, "项目组成员"),
  9094. Vue.h("div", { class: "text" }, "我司:3人"),
  9095. Vue.h("div", { class: "text" }, "对方:2人"),
  9096. Vue.h("div", { class: "text" }, "项目负责人:张三"),
  9097. ]),
  9098. Vue.h("div", { class: "section" }, [
  9099. Vue.h("div", { class: "title" }, "采购"),
  9100. Vue.h("div", { class: "text" }, "总额:999,320"),
  9101. Vue.h("div", { class: "text" }, "已付金额:335,345"),
  9102. Vue.h("div", { class: "text" }, "未付金额:663,975"),
  9103. ]),
  9104. ]),
  9105. ]);
  9106. },
  9107. };
  9108. //
  9109. const SsSuccessPopup = {
  9110. name: "SsSuccessPopup",
  9111. props: {
  9112. right: {
  9113. type: String,
  9114. default: "20px",
  9115. },
  9116. bottom: {
  9117. type: String,
  9118. default: "calc(100% + 5px)",
  9119. },
  9120. },
  9121. setup(props, { expose }) {
  9122. // 响应式状态:是否可见
  9123. const visible = ref(false);
  9124. // 计算样式
  9125. const style = computed(() => {
  9126. return {
  9127. "--message-dialog-right": props.right,
  9128. "--message-dialog-bottom": props.bottom,
  9129. };
  9130. });
  9131. // 显示对话框的方法
  9132. const show = () => {
  9133. visible.value = true;
  9134. };
  9135. // 隐藏对话框的方法
  9136. const hide = () => {
  9137. visible.value = false;
  9138. };
  9139. // 将方法暴露给外部使用
  9140. expose({ show, hide });
  9141. // 返回渲染函数
  9142. return () => {
  9143. if (!visible.value) return null;
  9144. const SsIcon = resolveComponent("ss-icon");
  9145. return h(
  9146. "div",
  9147. {
  9148. class: "success-popup",
  9149. style: style.value,
  9150. onClick: (e) => e.stopPropagation(),
  9151. },
  9152. [
  9153. h("div", { class: "left" }, [
  9154. h("div", { class: "icon" }, [
  9155. h(SsIcon, { name: "check", size: "36px" }),
  9156. ]),
  9157. ]),
  9158. h("div", { class: "right" }, [
  9159. h("div", { class: "title" }, "提交成功"),
  9160. h("div", { class: "desc" }, "您的信息已成功提交。"),
  9161. ]),
  9162. ]
  9163. );
  9164. };
  9165. },
  9166. };
  9167. const SsErrorDialog = {
  9168. name: "SsErrorDialog",
  9169. setup(props, { emit }) {
  9170. const visible = ref(false);
  9171. const style = computed(() => {
  9172. return {};
  9173. });
  9174. const show = () => {
  9175. visible.value = true;
  9176. };
  9177. const hide = () => {
  9178. visible.value = false;
  9179. };
  9180. const onBack = () => {
  9181. emit("back");
  9182. hide();
  9183. };
  9184. return {
  9185. visible,
  9186. style,
  9187. show,
  9188. hide,
  9189. onBack,
  9190. };
  9191. },
  9192. render() {
  9193. const SsIcon = resolveComponent("ss-icon");
  9194. return this.visible
  9195. ? h(
  9196. "div",
  9197. {
  9198. class: "errorDialog",
  9199. style: this.style,
  9200. onClick: (event) => event.stopPropagation(),
  9201. },
  9202. [
  9203. h("div", { class: "body" }, [
  9204. h("div", { class: "left" }, [
  9205. h("div", { class: "icon" }, [
  9206. h(SsIcon, { name: "close", size: "36px" }),
  9207. ]),
  9208. ]),
  9209. h("div", { class: "right" }, [
  9210. h("div", { class: "title" }, "操作失败"),
  9211. h("div", { class: "desc" }, "请点击返回以继续。"),
  9212. ]),
  9213. ]),
  9214. h("div", { class: "footer" }, [
  9215. h("div", { class: "left" }),
  9216. h("div", { class: "right" }, [
  9217. h(
  9218. "div",
  9219. {
  9220. class: "btn",
  9221. onClick: this.onBack,
  9222. },
  9223. [h(SsIcon, { name: "arrow-left-line" }), h("div", "返回")]
  9224. ),
  9225. ]),
  9226. ]),
  9227. ]
  9228. )
  9229. : null;
  9230. },
  9231. };
  9232. /**
  9233. * 审核链条
  9234. * @name ss-verify
  9235. * @param { Array } verify-list 审核节点列表
  9236. * @property { Array } verify-list 审核节点列表
  9237. * @example <ss-verify :verify-list="verifyList"></ss-verify>
  9238. * verify-list [
  9239. * {
  9240. * groupName: "", // 群组名称
  9241. * open: true, // 默认是否展开
  9242. * children:[ //群组里的人员
  9243. * {
  9244. * thumb: "images/example/user-4.png", // 头像
  9245. * name: "李丽思 ", // 姓名
  9246. * role: "人事处处长", // 角色
  9247. * description: "同意。", // 审核意见
  9248. * time: "09:38 08/11", // 审核时间
  9249. * video: false, // false不显示/true显示 视频icon
  9250. * link: false, // false不显示/true显示 链接icon 后续应该是附件
  9251. * }
  9252. * ]
  9253. * }
  9254. * ]
  9255. */
  9256. const SsVerify = {
  9257. name: "SsVerify",
  9258. props: {
  9259. verifyList: {
  9260. type: Array,
  9261. required: true,
  9262. },
  9263. },
  9264. setup(props) {
  9265. const toggleOpen = (item) => {
  9266. item.open = !item.open;
  9267. };
  9268. onMounted(() => {
  9269. setTimeout(() => {
  9270. const lastOpenGroup = document.querySelector(".group-item-last-open");
  9271. console.log("lastOpenGroup", lastOpenGroup);
  9272. if (lastOpenGroup) {
  9273. const nodes = $(lastOpenGroup).find(".verify-node-container");
  9274. if (nodes.length) {
  9275. let totalHeight = 0;
  9276. const gudingHeight = 100;
  9277. if (nodes.length === 1) {
  9278. totalHeight = gudingHeight;
  9279. } else {
  9280. // 累加除最后一个节点外的所有节点高度
  9281. for (let i = 0; i < nodes.length - 1; i++) {
  9282. totalHeight += $(nodes[i]).outerHeight();
  9283. }
  9284. totalHeight += gudingHeight;
  9285. }
  9286. console.log("节点信息:", {
  9287. 节点总数: nodes.length,
  9288. 计算后的高度: totalHeight,
  9289. });
  9290. lastOpenGroup.style.setProperty(
  9291. "--group-line-height",
  9292. `${totalHeight}px`
  9293. );
  9294. }
  9295. }
  9296. }, 0);
  9297. });
  9298. return {
  9299. toggleOpen,
  9300. };
  9301. },
  9302. render() {
  9303. const SsIcon = resolveComponent("ss-icon");
  9304. const SsCommonIcon = resolveComponent("ss-common-icon");
  9305. const SsVerifyNode = resolveComponent("ss-verify-node");
  9306. return h(
  9307. "div",
  9308. { class: "verify-nodes" },
  9309. this.verifyList.map((item, i) =>
  9310. h(
  9311. "div",
  9312. {
  9313. key: i,
  9314. class: {
  9315. "group-item": true,
  9316. "group-item-last-open":
  9317. i === this.verifyList.length - 1 && item.open,
  9318. },
  9319. },
  9320. [
  9321. h(
  9322. "div",
  9323. {
  9324. class: "group-item-title",
  9325. onClick: () => this.toggleOpen(item),
  9326. },
  9327. [
  9328. h("div", { class: "icon" }, [
  9329. item.open
  9330. ? h(SsCommonIcon, { class: "common-icon-folder-open" })
  9331. : h(SsCommonIcon, { class: "common-icon-folder-close" }),
  9332. h(
  9333. "div",
  9334. {
  9335. class: "num",
  9336. style: { top: item.open ? "60%" : "55%" },
  9337. },
  9338. item.children?.length || 0
  9339. ),
  9340. ]),
  9341. h("div", { class: "name" }, item.groupName),
  9342. ]
  9343. ),
  9344. item.open && item.children?.length > 0
  9345. ? h(
  9346. "div",
  9347. { class: "group-item-children" },
  9348. item.children.map((citem, j) =>
  9349. h(SsVerifyNode, {
  9350. key: j,
  9351. item: citem,
  9352. // isGroup: i + 1 !== this.verifyList.length,
  9353. isGroup: true,
  9354. })
  9355. )
  9356. )
  9357. : null,
  9358. ]
  9359. )
  9360. )
  9361. );
  9362. },
  9363. };
  9364. /**
  9365. * 审核页面的审核节点
  9366. * @name ss-verify-node
  9367. * @param {Object} item 审核节点信息
  9368. * @param {Boolean} isGroup 是否为分组节点
  9369. */
  9370. const SsVerifyNode = {
  9371. name: "SsVerifyNode",
  9372. props: {
  9373. item: {
  9374. type: Object,
  9375. required: true,
  9376. },
  9377. isGroup: {
  9378. type: Boolean,
  9379. default: false,
  9380. },
  9381. },
  9382. render() {
  9383. const SsIcon = resolveComponent("ss-icon");
  9384. const SsCommonIcon = resolveComponent("ss-common-icon");
  9385. return Vue.h("div", { class: "verify-node-container" }, [
  9386. Vue.h("div", { class: "info" }, [
  9387. Vue.h("div", { class: "avatar" }, [
  9388. Vue.h("img", {
  9389. src: this.item.thumb,
  9390. style: {
  9391. width: "50px",
  9392. height: "50px",
  9393. borderRadius: "50%",
  9394. },
  9395. }),
  9396. ]),
  9397. Vue.h("div", { class: "desc" }, [
  9398. Vue.h("div", this.item.name),
  9399. Vue.h("div", this.item.role),
  9400. ]),
  9401. Vue.h("div", { class: "link" }, [
  9402. Vue.h("div", [
  9403. this.item.video
  9404. ? Vue.h(SsCommonIcon, { class: "common-icon-video" })
  9405. : null,
  9406. this.item.link
  9407. ? Vue.h(SsCommonIcon, {
  9408. class: "common-icon-paper-clip",
  9409. })
  9410. : null,
  9411. ]),
  9412. ]),
  9413. ]),
  9414. Vue.h(
  9415. "div",
  9416. {
  9417. class: {
  9418. description: true,
  9419. link: this.isGroup,
  9420. },
  9421. attrs: { "data-num": "3" },
  9422. },
  9423. [Vue.h("div", this.item.description)]
  9424. ),
  9425. Vue.h("div", { class: "time" }, this.item.time),
  9426. ]);
  9427. },
  9428. };
  9429. /**
  9430. * 智能识别图片的左侧图片播放 可以放大缩小旋转图片
  9431. * @name ss-orc-img-box
  9432. * @param { Object } image-obj 包含图片的url, 和图片的名称
  9433. *
  9434. */
  9435. const SsOrcImgBox = {
  9436. name: "SsOrcImgBox",
  9437. props: {
  9438. imageObj: {
  9439. type: Object,
  9440. required: true,
  9441. },
  9442. },
  9443. setup(props) {
  9444. const zoom = ref(1);
  9445. const rotation = ref(0);
  9446. const containerWidth = ref(0);
  9447. const containerHeight = ref(0);
  9448. const container = ref(null);
  9449. const imgPosition = ref({ x: 0, y: 0 });
  9450. const isDragging = ref(false);
  9451. const lastMousePosition = ref({ x: 0, y: 0 });
  9452. const imgStyle = computed(() => ({
  9453. width: `${zoom.value * 100}%`,
  9454. height: `${zoom.value * 100}%`,
  9455. transform: `rotate(${rotation.value}deg) translate(${imgPosition.value.x}px, ${imgPosition.value.y}px)`,
  9456. transformOrigin: "center center",
  9457. cursor: isDragging.value ? "grabbing" : "grab",
  9458. }));
  9459. const resetZoom = () => {
  9460. zoom.value = 1;
  9461. rotation.value = rotation.value + 90;
  9462. imgPosition.value = { x: 0, y: 0 };
  9463. };
  9464. const handleRangeChange = (event) => {
  9465. const value = event.target.value / 50; // 0 到 100 映射到 0 到 2 的缩放
  9466. zoom.value = Math.max(value, 0.1); // 设置最小缩放值为 0.1
  9467. };
  9468. const updateImgBoxDimensions = () => {
  9469. if (container.value) {
  9470. containerWidth.value = container.value.clientWidth;
  9471. containerHeight.value = container.value.clientHeight;
  9472. }
  9473. };
  9474. const onMouseDown = (event) => {
  9475. isDragging.value = true;
  9476. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  9477. };
  9478. const onMouseMove = (event) => {
  9479. if (isDragging.value) {
  9480. const dx = event.clientX - lastMousePosition.value.x;
  9481. const dy = event.clientY - lastMousePosition.value.y;
  9482. // 防止旋转后拖动的x,y反转
  9483. // 首先将当前旋转角度从度数转换为弧度,因为 JavaScript 的 Math 库使用弧度
  9484. const angle = rotation.value * (Math.PI / 180);
  9485. // 使用基本的二维旋转矩阵将原始位移 dx 和 dy 转换为旋转后的位移 rotatedDx 和 rotatedDy。
  9486. const rotatedDx = dx * Math.cos(angle) + dy * Math.sin(angle);
  9487. const rotatedDy = dy * Math.cos(angle) - dx * Math.sin(angle);
  9488. imgPosition.value = {
  9489. x: imgPosition.value.x + rotatedDx,
  9490. y: imgPosition.value.y + rotatedDy,
  9491. };
  9492. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  9493. }
  9494. };
  9495. const onMouseUp = () => {
  9496. isDragging.value = false;
  9497. };
  9498. onMounted(() => {
  9499. nextTick(() => {
  9500. updateImgBoxDimensions();
  9501. window.addEventListener("resize", updateImgBoxDimensions);
  9502. window.addEventListener("mousemove", onMouseMove);
  9503. window.addEventListener("mouseup", onMouseUp);
  9504. });
  9505. });
  9506. return {
  9507. zoom,
  9508. rotation,
  9509. container,
  9510. imgStyle,
  9511. resetZoom,
  9512. handleRangeChange,
  9513. containerWidth,
  9514. containerHeight,
  9515. onMouseDown,
  9516. imgPosition,
  9517. };
  9518. },
  9519. render() {
  9520. const SsIcon = resolveComponent("ss-icon");
  9521. return h("div", { class: "ocr-img-box" }, [
  9522. h("div", { class: "img-bar" }, [
  9523. h("div", this.imageObj.name),
  9524. h("div", { class: "action-bar" }, [
  9525. h("div", { class: "ocr-img-range-box" }, [
  9526. h("input", {
  9527. type: "range",
  9528. min: 0,
  9529. max: 100,
  9530. value: this.zoom * 50, // 初始位置为50
  9531. onInput: this.handleRangeChange,
  9532. }),
  9533. h("span", { class: "line" }),
  9534. ]),
  9535. h(SsIcon, {
  9536. name: "reset",
  9537. size: "26px",
  9538. onClick: this.resetZoom,
  9539. }),
  9540. ]),
  9541. ]),
  9542. h("div", { class: "img-viewer", ref: "container" }, [
  9543. h(
  9544. "div",
  9545. {
  9546. class: "img-box",
  9547. style: {
  9548. width: `${this.containerWidth}px`,
  9549. height: `${this.containerHeight}px`,
  9550. overflow: "hidden",
  9551. position: "relative",
  9552. },
  9553. },
  9554. [
  9555. h("img", {
  9556. src: this.imageObj.thumb,
  9557. style: this.imgStyle,
  9558. class: "zoomable-img",
  9559. onMousedown: this.onMouseDown,
  9560. }),
  9561. ]
  9562. ),
  9563. ]),
  9564. ]);
  9565. },
  9566. };
  9567. // 搜索输入框组件
  9568. const SsSearchInput = {
  9569. name: "SsSearchInput",
  9570. props: {
  9571. name: String,
  9572. placeholder: String,
  9573. width: {
  9574. type: String,
  9575. default: "100px",
  9576. },
  9577. modelValue: String,
  9578. },
  9579. emits: ["update:modelValue", "search"],
  9580. setup(props, { emit }) {
  9581. const handleInput = (e) => {
  9582. emit("update:modelValue", e.target.value);
  9583. };
  9584. const handleKeyup = (e) => {
  9585. if (e.key === "Enter") {
  9586. emit("search");
  9587. }
  9588. };
  9589. return { handleInput, handleKeyup };
  9590. },
  9591. render() {
  9592. return h(
  9593. "div",
  9594. {
  9595. class: "input",
  9596. style: this.width ? { width: this.width } : undefined,
  9597. },
  9598. [
  9599. h("input", {
  9600. name: this.name,
  9601. placeholder: this.placeholder,
  9602. value: this.modelValue,
  9603. onInput: this.handleInput,
  9604. onKeyup: this.handleKeyup,
  9605. }),
  9606. ]
  9607. );
  9608. },
  9609. };
  9610. // ss-search-date-picker 日期时间选择器组件
  9611. const SsSearchDatePicker = {
  9612. name: "SsSearchDatePicker",
  9613. props: {
  9614. modelValue: {
  9615. type: [String, Number, Date],
  9616. default: "",
  9617. },
  9618. name: {
  9619. type: String,
  9620. required: true,
  9621. },
  9622. type: {
  9623. type: String,
  9624. default: "date",
  9625. validator: (value) => ["date", "datetime", "time"].includes(value),
  9626. },
  9627. fmt: {
  9628. type: String,
  9629. default: null,
  9630. },
  9631. placeholder: {
  9632. type: String,
  9633. default: "",
  9634. },
  9635. width: {
  9636. type: String,
  9637. default: "100%",
  9638. },
  9639. },
  9640. emits: ["update:modelValue"],
  9641. setup(props, { emit }) {
  9642. const errMsg = ref("");
  9643. const validate = () => {
  9644. if (window.ssVm) {
  9645. const result = window.ssVm.validateField(props.name);
  9646. console.log("validate", window.ssVm.validateField(props.name));
  9647. errMsg.value = result.valid ? "" : result.message;
  9648. }
  9649. };
  9650. // 根据type确定默认格式
  9651. const defaultFormat = computed(() => {
  9652. switch (props.type) {
  9653. case "datetime":
  9654. return "YYYY-MM-DD HH:mm:ss";
  9655. case "date":
  9656. return "YYYY-MM-DD";
  9657. case "time":
  9658. return "HH:mm:ss";
  9659. }
  9660. });
  9661. const convertJavaFormatToElement = (javaFormat) => {
  9662. if (!javaFormat) return null;
  9663. return javaFormat
  9664. .replace("yyyy", "YYYY")
  9665. .replace("MM", "MM")
  9666. .replace("dd", "DD")
  9667. .replace("HH", "HH")
  9668. .replace("mm", "mm")
  9669. .replace("ss", "ss");
  9670. };
  9671. const finalFormat = computed(() => {
  9672. if (props.fmt) {
  9673. return convertJavaFormatToElement(props.fmt);
  9674. }
  9675. return defaultFormat.value;
  9676. });
  9677. // 使用 resolveComponent 获取组件
  9678. const ElDatePicker = resolveComponent("ElDatePicker");
  9679. const ElTimePicker = resolveComponent("ElTimePicker");
  9680. const SsFormIcon = resolveComponent("SsFormIcon");
  9681. const ElIcon = resolveComponent("ElIcon");
  9682. let useTimePicker = true;
  9683. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  9684. if (props.fmt) {
  9685. //有fmt属性,则以fmt属性优先判断类型
  9686. if (/[dMy]/.test(props.fmt)) {
  9687. //如果有传入日期格式,且含年月日
  9688. useTimePicker = false;
  9689. } else {
  9690. useTimePicker = true;
  9691. }
  9692. } else if (props.type !== "time") {
  9693. useTimePicker = false;
  9694. }
  9695. const dateType = computed(() => {
  9696. const fmt = props.fmt || "";
  9697. if (fmt.includes("HH:mm:ss")) {
  9698. return "datetime";
  9699. } else if (fmt.includes("HH:mm")) {
  9700. return "datetime";
  9701. } else if (fmt.includes("mm:ss")) {
  9702. return "time";
  9703. }
  9704. return "date";
  9705. });
  9706. const handleValueUpdate = (val) => {
  9707. emit("update:modelValue", val);
  9708. emit("change", val); // 同时触发 change 事件
  9709. setTimeout(() => {
  9710. validate();
  9711. }, 50);
  9712. };
  9713. return () =>
  9714. h(
  9715. "div",
  9716. { class: "ss-search-date-picker", style: { width: props.width } },
  9717. [
  9718. h("input", {
  9719. type: "hidden",
  9720. name: props.name,
  9721. value: props.modelValue,
  9722. }),
  9723. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  9724. modelValue: props.modelValue,
  9725. "onUpdate:modelValue": handleValueUpdate,
  9726. type: dateType.value,
  9727. format: finalFormat.value,
  9728. "value-format": finalFormat.value,
  9729. clearable: true,
  9730. placeholder: props.placeholder,
  9731. class: "custom-date-picker", // 用于自定义样式
  9732. "time-arrow-control": props.type === "datetime", // 修改这里
  9733. size: "large", // 添加这一行,改为 large 尺寸
  9734. style: { width: "100%" },
  9735. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  9736. }),
  9737. ]
  9738. );
  9739. },
  9740. };
  9741. // 搜索按钮组件(包含下拉按钮)
  9742. const SsSearchButton = {
  9743. name: "SsSearchButton",
  9744. props: {
  9745. text: {
  9746. type: String,
  9747. required: true,
  9748. },
  9749. iconClass: {
  9750. type: String,
  9751. required: false,
  9752. },
  9753. opt: {
  9754. type: Array,
  9755. default: () => [],
  9756. },
  9757. checkId: {
  9758. type: String,
  9759. default: "0",
  9760. },
  9761. width: {
  9762. //add by Ben(20251225)
  9763. type: String,
  9764. required: false,
  9765. },
  9766. id: {
  9767. //add by Ben(20251225)
  9768. type: String,
  9769. required: false,
  9770. },
  9771. },
  9772. emits: ["click"],
  9773. setup(props, { emit }) {
  9774. const currentId = ref(props.checkId || "0");
  9775. const showPopup = ref(false);
  9776. const handleMouseEnter = () => {
  9777. showPopup.value = true;
  9778. };
  9779. const handleMouseLeave = () => {
  9780. showPopup.value = false;
  9781. };
  9782. // 添加点击事件处理,阻止默认行为
  9783. const handleClick = (e) => {
  9784. e.preventDefault();
  9785. if (props.opt?.length > 0) {
  9786. const selectedOption =
  9787. currentId.value === "0"
  9788. ? props.opt[0]
  9789. : props.opt.find((opt) => opt.id === currentId.value);
  9790. if (selectedOption) {
  9791. selectedOption.callback?.();
  9792. }
  9793. } else {
  9794. emit("click", e);
  9795. }
  9796. };
  9797. // 获取显示文本
  9798. const getDisplayText = () => {
  9799. if (!props.opt?.length) return props.text;
  9800. const selectedOption =
  9801. currentId.value === "0"
  9802. ? props.opt[0]
  9803. : props.opt.find((opt) => opt.id === currentId.value);
  9804. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  9805. };
  9806. return () =>
  9807. h(
  9808. "button",
  9809. {
  9810. class:
  9811. props.opt?.length > 0
  9812. ? "ss-drop-button ss-drop-button-more"
  9813. : "ss-drop-button",
  9814. type: "button", // 明确指定按钮类型为 button
  9815. onMouseenter: handleMouseEnter,
  9816. onMouseleave: handleMouseLeave,
  9817. onClick: handleClick, // 添加点击事件处理
  9818. style: { width: props.width }, //add by Ben(20251225)
  9819. id: props.id, //add by Ben(20251225)
  9820. },
  9821. [
  9822. props.iconClass
  9823. ? h("span", {
  9824. class: props.iconClass,
  9825. style: { fontFamily: "iconfont", marginRight: "5px" },
  9826. })
  9827. : null,
  9828. h("span", getDisplayText()),
  9829. props.opt.length > 0 &&
  9830. showPopup.value &&
  9831. h(
  9832. "div",
  9833. {
  9834. class: "popup",
  9835. },
  9836. props.opt.map((item) =>
  9837. h(
  9838. "div",
  9839. {
  9840. onClick: (e) => {
  9841. e.preventDefault(); // 选项点击也阻止默认行为
  9842. e.stopPropagation(); // 阻止事件冒泡
  9843. currentId.value = item.id; // 更新当前选中的ID
  9844. item.callback();
  9845. showPopup.value = false; // 选择后关闭弹窗
  9846. },
  9847. },
  9848. item.desc
  9849. )
  9850. )
  9851. ),
  9852. ]
  9853. );
  9854. },
  9855. };
  9856. // 下拉按钮组件
  9857. const SsDropButton = {
  9858. name: "SsDropButton",
  9859. props: {
  9860. text: {
  9861. type: String,
  9862. required: true,
  9863. },
  9864. iconClass: {
  9865. type: String,
  9866. required: true,
  9867. },
  9868. opt: {
  9869. type: Array,
  9870. default: () => [],
  9871. },
  9872. checkId: {
  9873. type: String,
  9874. default: "0",
  9875. },
  9876. onclick: {
  9877. type: Function,
  9878. default: null,
  9879. },
  9880. },
  9881. setup(props) {
  9882. const currentId = ref(props.checkId || "0");
  9883. const showPopup = ref(false);
  9884. const handleMouseEnter = () => {
  9885. showPopup.value = true;
  9886. };
  9887. const handleMouseLeave = () => {
  9888. showPopup.value = false;
  9889. };
  9890. // 添加点击事件处理,阻止默认行为
  9891. const handleClick = (e) => {
  9892. e.preventDefault();
  9893. if (props.opt?.length > 0) {
  9894. const selectedOption =
  9895. currentId.value === "0"
  9896. ? props.opt[0]
  9897. : props.opt.find((opt) => opt.id === currentId.value);
  9898. if (selectedOption) {
  9899. selectedOption.callback?.();
  9900. }
  9901. } else if (props.onclick) {
  9902. props.onclick();
  9903. }
  9904. };
  9905. // 获取显示文本
  9906. const getDisplayText = () => {
  9907. if (!props.opt?.length) return props.text;
  9908. const selectedOption =
  9909. currentId.value === "0"
  9910. ? props.opt[0]
  9911. : props.opt.find((opt) => opt.id === currentId.value);
  9912. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  9913. };
  9914. return () =>
  9915. h(
  9916. "button",
  9917. {
  9918. class:
  9919. props.opt?.length > 0
  9920. ? "ss-drop-button ss-drop-button-more"
  9921. : "ss-drop-button",
  9922. type: "button", // 明确指定按钮类型为 button
  9923. onMouseenter: handleMouseEnter,
  9924. onMouseleave: handleMouseLeave,
  9925. onClick: handleClick, // 添加点击事件处理
  9926. },
  9927. [
  9928. h("span", {
  9929. class: props.iconClass,
  9930. style: { fontFamily: "iconfont" },
  9931. }),
  9932. h("span", getDisplayText()),
  9933. props.opt.length > 0 &&
  9934. showPopup.value &&
  9935. h(
  9936. "div",
  9937. {
  9938. class: "popup",
  9939. },
  9940. props.opt.map((item) =>
  9941. h(
  9942. "div",
  9943. {
  9944. onClick: (e) => {
  9945. e.preventDefault(); // 选项点击也阻止默认行为
  9946. e.stopPropagation(); // 阻止事件冒泡
  9947. currentId.value = item.id; // 更新当前选中的ID
  9948. item.callback();
  9949. showPopup.value = false; // 选择后关闭弹窗
  9950. },
  9951. },
  9952. item.desc
  9953. )
  9954. )
  9955. ),
  9956. ]
  9957. );
  9958. },
  9959. };
  9960. /**
  9961. * 二级页面标签组件
  9962. * @name ss-sub-tab
  9963. * @description 用于展示二级页面的布局组件,包含左侧垂直标签导航(支持分组)和右侧iframe内容区
  9964. * @property {String} headerImage - 左侧顶部图片地址
  9965. * @property {Array} menuList - 菜单配置列表
  9966. * @property {Object} [activeMenu] - 当前选中的菜单项,不传则自动选择第一个可选菜单
  9967. * @property {Array} footerButtons - 底部按钮配置列表
  9968. */
  9969. /**
  9970. * SsSubTab 左侧菜单+iframe内容组件
  9971. * v3.0 改造:去掉顶部图片,改为图标+悬浮模式,iframe懒加载 by xu 20251216
  9972. */
  9973. const SsSubTab = {
  9974. name: "SsSubTab",
  9975. props: {
  9976. menuList: {
  9977. type: Array,
  9978. required: true,
  9979. },
  9980. activeMenu: {
  9981. type: String,
  9982. default: "",
  9983. },
  9984. footerButtons: {
  9985. type: Array,
  9986. default: () => [],
  9987. },
  9988. leftDisplay: {
  9989. type: Boolean,
  9990. default: true,
  9991. },
  9992. // v3.0 新增:菜单模式 collapse(悬浮展开) / fixed(始终收起) by xu 20251216
  9993. initialMode: {
  9994. type: String,
  9995. default: "collapse",
  9996. },
  9997. },
  9998. emits: ["menu-change", "footer-click"],
  9999. setup(props, { emit }) {
  10000. // v3.0 新增:默认图标映射,使用icon-biz图标 by xu 20251216
  10001. const defaultIcons = [
  10002. "icon-obj-ry", // 人员
  10003. "icon-obj-dw", // 单位
  10004. "icon-obj-gw", // 岗位
  10005. "icon-biz-rc", // 人才
  10006. "icon-biz-xc", // 巡查
  10007. "icon-biz-cl", // 材料
  10008. "icon-biz-men", // 门
  10009. "icon-obj-xy", // 协议
  10010. ];
  10011. //功能: SsSubTab 支持后端下发 iconName + pobj/cobj 两级菜单 by xu 20251222
  10012. const isTrue = (v) => v === true || v === "true" || v === 1 || v === "1"; //功能 by xu 20251222
  10013. const resolveIconClass = (iconNameOrClass, fallbackIndex) => {
  10014. //功能 by xu 20251222
  10015. const fallback = `menu-icon ${
  10016. defaultIcons[fallbackIndex % defaultIcons.length]
  10017. }`;
  10018. if (!iconNameOrClass) {
  10019. return fallback;
  10020. }
  10021. // 已经是完整 class(可能包含 menu-icon / menu-base-icon / 多个 class)
  10022. if (
  10023. typeof iconNameOrClass === "string" &&
  10024. iconNameOrClass.indexOf(" ") > -1
  10025. ) {
  10026. return iconNameOrClass;
  10027. }
  10028. const iconName = iconNameOrClass;
  10029. if (iconName === "menu-icon" || iconName === "menu-base-icon") {
  10030. return fallback;
  10031. }
  10032. // 业务图标库:icon-biz / icon-obj -> menu-icon
  10033. if (
  10034. typeof iconName === "string" &&
  10035. (iconName.indexOf("icon-obj-") === 0 ||
  10036. iconName.indexOf("icon-biz-") === 0)
  10037. ) {
  10038. return `menu-icon ${iconName}`;
  10039. }
  10040. // 默认认为是 icon-base 图标 -> menu-base-icon
  10041. return `menu-base-icon ${iconName}`;
  10042. };
  10043. const getMenuIcon = (item, index) => {
  10044. //功能 by xu 20251222
  10045. if (!item) {
  10046. return resolveIconClass(null, index);
  10047. }
  10048. //功能: 变动图标后端暂不正确,前端先写死为 icon-chg by xu 20251223
  10049. if (item.title === "变动" || item.name === "sys_bd") {
  10050. return resolveIconClass("icon-chg", index);
  10051. }
  10052. // 兼容旧字段 icon(优先使用)
  10053. if (item.icon) return resolveIconClass(item.icon, index);
  10054. // v3.0 使用后端下发 iconName
  10055. if (item.iconName) return resolveIconClass(item.iconName, index);
  10056. return resolveIconClass(null, index);
  10057. };
  10058. //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  10059. const getFooterIcon = (button) => {
  10060. //功能 by xu 20251224
  10061. if (!button) return "menu-base-icon icon-subm";
  10062. const iconNameOrClass =
  10063. button.iconClass || button.iconName || button.icon;
  10064. if (!iconNameOrClass) return "menu-base-icon icon-subm";
  10065. if (
  10066. typeof iconNameOrClass === "string" &&
  10067. iconNameOrClass.indexOf(" ") > -1
  10068. ) {
  10069. return iconNameOrClass;
  10070. }
  10071. return `menu-base-icon ${iconNameOrClass}`;
  10072. };
  10073. //功能: pobj/cobj 扁平结构转换为 children 树结构,兼容原 children 结构 by xu 20251222
  10074. const normalizeMenuList = (rawList) => {
  10075. if (!Array.isArray(rawList) || rawList.length === 0) {
  10076. return [];
  10077. }
  10078. const hasTree = rawList.some(
  10079. (it) => Array.isArray(it?.children) && it.children.length > 0
  10080. );
  10081. if (hasTree) {
  10082. return rawList.map((it) => ({
  10083. ...it,
  10084. __level: 1,
  10085. children: Array.isArray(it.children)
  10086. ? it.children.map((c) => ({ ...c, __level: 2 }))
  10087. : it.children,
  10088. }));
  10089. }
  10090. const hasMarker = rawList.some(
  10091. (it) => it && ("pobj" in it || "cobj" in it)
  10092. );
  10093. if (!hasMarker) {
  10094. return rawList.map((it) => ({ ...it, __level: 1 }));
  10095. }
  10096. const result = [];
  10097. let currentGroup = null;
  10098. for (const item of rawList) {
  10099. //功能: “变动”始终按一级处理(即使后端误传 pobj/cobj)by xu 20251223
  10100. const isChgItem =
  10101. item && (item.title === "变动" || item.name === "sys_bd");
  10102. if (isChgItem) {
  10103. result.push({ ...item, __level: 1 });
  10104. continue;
  10105. }
  10106. const isParent = isTrue(item?.pobj);
  10107. const isChild = isTrue(item?.cobj);
  10108. if (isParent) {
  10109. currentGroup = {
  10110. ...item,
  10111. __level: 1,
  10112. children: [],
  10113. };
  10114. result.push(currentGroup);
  10115. continue;
  10116. }
  10117. if (isChild && currentGroup) {
  10118. currentGroup.children.push({ ...item, __level: 2 });
  10119. continue;
  10120. }
  10121. //功能: 变动等无 pobj/cobj 的选项按一级展示(不挂到 children,也不打断当前分组)by xu 20251223
  10122. result.push({ ...item, __level: 1 });
  10123. }
  10124. return result;
  10125. };
  10126. const menuListComputed = computed(() =>
  10127. normalizeMenuList(props.menuList)
  10128. ); //功能 by xu 20251222
  10129. //功能: 分组展开状态(默认展开),避免 computed 生成对象导致 open 状态丢失 by xu 20251222
  10130. const groupOpenState = reactive({}); // { [key]: boolean }
  10131. const getGroupKey = (item) => item?.name || item?.title || ""; //功能 by xu 20251222
  10132. const isGroupOpen = (item) => {
  10133. //功能 by xu 20251222
  10134. const key = getGroupKey(item);
  10135. if (!key) return true;
  10136. return groupOpenState[key] !== false;
  10137. };
  10138. const toggleGroupOpen = (item) => {
  10139. //功能 by xu 20251222
  10140. const key = getGroupKey(item);
  10141. if (!key) return;
  10142. groupOpenState[key] = !isGroupOpen(item);
  10143. };
  10144. const getLevelClass = (item, fallbackLevel) => {
  10145. //功能 by xu 20251222
  10146. //功能: “变动”始终按一级样式处理 by xu 20251223
  10147. if (item && (item.title === "变动" || item.name === "sys_bd")) {
  10148. return "level-1";
  10149. }
  10150. const level = item?.__level || fallbackLevel || 1;
  10151. return level === 2 ? "level-2" : "level-1";
  10152. };
  10153. // v3.0 新增:菜单模式管理 by xu 20251216
  10154. const menuMode = ref(props.initialMode);
  10155. const isHovering = ref(false);
  10156. const toggleMenuMode = () => {
  10157. menuMode.value = menuMode.value === "collapse" ? "fixed" : "collapse";
  10158. };
  10159. //功能: 提供给旧UI弹窗顶部按钮调用的 API(替代点击 .menu-mode-toggle DOM)by xu 20251224
  10160. const registerSsSubTabApi = () => {
  10161. //功能 by xu 20251224
  10162. try {
  10163. window.SS = window.SS || {};
  10164. window.SS.dom = window.SS.dom || {};
  10165. //功能: 兼容小写 ss 命名空间(部分页面只引用 window.ss)by xu 20251224
  10166. window.ss = window.ss || window.SS;
  10167. window.ss.dom = window.ss.dom || window.SS.dom;
  10168. const api = {
  10169. toggleMenuMode,
  10170. getMenuMode: () => menuMode.value,
  10171. };
  10172. window.SS.dom.ssSubTabApi = api;
  10173. window.ss.dom.ssSubTabApi = api;
  10174. //功能: 多层弹窗(如 objPlay -> objInfo) 场景,将 API 注册到 topWindow 供按钮跨层调用 by xu 20251224
  10175. try {
  10176. const wdDialogId =
  10177. window.wd &&
  10178. wd.display &&
  10179. wd.display.getwdDialogId &&
  10180. wd.display.getwdDialogId();
  10181. if (wdDialogId && window.top) {
  10182. window.top.__ssSubTabApiMap = window.top.__ssSubTabApiMap || {};
  10183. window.top.__ssSubTabApiMap[wdDialogId] = api;
  10184. }
  10185. } catch (e) {}
  10186. try {
  10187. console.log(
  10188. "[SsSubTabApi] registered",
  10189. window.location && window.location.pathname
  10190. );
  10191. } catch (e) {}
  10192. } catch (e) {}
  10193. };
  10194. const unregisterSsSubTabApi = () => {
  10195. //功能 by xu 20251224
  10196. try {
  10197. //功能: 从 topWindow 解绑(避免弹窗关闭后残留)by xu 20251224
  10198. try {
  10199. const wdDialogId =
  10200. window.wd &&
  10201. wd.display &&
  10202. wd.display.getwdDialogId &&
  10203. wd.display.getwdDialogId();
  10204. if (
  10205. wdDialogId &&
  10206. window.top &&
  10207. window.top.__ssSubTabApiMap &&
  10208. window.top.__ssSubTabApiMap[wdDialogId]
  10209. ) {
  10210. delete window.top.__ssSubTabApiMap[wdDialogId];
  10211. }
  10212. } catch (e) {}
  10213. if (window.SS?.dom?.ssSubTabApi?.toggleMenuMode === toggleMenuMode) {
  10214. delete window.SS.dom.ssSubTabApi;
  10215. }
  10216. if (window.ss?.dom?.ssSubTabApi?.toggleMenuMode === toggleMenuMode) {
  10217. delete window.ss.dom.ssSubTabApi;
  10218. }
  10219. } catch (e) {}
  10220. };
  10221. //功能: 立即注册,避免 enable 早于 onMounted 导致“api not ready”by xu 20251224
  10222. registerSsSubTabApi(); //功能 by xu 20251224
  10223. onBeforeUnmount(unregisterSsSubTabApi); //功能 by xu 20251224
  10224. const onMouseEnter = () => {
  10225. if (menuMode.value === "collapse") {
  10226. isHovering.value = true;
  10227. }
  10228. };
  10229. const onMouseLeave = () => {
  10230. isHovering.value = false;
  10231. };
  10232. const isExpanded = computed(() => {
  10233. return menuMode.value === "collapse" && isHovering.value;
  10234. });
  10235. // v3.0 新增:iframe 懒加载,点击才加载 by xu 20251216
  10236. const loadedMenus = ref(new Set());
  10237. const isMenuLoaded = (menuName) => {
  10238. return loadedMenus.value.has(menuName);
  10239. };
  10240. // 根据标题找到对应的菜单项
  10241. const findMenuByTitle = (title) => {
  10242. for (const item of menuListComputed.value) {
  10243. //功能 by xu 20251222
  10244. if (item.children?.length > 0) {
  10245. const child = item.children.find((c) => c.title === title);
  10246. if (child) return child;
  10247. } else if (item.title === title) {
  10248. return item;
  10249. }
  10250. }
  10251. return null;
  10252. };
  10253. // 计算默认选中的菜单项
  10254. const defaultActiveMenu = computed(() => {
  10255. if (props.activeMenu) {
  10256. const menu = findMenuByTitle(props.activeMenu);
  10257. if (menu) return menu;
  10258. }
  10259. const firstItem = menuListComputed.value[0]; //功能 by xu 20251222
  10260. if (!firstItem) return null;
  10261. //功能: 默认选中第一个一级菜单(不默认跳到第一个二级)by xu 20251224
  10262. return firstItem;
  10263. });
  10264. const currentMenu = ref(defaultActiveMenu.value);
  10265. // 监听外部activeMenu变化
  10266. watch(
  10267. () => props.activeMenu,
  10268. (newTitle) => {
  10269. if (newTitle) {
  10270. const menu = findMenuByTitle(newTitle);
  10271. if (menu) {
  10272. currentMenu.value = menu;
  10273. }
  10274. }
  10275. }
  10276. );
  10277. // 初始化:默认选中项加入已加载集合
  10278. watch(
  10279. currentMenu,
  10280. (menu) => {
  10281. if (menu?.name) {
  10282. loadedMenus.value.add(menu.name);
  10283. }
  10284. },
  10285. { immediate: true }
  10286. );
  10287. // 选择菜单项时触发 menu-change 钩子
  10288. const selectItem = (item) => {
  10289. currentMenu.value = item;
  10290. // 标记为已加载
  10291. if (item.name) {
  10292. loadedMenus.value.add(item.name);
  10293. }
  10294. emit("menu-change", item);
  10295. };
  10296. // 处理底部按钮点击
  10297. const handleFooterClick = (button, index) => {
  10298. emit("footer-click", { button, index });
  10299. };
  10300. return {
  10301. menuListComputed, //功能 by xu 20251222
  10302. currentMenu,
  10303. selectItem,
  10304. handleFooterClick,
  10305. getFooterIcon, //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  10306. menuMode,
  10307. isHovering,
  10308. isExpanded,
  10309. toggleMenuMode,
  10310. onMouseEnter,
  10311. onMouseLeave,
  10312. isMenuLoaded,
  10313. getMenuIcon,
  10314. isGroupOpen, //功能 by xu 20251222
  10315. toggleGroupOpen, //功能 by xu 20251222
  10316. getLevelClass, //功能 by xu 20251222
  10317. };
  10318. },
  10319. template: `
  10320. <div class="project-edit-container">
  10321. <div class="left-side"
  10322. v-if="leftDisplay"
  10323. :data-mode="menuMode"
  10324. :class="{ 'is-expanded': isExpanded }"
  10325. @mouseenter="onMouseEnter"
  10326. @mouseleave="onMouseLeave">
  10327. <!-- 菜单内容 -->
  10328. <div class="menu-content">
  10329. <div class="scroll-view">
  10330. <template v-for="(menuItem, i) in menuListComputed" :key="i">
  10331. <!-- 分组菜单 -->
  10332. <div v-if="menuItem.children?.length > 0" class="group">
  10333. <!-- 功能: 一级(pobj)可点击进入,箭头仅控制展开/收起;二级点击不影响一级选中状态 by xu 20251223 -->
  10334. <div class="menu-item"
  10335. :class="[getLevelClass(menuItem, 1), { active: menuItem.name === currentMenu?.name }]"
  10336. @click="selectItem(menuItem)">
  10337. <ss-icon :class="getMenuIcon(menuItem, i)" />
  10338. <span class="menu-label">{{ menuItem.title }}</span>
  10339. <!-- 功能: 一级菜单有子项时显示 dot(参考全局左侧菜单)by xu 20251224 -->
  10340. <div class="has-children-dot"></div>
  10341. <div class="menu-tooltip">{{ menuItem.title }}</div>
  10342. </div>
  10343. <!-- 功能: 二级菜单始终展示,不做收缩展开 by xu 20251223 -->
  10344. <div class="group-detail">
  10345. <div v-for="(item, j) in menuItem.children"
  10346. :key="j"
  10347. class="menu-item"
  10348. :class="[getLevelClass(item, 2), { active: item.name === currentMenu?.name }]"
  10349. @click.stop="selectItem(item)">
  10350. <ss-icon :class="getMenuIcon(item, j)" />
  10351. <span class="menu-label">{{ item.title }}</span>
  10352. </div>
  10353. </div>
  10354. </div>
  10355. <!-- 普通菜单项 -->
  10356. <div v-else
  10357. class="menu-item"
  10358. :class="[getLevelClass(menuItem, 1), { active: menuItem.name === currentMenu?.name }]"
  10359. @click="selectItem(menuItem)">
  10360. <ss-icon :class="getMenuIcon(menuItem, i)" />
  10361. <span class="menu-label">{{ menuItem.title }}</span>
  10362. <div class="menu-tooltip">{{ menuItem.title }}</div>
  10363. </div>
  10364. </template>
  10365. </div>
  10366. </div>
  10367. <!-- 底部按钮 -->
  10368. <div v-if="footerButtons.length > 0"
  10369. class="sub-tab-menu-footer"
  10370. :class="{ 'has-text': !!footerButtons[0].text }"
  10371. @click="footerButtons[0].onclick">
  10372. <ss-icon :class="getFooterIcon(footerButtons[0])" />
  10373. <div class="footer-label" v-if="footerButtons[0].text">{{ footerButtons[0].text }}</div>
  10374. <ss-icon v-if="footerButtons.length > 1" class="footer-arrow" name="arrow-up" size="24px" />
  10375. <div v-if="footerButtons.length > 1" class="sub-tab-menu-popup">
  10376. <div v-for="(button, index) in footerButtons.slice(1)"
  10377. :key="index"
  10378. @click.stop="button.onclick">
  10379. {{ button.text }}
  10380. </div>
  10381. </div>
  10382. </div>
  10383. </div>
  10384. <!-- 右侧内容区域 - 懒加载 iframe -->
  10385. <div class="content-area fit-height-content" style="overflow: hidden;" :style="!leftDisplay ? { width: '100%' } : {}">
  10386. <template v-for="(menuItem, i) in menuList" :key="i">
  10387. <iframe
  10388. v-if="isMenuLoaded(menuItem.name)"
  10389. :src="menuItem.url"
  10390. style="height: 100%;width: 100%;"
  10391. frameborder="0"
  10392. class="sub-tab-iframe"
  10393. :id="i === 0 ? 'sub-tab-iframe' : ''"
  10394. v-show="currentMenu?.name === menuItem.name"
  10395. />
  10396. </template>
  10397. </div>
  10398. </div>
  10399. `,
  10400. };
  10401. // <iframe
  10402. // v-if="currentMenu?.url"
  10403. // :src="currentMenu.url"
  10404. // style="height: 100%;width: 100%;"
  10405. // frameborder="0"
  10406. // id="sub-tab-iframe"
  10407. // />
  10408. // ss-photo-upload 通用图片上传组件
  10409. const SsImgUpload = {
  10410. name: "SsImgUpload",
  10411. props: {
  10412. name: {
  10413. type: String,
  10414. required: true,
  10415. },
  10416. // 图片URL,用于回显
  10417. // url: {
  10418. // type: String,
  10419. // default: "",
  10420. // },
  10421. // 样式类名
  10422. class: {
  10423. type: String,
  10424. required: true,
  10425. },
  10426. // 裁剪配置
  10427. cropperOpt: {
  10428. type: Object,
  10429. default: () => ({
  10430. width: 360,
  10431. height: 360,
  10432. aspectRatio: 1,
  10433. }),
  10434. },
  10435. //上传图片url(未加图片名参数之前的部分)
  10436. ulUrl: {
  10437. type: String,
  10438. required: true,
  10439. },
  10440. //下载图片url(未加图片名参数之前的部分)
  10441. dlUrl: {
  10442. type: String,
  10443. required: true,
  10444. },
  10445. modelValue: [String, Number],
  10446. },
  10447. emits: ["update:modelValue"],
  10448. setup(props, { emit }) {
  10449. const inputId = Vue.computed(
  10450. () => `file_${Vue.getCurrentInstance().uid}`
  10451. );
  10452. //修改图片初始显示路径
  10453. let pathVal = ref(props.modelValue);
  10454. let picUrl = ref("");
  10455. if (props.modelValue) {
  10456. picUrl.value = props.dlUrl + "&path=" + props.modelValue;
  10457. }
  10458. Vue.onMounted(() => {
  10459. window.SS.cropper.init({
  10460. el: $(`#${inputId.value}`),
  10461. photoSize: {
  10462. width: props.cropperOpt.width,
  10463. height: props.cropperOpt.height,
  10464. },
  10465. aspectRatio: props.cropperOpt.aspectRatio,
  10466. uploadUrl: props.ulUrl,
  10467. success: (path) => {
  10468. pathVal.value = path;
  10469. picUrl.value = props.dlUrl + "&path=" + path;
  10470. emit("update:modelValue", path);
  10471. },
  10472. });
  10473. });
  10474. return () =>
  10475. h("div", { class: [props.class] }, [
  10476. h("input", {
  10477. type: "file",
  10478. accept: "image/*",
  10479. id: inputId.value,
  10480. style: { display: "none" },
  10481. }),
  10482. h("input", {
  10483. type: "hidden",
  10484. name: props.name,
  10485. value: pathVal.value,
  10486. }),
  10487. h(
  10488. "div",
  10489. {
  10490. style: {
  10491. width: "100%",
  10492. height: "100%",
  10493. },
  10494. onClick: () => $(`#${inputId.value}`).click(),
  10495. },
  10496. [
  10497. picUrl.value &&
  10498. h("img", {
  10499. src: picUrl.value,
  10500. style:
  10501. "width: 100%; height: 100%;object-fit: inherit;position: relative;z-index: 11;",
  10502. }),
  10503. ]
  10504. ),
  10505. ]);
  10506. },
  10507. };
  10508. // 初始化函数,负责创建和挂载 Vue 应用
  10509. // window.SS = { dom: {} };
  10510. /**
  10511. * 获取当前窗口的父窗口
  10512. * @returns {Window} 父窗口对象
  10513. */
  10514. window.SS.topWin = (function (p, c) {
  10515. while (p != c) {
  10516. c = p;
  10517. p = p.parent;
  10518. }
  10519. return c;
  10520. })(window.parent, window);
  10521. window.SS.createSsDialogInstance = createSsDialogInstance;
  10522. /**
  10523. * 创建弹窗
  10524. * @param {Object} setting
  10525. * @param {Function} callbackEvent
  10526. */
  10527. window.SS.openDialog = function (setting, callbackEvent) {
  10528. if (setting.params) {
  10529. const encodedParams = encodeURIComponent(JSON.stringify(setting.params));
  10530. setting.src +=
  10531. (setting.src.includes("?") ? "&" : "?") + "params=" + encodedParams;
  10532. }
  10533. if (window.parent && window.parent !== window) {
  10534. window.parent.SS.createSsDialogInstance(setting, callbackEvent);
  10535. } else {
  10536. createSsDialogInstance(setting, callbackEvent);
  10537. }
  10538. };
  10539. //关闭弹窗
  10540. window.SS.closeDialog = function () {
  10541. console.log("关闭弹窗");
  10542. if (topWindow.dialogInstances.length > 0) {
  10543. const instance = topWindow.dialogInstances.pop();
  10544. console.log("instance", instance);
  10545. console.log("instance.callbackEvent", instance.callbackEvent);
  10546. console.log(
  10547. "instance.callbackEvent.end",
  10548. typeof instance.callbackEvent === "function"
  10549. );
  10550. if (instance.callbackEvent) {
  10551. // 判断是否有end回调并执行
  10552. if (typeof instance.callbackEvent === "function") {
  10553. instance.callbackEvent();
  10554. }
  10555. if (typeof instance.callbackEvent.end === "function") {
  10556. instance.callbackEvent.end();
  10557. }
  10558. }
  10559. instance.app.unmount(); // 卸载最后一个实例
  10560. if (instance.container && instance.container.parentNode) {
  10561. instance.container.parentNode.removeChild(instance.container); // 移除容器
  10562. }
  10563. }
  10564. };
  10565. /**
  10566. * 裁剪插件
  10567. */
  10568. window.SS.cropper = {
  10569. init: function (setting) {
  10570. if (!window.top.SS) window.top.SS = {};
  10571. // 重要:确保 cropper 对象的完整初始化
  10572. if (!window.top.SS.cropper) {
  10573. window.top.SS.cropper = {
  10574. settings: new Map(),
  10575. _backupSettings: {},
  10576. getSetting: this.getSetting,
  10577. clearSetting: this.clearSetting,
  10578. debug: this.debug,
  10579. };
  10580. } else if (!window.top.SS.cropper.settings) {
  10581. // 如果 cropper 存在但 settings 不存在,重新初始化 settings
  10582. window.top.SS.cropper.settings = new Map();
  10583. window.top.SS.cropper._backupSettings = {};
  10584. }
  10585. const uploaderId = `uploader_${Date.now()}_${Math.random()
  10586. .toString(36)
  10587. .substr(2, 9)}`;
  10588. window.top.SS.cropper.settings.set(uploaderId, setting);
  10589. window.top.SS.cropper._backupSettings[uploaderId] = setting;
  10590. setting.box = setting.box || "1";
  10591. var winSetting = {
  10592. headerTitle: "图片裁剪",
  10593. src: "/js/cropper/cropper.jsp", //原来在"/newUI/page/cropper.jsp" Ben(20251205)
  10594. width: "900",
  10595. height: "500",
  10596. };
  10597. $(setting.el).change(function () {
  10598. if (!window.SS.cropper.verify(setting)) {
  10599. $(setting.el).val(""); // 清空文件选择
  10600. return false;
  10601. }
  10602. var files = this.files;
  10603. if (files && files.length) {
  10604. if (!window.SS.cropper.verifySize($(setting.el)[0], 5)) {
  10605. $(setting.el).val(""); // 清空文件选择
  10606. alert("文件大小不能超过5M,请重新选择");
  10607. return false;
  10608. }
  10609. var URL = window.URL || window.webkitURL;
  10610. var file = files[0];
  10611. setting.file = file;
  10612. if (
  10613. /^image\/\w+$/.test(file.type) &&
  10614. /\.(jpg|jpeg|png|)$/i.test(file.name)
  10615. ) {
  10616. var uploadedImageURL = URL.createObjectURL(file);
  10617. setting.data = uploadedImageURL;
  10618. setting.fileName = file.name;
  10619. // console.log()
  10620. winSetting.params = {
  10621. ...setting,
  10622. uploaderId,
  10623. };
  10624. console.log("ss-componets中change之后的winSetting", winSetting);
  10625. SS.openDialog(winSetting, {
  10626. success: function (win) {
  10627. console.log("裁剪插件成功");
  10628. // win.cropperSetting = setting;
  10629. },
  10630. end: function () {
  10631. console.log("裁剪插件结束");
  10632. $(setting.el).val(""); // 清空文件选择
  10633. },
  10634. });
  10635. } else {
  10636. alert("请选择图片文件,支持jpg、jpeg、png格式");
  10637. }
  10638. }
  10639. });
  10640. return uploaderId;
  10641. },
  10642. verify: function (setting) {
  10643. if (!setting) {
  10644. console.error(" cropper setting is not undefined! ");
  10645. return false;
  10646. }
  10647. if (!setting.el) {
  10648. console.error(" cropper setting.el is not undefined! ");
  10649. return false;
  10650. }
  10651. if (setting.photoSize) {
  10652. if (
  10653. (!setting.photoSize.width && setting.photoSize.height) ||
  10654. (!setting.photoSize.height && setting.photoSize.width)
  10655. ) {
  10656. console.error(
  10657. " cropper setting.photoSize { width, height } is not undefined! "
  10658. );
  10659. return false;
  10660. }
  10661. }
  10662. if (!setting.box) {
  10663. setting.box = "1";
  10664. }
  10665. if (!setting.aspectRatio) {
  10666. setting.aspectRatio = 1 / 1;
  10667. }
  10668. return true;
  10669. },
  10670. verifySize: function (fileEl, maxSize) {
  10671. // 判断是否为IE浏览器: /msie/i.test(navigator.userAgent) 为一个简单正则
  10672. var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  10673. var fileSize = 0;
  10674. if (isIE && !fileEl.files) {
  10675. // IE浏览器
  10676. var filePath = fileEl.value; // 获得上传文件的绝对路径
  10677. var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
  10678. var file = fileSystem.GetFile(filePath);
  10679. fileSize = file.Size; // 文件大小,单位:b
  10680. } else {
  10681. // 非IE浏览器
  10682. fileSize = fileEl.files[0].size;
  10683. }
  10684. var size = fileSize / 1024 / 1024;
  10685. return !(size > maxSize);
  10686. },
  10687. // 获取特定上传组件的setting
  10688. getSetting: function (uploaderId) {
  10689. if (!window.top.SS?.cropper) {
  10690. console.warn("顶层窗口中未找到 SS.cropper");
  10691. return null;
  10692. }
  10693. // 优先从 Map 中获取
  10694. let setting = window.top.SS.cropper.settings.get(uploaderId);
  10695. // 如果 Map 中没有,尝试从备份中获取
  10696. if (!setting && window.top.SS.cropper._backupSettings[uploaderId]) {
  10697. console.log("从备份中恢复 setting");
  10698. setting = window.top.SS.cropper._backupSettings[uploaderId];
  10699. // 恢复到 Map 中
  10700. window.top.SS.cropper.settings.set(uploaderId, setting);
  10701. }
  10702. return setting;
  10703. },
  10704. // 清理特定上传组件的setting
  10705. clearSetting: function (uploaderId) {
  10706. if (!window.top.SS?.cropper) return;
  10707. window.top.SS.cropper.settings.delete(uploaderId);
  10708. delete window.top.SS.cropper._backupSettings[uploaderId];
  10709. console.log(
  10710. "清理设置后的 Map size:",
  10711. window.top.SS.cropper.settings.size
  10712. );
  10713. },
  10714. };
  10715. /**
  10716. * 获取url中的参数
  10717. * @returns {Object}
  10718. */
  10719. window.SS.getQueryParams = function () {
  10720. const params = {};
  10721. const queryString = window.location.search.substring(1);
  10722. const pairs = queryString.split("&");
  10723. for (let i = 0; i < pairs.length; i++) {
  10724. const pair = pairs[i].split("=");
  10725. params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  10726. }
  10727. if (params.params) {
  10728. try {
  10729. params.params = JSON.parse(params.params);
  10730. } catch (e) {
  10731. console.error("Failed to parse params:", e);
  10732. }
  10733. }
  10734. return params;
  10735. };
  10736. /**
  10737. * 创建vue应用
  10738. * @param {Object} config 配置项
  10739. * @values {String} config.el 挂载的元素
  10740. * @values {Boolean} config.isDialogPage 是否是弹窗页面 决定了是否可以使用顶天立地
  10741. * @values {Object} config.vueOptions vue配置项
  10742. * @returns {Object} vue实例
  10743. */
  10744. window.ss = window.ss || window.SS;
  10745. window.ss.dom = window.ss.dom || window.SS.dom;
  10746. window.SS.dom._vueAppSeq =
  10747. window.SS.dom._vueAppSeq || window.ss.dom._vueAppSeq || 0;
  10748. window.SS.dom.vueApps = window.SS.dom.vueApps || window.ss.dom.vueApps || [];
  10749. window.ss.dom._vueAppSeq = window.SS.dom._vueAppSeq;
  10750. window.ss.dom.vueApps = window.SS.dom.vueApps;
  10751. window.SS.dom._registerVueApp = function ({ vm, el, appKey, scope, href }) {
  10752. if (!vm) return null;
  10753. const registry = window.SS.dom.vueApps || (window.SS.dom.vueApps = []);
  10754. const id = `vue-app-${++window.SS.dom._vueAppSeq}`;
  10755. const record = {
  10756. id,
  10757. el: el || "",
  10758. appKey: appKey || "",
  10759. scope: scope || "current",
  10760. href: href || window.location.href,
  10761. createdAt: Date.now(),
  10762. vm,
  10763. win: window,
  10764. };
  10765. registry.push(record);
  10766. window.SS.dom.currentApp = vm;
  10767. window.SS.dom.currentAppRecord = record;
  10768. if (window.ss && window.ss.dom) {
  10769. window.ss.dom.vueApps = registry;
  10770. window.ss.dom._vueAppSeq = window.SS.dom._vueAppSeq;
  10771. window.ss.dom.currentApp = vm;
  10772. window.ss.dom.currentAppRecord = record;
  10773. }
  10774. return record;
  10775. };
  10776. window.SS.dom._getVmData = function (vm) {
  10777. if (!vm) return null;
  10778. return vm.$data || vm;
  10779. };
  10780. window.SS.dom._hasVmKey = function (vm, key) {
  10781. if (!vm || !key) return false;
  10782. const data = window.SS.dom._getVmData(vm);
  10783. return key in vm || (!!data && key in data);
  10784. };
  10785. window.SS.dom._hasVmMethod = function (vm, methodName) {
  10786. return !!(vm && methodName && typeof vm[methodName] === "function");
  10787. };
  10788. window.SS.dom._normalizeBridgeOptions = function (
  10789. options = {},
  10790. defaults = {}
  10791. ) {
  10792. return {
  10793. scope: "chain",
  10794. ...defaults,
  10795. ...options,
  10796. };
  10797. };
  10798. window.SS.dom._matchVueRecord = function (record, options = {}) {
  10799. if (!record || !record.vm) return false;
  10800. if (options.appKey && record.appKey !== options.appKey) return false;
  10801. if (options.el && record.el !== options.el) return false;
  10802. if (options.id && record.id !== options.id) return false;
  10803. if (
  10804. options.dataKey &&
  10805. !window.SS.dom._hasVmKey(record.vm, options.dataKey)
  10806. ) {
  10807. return false;
  10808. }
  10809. if (
  10810. options.methodName &&
  10811. !window.SS.dom._hasVmMethod(record.vm, options.methodName)
  10812. ) {
  10813. return false;
  10814. }
  10815. if (typeof options.predicate === "function") {
  10816. try {
  10817. if (!options.predicate(record.vm, record)) {
  10818. return false;
  10819. }
  10820. } catch (e) {
  10821. return false;
  10822. }
  10823. }
  10824. return true;
  10825. };
  10826. window.SS.dom._getWindowVueRecord = function (targetWindow, options = {}) {
  10827. if (!targetWindow || !targetWindow.SS || !targetWindow.SS.dom) return null;
  10828. const registry = targetWindow.SS.dom.vueApps || [];
  10829. for (let i = registry.length - 1; i >= 0; i--) {
  10830. if (targetWindow.SS.dom._matchVueRecord(registry[i], options)) {
  10831. return registry[i];
  10832. }
  10833. }
  10834. const currentRecord = targetWindow.SS.dom.currentAppRecord;
  10835. if (targetWindow.SS.dom._matchVueRecord(currentRecord, options)) {
  10836. return currentRecord;
  10837. }
  10838. const currentVm = targetWindow.SS.dom.currentApp;
  10839. const fallbackRecord = currentVm
  10840. ? {
  10841. vm: currentVm,
  10842. win: targetWindow,
  10843. el: "",
  10844. appKey: "",
  10845. id: "",
  10846. }
  10847. : null;
  10848. if (targetWindow.SS.dom._matchVueRecord(fallbackRecord, options)) {
  10849. return fallbackRecord;
  10850. }
  10851. return null;
  10852. };
  10853. window.SS.dom.getVueAppRecord = function (options = {}) {
  10854. const scope = options.scope || "current";
  10855. if (scope === "current") {
  10856. return window.SS.dom._getWindowVueRecord(window, options);
  10857. }
  10858. if (scope === "top") {
  10859. try {
  10860. return window.SS.dom._getWindowVueRecord(window.top, options);
  10861. } catch (e) {
  10862. return null;
  10863. }
  10864. }
  10865. if (scope === "parent") {
  10866. try {
  10867. if (window.parent && window.parent !== window) {
  10868. return window.SS.dom._getWindowVueRecord(window.parent, options);
  10869. }
  10870. } catch (e) {
  10871. return null;
  10872. }
  10873. return null;
  10874. }
  10875. if (scope === "chain") {
  10876. let currentWindow = window;
  10877. while (currentWindow) {
  10878. try {
  10879. const record = window.SS.dom._getWindowVueRecord(
  10880. currentWindow,
  10881. options
  10882. );
  10883. if (record) {
  10884. return record;
  10885. }
  10886. } catch (e) {
  10887. return null;
  10888. }
  10889. if (currentWindow === currentWindow.parent) {
  10890. break;
  10891. }
  10892. currentWindow = currentWindow.parent;
  10893. }
  10894. return null;
  10895. }
  10896. return window.SS.dom._getWindowVueRecord(window, options);
  10897. };
  10898. window.SS.dom.getVueApp = function (options = {}) {
  10899. const record = window.SS.dom.getVueAppRecord(options);
  10900. return record ? record.vm : null;
  10901. };
  10902. window.SS.dom.getVmValue = function (key, options = {}) {
  10903. const vm = window.SS.dom.getVueApp(
  10904. window.SS.dom._normalizeBridgeOptions(options, { dataKey: key })
  10905. );
  10906. if (!vm) return undefined;
  10907. return vm[key];
  10908. };
  10909. window.SS.dom.setVmValue = function (key, value, options = {}) {
  10910. const vm = window.SS.dom.getVueApp(
  10911. window.SS.dom._normalizeBridgeOptions(options, { dataKey: key })
  10912. );
  10913. if (!vm) return false;
  10914. vm[key] = value;
  10915. return true;
  10916. };
  10917. window.SS.dom.callVmMethod = function (methodName, args = [], options = {}) {
  10918. const vm = window.SS.dom.getVueApp(
  10919. window.SS.dom._normalizeBridgeOptions(options, { methodName })
  10920. );
  10921. if (!vm || typeof vm[methodName] !== "function") {
  10922. return undefined;
  10923. }
  10924. return vm[methodName].apply(vm, args);
  10925. };
  10926. window.SS.dom.get = function (key, options = {}) {
  10927. return window.SS.dom.getVmValue(key, options);
  10928. };
  10929. window.SS.dom.set = function (key, value, options = {}) {
  10930. return window.SS.dom.setVmValue(key, value, options);
  10931. };
  10932. window.SS.dom.call = function (methodName, args = [], options = {}) {
  10933. return window.SS.dom.callVmMethod(methodName, args, options);
  10934. };
  10935. [
  10936. "_registerVueApp",
  10937. "_getVmData",
  10938. "_hasVmKey",
  10939. "_hasVmMethod",
  10940. "_normalizeBridgeOptions",
  10941. "_matchVueRecord",
  10942. "_getWindowVueRecord",
  10943. "getVueAppRecord",
  10944. "getVueApp",
  10945. "getVmValue",
  10946. "setVmValue",
  10947. "callVmMethod",
  10948. "get",
  10949. "set",
  10950. "call",
  10951. ].forEach((name) => {
  10952. window.ss.dom[name] = window.SS.dom[name];
  10953. });
  10954. window.SS.dom.initializeFormApp = function (config) {
  10955. const {
  10956. el,
  10957. isDialogPage = false,
  10958. appKey = "",
  10959. scope = "current",
  10960. ...vueOptions
  10961. } = config;
  10962. const app = createApp({
  10963. ...vueOptions,
  10964. });
  10965. if (isDialogPage) {
  10966. function checkScroll() {
  10967. const elements = document.querySelectorAll(".fit-height-content");
  10968. let hasScrollBar = false;
  10969. elements.forEach((el) => {
  10970. if (el.scrollHeight > el.clientHeight) {
  10971. hasScrollBar = true;
  10972. }
  10973. });
  10974. window.parent.postMessage({ hasScrollBar }, "*");
  10975. }
  10976. function addScrollListeners() {
  10977. const elements = document.querySelectorAll("div");
  10978. elements.forEach((el) => {
  10979. el.addEventListener("scroll", checkScroll);
  10980. });
  10981. }
  10982. const observer = new MutationObserver(() => {
  10983. addScrollListeners();
  10984. checkScroll();
  10985. });
  10986. observer.observe(document.body, {
  10987. childList: true,
  10988. subtree: true,
  10989. });
  10990. window.addEventListener("resize", checkScroll);
  10991. }
  10992. app.component("SsLoginIcon", SsLoginIcon);
  10993. app.component("SsMark", SsMark);
  10994. app.component("SsFullStyleHeader", SsFullStyleHeader);
  10995. app.component("SsDialog", SsDialog);
  10996. app.component("SsInp", SsInput);
  10997. app.component("SsObjp", SsObjp);
  10998. app.component("SsHidden", SsHidden);
  10999. app.component("SsCcp", SsCcp);
  11000. app.component("SsDatePicker", SsDatePicker);
  11001. app.component("SsIcon", SsIcon);
  11002. app.component("SsCommonIcon", SsCommonIcon);
  11003. app.component("SsBreadcrumb", SsBreadcrumb);
  11004. app.component("SsEditor", SsEditor);
  11005. app.component("SsDialogIcon", SsDialogIcon);
  11006. app.component("SsBottomButton", SsBottomButton);
  11007. app.component("ss-btn", SsBottomButton);
  11008. app.component("SsNavIcon", SsNavIcon);
  11009. app.component("SsHeaderIcon", SsHeaderIcon);
  11010. app.component("SsGolbalMenuIcon", SsGolbalMenuIcon);
  11011. app.component("SsCartListIcon", SsCartListIcon);
  11012. app.component("SsQuickIcon", SsQuickIcon);
  11013. app.component("SsFormIcon", SsFormIcon);
  11014. app.component("SsBottomDivIcon", SsBottomDivIcon);
  11015. app.component("SsEditorIcon", SsEditorIcon);
  11016. app.component("SsValidate", SsValidate);
  11017. app.component("SsOnoff", Ssonoff);
  11018. app.component("SsonoffArray", SsonoffArray);
  11019. app.component("SsTextarea", SsTextarea);
  11020. app.component("SsLoginInput", SsLoginInput);
  11021. app.component("SsLoginButton", SsLoginButton);
  11022. app.component("SsSearch", SsSearch);
  11023. app.component("SsCartItem", SsCartItem);
  11024. app.component("SsCartItem2", SsCartItem2);
  11025. app.component("SsListCard", SsListCard);
  11026. app.component("ss-cobj-card-list", SsCObjCardList);
  11027. app.component("SsFolderCard", SsFolderCard);
  11028. app.component("ss-sidebar", SsSidebar);
  11029. app.component("ss-sidebar-buttons", SsSidebarButtons);
  11030. app.component("ss-sidebar-chart", SsSidebarChart);
  11031. app.component("ss-sidebar-chart-hover", SsSidebarChartHover);
  11032. app.component("ss-sidebar-list", SsSidebarList);
  11033. app.component("ss-sidebar-report-table", SsSidebarReportTable);
  11034. app.component("SsFolderCartView", SsFolderCartView);
  11035. app.component("SsPage", SsPage);
  11036. app.component("SsRightInfo", SSRightInfo);
  11037. app.component("SsSuccessPopup", SsSuccessPopup);
  11038. app.component("SsErrorDialog", SsErrorDialog);
  11039. app.component("SsVerify", SsVerify);
  11040. app.component("SsVerifyNode", SsVerifyNode);
  11041. app.component("SsOrcImgBox", SsOrcImgBox);
  11042. app.component("ss-search-input", SsSearchInput);
  11043. app.component("ss-search-date-picker", SsSearchDatePicker);
  11044. app.component("ss-search-button", SsSearchButton);
  11045. app.component("ss-drop-button", SsDropButton);
  11046. app.component("ss-sub-tab", SsSubTab);
  11047. app.component("ss-img", SsImgUpload);
  11048. app.use(ElementPlus, {
  11049. locale: ElementPlusLocaleZhCn,
  11050. });
  11051. for (const componentName in IndexComponents) {
  11052. app.component(componentName, IndexComponents[componentName]);
  11053. }
  11054. for (const componentName in EchartComponents) {
  11055. app.component(componentName, EchartComponents[componentName]);
  11056. }
  11057. let vm;
  11058. try {
  11059. vm = app.mount(el);
  11060. vm.data = vueOptions.data();
  11061. window.SS.dom._registerVueApp({
  11062. vm,
  11063. el,
  11064. appKey,
  11065. scope,
  11066. href: window.location.href,
  11067. });
  11068. console.log("vm:", vm);
  11069. console.log("vueOptions:", vueOptions);
  11070. } catch (error) {
  11071. console.log("Mount failed:" + error);
  11072. }
  11073. return vm;
  11074. };
  11075. })();