ss-components.js 420 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892
  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. onchange: {
  1670. type: String,
  1671. required: false,
  1672. },
  1673. //级联菜单配置参数,如果是数组,则代表本下拉菜单是多套级联菜单共用的第一级菜单。如果是对象,则只有一套级联菜单用此下拉菜单。
  1674. param: {
  1675. type: String,
  1676. required: true,
  1677. },
  1678. //向后台拿数据的url
  1679. url: {
  1680. type: String,
  1681. required: true,
  1682. },
  1683. },
  1684. emits: ["update:modelValue", "change"],
  1685. setup(props, { emit }) {
  1686. const canInput = props.inp === true;
  1687. const inputText = Vue.ref("");
  1688. const filteredOptions = Vue.ref(props.opt);
  1689. const visibleOptions = Vue.computed(() =>
  1690. canInput ? filteredOptions.value : props.opt
  1691. );
  1692. let inputRequestId = 0;
  1693. // alert('级联菜单初始化:'+props.name+':--:'+props.modelValue);
  1694. const selectItem = Vue.ref({ label: props.placeholder, value: "" });
  1695. const popupWinVisible = Vue.ref(false);
  1696. const isAutoEcho = Vue.ref(false); // 用于标记是否是自动回显
  1697. const upperValue = Vue.ref(""); //上级下拉菜单当前值,在初始化下拉菜单默认值时,和上级下拉菜单的值变化时,修改此upperValue变量
  1698. const popupDirection = Vue.ref("bottom");
  1699. const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
  1700. const selectContainerRef = Vue.ref(null);
  1701. const popupRef = Vue.ref(null);
  1702. const teleportRootStyle = Vue.ref({
  1703. position: "fixed",
  1704. left: "0",
  1705. top: "0",
  1706. width: "0",
  1707. height: "0",
  1708. zIndex: 9999,
  1709. pointerEvents: "none",
  1710. });
  1711. const popupLayerStyle = Vue.ref({
  1712. position: "fixed",
  1713. left: "0",
  1714. top: "0",
  1715. bottom: "auto",
  1716. minWidth: "0",
  1717. zIndex: 9999,
  1718. pointerEvents: "auto",
  1719. });
  1720. //有隐藏字段的下拉菜单,加载菜单项并展开事件
  1721. // 被上级下拉菜单选中值后,触发本下拉菜单刷新菜单项并弹出显示
  1722. window.addEventListener("cascader-open-" + props.name, async (event) => {
  1723. const { upperVal } = event.detail;
  1724. upperValue.value = upperVal;
  1725. console.log(
  1726. "22props.name:" +
  1727. props.name +
  1728. ",22props.upperValue:" +
  1729. upperValue.value
  1730. );
  1731. selectItem.value = ""; //清除本下拉菜单当前选中的值
  1732. inputText.value = "";
  1733. filteredOptions.value = props.opt;
  1734. emit("update:modelValue", ""); //通知父级
  1735. //清空下拉菜单,并设置第一项的值为placeholder
  1736. clearAndInit1stOpt();
  1737. //下个下拉菜单名
  1738. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1739. if (nextSelName) {
  1740. //清下个下拉菜单选中值和选项
  1741. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  1742. detail: {},
  1743. });
  1744. window.dispatchEvent(event);
  1745. }
  1746. showPopup();
  1747. });
  1748. //设置mode2的下级下拉菜单的上级菜单当前值
  1749. function setNextSelectUpperValue() {
  1750. //设置下级菜单的上级菜单当前值upperValue
  1751. let paramArr = undefined;
  1752. if (Array.isArray(props.param)) {
  1753. paramArr = props.param;
  1754. } else {
  1755. paramArr = [];
  1756. paramArr.push(props.param);
  1757. }
  1758. for (const oneParam of paramArr) {
  1759. //下个下拉菜单名
  1760. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  1761. if (nextSelName) {
  1762. setTimeout(() => {
  1763. const openNextEvent = new CustomEvent(
  1764. "cascade-setUpperVal-" + nextSelName,
  1765. {
  1766. detail: {
  1767. upperVal: props.modelValue,
  1768. },
  1769. }
  1770. );
  1771. window.dispatchEvent(openNextEvent);
  1772. }, 100);
  1773. }
  1774. } // end for
  1775. }
  1776. // 把上级 级联下拉菜单的值,设置进本组件的事件
  1777. window.addEventListener("cascade-setUpperVal-" + props.name, (event) => {
  1778. // alert('props.name:'+props.name+',props.upperValue:'+event.detail.upperVal);
  1779. const { upperVal } = event.detail;
  1780. upperValue.value = upperVal;
  1781. // console.log('props.name:'+props.name+',props.upperValue:'+upperValue.value);
  1782. });
  1783. //清空下拉菜单,并设置第一项的值为空
  1784. function clearAndInit1stOpt() {
  1785. if (props.opt)
  1786. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  1787. else {
  1788. props.opt = [];
  1789. }
  1790. props.opt.push({ label: "", value: "" });
  1791. }
  1792. // 兼容旧版 Map 结果和新版 List<Map> 结果,避免下拉项显示为 [object Object]
  1793. function normalizeCcpResult(result) {
  1794. const normalized = [];
  1795. if (!result) {
  1796. return normalized;
  1797. }
  1798. if (Array.isArray(result)) {
  1799. result.forEach((item) => {
  1800. if (!item || typeof item !== "object") {
  1801. return;
  1802. }
  1803. const entry = Object.entries(item)[0];
  1804. if (!entry) {
  1805. return;
  1806. }
  1807. normalized.push({
  1808. label: entry[1],
  1809. value: entry[0],
  1810. });
  1811. });
  1812. return normalized;
  1813. }
  1814. Object.keys(result).forEach((key) => {
  1815. normalized.push({
  1816. label: result[key],
  1817. value: key,
  1818. });
  1819. });
  1820. return normalized;
  1821. }
  1822. //获取下一级下拉菜单,如果下一级下拉菜单不存在,则返回undefined
  1823. function getNextSel(selName, selNameArr) {
  1824. // 检查参数有效性
  1825. if (!Array.isArray(selNameArr) || selNameArr.length === 0) {
  1826. return undefined;
  1827. }
  1828. // 查找当前元素的索引
  1829. const currentIndex = selNameArr.indexOf(selName);
  1830. // 如果元素不存在或已经是最后一个元素,返回undefined
  1831. if (currentIndex === -1 || currentIndex === selNameArr.length - 1) {
  1832. return undefined;
  1833. }
  1834. // 返回下一个元素
  1835. return selNameArr[currentIndex + 1];
  1836. }
  1837. const validate = () => {
  1838. if (window.ssVm) {
  1839. return window.ssVm.validateField(props.name);
  1840. }
  1841. return { valid: true };
  1842. };
  1843. const updateSelectItem = () => {
  1844. const item = props.opt.find((it) => it.value === props.modelValue);
  1845. if (item) {
  1846. selectItem.value = item;
  1847. inputText.value = item.label;
  1848. } else {
  1849. selectItem.value = { label: "", value: "" };
  1850. inputText.value = "";
  1851. }
  1852. };
  1853. // 处理选择事件
  1854. const doSelectItem = (item) => {
  1855. selectItem.value = item;
  1856. inputText.value = item.label;
  1857. emit("update:modelValue", item.value); //修改本下拉菜单在vue中保存的值
  1858. // alert('item.value:'+item.value);
  1859. if (props.mode === "1") {
  1860. // mode 1 模式:修改隐藏字段值
  1861. let event = new CustomEvent(
  1862. "cascader-setHiddenVal-" + props.param.combField,
  1863. {
  1864. detail: {
  1865. value: item.value,
  1866. },
  1867. }
  1868. );
  1869. window.dispatchEvent(event);
  1870. }
  1871. emit("change", item.value); //触发配置的change方法
  1872. if (props.onchange && typeof props.onchange === "string") {
  1873. if (
  1874. typeof window !== "undefined" &&
  1875. window[props.onchange] &&
  1876. typeof window[props.onchange] === "function"
  1877. ) {
  1878. try {
  1879. window[props.onchange](item.value, item.label);
  1880. } catch (error) {
  1881. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  1882. }
  1883. }
  1884. }
  1885. nextTick(() => {
  1886. validate();
  1887. if (window.ssVm) {
  1888. for (const [field, rules] of window.ssVm.validations.entries()) {
  1889. for (const rule of rules) {
  1890. if (rule.options?.relField) {
  1891. const relFields = String(rule.options.relField)
  1892. .split(",")
  1893. .map((name) => name.trim())
  1894. .filter(Boolean);
  1895. if (relFields.includes(props.name)) {
  1896. window.ssVm.validateField(field);
  1897. }
  1898. }
  1899. }
  1900. }
  1901. }
  1902. });
  1903. //设置下级菜单的上级菜单当前值upperValue
  1904. let paramArr = undefined;
  1905. if (Array.isArray(props.param)) {
  1906. paramArr = props.param;
  1907. } else {
  1908. paramArr = [];
  1909. paramArr.push(props.param);
  1910. }
  1911. for (const oneParam of paramArr) {
  1912. //下个下拉菜单名
  1913. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  1914. if (nextSelName) {
  1915. setTimeout(() => {
  1916. const openNextEvent = new CustomEvent(
  1917. "cascader-open-" + nextSelName,
  1918. {
  1919. detail: {
  1920. upperVal: item.value,
  1921. },
  1922. }
  1923. );
  1924. window.dispatchEvent(openNextEvent);
  1925. }, 100);
  1926. }
  1927. } // end for
  1928. hidePopup();
  1929. //下个下拉菜单名
  1930. // let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1931. // if(nextSelName){
  1932. // // //设置下一级下拉菜单中保存的本下拉菜单值(upperValue)
  1933. // // event = new CustomEvent('cascade-setUpperVal-'+nextSelName, {
  1934. // // detail: {
  1935. // // value: item.value
  1936. // // }
  1937. // // });
  1938. // // window.dispatchEvent(event);
  1939. //
  1940. // //触发下一级下拉菜单,重新初始化下拉菜单项并弹出显示
  1941. // event = new CustomEvent('cascader-open-' +nextSelName, {
  1942. // detail: {
  1943. // upperVal: item.value
  1944. // }
  1945. // });
  1946. // window.dispatchEvent(event);
  1947. // }
  1948. // 只在手动选择时自动展开下一级
  1949. // if (!isAutoEcho.value) {
  1950. // const nextLevel = props.level + 1;
  1951. // setTimeout(() => {
  1952. // const openNextEvent = new CustomEvent('open-next-cascader', {
  1953. // detail: {
  1954. // name: props.name,
  1955. // level: nextLevel
  1956. // }
  1957. // });
  1958. // window.dispatchEvent(openNextEvent);
  1959. // }, 100);
  1960. // }
  1961. };
  1962. // 监听下一级展开事件 (仅 mode 2)
  1963. window.addEventListener("cascade-open", (event) => {
  1964. if (props.mode === "2") {
  1965. const { level } = event.detail;
  1966. if (level === props.level) {
  1967. popupWinVisible.value = true;
  1968. }
  1969. }
  1970. });
  1971. if (props.mode === "1") {
  1972. //如果是有隐藏字段的下拉菜单
  1973. // 监听回显事件
  1974. window.addEventListener(
  1975. "cascader-echo-" + props.name,
  1976. async (event) => {
  1977. const { name, value, isAuto, upperVal } = event.detail;
  1978. // level,
  1979. if (upperVal) {
  1980. upperValue.value = upperVal;
  1981. console.log(
  1982. "value:" +
  1983. value +
  1984. ",upperValue:" +
  1985. upperValue +
  1986. ",初始化级联组件时props.name:" +
  1987. props.name
  1988. );
  1989. }
  1990. // if (name === props.name && level === props.level) {
  1991. // 设置自动回显标记
  1992. isAutoEcho.value = true;
  1993. // if (props.opt.length === 0) {
  1994. // const loadDataEvent = new CustomEvent('cascader-load-data', {
  1995. // detail: {
  1996. // name: props.name,
  1997. // level: props.level,
  1998. // value: value
  1999. // }
  2000. // });
  2001. // window.dispatchEvent(loadDataEvent);
  2002. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  2003. //Vue.watch用于监听数据的变化,并在数据变化时执行特定的回调函数。
  2004. //这段代码使用了 Vue.js 的 watch API 来监听 props.opt 的变化,如果props.opt有变化,则自动
  2005. // const unwatch = Vue.watch(
  2006. // () => props.opt, // 监听的数据源(props.opt)
  2007. // (newOptions) => { // 回调函数
  2008. // if (newOptions.length > 0) { // 条件判断
  2009. // matchAndSelect(value); // 执行逻辑
  2010. // unwatch(); // 停止监听
  2011. // }
  2012. // },
  2013. // { immediate: true } // 配置:立即触发一次
  2014. // );
  2015. // } else {
  2016. // matchAndSelect(value);
  2017. // }
  2018. // 初始化级联菜单在页面刚打开时的默认值
  2019. async function initDefaultValue(value) {
  2020. try {
  2021. // alert(1);
  2022. if (
  2023. props.url &&
  2024. props.param
  2025. // && props.modelValue 对于有rule编码规则的级联菜单(即mode=1),modelValue一定是空的,所以注释掉,修复mode=1的级联菜单无法回显问题。Ben(20251124)
  2026. ) {
  2027. // alert(2);
  2028. /**
  2029. * let objectPickerParam=
  2030. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  2031. * "\"name\":\"hksheng\"," +
  2032. * "\"cascadingName\":\"dq\",\"cascadingInputsName\":\"hkdqm\"," +
  2033. * "\"codebook\":\"sheng\"}",
  2034. * "objectpickertype":2,
  2035. * "objectpickervalue":"440000"
  2036. * };
  2037. */
  2038. const objectPickerParam = {
  2039. input: "false",
  2040. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2041. name: props.name, //本下拉菜单名
  2042. cascadingName: props.param.name, //级联菜单名
  2043. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  2044. codebook: props.param.codebook,
  2045. };
  2046. const objectPickerParamStr =
  2047. JSON.stringify(objectPickerParam);
  2048. const params = new URLSearchParams();
  2049. params.append("objectpickerparam", objectPickerParamStr);
  2050. params.append("objectpickertype", "2");
  2051. params.append("objectpickervalue", value); //需回显的值
  2052. axios
  2053. .post(props.url, params, {
  2054. headers: {
  2055. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2056. },
  2057. })
  2058. .then((response) => {
  2059. // alert(JSON.stringify(response.data));
  2060. if ("timeout" == response.data.statusText) {
  2061. alert("网络超时!");
  2062. return;
  2063. }
  2064. if (response.data.result) {
  2065. const normalizedResult = normalizeCcpResult(
  2066. response.data.result
  2067. );
  2068. if (normalizedResult.length === 1) {
  2069. const option = normalizedResult[0];
  2070. clearAndInit1stOpt();
  2071. props.opt.push(option);
  2072. if (value) matchAndSelect(value);
  2073. // updateSelectItem();
  2074. // alert('props.opt:'+JSON.stringify(props.opt));
  2075. }
  2076. }
  2077. });
  2078. }
  2079. } catch (error) {
  2080. alert(error);
  2081. // callback(null, error.message); // 失败回调,传递错误
  2082. }
  2083. }
  2084. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  2085. initDefaultValue(value);
  2086. // 延迟重置自动回显标记
  2087. setTimeout(() => {
  2088. isAutoEcho.value = false;
  2089. }, 500);
  2090. }
  2091. );
  2092. // 被上级下拉菜单触发的,清除选中值和下拉菜单选项
  2093. window.addEventListener(
  2094. "cascader-cleanOpt-" + props.name,
  2095. async (event) => {
  2096. upperValue.value = "";
  2097. selectItem.value = ""; //清除本下拉菜单当前选中的值
  2098. inputText.value = "";
  2099. filteredOptions.value = props.opt;
  2100. emit("update:modelValue", ""); //通知父级
  2101. //清空所有下拉菜单项
  2102. if (props.opt) {
  2103. props.opt.length = 0;
  2104. } else {
  2105. props.opt = [];
  2106. }
  2107. //下个下拉菜单名
  2108. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  2109. // alert('nextSelName:'+nextSelName+'--,props.name:'+props.name);
  2110. if (nextSelName) {
  2111. //清下个下拉菜单选中值和选项
  2112. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  2113. detail: {},
  2114. });
  2115. window.dispatchEvent(event);
  2116. }
  2117. }
  2118. );
  2119. } else if (props.mode === "2") {
  2120. //没隐藏字段的下拉菜单,在这初始化默认值
  2121. let needInitParam = undefined;
  2122. if (Array.isArray(props.param)) {
  2123. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  2124. console.log("needInitParam最后一项:" + JSON.stringify(needInitParam));
  2125. } else {
  2126. needInitParam = props.param;
  2127. }
  2128. // 初始化级联菜单在页面刚打开时的默认值
  2129. async function initDefaultValue(value, param) {
  2130. try {
  2131. // alert(1);
  2132. if (props.url && param && props.modelValue) {
  2133. // alert(2);
  2134. /**
  2135. * let param=
  2136. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"rylbm,gwid\"," +
  2137. * "\"name\":\"gwid\",\"cascadingName\":\"rylb_gw\"," +
  2138. * "\"codebook\":\"gwByRylb\"}",
  2139. * "objectpickertype":2,
  2140. * "objectpickervalue":"102121"};
  2141. */
  2142. // alert('props.name:'+props.name+',props.param.fieldOrd:'+props.param.fieldOrd);
  2143. const objectPickerParam = {
  2144. input: "false",
  2145. cascadingLevel: param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2146. name: props.name, //本下拉菜单名
  2147. cascadingName: param.name, //级联菜单名
  2148. codebook: param.codebook,
  2149. };
  2150. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2151. const sendParams = new URLSearchParams();
  2152. sendParams.append("objectpickerparam", objectPickerParamStr);
  2153. sendParams.append("objectpickertype", "2");
  2154. sendParams.append("objectpickervalue", value); //需回显的值
  2155. axios
  2156. .post(props.url, sendParams, {
  2157. headers: {
  2158. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2159. },
  2160. })
  2161. .then((response) => {
  2162. // alert(JSON.stringify(response.data));
  2163. if ("timeout" == response.data.statusText) {
  2164. alert("网络超时!");
  2165. return;
  2166. }
  2167. if (response.data.result) {
  2168. const normalizedResult = normalizeCcpResult(
  2169. response.data.result
  2170. );
  2171. console.log(
  2172. "name:" +
  2173. props.name +
  2174. ",@@级联初始化默认值value:" +
  2175. value +
  2176. "--param:" +
  2177. JSON.stringify(param) +
  2178. "--objectPickerParamStr:" +
  2179. objectPickerParamStr +
  2180. "--response.data:" +
  2181. JSON.stringify(response.data)
  2182. );
  2183. if (normalizedResult.length === 1) {
  2184. const option = normalizedResult[0];
  2185. if (props.opt)
  2186. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  2187. else {
  2188. props.opt = [];
  2189. }
  2190. props.opt.push(option);
  2191. if (value) matchAndSelect(value);
  2192. console.log(
  2193. "GOOD mode2回显的默认值:" +
  2194. JSON.stringify(option) +
  2195. "--props.param:" +
  2196. JSON.stringify(param)
  2197. );
  2198. // updateSelectItem();
  2199. // alert('props.opt:'+JSON.stringify(props.opt));
  2200. }
  2201. }
  2202. });
  2203. }
  2204. } catch (error) {
  2205. alert(error);
  2206. // callback(null, error.message); // 失败回调,传递错误
  2207. }
  2208. // 重置自动回显标记
  2209. isAutoEcho.value = false;
  2210. }
  2211. // 初始化级联菜单在页面刚打开时的默认值
  2212. initDefaultValue(props.modelValue, needInitParam);
  2213. //设置mode2的下级下拉菜单的上级菜单当前值
  2214. setNextSelectUpperValue();
  2215. }
  2216. //选中要回显的默认值
  2217. const matchAndSelect = (value) => {
  2218. const matchedOption = props.opt.find((opt) => opt.value === value);
  2219. if (matchedOption) {
  2220. selectItem.value = matchedOption;
  2221. inputText.value = matchedOption.label;
  2222. emit("update:modelValue", value);
  2223. emit("change", value);
  2224. }
  2225. };
  2226. async function updateOptionBYInputText(inputValue) {
  2227. const pickerParam = Array.isArray(props.param)
  2228. ? props.param[props.param.length - 1]
  2229. : props.param;
  2230. if (!props.url || !pickerParam || !pickerParam.codebook) return;
  2231. const requestId = ++inputRequestId;
  2232. const searchText = inputValue || "";
  2233. const searchAll = searchText.trim().length === 0;
  2234. let url = props.url;
  2235. const filterObj = {
  2236. ...(pickerParam.filter && typeof pickerParam.filter === "object"
  2237. ? pickerParam.filter
  2238. : {}),
  2239. };
  2240. Object.keys(filterObj).forEach((key) => {
  2241. url += "&" + key + "=" + encodeURIComponent(filterObj[key]);
  2242. });
  2243. if (pickerParam.filterfield) {
  2244. const filterFields = String(pickerParam.filterfield).split(",");
  2245. filterFields.forEach((fieldName) => {
  2246. const fields = document.getElementsByName(fieldName);
  2247. if (!fields || fields.length < 1) {
  2248. console.warn("下拉菜单配置的过滤条件" + fieldName + "不存在");
  2249. return;
  2250. }
  2251. const field = Array.from(fields).find((item) => item.value);
  2252. if (field) {
  2253. url += "&" + fieldName + "=" + encodeURIComponent(field.value);
  2254. filterObj[fieldName] = field.value;
  2255. }
  2256. });
  2257. }
  2258. const objectPickerParam = {
  2259. ...filterObj,
  2260. input: props.inp,
  2261. codebook: pickerParam.codebook,
  2262. cascadingLevel: Array.isArray(pickerParam.fieldOrd)
  2263. ? pickerParam.fieldOrd.join(",")
  2264. : pickerParam.fieldOrd || "",
  2265. name: props.name,
  2266. cascadingName: pickerParam.name,
  2267. };
  2268. if (pickerParam.combField) {
  2269. objectPickerParam.cascadingInputsName = pickerParam.combField;
  2270. }
  2271. const params = new URLSearchParams();
  2272. params.append("objectpickerparam", JSON.stringify(objectPickerParam));
  2273. params.append("objectpickertype", "1");
  2274. params.append("objectpickersearchAll", searchAll ? "1" : "0");
  2275. params.append("objectpickerinput", searchAll ? "" : searchText);
  2276. if (!searchAll) {
  2277. url += "&objectpickerinput=" + encodeURIComponent(searchText);
  2278. }
  2279. if (upperValue.value) {
  2280. params.append("upperValue", upperValue.value);
  2281. }
  2282. try {
  2283. const response = await axios.post(url, params, {
  2284. headers: {
  2285. "Content-Type": "application/x-www-form-urlencoded",
  2286. },
  2287. });
  2288. if (requestId !== inputRequestId) return;
  2289. if (response.data.statusText === "timeout") {
  2290. alert("网络超时!");
  2291. return;
  2292. }
  2293. const normalizedResult = normalizeCcpResult(response.data.result);
  2294. props.opt.length = 0;
  2295. normalizedResult.forEach((option) => props.opt.push(option));
  2296. const matchedOptions = searchAll
  2297. ? normalizedResult
  2298. : normalizedResult.filter((option) =>
  2299. String(option.label)
  2300. .toLowerCase()
  2301. .includes(searchText.toLowerCase())
  2302. );
  2303. filteredOptions.value = matchedOptions.length
  2304. ? [{ label: "", value: "" }, ...matchedOptions]
  2305. : [];
  2306. openPopup();
  2307. } catch (error) {
  2308. console.error("[SsCcp] 输入筛选失败:", error);
  2309. }
  2310. }
  2311. // 计算弹出方向和最大高度的方法 by xu 20251212
  2312. // 当空间不足时限制popup高度并显示滚动条
  2313. const calculatePopupDirection = () => {
  2314. const triggerEl =
  2315. selectContainerRef.value?.querySelector(".input") ||
  2316. selectContainerRef.value;
  2317. if (!triggerEl) return;
  2318. // 2. 获取位置信息
  2319. const selectRect = triggerEl.getBoundingClientRect();
  2320. const viewportHeight = window.innerHeight;
  2321. // 3. 计算上下可用空间 by xu 20251212
  2322. const spaceBelow = viewportHeight - selectRect.bottom - 10; // 减10px留边距
  2323. const spaceAbove = selectRect.top - 10; // 减10px留边距
  2324. // 4. popup预估高度(假设每项36px,最多显示8项 + padding)
  2325. const estimatedPopupHeight = 300;
  2326. const minPopupHeight = 100; // 最小高度
  2327. console.log(
  2328. "[popup] 空间计算 - spaceAbove:",
  2329. spaceAbove,
  2330. "spaceBelow:",
  2331. spaceBelow,
  2332. "estimatedHeight:",
  2333. estimatedPopupHeight
  2334. );
  2335. // 5. 判断方向和最大高度 by xu 20251212
  2336. if (spaceBelow >= estimatedPopupHeight) {
  2337. // 下方空间足够,向下展开,不限制高度
  2338. popupDirection.value = "bottom";
  2339. popupMaxHeight.value = "none";
  2340. console.log("[popup] 向下展开,空间充足");
  2341. } else if (spaceAbove >= estimatedPopupHeight) {
  2342. // 上方空间足够,向上展开,不限制高度
  2343. popupDirection.value = "top";
  2344. popupMaxHeight.value = "none";
  2345. console.log("[popup] 向上展开,空间充足");
  2346. } else {
  2347. // 上下空间都不足,选择空间大的方向,并限制高度出滚动条
  2348. if (spaceBelow >= spaceAbove) {
  2349. popupDirection.value = "bottom";
  2350. popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px";
  2351. console.log(
  2352. "[popup] 向下展开,空间不足,限制高度:",
  2353. popupMaxHeight.value
  2354. );
  2355. } else {
  2356. popupDirection.value = "top";
  2357. popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px";
  2358. console.log(
  2359. "[popup] 向上展开,空间不足,限制高度:",
  2360. popupMaxHeight.value
  2361. );
  2362. }
  2363. }
  2364. };
  2365. const updatePopupPosition = () => {
  2366. const triggerEl =
  2367. selectContainerRef.value?.querySelector(".input") ||
  2368. selectContainerRef.value;
  2369. if (!triggerEl) return;
  2370. const triggerRect = triggerEl.getBoundingClientRect();
  2371. const margin = 10;
  2372. const viewportWidth = window.innerWidth;
  2373. const viewportHeight = window.innerHeight;
  2374. const popupGap = 0;
  2375. popupLayerStyle.value = {
  2376. position: "fixed",
  2377. left: `${Math.max(margin, triggerRect.left)}px`,
  2378. top: `${Math.max(margin, triggerRect.bottom + popupGap)}px`,
  2379. bottom: "auto",
  2380. minWidth: `${Math.max(0, triggerRect.width)}px`,
  2381. zIndex: 9999,
  2382. pointerEvents: "auto",
  2383. };
  2384. Vue.nextTick(() => {
  2385. const popupEl = popupRef.value;
  2386. if (!popupEl) return;
  2387. const popupRect = popupEl.getBoundingClientRect();
  2388. const maxLeft = viewportWidth - popupRect.width - margin;
  2389. const left = Math.min(
  2390. Math.max(margin, triggerRect.left),
  2391. Math.max(margin, maxLeft)
  2392. );
  2393. let top;
  2394. if (popupDirection.value === "top") {
  2395. top = triggerRect.top - popupRect.height - popupGap;
  2396. top = Math.max(margin, top);
  2397. } else {
  2398. top = triggerRect.bottom + popupGap;
  2399. if (top + popupRect.height > viewportHeight - margin) {
  2400. top = Math.max(
  2401. margin,
  2402. viewportHeight - popupRect.height - margin
  2403. );
  2404. }
  2405. }
  2406. popupLayerStyle.value = {
  2407. ...popupLayerStyle.value,
  2408. left: `${left}px`,
  2409. top: `${top}px`,
  2410. bottom: "auto",
  2411. };
  2412. });
  2413. };
  2414. const openPopup = () => {
  2415. if (!popupWinVisible.value) popupWinVisible.value = true;
  2416. Vue.nextTick(() => {
  2417. calculatePopupDirection();
  2418. updatePopupPosition();
  2419. });
  2420. };
  2421. const handleViewportChange = () => {
  2422. if (!popupWinVisible.value) return;
  2423. calculatePopupDirection();
  2424. updatePopupPosition();
  2425. };
  2426. const onDocPointerDown = (event) => {
  2427. if (!popupWinVisible.value) return;
  2428. const target = event.target;
  2429. if (selectContainerRef.value?.contains(target)) return;
  2430. if (popupRef.value?.contains(target)) return;
  2431. hidePopup();
  2432. };
  2433. let hidePopupTimer = null;
  2434. let keepPopupTimer = null;
  2435. const leaveInput = () => {
  2436. clearTimeout(hidePopupTimer);
  2437. hidePopupTimer = setTimeout(() => {
  2438. popupWinVisible.value = false;
  2439. }, 200);
  2440. };
  2441. const enterInput = () => {
  2442. clearTimeout(hidePopupTimer);
  2443. if (popupWinVisible.value) {
  2444. clearTimeout(keepPopupTimer);
  2445. }
  2446. };
  2447. const enterPopup = () => {
  2448. clearTimeout(hidePopupTimer);
  2449. popupWinVisible.value = true;
  2450. };
  2451. const leavePopup = () => {
  2452. clearTimeout(keepPopupTimer);
  2453. keepPopupTimer = setTimeout(() => {
  2454. popupWinVisible.value = false;
  2455. }, 200);
  2456. };
  2457. //级联菜单点击事件
  2458. const togglePopup = () => {
  2459. if (canInput) {
  2460. updateOptionBYInputText(inputText.value);
  2461. return;
  2462. }
  2463. if (!popupWinVisible.value) {
  2464. //如果当前下拉菜单是隐藏的,先ajax重新加载下拉菜单项,再显示。
  2465. showPopup();
  2466. } else {
  2467. hidePopup();
  2468. }
  2469. };
  2470. //显示下拉菜单,在此之前先清除下拉菜单项
  2471. const showPopup = () => {
  2472. //清空下拉菜单,并设置第一项的值为空
  2473. if (canInput) filteredOptions.value = props.opt;
  2474. clearAndInit1stOpt();
  2475. Vue.nextTick(() => {
  2476. calculatePopupDirection();
  2477. });
  2478. let url = props.url;
  2479. let filterObj = props.param.filter;
  2480. if (filterObj) {
  2481. for (let k in filterObj) {
  2482. let v = filterObj[k];
  2483. url += "&" + k + "=" + v;
  2484. }
  2485. }
  2486. if (props.mode === "1") {
  2487. //如果是有隐藏字段的下拉菜单
  2488. console.log("666url:" + url);
  2489. // alert('url:'+url);
  2490. // 获取级联菜单所有下拉菜单项
  2491. async function getSelectItems(value) {
  2492. try {
  2493. // alert(1);
  2494. if (props.url && props.param) {
  2495. // alert(2);
  2496. /**
  2497. * param={"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  2498. * "\"name\":\"hksheng\",\"cascadingName\":\"dq\"," +
  2499. * "\"cascadingInputsName\":\"hkdqm\",\"codebook\":\"sheng\"}",
  2500. * "objectpickertype":1,//2表示获取要回显的一项,1表示获取所有下拉菜单项
  2501. * "upperValue":"440000"
  2502. * };
  2503. */
  2504. const objectPickerParam = {
  2505. input: "false",
  2506. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2507. name: props.name, //本下拉菜单名
  2508. cascadingName: props.param.name, //级联菜单名
  2509. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  2510. codebook: props.param.codebook,
  2511. };
  2512. console.log("mode1 upperValue.value:" + upperValue.value);
  2513. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2514. const params = new URLSearchParams();
  2515. params.append("objectpickerparam", objectPickerParamStr);
  2516. params.append("objectpickertype", "1");
  2517. if (upperValue.value) {
  2518. params.append("upperValue", upperValue.value);
  2519. }
  2520. // params.append('objectpickervalue', value); //需回显的值
  2521. axios
  2522. .post(url, params, {
  2523. headers: {
  2524. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2525. },
  2526. })
  2527. .then((response) => {
  2528. if ("timeout" == response.data.statusText) {
  2529. alert("网络超时!");
  2530. return;
  2531. }
  2532. if (response.data.result) {
  2533. const normalizedResult = normalizeCcpResult(
  2534. response.data.result
  2535. );
  2536. console.log(
  2537. "params:" +
  2538. params +
  2539. "@@response.data:" +
  2540. JSON.stringify(response.data)
  2541. );
  2542. if (normalizedResult.length > 0) {
  2543. normalizedResult.forEach((option) => {
  2544. props.opt.push(option);
  2545. });
  2546. console.log("props.opt11:" + JSON.stringify(props.opt));
  2547. } else {
  2548. // 没有数据时打印日志 by xu 20251212
  2549. console.log("[ccp mode1] 接口返回空数据");
  2550. }
  2551. } else {
  2552. // result不存在时打印日志 by xu 20251212
  2553. console.log("[ccp mode1] 接口返回无result");
  2554. }
  2555. // 无论是否有数据,都显示popup by xu 20251212
  2556. openPopup();
  2557. });
  2558. }
  2559. } catch (error) {
  2560. alert(error);
  2561. // callback(null, error.message); // 失败回调,传递错误
  2562. }
  2563. }
  2564. getSelectItems(props.modelValue);
  2565. } else if (props.mode === "2") {
  2566. //没隐藏字段的下拉菜单
  2567. let needInitParam = undefined;
  2568. if (Array.isArray(props.param)) {
  2569. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  2570. console.log(
  2571. "needInitParam最后一项:" + JSON.stringify(needInitParam)
  2572. );
  2573. } else {
  2574. needInitParam = props.param;
  2575. }
  2576. // 获取级联菜单所有下拉菜单项
  2577. async function getSelectItems(value, sendParam) {
  2578. try {
  2579. // alert(1);
  2580. if (props.url && sendParam) {
  2581. // alert(2);
  2582. /**
  2583. * param="{\"input\":\"false\",\"cascadingLevel\":\"dwid,sjryid\",
  2584. * \"ryid\":\"111121\",\"name\":\"sjryid\",
  2585. * \"cascadingName\":\"dw_sjry\",\"codebook\":\"sjryByDw\"}"
  2586. */
  2587. const objectPickerParam = {
  2588. input: "false",
  2589. cascadingLevel: sendParam.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2590. name: props.name, //本下拉菜单名
  2591. cascadingName: sendParam.name, //级联菜单名
  2592. codebook: sendParam.codebook,
  2593. };
  2594. console.log("mode2 upperValue.value:" + upperValue.value);
  2595. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2596. const params = new URLSearchParams();
  2597. params.append("objectpickerparam", objectPickerParamStr);
  2598. params.append("objectpickertype", "1");
  2599. if (upperValue.value) {
  2600. params.append("upperValue", upperValue.value);
  2601. }
  2602. // params.append('objectpickervalue', value); //需回显的值
  2603. axios
  2604. .post(url, params, {
  2605. headers: {
  2606. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2607. },
  2608. })
  2609. .then((response) => {
  2610. if ("timeout" == response.data.statusText) {
  2611. alert("网络超时!");
  2612. return;
  2613. }
  2614. if (response.data.result) {
  2615. const normalizedResult = normalizeCcpResult(
  2616. response.data.result
  2617. );
  2618. console.log(
  2619. "params:" +
  2620. params +
  2621. "@@response.data:" +
  2622. JSON.stringify(response.data)
  2623. );
  2624. if (normalizedResult.length > 0) {
  2625. normalizedResult.forEach((option) => {
  2626. props.opt.push(option);
  2627. });
  2628. console.log("props.opt11:" + JSON.stringify(props.opt));
  2629. } else {
  2630. // 没有数据时打印日志 by xu 20251212
  2631. console.log("[ccp mode2] 接口返回空数据");
  2632. }
  2633. } else {
  2634. // result不存在时打印日志 by xu 20251212
  2635. console.log("[ccp mode2] 接口返回无result");
  2636. }
  2637. // 无论是否有数据,都显示popup by xu 20251212
  2638. openPopup();
  2639. });
  2640. }
  2641. } catch (error) {
  2642. alert(error);
  2643. // callback(null, error.message); // 失败回调,传递错误
  2644. }
  2645. }
  2646. getSelectItems(props.modelValue, needInitParam);
  2647. // popupWinVisible.value = !popupWinVisible.value;
  2648. }
  2649. };
  2650. const hidePopup = () => {
  2651. popupWinVisible.value = false;
  2652. };
  2653. const suffixClick = () => {
  2654. if (popupWinVisible.value) {
  2655. hidePopup();
  2656. return;
  2657. }
  2658. if (canInput) {
  2659. updateOptionBYInputText("");
  2660. } else {
  2661. showPopup();
  2662. }
  2663. };
  2664. const handleInputChange = (event) => {
  2665. inputText.value = event.target.value || "";
  2666. updateOptionBYInputText(inputText.value);
  2667. };
  2668. // 合并所有的 onMounted 逻辑
  2669. Vue.onMounted(() => {
  2670. window.addEventListener("resize", handleViewportChange);
  2671. window.addEventListener("scroll", handleViewportChange, true);
  2672. document.addEventListener("pointerdown", onDocPointerDown);
  2673. // 1. 监听展开下一级事件
  2674. window.addEventListener("open-next-cascader", (event) => {
  2675. const { name, level } = event.detail;
  2676. if (name === props.name && level === props.level) {
  2677. popupWinVisible.value = true;
  2678. }
  2679. });
  2680. // 2. 监听级联事件
  2681. window.addEventListener("cascader-change", (event) => {
  2682. const { name, level, value } = event.detail;
  2683. if (name === props.name && level < props.level) {
  2684. selectItem.value = { label: "", value: "" };
  2685. emit("update:modelValue", "");
  2686. if (ssHidden) {
  2687. ssHidden.updateValue(value);
  2688. }
  2689. }
  2690. });
  2691. });
  2692. Vue.onUnmounted(() => {
  2693. window.removeEventListener("resize", handleViewportChange);
  2694. window.removeEventListener("scroll", handleViewportChange, true);
  2695. document.removeEventListener("pointerdown", onDocPointerDown);
  2696. clearTimeout(hidePopupTimer);
  2697. clearTimeout(keepPopupTimer);
  2698. });
  2699. // 监听值变化,处理回显 (mode 2)
  2700. Vue.watch(
  2701. () => props.modelValue,
  2702. (newVal) => {
  2703. if (props.mode === "2" && newVal) {
  2704. // 使用 watchEffect 替代嵌套的 watch
  2705. Vue.watchEffect(() => {
  2706. if (props.opt.length > 0) {
  2707. const matchedOption = props.opt.find(
  2708. (opt) => opt.value === newVal
  2709. );
  2710. if (matchedOption) {
  2711. selectItem.value = matchedOption;
  2712. inputText.value = matchedOption.label;
  2713. }
  2714. }
  2715. });
  2716. } else {
  2717. // 原有的值变化处理
  2718. const item = props.opt.find((it) => it.value === newVal);
  2719. if (item) {
  2720. selectItem.value = item;
  2721. inputText.value = item.label;
  2722. } else {
  2723. selectItem.value = { label: "", value: "" };
  2724. inputText.value = "";
  2725. }
  2726. }
  2727. },
  2728. { immediate: true }
  2729. );
  2730. // 监听选项变化,当数据加载完成时进行匹配
  2731. Vue.watch(
  2732. () => props.opt,
  2733. (newOptions) => {
  2734. if (newOptions.length > 0) {
  2735. const matchedOption = newOptions.find(
  2736. (opt) => opt.value === selectItem.value.value
  2737. );
  2738. if (matchedOption) {
  2739. selectItem.value = matchedOption;
  2740. emit("update:modelValue", matchedOption.value);
  2741. emit("change", matchedOption.value);
  2742. }
  2743. }
  2744. }
  2745. );
  2746. return {
  2747. selectItem,
  2748. popupWinVisible,
  2749. popupDirection,
  2750. popupMaxHeight, // 添加popup最大高度 by xu 20251212
  2751. togglePopup,
  2752. hidePopup,
  2753. doSelectItem,
  2754. leaveInput,
  2755. enterInput,
  2756. leavePopup,
  2757. enterPopup,
  2758. selectContainerRef,
  2759. popupRef,
  2760. teleportRootStyle,
  2761. popupLayerStyle,
  2762. canInput,
  2763. inputText,
  2764. visibleOptions,
  2765. suffixClick,
  2766. handleInputChange,
  2767. };
  2768. },
  2769. template: `
  2770. <div class="input ss-ccp-container" style="position: relative" :style="{width: width}">
  2771. <input type="hidden" :name="name" :value="modelValue">
  2772. <div class="select-container" ref="selectContainerRef" @mouseleave="leaveInput" @mouseenter="enterInput">
  2773. <div class="input" @click="togglePopup">
  2774. <input
  2775. type="hidden"
  2776. :name="name"
  2777. :value="selectItem.value"
  2778. />
  2779. <input
  2780. v-if="canInput"
  2781. v-model="inputText"
  2782. @input="handleInputChange"
  2783. :placeholder="placeholder"
  2784. />
  2785. <input
  2786. v-else
  2787. :placeholder="placeholder"
  2788. :value="selectItem.label"
  2789. disabled
  2790. style="pointer-events: none;"
  2791. />
  2792. <div class="suffix" @click.stop="suffixClick">
  2793. <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
  2794. </div>
  2795. </div>
  2796. </div>
  2797. <teleport to="body">
  2798. <div
  2799. v-show="popupWinVisible"
  2800. class="select-container ss-ccp-teleport-root"
  2801. :style="teleportRootStyle"
  2802. @mouseleave="leavePopup"
  2803. @mouseenter="enterPopup"
  2804. >
  2805. <div
  2806. ref="popupRef"
  2807. class="popup-win"
  2808. :style="[popupLayerStyle, { maxHeight: popupMaxHeight !== 'none' ? popupMaxHeight : 'none', overflowY: popupMaxHeight !== 'none' ? 'auto' : 'visible' }]"
  2809. >
  2810. <div v-if="visibleOptions && visibleOptions.length > 0" class="popup-content">
  2811. <div class="content-area">
  2812. <div
  2813. v-for="(item, index) in visibleOptions"
  2814. :key="index"
  2815. @click="doSelectItem(item)"
  2816. :class="{ active: item.value === selectItem.value }"
  2817. >
  2818. <span class="check-icon">
  2819. <ss-form-icon class="form-icon-select-checked" />
  2820. </span>
  2821. <span>{{ item.label }}</span>
  2822. </div>
  2823. </div>
  2824. </div>
  2825. <div v-else class="popup-content">
  2826. <div class="content-area">
  2827. <div class="content-area">
  2828. <span>无选项</span>
  2829. </div>
  2830. </div>
  2831. </div>
  2832. </div>
  2833. </div>
  2834. </teleport>
  2835. </div>
  2836. `,
  2837. };
  2838. // ss-date-picker 日期时间选择器组件
  2839. const SsDatePicker = {
  2840. name: "SsDatePicker",
  2841. props: {
  2842. modelValue: {
  2843. type: [String, Number, Date],
  2844. default: "",
  2845. },
  2846. name: {
  2847. type: String,
  2848. required: true,
  2849. },
  2850. type: {
  2851. type: String,
  2852. default: "date",
  2853. validator: (value) => ["date", "datetime", "time"].includes(value),
  2854. },
  2855. fmt: {
  2856. type: String,
  2857. default: null,
  2858. },
  2859. placeholder: {
  2860. type: String,
  2861. default: "",
  2862. },
  2863. width: {
  2864. type: String,
  2865. default: "100%",
  2866. },
  2867. },
  2868. emits: ["update:modelValue"],
  2869. setup(props, { emit }) {
  2870. const errMsg = ref("");
  2871. const validate = () => {
  2872. if (window.ssVm) {
  2873. const result = window.ssVm.validateField(props.name);
  2874. console.log("validate", window.ssVm.validateField(props.name));
  2875. errMsg.value = result.valid ? "" : result.message;
  2876. }
  2877. };
  2878. // 根据type确定默认格式
  2879. const defaultFormat = computed(() => {
  2880. switch (props.type) {
  2881. case "datetime":
  2882. return "YYYY-MM-DD HH:mm:ss";
  2883. case "date":
  2884. return "YYYY-MM-DD";
  2885. case "time":
  2886. return "HH:mm:ss";
  2887. }
  2888. });
  2889. const convertJavaFormatToElement = (javaFormat) => {
  2890. if (!javaFormat) return null;
  2891. return javaFormat
  2892. .replace("yyyy", "YYYY")
  2893. .replace("MM", "MM")
  2894. .replace("dd", "DD")
  2895. .replace("HH", "HH")
  2896. .replace("mm", "mm")
  2897. .replace("ss", "ss");
  2898. };
  2899. const finalFormat = computed(() => {
  2900. if (props.fmt) {
  2901. return convertJavaFormatToElement(props.fmt);
  2902. }
  2903. return defaultFormat.value;
  2904. });
  2905. // 使用 resolveComponent 获取组件
  2906. const ElDatePicker = resolveComponent("ElDatePicker");
  2907. const ElTimePicker = resolveComponent("ElTimePicker");
  2908. const SsFormIcon = resolveComponent("SsFormIcon");
  2909. const ElIcon = resolveComponent("ElIcon");
  2910. const handleValueUpdate = (val) => {
  2911. emit("update:modelValue", val);
  2912. emit("change", val); // 同时触发 change 事件
  2913. setTimeout(() => {
  2914. validate();
  2915. }, 50);
  2916. };
  2917. const dateType = computed(() => {
  2918. const fmt = props.fmt || "";
  2919. if (fmt.includes("HH:mm:ss")) {
  2920. return "datetime";
  2921. } else if (fmt.includes("HH:mm")) {
  2922. return "datetime";
  2923. } else if (fmt.includes("mm:ss")) {
  2924. return "time";
  2925. }
  2926. return "date";
  2927. });
  2928. let useTimePicker = true;
  2929. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  2930. if (props.fmt) {
  2931. //有fmt属性,则以fmt属性优先判断类型
  2932. if (/[dMy]/.test(props.fmt)) {
  2933. //如果有传入日期格式,且含年月日
  2934. useTimePicker = false;
  2935. } else {
  2936. useTimePicker = true;
  2937. }
  2938. } else if (props.type !== "time") {
  2939. useTimePicker = false;
  2940. }
  2941. return () =>
  2942. h("div", { class: "ss-date-picker", style: { width: props.width } }, [
  2943. h("input", {
  2944. type: "hidden",
  2945. name: props.name,
  2946. value: props.modelValue,
  2947. }),
  2948. // 选择组件
  2949. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  2950. modelValue: props.modelValue,
  2951. "onUpdate:modelValue": handleValueUpdate,
  2952. type: dateType.value,
  2953. format: finalFormat.value,
  2954. "value-format": finalFormat.value,
  2955. clearable: true,
  2956. placeholder: props.placeholder,
  2957. class: "custom-date-picker", // 用于自定义样式
  2958. "time-arrow-control": props.type === "datetime", // 修改这里
  2959. size: "large", // 添加这一行,改为 large 尺寸
  2960. style: { width: "100%" },
  2961. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  2962. }),
  2963. ]);
  2964. },
  2965. };
  2966. // ss-icon 图标
  2967. // v3.0 增加 class 属性分支:有 class 走新逻辑,否则走 v1.0 逻辑 by xu 20251212
  2968. // v3.0 用法: <ss-icon class="icon-obj-ry menu-icon" />
  2969. // v1.0 用法: <ss-icon name="setting" size="20px" />
  2970. const SsIcon = {
  2971. name: "SsIcon",
  2972. // v3.0 禁用 class 透传,手动处理 by xu 20251215
  2973. inheritAttrs: false,
  2974. props: {
  2975. // v1.0: 以下为旧属性
  2976. name: { type: String },
  2977. size: { type: [Number, String], default: 16 },
  2978. unit: { type: String, default: "px" },
  2979. color: String,
  2980. type: {
  2981. type: String,
  2982. default: ssIcon.name,
  2983. validator: function (value) {
  2984. return [ssIcon, commonIcon].some((icon) => icon.name === value);
  2985. },
  2986. },
  2987. },
  2988. emits: ["update:modelValue", "input", "blur", "change"],
  2989. setup(props, { emit, attrs }) {
  2990. // v3.0 分支:有 class 属性时直接渲染(从 attrs 获取) by xu 20251215
  2991. if (attrs.class) {
  2992. return () =>
  2993. h("i", { ...attrs, class: attrs.class + " icon-container" });
  2994. }
  2995. // v1.0 分支:原有逻辑
  2996. const useIconType = computed(() => {
  2997. return [ssIcon, commonIcon].find(
  2998. (iconConfig) => iconConfig.name === props.type
  2999. );
  3000. });
  3001. const iconName = computed(() => {
  3002. const iconConfig = useIconType.value; // 注意:使用 .value 来访问响应式引用的值
  3003. if (!iconConfig) {
  3004. console.error(`Icon type "${props.type}" not found.`);
  3005. return "";
  3006. }
  3007. const iconType = iconConfig.types[props.name];
  3008. if (!iconType) {
  3009. console.error(
  3010. `Icon name "${props.name}" not found in type "${props.type}".`
  3011. );
  3012. return "";
  3013. }
  3014. return `${iconConfig.prefix}${iconType}`;
  3015. });
  3016. // 类似地,你可以计算 fontFamily 和 style
  3017. const fontFamily = computed(() => {
  3018. return useIconType.value ? useIconType.value.family : "";
  3019. });
  3020. // console.log(iconName.value,fontFamily.value)
  3021. const style = computed(() => {
  3022. const sizeStyle = isNum(props.size)
  3023. ? `${props.size}${props.unit}`
  3024. : props.size;
  3025. const styleObj = {
  3026. fontSize: sizeStyle,
  3027. color: props.color || "",
  3028. };
  3029. return toStyleStr(styleObj);
  3030. });
  3031. // 使用渲染函数定义模板逻辑
  3032. return () =>
  3033. h("i", {
  3034. class: ["icon-container", iconName.value, fontFamily.value],
  3035. style: style.value,
  3036. });
  3037. },
  3038. };
  3039. // 通用icon
  3040. const SsCommonIcon = {
  3041. name: "SsCommonIcon",
  3042. props: {
  3043. class: {
  3044. type: String,
  3045. required: true,
  3046. },
  3047. },
  3048. setup(props) {
  3049. return () =>
  3050. h("i", {
  3051. class: props.class + " common-icon",
  3052. });
  3053. },
  3054. };
  3055. // 登录页icon
  3056. const SsLoginIcon = {
  3057. name: "SsLoginIcon",
  3058. props: {
  3059. class: {
  3060. type: String,
  3061. required: true,
  3062. },
  3063. },
  3064. setup(props) {
  3065. return () =>
  3066. h("div", {
  3067. class: props.class + " login-icon",
  3068. });
  3069. },
  3070. };
  3071. // 弹窗icon
  3072. const SsDialogIcon = {
  3073. name: "SsDialogIcon",
  3074. props: {
  3075. class: {
  3076. type: String,
  3077. required: true,
  3078. },
  3079. },
  3080. setup(props) {
  3081. return () =>
  3082. h("i", {
  3083. class: props.class + " dialog-icon",
  3084. });
  3085. },
  3086. };
  3087. // 全局左侧导航图标组件
  3088. const SsNavIcon = {
  3089. name: "SsNavIcon",
  3090. props: {
  3091. class: {
  3092. type: String,
  3093. required: true,
  3094. },
  3095. },
  3096. setup(props) {
  3097. return () =>
  3098. h("div", {
  3099. class: props.class + " nav-icon",
  3100. });
  3101. },
  3102. };
  3103. // 顶部工具栏图标组件
  3104. const SsHeaderIcon = {
  3105. name: "SsHeaderIcon",
  3106. props: {
  3107. class: {
  3108. type: String,
  3109. required: true,
  3110. },
  3111. },
  3112. setup(props) {
  3113. return () =>
  3114. h("div", {
  3115. class: props.class + " header-icon",
  3116. });
  3117. },
  3118. };
  3119. // 全局菜单图标组件
  3120. const SsGolbalMenuIcon = {
  3121. name: "SsGolbalMenuIcon",
  3122. props: {
  3123. class: {
  3124. type: String,
  3125. required: true,
  3126. },
  3127. },
  3128. setup(props) {
  3129. return () =>
  3130. h("div", {
  3131. class: props.class + " global-menu-icon",
  3132. });
  3133. },
  3134. };
  3135. // 全局查询列表卡片图标
  3136. const SsCartListIcon = {
  3137. name: "SsCartListIcon",
  3138. props: {
  3139. class: {
  3140. type: String,
  3141. required: true,
  3142. },
  3143. },
  3144. setup(props) {
  3145. return () =>
  3146. h("div", {
  3147. class: props.class + " cart-list-icon",
  3148. });
  3149. },
  3150. };
  3151. // 全局底部工具栏图标组件
  3152. const SsQuickIcon = {
  3153. name: "SsQuickIcon",
  3154. props: {
  3155. class: {
  3156. type: String,
  3157. required: true,
  3158. },
  3159. },
  3160. setup(props) {
  3161. return () =>
  3162. h("div", {
  3163. class: props.class + " quick-icon",
  3164. });
  3165. },
  3166. };
  3167. // 表单组件icon
  3168. const SsFormIcon = {
  3169. name: "SsFormIcon",
  3170. props: {
  3171. class: {
  3172. type: String,
  3173. required: true,
  3174. },
  3175. },
  3176. setup(props) {
  3177. return () =>
  3178. h("div", {
  3179. class: props.class + " form-icon",
  3180. });
  3181. },
  3182. };
  3183. // 弹窗底部按钮icon
  3184. const SsBottomDivIcon = {
  3185. name: "SsBottomDivIcon",
  3186. props: {
  3187. class: {
  3188. type: String,
  3189. required: true,
  3190. },
  3191. },
  3192. setup(props) {
  3193. return () =>
  3194. h("div", {
  3195. class: props.class + " bottom-div-icon",
  3196. });
  3197. },
  3198. };
  3199. // editor组件icon
  3200. const SsEditorIcon = {
  3201. name: "SsEditorIcon",
  3202. props: {
  3203. class: {
  3204. type: String,
  3205. required: true,
  3206. },
  3207. },
  3208. setup(props) {
  3209. return () =>
  3210. h("i", {
  3211. class: props.class + " editor-icon",
  3212. });
  3213. },
  3214. };
  3215. // ss-validate校验器
  3216. const SsValidate = {
  3217. name: "SsValidate",
  3218. props: {
  3219. errMsg: { type: String },
  3220. textAlign: { type: String, default: "left" },
  3221. style: { type: Object, default: () => ({}) },
  3222. },
  3223. template: `<div class="validate-vline"></div>
  3224. <div class="validate-tip" :style="style">
  3225. <div class="tip" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  3226. <div class="tip-more" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  3227. </div>`,
  3228. };
  3229. // ss-onoff-array 多选按钮 数组形式
  3230. const SsonoffArray = {
  3231. name: "SsonoffArray",
  3232. props: {
  3233. name: {
  3234. type: String,
  3235. required: true,
  3236. },
  3237. opt: {
  3238. type: Array,
  3239. default: () => [],
  3240. },
  3241. defaultValue: [String, Number, Array],
  3242. modelValue: [String, Number, Array],
  3243. multiple: {
  3244. // 新增多选模式属性
  3245. type: Boolean,
  3246. default: false,
  3247. },
  3248. // 是否允许一项都不选,默认true允许 by xu 20251212
  3249. null: {
  3250. type: Boolean,
  3251. default: true,
  3252. },
  3253. },
  3254. emits: ["update:modelValue"], // 允许更新 v-model 绑定的值
  3255. setup(props, { emit }) {
  3256. console.log("多选按钮", props.opt);
  3257. // 使用数组来存储选中值
  3258. const checkedValue = ref(
  3259. props.multiple
  3260. ? Array.isArray(props.defaultValue)
  3261. ? props.defaultValue
  3262. : []
  3263. : props.defaultValue
  3264. );
  3265. const errMsg = ref(props.errTip);
  3266. // 生成icon名字
  3267. const genIconName = (itemValue) => {
  3268. if (props.multiple) {
  3269. return checkedValue.value.includes(itemValue)
  3270. ? "form-icon-onoff-checked"
  3271. : "form-icon-onoff-unchecked";
  3272. }
  3273. return checkedValue.value === itemValue
  3274. ? "form-icon-onoff-checked"
  3275. : "form-icon-onoff-unchecked";
  3276. };
  3277. // 选中项
  3278. const selectItem = (value) => {
  3279. if (props.multiple) {
  3280. // 多选模式
  3281. const index = checkedValue.value.indexOf(value);
  3282. if (index === -1) {
  3283. checkedValue.value = [...checkedValue.value, value];
  3284. } else {
  3285. // 取消选中当前项
  3286. const newValue = checkedValue.value.filter((v) => v !== value);
  3287. // 如果不允许为空且取消后为空,则阻止取消操作 by xu 20251212
  3288. if (!props.null && newValue.length === 0) {
  3289. return; // 阻止取消最后一项
  3290. }
  3291. checkedValue.value = newValue;
  3292. }
  3293. } else {
  3294. // 单选模式
  3295. // 如果点击的是当前已选中的项,判断是否允许取消 by xu 20251212
  3296. if (checkedValue.value === value) {
  3297. if (!props.null) {
  3298. return; // 不允许为空时,阻止取消
  3299. }
  3300. checkedValue.value = ""; // 允许为空时,取消选中
  3301. } else {
  3302. checkedValue.value = value;
  3303. }
  3304. }
  3305. emit("update:modelValue", checkedValue.value);
  3306. nextTick(() => {
  3307. // 触发验证
  3308. if (window.ssVm) {
  3309. window.ssVm.validateField(props.name);
  3310. }
  3311. });
  3312. };
  3313. return { checkedValue, genIconName, selectItem };
  3314. },
  3315. // 使用渲染函数定义模板逻辑
  3316. render() {
  3317. const SsFormIcon = resolveComponent("ss-form-icon");
  3318. return h("div", { class: "radio-container" }, [
  3319. // 根据情况创建 input
  3320. this.multiple
  3321. ? this.checkedValue.length
  3322. ? // 多选且有选中值:为选中项创建 input
  3323. this.checkedValue.map((value) =>
  3324. h("input", {
  3325. type: "checkbox",
  3326. name: this.name,
  3327. value: value,
  3328. checked: true,
  3329. style: { display: "none" },
  3330. })
  3331. )
  3332. : // 多选但没有选中值:创建一个空值 input
  3333. h("input", {
  3334. type: "hidden",
  3335. name: this.name,
  3336. value: "",
  3337. })
  3338. : // 单选模式:创建一个 input
  3339. h("input", {
  3340. type: "hidden",
  3341. name: this.name,
  3342. value: this.checkedValue || "",
  3343. }),
  3344. this.opt.map((item, i) =>
  3345. h(
  3346. "div",
  3347. {
  3348. key: i,
  3349. class: {
  3350. checked: this.multiple
  3351. ? this.checkedValue.includes(item.value)
  3352. : this.checkedValue === item.value,
  3353. },
  3354. style: { width: item.width },
  3355. onClick: () => this.selectItem(item.value),
  3356. },
  3357. [
  3358. h("span", null, item.label),
  3359. h("div", { class: "mark" }, [
  3360. h(SsFormIcon, {
  3361. class: this.genIconName(item.value),
  3362. }),
  3363. ]),
  3364. ]
  3365. )
  3366. ),
  3367. ]);
  3368. },
  3369. };
  3370. // ss-onoff 一个按钮
  3371. const Ssonoff = {
  3372. name: "Ssonoff",
  3373. props: {
  3374. name: {
  3375. type: String,
  3376. required: true,
  3377. },
  3378. label: {
  3379. type: String,
  3380. required: true,
  3381. },
  3382. value: {
  3383. type: [String, Number],
  3384. required: true,
  3385. },
  3386. width: {
  3387. type: String,
  3388. default: "",
  3389. },
  3390. onchange: {
  3391. // 在此属性传入 onChange 的 window 全局回调函数,第一参数是当前整组值 by Ben/xu(20260320)
  3392. type: String,
  3393. required: false,
  3394. },
  3395. modelValue: [String, Number, Array],
  3396. multiple: {
  3397. type: Boolean,
  3398. default: false,
  3399. },
  3400. null: {
  3401. type: Boolean,
  3402. default: true,
  3403. },
  3404. },
  3405. emits: ["update:modelValue", "change"],
  3406. setup(props, { emit }) {
  3407. const parseModelValue = (val) => {
  3408. if (Array.isArray(val)) {
  3409. return val
  3410. .map((item) => (item == null ? "" : item.toString()))
  3411. .filter(Boolean);
  3412. }
  3413. if (val == null || val === "") return [];
  3414. // 如果以逗号开头,去掉开头的逗号
  3415. const cleanValue = val.toString().replace(/^,+/, "");
  3416. if (!cleanValue) return [];
  3417. if (cleanValue.includes("|")) {
  3418. return cleanValue.split("|").filter(Boolean);
  3419. }
  3420. if (cleanValue.includes(",")) {
  3421. return cleanValue.split(",").filter(Boolean);
  3422. }
  3423. return [cleanValue];
  3424. };
  3425. const callGlobalOnchg = (groupValue) => {
  3426. if (props.onchange && typeof props.onchange === "string") {
  3427. if (
  3428. typeof window !== "undefined" &&
  3429. window[props.onchange] &&
  3430. typeof window[props.onchange] === "function"
  3431. ) {
  3432. try {
  3433. window[props.onchange](groupValue, props.value, props.label);
  3434. } catch (error) {
  3435. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  3436. }
  3437. } else {
  3438. console.warn(`全局函数 ${props.onchange} 未定义或不是一个函数。`);
  3439. }
  3440. }
  3441. };
  3442. // 判断当前按钮是否选中
  3443. const isChecked = computed(() => {
  3444. if (props.multiple) {
  3445. const currentValue = parseModelValue(props.modelValue);
  3446. return currentValue.includes(props.value.toString());
  3447. }
  3448. return props.modelValue + "" === props.value + ""; //强转为字符串类型再比较(改之前是数字类型和字符串类型作比较,永远为false) Ben 20251206
  3449. });
  3450. // 功能说明:watch modelValue 变化,兼容桥接 API 赋值触发 onChange by xu 20260416
  3451. let isToggleTriggering = false; // 避免 toggleSelect 内部 emit 重复触发
  3452. Vue.watch(
  3453. () => props.modelValue,
  3454. (newVal) => {
  3455. if (isToggleTriggering) return;
  3456. callGlobalOnchg(newVal);
  3457. }
  3458. );
  3459. // 切换选中状态
  3460. const toggleSelect = () => {
  3461. let newModelValue;
  3462. if (props.multiple) {
  3463. const currentValue = parseModelValue(props.modelValue);
  3464. const currentButtonValue = props.value.toString();
  3465. const index = currentValue.indexOf(currentButtonValue);
  3466. let newValue;
  3467. if (index === -1) {
  3468. // 选中当前项
  3469. newValue = [...currentValue, currentButtonValue];
  3470. } else {
  3471. // 取消选中当前项
  3472. const filteredValue = currentValue.filter(
  3473. (value) => value !== currentButtonValue
  3474. );
  3475. // 如果不允许为空且取消后为空,则阻止取消操作
  3476. if (!props.null && filteredValue.length === 0) {
  3477. return; // 阻止取消最后一项
  3478. }
  3479. newValue = filteredValue;
  3480. }
  3481. newModelValue = newValue.join(",");
  3482. } else {
  3483. // 单选模式
  3484. const currentValue = parseModelValue(props.modelValue);
  3485. const isCurrentlySelected = currentValue.includes(
  3486. props.value.toString()
  3487. );
  3488. if (!isCurrentlySelected) {
  3489. // 选中当前项
  3490. newModelValue = props.value;
  3491. } else {
  3492. // 取消选中当前项
  3493. // 如果不允许为空且当前只有这一项被选中,则阻止取消操作
  3494. if (!props.null && currentValue.length === 1) {
  3495. return; // 阻止取消唯一选中项
  3496. }
  3497. newModelValue = "";
  3498. }
  3499. }
  3500. isToggleTriggering = true; // emit 前设置,避免 watch 重复触发 onChange by xu 20260416
  3501. emit("update:modelValue", newModelValue);
  3502. emit("change", newModelValue, props.value, props.label);
  3503. nextTick(() => {
  3504. isToggleTriggering = false; // 重置标志,允许后续桥接 API 赋值触发 onChange by xu 20260416
  3505. // 触发验证
  3506. if (window.ssVm) {
  3507. window.ssVm.validateField(props.name);
  3508. }
  3509. });
  3510. };
  3511. return { isChecked, toggleSelect };
  3512. },
  3513. render() {
  3514. const SsFormIcon = resolveComponent("ss-form-icon");
  3515. return h("div", { class: "radio-container2" }, [
  3516. // 隐藏的表单元素
  3517. this.multiple
  3518. ? h("input", {
  3519. type: "hidden",
  3520. name: `${this.name}`, // 多选模式下使用数组形式的 name
  3521. value: this.isChecked ? this.value : "",
  3522. })
  3523. : this.isChecked &&
  3524. h("input", {
  3525. // 只有当前按钮被选中时才创建 input
  3526. type: "hidden",
  3527. name: this.name,
  3528. value: this.value,
  3529. }),
  3530. // 按钮显示
  3531. h(
  3532. "div",
  3533. {
  3534. class: { checked: this.isChecked },
  3535. style: { width: this.width },
  3536. onClick: this.toggleSelect,
  3537. },
  3538. [
  3539. h("span", null, this.label),
  3540. h("div", { class: "mark" }, [
  3541. h(SsFormIcon, {
  3542. class: this.isChecked
  3543. ? "form-icon-onoff-checked"
  3544. : "form-icon-onoff-unchecked",
  3545. }),
  3546. ]),
  3547. ]
  3548. ),
  3549. ]);
  3550. },
  3551. };
  3552. // ss-textarea
  3553. // ss-textarea
  3554. const SsTextarea = {
  3555. name: "SsTextarea",
  3556. props: {
  3557. name: {
  3558. type: String,
  3559. required: true,
  3560. },
  3561. placeholder: {
  3562. type: String,
  3563. default: "请输入",
  3564. },
  3565. defaultValue: [String, Number],
  3566. modelValue: [String, Number],
  3567. // 功能说明:onChange 全局回调 prop,桥接 API 赋值时自动触发 by xu 20260416
  3568. onchange: {
  3569. type: String,
  3570. required: false,
  3571. },
  3572. },
  3573. emits: ["update:modelValue"],
  3574. setup(props, { emit }) {
  3575. const inputValue = ref(props.modelValue || props.defaultValue || "");
  3576. // 功能说明:调用全局 onChange 回调 by xu 20260416
  3577. const callGlobalOnchg = (value) => {
  3578. if (props.onchange && typeof props.onchange === "string") {
  3579. if (
  3580. typeof window !== "undefined" &&
  3581. window[props.onchange] &&
  3582. typeof window[props.onchange] === "function"
  3583. ) {
  3584. try {
  3585. window[props.onchange](value);
  3586. } catch (error) {
  3587. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  3588. }
  3589. }
  3590. }
  3591. };
  3592. // 监听 modelValue 变化
  3593. watch(
  3594. () => props.modelValue,
  3595. (newVal) => {
  3596. inputValue.value = newVal;
  3597. callGlobalOnchg(newVal);
  3598. }
  3599. );
  3600. // 输入事件处理
  3601. const onInput = (event) => {
  3602. const newValue = event.target.value;
  3603. inputValue.value = newValue;
  3604. emit("update:modelValue", newValue);
  3605. // 触发验证
  3606. if (window.ssVm) {
  3607. window.ssVm.validateField(props.name);
  3608. }
  3609. };
  3610. // 失焦时验证
  3611. const onBlur = () => {
  3612. if (window.ssVm) {
  3613. window.ssVm.validateField(props.name);
  3614. }
  3615. };
  3616. return { inputValue, onInput, onBlur };
  3617. },
  3618. render() {
  3619. return h("div", { class: "textarea-container" }, [
  3620. h("div", { class: "textarea" }, [
  3621. h("input", {
  3622. type: "hidden",
  3623. name: this.name,
  3624. value: this.inputValue || "",
  3625. }),
  3626. h("textarea", {
  3627. placeholder: this.placeholder,
  3628. value: this.inputValue,
  3629. onInput: this.onInput,
  3630. onBlur: this.onBlur,
  3631. }),
  3632. ]),
  3633. ]);
  3634. },
  3635. };
  3636. // ss-editor 富文本编辑器 基于Jodit
  3637. const SsEditor = {
  3638. name: "SsEditor",
  3639. props: {
  3640. modelValue: {
  3641. type: String,
  3642. default: "",
  3643. },
  3644. html: {
  3645. type: String,
  3646. default: "",
  3647. },
  3648. htmlname: {
  3649. type: String,
  3650. default: "",
  3651. },
  3652. storename: {
  3653. type: String,
  3654. default: "",
  3655. },
  3656. name: {
  3657. type: String,
  3658. default: "",
  3659. },
  3660. url: {
  3661. type: String,
  3662. default: "",
  3663. },
  3664. height: {
  3665. type: [Number, String],
  3666. default: 400,
  3667. },
  3668. placeholder: {
  3669. type: String,
  3670. default: "请输入内容",
  3671. },
  3672. mode: {
  3673. type: String,
  3674. default: "edit", // 'edit' | 'play'
  3675. },
  3676. uploadUrl: {
  3677. type: String,
  3678. default: "/ulByHttp", //原值为“upload” Ben(20251205)
  3679. },
  3680. param: {
  3681. type: Object,
  3682. default: () => ({}),
  3683. },
  3684. },
  3685. emits: ["update:modelValue", "ready", "change"],
  3686. setup(props, { emit }) {
  3687. const editorRef = ref(null);
  3688. const editorContent = ref("");
  3689. const currentModelValue = ref(props.modelValue || "");
  3690. const uniqueId = "editor-" + Date.now();
  3691. const errMsg = Vue.ref("");
  3692. // button 支持对象(旧格式,单个附件按钮)或数组(新格式,多个按钮)by xu 20250331
  3693. const buttonConfigRaw = props.param && props.param.button ? props.param.button : null;
  3694. const buttonArray = Array.isArray(buttonConfigRaw)
  3695. ? buttonConfigRaw
  3696. : buttonConfigRaw
  3697. ? [buttonConfigRaw]
  3698. : [];
  3699. // 找到附件按钮配置(有 cmsAddUrl 的)
  3700. const fjButton = buttonArray.find(btn => btn && btn.cmsAddUrl && btn.cmsUpdUrl) || {};
  3701. const fjid = ref(fjButton.val || null);
  3702. const attachmentFieldName = fjButton.name || "fjid";
  3703. const attachmentLabel = fjButton.desc || fjButton.text || "附件";
  3704. const resolveStoreFieldName = () => {
  3705. if (props.storename) {
  3706. return props.storename;
  3707. }
  3708. if (!props.name) {
  3709. return "";
  3710. }
  3711. return /wj$/i.test(props.name) ? props.name : props.name + "wj";
  3712. };
  3713. const resolveHtmlFieldName = () => {
  3714. if (props.htmlname) {
  3715. return props.htmlname;
  3716. }
  3717. const storeFieldName = resolveStoreFieldName();
  3718. if (storeFieldName && /wj$/i.test(storeFieldName)) {
  3719. return storeFieldName.replace(/wj$/i, "") + "Edit";
  3720. }
  3721. if (!props.name) {
  3722. return "";
  3723. }
  3724. return props.name.replace(/wj$/i, "") + "Edit";
  3725. };
  3726. const resolvePageSearchParam = (key) => {
  3727. try {
  3728. return new URL(window.location.href).searchParams.get(key) || "";
  3729. } catch (error) {
  3730. return "";
  3731. }
  3732. };
  3733. const resolveAttachmentObjName = () =>
  3734. props.param?.obj ||
  3735. props.param?.ssObjName ||
  3736. document.querySelector("[name='ssObjName']")?.value ||
  3737. window?.ss?.dom?.ssObjName ||
  3738. resolvePageSearchParam("ssObjName") ||
  3739. "";
  3740. const resolveAttachmentObjId = () =>
  3741. props.param?.ssObjId ||
  3742. props.param?.objId ||
  3743. document.querySelector("[name='ssObjId']")?.value ||
  3744. resolvePageSearchParam("ssObjId") ||
  3745. "";
  3746. const buildAttachmentCreatePayload = () => ({
  3747. name: attachmentFieldName,
  3748. ssNrObjName: resolveAttachmentObjName(),
  3749. ssNrObjId: resolveAttachmentObjId(),
  3750. });
  3751. const buildAttachmentDialogQuery = () =>
  3752. "&nrid=T-" +
  3753. fjid.value +
  3754. "&objectId=" +
  3755. fjid.value +
  3756. "&objectName=" +
  3757. attachmentFieldName +
  3758. "&callback=" +
  3759. (window[attachmentFieldName + "CallbackName"] || "");
  3760. const ensureAttachmentId = () => {
  3761. if (fjid.value != null && fjid.value !== "") {
  3762. return true;
  3763. }
  3764. if (!fjButton.cmsAddUrl) {
  3765. console.warn("ss-editor 未配置附件创建地址,无法初始化附件记录");
  3766. return false;
  3767. }
  3768. $.ajax({
  3769. type: "post",
  3770. url: fjButton.cmsAddUrl,
  3771. async: false,
  3772. data: buildAttachmentCreatePayload(),
  3773. success: function (_fjid) {
  3774. console.log("cmsAddUrl success", _fjid);
  3775. fjid.value = _fjid;
  3776. },
  3777. });
  3778. return fjid.value != null && fjid.value !== "";
  3779. };
  3780. const openAttachmentDialog = () => {
  3781. if (!fjButton.cmsUpdUrl) {
  3782. console.warn("ss-editor 未配置附件编辑地址,忽略附件操作");
  3783. return;
  3784. }
  3785. if (!ensureAttachmentId()) {
  3786. return;
  3787. }
  3788. const str = buildAttachmentDialogQuery();
  3789. console.log("str", str);
  3790. SS.openDialog({
  3791. src: fjButton.cmsUpdUrl + str,
  3792. headerTitle: "编辑",
  3793. width: 900,
  3794. high: 664,
  3795. zIndex: 51,
  3796. });
  3797. };
  3798. // 筛选出自定义按钮(有 func 的)
  3799. const customButtonsFromParam = buttonArray.filter(btn => btn.func).map(btn => ({
  3800. name: btn.name,
  3801. text: btn.desc || btn.text,
  3802. tooltip: btn.desc || btn.tooltip,
  3803. icon: btn.icon || 'editor-icon-file',
  3804. onClick: btn.func // 函数名字符串
  3805. }));
  3806. const mode = props.param ? props.param.mode : null;
  3807. const normalizeHtml = (rawHtml) => {
  3808. if (rawHtml == null) {
  3809. return "";
  3810. }
  3811. const html = String(rawHtml).trim();
  3812. if (!html) {
  3813. return "";
  3814. }
  3815. if (
  3816. /<html[\s>]/i.test(html) ||
  3817. /<body[\s>]/i.test(html) ||
  3818. /<!doctype/i.test(html)
  3819. ) {
  3820. try {
  3821. const doc = new DOMParser().parseFromString(html, "text/html");
  3822. if (doc && doc.body) {
  3823. return doc.body.innerHTML || "";
  3824. }
  3825. } catch (e) {
  3826. console.warn("ss-editor 解析完整HTML失败,回退原始内容:", e);
  3827. }
  3828. }
  3829. return html;
  3830. };
  3831. const syncHiddenContentInput = (html) => {
  3832. const contentElements = document.getElementsByName(resolveHtmlFieldName());
  3833. if (contentElements.length > 0) {
  3834. contentElements[0].value = html;
  3835. }
  3836. };
  3837. const setEditorHtml = (html) => {
  3838. const normalizedHtml = normalizeHtml(html);
  3839. editorContent.value = normalizedHtml;
  3840. syncHiddenContentInput(normalizedHtml);
  3841. if (editorRef.value && editorRef.value.value !== normalizedHtml) {
  3842. editorRef.value.value = normalizedHtml;
  3843. }
  3844. };
  3845. const resolveWindowFunction = (handlerName) => {
  3846. if (!handlerName || typeof handlerName !== "string") {
  3847. return null;
  3848. }
  3849. return handlerName.split(".").reduce((current, key) => {
  3850. return current && current[key] != null ? current[key] : null;
  3851. }, window);
  3852. };
  3853. const getCustomButtonKey = (button, index) => {
  3854. const baseName =
  3855. (button &&
  3856. (button.key || button.name || button.text || button.tooltip)) ||
  3857. `button${index + 1}`;
  3858. return `ssCustomButton_${String(baseName).replace(
  3859. /[^a-zA-Z0-9_-]/g,
  3860. "_"
  3861. )}_${index}`;
  3862. };
  3863. const normalizeCustomButtons = (buttons = []) => {
  3864. return Array.isArray(buttons)
  3865. ? buttons.filter(Boolean).map((button, index) => ({
  3866. ...button,
  3867. _buttonKey: getCustomButtonKey(button, index),
  3868. }))
  3869. : [];
  3870. };
  3871. const renderButtonIcon = (icon) => {
  3872. if (!icon) {
  3873. return null;
  3874. }
  3875. if (typeof icon === "string" && icon.trim().startsWith("<")) {
  3876. return icon;
  3877. }
  3878. return `<span class="editor-icon ${icon}"></span>`;
  3879. };
  3880. const buildCustomButtonRegistry = (buttons = []) => {
  3881. const controls = {};
  3882. const buttonNames = [];
  3883. const iconMap = {};
  3884. normalizeCustomButtons(buttons).forEach((button) => {
  3885. const buttonKey = button._buttonKey;
  3886. const handler =
  3887. button.onClick ||
  3888. button.click ||
  3889. button.handler ||
  3890. button.exec ||
  3891. null;
  3892. const tooltip =
  3893. button.tooltip ||
  3894. button.text ||
  3895. button.label ||
  3896. button.name ||
  3897. "自定义按钮";
  3898. buttonNames.push(buttonKey);
  3899. if (button.icon) {
  3900. iconMap[buttonKey] = button.icon;
  3901. }
  3902. controls[buttonKey] = {
  3903. name: button.name || buttonKey,
  3904. tooltip,
  3905. exec: function (editor) {
  3906. const context = {
  3907. editor,
  3908. button,
  3909. props,
  3910. value:
  3911. editor && typeof editor.value !== "undefined"
  3912. ? editor.value
  3913. : "",
  3914. setValue: (value) => setEditorHtml(value),
  3915. getValue: () =>
  3916. editor && typeof editor.value !== "undefined"
  3917. ? editor.value
  3918. : "",
  3919. emit,
  3920. currentModelValue: currentModelValue.value,
  3921. fjid: fjid.value,
  3922. };
  3923. if (typeof handler === "function") {
  3924. return handler(context);
  3925. }
  3926. if (typeof handler === "string") {
  3927. const windowHandler = resolveWindowFunction(handler);
  3928. if (typeof windowHandler === "function") {
  3929. return windowHandler(context);
  3930. }
  3931. console.warn("ss-editor 自定义按钮未找到点击事件:", handler);
  3932. return undefined;
  3933. }
  3934. console.warn("ss-editor 自定义按钮缺少点击事件配置:", button);
  3935. return undefined;
  3936. },
  3937. };
  3938. });
  3939. return {
  3940. controls,
  3941. buttonNames,
  3942. iconMap,
  3943. };
  3944. };
  3945. const validate = () => {
  3946. if (window.ssVm) {
  3947. const result = window.ssVm.validateField(props.name);
  3948. console.log("validate", window.ssVm.validateField(props.name));
  3949. errMsg.value = result.valid ? "" : result.message;
  3950. }
  3951. };
  3952. onMounted(() => {
  3953. validate();
  3954. // 只读模式下不初始化 Jodit,直接设置内容 by xu 20250402
  3955. if (props.mode === "play") {
  3956. if (props.html) {
  3957. setEditorHtml(props.html);
  3958. } else if (props.url) {
  3959. const params = new URLSearchParams();
  3960. if (mode) params.append("mode", mode);
  3961. if (props.modelValue) params.append("path", props.modelValue);
  3962. axios
  3963. .post(props.url, params, {
  3964. headers: {
  3965. "Content-Type": "application/x-www-form-urlencoded",
  3966. },
  3967. })
  3968. .then((response) => {
  3969. if ("timeout" == response.data.statusText) {
  3970. alert("网络超时!");
  3971. return;
  3972. }
  3973. const content = response.data.content;
  3974. if (content != null) {
  3975. setEditorHtml(content);
  3976. }
  3977. const filePath = response.data.path;
  3978. if (filePath) {
  3979. currentModelValue.value = filePath;
  3980. emit("update:modelValue", filePath);
  3981. }
  3982. });
  3983. } else {
  3984. setEditorHtml(props.html);
  3985. }
  3986. return;
  3987. }
  3988. // 读取按钮配置 by xu 20250408(移除废弃的 props.customButtons)
  3989. let buttonsToUse = [];
  3990. // 1. 优先从 param.button 数组中筛选(新格式)by xu 20250331
  3991. if (customButtonsFromParam && customButtonsFromParam.length > 0) {
  3992. buttonsToUse = customButtonsFromParam;
  3993. }
  3994. // 2. 尝试从 param.customButtons 读取(旧格式,兼容)
  3995. if (!buttonsToUse || buttonsToUse.length === 0) {
  3996. if (props.param && props.param.customButtons && props.param.customButtons.length > 0) {
  3997. buttonsToUse = props.param.customButtons;
  3998. }
  3999. }
  4000. // 3. 尝试通过桥接 API 读取
  4001. if (!buttonsToUse || buttonsToUse.length === 0) {
  4002. const vm = window.SS.dom.getVueApp({ scope: "chain" });
  4003. if (vm && vm.zwwjCustomButtons) {
  4004. buttonsToUse = vm.zwwjCustomButtons;
  4005. }
  4006. }
  4007. // 4. 从 formElemConfig 读取(兜底)
  4008. if (!buttonsToUse || buttonsToUse.length === 0) {
  4009. const zwwjConfig = window.SS.dom.formElemConfig?.zwwj;
  4010. if (zwwjConfig?.customButtons) {
  4011. buttonsToUse = zwwjConfig.customButtons;
  4012. } else {
  4013. buttonsToUse = window.SS.dom.formElemConfig?.zwwjCustomButtons;
  4014. }
  4015. }
  4016. const {
  4017. controls: customButtonControls,
  4018. buttonNames: customButtonNames,
  4019. iconMap: customButtonIconMap,
  4020. } = buildCustomButtonRegistry(buttonsToUse);
  4021. console.log(
  4022. "[SsEditor] 解析后的按钮:",
  4023. customButtonNames,
  4024. customButtonControls
  4025. );
  4026. const appendCustomButtons = (buttons = []) => {
  4027. if (!customButtonNames.length) {
  4028. return buttons;
  4029. }
  4030. const toolbarButtons = [...buttons];
  4031. const insertIndex = toolbarButtons.includes("dots")
  4032. ? toolbarButtons.indexOf("dots")
  4033. : toolbarButtons.includes("print")
  4034. ? toolbarButtons.indexOf("print")
  4035. : -1;
  4036. if (insertIndex >= 0) {
  4037. toolbarButtons.splice(insertIndex, 0, ...customButtonNames);
  4038. return toolbarButtons;
  4039. }
  4040. return [...toolbarButtons, ...customButtonNames];
  4041. };
  4042. const editor = Jodit.make(`#${uniqueId}`, {
  4043. height: props.height,
  4044. placeholder: props.placeholder,
  4045. readonly: props.mode === "play",
  4046. language: "zh_cn",
  4047. i18n: {
  4048. zh_cn: {
  4049. Link: "链接",
  4050. URL: "链接",
  4051. "No follow": "无跟踪",
  4052. "Class name": "类名",
  4053. Image: "图片",
  4054. File: "文件",
  4055. "Line height": "行高",
  4056. Alternative: "描述",
  4057. "Alternative text": "描述",
  4058. "Lower Alpha": "小写字母",
  4059. "Upper Alpha": "大写字母",
  4060. "Upper Roman": "大写罗马数字",
  4061. "Lower Roman": "小写罗马数字",
  4062. "Lower Greek": "小写希腊字母",
  4063. "Lower Letter": "小写字母",
  4064. "Upper Letter": "大写字母",
  4065. },
  4066. },
  4067. showXPathInStatusbar: false,
  4068. showCharsCounter: false,
  4069. showWordsCounter: false,
  4070. allowResizeY: false,
  4071. toolbarSticky: false,
  4072. statusbar: false,
  4073. uploader: {
  4074. url: props.uploadUrl,
  4075. format: "json",
  4076. method: "POST",
  4077. filesVariableName: function (i) {
  4078. return "imgs[" + i + "]";
  4079. },
  4080. headers: {
  4081. Accept: "application/json",
  4082. },
  4083. prepareData: function (formData) {
  4084. return formData;
  4085. },
  4086. isSuccess: function (resp) {
  4087. console.log("isSuccess resp:", resp);
  4088. return resp.code === 0;
  4089. },
  4090. getMessage: function (resp) {
  4091. console.log("getMessage resp:", resp);
  4092. return resp.msg || "上传失败";
  4093. },
  4094. process: function (resp) {
  4095. console.log("process resp:", resp);
  4096. return resp.data.url;
  4097. },
  4098. error: function (e) {
  4099. console.error("上传失败:", e.message);
  4100. },
  4101. defaultHandlerSuccess: function (resp) {
  4102. console.log("上传成功:", resp);
  4103. },
  4104. defaultHandlerError: function (err) {
  4105. console.error("上传错误:", err);
  4106. },
  4107. contentType: function () {
  4108. return false;
  4109. },
  4110. },
  4111. controls: {
  4112. font: {
  4113. list: {
  4114. Arial: "Arial",
  4115. SimSun: "宋体",
  4116. SimHei: "黑体",
  4117. "Microsoft YaHei": "微软雅黑",
  4118. KaiTi: "楷体",
  4119. FangSong: "仿宋",
  4120. "Times New Roman": "Times New Roman",
  4121. "Courier New": "Courier New",
  4122. },
  4123. },
  4124. customLinkButton: {
  4125. name: "link",
  4126. tooltip: attachmentLabel,
  4127. exec: function () {
  4128. openAttachmentDialog();
  4129. },
  4130. },
  4131. ...customButtonControls,
  4132. },
  4133. toolbarAdaptive: true,
  4134. // 调试:记录最终按钮配置
  4135. buttons: (() => {
  4136. const finalButtons = appendCustomButtons([
  4137. "fullsize",
  4138. "bold",
  4139. "italic",
  4140. "underline",
  4141. "strikethrough",
  4142. "eraser",
  4143. "|",
  4144. "font",
  4145. "fontsize",
  4146. "brush",
  4147. "paragraph",
  4148. "|",
  4149. "left",
  4150. "center",
  4151. "right",
  4152. "justify",
  4153. "|",
  4154. "ul",
  4155. "ol",
  4156. "indent",
  4157. "outdent",
  4158. "|",
  4159. "image",
  4160. "table",
  4161. "customLinkButton",
  4162. "print",
  4163. "|",
  4164. "undo",
  4165. "redo",
  4166. "find",
  4167. ]);
  4168. console.log("[SsEditor] 最终 buttons 配置:", finalButtons);
  4169. return finalButtons;
  4170. })(),
  4171. buttonsMD: appendCustomButtons([
  4172. "fullsize",
  4173. "bold",
  4174. "italic",
  4175. "underline",
  4176. "strikethrough",
  4177. "eraser",
  4178. "|",
  4179. "font",
  4180. "fontsize",
  4181. "brush",
  4182. "paragraph",
  4183. "|",
  4184. "font",
  4185. "fontsize",
  4186. "|",
  4187. "left",
  4188. "center",
  4189. "right",
  4190. "justify",
  4191. "|",
  4192. "image",
  4193. "customLinkButton",
  4194. "|",
  4195. "dots",
  4196. ]),
  4197. buttonsSM: appendCustomButtons([
  4198. "fullsize",
  4199. "bold",
  4200. "italic",
  4201. "|",
  4202. "image",
  4203. "|",
  4204. "dots",
  4205. ]),
  4206. buttonsXS: appendCustomButtons(["fullsize", "bold", "|", "dots"]),
  4207. sizeLG: 1024,
  4208. sizeMD: 768,
  4209. sizeSM: 576,
  4210. getIcon: function (name, clearName) {
  4211. const iconMap = {
  4212. bold: "editor-icon-bold",
  4213. italic: "editor-icon-italic",
  4214. underline: "editor-icon-underline",
  4215. strikethrough: "editor-icon-strikethrough",
  4216. eraser: "editor-icon-eraser",
  4217. copyformat: "editor-icon-copyformat",
  4218. font: "editor-icon-font",
  4219. fontsize: "editor-icon-fontsize",
  4220. brush: "editor-icon-brush",
  4221. paragraph: "editor-icon-paragraph",
  4222. left: "editor-icon-align-left",
  4223. center: "editor-icon-align-center",
  4224. right: "editor-icon-align-right",
  4225. justify: "editor-icon-align-justify",
  4226. ul: "editor-icon-ul",
  4227. ol: "editor-icon-ol",
  4228. indent: "editor-icon-indent",
  4229. outdent: "editor-icon-outdent",
  4230. image: "editor-icon-image",
  4231. file: "editor-icon-file",
  4232. video: "editor-icon-video",
  4233. table: "editor-icon-table",
  4234. link: "editor-icon-link",
  4235. source: "editor-icon-source",
  4236. eye: "editor-icon-preview",
  4237. fullsize: "editor-icon-fullsize",
  4238. shrink: "editor-icon-fullsize-exit",
  4239. print: "editor-icon-print",
  4240. undo: "editor-icon-undo",
  4241. redo: "editor-icon-redo",
  4242. search: "editor-icon-find",
  4243. selectall: "editor-icon-selectall",
  4244. };
  4245. const customIcon =
  4246. customButtonIconMap[clearName] || customButtonIconMap[name];
  4247. if (customIcon) {
  4248. return renderButtonIcon(customIcon);
  4249. }
  4250. const iconClass = iconMap[clearName] || iconMap[name];
  4251. if (iconClass) {
  4252. return renderButtonIcon(iconClass);
  4253. }
  4254. return null;
  4255. },
  4256. });
  4257. editorRef.value = editor;
  4258. editor.events.on("change", () => {
  4259. const html = editor.value || "";
  4260. editorContent.value = html;
  4261. syncHiddenContentInput(html);
  4262. emit("change", html);
  4263. setTimeout(() => {
  4264. validate();
  4265. }, 50);
  4266. });
  4267. emit("ready", editor);
  4268. if (props.html) {
  4269. setEditorHtml(props.html);
  4270. } else if (props.url) {
  4271. const params = new URLSearchParams();
  4272. if (mode) params.append("mode", mode);
  4273. if (props.modelValue) params.append("path", props.modelValue);
  4274. axios
  4275. .post(props.url, params, {
  4276. headers: {
  4277. "Content-Type": "application/x-www-form-urlencoded",
  4278. },
  4279. })
  4280. .then((response) => {
  4281. if ("timeout" == response.data.statusText) {
  4282. alert("网络超时!");
  4283. return;
  4284. }
  4285. const content = response.data.content;
  4286. if (content != null) {
  4287. setEditorHtml(content);
  4288. }
  4289. const filePath = response.data.path;
  4290. if (filePath) {
  4291. currentModelValue.value = filePath;
  4292. emit("update:modelValue", filePath);
  4293. }
  4294. });
  4295. } else {
  4296. setEditorHtml(props.html);
  4297. }
  4298. });
  4299. watch(
  4300. () => props.html,
  4301. (newValue) => {
  4302. setEditorHtml(newValue);
  4303. }
  4304. );
  4305. watch(
  4306. () => props.modelValue,
  4307. (newValue) => {
  4308. currentModelValue.value = newValue || "";
  4309. }
  4310. );
  4311. watch(
  4312. () => props.mode,
  4313. (newMode) => {
  4314. if (editorRef.value) {
  4315. editorRef.value.setReadOnly(newMode === "play");
  4316. }
  4317. }
  4318. );
  4319. onBeforeUnmount(() => {
  4320. if (editorRef.value) {
  4321. editorRef.value.destruct();
  4322. }
  4323. });
  4324. return () => {
  4325. const htmlFieldName = resolveHtmlFieldName();
  4326. const storeFieldName = resolveStoreFieldName();
  4327. const editorPathField = storeFieldName || props.name || "";
  4328. // 只读模式:不初始化 Jodit,直接渲染 HTML + 附件按钮 by xu 20250402
  4329. if (props.mode === "play") {
  4330. return h("div", { class: "ss-editor-container ss-editor-readonly" }, [
  4331. fjid.value &&
  4332. h("input", {
  4333. type: "hidden",
  4334. name: attachmentFieldName,
  4335. value: fjid.value,
  4336. }),
  4337. h("input", {
  4338. type: "hidden",
  4339. name: htmlFieldName,
  4340. value: editorContent.value,
  4341. }),
  4342. h("input", {
  4343. type: "hidden",
  4344. name: storeFieldName,
  4345. value: currentModelValue.value,
  4346. }),
  4347. h("input", {
  4348. type: "hidden",
  4349. name: "ueditorpath",
  4350. value: editorPathField,
  4351. }),
  4352. // 附件按钮(只读模式下仍显示)
  4353. fjButton.cmsAddUrl && fjButton.cmsUpdUrl &&
  4354. h("div", {
  4355. class: "ss-editor-attach-btn",
  4356. onClick: openAttachmentDialog,
  4357. }, [
  4358. h("span", { class: "editor-icon editor-icon-file" }),
  4359. h("span", { class: "ss-editor-attach-text" }, attachmentLabel)
  4360. ]),
  4361. // HTML 内容展示
  4362. h("div", {
  4363. class: "ss-editor-readonly-content",
  4364. innerHTML: editorContent.value,
  4365. }),
  4366. ]);
  4367. }
  4368. // 正常编辑模式:渲染 textarea 供 Jodit 初始化
  4369. return h("div", { class: "ss-editor-container" }, [
  4370. fjid.value &&
  4371. h("input", {
  4372. type: "hidden",
  4373. name: attachmentFieldName,
  4374. value: fjid.value,
  4375. }),
  4376. h("input", {
  4377. type: "hidden",
  4378. name: htmlFieldName,
  4379. value: editorContent.value,
  4380. }),
  4381. h("input", {
  4382. type: "hidden",
  4383. name: storeFieldName,
  4384. value: currentModelValue.value,
  4385. }),
  4386. h("input", {
  4387. type: "hidden",
  4388. name: "ueditorpath",
  4389. value: editorPathField,
  4390. }),
  4391. h("textarea", { id: uniqueId }),
  4392. ]);
  4393. };
  4394. },
  4395. };
  4396. // 弹窗右边图标
  4397. const SsFullStyleHeader = {
  4398. name: "SsFullStyleHeader",
  4399. props: {
  4400. title: {
  4401. type: String,
  4402. default: "标题",
  4403. },
  4404. },
  4405. emits: ["close"],
  4406. setup(props, { emit }) {
  4407. // console.log(props.title)
  4408. const onClose = () => {
  4409. emit("close");
  4410. };
  4411. const SsIcon = resolveComponent("ss-icon");
  4412. return () =>
  4413. h("div", { class: "header-container" }, [
  4414. h("div", { class: "title" }, props.title),
  4415. h("div", { class: "handle-bar" }, [
  4416. h("div", { class: "left-bar" }, [
  4417. h(SsDialogIcon, { class: "dialog-icon-download" }),
  4418. h(SsDialogIcon, { class: "dialog-icon-print" }),
  4419. h(SsDialogIcon, { class: "dialog-icon-setting" }),
  4420. h(SsDialogIcon, { class: "dialog-icon-collect" }),
  4421. h(SsDialogIcon, { class: "dialog-icon-help" }),
  4422. h(SsDialogIcon, { class: "dialog-icon-full-screen" }),
  4423. h(SsDialogIcon, { class: "dialog-icon-lock" }),
  4424. ]),
  4425. h("div", { class: "close-bar", onClick: onClose }, [
  4426. h(SsDialogIcon, { class: "dialog-icon-close" }),
  4427. ]),
  4428. ]),
  4429. ]);
  4430. },
  4431. };
  4432. // ss-dialog弹窗
  4433. const SsDialog = {
  4434. name: "SsDialog",
  4435. props: {
  4436. src: {
  4437. type: String,
  4438. },
  4439. headerTitle: {
  4440. type: String,
  4441. // required: true,
  4442. default: "弹窗",
  4443. },
  4444. width: {
  4445. type: String,
  4446. default: "1400",
  4447. },
  4448. height: {
  4449. type: String,
  4450. default: "600",
  4451. },
  4452. params: {
  4453. type: Object,
  4454. default: () => ({}),
  4455. },
  4456. zIndex: {
  4457. type: Number,
  4458. default: 1000,
  4459. },
  4460. },
  4461. emits: ["close"],
  4462. setup(props, { slots, emit }) {
  4463. // 关闭窗口方法
  4464. const onClose = () => {
  4465. emit("close");
  4466. };
  4467. const showHeader = ref(true);
  4468. const headerVisible = ref(false);
  4469. const popupHieght = ref(props.height);
  4470. // 状态:存储位置信息
  4471. const position = reactive({
  4472. // 页面居中
  4473. x: (window.innerWidth - props.width) / 2,
  4474. y: (window.innerHeight - popupHieght.value) / 2,
  4475. isDragging: false,
  4476. offsetX: 0,
  4477. offsetY: 0,
  4478. });
  4479. // 鼠标按下时设置起始坐标并开始拖拽
  4480. const startDrag = (event) => {
  4481. position.isDragging = true;
  4482. position.offsetX = event.clientX - position.x;
  4483. position.offsetY = event.clientY - position.y;
  4484. };
  4485. // 鼠标移动时更新位置
  4486. const onDrag = (event) => {
  4487. if (position.isDragging) {
  4488. position.x = event.clientX - position.offsetX;
  4489. position.y = event.clientY - position.offsetY;
  4490. }
  4491. };
  4492. // 鼠标放开时结束拖拽
  4493. const endDrag = () => {
  4494. position.isDragging = false;
  4495. };
  4496. // 监听来自 iframe 的消息
  4497. const handleMessage = (event) => {
  4498. // 顶天立地
  4499. if (event.data && typeof event.data.hasScrollBar !== "undefined") {
  4500. if (event.data.hasScrollBar) {
  4501. // console.log(event);
  4502. position.y = 10;
  4503. showHeader.value = false;
  4504. headerVisible.value = true;
  4505. popupHieght.value = window.innerHeight - 20;
  4506. // console.log(popupHieght.value);
  4507. document.querySelector(".body").style.height = "100%";
  4508. document.querySelector(".body").style.paddingTop = "30px";
  4509. document.querySelector(".header-container ").style.position =
  4510. "absolute";
  4511. document.querySelector(".header-container ").style.zIndex = "10";
  4512. }
  4513. }
  4514. };
  4515. // 鼠标移入关闭按钮区域时显示头部
  4516. const onMouseEnterCloseButton = () => {
  4517. headerVisible.value = false;
  4518. };
  4519. // 鼠标移出关闭按钮区域时隐藏头部
  4520. const onMouseLeaveCloseButton = () => {
  4521. headerVisible.value = true;
  4522. };
  4523. // 在组件挂载时添加全局事件监听器
  4524. Vue.onMounted(() => {
  4525. // 如果传过来的高度大于窗口高度,则设置为窗口高度减去20 否则保持传过来的高度
  4526. popupHieght.value =
  4527. popupHieght.value > window.innerHeight
  4528. ? window.innerHeight - 20
  4529. : popupHieght.value;
  4530. const container = document.querySelector(".header-container");
  4531. if (container) {
  4532. container.addEventListener("mousedown", startDrag);
  4533. }
  4534. document.addEventListener("mousemove", onDrag);
  4535. document.addEventListener("mouseup", endDrag);
  4536. window.addEventListener("message", handleMessage);
  4537. });
  4538. // 在组件卸载时移除全局事件监听器
  4539. Vue.onUnmounted(() => {
  4540. document.removeEventListener("mousemove", onDrag);
  4541. document.removeEventListener("mouseup", endDrag);
  4542. window.removeEventListener("message", handleMessage);
  4543. });
  4544. const SsMark = resolveComponent("ss-mark");
  4545. const SsFullStyleHeader = resolveComponent("ss-full-style-header");
  4546. // render函数定义组件结构
  4547. return () =>
  4548. h(
  4549. Teleport,
  4550. { to: "body" }, // 使用 Teleport 将弹窗内容挂载到 body
  4551. h(SsMark, {}, [
  4552. h(
  4553. "div",
  4554. {
  4555. class: "popup-container",
  4556. style: {
  4557. position: "absolute",
  4558. left: `${position.x}px`,
  4559. top: `${position.y}px`,
  4560. width: props.width + "px",
  4561. height: popupHieght.value + "px",
  4562. zIndex: props.zIndex, // 确保弹窗在最上层
  4563. },
  4564. },
  4565. [
  4566. h(SsFullStyleHeader, {
  4567. class: "header",
  4568. title: props.headerTitle,
  4569. onClose: onClose,
  4570. onMousedown: startDrag, // 绑定拖动事件
  4571. onMouseUp: endDrag,
  4572. ...(!showHeader.value && {
  4573. onMouseenter: onMouseEnterCloseButton,
  4574. onMouseleave: onMouseLeaveCloseButton,
  4575. }),
  4576. style: {
  4577. cursor: position.isDragging ? "grabbing" : "grab",
  4578. visibility: headerVisible.value ? "hidden" : "visible",
  4579. },
  4580. }),
  4581. h(
  4582. "div",
  4583. {
  4584. class: "body",
  4585. style: {},
  4586. },
  4587. [
  4588. h("iframe", {
  4589. src: props.src,
  4590. frameborder: 0,
  4591. style: { width: "100%", height: "100%" },
  4592. }),
  4593. ]
  4594. ),
  4595. headerVisible.value &&
  4596. h("div", {
  4597. class: "close-button",
  4598. onMouseenter: onMouseEnterCloseButton,
  4599. onMouseleave: onMouseLeaveCloseButton,
  4600. style: {
  4601. position: "absolute",
  4602. top: "0",
  4603. right: "0",
  4604. // background: 'black',
  4605. width: "60px",
  4606. height: "60px",
  4607. cursor: "pointer",
  4608. },
  4609. }),
  4610. ]
  4611. ),
  4612. ])
  4613. );
  4614. },
  4615. };
  4616. // ss-mark遮罩层
  4617. const SsMark = {
  4618. name: "SsMark",
  4619. setup(props, { slots, emit }) {
  4620. return () =>
  4621. h("div", { class: "dialog-container" }, [
  4622. h("div", { class: "mark-content" }, [
  4623. h("div", { class: "dialog-contianer" }, [
  4624. slots.default ? slots.default() : "",
  4625. ]),
  4626. ]),
  4627. ]);
  4628. },
  4629. };
  4630. // ss-bottom-button 底部按钮
  4631. // 修改支持更多按钮 by xu 20251211
  4632. const SsBottomButton = {
  4633. name: "SsBottomButton",
  4634. props: {
  4635. text: {
  4636. type: String,
  4637. required: false,
  4638. },
  4639. type: {
  4640. type: String,
  4641. default: "button",
  4642. },
  4643. iconClass: {
  4644. type: String,
  4645. },
  4646. class: {
  4647. type: String,
  4648. default: "",
  4649. },
  4650. onclick: {
  4651. type: [Function, String],
  4652. default: null,
  4653. },
  4654. // 修改支持更多按钮 by xu 20251211
  4655. more: {
  4656. type: [Boolean, String],
  4657. default: false,
  4658. },
  4659. },
  4660. setup(props, { emit }) {
  4661. const SsBottomDivIcon = Vue.resolveComponent("ss-bottom-div-icon");
  4662. const showDropdown = Vue.ref(false);
  4663. // 修改支持更多按钮 by xu 20251211
  4664. const moreKey = Vue.computed(() => {
  4665. const val = props.more;
  4666. if (val === false || val === null || typeof val === "undefined") {
  4667. return null;
  4668. }
  4669. if (val === true || val === "" || val === "true") {
  4670. return "moreChg";
  4671. }
  4672. return val;
  4673. });
  4674. // 从配置中读取按钮信息和下拉选项
  4675. const config = Vue.computed(() => {
  4676. if (
  4677. moreKey.value &&
  4678. window.ss &&
  4679. window.ss.dom &&
  4680. window.ss.dom.btnElemConfig
  4681. ) {
  4682. return window.ss.dom.btnElemConfig[moreKey.value] || {};
  4683. }
  4684. return {};
  4685. });
  4686. const buttonText = Vue.computed(() => {
  4687. return props.text || config.value.desc || "";
  4688. });
  4689. const dropOptions = Vue.computed(() => {
  4690. return config.value.dropOptions || [];
  4691. });
  4692. const hasDropdown = Vue.computed(() => {
  4693. return dropOptions.value.length > 0;
  4694. });
  4695. const handleMouseEnter = () => {
  4696. if (hasDropdown.value) {
  4697. showDropdown.value = true;
  4698. }
  4699. };
  4700. const handleMouseLeave = () => {
  4701. showDropdown.value = false;
  4702. };
  4703. const handleDropItemClick = (option) => {
  4704. if (option.callback && typeof option.callback === "function") {
  4705. option.callback();
  4706. }
  4707. showDropdown.value = false;
  4708. };
  4709. return () =>
  4710. h(
  4711. "div",
  4712. {
  4713. class: "ss-bottom-button-wrapper",
  4714. onMouseenter: handleMouseEnter,
  4715. onMouseleave: handleMouseLeave,
  4716. },
  4717. [
  4718. h(
  4719. "button",
  4720. {
  4721. class: props.class,
  4722. onClick: (e) => {
  4723. e.stopPropagation();
  4724. emit("click", e);
  4725. if (props.onclick) {
  4726. // 如果是函数直接调用
  4727. if (typeof props.onclick === "function") {
  4728. props.onclick(e);
  4729. } else if (typeof props.onclick === "string") {
  4730. // 如果是字符串,使用直接的方法执行
  4731. // 临时存储按钮元素到全局变量
  4732. window.__ss_current_button = e.currentTarget;
  4733. // 直接执行代码,使用eval以保留原始上下文
  4734. try {
  4735. eval(props.onclick);
  4736. } finally {
  4737. // 清理全局变量
  4738. delete window.__ss_current_button;
  4739. }
  4740. }
  4741. }
  4742. },
  4743. type: props.type,
  4744. },
  4745. [
  4746. h("span", null, [
  4747. h(SsBottomDivIcon, {
  4748. class: props.iconClass,
  4749. }),
  4750. ]),
  4751. h("span", null, buttonText.value),
  4752. ]
  4753. ),
  4754. // 渲染下拉菜单
  4755. hasDropdown.value && showDropdown.value
  4756. ? h(
  4757. "div",
  4758. {
  4759. class: "ss-bottom-button-dropdown",
  4760. },
  4761. dropOptions.value.map((option) =>
  4762. h(
  4763. "div",
  4764. {
  4765. class: "ss-bottom-button-dropdown-item",
  4766. onClick: (e) => {
  4767. e.stopPropagation();
  4768. handleDropItemClick(option);
  4769. },
  4770. },
  4771. option.desc
  4772. )
  4773. )
  4774. )
  4775. : null,
  4776. ]
  4777. );
  4778. },
  4779. };
  4780. // ss-search搜索框
  4781. const SsSearch = {
  4782. name: "SsSearch",
  4783. props: {
  4784. theme: {
  4785. type: String,
  4786. default: "light",
  4787. validator: function (value) {
  4788. return ["dark", "light"].includes(value);
  4789. },
  4790. },
  4791. placeholder: {
  4792. type: String,
  4793. default: "请输入搜索条件",
  4794. },
  4795. },
  4796. setup(props, { emit }) {
  4797. const onClick = () => {
  4798. console.log("Search clicked");
  4799. emit("click");
  4800. };
  4801. const SsIcon = Vue.resolveComponent("ss-icon");
  4802. return () =>
  4803. Vue.h(
  4804. "div",
  4805. {
  4806. class: ["search-container", props.theme],
  4807. onClick: onClick,
  4808. },
  4809. [
  4810. Vue.h("input", {
  4811. placeholder: props.placeholder,
  4812. disabled: true,
  4813. }),
  4814. Vue.h(SsIcon, {
  4815. name: "search-result",
  4816. size: "20px",
  4817. }),
  4818. ]
  4819. );
  4820. },
  4821. };
  4822. // ss-cart-item 菜单页面的卡片 左右结构
  4823. const SsCartItem = {
  4824. name: "SsCartItem",
  4825. props: {
  4826. active: Boolean,
  4827. item: {
  4828. type: Object,
  4829. default: () => ({
  4830. thumb: "images/example/project-img.png",
  4831. title: "广州(国际)科技成果转化天河基地专",
  4832. description: "佳能中国广州分公司",
  4833. all: 50,
  4834. finish: 5,
  4835. }),
  4836. },
  4837. },
  4838. setup(props, { emit }) {
  4839. const item = props.item;
  4840. const itemWidth = Vue.computed(() => {
  4841. const containerWidth =
  4842. document.body.clientWidth || document.body.scrollWidth - 520;
  4843. const halfWidth = containerWidth / 2;
  4844. if (halfWidth < 480) {
  4845. return Math.min(containerWidth, 702) + "px";
  4846. } else {
  4847. return Math.min(halfWidth, 702) + "px";
  4848. }
  4849. });
  4850. const onItemClick = (e) => {
  4851. emit("click", e);
  4852. };
  4853. return {
  4854. item,
  4855. itemWidth,
  4856. onItemClick,
  4857. };
  4858. },
  4859. render() {
  4860. const SsIcon = Vue.resolveComponent("ss-icon");
  4861. return Vue.h(
  4862. "div",
  4863. {
  4864. class: { "item-container": true, active: this.active },
  4865. onClick: this.onItemClick,
  4866. style: { width: this.itemWidth },
  4867. },
  4868. [
  4869. Vue.h("div", { class: "header" }, [
  4870. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  4871. ]),
  4872. Vue.h("div", { class: "body" }, [
  4873. Vue.h("div", { class: "left" }, [
  4874. Vue.h("img", {
  4875. src: this.item.thumb,
  4876. alt: "Thumbnail",
  4877. class: "imgUnHandle",
  4878. style: { "object-fit": "cover", width: "100%", height: "100%" },
  4879. }),
  4880. ]),
  4881. Vue.h("div", { class: "right" }, [
  4882. Vue.h("div", { class: "title" }, this.item.title),
  4883. Vue.h("div", { class: "desc" }, this.item.description),
  4884. Vue.h("div", { class: "progress" }, [
  4885. Vue.h(
  4886. "div",
  4887. {
  4888. style: {
  4889. width: `${(this.item.finish / this.item.all) * 100}%`,
  4890. },
  4891. },
  4892. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  4893. ),
  4894. ]),
  4895. ]),
  4896. ]),
  4897. ]
  4898. );
  4899. },
  4900. };
  4901. // ss-cart-item2 菜单页面的卡片 上下结构
  4902. const SsCartItem2 = {
  4903. name: "SsCartItem2",
  4904. props: {
  4905. active: Boolean,
  4906. item: {
  4907. type: Object,
  4908. default: () => ({
  4909. thumb: "images/example/project-img.png",
  4910. title: "广州(国际)科技成果转化天河基地专",
  4911. description: "佳能中国广州分公司",
  4912. all: 50,
  4913. finish: 5,
  4914. }),
  4915. },
  4916. },
  4917. setup(props, { emit }) {
  4918. const item = props.item;
  4919. const itemWidth = Vue.computed(() => {
  4920. const containerWidth =
  4921. document.body.clientWidth || document.body.scrollWidth - 520;
  4922. const halfWidth = containerWidth / 2;
  4923. if (halfWidth < 480) {
  4924. return Math.min(containerWidth, 702) + "px";
  4925. } else {
  4926. return Math.min(halfWidth, 702) + "px";
  4927. }
  4928. });
  4929. const onItemClick = (e) => {
  4930. emit("click", e);
  4931. };
  4932. return {
  4933. item,
  4934. itemWidth,
  4935. onItemClick,
  4936. };
  4937. },
  4938. render() {
  4939. const SsIcon = Vue.resolveComponent("ss-icon");
  4940. return Vue.h(
  4941. "div",
  4942. {
  4943. class: { "item-container2": true, active: this.active },
  4944. onClick: this.onItemClick,
  4945. style: { width: this.itemWidth },
  4946. },
  4947. [
  4948. Vue.h("div", { class: "action-bar" }, [
  4949. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  4950. ]),
  4951. Vue.h("div", { class: "header" }, [
  4952. Vue.h("div", { class: "title" }, `${this.item.title}`),
  4953. ]),
  4954. Vue.h("div", { class: "body" }, [
  4955. Vue.h("div", { class: "left" }, [
  4956. Vue.h("img", {
  4957. src: this.item.thumb,
  4958. alt: "Thumbnail",
  4959. class: "imgUnHandle",
  4960. style: { "object-fit": "cover", width: "100%", height: "100%" },
  4961. }),
  4962. ]),
  4963. Vue.h("div", { class: "right" }, [
  4964. Vue.h("div", { class: "content" }, this.item.description),
  4965. Vue.h("div", { class: "tip" }, [
  4966. Vue.h("div", { class: "progress" }, [
  4967. Vue.h(
  4968. "div",
  4969. {
  4970. style: {
  4971. width: `${(this.item.finish / this.item.all) * 100}%`,
  4972. },
  4973. },
  4974. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  4975. ),
  4976. ]),
  4977. ]),
  4978. ]),
  4979. ]),
  4980. ]
  4981. );
  4982. },
  4983. };
  4984. /**
  4985. * SsListCard - 列表卡片组件
  4986. *
  4987. * @description 用于显示列表项的卡片组件,支持缩略图、标签、状态、操作按钮和选择功能
  4988. *
  4989. * @prop {Object} item - 卡片数据对象
  4990. * @prop {String} item.title - 卡片标题
  4991. * @prop {String} [item.thumb] - 缩略图 URL(可选)
  4992. * @prop {String} [item.thumbType] - 缩略图类型:'thumbnail'(缩略图)或默认(证件照)
  4993. * @prop {String} [item.status] - 卡片状态:'available'(可用-绿色)、'unavailable'(不可用-黄色)、'disabled'(禁用-红色)
  4994. * @prop {Array} item.tags - 标签数组,格式:[{键: 值}, ...]
  4995. * @prop {Function} item.onclick - 点击卡片的回调函数
  4996. * @prop {Array} [item.buttons] - 操作按钮数组(可选),显示在右上角齿轮
  4997. * @prop {Array} [item.statusIcons] - 状态图标数组(可选),显示在右上角,格式:[{class: '图标类名', title: '提示文字'}, ...]
  4998. *
  4999. * @example
  5000. * // 基础用法
  5001. * const item = {
  5002. * title: "卡片标题",
  5003. * tags: [
  5004. * { 类型: '文档' },
  5005. * { 状态: '进行中' }
  5006. * ],
  5007. * onclick: () => console.log('点击了卡片')
  5008. * };
  5009. *
  5010. * @example
  5011. * // 带缩略图和状态
  5012. * const item = {
  5013. * title: "场地预定",
  5014. * thumbType: 'thumbnail',
  5015. * thumb: "https://example.com/image.jpg",
  5016. * status: "available", // 绿色背景
  5017. * tags: [{ 容量: '50人' }],
  5018. * onclick: () => {}
  5019. * };
  5020. *
  5021. * @example
  5022. * // 带操作按钮和状态图标
  5023. * const item = {
  5024. * title: "会议室A",
  5025. * tags: [{ 楼层: '3F' }],
  5026. * onclick: () => {},
  5027. * // 右上角操作按钮(齿轮)
  5028. * buttons: [{
  5029. * class: 'cart-list-setting',
  5030. * title: '编辑',
  5031. * onclick: () => console.log('编辑')
  5032. * }],
  5033. * // 右上角状态图标(在齿轮右边)
  5034. * statusIcons: [{
  5035. * class: 'icon-emoji',
  5036. * title: '清洁中'
  5037. * }]
  5038. * };
  5039. *
  5040. * @features
  5041. * - 卡片选择:鼠标悬停右下角显示选择角标,点击切换选中状态,选中后显示底部深灰色线条
  5042. * - 状态颜色:根据 status 字段显示不同背景色(可用/不可用/禁用)
  5043. * - 图片类型:支持证件照(73×100px)和缩略图(180×100px)两种尺寸
  5044. * - 操作按钮:右上角齿轮,hover 显示,支持多个按钮下拉菜单
  5045. * - 状态图标:右上角显示状态图标,齿轮会根据图标数量自动左移
  5046. *
  5047. * @author xu
  5048. * @date 20260105
  5049. */
  5050. // 组件文档补全(JSDoc) by xu 20260108
  5051. /**
  5052. * SsListCard(左侧对象卡片)
  5053. *
  5054. * 用途:
  5055. * - 渲染左侧卡片(标题 + tags)
  5056. * - 右下角“角标”用于选中/取消选中(不会触发卡片 click)
  5057. *
  5058. * 调用示例:
  5059. * ```html
  5060. * <ss-list-card :item="item" @toggle-select="handleToggleSelect" @click="openDetail"></ss-list-card>
  5061. * ```
  5062. *
  5063. * Props:
  5064. * - `item`:卡片数据对象(建议含 `id/title/tags[]`;内部会读写 `item._ssSelected` 作为选中态)
  5065. *
  5066. * Emits:
  5067. * - `toggle-select`:点击角标触发,参数 `{ item, selected }`
  5068. * - `click`:点击卡片主体触发(用于打开详情等)
  5069. */
  5070. const SsListCard = {
  5071. name: "SsListCard",
  5072. props: {
  5073. ssObjName: { type: String, default: "" }, // 功能:业务对象名(用于默认缩略图 icon) by xu 20260109
  5074. cardClickAction: { type: String, default: "view" }, // 功能:卡片主体点击动作(view=查看;single=单选互斥) by xu 20260109
  5075. item: {
  5076. type: Object,
  5077. required: true,
  5078. },
  5079. },
  5080. emits: ["click", "change", "toggle-select"],
  5081. setup(props, { emit }) {
  5082. const item = props.item;
  5083. // 移除 itemWidth 计算属性,不再需要 by xu 20260105
  5084. // 判断卡片类型 by xu 20260105
  5085. const cardType = Vue.computed(() => {
  5086. // 支持“无图但保留缩略图占位”(同一业务列表图片形态一致) by xu 20260109
  5087. if (!item.thumb && !item.thumbType) return ""; // 业务列表“无图”形态
  5088. // 根据 thumbType 字段判断,如果没有则默认为证件照
  5089. return item.thumbType === "thumbnail" ? "card-thumbnail" : "card-photo";
  5090. });
  5091. // 判断状态类型 - 场地预定状态 by xu 20260105
  5092. const statusClass = Vue.computed(() => {
  5093. if (!item.status) return ""; // 无状态,默认白色
  5094. // 映射状态值到 CSS 类名
  5095. const statusMap = {
  5096. available: "status-available",
  5097. unavailable: "status-unavailable",
  5098. disabled: "status-disabled",
  5099. };
  5100. return statusMap[item.status] || "";
  5101. });
  5102. const onItemClick = (e) => {
  5103. // 清除所有类型卡片的 active 状态(卡片主体点击仅做 active 高亮) by xu 20260109
  5104. const allListCards = document.querySelectorAll(
  5105. ".knowledge-item-container"
  5106. );
  5107. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  5108. allListCards.forEach((card) => card.classList.remove("active"));
  5109. allFolderCards.forEach((card) => card.classList.remove("active"));
  5110. // 设置当前项的 active 状态
  5111. e.currentTarget.classList.add("active");
  5112. // 卡片主体点击动作由页面级配置控制 by xu 20260109
  5113. if (props.cardClickAction === "view") {
  5114. props.item.onclick?.();
  5115. // 通知父级:卡片点击(查看) by xu 20260109
  5116. emit("click", props.item);
  5117. }
  5118. };
  5119. const onItemChange = (e, icon, index) => {
  5120. e.stopPropagation(); // 阻止事件冒泡到卡片
  5121. props.item.buttons[0].onclick();
  5122. // emit("change", { item: props.item, icon, index });
  5123. };
  5124. return {
  5125. item,
  5126. cardType,
  5127. statusClass,
  5128. onItemClick,
  5129. onItemChange,
  5130. };
  5131. },
  5132. data() {
  5133. return {
  5134. showButtons: false,
  5135. selected: false, // 选择状态 by xu 20260105
  5136. showTextPopover: false, // 功能:右侧文字区 hover 展示全量 by xu 20260108
  5137. textPopoverType: "", // second-summary / second-tags / third / third-full by xu 20260108
  5138. textPopoverBottom: 0, // 功能:popover 从当前省略行位置向上展开 by xu 20260108
  5139. hideTextPopoverTimer: null, // 功能:鼠标从省略行移到浮层的缓冲 by xu 20260108
  5140. textPopoverPayload: null, // { kind, text?, lines? } by xu 20260108
  5141. ellipsisVisible: {
  5142. // 功能:只在真实出现 ... 时才显示命中区/允许 goheight by xu 20260109
  5143. secondSummary: false,
  5144. secondTags: false,
  5145. third: false,
  5146. thirdFull: false,
  5147. },
  5148. };
  5149. },
  5150. methods: {
  5151. __allowSelect() {
  5152. // 功能说明:无 rbarObj 时禁用选中能力(隐藏右下角勾选并禁止 toggle) by xu 20260122
  5153. try {
  5154. if (this?.$root && this.$root.hasObjPanel === false) return false;
  5155. if (
  5156. typeof window !== "undefined" &&
  5157. window.__objListVm &&
  5158. window.__objListVm.hasObjPanel === false
  5159. )
  5160. return false;
  5161. } catch (_) {}
  5162. return true;
  5163. },
  5164. // 切换选择状态(对外 emit,支持方案A父级 state 中转) by xu 20260106
  5165. toggleSelect(e) {
  5166. e.stopPropagation();
  5167. if (!this.__allowSelect()) return; // 功能说明:无 rbarObj 时禁止选中 by xu 20260122
  5168. // 使用 item 上的状态,便于父级/右侧边栏反向同步 by xu 20260106
  5169. this.item._ssSelected = !this.item?._ssSelected;
  5170. this.$emit("toggle-select", {
  5171. item: this.item,
  5172. selected: !!this.item?._ssSelected,
  5173. });
  5174. },
  5175. // 卡片主体点击=单选互斥:只有“本次切到选中”才清理其他选中 by xu 20260109
  5176. toggleSelectExclusive(e) {
  5177. e?.stopPropagation?.();
  5178. if (!this.__allowSelect()) return; // 功能说明:无 rbarObj 时禁止选中 by xu 20260122
  5179. this.item._ssSelected = !this.item?._ssSelected;
  5180. const selected = !!this.item?._ssSelected;
  5181. this.$emit("toggle-select", {
  5182. item: this.item,
  5183. selected,
  5184. exclusive: true,
  5185. });
  5186. },
  5187. // 功能:无缩略图时,用业务对象 icon 做默认图(ss-icon + icon-obj-xx) by xu 20260109
  5188. getBizThumbIconClass() {
  5189. const name = String(
  5190. this.ssObjName ||
  5191. this.item?.ssObjName ||
  5192. this.$root?.ssObjName ||
  5193. window?.ss?.dom?.ssObjName ||
  5194. ""
  5195. ).trim();
  5196. if (!name) return "";
  5197. return `icon-obj-${name}`;
  5198. },
  5199. // 功能:构造右侧文字区 4 行(摘要/类目或标签/对象号) by xu 20260108
  5200. buildRightTextLines() {
  5201. const item = this.item || {};
  5202. const summary = String(item?.desc ?? "").trim(); // 后端字段后续映射 by xu 20260108
  5203. const objNum = String(item?.objNum ?? "").trim(); // 后端字段后续映射 by xu 20260108
  5204. const categoryArr = Array.isArray(item?.category) ? item.category : [];
  5205. const tagsArr = Array.isArray(item?.tags) ? item.tags : [];
  5206. const hasTags = tagsArr.length > 0;
  5207. const hasCategory = categoryArr.length > 0;
  5208. // 第二部分(L1-L3):摘要优先,其次物品参数 by xu 20260108
  5209. const secondKind = summary ? "summary" : hasTags ? "tags" : "";
  5210. const hasSecond = !!secondKind;
  5211. // 第三部分(L4):对象号优先,其次类目 by xu 20260108
  5212. const thirdKind = objNum ? "objNum" : hasCategory ? "category" : "";
  5213. const hasThird = !!thirdKind;
  5214. const thirdFull = !hasSecond && hasThird; // 第二部分为空则第三部分占满 4 行 by xu 20260108
  5215. const secondFull = hasSecond && !hasThird && secondKind === "tags"; // 仅标签时占满 4 行(不留空行) by xu 20260109
  5216. const toValueText = (obj) => {
  5217. // 功能说明:类目/物品参数回显展示 key: value(否则只显示值看不懂) by xu 20260114
  5218. const [k, v] = Object.entries(obj || {})[0] || ["", ""];
  5219. const key = k !== undefined && k !== null ? String(k).trim() : "";
  5220. const val = v !== undefined && v !== null ? String(v).trim() : "";
  5221. if (key && val) return `${key}:${val}`;
  5222. if (val) return val;
  5223. if (key) return key;
  5224. return "";
  5225. };
  5226. const toLineList = (arr) =>
  5227. (arr || [])
  5228. .map(toValueText)
  5229. .map((s) => String(s ?? "").trim())
  5230. .filter(Boolean);
  5231. const flat = (arr) => toLineList(arr).join(" ");
  5232. // 第二部分 tags:默认 3 行;仅标签时占满 4 行(避免底部空一行) by xu 20260109
  5233. const secondTagsMaxLines = secondFull ? 4 : 3;
  5234. const secondTagsLinesFull = toLineList(tagsArr);
  5235. const secondTagsHead = secondTagsLinesFull.slice(
  5236. 0,
  5237. Math.max(0, secondTagsMaxLines - 1)
  5238. );
  5239. const secondTagsTail = secondTagsLinesFull.slice(
  5240. Math.max(0, secondTagsMaxLines - 1)
  5241. );
  5242. const secondTagsLast =
  5243. secondTagsTail.length <= 1
  5244. ? secondTagsTail[0] || ""
  5245. : secondTagsTail.join(" "); // 功能:最后一行平铺剩余 by xu 20260108
  5246. // 第三部分类目:卡片上串成一行;goheight 展开时一条一行 by xu 20260109
  5247. const categoryLinesFull = toLineList(categoryArr);
  5248. const categoryLine = categoryLinesFull.join(" ");
  5249. const thirdText =
  5250. thirdKind === "objNum"
  5251. ? objNum
  5252. : thirdKind === "category"
  5253. ? categoryLine
  5254. : "";
  5255. return {
  5256. secondKind,
  5257. thirdKind,
  5258. hasSecond,
  5259. hasThird,
  5260. thirdFull,
  5261. secondFull,
  5262. summary,
  5263. secondTagsMaxLines,
  5264. secondTagsHead,
  5265. secondTagsLast,
  5266. secondTagsLinesFull,
  5267. objNum,
  5268. categoryLine,
  5269. categoryLinesFull,
  5270. thirdText,
  5271. };
  5272. },
  5273. measureTextOverflowByLines(text, maxLines, width) {
  5274. const w = Number(width) || 0;
  5275. if (!w || !text) return false;
  5276. const probe = document.createElement("div");
  5277. probe.style.position = "fixed";
  5278. probe.style.left = "-99999px";
  5279. probe.style.top = "0";
  5280. probe.style.width = w + "px";
  5281. probe.style.fontSize = "18px";
  5282. probe.style.lineHeight = "24px";
  5283. probe.style.whiteSpace = "normal";
  5284. probe.style.wordBreak = "break-word";
  5285. probe.style.visibility = "hidden";
  5286. probe.textContent = text;
  5287. document.body.appendChild(probe);
  5288. const h = probe.getBoundingClientRect().height || 0;
  5289. document.body.removeChild(probe);
  5290. return h > maxLines * 24 + 1;
  5291. },
  5292. measureSingleLineOverflow(text, width) {
  5293. const w = Number(width) || 0;
  5294. if (!w || !text) return false;
  5295. const probe = document.createElement("span");
  5296. probe.style.position = "fixed";
  5297. probe.style.left = "-99999px";
  5298. probe.style.top = "0";
  5299. probe.style.display = "inline-block";
  5300. probe.style.maxWidth = w + "px";
  5301. probe.style.fontSize = "18px";
  5302. probe.style.lineHeight = "24px";
  5303. probe.style.whiteSpace = "nowrap";
  5304. probe.style.visibility = "hidden";
  5305. probe.textContent = text;
  5306. document.body.appendChild(probe);
  5307. const overflow =
  5308. (probe.scrollWidth || 0) > (probe.clientWidth || w) + 1;
  5309. document.body.removeChild(probe);
  5310. return overflow;
  5311. },
  5312. // 功能:根据当前卡片宽度刷新「是否出现 ...」状态(用于控制命中区显示) by xu 20260109
  5313. refreshEllipsisVisible() {
  5314. try {
  5315. const right = this.$el?.querySelector?.(".right");
  5316. const rawWidth =
  5317. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  5318. const width = Math.max(0, Math.round(rawWidth)); // 修复:内容区不再使用 padding-right 预留,测量按真实宽度 by xu 20260109
  5319. const model = this.buildRightTextLines();
  5320. const next = {
  5321. secondSummary: false,
  5322. secondTags: false,
  5323. third: false,
  5324. thirdFull: false,
  5325. };
  5326. if (model.secondKind === "summary" && model.summary) {
  5327. next.secondSummary = this.measureTextOverflowByLines(
  5328. model.summary,
  5329. 3,
  5330. width
  5331. );
  5332. }
  5333. if (model.secondKind === "tags") {
  5334. // 功能说明:tags 采用「最后一行平铺剩余」策略,是否出现 ... 仅取决于最后一行是否溢出(数量多但平铺放得下不算溢出) by xu 20260114
  5335. next.secondTags = this.measureSingleLineOverflow(
  5336. model.secondTagsLast,
  5337. width
  5338. );
  5339. }
  5340. if (model.hasThird && !model.thirdFull) {
  5341. next.third = this.measureSingleLineOverflow(model.thirdText, width);
  5342. }
  5343. if (model.hasThird && model.thirdFull) {
  5344. next.thirdFull = this.measureTextOverflowByLines(
  5345. model.thirdText,
  5346. 4,
  5347. width
  5348. );
  5349. }
  5350. const prev = this.ellipsisVisible || {};
  5351. const changed =
  5352. prev.secondSummary !== next.secondSummary ||
  5353. prev.secondTags !== next.secondTags ||
  5354. prev.third !== next.third ||
  5355. prev.thirdFull !== next.thirdFull;
  5356. if (changed) this.ellipsisVisible = next;
  5357. } catch (e) {
  5358. // ignore by xu 20260109
  5359. }
  5360. },
  5361. showTextPopoverFor(el, kind) {
  5362. // 调试开关:window.__SS_LISTCARD_DEBUG__ = true 时打印 hover/溢出判断日志 by xu 20260108
  5363. const debug =
  5364. typeof window !== "undefined" && !!window.__SS_LISTCARD_DEBUG__;
  5365. if (debug) {
  5366. console.log("[SsListCard] ellipsis hover", {
  5367. kind,
  5368. el: el?.className,
  5369. });
  5370. }
  5371. const model = this.buildRightTextLines();
  5372. const lineEl = el?.closest?.(".ss-card-text__line") || el;
  5373. const right = lineEl?.closest?.(".right") || el?.closest?.(".right");
  5374. const rawWidth =
  5375. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  5376. const width = Math.max(0, Math.round(rawWidth)); // 修复:内容区不再预留 padding-right,测量按真实宽度 by xu 20260109
  5377. const textEl =
  5378. kind === "second-summary"
  5379. ? lineEl?.querySelector?.(".ss-card-text__secondSummary")
  5380. : kind === "second-tags"
  5381. ? lineEl?.querySelector?.(".ss-card-text__tagLineLast")
  5382. : kind === "third"
  5383. ? lineEl?.querySelector?.(".ss-card-text__thirdLine")
  5384. : lineEl?.querySelector?.(".ss-card-text__thirdFull");
  5385. let payload = null;
  5386. // 仅当真实会出现 ... 时才允许 goheight(避免“没超出也能出 goheight”) by xu 20260109
  5387. const overflowed =
  5388. kind === "second-summary"
  5389. ? this.measureTextOverflowByLines(model.summary, 3, width)
  5390. : kind === "second-tags"
  5391. ? this.measureSingleLineOverflow(model.secondTagsLast, width) // 功能说明:同 refreshEllipsisVisible,tags 仅看最后一行是否溢出 by xu 20260114
  5392. : kind === "third"
  5393. ? this.measureSingleLineOverflow(model.thirdText, width)
  5394. : this.measureTextOverflowByLines(model.thirdText, 4, width);
  5395. if (!overflowed) return;
  5396. if (kind === "second-summary") {
  5397. if (model.summary) payload = { kind, text: model.summary };
  5398. } else if (kind === "second-tags") {
  5399. if (
  5400. Array.isArray(model.secondTagsLinesFull) &&
  5401. model.secondTagsLinesFull.length
  5402. ) {
  5403. payload = { kind, lines: model.secondTagsLinesFull };
  5404. }
  5405. } else if (kind === "third") {
  5406. if (
  5407. model.thirdKind === "category" &&
  5408. Array.isArray(model.categoryLinesFull) &&
  5409. model.categoryLinesFull.length
  5410. ) {
  5411. payload = { kind, lines: model.categoryLinesFull }; // 功能:类目展开一条一行 by xu 20260109
  5412. } else if (model.thirdText) {
  5413. payload = { kind, text: model.thirdText };
  5414. }
  5415. } else if (kind === "third-full") {
  5416. if (
  5417. model.thirdKind === "category" &&
  5418. Array.isArray(model.categoryLinesFull) &&
  5419. model.categoryLinesFull.length
  5420. ) {
  5421. payload = { kind, lines: model.categoryLinesFull }; // 功能:类目占满模式展开一条一行 by xu 20260109
  5422. } else if (model.thirdText) {
  5423. payload = { kind, text: model.thirdText };
  5424. }
  5425. }
  5426. if (debug) {
  5427. console.log("[SsListCard] ellipsis decide", {
  5428. kind,
  5429. rawWidth: Math.round(rawWidth),
  5430. width,
  5431. hasPayload: !!payload,
  5432. textEl: textEl?.className,
  5433. textClient: textEl
  5434. ? {
  5435. cw: textEl.clientWidth,
  5436. ch: textEl.clientHeight,
  5437. sw: textEl.scrollWidth,
  5438. sh: textEl.scrollHeight,
  5439. }
  5440. : null,
  5441. });
  5442. }
  5443. if (!payload) return;
  5444. this.clearHideTextPopoverTimer();
  5445. const container = lineEl?.closest?.(".right");
  5446. const containerRect = container?.getBoundingClientRect?.();
  5447. const lineRect = lineEl?.getBoundingClientRect?.();
  5448. if (containerRect && lineRect) {
  5449. const bottom = Math.max(
  5450. 0,
  5451. Math.round(containerRect.bottom - lineRect.bottom)
  5452. );
  5453. this.textPopoverBottom = bottom;
  5454. } else {
  5455. this.textPopoverBottom = 0;
  5456. }
  5457. this.textPopoverPayload = payload;
  5458. this.textPopoverType = kind;
  5459. this.showTextPopover = true;
  5460. if (debug) console.log("[SsListCard] goheight show", payload);
  5461. },
  5462. isOverflowing(el) {
  5463. if (!el) return false;
  5464. // 单行/多行省略统一判断:scroll 尺寸大于 client 尺寸即认为有 ... by xu 20260108
  5465. return (
  5466. (el.scrollWidth &&
  5467. el.clientWidth &&
  5468. el.scrollWidth > el.clientWidth + 1) ||
  5469. (el.scrollHeight &&
  5470. el.clientHeight &&
  5471. el.scrollHeight > el.clientHeight + 1)
  5472. );
  5473. },
  5474. isSummaryOverflowing(el) {
  5475. if (!el) return false;
  5476. // -webkit-line-clamp 场景下 scrollHeight 不稳定,改用“无 clamp 的离屏测量”判断是否超过 2 行 by xu 20260108
  5477. const text = String(this.item?.desc ?? "").trim();
  5478. if (!text) return false;
  5479. const rect = el.getBoundingClientRect?.();
  5480. const width = rect?.width || el.clientWidth || 0;
  5481. if (!width) return false;
  5482. const probe = document.createElement("div");
  5483. probe.style.position = "fixed";
  5484. probe.style.left = "-99999px";
  5485. probe.style.top = "0";
  5486. probe.style.width = width + "px";
  5487. probe.style.fontSize = "18px";
  5488. probe.style.lineHeight = "24px";
  5489. probe.style.whiteSpace = "normal";
  5490. probe.style.wordBreak = "break-word";
  5491. probe.style.visibility = "hidden";
  5492. probe.textContent = text;
  5493. document.body.appendChild(probe);
  5494. const h = probe.getBoundingClientRect().height || 0;
  5495. document.body.removeChild(probe);
  5496. return h > 48 + 1;
  5497. },
  5498. clearHideTextPopoverTimer() {
  5499. if (this.hideTextPopoverTimer) {
  5500. clearTimeout(this.hideTextPopoverTimer);
  5501. this.hideTextPopoverTimer = null;
  5502. }
  5503. },
  5504. // 修复 goheight hover 无响应:移除重复方法覆盖,统一使用上面的 showTextPopoverFor(el, kind) by xu 20260109
  5505. hideTextPopoverLater() {
  5506. this.clearHideTextPopoverTimer();
  5507. this.hideTextPopoverTimer = setTimeout(() => {
  5508. this.showTextPopover = false;
  5509. this.textPopoverType = "";
  5510. this.textPopoverPayload = null;
  5511. }, 120);
  5512. },
  5513. hideTextPopover() {
  5514. this.clearHideTextPopoverTimer();
  5515. this.showTextPopover = false;
  5516. this.textPopoverType = "";
  5517. this.textPopoverPayload = null;
  5518. },
  5519. // 功能:新需求下不在 updated 内做测量,避免死循环 by xu 20260108
  5520. },
  5521. mounted() {
  5522. // 无需在 mounted/updated 里做 overflow 测量(避免死循环),只在 hover 触发时判断 by xu 20260108
  5523. // 仅用于控制“...命中区是否显示”,不会触发循环更新 by xu 20260109
  5524. this.$nextTick?.(() => {
  5525. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5526. });
  5527. this.__ssListCardResizeHandler = () => this.refreshEllipsisVisible?.(); // 功能:窗口变化时刷新 ... 显示 by xu 20260109
  5528. window.addEventListener?.("resize", this.__ssListCardResizeHandler);
  5529. },
  5530. updated() {
  5531. // 卡片数据更新后刷新一次 ... 显示状态(避免“宽度/内容变了但命中区不变”) by xu 20260109
  5532. this.$nextTick?.(() => {
  5533. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5534. });
  5535. },
  5536. beforeUnmount() {
  5537. // 清理 timer,避免残留导致异常 by xu 20260108
  5538. this.clearHideTextPopoverTimer?.();
  5539. if (this.__ssListCardResizeHandler) {
  5540. window.removeEventListener?.("resize", this.__ssListCardResizeHandler);
  5541. this.__ssListCardResizeHandler = null;
  5542. }
  5543. },
  5544. render() {
  5545. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  5546. const SsIcon = Vue.resolveComponent("ss-icon");
  5547. const hasThumbArea = !!(this.item?.thumb || this.item?.thumbType); // 功能:无图但有 thumbType 时仍保留占位 by xu 20260109
  5548. const thumbSrc = (() => {
  5549. // 功能说明:兼容 thumb 为 raw path 或 {val}/{value},组件内统一转为 dlByHttp URL by xu 20260122
  5550. const t = this.item?.thumb;
  5551. if (!t) return "";
  5552. if (typeof t === "string") {
  5553. const s = t.trim();
  5554. if (!s) return "";
  5555. // 已经是 URL/绝对路径则直接使用;否则按 path 构建 dlByHttp by xu 20260122
  5556. if (
  5557. /^https?:\/\//i.test(s) ||
  5558. s.startsWith("/service?") ||
  5559. s.startsWith("/")
  5560. )
  5561. return s;
  5562. return buildThumbUrl(s);
  5563. }
  5564. return buildThumbUrl(t);
  5565. })();
  5566. return Vue.h(
  5567. "div",
  5568. {
  5569. class: {
  5570. "knowledge-item-container": true,
  5571. active: this.item.active,
  5572. [this.cardType]: !!this.cardType, // 动态添加卡片类型类名 by xu 20260105
  5573. [this.statusClass]: !!this.statusClass,
  5574. },
  5575. onClick: (e) => {
  5576. this.onItemClick?.(e);
  5577. if (this.__allowSelect() && this.cardClickAction === "single") {
  5578. // 功能说明:无 rbarObj 时不允许单选互斥 by xu 20260122
  5579. this.toggleSelectExclusive?.(e);
  5580. }
  5581. }, // 功能:卡片主体点击动作(view/single) by xu 20260109
  5582. // 移除固定宽度,由 CSS min-width 控制 by xu 20260105
  5583. },
  5584. [
  5585. // 右上角状态图标区域 by xu 20260105
  5586. this.item?.statusIcons?.length > 0 &&
  5587. Vue.h(
  5588. "div",
  5589. { class: "card-status-icons" },
  5590. this.item.statusIcons.map((icon) =>
  5591. Vue.h(SsIcon, {
  5592. class: `status-icon ${icon.class}`,
  5593. title: icon.title,
  5594. })
  5595. )
  5596. ),
  5597. this.item?.buttons?.length > 0 &&
  5598. Vue.h(
  5599. "div",
  5600. {
  5601. class: "header",
  5602. style:
  5603. this.item?.statusIcons?.length > 0
  5604. ? {
  5605. right: `${this.item.statusIcons.length * 48}px`,
  5606. borderTopRightRadius: "0",
  5607. }
  5608. : {},
  5609. onMouseenter: () => (this.showButtons = true),
  5610. onMouseleave: () => (this.showButtons = false),
  5611. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  5612. },
  5613. [
  5614. // 只在有按钮时渲染设置图标
  5615. // this.item?.buttons?.length > 0 &&
  5616. Vue.h("div", {
  5617. class: "cart-list-setting cart-list-icon",
  5618. title: this.item?.buttons?.[0]?.title,
  5619. }),
  5620. // 鼠标移入时显示按钮列表,与图标同级
  5621. // this.item?.buttons?.length > 0 &&
  5622. this.showButtons &&
  5623. this.item?.buttons?.length > 1 &&
  5624. Vue.h(
  5625. "div",
  5626. {
  5627. class: "cart-list-button-popup",
  5628. },
  5629. this.item.buttons.map((btn) =>
  5630. Vue.h(
  5631. "div",
  5632. {
  5633. onClick: (e) => {
  5634. e.stopPropagation();
  5635. btn.onclick?.();
  5636. },
  5637. },
  5638. [
  5639. // 如果有 class,显示对应的图标
  5640. btn.class &&
  5641. Vue.h(SsCartListIcon, {
  5642. class: [btn.class],
  5643. }),
  5644. // 显示按钮文本
  5645. Vue.h("span", null, btn.title),
  5646. ]
  5647. )
  5648. )
  5649. ),
  5650. ]
  5651. ),
  5652. Vue.h("div", { class: "body" }, [
  5653. Vue.h("div", { class: "box-header" }, [
  5654. Vue.h("div", `${this.item.title}`),
  5655. ]),
  5656. Vue.h(
  5657. "div",
  5658. {
  5659. class: !hasThumbArea ? "no-thumb box-body" : "box-body",
  5660. },
  5661. [
  5662. hasThumbArea
  5663. ? thumbSrc
  5664. ? Vue.h("div", { class: "left" }, [
  5665. Vue.h("img", {
  5666. src: thumbSrc,
  5667. alt: "Thumbnail",
  5668. class: "imgUnHandle",
  5669. style: {
  5670. "object-fit": "cover",
  5671. width: "100%",
  5672. height: "100%",
  5673. },
  5674. }),
  5675. ])
  5676. : Vue.h(
  5677. // 功能:无图占位(ss-icon + biz icon,居中) by xu 20260109
  5678. "div",
  5679. { class: "left ss-objlist-thumbPlaceholder" },
  5680. [
  5681. Vue.h(SsIcon, {
  5682. class: `${this.getBizThumbIconClass()} ss-objlist-thumbIcon`,
  5683. }),
  5684. ]
  5685. )
  5686. : null,
  5687. Vue.h(
  5688. "div",
  5689. {
  5690. class: "right",
  5691. },
  5692. (() => {
  5693. const model = this.buildRightTextLines(); // 功能:右侧文字区新规则(第二部分/第三部分优先级) by xu 20260108
  5694. const hasAny = !!(model?.hasSecond || model?.hasThird);
  5695. if (!hasAny) return [];
  5696. const children = [];
  5697. // 第二部分:L1-L3(摘要优先,其次 tags;不足留空;超出 L3 ...) by xu 20260108
  5698. if (model.hasSecond) {
  5699. if (model.secondKind === "summary") {
  5700. children.push(
  5701. Vue.h(
  5702. "div",
  5703. {
  5704. class:
  5705. "ss-card-text__line ss-card-text__secondBlock",
  5706. },
  5707. [
  5708. Vue.h(
  5709. "div",
  5710. {
  5711. class: "ss-card-text__secondSummary",
  5712. title: model.summary,
  5713. },
  5714. model.summary
  5715. ),
  5716. Vue.h("span", {
  5717. class: [
  5718. "ss-card-text__ellipsisHit",
  5719. "ss-card-text__ellipsisHit--second",
  5720. this.ellipsisVisible?.secondSummary
  5721. ? "is-on"
  5722. : "",
  5723. ],
  5724. title: "查看完整摘要",
  5725. onMouseenter: (e) =>
  5726. this.showTextPopoverFor(
  5727. e?.currentTarget,
  5728. "second-summary"
  5729. ),
  5730. onClick: (e) => {
  5731. e?.stopPropagation?.();
  5732. this.showTextPopoverFor(
  5733. e?.currentTarget,
  5734. "second-summary"
  5735. );
  5736. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5737. onMouseleave: () => this.hideTextPopoverLater(),
  5738. }),
  5739. ]
  5740. )
  5741. );
  5742. } else if (model.secondKind === "tags") {
  5743. children.push(
  5744. Vue.h(
  5745. "div",
  5746. {
  5747. class: [
  5748. "ss-card-text__line",
  5749. model.secondFull
  5750. ? "ss-card-text__secondFullBlock"
  5751. : "ss-card-text__secondBlock",
  5752. ],
  5753. },
  5754. [
  5755. // 功能:仅标签时占满 4 行 by xu 20260109
  5756. Vue.h(
  5757. "div",
  5758. { class: "ss-card-text__secondTags" },
  5759. [
  5760. ...model.secondTagsHead.map((t) =>
  5761. Vue.h(
  5762. "div",
  5763. {
  5764. class: "ss-card-text__tagLine",
  5765. title: t,
  5766. },
  5767. t
  5768. )
  5769. ),
  5770. // 第三行:平铺剩余(可能为空) by xu 20260108
  5771. Vue.h(
  5772. "div",
  5773. {
  5774. class:
  5775. "ss-card-text__tagLine is-last ss-card-text__tagLineLast",
  5776. title: model.secondTagsLast,
  5777. },
  5778. model.secondTagsLast
  5779. ),
  5780. ].filter(Boolean)
  5781. ),
  5782. // 只在最后一行出现 ... 时才触发 goheight by xu 20260108
  5783. Vue.h("span", {
  5784. class: [
  5785. "ss-card-text__ellipsisHit",
  5786. "ss-card-text__ellipsisHit--second",
  5787. this.ellipsisVisible?.secondTags
  5788. ? "is-on"
  5789. : "",
  5790. ],
  5791. title: "查看完整物品参数",
  5792. onMouseenter: (e) =>
  5793. this.showTextPopoverFor(
  5794. e?.currentTarget,
  5795. "second-tags"
  5796. ),
  5797. onClick: (e) => {
  5798. e?.stopPropagation?.();
  5799. this.showTextPopoverFor(
  5800. e?.currentTarget,
  5801. "second-tags"
  5802. );
  5803. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5804. onMouseleave: () => this.hideTextPopoverLater(),
  5805. }),
  5806. ]
  5807. )
  5808. );
  5809. }
  5810. }
  5811. // 第三部分:默认 L4;第二部分为空则占满 L1-L4 by xu 20260108
  5812. if (model.hasThird) {
  5813. if (model.thirdFull) {
  5814. children.push(
  5815. Vue.h(
  5816. "div",
  5817. {
  5818. class:
  5819. "ss-card-text__line ss-card-text__thirdFullBlock",
  5820. },
  5821. [
  5822. Vue.h(
  5823. "div",
  5824. {
  5825. class: "ss-card-text__thirdFull",
  5826. title: model.thirdText,
  5827. },
  5828. model.thirdText
  5829. ),
  5830. Vue.h("span", {
  5831. class: [
  5832. "ss-card-text__ellipsisHit",
  5833. "ss-card-text__ellipsisHit--third",
  5834. this.ellipsisVisible?.thirdFull
  5835. ? "is-on"
  5836. : "",
  5837. ],
  5838. title: "查看完整信息",
  5839. onMouseenter: (e) =>
  5840. this.showTextPopoverFor(
  5841. e?.currentTarget,
  5842. "third-full"
  5843. ),
  5844. onClick: (e) => {
  5845. e?.stopPropagation?.();
  5846. this.showTextPopoverFor(
  5847. e?.currentTarget,
  5848. "third-full"
  5849. );
  5850. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5851. onMouseleave: () => this.hideTextPopoverLater(),
  5852. }),
  5853. ]
  5854. )
  5855. );
  5856. } else {
  5857. children.push(
  5858. Vue.h(
  5859. "div",
  5860. {
  5861. class:
  5862. "ss-card-text__line ss-card-text__thirdLineWrap",
  5863. },
  5864. [
  5865. Vue.h(
  5866. "div",
  5867. {
  5868. class: "ss-card-text__thirdLine",
  5869. title: model.thirdText,
  5870. },
  5871. model.thirdText
  5872. ),
  5873. Vue.h("span", {
  5874. class: [
  5875. "ss-card-text__ellipsisHit",
  5876. "ss-card-text__ellipsisHit--third",
  5877. this.ellipsisVisible?.third ? "is-on" : "",
  5878. ],
  5879. title: "查看完整信息",
  5880. onMouseenter: (e) =>
  5881. this.showTextPopoverFor(
  5882. e?.currentTarget,
  5883. "third"
  5884. ),
  5885. onClick: (e) => {
  5886. e?.stopPropagation?.();
  5887. this.showTextPopoverFor(
  5888. e?.currentTarget,
  5889. "third"
  5890. );
  5891. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5892. onMouseleave: () => this.hideTextPopoverLater(),
  5893. }),
  5894. ]
  5895. )
  5896. );
  5897. }
  5898. }
  5899. // hover 展开浮层:宽度=右侧文字区,底对齐向上展开,带阴影 by xu 20260108
  5900. // popover 作为 `.right` 的 sibling 渲染,避免被 `.ss-card-text{overflow:hidden}` 裁剪 by xu 20260108
  5901. const popover =
  5902. this.showTextPopover &&
  5903. Vue.h(
  5904. "div",
  5905. {
  5906. class: "ss-card-text-popover",
  5907. style: { bottom: this.textPopoverBottom + "px" },
  5908. onMouseenter: () => {
  5909. this.clearHideTextPopoverTimer();
  5910. this.showTextPopover = true;
  5911. },
  5912. onMouseleave: () => this.hideTextPopoverLater(),
  5913. },
  5914. (() => {
  5915. const p = this.textPopoverPayload || {};
  5916. if (p.kind === "second-summary" && p.text) {
  5917. return [
  5918. Vue.h(
  5919. "div",
  5920. { class: "ss-card-text-popover__summary" },
  5921. p.text
  5922. ),
  5923. ];
  5924. }
  5925. if (Array.isArray(p.lines)) {
  5926. return [
  5927. Vue.h(
  5928. "div",
  5929. { class: "ss-card-text-popover__kvlist" },
  5930. p.lines.map((t) =>
  5931. Vue.h(
  5932. "div",
  5933. { class: "ss-card-text-popover__kv" },
  5934. t
  5935. )
  5936. )
  5937. ),
  5938. ];
  5939. }
  5940. if (
  5941. (p.kind === "third" || p.kind === "third-full") &&
  5942. p.text
  5943. ) {
  5944. return [
  5945. Vue.h(
  5946. "div",
  5947. { class: "ss-card-text-popover__objno" },
  5948. p.text
  5949. ),
  5950. ];
  5951. }
  5952. return [];
  5953. })()
  5954. );
  5955. return [
  5956. Vue.h("div", { class: "ss-card-text" }, children),
  5957. popover,
  5958. ];
  5959. })()
  5960. ),
  5961. ]
  5962. ),
  5963. ]),
  5964. // 右下角卡片选择图标 by xu 20260105
  5965. this.__allowSelect()
  5966. ? Vue.h(SsIcon, {
  5967. class: this.item?._ssSelected
  5968. ? "card-icon icon-cardChk-on"
  5969. : "card-icon icon-cardChk",
  5970. onClick: this.toggleSelect,
  5971. })
  5972. : null,
  5973. // 选中后底部线条 by xu 20260105
  5974. this.__allowSelect() &&
  5975. this.item?._ssSelected &&
  5976. Vue.h("div", { class: "select-bottom-line" }),
  5977. ]
  5978. );
  5979. },
  5980. };
  5981. // 二级对象卡片:复用一级对象新卡片布局/省略浮层,但去掉勾选与 single 选中,仅支持点击查看 by xu 20260115
  5982. const SsCObjCardList = {
  5983. name: "SsCObjCardList",
  5984. props: {
  5985. ssObjName: { type: String, default: "" }, // 功能说明:业务对象名(用于默认缩略图 icon) by xu 20260115
  5986. dataType: { type: String, default: "" }, // 功能说明:页面类型(play=查看模式不显示右上角按钮) by xu 20250408
  5987. item: {
  5988. type: Object,
  5989. required: true,
  5990. },
  5991. },
  5992. emits: ["click", "change"],
  5993. setup(props, { emit }) {
  5994. const item = props.item;
  5995. const dataType = props.dataType; // 功能说明:页面类型 by xu 20250408
  5996. const cardType = Vue.computed(() => {
  5997. if (!item.thumb && !item.thumbType) return "";
  5998. return item.thumbType === "thumbnail" ? "card-thumbnail" : "card-photo";
  5999. });
  6000. const statusClass = Vue.computed(() => {
  6001. if (!item.status) return "";
  6002. const statusMap = {
  6003. available: "status-available",
  6004. unavailable: "status-unavailable",
  6005. disabled: "status-disabled",
  6006. };
  6007. return statusMap[item.status] || "";
  6008. });
  6009. const onItemClick = (e) => {
  6010. // 清除所有类型卡片的 active 状态(保持与一级对象一致) by xu 20260115
  6011. const allListCards = document.querySelectorAll(
  6012. ".knowledge-item-container"
  6013. );
  6014. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  6015. allListCards.forEach((card) => card.classList.remove("active"));
  6016. allFolderCards.forEach((card) => card.classList.remove("active"));
  6017. e.currentTarget.classList.add("active");
  6018. // 二级对象卡片:点击仅查看(调用 item.onclick) by xu 20260115
  6019. props.item.onclick?.();
  6020. emit("click", props.item);
  6021. };
  6022. const onItemChange = (e) => {
  6023. e.stopPropagation();
  6024. props.item.buttons?.[0]?.onclick?.();
  6025. };
  6026. return { item, dataType, cardType, statusClass, onItemClick, onItemChange };
  6027. },
  6028. data() {
  6029. return {
  6030. showButtons: false,
  6031. showTextPopover: false, // 功能:右侧文字区 hover 展示全量 by xu 20260115
  6032. textPopoverType: "", // second-summary / second-tags / third / third-full by xu 20260115
  6033. textPopoverBottom: 0, // 功能:popover 从当前省略行位置向上展开 by xu 20260115
  6034. hideTextPopoverTimer: null, // 功能:鼠标从省略行移到浮层的缓冲 by xu 20260115
  6035. textPopoverPayload: null, // { kind, text?, lines? } by xu 20260115
  6036. ellipsisVisible: {
  6037. secondSummary: false,
  6038. secondTags: false,
  6039. third: false,
  6040. thirdFull: false,
  6041. }, // 功能:只在真实出现 ... 时才显示命中区/允许 goheight by xu 20260115
  6042. };
  6043. },
  6044. methods: {
  6045. getBizThumbIconClass() {
  6046. // 功能:无缩略图时,用业务对象 icon 做默认图(ss-icon + icon-obj-xx) by xu 20260115
  6047. const name = String(
  6048. this.ssObjName ||
  6049. this.item?.ssObjName ||
  6050. this.$root?.ssObjName ||
  6051. window?.ss?.dom?.ssObjName ||
  6052. ""
  6053. ).trim();
  6054. if (!name) return "";
  6055. return "icon-obj-" + name;
  6056. },
  6057. buildRightTextLines() {
  6058. // 功能:沿用一级对象卡片右侧文字区规则 by xu 20260115
  6059. const item = this.item || {};
  6060. const summary = String(item?.desc ?? "").trim();
  6061. const objNum = String(item?.objNum ?? "").trim();
  6062. const categoryArr = Array.isArray(item?.category) ? item.category : [];
  6063. const tagsArr = Array.isArray(item?.tags) ? item.tags : [];
  6064. const hasTags = tagsArr.length > 0;
  6065. const hasCategory = categoryArr.length > 0;
  6066. const secondKind = summary ? "summary" : hasTags ? "tags" : "";
  6067. const hasSecond = !!secondKind;
  6068. const thirdKind = objNum ? "objNum" : hasCategory ? "category" : "";
  6069. const hasThird = !!thirdKind;
  6070. const thirdFull = !hasSecond && hasThird;
  6071. const secondFull = hasSecond && !hasThird && secondKind === "tags";
  6072. const toValueText = (obj) => {
  6073. // 功能说明:类目/物品参数回显展示 key: value(否则只显示值看不懂) by xu 20260115
  6074. const [k, v] = Object.entries(obj || {})[0] || ["", ""];
  6075. const key = k !== undefined && k !== null ? String(k).trim() : "";
  6076. const val = v !== undefined && v !== null ? String(v).trim() : "";
  6077. if (key && val) return key + ":" + val;
  6078. if (val) return val;
  6079. if (key) return key;
  6080. return "";
  6081. };
  6082. const toLineList = (arr) =>
  6083. (arr || [])
  6084. .map(toValueText)
  6085. .map((s) => String(s ?? "").trim())
  6086. .filter(Boolean);
  6087. const secondTagsMaxLines = secondFull ? 4 : 3;
  6088. const secondTagsLinesFull = toLineList(tagsArr);
  6089. const secondTagsHead = secondTagsLinesFull.slice(
  6090. 0,
  6091. Math.max(0, secondTagsMaxLines - 1)
  6092. );
  6093. const secondTagsTail = secondTagsLinesFull.slice(
  6094. Math.max(0, secondTagsMaxLines - 1)
  6095. );
  6096. const secondTagsLast =
  6097. secondTagsTail.length <= 1
  6098. ? secondTagsTail[0] || ""
  6099. : secondTagsTail.join(" ");
  6100. const categoryLinesFull = toLineList(categoryArr);
  6101. const categoryLine = categoryLinesFull.join(" ");
  6102. const thirdText =
  6103. thirdKind === "objNum"
  6104. ? objNum
  6105. : thirdKind === "category"
  6106. ? categoryLine
  6107. : "";
  6108. return {
  6109. secondKind,
  6110. thirdKind,
  6111. hasSecond,
  6112. hasThird,
  6113. thirdFull,
  6114. secondFull,
  6115. summary,
  6116. secondTagsMaxLines,
  6117. secondTagsHead,
  6118. secondTagsLast,
  6119. secondTagsLinesFull,
  6120. objNum,
  6121. categoryLine,
  6122. categoryLinesFull,
  6123. thirdText,
  6124. };
  6125. },
  6126. measureTextOverflowByLines(text, maxLines, width) {
  6127. const w = Number(width) || 0;
  6128. if (!w || !text) return false;
  6129. const probe = document.createElement("div");
  6130. probe.style.position = "fixed";
  6131. probe.style.left = "-99999px";
  6132. probe.style.top = "0";
  6133. probe.style.width = w + "px";
  6134. probe.style.fontSize = "18px";
  6135. probe.style.lineHeight = "24px";
  6136. probe.style.whiteSpace = "normal";
  6137. probe.style.wordBreak = "break-word";
  6138. probe.style.visibility = "hidden";
  6139. probe.textContent = text;
  6140. document.body.appendChild(probe);
  6141. const h = probe.getBoundingClientRect().height || 0;
  6142. document.body.removeChild(probe);
  6143. return h > maxLines * 24 + 1;
  6144. },
  6145. measureSingleLineOverflow(text, width) {
  6146. const w = Number(width) || 0;
  6147. if (!w || !text) return false;
  6148. const probe = document.createElement("span");
  6149. probe.style.position = "fixed";
  6150. probe.style.left = "-99999px";
  6151. probe.style.top = "0";
  6152. probe.style.display = "inline-block";
  6153. probe.style.maxWidth = w + "px";
  6154. probe.style.fontSize = "18px";
  6155. probe.style.lineHeight = "24px";
  6156. probe.style.whiteSpace = "nowrap";
  6157. probe.style.visibility = "hidden";
  6158. probe.textContent = text;
  6159. document.body.appendChild(probe);
  6160. const overflow =
  6161. (probe.scrollWidth || 0) > (probe.clientWidth || w) + 1;
  6162. document.body.removeChild(probe);
  6163. return overflow;
  6164. },
  6165. refreshEllipsisVisible() {
  6166. // 功能:刷新「是否出现 ...」状态(用于控制命中区显示) by xu 20260115
  6167. try {
  6168. const right = this.$el?.querySelector?.(".right");
  6169. const rawWidth =
  6170. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  6171. const width = Math.max(0, Math.round(rawWidth));
  6172. const model = this.buildRightTextLines();
  6173. const next = {
  6174. secondSummary: false,
  6175. secondTags: false,
  6176. third: false,
  6177. thirdFull: false,
  6178. };
  6179. if (model.secondKind === "summary" && model.summary) {
  6180. next.secondSummary = this.measureTextOverflowByLines(
  6181. model.summary,
  6182. 3,
  6183. width
  6184. );
  6185. }
  6186. if (model.secondKind === "tags") {
  6187. next.secondTags = this.measureSingleLineOverflow(
  6188. model.secondTagsLast,
  6189. width
  6190. ); // 功能说明:tags 仅看最后一行是否溢出 by xu 20260115
  6191. }
  6192. if (model.hasThird && !model.thirdFull) {
  6193. next.third = this.measureSingleLineOverflow(model.thirdText, width);
  6194. }
  6195. if (model.hasThird && model.thirdFull) {
  6196. next.thirdFull = this.measureTextOverflowByLines(
  6197. model.thirdText,
  6198. 4,
  6199. width
  6200. );
  6201. }
  6202. const prev = this.ellipsisVisible || {};
  6203. const changed =
  6204. prev.secondSummary !== next.secondSummary ||
  6205. prev.secondTags !== next.secondTags ||
  6206. prev.third !== next.third ||
  6207. prev.thirdFull !== next.thirdFull;
  6208. if (changed) this.ellipsisVisible = next;
  6209. } catch (e) {
  6210. // ignore by xu 20260115
  6211. }
  6212. },
  6213. clearHideTextPopoverTimer() {
  6214. if (this.hideTextPopoverTimer) {
  6215. clearTimeout(this.hideTextPopoverTimer);
  6216. this.hideTextPopoverTimer = null;
  6217. }
  6218. },
  6219. hideTextPopoverLater() {
  6220. this.clearHideTextPopoverTimer();
  6221. this.hideTextPopoverTimer = setTimeout(() => {
  6222. this.showTextPopover = false;
  6223. this.textPopoverType = "";
  6224. this.textPopoverPayload = null;
  6225. }, 120);
  6226. },
  6227. showTextPopoverFor(el, kind) {
  6228. const model = this.buildRightTextLines();
  6229. const lineEl = el?.closest?.(".ss-card-text__line") || el;
  6230. const right = lineEl?.closest?.(".right") || el?.closest?.(".right");
  6231. const rawWidth =
  6232. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  6233. const width = Math.max(0, Math.round(rawWidth));
  6234. const overflowed =
  6235. kind === "second-summary"
  6236. ? this.measureTextOverflowByLines(model.summary, 3, width)
  6237. : kind === "second-tags"
  6238. ? this.measureSingleLineOverflow(model.secondTagsLast, width)
  6239. : kind === "third"
  6240. ? this.measureSingleLineOverflow(model.thirdText, width)
  6241. : this.measureTextOverflowByLines(model.thirdText, 4, width);
  6242. if (!overflowed) return;
  6243. let payload = null;
  6244. if (kind === "second-summary") {
  6245. if (model.summary) payload = { kind, text: model.summary };
  6246. } else if (kind === "second-tags") {
  6247. if (
  6248. Array.isArray(model.secondTagsLinesFull) &&
  6249. model.secondTagsLinesFull.length
  6250. ) {
  6251. payload = { kind, lines: model.secondTagsLinesFull };
  6252. }
  6253. } else if (kind === "third") {
  6254. if (
  6255. model.thirdKind === "category" &&
  6256. Array.isArray(model.categoryLinesFull) &&
  6257. model.categoryLinesFull.length
  6258. ) {
  6259. payload = { kind, lines: model.categoryLinesFull };
  6260. } else if (model.thirdText) {
  6261. payload = { kind, text: model.thirdText };
  6262. }
  6263. } else if (kind === "third-full") {
  6264. if (
  6265. model.thirdKind === "category" &&
  6266. Array.isArray(model.categoryLinesFull) &&
  6267. model.categoryLinesFull.length
  6268. ) {
  6269. payload = { kind, lines: model.categoryLinesFull };
  6270. } else if (model.thirdText) {
  6271. payload = { kind, text: model.thirdText };
  6272. }
  6273. }
  6274. if (!payload) return;
  6275. this.clearHideTextPopoverTimer();
  6276. const container = lineEl?.closest?.(".right");
  6277. const containerRect = container?.getBoundingClientRect?.();
  6278. const lineRect = lineEl?.getBoundingClientRect?.();
  6279. if (containerRect && lineRect) {
  6280. const bottom = Math.max(
  6281. 0,
  6282. Math.round(containerRect.bottom - lineRect.bottom)
  6283. );
  6284. this.textPopoverBottom = bottom;
  6285. } else {
  6286. this.textPopoverBottom = 0;
  6287. }
  6288. this.textPopoverPayload = payload;
  6289. this.textPopoverType = kind;
  6290. this.showTextPopover = true;
  6291. },
  6292. },
  6293. mounted() {
  6294. this.$nextTick?.(() => {
  6295. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  6296. });
  6297. this.__ssCObjCardResizeHandler = () => this.refreshEllipsisVisible?.(); // 功能说明:窗口变化时刷新 ... 显示 by xu 20260115
  6298. window.addEventListener?.("resize", this.__ssCObjCardResizeHandler);
  6299. },
  6300. updated() {
  6301. this.$nextTick?.(() => {
  6302. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  6303. });
  6304. },
  6305. beforeUnmount() {
  6306. this.clearHideTextPopoverTimer?.();
  6307. if (this.__ssCObjCardResizeHandler) {
  6308. window.removeEventListener?.("resize", this.__ssCObjCardResizeHandler);
  6309. this.__ssCObjCardResizeHandler = null;
  6310. }
  6311. },
  6312. render() {
  6313. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  6314. const SsIcon = Vue.resolveComponent("ss-icon");
  6315. const hasThumbArea = !!(this.item?.thumb || this.item?.thumbType);
  6316. const thumbSrc = (() => {
  6317. // 功能说明:兼容 thumb 为 raw path 或 {val}/{value},组件内统一转为 dlByHttp URL by xu 20260122
  6318. const t = this.item?.thumb;
  6319. if (!t) return "";
  6320. if (typeof t === "string") {
  6321. const s = t.trim();
  6322. if (!s) return "";
  6323. if (
  6324. /^https?:\/\//i.test(s) ||
  6325. s.startsWith("/service?") ||
  6326. s.startsWith("/")
  6327. )
  6328. return s;
  6329. return buildThumbUrl(s);
  6330. }
  6331. return buildThumbUrl(t);
  6332. })();
  6333. return Vue.h(
  6334. "div",
  6335. {
  6336. class: {
  6337. "knowledge-item-container": true,
  6338. active: this.item.active,
  6339. [this.cardType]: !!this.cardType,
  6340. [this.statusClass]: !!this.statusClass,
  6341. },
  6342. onClick: (e) => this.onItemClick?.(e), // 功能说明:二级对象卡片点击仅查看 by xu 20260115
  6343. },
  6344. [
  6345. this.item?.statusIcons?.length > 0 &&
  6346. Vue.h(
  6347. "div",
  6348. { class: "card-status-icons" },
  6349. this.item.statusIcons.map((icon) =>
  6350. Vue.h(SsIcon, {
  6351. class: "status-icon " + icon.class,
  6352. title: icon.title,
  6353. })
  6354. )
  6355. ),
  6356. this.item?.buttons?.length > 0 && this.dataType !== "play" &&
  6357. Vue.h(
  6358. "div",
  6359. {
  6360. class: "header",
  6361. style:
  6362. this.item?.statusIcons?.length > 0
  6363. ? {
  6364. right: String(this.item.statusIcons.length * 48) + "px",
  6365. borderTopRightRadius: "0",
  6366. }
  6367. : {},
  6368. onMouseenter: () => (this.showButtons = true),
  6369. onMouseleave: () => (this.showButtons = false),
  6370. onClick: (e) => this.onItemChange(e),
  6371. },
  6372. [
  6373. Vue.h("div", {
  6374. class: "cart-list-setting cart-list-icon",
  6375. title: this.item?.buttons?.[0]?.title,
  6376. }),
  6377. this.showButtons &&
  6378. this.item?.buttons?.length > 1 &&
  6379. Vue.h(
  6380. "div",
  6381. { class: "cart-list-button-popup" },
  6382. this.item.buttons.map((btn) =>
  6383. Vue.h(
  6384. "div",
  6385. {
  6386. onClick: (e) => {
  6387. e.stopPropagation();
  6388. btn.onclick?.();
  6389. },
  6390. },
  6391. [
  6392. btn.class &&
  6393. Vue.h(SsCartListIcon, { class: [btn.class] }),
  6394. Vue.h("span", null, btn.title),
  6395. ]
  6396. )
  6397. )
  6398. ),
  6399. ]
  6400. ),
  6401. Vue.h("div", { class: "body" }, [
  6402. Vue.h("div", { class: "box-header" }, [
  6403. Vue.h("div", String(this.item.title || "")),
  6404. ]),
  6405. Vue.h(
  6406. "div",
  6407. { class: !hasThumbArea ? "no-thumb box-body" : "box-body" },
  6408. [
  6409. hasThumbArea
  6410. ? thumbSrc
  6411. ? Vue.h("div", { class: "left" }, [
  6412. Vue.h("img", {
  6413. src: thumbSrc,
  6414. alt: "Thumbnail",
  6415. class: "imgUnHandle",
  6416. style: {
  6417. "object-fit": "cover",
  6418. width: "100%",
  6419. height: "100%",
  6420. },
  6421. }),
  6422. ])
  6423. : Vue.h(
  6424. "div",
  6425. { class: "left ss-objlist-thumbPlaceholder" },
  6426. [
  6427. Vue.h(SsIcon, {
  6428. class:
  6429. this.getBizThumbIconClass() +
  6430. " ss-objlist-thumbIcon",
  6431. }),
  6432. ]
  6433. )
  6434. : null,
  6435. Vue.h(
  6436. "div",
  6437. { class: "right" },
  6438. (() => {
  6439. const model = this.buildRightTextLines();
  6440. const hasAny = !!(model?.hasSecond || model?.hasThird);
  6441. if (!hasAny) return [];
  6442. const children = [];
  6443. if (model.hasSecond && model.secondKind === "summary") {
  6444. children.push(
  6445. Vue.h(
  6446. "div",
  6447. {
  6448. class:
  6449. "ss-card-text__line ss-card-text__secondBlock",
  6450. },
  6451. [
  6452. Vue.h(
  6453. "div",
  6454. {
  6455. class: "ss-card-text__secondSummary",
  6456. title: model.summary,
  6457. },
  6458. model.summary
  6459. ),
  6460. Vue.h("span", {
  6461. class: [
  6462. "ss-card-text__ellipsisHit",
  6463. "ss-card-text__ellipsisHit--second",
  6464. this.ellipsisVisible?.secondSummary
  6465. ? "is-on"
  6466. : "",
  6467. ],
  6468. title: "查看完整信息",
  6469. onMouseenter: (e) =>
  6470. this.showTextPopoverFor(
  6471. e?.currentTarget,
  6472. "second-summary"
  6473. ),
  6474. onClick: (e) => {
  6475. e?.stopPropagation?.();
  6476. this.showTextPopoverFor(
  6477. e?.currentTarget,
  6478. "second-summary"
  6479. );
  6480. },
  6481. onMouseleave: () => this.hideTextPopoverLater(),
  6482. }),
  6483. ]
  6484. )
  6485. );
  6486. }
  6487. if (model.hasSecond && model.secondKind === "tags") {
  6488. children.push(
  6489. Vue.h(
  6490. "div",
  6491. {
  6492. class: [
  6493. "ss-card-text__line",
  6494. model.secondFull
  6495. ? "ss-card-text__secondFullBlock"
  6496. : "ss-card-text__secondBlock",
  6497. ],
  6498. },
  6499. [
  6500. Vue.h(
  6501. "div",
  6502. { class: "ss-card-text__secondTags" },
  6503. [
  6504. ...model.secondTagsHead.map((t) =>
  6505. Vue.h(
  6506. "div",
  6507. {
  6508. class: "ss-card-text__tagLine",
  6509. title: t,
  6510. },
  6511. t
  6512. )
  6513. ),
  6514. Vue.h(
  6515. "div",
  6516. {
  6517. class:
  6518. "ss-card-text__tagLine is-last ss-card-text__tagLineLast",
  6519. title: model.secondTagsLast,
  6520. },
  6521. model.secondTagsLast
  6522. ),
  6523. ]
  6524. ),
  6525. Vue.h("span", {
  6526. class: [
  6527. "ss-card-text__ellipsisHit",
  6528. "ss-card-text__ellipsisHit--second",
  6529. this.ellipsisVisible?.secondTags ? "is-on" : "",
  6530. ],
  6531. title: "查看完整信息",
  6532. onMouseenter: (e) =>
  6533. this.showTextPopoverFor(
  6534. e?.currentTarget,
  6535. "second-tags"
  6536. ),
  6537. onClick: (e) => {
  6538. e?.stopPropagation?.();
  6539. this.showTextPopoverFor(
  6540. e?.currentTarget,
  6541. "second-tags"
  6542. );
  6543. },
  6544. onMouseleave: () => this.hideTextPopoverLater(),
  6545. }),
  6546. ]
  6547. )
  6548. );
  6549. }
  6550. if (model.hasThird) {
  6551. if (model.thirdFull) {
  6552. children.push(
  6553. Vue.h(
  6554. "div",
  6555. {
  6556. class:
  6557. "ss-card-text__line ss-card-text__thirdFullBlock",
  6558. },
  6559. [
  6560. Vue.h(
  6561. "div",
  6562. {
  6563. class: "ss-card-text__thirdFull",
  6564. title: model.thirdText,
  6565. },
  6566. model.thirdText
  6567. ),
  6568. Vue.h("span", {
  6569. class: [
  6570. "ss-card-text__ellipsisHit",
  6571. "ss-card-text__ellipsisHit--third",
  6572. this.ellipsisVisible?.thirdFull
  6573. ? "is-on"
  6574. : "",
  6575. ],
  6576. title: "查看完整信息",
  6577. onMouseenter: (e) =>
  6578. this.showTextPopoverFor(
  6579. e?.currentTarget,
  6580. "third-full"
  6581. ),
  6582. onClick: (e) => {
  6583. e?.stopPropagation?.();
  6584. this.showTextPopoverFor(
  6585. e?.currentTarget,
  6586. "third-full"
  6587. );
  6588. },
  6589. onMouseleave: () => this.hideTextPopoverLater(),
  6590. }),
  6591. ]
  6592. )
  6593. );
  6594. } else {
  6595. children.push(
  6596. Vue.h(
  6597. "div",
  6598. {
  6599. class:
  6600. "ss-card-text__line ss-card-text__thirdLineWrap",
  6601. },
  6602. [
  6603. Vue.h(
  6604. "div",
  6605. {
  6606. class: "ss-card-text__thirdLine",
  6607. title: model.thirdText,
  6608. },
  6609. model.thirdText
  6610. ),
  6611. Vue.h("span", {
  6612. class: [
  6613. "ss-card-text__ellipsisHit",
  6614. "ss-card-text__ellipsisHit--third",
  6615. this.ellipsisVisible?.third ? "is-on" : "",
  6616. ],
  6617. title: "查看完整信息",
  6618. onMouseenter: (e) =>
  6619. this.showTextPopoverFor(
  6620. e?.currentTarget,
  6621. "third"
  6622. ),
  6623. onClick: (e) => {
  6624. e?.stopPropagation?.();
  6625. this.showTextPopoverFor(
  6626. e?.currentTarget,
  6627. "third"
  6628. );
  6629. },
  6630. onMouseleave: () => this.hideTextPopoverLater(),
  6631. }),
  6632. ]
  6633. )
  6634. );
  6635. }
  6636. }
  6637. const popover =
  6638. this.showTextPopover &&
  6639. Vue.h(
  6640. "div",
  6641. {
  6642. class: "ss-card-text-popover",
  6643. style: { bottom: this.textPopoverBottom + "px" },
  6644. onMouseenter: () => {
  6645. this.clearHideTextPopoverTimer();
  6646. this.showTextPopover = true;
  6647. },
  6648. onMouseleave: () => this.hideTextPopoverLater(),
  6649. },
  6650. (() => {
  6651. const p = this.textPopoverPayload || {};
  6652. if (p.kind === "second-summary" && p.text) {
  6653. return [
  6654. Vue.h(
  6655. "div",
  6656. { class: "ss-card-text-popover__summary" },
  6657. p.text
  6658. ),
  6659. ];
  6660. }
  6661. if (Array.isArray(p.lines)) {
  6662. return [
  6663. Vue.h(
  6664. "div",
  6665. { class: "ss-card-text-popover__kvlist" },
  6666. p.lines.map((t) =>
  6667. Vue.h(
  6668. "div",
  6669. { class: "ss-card-text-popover__kv" },
  6670. t
  6671. )
  6672. )
  6673. ),
  6674. ];
  6675. }
  6676. if (
  6677. (p.kind === "third" || p.kind === "third-full") &&
  6678. p.text
  6679. ) {
  6680. return [
  6681. Vue.h(
  6682. "div",
  6683. { class: "ss-card-text-popover__objno" },
  6684. p.text
  6685. ),
  6686. ];
  6687. }
  6688. return [];
  6689. })()
  6690. );
  6691. return [
  6692. Vue.h("div", { class: "ss-card-text" }, children),
  6693. popover,
  6694. ];
  6695. })()
  6696. ),
  6697. ]
  6698. ),
  6699. ]),
  6700. ]
  6701. );
  6702. },
  6703. };
  6704. // ss-sidebar 右侧边栏(容器 + 子组件),用于 objList 右侧区域 by xu 20260106
  6705. // 组件文档补全(JSDoc) by xu 20260108
  6706. /**
  6707. * SsSidebarButtons(右侧边栏顶部按钮栏)
  6708. *
  6709. * 用途:
  6710. * - 渲染 objList 右侧顶部快捷操作(预定/入住/退房/清洁...)
  6711. * - 内部复用 `ss-search-button`(项目现有按钮样式/交互)
  6712. *
  6713. * 调用示例:
  6714. * ```html
  6715. * <ss-sidebar-buttons :items="sidebarButtons" />
  6716. * ```
  6717. *
  6718. * Props:
  6719. * - `items`: 按钮配置数组
  6720. * - `{ id, text, icon?, onClick? }`
  6721. *
  6722. * Emits:
  6723. * - `click`:点击按钮时触发,参数为按钮对象
  6724. */
  6725. const SsSidebarButtons = {
  6726. name: "SsSidebarButtons",
  6727. props: {
  6728. items: { type: Array, default: () => [] },
  6729. },
  6730. emits: ["click"],
  6731. render() {
  6732. const SsSearchButton = Vue.resolveComponent("ss-search-button");
  6733. const items = this.items || [];
  6734. if (!items.length) return null;
  6735. return Vue.h(
  6736. "div",
  6737. { class: "ss-sidebar-actions" },
  6738. items.map((btn) =>
  6739. // 顶部操作按钮复用 ss-search-button(先 mock 固定按钮) by xu 20260106
  6740. Vue.h(SsSearchButton, {
  6741. text: btn?.text ?? "",
  6742. iconClass: btn?.iconClass ?? "",
  6743. opt: btn?.opt ?? [],
  6744. checkId: btn?.checkId ?? "0",
  6745. width: btn?.width,
  6746. id: btn?.id,
  6747. onClick: (e) => {
  6748. e?.stopPropagation?.();
  6749. btn?.onClick?.(btn);
  6750. this.$emit("click", btn);
  6751. },
  6752. })
  6753. )
  6754. );
  6755. },
  6756. };
  6757. // 组件文档补全(JSDoc) by xu 20260108
  6758. /**
  6759. * SsSidebarChart(ECharts 容器渲染)
  6760. *
  6761. * 用途:
  6762. * - 仅负责 echarts init / setOption / resize / dispose
  6763. * - 被 `ss-sidebar-chart-hover` 与图表面板复用
  6764. *
  6765. * 调用示例:
  6766. * ```html
  6767. * <ss-sidebar-chart :options="option" height="220px" />
  6768. * ```
  6769. *
  6770. * Props:
  6771. * - `options`:ECharts option(Object)
  6772. * - `height`:容器高度(String)
  6773. */
  6774. const SsSidebarChart = {
  6775. name: "SsSidebarChart",
  6776. props: {
  6777. options: { type: Object, default: () => ({}) },
  6778. height: { type: String, default: "200px" },
  6779. },
  6780. setup(props) {
  6781. const elRef = Vue.ref(null);
  6782. let chart = null;
  6783. const renderChart = () => {
  6784. if (!elRef.value || !window.echarts) return;
  6785. if (!chart) {
  6786. chart = window.echarts.init(elRef.value);
  6787. }
  6788. chart.setOption(props.options || {}, true);
  6789. };
  6790. const resizeChart = () => {
  6791. chart?.resize?.();
  6792. };
  6793. Vue.onMounted(() => {
  6794. renderChart();
  6795. window.addEventListener("resize", resizeChart);
  6796. });
  6797. Vue.onBeforeUnmount(() => {
  6798. window.removeEventListener("resize", resizeChart);
  6799. chart?.dispose?.();
  6800. chart = null;
  6801. });
  6802. Vue.watch(
  6803. () => props.options,
  6804. () => {
  6805. renderChart();
  6806. },
  6807. { deep: true }
  6808. );
  6809. return { elRef };
  6810. },
  6811. render() {
  6812. return Vue.h("div", {
  6813. ref: "elRef",
  6814. style: {
  6815. width: "100%",
  6816. height: this.height,
  6817. // 图表容器不加 padding/border,由外层布局控制 by xu 20260106
  6818. background: "transparent",
  6819. border: "none",
  6820. "border-radius": "0",
  6821. },
  6822. });
  6823. },
  6824. };
  6825. // ss-sidebar-chart-hover:hover 弹出左侧大图(支持图钉/全屏) by xu 20260106
  6826. // 组件文档补全(JSDoc) by xu 20260108
  6827. /**
  6828. * SsSidebarChartHover(小图 + hover 左侧大图预览 + 图钉固定 + 全屏)
  6829. *
  6830. * 用途:
  6831. * - 右侧统计图小卡片:hover 时在左侧弹出大图预览
  6832. * - 预览头部:左侧图标+标题;右侧固定/全屏按钮(icon-base)
  6833. * - 全屏:方案A(浏览器 Fullscreen API)
  6834. *
  6835. * 调用示例(由 ss-sidebar chart panel 内部调用):
  6836. * ```html
  6837. * <ss-sidebar-chart-hover
  6838. * title="校舍建筑面积和总体分布"
  6839. * icon-class="menu-icon icon-obj-jzw"
  6840. * :options="option"
  6841. * height="220px"
  6842. * />
  6843. * ```
  6844. *
  6845. * Props:
  6846. * - `title/iconClass/icon`:用于预览/全屏 header 显示(与面板 header 一致)
  6847. * - `options`:ECharts option
  6848. * - `height`:小图高度
  6849. * - `previewWidth/previewHeight`:预览建议尺寸(会按视口自适应)
  6850. */
  6851. const SsSidebarChartHover = {
  6852. name: "SsSidebarChartHover",
  6853. props: {
  6854. // hover 大图标题/图标(与小图面板 header 一致) by xu 20260108
  6855. title: { type: String, default: "" },
  6856. iconClass: { type: String, default: "" },
  6857. icon: { type: String, default: "" },
  6858. options: { type: Object, default: () => ({}) },
  6859. height: { type: String, default: "220px" },
  6860. // hover 弹窗建议尺寸:默认 1000x650(比例由逻辑统一管控),实际渲染会按比例自适应视口 by xu 20260115
  6861. previewWidth: { type: Number, default: 1000 },
  6862. previewHeight: { type: Number, default: 650 },
  6863. },
  6864. setup(props) {
  6865. const triggerRef = Vue.ref(null);
  6866. const fullscreenRef = Vue.ref(null);
  6867. const open = Vue.ref(false);
  6868. const pinned = Vue.ref(false);
  6869. const fullscreen = Vue.ref(false);
  6870. const hoveringTrigger = Vue.ref(false);
  6871. const hoveringPreview = Vue.ref(false);
  6872. const previewStyle = Vue.ref({});
  6873. let closeTimer = null;
  6874. const updatePreviewPosition = () => {
  6875. const el = triggerRef.value;
  6876. if (!el) return;
  6877. const rect = el.getBoundingClientRect();
  6878. // 功能说明:优先使用 visualViewport(避免浏览器 UI/缩放导致可视区与 innerHeight 偏差,出现预览被遮挡约 70px) by xu 20260116
  6879. const docEl = document.documentElement;
  6880. const vv = window.visualViewport;
  6881. let viewportLeft = Number(vv?.offsetLeft ?? 0) || 0;
  6882. let viewportTop = Number(vv?.offsetTop ?? 0) || 0;
  6883. let vw =
  6884. Number(vv?.width ?? 0) ||
  6885. Number(docEl?.clientWidth || 0) ||
  6886. window.innerWidth;
  6887. let vh =
  6888. Number(vv?.height ?? 0) ||
  6889. Number(docEl?.clientHeight || 0) ||
  6890. window.innerHeight;
  6891. // 功能说明:若页面在 iframe 内,父页面可能裁切 iframe 可见区域(overflow/弹窗容器),需要用“iframe可见区域”做二次约束 by xu 20260116
  6892. try {
  6893. const inIframe = window.top && window.top !== window;
  6894. const frameEl = window.frameElement;
  6895. if (inIframe && frameEl && window.top?.document) {
  6896. const topVv = window.top.visualViewport;
  6897. const topDocEl = window.top.document.documentElement;
  6898. const topVw =
  6899. Number(topVv?.width ?? 0) ||
  6900. Number(topDocEl?.clientWidth || 0) ||
  6901. window.top.innerWidth;
  6902. const topVh =
  6903. Number(topVv?.height ?? 0) ||
  6904. Number(topDocEl?.clientHeight || 0) ||
  6905. window.top.innerHeight;
  6906. const fr = frameEl.getBoundingClientRect?.();
  6907. if (fr && fr.width > 0 && fr.height > 0) {
  6908. const visibleW = Math.max(
  6909. 0,
  6910. Math.min(fr.right, topVw) - Math.max(fr.left, 0)
  6911. );
  6912. const visibleH = Math.max(
  6913. 0,
  6914. Math.min(fr.bottom, topVh) - Math.max(fr.top, 0)
  6915. );
  6916. if (visibleW > 0) {
  6917. vw = Math.min(vw, visibleW);
  6918. viewportLeft = Math.max(0, -fr.left); // iframe内坐标系偏移(左侧被裁切时) by xu 20260116
  6919. }
  6920. if (visibleH > 0) {
  6921. vh = Math.min(vh, visibleH);
  6922. viewportTop = Math.max(0, -fr.top); // iframe内坐标系偏移(顶部被裁切时) by xu 20260116
  6923. }
  6924. }
  6925. }
  6926. } catch (_) {}
  6927. // 预览窗尺寸:优先保证“完整可见”,其次再尽量对齐右侧 header 顶部 by xu 20260116
  6928. const viewportPaddingX = 40;
  6929. const viewportPaddingTop = 20;
  6930. const viewportPaddingBottom = 10;
  6931. // 功能说明:hover 预览框不要覆盖右侧栏,优先放在 ss-sidebar 左侧;必要时动态缩小宽度 by xu 20260115
  6932. const sidebarEl = el.closest ? el.closest(".ss-sidebar") : null;
  6933. const sidebarRect = sidebarEl?.getBoundingClientRect?.();
  6934. const maxWidthByViewport = Math.max(240, vw - viewportPaddingX);
  6935. const maxWidthByLeftSpace = sidebarRect
  6936. ? Math.max(
  6937. 240,
  6938. sidebarRect.left - viewportPaddingX - 14 /* gapFromSidebar */
  6939. )
  6940. : maxWidthByViewport;
  6941. // 功能说明:预览框尺寸按比例(默认 5:3)缩放,并提供最大/最小值约束 by xu 20260115
  6942. const ratio = 3 / 5;
  6943. const minWidth = 320;
  6944. const minHeight = 240;
  6945. const maxHeightByViewport = Math.max(
  6946. minHeight,
  6947. vh - viewportPaddingTop - viewportPaddingBottom
  6948. );
  6949. const maxWidthByProp = Number(props.previewWidth) || 1000;
  6950. const maxHeightByProp = Number(props.previewHeight) || 650;
  6951. // 优先按高度撑满可视区(保证预览完整可见),再根据左侧可用宽度回退 by xu 20260116
  6952. const maxHeight = Math.min(maxHeightByProp, maxHeightByViewport);
  6953. let height = Math.max(minHeight, maxHeight);
  6954. let width = Math.round(height / ratio);
  6955. width = Math.min(
  6956. width,
  6957. maxWidthByProp,
  6958. maxWidthByViewport,
  6959. maxWidthByLeftSpace
  6960. );
  6961. width = Math.max(minWidth, width);
  6962. height = Math.round(width * ratio);
  6963. if (height > maxHeight) {
  6964. height = maxHeight;
  6965. width = Math.round(height / ratio);
  6966. }
  6967. // 默认贴着小图左侧弹出,右边缘与小图左边缘轻微重叠,避免 1px 缝隙导致 hover 闪断 by xu 20260108
  6968. const overlap = 2;
  6969. const gapFromSidebar = 14; // 功能说明:弹窗与右侧边栏留出距离(更不贴近) by xu 20260108
  6970. // 优先:贴在 sidebar 左侧(不压住右侧栏内容) by xu 20260115
  6971. let left = sidebarRect
  6972. ? sidebarRect.left - gapFromSidebar - width + overlap
  6973. : rect.left - width - gapFromSidebar + overlap;
  6974. // 如果左侧空间不足,则贴右侧(兜底,同样重叠) by xu 20260108
  6975. if (left < 0) left = rect.right + gapFromSidebar - overlap;
  6976. left = Math.max(
  6977. viewportLeft,
  6978. Math.min(left, viewportLeft + vw - width)
  6979. );
  6980. // top:优先保证完整可见,然后才贴近 header 顶部 by xu 20260116
  6981. let headerEl = el;
  6982. while (headerEl && !headerEl.classList?.contains("ss-sidebar-panel")) {
  6983. headerEl = headerEl.parentElement;
  6984. }
  6985. let headerRect = headerEl
  6986. ?.querySelector(".ss-sidebar-panel__header")
  6987. ?.getBoundingClientRect();
  6988. let top = headerRect?.top ?? rect.top;
  6989. top = Math.max(
  6990. viewportTop + viewportPaddingTop,
  6991. Math.min(top, viewportTop + vh - height - viewportPaddingBottom)
  6992. );
  6993. previewStyle.value = {
  6994. position: "fixed",
  6995. left: `${Math.round(left)}px`,
  6996. top: `${Math.round(top)}px`,
  6997. width: `${width}px`,
  6998. height: `${height}px`,
  6999. zIndex: 2147483647, // 功能说明:提高层级到接近浏览器上限,避免仍被页面固定栏/弹窗遮挡 by xu 20260116
  7000. };
  7001. };
  7002. const clearCloseTimer = () => {
  7003. if (closeTimer) {
  7004. clearTimeout(closeTimer);
  7005. closeTimer = null;
  7006. }
  7007. };
  7008. const scheduleClose = () => {
  7009. clearCloseTimer();
  7010. if (pinned.value || fullscreen.value) return;
  7011. if (hoveringTrigger.value || hoveringPreview.value) return; // 功能:鼠标在小图/大图之间移动不关闭 by xu 20260108
  7012. closeTimer = setTimeout(() => {
  7013. open.value = false;
  7014. }, 100);
  7015. };
  7016. const openPreview = () => {
  7017. clearCloseTimer();
  7018. updatePreviewPosition();
  7019. open.value = true;
  7020. };
  7021. const togglePin = () => {
  7022. pinned.value = !pinned.value;
  7023. if (pinned.value) {
  7024. open.value = true;
  7025. updatePreviewPosition();
  7026. }
  7027. };
  7028. const toggleFullscreen = () => {
  7029. // 全屏:采用浏览器 Fullscreen API(方案A),不使用遮罩弹窗 by xu 20260108
  7030. if (!fullscreen.value) {
  7031. open.value = false; // 避免同时渲染预览与全屏 by xu 20260108
  7032. fullscreen.value = true;
  7033. Vue.nextTick(() => {
  7034. const el = fullscreenRef.value;
  7035. if (el?.requestFullscreen) {
  7036. el.requestFullscreen().catch(() => {
  7037. // requestFullscreen 失败则回退为非全屏状态 by xu 20260108
  7038. fullscreen.value = false;
  7039. });
  7040. } else {
  7041. fullscreen.value = false;
  7042. }
  7043. });
  7044. } else {
  7045. if (document?.exitFullscreen) {
  7046. document.exitFullscreen().catch(() => {});
  7047. }
  7048. }
  7049. };
  7050. const handleFullscreenChange = () => {
  7051. const isFs = !!document.fullscreenElement;
  7052. fullscreen.value = isFs; // 功能说明:同步 ESC/系统退出全屏状态 by xu 20260108
  7053. if (isFs) {
  7054. open.value = false;
  7055. clearCloseTimer();
  7056. return;
  7057. }
  7058. // 退出全屏后:若固定或仍 hover,则恢复预览,否则关闭 by xu 20260108
  7059. if (pinned.value || hoveringTrigger.value || hoveringPreview.value) {
  7060. open.value = true;
  7061. updatePreviewPosition();
  7062. } else {
  7063. open.value = false;
  7064. }
  7065. };
  7066. Vue.onMounted(() => {
  7067. window.addEventListener("resize", updatePreviewPosition);
  7068. window.addEventListener("scroll", updatePreviewPosition, true);
  7069. document.addEventListener("fullscreenchange", handleFullscreenChange); // 功能说明:监听全屏状态变化 by xu 20260108
  7070. });
  7071. Vue.onBeforeUnmount(() => {
  7072. clearCloseTimer();
  7073. window.removeEventListener("resize", updatePreviewPosition);
  7074. window.removeEventListener("scroll", updatePreviewPosition, true);
  7075. document.removeEventListener(
  7076. "fullscreenchange",
  7077. handleFullscreenChange
  7078. );
  7079. });
  7080. return {
  7081. triggerRef,
  7082. fullscreenRef,
  7083. open,
  7084. pinned,
  7085. fullscreen,
  7086. hoveringTrigger,
  7087. hoveringPreview,
  7088. previewStyle,
  7089. openPreview,
  7090. scheduleClose,
  7091. clearCloseTimer,
  7092. togglePin,
  7093. toggleFullscreen,
  7094. };
  7095. },
  7096. render() {
  7097. const SsIcon = Vue.resolveComponent("ss-icon");
  7098. const Chart = Vue.resolveComponent("ss-sidebar-chart");
  7099. const hasHeader = !!(this.title || this.iconClass || this.icon); // 功能:hover 大图显示左侧图标+标题 by xu 20260108
  7100. const previewContent = Vue.h(
  7101. "div",
  7102. {
  7103. class: { "ss-sidebar-chart-preview": true, "is-pinned": this.pinned },
  7104. style: this.previewStyle,
  7105. onMouseenter: () => {
  7106. this.hoveringPreview = true;
  7107. this.clearCloseTimer();
  7108. },
  7109. onMouseleave: () => {
  7110. this.hoveringPreview = false;
  7111. this.scheduleClose();
  7112. },
  7113. },
  7114. [
  7115. hasHeader
  7116. ? Vue.h(
  7117. "div",
  7118. {
  7119. class:
  7120. "ss-sidebar-panel__header ss-sidebar-chart-preview__header",
  7121. },
  7122. [
  7123. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7124. this.iconClass
  7125. ? Vue.h(SsIcon, {
  7126. class: this.iconClass + " ss-sidebar-panel__icon",
  7127. })
  7128. : this.icon
  7129. ? Vue.h(SsIcon, {
  7130. name: this.icon,
  7131. size: "16px",
  7132. class: "ss-sidebar-panel__icon",
  7133. })
  7134. : null,
  7135. Vue.h("span", null, this.title || "统计图"),
  7136. ]),
  7137. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7138. Vue.h(
  7139. "button",
  7140. {
  7141. type: "button",
  7142. class: {
  7143. "ss-sidebar-chart-tool": true,
  7144. "is-active": this.pinned,
  7145. },
  7146. title: this.pinned ? "取消固定" : "固定",
  7147. onClick: (e) => {
  7148. e.stopPropagation();
  7149. this.togglePin();
  7150. },
  7151. },
  7152. // 功能说明:右侧栏 hover 工具图标使用 ss-sidebar-base-icon(不复用左侧 menu-base-icon) by xu 20260123
  7153. [
  7154. Vue.h(SsIcon, {
  7155. class: this.pinned
  7156. ? "ss-sidebar-base-icon icon-fix-bold"
  7157. : "ss-sidebar-base-icon icon-fix",
  7158. }),
  7159. ]
  7160. ),
  7161. Vue.h(
  7162. "button",
  7163. {
  7164. type: "button",
  7165. class: "ss-sidebar-chart-tool",
  7166. title: "全屏",
  7167. onClick: (e) => {
  7168. e.stopPropagation();
  7169. this.toggleFullscreen();
  7170. },
  7171. },
  7172. [
  7173. Vue.h(SsIcon, {
  7174. class: this.fullscreen
  7175. ? "ss-sidebar-base-icon icon-fs-exit"
  7176. : "ss-sidebar-base-icon icon-fs",
  7177. }),
  7178. ]
  7179. ),
  7180. ]),
  7181. ]
  7182. )
  7183. : Vue.h(
  7184. "div",
  7185. {
  7186. class:
  7187. "ss-sidebar-chart-preview__header ss-sidebar-chart-preview__header--simple",
  7188. },
  7189. [
  7190. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7191. Vue.h(
  7192. "button",
  7193. {
  7194. type: "button",
  7195. class: {
  7196. "ss-sidebar-chart-tool": true,
  7197. "is-active": this.pinned,
  7198. },
  7199. title: this.pinned ? "取消固定" : "固定",
  7200. onClick: (e) => {
  7201. e.stopPropagation();
  7202. this.togglePin();
  7203. },
  7204. },
  7205. [
  7206. Vue.h(SsIcon, {
  7207. class: this.pinned
  7208. ? "ss-sidebar-base-icon icon-fix-bold"
  7209. : "ss-sidebar-base-icon icon-fix",
  7210. }),
  7211. ]
  7212. ),
  7213. Vue.h(
  7214. "button",
  7215. {
  7216. type: "button",
  7217. class: "ss-sidebar-chart-tool",
  7218. title: "全屏",
  7219. onClick: (e) => {
  7220. e.stopPropagation();
  7221. this.toggleFullscreen();
  7222. },
  7223. },
  7224. [
  7225. Vue.h(SsIcon, {
  7226. class: this.fullscreen
  7227. ? "ss-sidebar-base-icon icon-chk-on"
  7228. : "ss-sidebar-base-icon icon-chk",
  7229. }),
  7230. ]
  7231. ),
  7232. ]),
  7233. ]
  7234. ),
  7235. Vue.h("div", { class: "ss-sidebar-chart-preview__body" }, [
  7236. Vue.h(Chart, { options: this.options, height: "100%" }),
  7237. ]),
  7238. ]
  7239. );
  7240. const fullscreenContent =
  7241. this.fullscreen &&
  7242. Vue.h(
  7243. "div",
  7244. {
  7245. ref: "fullscreenRef",
  7246. class: "ss-sidebar-chart-fullscreen",
  7247. },
  7248. [
  7249. Vue.h(
  7250. "div",
  7251. {
  7252. class:
  7253. "ss-sidebar-panel__header ss-sidebar-chart-fullscreen__header",
  7254. },
  7255. [
  7256. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7257. this.iconClass
  7258. ? Vue.h(SsIcon, {
  7259. class: this.iconClass + " ss-sidebar-panel__icon",
  7260. })
  7261. : this.icon
  7262. ? Vue.h(SsIcon, {
  7263. name: this.icon,
  7264. size: "16px",
  7265. class: "ss-sidebar-panel__icon",
  7266. })
  7267. : null,
  7268. Vue.h("span", null, this.title || "统计图"),
  7269. ]),
  7270. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7271. Vue.h(
  7272. "button",
  7273. {
  7274. type: "button",
  7275. class: {
  7276. "ss-sidebar-chart-tool": true,
  7277. "is-active": this.pinned,
  7278. },
  7279. title: this.pinned ? "取消固定" : "固定",
  7280. onClick: (e) => {
  7281. e.stopPropagation();
  7282. this.togglePin();
  7283. },
  7284. },
  7285. [
  7286. Vue.h(SsIcon, {
  7287. class: this.pinned
  7288. ? "ss-sidebar-base-icon icon-fix-bold"
  7289. : "ss-sidebar-base-icon icon-fix",
  7290. }),
  7291. ]
  7292. ),
  7293. Vue.h(
  7294. "button",
  7295. {
  7296. type: "button",
  7297. class: "ss-sidebar-chart-tool",
  7298. title: "退出全屏",
  7299. onClick: (e) => {
  7300. e.stopPropagation();
  7301. this.toggleFullscreen();
  7302. },
  7303. },
  7304. [
  7305. Vue.h(SsIcon, {
  7306. class: "ss-sidebar-base-icon icon-fs-exit",
  7307. }),
  7308. ]
  7309. ),
  7310. ]),
  7311. ]
  7312. ),
  7313. Vue.h("div", { class: "ss-sidebar-chart-fullscreen__body" }, [
  7314. Vue.h(Chart, { options: this.options, height: "100%" }),
  7315. ]),
  7316. ]
  7317. );
  7318. return Vue.h("div", { class: "ss-sidebar-chart-hover" }, [
  7319. Vue.h(
  7320. "div",
  7321. {
  7322. ref: "triggerRef",
  7323. class: "ss-sidebar-chart-hover__trigger",
  7324. onMouseenter: () => {
  7325. this.hoveringTrigger = true;
  7326. this.openPreview();
  7327. },
  7328. onMouseleave: () => {
  7329. this.hoveringTrigger = false;
  7330. this.scheduleClose();
  7331. },
  7332. },
  7333. [Vue.h(Chart, { options: this.options, height: this.height })]
  7334. ),
  7335. (this.open || this.fullscreen) &&
  7336. Vue.h(Vue.Teleport, { to: "body" }, [
  7337. this.open ? previewContent : null,
  7338. fullscreenContent || null,
  7339. ]),
  7340. ]);
  7341. },
  7342. };
  7343. // 组件文档补全(JSDoc) by xu 20260108
  7344. /**
  7345. * SsSidebarList(右侧业务面板:人员/已选/服务/预定...)
  7346. *
  7347. * 用途:
  7348. * - 统一渲染面板 header(图标/标题/数量/右侧按钮)
  7349. * - 统一渲染 list(固定行高、hover、右侧移除按钮等)
  7350. *
  7351. * 调用示例(由 ss-sidebar 通过 panels 配置驱动):
  7352. * ```js
  7353. * { type:'list', title:'已选', iconClass:'menu-icon icon-obj-xcd', mode:'selected', items:selectedItems, closable:true }
  7354. * ```
  7355. *
  7356. * Props(核心):
  7357. * - `title`:header 标题
  7358. * - `iconClass/icon`:header 图标(优先 iconClass)
  7359. * - `count`:数量回显(图表面板可不传)
  7360. * - `closable`:是否显示“清空”按钮(触发 emit clear)
  7361. * - `headerFilters`:header 条件数组(组件名 + props),用于联调接口搜索
  7362. * - `headerSearchButton`:是否显示搜索按钮(触发 emit search)
  7363. * - `items`:列表数据
  7364. * - `mode`:`selected` 时右侧按钮语义为“移除”
  7365. * - `itemLayout`:`simple` / `person`(人员号槽位)
  7366. * - `itemAction`:是否显示 item 右侧操作按钮(hover 才出现)
  7367. *
  7368. * Emits:
  7369. * - `remove(item)`:点击 item 右侧移除
  7370. * - `clear()`:点击 header 清空
  7371. * - `search({keyword, filters})`:点击 header 搜索
  7372. */
  7373. const SsSidebarList = {
  7374. name: "SsSidebarList",
  7375. props: {
  7376. title: { type: String, default: "" },
  7377. // header 图标:优先使用 iconClass(走 ss-icon v3.0 class 分支) by xu 20260106
  7378. iconClass: { type: String, default: "" },
  7379. icon: { type: String, default: "" }, // 兼容旧写法(ss-icon name)
  7380. count: { type: [Number, String], default: "" },
  7381. // 选中类分区:右侧关闭按钮=清空分区数据 by xu 20260106
  7382. closable: { type: Boolean, default: false },
  7383. searchable: { type: Boolean, default: false },
  7384. // 搜索框是否放在 header 内(人员块需要该布局) by xu 20260106
  7385. searchInHeader: { type: Boolean, default: false },
  7386. // header 搜索:下拉条件 + 搜索按钮(适合“人员”块) by xu 20260106
  7387. headerFilters: { type: Array, default: () => [] },
  7388. headerSearchButton: { type: Boolean, default: false },
  7389. searchPlaceholder: { type: String, default: "搜索" },
  7390. // 列表项布局:simple(仅标题) / person(标题+人员号槽位) by xu 20260106
  7391. itemLayout: { type: String, default: "simple" },
  7392. itemAction: { type: Boolean, default: true },
  7393. collapsible: { type: Boolean, default: true }, // 功能说明:是否允许双击 header 折叠/展开 by xu 20260116
  7394. collapsed: { type: Boolean, default: false }, // 功能说明:折叠态仅展示 header by xu 20260116
  7395. items: { type: Array, default: () => [] },
  7396. mode: { type: String, default: "search" }, // search / selected
  7397. },
  7398. emits: ["select", "remove", "clear", "search", "toggle-collapse"],
  7399. data() {
  7400. return {
  7401. keyword: "",
  7402. filterValues: {},
  7403. }; // 功能说明:折叠状态完全由 props.collapsed 驱动,避免多面板复用导致状态不同步 by xu 20260116
  7404. },
  7405. created() {
  7406. // header 下拉条件默认值初始化 by xu 20260106
  7407. (this.headerFilters || []).forEach((f) => {
  7408. if (!f || !f.key) return;
  7409. if (this.filterValues[f.key] !== undefined) return;
  7410. const first = f?.options?.[0]?.value ?? "";
  7411. this.filterValues[f.key] = f.value !== undefined ? f.value : first;
  7412. });
  7413. },
  7414. methods: {
  7415. __shouldIgnoreHeaderToggle(e) {
  7416. // 功能说明:忽略工具区/输入区触发折叠,避免误触 by xu 20260116
  7417. const t = e?.target;
  7418. if (!t || !t.closest) return false;
  7419. if (t.closest(".ss-sidebar-panel__tools")) return true;
  7420. if (t.closest(".ss-sidebar-panel__filters")) return true;
  7421. if (t.closest("input,textarea,select,button")) return true;
  7422. return false;
  7423. },
  7424. __toggleCollapseInternal(e, source) {
  7425. if (!this.collapsible) return;
  7426. if (this.__shouldIgnoreHeaderToggle(e)) return;
  7427. const nextCollapsed = !this.collapsed;
  7428. console.log("[SsSidebarList] toggle emit", {
  7429. title: this.title,
  7430. source,
  7431. to: nextCollapsed,
  7432. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7433. // 功能说明:由父组件(SsSidebar.toggleSectionCollapse)统一控制 section 高度与折叠数组 by xu 20260116
  7434. this.$emit("toggle-collapse");
  7435. },
  7436. },
  7437. render() {
  7438. const items = this.items || [];
  7439. const SsIcon = Vue.resolveComponent("ss-icon");
  7440. const isSelectedMode = this.mode === "selected";
  7441. const activeKeyword = this.filterValues?.keyword ?? this.keyword; // 功能:keyword 优先取 headerFilters.keyword by xu 20260106
  7442. const hasHeaderKeyword = (this.headerFilters || []).some(
  7443. (f) => f?.key === "keyword"
  7444. ); // 功能:header 内 keyword 过滤 by xu 20260106
  7445. const renderHeaderFilter = (f) => {
  7446. if (!f) return null;
  7447. const key = f.key;
  7448. const componentName = f.component;
  7449. if (!key || !componentName) return null;
  7450. const Comp = Vue.resolveComponent(componentName);
  7451. if (!Comp) return null;
  7452. const modelValue = this.filterValues[key];
  7453. const props = f.props || {};
  7454. return Vue.h(Comp, {
  7455. ...props,
  7456. modelValue,
  7457. "onUpdate:modelValue": (v) => {
  7458. this.filterValues[key] = v;
  7459. },
  7460. });
  7461. };
  7462. const filteredItems =
  7463. this.searchable && activeKeyword
  7464. ? items.filter((it) =>
  7465. String(it?.title ?? "")
  7466. .toLowerCase()
  7467. .includes(String(activeKeyword).toLowerCase())
  7468. )
  7469. : items;
  7470. if (!filteredItems.length && !this.title) return null;
  7471. if (this.collapsed) {
  7472. return Vue.h("div", { class: "ss-sidebar-panel" }, [
  7473. this.title
  7474. ? Vue.h(
  7475. "div",
  7476. {
  7477. class: "ss-sidebar-panel__header",
  7478. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  7479. onDblclick: (e) => {
  7480. e?.preventDefault?.();
  7481. e?.stopPropagation?.();
  7482. console.log("[SsSidebarList] header dblclick", {
  7483. title: this.title,
  7484. collapsed: true,
  7485. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7486. this.__toggleCollapseInternal(e, "dblclick");
  7487. },
  7488. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  7489. },
  7490. [
  7491. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7492. this.iconClass
  7493. ? Vue.h(SsIcon, {
  7494. class: this.iconClass + " ss-sidebar-panel__icon",
  7495. })
  7496. : this.icon
  7497. ? Vue.h(SsIcon, {
  7498. name: this.icon,
  7499. size: "16px",
  7500. class: "ss-sidebar-panel__icon",
  7501. })
  7502. : null,
  7503. Vue.h("span", null, this.title),
  7504. this.count !== ""
  7505. ? Vue.h(
  7506. "span",
  7507. { class: "ss-sidebar-panel__count" },
  7508. `(${this.count})`
  7509. )
  7510. : null,
  7511. ]),
  7512. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7513. this.closable
  7514. ? Vue.h(
  7515. "button",
  7516. {
  7517. type: "button",
  7518. class: "ss-sidebar-icon-btn ss-sidebar-header-btn",
  7519. title: "清空",
  7520. onClick: (e) => {
  7521. e.stopPropagation();
  7522. this.$emit("clear");
  7523. },
  7524. },
  7525. [
  7526. Vue.h(SsIcon, {
  7527. class: "ss-sidebar-base-icon icon-cl",
  7528. }),
  7529. ] // 功能说明:右侧栏“已选”清空按钮图标使用 ss-sidebar-base-icon by xu 20260123
  7530. )
  7531. : null,
  7532. ]),
  7533. ]
  7534. )
  7535. : null,
  7536. ]);
  7537. }
  7538. return Vue.h("div", { class: "ss-sidebar-panel" }, [
  7539. this.title
  7540. ? Vue.h(
  7541. "div",
  7542. {
  7543. class: "ss-sidebar-panel__header",
  7544. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  7545. onDblclick: (e) => {
  7546. e?.preventDefault?.();
  7547. e?.stopPropagation?.();
  7548. console.log("[SsSidebarList] header dblclick", {
  7549. title: this.title,
  7550. collapsed: false,
  7551. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7552. this.__toggleCollapseInternal(e, "dblclick");
  7553. },
  7554. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  7555. },
  7556. [
  7557. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7558. // 图标 + 标题(每个分区都有) by xu 20260106
  7559. this.iconClass
  7560. ? Vue.h(SsIcon, {
  7561. class: this.iconClass + " ss-sidebar-panel__icon",
  7562. })
  7563. : this.icon
  7564. ? Vue.h(SsIcon, {
  7565. name: this.icon,
  7566. size: "16px",
  7567. class: "ss-sidebar-panel__icon",
  7568. })
  7569. : null,
  7570. Vue.h("span", null, this.title),
  7571. // 数量回显:图表分区可不传 count by xu 20260106
  7572. this.count !== ""
  7573. ? Vue.h(
  7574. "span",
  7575. { class: "ss-sidebar-panel__count" },
  7576. `(${this.count})`
  7577. )
  7578. : null,
  7579. ]),
  7580. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7581. // header 条件(例如下拉框)+ 右侧搜索按钮 by xu 20260106
  7582. this.headerFilters?.length
  7583. ? Vue.h(
  7584. "div",
  7585. { class: "ss-sidebar-panel__filters" },
  7586. this.headerFilters
  7587. .map(renderHeaderFilter)
  7588. .filter(Boolean)
  7589. )
  7590. : null,
  7591. this.headerSearchButton
  7592. ? Vue.h(
  7593. "button",
  7594. {
  7595. type: "button",
  7596. class: "ss-sidebar-icon-btn",
  7597. title: "搜索",
  7598. onClick: (e) => {
  7599. e.stopPropagation();
  7600. this.$emit("search", {
  7601. // headerFilters 内也可能包含 keyword by xu 20260106
  7602. keyword: activeKeyword,
  7603. filters: { ...(this.filterValues || {}) },
  7604. });
  7605. },
  7606. },
  7607. [Vue.h(SsIcon, { name: "search", size: "14px" })]
  7608. )
  7609. : null,
  7610. // 人员块:搜索框在 header 内 by xu 20260106
  7611. this.searchable &&
  7612. this.searchInHeader &&
  7613. !this.headerSearchButton
  7614. ? Vue.h(
  7615. "div",
  7616. { class: "ss-sidebar-panel__searchInline" },
  7617. [
  7618. Vue.h(
  7619. "div",
  7620. { class: "ss-sidebar-search is-inline" },
  7621. [
  7622. Vue.h(SsIcon, {
  7623. name: "search",
  7624. size: "14px",
  7625. class: "ss-sidebar-search__prefix",
  7626. }),
  7627. Vue.h("input", {
  7628. class: "ss-sidebar-search__input",
  7629. value: this.keyword,
  7630. placeholder: this.searchPlaceholder,
  7631. onInput: (e) => {
  7632. this.keyword = e?.target?.value ?? "";
  7633. },
  7634. }),
  7635. ]
  7636. ),
  7637. ]
  7638. )
  7639. : null,
  7640. this.closable
  7641. ? Vue.h(
  7642. "button",
  7643. {
  7644. type: "button",
  7645. class: "ss-sidebar-icon-btn ss-sidebar-header-btn",
  7646. title: "清空",
  7647. onClick: (e) => {
  7648. e.stopPropagation();
  7649. this.$emit("clear");
  7650. },
  7651. },
  7652. // 清空按钮使用 icon-base 的 icon-cl by xu 20260106
  7653. [
  7654. Vue.h(SsIcon, {
  7655. class: "ss-sidebar-base-icon icon-cl",
  7656. }),
  7657. ] // 功能说明:右侧栏清空按钮图标使用 ss-sidebar-base-icon by xu 20260123
  7658. )
  7659. : null,
  7660. ]),
  7661. ]
  7662. )
  7663. : null,
  7664. // 非 header 内搜索:独立一行 by xu 20260106
  7665. // headerSearchButton/headerFilters 已覆盖搜索能力时,不再额外渲染独立搜索行 by xu 20260106
  7666. this.searchable &&
  7667. !this.searchInHeader &&
  7668. !this.headerSearchButton &&
  7669. !hasHeaderKeyword
  7670. ? Vue.h("div", { class: "ss-sidebar-panel__search" }, [
  7671. Vue.h("div", { class: "ss-sidebar-search" }, [
  7672. Vue.h(SsIcon, {
  7673. name: "search",
  7674. size: "14px",
  7675. class: "ss-sidebar-search__prefix",
  7676. }),
  7677. Vue.h("input", {
  7678. class: "ss-sidebar-search__input",
  7679. value: this.keyword,
  7680. placeholder: this.searchPlaceholder,
  7681. onInput: (e) => {
  7682. this.keyword = e?.target?.value ?? "";
  7683. },
  7684. }),
  7685. ]),
  7686. ])
  7687. : null,
  7688. Vue.h(
  7689. "div",
  7690. { class: "ss-sidebar-list" },
  7691. filteredItems.map((item, idx) => {
  7692. const title = item?.title ?? "";
  7693. const tags = item?.tags || [];
  7694. const isPersonLayout = this.itemLayout === "person";
  7695. const hasTags = !isPersonLayout && tags?.length > 0; // 列表项垂直对齐:有 tags 顶对齐 by xu 20260106
  7696. return Vue.h(
  7697. "div",
  7698. {
  7699. class: {
  7700. "ss-sidebar-list-item": true,
  7701. "is-first": idx === 0,
  7702. "is-person": isPersonLayout,
  7703. "has-tags": hasTags,
  7704. },
  7705. },
  7706. [
  7707. Vue.h("div", { class: "ss-sidebar-list-item__main" }, [
  7708. Vue.h(
  7709. "div",
  7710. { class: "ss-sidebar-list-item__title" },
  7711. Vue.h(
  7712. "span",
  7713. {
  7714. style: {
  7715. "white-space": "nowrap",
  7716. overflow: "hidden",
  7717. "text-overflow": "ellipsis",
  7718. },
  7719. },
  7720. title
  7721. )
  7722. ),
  7723. // 非人员布局才显示 tags by xu 20260106
  7724. !isPersonLayout && tags?.length
  7725. ? Vue.h(
  7726. "div",
  7727. { class: "ss-sidebar-list-item__tags" },
  7728. tags.map((tag) => {
  7729. const [k, v] = Object.entries(tag)[0] || ["", ""];
  7730. return Vue.h(
  7731. "span",
  7732. { class: "ss-sidebar-tag", title: `${k}: ${v}` },
  7733. `${k}: ${v}`
  7734. );
  7735. })
  7736. )
  7737. : null,
  7738. ]),
  7739. // 人员布局:中间保留“人员号”槽位 by xu 20260106
  7740. isPersonLayout
  7741. ? Vue.h(
  7742. "div",
  7743. {
  7744. class: "ss-sidebar-list-item__meta",
  7745. title: String(item?.meta ?? ""),
  7746. },
  7747. item?.meta ?? ""
  7748. )
  7749. : null,
  7750. this.itemAction
  7751. ? Vue.h(
  7752. "button",
  7753. {
  7754. type: "button",
  7755. class: {
  7756. // item 操作按钮:默认无背景/无边框,hover 才高亮 by xu 20260106
  7757. "ss-sidebar-item-btn": true,
  7758. },
  7759. title: isSelectedMode ? "移除" : "选择",
  7760. onClick: (e) => {
  7761. e.stopPropagation();
  7762. if (isSelectedMode) this.$emit("remove", item);
  7763. else this.$emit("select", item);
  7764. },
  7765. },
  7766. [
  7767. // item 移除图标使用 icon-base 的 icon-cl by xu 20260106
  7768. isSelectedMode
  7769. ? Vue.h(SsIcon, {
  7770. class: "ss-sidebar-base-icon icon-cl",
  7771. }) // 功能说明:右侧栏 item 移除图标使用 ss-sidebar-base-icon by xu 20260123
  7772. : Vue.h(SsIcon, { name: "check", size: "14px" }),
  7773. ]
  7774. )
  7775. : null,
  7776. ]
  7777. );
  7778. })
  7779. ),
  7780. ]);
  7781. },
  7782. };
  7783. // ss-sidebar-report-table:右侧“统计表/报表”面板(pstatList grtjlbm=51 聚拢渲染) by xu 20260115
  7784. const SsSidebarReportTable = {
  7785. name: "SsSidebarReportTable",
  7786. props: {
  7787. title: { type: String, default: "" },
  7788. iconClass: { type: String, default: "" },
  7789. icon: { type: String, default: "" },
  7790. items: { type: Array, default: () => [] }, // pstatList(grtjlbm=51) 数组
  7791. onOpen: { type: Function, default: null }, // (srv, ctx) => void
  7792. collapsible: { type: Boolean, default: true }, // 功能说明:是否允许双击 header 折叠/展开 by xu 20260116
  7793. collapsed: { type: Boolean, default: false }, // 功能说明:折叠态仅展示 header by xu 20260116
  7794. },
  7795. emits: ["open", "toggle-collapse"],
  7796. data() {
  7797. return {}; // 功能说明:折叠状态完全由 props.collapsed 驱动 by xu 20260116
  7798. },
  7799. methods: {
  7800. __toggleCollapseInternal(e, source) {
  7801. if (!this.collapsible) return;
  7802. const next = !this.collapsed;
  7803. console.log("[SsSidebarReportTable] toggle emit", {
  7804. title: this.title,
  7805. source,
  7806. to: next,
  7807. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7808. this.$emit("toggle-collapse");
  7809. },
  7810. },
  7811. render() {
  7812. const SsIcon = Vue.resolveComponent("ss-icon");
  7813. const list = this.items || [];
  7814. if (!this.title && !list.length) return null;
  7815. const header = this.title
  7816. ? Vue.h(
  7817. "div",
  7818. {
  7819. class: "ss-sidebar-panel__header",
  7820. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  7821. onDblclick: (e) => {
  7822. e?.preventDefault?.();
  7823. e?.stopPropagation?.();
  7824. console.log("[SsSidebarReportTable] header dblclick", {
  7825. title: this.title,
  7826. collapsed: this.collapsed,
  7827. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7828. this.__toggleCollapseInternal(e, "dblclick");
  7829. },
  7830. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  7831. },
  7832. [
  7833. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7834. this.iconClass
  7835. ? Vue.h(SsIcon, {
  7836. class: this.iconClass + " ss-sidebar-panel__icon",
  7837. })
  7838. : this.icon
  7839. ? Vue.h(SsIcon, {
  7840. name: this.icon,
  7841. size: "16px",
  7842. class: "ss-sidebar-panel__icon",
  7843. })
  7844. : null,
  7845. Vue.h("span", null, this.title),
  7846. ]),
  7847. Vue.h("div", { class: "ss-sidebar-panel__tools" }),
  7848. ]
  7849. )
  7850. : null;
  7851. const renderReport = (report) => {
  7852. const title = String(report?.mc ?? "");
  7853. const mx = Array.isArray(report?.grtjmxList) ? report.grtjmxList : [];
  7854. if (!title && !mx.length) return null;
  7855. // 功能说明:每个报表对象渲染为一个 table(有边框、无圆角、表间距10px;样式由 base.css 统一控制) by xu 20260115
  7856. const cols = Math.max(1, mx.length);
  7857. // 功能说明:table 外层包一层 wrap,子项过多时支持横向滚动 by xu 20260115
  7858. return Vue.h("div", { class: "ss-sidebar-report-table-wrap" }, [
  7859. Vue.h("table", { class: "ss-sidebar-report-table" }, [
  7860. Vue.h("thead", null, [
  7861. Vue.h("tr", null, [
  7862. Vue.h(
  7863. "th",
  7864. { class: "ss-sidebar-report-table__title", colspan: cols },
  7865. Vue.h(
  7866. "div",
  7867. { class: "ss-sidebar-report-table__title-content" },
  7868. [
  7869. Vue.h("span", { class: "ss-sidebar-report-table__dot" }),
  7870. Vue.h(
  7871. "span",
  7872. { class: "ss-sidebar-report-table__title-text", title },
  7873. title
  7874. ),
  7875. ]
  7876. )
  7877. ),
  7878. ]),
  7879. ]),
  7880. Vue.h("tbody", null, [
  7881. Vue.h(
  7882. "tr",
  7883. null,
  7884. mx.map((cell) => {
  7885. const text = String(cell?.mc ?? "");
  7886. const srv = {
  7887. servName: cell?.fwm ?? "",
  7888. dest: cell?.bjm ?? "",
  7889. title: text,
  7890. width: cell?.width,
  7891. height: cell?.height,
  7892. minHeight: cell?.height,
  7893. maxHeight: cell?.height,
  7894. showTitle: text,
  7895. };
  7896. return Vue.h(
  7897. "td",
  7898. {
  7899. class: "ss-sidebar-report-table__cell",
  7900. title: text,
  7901. onClick: (e) => {
  7902. e?.stopPropagation?.();
  7903. try {
  7904. this.onOpen?.(srv, { report, cell });
  7905. } catch (_) {}
  7906. this.$emit("open", { report, cell, srv });
  7907. },
  7908. },
  7909. text
  7910. );
  7911. })
  7912. ),
  7913. ]),
  7914. ]),
  7915. ]);
  7916. };
  7917. // 功能说明:报表面板增加独立 class,便于 base.css 统一控制 padding/间距 by xu 20260115
  7918. return Vue.h(
  7919. "div",
  7920. { class: "ss-sidebar-panel ss-sidebar-report-panel" },
  7921. [
  7922. header,
  7923. this.collapsed
  7924. ? null
  7925. : Vue.h(
  7926. "div",
  7927. // 功能说明:报表列表滚动/高度样式下沉到 base.css,避免写在 DOM 上 by xu 20260115
  7928. { class: "ss-sidebar-report__list" },
  7929. list.map(renderReport).filter(Boolean)
  7930. ),
  7931. ]
  7932. );
  7933. },
  7934. };
  7935. // 组件文档补全(JSDoc) by xu 20260108
  7936. /**
  7937. * SsSidebar(objList 右侧边栏容器)
  7938. *
  7939. * 用途:
  7940. * - 统一渲染顶部按钮栏(buttons)
  7941. * - 统一渲染中间业务面板(list panels,可拖拽调高度)
  7942. * - 统一渲染底部图表(chart panels,内部用 ss-sidebar-chart-hover)
  7943. *
  7944. * 调用示例:
  7945. * ```html
  7946. * <ss-sidebar :buttons="sidebarButtons" :panels="sidebarPanels" @remove="handleSidebarRemove" />
  7947. * ```
  7948. *
  7949. * Props:
  7950. * - `buttons`:顶部按钮配置数组
  7951. * - `panels`:分区配置数组(`type: 'list' | 'chart'`)
  7952. *
  7953. * Events(向外透传):
  7954. * - `remove(item)`:来自 list 面板移除
  7955. * - `select(item)`:来自 list 面板选择(如后续需要)
  7956. */
  7957. const SsSidebar = {
  7958. name: "SsSidebar",
  7959. props: {
  7960. buttons: { type: Array, default: () => [] },
  7961. charts: { type: Array, default: () => [] },
  7962. list: { type: Array, default: () => [] }, // legacy
  7963. listMode: { type: String, default: "search" }, // legacy
  7964. panels: { type: Array, default: () => [] },
  7965. },
  7966. emits: ["select", "remove"],
  7967. data() {
  7968. return {
  7969. // 业务面板高度(索引 -> px) by xu 20260106
  7970. sectionHeights: [],
  7971. sectionCollapsed: [], // 功能说明:面板折叠状态(sectionPanels 索引) by xu 20260116
  7972. sectionHeightsExpanded: [], // 功能说明:面板展开高度缓存(用于折叠后恢复) by xu 20260116
  7973. sectionLastItemCounts: [], // 功能说明:记录栏目数据量,供“无数据默认关闭/已选自动展开”规则复用 by xu 20260313
  7974. chartCollapsed: [], // 功能说明:图表面板折叠状态(chartPanels 索引) by xu 20260116
  7975. chartHeaderTitleDownAt: [], // 功能说明:双击检测绑定到 chart 标题区 by xu 20260116
  7976. reportCollapsed: [], // 功能说明:报表面板折叠状态(reportPanels 索引) by xu 20260116
  7977. resizeTimer: null,
  7978. resizing: false,
  7979. resizeIndex: -1,
  7980. resizeStartY: 0,
  7981. resizeStartPrev: 0,
  7982. resizeStartNext: 0,
  7983. __resizeMoveHandler: null, // 功能说明:显式绑定 this 的 pointermove handler,避免 addEventListener 场景 this 丢失导致拖拽无效 by xu 20260122
  7984. __resizeEndHandler: null, // 功能说明:显式绑定 this 的 pointerup handler,确保能正确结束拖拽 by xu 20260122
  7985. __resizeCancelHandler: null, // 功能说明:显式绑定 this 的 pointercancel handler,触控取消也能收尾 by xu 20260122
  7986. __resizePrevSectionEl: null, // 功能说明:拖拽时直接写 DOM 高度(修复响应式更新不生效) by xu 20260122
  7987. __resizeNextSectionEl: null, // 功能说明:拖拽时直接写 DOM 高度(修复响应式更新不生效) by xu 20260122
  7988. };
  7989. },
  7990. methods: {
  7991. // 初始化默认高度(只在第一次/面板数量变化时补齐) by xu 20260106
  7992. ensureSectionHeights(sectionCount) {
  7993. if (!Array.isArray(this.sectionHeights)) this.sectionHeights = [];
  7994. if (this.sectionHeights.length === sectionCount) return;
  7995. const next = [];
  7996. for (let i = 0; i < sectionCount; i++) {
  7997. next[i] = this.sectionHeights[i] ?? 190; // 默认高度 by xu 20260106
  7998. }
  7999. this.sectionHeights = next;
  8000. // 功能说明:面板数量变化时补齐折叠/缓存数组长度 by xu 20260116
  8001. this.sectionCollapsed = Array.from(
  8002. { length: sectionCount },
  8003. (_, i) => !!this.sectionCollapsed?.[i]
  8004. );
  8005. this.sectionHeightsExpanded = Array.from(
  8006. { length: sectionCount },
  8007. (_, i) => this.sectionHeightsExpanded?.[i] ?? null
  8008. );
  8009. this.sectionLastItemCounts = Array.from(
  8010. { length: sectionCount },
  8011. (_, i) => Number(this.sectionLastItemCounts?.[i] ?? 0) || 0
  8012. );
  8013. },
  8014. __getPanelsForSectionState(panelsInput) {
  8015. return (panelsInput || []).length
  8016. ? panelsInput
  8017. : this.list?.length
  8018. ? [
  8019. {
  8020. type: "list",
  8021. title: "已选",
  8022. icon: "",
  8023. mode: this.listMode,
  8024. items: this.list,
  8025. },
  8026. ]
  8027. : [];
  8028. },
  8029. __getSectionPanelsForState(panelsInput) {
  8030. return this.__getPanelsForSectionState(panelsInput)
  8031. .filter((p) => {
  8032. const k = String(p?._tabKey ?? "")
  8033. .trim()
  8034. .toLowerCase();
  8035. const t = String(p?.title ?? "").trim();
  8036. if (k === "rbarobj") return false;
  8037. if (t === "对象") return false;
  8038. return true;
  8039. })
  8040. .filter((p) => p?.type !== "chart" && p?.type !== "report-table");
  8041. },
  8042. __getSectionPanelCount(panel) {
  8043. const explicitCount = Number(panel?.count);
  8044. if (Number.isFinite(explicitCount)) return explicitCount;
  8045. return Array.isArray(panel?.items) ? panel.items.length : 0;
  8046. },
  8047. __setSectionCollapsedState(index, collapsed) {
  8048. const i = Number(index);
  8049. if (isNaN(i) || i < 0) return;
  8050. const nextCollapsed = !!collapsed;
  8051. const collapsedHeight = 37;
  8052. const cur = !!this.sectionCollapsed?.[i];
  8053. const currentHeight = Number(this.sectionHeights?.[i] ?? 190) || 190;
  8054. if (nextCollapsed === cur) {
  8055. if (nextCollapsed && currentHeight !== collapsedHeight) {
  8056. this.sectionHeights.splice(i, 1, collapsedHeight);
  8057. }
  8058. return;
  8059. }
  8060. if (nextCollapsed) {
  8061. this.sectionHeightsExpanded[i] =
  8062. currentHeight > collapsedHeight
  8063. ? currentHeight
  8064. : Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  8065. this.sectionHeights.splice(i, 1, collapsedHeight);
  8066. } else {
  8067. const restore =
  8068. Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  8069. this.sectionHeights.splice(i, 1, restore);
  8070. }
  8071. this.sectionCollapsed.splice(i, 1, nextCollapsed);
  8072. },
  8073. __syncSectionAutoCollapse(panelsInput) {
  8074. const sectionPanels = this.__getSectionPanelsForState(panelsInput);
  8075. const sectionCount = sectionPanels.length;
  8076. this.ensureSectionHeights(sectionCount);
  8077. const prevCounts = Array.isArray(this.sectionLastItemCounts)
  8078. ? this.sectionLastItemCounts.slice()
  8079. : [];
  8080. const nextCounts = Array.from({ length: sectionCount }, (_, i) =>
  8081. this.__getSectionPanelCount(sectionPanels[i])
  8082. );
  8083. this.sectionLastItemCounts = nextCounts;
  8084. sectionPanels.forEach((panel, index) => {
  8085. const count = Number(nextCounts[index] ?? 0) || 0;
  8086. const prevCount = Number(prevCounts[index] ?? 0) || 0;
  8087. const title = String(panel?.title ?? "").trim();
  8088. if (count <= 0) {
  8089. this.__setSectionCollapsedState(index, true);
  8090. return;
  8091. }
  8092. if (title === "已选" && count > prevCount) {
  8093. this.__setSectionCollapsedState(index, false);
  8094. }
  8095. });
  8096. },
  8097. toggleSectionCollapse(index) {
  8098. // 功能说明:双击 header 折叠/展开 section 面板(仅控制高度与内容渲染) by xu 20260116
  8099. const i = Number(index);
  8100. if (isNaN(i) || i < 0) return;
  8101. // 功能说明:加更细粒度日志,定位“多面板折叠无视觉效果”的根因(高度是否真的变、DOM 是否更新) by xu 20260116
  8102. const collapsedHeight = 37; // 功能说明:header(35) + panel 边框(2),避免 flex shrink 导致 header 变 25px by xu 20260116
  8103. const cur = !!this.sectionCollapsed?.[i];
  8104. console.log("[SsSidebar] toggleSectionCollapse", {
  8105. index: i,
  8106. to: !cur,
  8107. prevHeight: this.sectionHeights?.[i],
  8108. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8109. if (!cur) {
  8110. this.sectionHeightsExpanded[i] = this.sectionHeights[i] ?? 190;
  8111. this.sectionHeights.splice(i, 1, collapsedHeight);
  8112. } else {
  8113. const restore =
  8114. Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  8115. this.sectionHeights.splice(i, 1, restore);
  8116. }
  8117. this.sectionCollapsed.splice(i, 1, !cur);
  8118. console.log("[SsSidebar] section state(after)", {
  8119. index: i,
  8120. height: this.sectionHeights?.[i],
  8121. collapsed: this.sectionCollapsed?.[i],
  8122. allHeights: Array.from(this.sectionHeights || []),
  8123. allCollapsed: Array.from(this.sectionCollapsed || []),
  8124. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8125. Vue.nextTick(() => {
  8126. try {
  8127. const root = this.$el;
  8128. const sections = root?.querySelectorAll?.(".ss-sidebar-section");
  8129. const el = sections?.[i];
  8130. const rectH = el?.getBoundingClientRect?.().height;
  8131. console.log("[SsSidebar] section dom(beforeFix)", {
  8132. index: i,
  8133. styleHeight: el?.style?.height,
  8134. rectH,
  8135. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8136. // 功能说明:若渲染未把 height patch 到 DOM,则在 nextTick 强制同步一次(并打印) by xu 20260116
  8137. const targetH =
  8138. (Number(this.sectionHeights?.[i] ?? 190) || 190) + "px";
  8139. if (el && el.style && el.style.height !== targetH) {
  8140. el.style.height = targetH;
  8141. }
  8142. if (el?.classList) {
  8143. el.classList.toggle("is-collapsed", !!this.sectionCollapsed?.[i]);
  8144. }
  8145. const rectAfter = el?.getBoundingClientRect?.().height;
  8146. console.log("[SsSidebar] section dom(afterFix)", {
  8147. index: i,
  8148. styleHeight: el?.style?.height,
  8149. rectH: rectAfter,
  8150. targetH,
  8151. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8152. } catch (err) {
  8153. console.log("[SsSidebar] section dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8154. }
  8155. });
  8156. },
  8157. toggleChartCollapse(index) {
  8158. // 功能说明:双击 header 折叠/展开底部 chart 面板(隐藏/显示 chart-hover) by xu 20260116
  8159. const i = Number(index);
  8160. if (isNaN(i) || i < 0) return;
  8161. const cur = !!this.chartCollapsed?.[i];
  8162. console.log("[SsSidebar] toggleChartCollapse", { index: i, to: !cur }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8163. this.chartCollapsed.splice(i, 1, !cur);
  8164. console.log("[SsSidebar] chart state(after)", {
  8165. index: i,
  8166. collapsed: this.chartCollapsed?.[i],
  8167. allCollapsed: Array.from(this.chartCollapsed || []),
  8168. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8169. Vue.nextTick(() => {
  8170. try {
  8171. const root = this.$el;
  8172. const el = root?.querySelector?.(
  8173. `.ss-sidebar-chart-panel[data-chart-idx="${i}"]`
  8174. );
  8175. console.log("[SsSidebar] chart dom(beforeFix)", {
  8176. index: i,
  8177. found: !!el,
  8178. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8179. if (el?.classList)
  8180. el.classList.toggle("is-collapsed", !!this.chartCollapsed?.[i]);
  8181. console.log("[SsSidebar] chart dom(afterFix)", {
  8182. index: i,
  8183. collapsed: !!this.chartCollapsed?.[i],
  8184. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8185. } catch (err) {
  8186. console.log("[SsSidebar] chart dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8187. }
  8188. });
  8189. },
  8190. toggleReportCollapse(index) {
  8191. // 功能说明:双击 header 折叠/展开底部 report-table 面板(隐藏/显示表格) by xu 20260116
  8192. const i = Number(index);
  8193. if (isNaN(i) || i < 0) return;
  8194. const cur = !!this.reportCollapsed?.[i];
  8195. console.log("[SsSidebar] toggleReportCollapse", { index: i, to: !cur }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8196. this.reportCollapsed.splice(i, 1, !cur);
  8197. console.log("[SsSidebar] report state(after)", {
  8198. index: i,
  8199. collapsed: this.reportCollapsed?.[i],
  8200. allCollapsed: Array.from(this.reportCollapsed || []),
  8201. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8202. Vue.nextTick(() => {
  8203. try {
  8204. const root = this.$el;
  8205. const el = root?.querySelector?.(
  8206. `.ss-sidebar-report-panel[data-report-idx="${i}"]`
  8207. );
  8208. console.log("[SsSidebar] report dom(beforeFix)", {
  8209. index: i,
  8210. found: !!el,
  8211. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8212. if (el?.classList)
  8213. el.classList.toggle("is-collapsed", !!this.reportCollapsed?.[i]);
  8214. console.log("[SsSidebar] report dom(afterFix)", {
  8215. index: i,
  8216. collapsed: !!this.reportCollapsed?.[i],
  8217. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8218. } catch (err) {
  8219. console.log("[SsSidebar] report dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  8220. }
  8221. });
  8222. },
  8223. startResize(index, e) {
  8224. if (e?.preventDefault) e.preventDefault();
  8225. if (e?.stopPropagation) e.stopPropagation();
  8226. if (this.resizing) return;
  8227. // 长按 0.5s 后才进入拖拽调高度 by xu 20260106
  8228. clearTimeout(this.resizeTimer);
  8229. // 功能说明:修复“长按拖拽偶发失效/卡死”——pointerup 早于 500ms 时必须取消 timer,否则 timer 触发后进入 resizing=true 且再也收不到 pointerup,导致后续都无法拖拽 by xu 20260122
  8230. const pointerId = e?.pointerId;
  8231. const cancelPendingResize = (ev) => {
  8232. try {
  8233. if (
  8234. pointerId != null &&
  8235. ev?.pointerId != null &&
  8236. ev.pointerId !== pointerId
  8237. )
  8238. return;
  8239. } catch (_) {}
  8240. clearTimeout(this.resizeTimer);
  8241. this.resizeTimer = null;
  8242. document.removeEventListener("pointerup", cancelPendingResize, true);
  8243. document.removeEventListener(
  8244. "pointercancel",
  8245. cancelPendingResize,
  8246. true
  8247. );
  8248. };
  8249. // 功能说明:用 document+capture 监听,避免 window 监听在部分容器/iframe 场景丢事件导致拖拽无响应 by xu 20260122
  8250. document.addEventListener("pointerup", cancelPendingResize, {
  8251. passive: false,
  8252. once: true,
  8253. capture: true,
  8254. });
  8255. document.addEventListener("pointercancel", cancelPendingResize, {
  8256. passive: false,
  8257. once: true,
  8258. capture: true,
  8259. });
  8260. const startY = e?.clientY ?? 0;
  8261. const gapEl = e?.currentTarget;
  8262. // 功能说明:记录 gap 前后 section 节点,拖拽过程中直接写入 style.height,避免某些环境下 Vue render 不刷新导致“拖拽无视觉变化” by xu 20260122
  8263. this.__resizePrevSectionEl = gapEl?.previousElementSibling || null;
  8264. this.__resizeNextSectionEl = gapEl?.nextElementSibling || null;
  8265. this.resizeTimer = setTimeout(() => {
  8266. // 定时器触发后进入拖拽态,移除“取消等待”监听,避免误取消 by xu 20260122
  8267. document.removeEventListener("pointerup", cancelPendingResize, true);
  8268. document.removeEventListener(
  8269. "pointercancel",
  8270. cancelPendingResize,
  8271. true
  8272. );
  8273. this.resizing = true;
  8274. this.resizeIndex = index;
  8275. this.resizeStartY = startY;
  8276. this.resizeStartPrev = this.sectionHeights[index] ?? 190;
  8277. this.resizeStartNext = this.sectionHeights[index + 1] ?? 190;
  8278. gapEl?.classList?.add("is-active");
  8279. try {
  8280. if (gapEl?.setPointerCapture && pointerId != null)
  8281. gapEl.setPointerCapture(pointerId);
  8282. } catch (_) {} // 功能说明:捕获 pointer,避免拖拽过程中移出窗口导致 pointermove 丢失 by xu 20260122
  8283. // 功能说明:用 document+capture,确保拖拽时 pointermove/up 不会被中途 stopPropagation 影响 by xu 20260122
  8284. document.addEventListener(
  8285. "pointermove",
  8286. this.__resizeMoveHandler || this.onResizeMove,
  8287. { passive: false, capture: true }
  8288. );
  8289. document.addEventListener(
  8290. "pointerup",
  8291. this.__resizeEndHandler || this.endResize,
  8292. { passive: false, once: true, capture: true }
  8293. );
  8294. document.addEventListener(
  8295. "pointercancel",
  8296. this.__resizeCancelHandler || this.endResize,
  8297. { passive: false, once: true, capture: true }
  8298. ); // 功能说明:触控/手势取消时也要结束拖拽 by xu 20260122
  8299. }, 500);
  8300. },
  8301. onResizeMove(e) {
  8302. if (!this.resizing) return;
  8303. if (e?.preventDefault) e.preventDefault();
  8304. const dy = (e?.clientY ?? 0) - this.resizeStartY;
  8305. const minPanelHeight = 83; // header(35) + listMin(48) by xu 20260106
  8306. const prev = Math.max(minPanelHeight, this.resizeStartPrev + dy);
  8307. const next = Math.max(minPanelHeight, this.resizeStartNext - dy);
  8308. // 若其中一个达到最小值,则停止继续挤压 by xu 20260106
  8309. const adjustedDy = prev - this.resizeStartPrev;
  8310. const nextAdjusted = this.resizeStartNext - adjustedDy;
  8311. const appliedPrev = prev;
  8312. const appliedNext = Math.max(minPanelHeight, nextAdjusted);
  8313. this.sectionHeights.splice(this.resizeIndex, 1, appliedPrev);
  8314. this.sectionHeights.splice(this.resizeIndex + 1, 1, appliedNext);
  8315. // 功能说明:强制触发一次 sectionHeights 引用变化,避免某些运行时环境下 splice 未触发视图更新导致“拖拽没反应” by xu 20260122
  8316. this.sectionHeights = (this.sectionHeights || []).slice();
  8317. // 功能说明:兜底——直接写 DOM 的 height,确保视觉立即响应(用于排查/修复某些环境下 render 不更新) by xu 20260122
  8318. try {
  8319. if (this.__resizePrevSectionEl?.style)
  8320. this.__resizePrevSectionEl.style.height = appliedPrev + "px";
  8321. if (this.__resizeNextSectionEl?.style)
  8322. this.__resizeNextSectionEl.style.height = appliedNext + "px";
  8323. } catch (_) {}
  8324. },
  8325. endResize(e) {
  8326. clearTimeout(this.resizeTimer);
  8327. this.resizeTimer = null;
  8328. if (!this.resizing) return;
  8329. if (e?.preventDefault) e.preventDefault();
  8330. const activeGaps = document.querySelectorAll(
  8331. ".ss-sidebar-gap.is-active"
  8332. );
  8333. activeGaps.forEach((g) => g.classList.remove("is-active"));
  8334. this.resizing = false;
  8335. this.resizeIndex = -1;
  8336. this.__resizePrevSectionEl = null; // 功能说明:释放 DOM 引用,避免内存泄漏 by xu 20260122
  8337. this.__resizeNextSectionEl = null; // 功能说明:释放 DOM 引用,避免内存泄漏 by xu 20260122
  8338. document.removeEventListener(
  8339. "pointermove",
  8340. this.__resizeMoveHandler || this.onResizeMove,
  8341. true
  8342. );
  8343. document.removeEventListener(
  8344. "pointercancel",
  8345. this.__resizeCancelHandler || this.endResize,
  8346. true
  8347. ); // 功能说明:清理 cancel 监听,避免残留 by xu 20260122
  8348. },
  8349. },
  8350. watch: {
  8351. panels: {
  8352. handler(nextPanels) {
  8353. this.__syncSectionAutoCollapse(nextPanels);
  8354. },
  8355. deep: true,
  8356. immediate: true,
  8357. },
  8358. list: {
  8359. handler(nextList) {
  8360. if ((this.panels || []).length) return;
  8361. this.__syncSectionAutoCollapse(nextList);
  8362. },
  8363. deep: true,
  8364. immediate: true,
  8365. },
  8366. },
  8367. mounted() {
  8368. clearTimeout(this.resizeTimer);
  8369. this.resizeTimer = null;
  8370. // 功能说明:绑定拖拽事件 handler(用于 add/removeEventListener) by xu 20260122
  8371. if (!this.__resizeMoveHandler)
  8372. this.__resizeMoveHandler = (e) => this.onResizeMove?.(e);
  8373. if (!this.__resizeEndHandler)
  8374. this.__resizeEndHandler = (e) => this.endResize?.(e);
  8375. if (!this.__resizeCancelHandler)
  8376. this.__resizeCancelHandler = (e) => this.endResize?.(e);
  8377. // 功能说明:暂时回退为固定底部留白方案(CSS 控制),后续再定位遮挡根因 by xu 20260115
  8378. },
  8379. beforeUnmount() {
  8380. clearTimeout(this.resizeTimer);
  8381. this.resizeTimer = null;
  8382. document.removeEventListener(
  8383. "pointermove",
  8384. this.__resizeMoveHandler || this.onResizeMove,
  8385. true
  8386. );
  8387. document.removeEventListener(
  8388. "pointerup",
  8389. this.__resizeEndHandler || this.endResize,
  8390. true
  8391. );
  8392. document.removeEventListener(
  8393. "pointercancel",
  8394. this.__resizeCancelHandler || this.endResize,
  8395. true
  8396. );
  8397. },
  8398. render() {
  8399. const SsSidebarButtonsComp = Vue.resolveComponent("ss-sidebar-buttons");
  8400. const SsSidebarChartComp = Vue.resolveComponent("ss-sidebar-chart");
  8401. const SsSidebarListComp = Vue.resolveComponent("ss-sidebar-list");
  8402. const SsSidebarReportTableComp = Vue.resolveComponent(
  8403. "ss-sidebar-report-table"
  8404. );
  8405. const SsIcon = Vue.resolveComponent("ss-icon");
  8406. // 支持 panels(多分区),list/listMode 作为 legacy 兜底 by xu 20260106
  8407. const panels = (this.panels || []).length
  8408. ? this.panels
  8409. : this.list?.length
  8410. ? [
  8411. {
  8412. type: "list",
  8413. title: "已选",
  8414. icon: "",
  8415. mode: this.listMode,
  8416. items: this.list,
  8417. },
  8418. ]
  8419. : [];
  8420. // 功能说明:右侧栏强制移除“对象”tab(兼容后端返回 rbarObj/rbarobj 或直接返回中文“对象”标题) by xu 20260116
  8421. const panelsNoObj = (panels || []).filter((p) => {
  8422. const k = String(p?._tabKey ?? "")
  8423. .trim()
  8424. .toLowerCase();
  8425. const t = String(p?.title ?? "").trim();
  8426. if (k === "rbarobj") return false;
  8427. if (t === "对象") return false;
  8428. return true;
  8429. });
  8430. // 功能说明:report-table 作为底部报表区(放在统计图下面),不参与可拖拽 section 面板 by xu 20260115
  8431. const sectionPanels = panelsNoObj.filter(
  8432. (p) => p?.type !== "chart" && p?.type !== "report-table"
  8433. );
  8434. const chartPanels = panelsNoObj.filter((p) => p?.type === "chart");
  8435. const reportPanels = panelsNoObj.filter(
  8436. (p) => p?.type === "report-table"
  8437. );
  8438. this.ensureSectionHeights(sectionPanels.length);
  8439. // 功能说明:补齐 chart/report 折叠数组长度 by xu 20260116
  8440. this.chartCollapsed = Array.from(
  8441. { length: chartPanels.length },
  8442. (_, i) => !!this.chartCollapsed?.[i]
  8443. );
  8444. this.chartHeaderTitleDownAt = Array.from(
  8445. { length: chartPanels.length },
  8446. (_, i) => this.chartHeaderTitleDownAt?.[i] ?? 0
  8447. );
  8448. this.reportCollapsed = Array.from(
  8449. { length: reportPanels.length },
  8450. (_, i) => !!this.reportCollapsed?.[i]
  8451. );
  8452. return Vue.h("div", { class: "ss-sidebar" }, [
  8453. this.buttons?.length
  8454. ? Vue.h(SsSidebarButtonsComp, { items: this.buttons })
  8455. : null,
  8456. Vue.h(
  8457. "div",
  8458. { class: "ss-sidebar__inner" },
  8459. [
  8460. ...(this.charts || []).map((c) =>
  8461. Vue.h(SsSidebarChartComp, {
  8462. options: c?.options || {},
  8463. height: c?.height || "200px",
  8464. })
  8465. ),
  8466. // 可拖拽的业务面板容器 by xu 20260106
  8467. Vue.h(
  8468. "div",
  8469. { class: "ss-sidebar-sections", style: { flex: "0 0 auto" } },
  8470. sectionPanels.flatMap((p, idx) => {
  8471. const panelContent =
  8472. p?.type === "report-table"
  8473. ? Vue.h(SsSidebarReportTableComp, {
  8474. key: `ss-sidebar-report-in-section-${idx}-${
  8475. p?.title ?? ""
  8476. }`,
  8477. title: p?.title ?? "",
  8478. icon: p?.icon ?? "",
  8479. iconClass: p?.iconClass ?? "",
  8480. items: p?.items || [],
  8481. onOpen: (srv, ctx) => p?.onOpen?.(srv, ctx),
  8482. })
  8483. : Vue.h(SsSidebarListComp, {
  8484. key: `ss-sidebar-list-${idx}-${p?.title ?? ""}`,
  8485. title: p?.title ?? "",
  8486. icon: p?.icon ?? "",
  8487. count: p?.count ?? p?.items?.length ?? "",
  8488. closable: !!p?.closable,
  8489. searchable: !!p?.searchable,
  8490. searchInHeader: !!p?.searchInHeader,
  8491. headerFilters: p?.headerFilters || [],
  8492. headerSearchButton: !!p?.headerSearchButton,
  8493. searchPlaceholder: p?.searchPlaceholder ?? "搜索",
  8494. itemLayout: p?.itemLayout ?? "simple",
  8495. itemAction: p?.itemAction ?? true,
  8496. collapsible: true,
  8497. collapsed: !!this.sectionCollapsed?.[idx],
  8498. onToggleCollapse: () =>
  8499. this.toggleSectionCollapse?.(idx),
  8500. iconClass: p?.iconClass ?? "",
  8501. items: p?.items || [],
  8502. mode: p?.mode || "search",
  8503. onSelect: (item) => this.$emit("select", item),
  8504. onRemove: (item) => this.$emit("remove", item),
  8505. onClear: () => p?.onClear?.(),
  8506. onSearch: (payload) => p?.onSearch?.(payload),
  8507. });
  8508. const section = Vue.h(
  8509. "div",
  8510. {
  8511. class: {
  8512. "ss-sidebar-section": true,
  8513. "is-collapsed": !!this.sectionCollapsed?.[idx],
  8514. },
  8515. key: `ss-sidebar-section-${idx}-${p?.type ?? "list"}-${
  8516. p?.title ?? ""
  8517. }`,
  8518. style: {
  8519. height: (this.sectionHeights[idx] ?? 190) + "px",
  8520. flex: "0 0 auto",
  8521. },
  8522. },
  8523. [
  8524. Vue.h("div", { class: "ss-sidebar-section__content" }, [
  8525. panelContent,
  8526. ]),
  8527. ]
  8528. );
  8529. const gap =
  8530. idx < sectionPanels.length - 1
  8531. ? Vue.h("div", {
  8532. class: "ss-sidebar-gap",
  8533. onPointerdown: (e) => this.startResize(idx, e),
  8534. })
  8535. : null;
  8536. return gap ? [section, gap] : [section];
  8537. })
  8538. ),
  8539. // 图表区固定在底部(hover 弹出大图) by xu 20260106
  8540. ...chartPanels.map((p, chartIdx) =>
  8541. Vue.h(
  8542. "div",
  8543. {
  8544. class: {
  8545. "ss-sidebar-panel": true,
  8546. "ss-sidebar-chart-panel": true,
  8547. "is-collapsed": !!this.chartCollapsed?.[chartIdx],
  8548. },
  8549. style: { flex: "0 0 auto", minHeight: "37px" },
  8550. "data-chart-idx": chartIdx,
  8551. key: `ss-sidebar-chart-${chartIdx}-${p?.title ?? ""}`,
  8552. },
  8553. [
  8554. p?.title
  8555. ? Vue.h(
  8556. "div",
  8557. {
  8558. class: "ss-sidebar-panel__header",
  8559. onDblclick: (e) => {
  8560. e?.preventDefault?.();
  8561. e?.stopPropagation?.();
  8562. console.log("[SsSidebar] chart header dblclick", {
  8563. idx: chartIdx,
  8564. title: p?.title,
  8565. });
  8566. this.toggleChartCollapse?.(chartIdx);
  8567. },
  8568. },
  8569. [
  8570. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  8571. p?.iconClass
  8572. ? Vue.h(SsIcon, {
  8573. class:
  8574. p.iconClass + " ss-sidebar-panel__icon",
  8575. })
  8576. : p?.icon
  8577. ? Vue.h(SsIcon, {
  8578. name: p.icon,
  8579. size: "16px",
  8580. class: "ss-sidebar-panel__icon",
  8581. })
  8582. : null,
  8583. Vue.h("span", null, p.title),
  8584. ]),
  8585. Vue.h("div", { class: "ss-sidebar-panel__tools" }),
  8586. ]
  8587. )
  8588. : null,
  8589. this.chartCollapsed?.[chartIdx]
  8590. ? null
  8591. : Vue.h(Vue.resolveComponent("ss-sidebar-chart-hover"), {
  8592. title: p?.title ?? "",
  8593. iconClass: p?.iconClass ?? "",
  8594. icon: p?.icon ?? "",
  8595. options: p?.options || {},
  8596. height: p?.height || "240px",
  8597. }),
  8598. ]
  8599. )
  8600. ),
  8601. ...reportPanels.map((p, reportIdx) =>
  8602. Vue.h(
  8603. "div",
  8604. {
  8605. class: {
  8606. "ss-sidebar-report-panel-wrap": true,
  8607. "ss-sidebar-report-panel": true,
  8608. "is-collapsed": !!this.reportCollapsed?.[reportIdx],
  8609. },
  8610. style: { flex: "0 0 auto", minHeight: "37px" },
  8611. "data-report-idx": reportIdx,
  8612. key: `ss-sidebar-report-wrap-${reportIdx}-${p?.title ?? ""}`,
  8613. },
  8614. [
  8615. Vue.h(SsSidebarReportTableComp, {
  8616. key: `ss-sidebar-report-${reportIdx}-${p?.title ?? ""}`,
  8617. title: p?.title ?? "",
  8618. icon: p?.icon ?? "",
  8619. iconClass: p?.iconClass ?? "",
  8620. items: p?.items || [],
  8621. collapsible: true,
  8622. collapsed: !!this.reportCollapsed?.[reportIdx],
  8623. onToggleCollapse: () =>
  8624. this.toggleReportCollapse?.(reportIdx),
  8625. onOpen: (srv, ctx) => p?.onOpen?.(srv, ctx),
  8626. }),
  8627. ]
  8628. )
  8629. ),
  8630. ].filter(Boolean)
  8631. ),
  8632. ]);
  8633. },
  8634. };
  8635. // ss-folder-card 文件夹卡片
  8636. const SsFolderCard = {
  8637. name: "SsFolderCard",
  8638. props: {
  8639. item: {
  8640. type: Object,
  8641. required: true,
  8642. },
  8643. },
  8644. data() {
  8645. return {
  8646. showButtons: false,
  8647. };
  8648. },
  8649. emits: ["click", "change"],
  8650. setup(props, { emit }) {
  8651. const item = props.item;
  8652. const showChildren = ref(false);
  8653. const eventBus = window.parent.sharedEventBus;
  8654. const itemWidth = Vue.computed(() => {
  8655. // 功能说明:页面改为 grid 等分布局后,卡片宽度交给容器控制,这里固定 100% by xu 20260116
  8656. return "100%";
  8657. });
  8658. onMounted(() => {
  8659. eventBus.subscribe("folderPath", (path) => {
  8660. const currentPath = path || [];
  8661. // 如果当前文件夹不在路径中,则销毁视图
  8662. if (
  8663. !currentPath.some((item) => item.folder.title === props.item.title)
  8664. ) {
  8665. showChildren.value = false;
  8666. }
  8667. });
  8668. });
  8669. const onItemClick = (e) => {
  8670. if (e && e.stopPropagation) {
  8671. e.stopPropagation();
  8672. }
  8673. // 单击只处理 active 状态
  8674. if (e && e.currentTarget) {
  8675. const allListCards = document.querySelectorAll(
  8676. ".knowledge-item-container"
  8677. );
  8678. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8679. allListCards.forEach((card) => card.classList.remove("active"));
  8680. allFolderCards.forEach((card) => card.classList.remove("active"));
  8681. e.currentTarget.classList.add("active");
  8682. } else {
  8683. // 如果是数据对象,需要找到对应的 DOM 元素
  8684. const allListCards = document.querySelectorAll(
  8685. ".knowledge-item-container"
  8686. );
  8687. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8688. allListCards.forEach((card) => card.classList.remove("active"));
  8689. allFolderCards.forEach((card) => card.classList.remove("active"));
  8690. // 找到标题匹配的文件夹元素
  8691. const targetFolder = Array.from(allFolderCards).find((card) =>
  8692. card.textContent.includes(e.title)
  8693. );
  8694. if (targetFolder) {
  8695. targetFolder.classList.add("active");
  8696. }
  8697. }
  8698. emit("click", item);
  8699. };
  8700. // 修改双击处理函数
  8701. const handleFolderDblClick = (folder, e) => {
  8702. if (e) e.stopPropagation();
  8703. if (folder.children?.length) {
  8704. showChildren.value = true;
  8705. const pathInfo = {
  8706. title: folder.title,
  8707. folder: folder,
  8708. };
  8709. const currentPath = eventBus.getState("folderPath") || [];
  8710. if (!currentPath.some((item) => item.title === folder.title)) {
  8711. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  8712. }
  8713. }
  8714. };
  8715. const onItemChange = (e, icon, index) => {
  8716. e.stopPropagation();
  8717. props.item.buttons[0].onclick();
  8718. // emit("change", { item: props.item, icon, index });
  8719. };
  8720. return {
  8721. item,
  8722. itemWidth,
  8723. showChildren,
  8724. onItemClick,
  8725. onItemChange,
  8726. handleFolderDblClick,
  8727. };
  8728. },
  8729. render() {
  8730. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  8731. if (this.showChildren) {
  8732. return h(SsFolderCartView, {
  8733. folder: this.item,
  8734. });
  8735. }
  8736. return Vue.h(
  8737. "div",
  8738. {
  8739. class: { "ss-folder-list": true, active: this.item.active },
  8740. onClick: (e) => {
  8741. e.stopPropagation();
  8742. this.onItemClick(e);
  8743. },
  8744. onDblclick: (e) => this.handleFolderDblClick(this.item, e),
  8745. style: { width: this.itemWidth },
  8746. },
  8747. [
  8748. // 文件夹特有的装饰元素
  8749. Vue.h("div", { class: "ss-folder-list-trapezoid" }),
  8750. Vue.h("div", { class: "ss-folder-list-top-transparent" }),
  8751. Vue.h("div", { class: "ss-folder-list-top" }),
  8752. Vue.h("div", { class: "ss-folder-list-right" }),
  8753. // header 部分(按钮)
  8754. this.item?.buttons?.length > 0 &&
  8755. Vue.h(
  8756. "div",
  8757. {
  8758. class: "header",
  8759. onMouseenter: () => (this.showButtons = true),
  8760. onMouseleave: () => (this.showButtons = false),
  8761. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  8762. },
  8763. [
  8764. // this.item?.buttons?.length > 0 &&
  8765. Vue.h("div", {
  8766. class: "cart-list-setting cart-list-icon",
  8767. title: this.item?.buttons?.[0]?.title,
  8768. }),
  8769. // this.item?.buttons?.length > 0 &&
  8770. this.showButtons &&
  8771. this.item?.buttons?.length > 1 &&
  8772. Vue.h(
  8773. "div",
  8774. {
  8775. class: "cart-list-button-popup",
  8776. },
  8777. this.item.buttons.map((btn) =>
  8778. Vue.h(
  8779. "div",
  8780. {
  8781. onClick: (e) => {
  8782. e.stopPropagation();
  8783. btn.onclick?.();
  8784. },
  8785. },
  8786. [
  8787. btn.class &&
  8788. Vue.h(SsCartListIcon, {
  8789. class: [btn.class],
  8790. }),
  8791. Vue.h("span", null, btn.title),
  8792. ]
  8793. )
  8794. )
  8795. ),
  8796. ]
  8797. ),
  8798. // body 部分
  8799. Vue.h("div", { class: "body" }, [
  8800. Vue.h("div", { class: "box-header" }, [
  8801. Vue.h("div", null, this.item.title),
  8802. ]),
  8803. Vue.h(
  8804. "div",
  8805. {
  8806. class: !this.item.thumb ? "no-thumb box-body" : "box-body",
  8807. },
  8808. [
  8809. this.item.thumb
  8810. ? Vue.h("div", { class: "left" }, [
  8811. Vue.h("img", {
  8812. src: this.item.thumb,
  8813. alt: "Thumbnail",
  8814. class: "imgUnHandle",
  8815. style: {
  8816. "object-fit": "cover",
  8817. width: "100%",
  8818. height: "100%",
  8819. },
  8820. }),
  8821. ])
  8822. : null,
  8823. Vue.h("div", { class: "right" }, [
  8824. ...this.item.tags.map((tag) => {
  8825. const [key, value] = Object.entries(tag)[0];
  8826. return Vue.h(
  8827. "div",
  8828. {
  8829. class: "title",
  8830. title: `${key}: ${value}`,
  8831. },
  8832. `${key}: ${value}`
  8833. );
  8834. }),
  8835. ]),
  8836. ]
  8837. ),
  8838. ]),
  8839. ]
  8840. );
  8841. },
  8842. };
  8843. // SsFolderCartView 组件 - 用于显示文件夹内容
  8844. const SsFolderCartView = {
  8845. name: "SsFolderCartView",
  8846. props: {
  8847. folder: {
  8848. type: Object,
  8849. required: true,
  8850. },
  8851. },
  8852. emits: ["click"],
  8853. setup(props, { emit }) {
  8854. const eventBus = window.parent.sharedEventBus;
  8855. const currentFolder = ref(props.folder);
  8856. const showChildren = ref(false);
  8857. const onItemClick = (e) => {
  8858. if (e && e.stopPropagation) {
  8859. e.stopPropagation();
  8860. }
  8861. // 单击只处理 active 状态
  8862. if (e && e.currentTarget) {
  8863. const allListCards = document.querySelectorAll(
  8864. ".knowledge-item-container"
  8865. );
  8866. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8867. allListCards.forEach((card) => card.classList.remove("active"));
  8868. allFolderCards.forEach((card) => card.classList.remove("active"));
  8869. e.currentTarget.classList.add("active");
  8870. } else {
  8871. // 如果是数据对象,需要找到对应的 DOM 元素
  8872. const allListCards = document.querySelectorAll(
  8873. ".knowledge-item-container"
  8874. );
  8875. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8876. allListCards.forEach((card) => card.classList.remove("active"));
  8877. allFolderCards.forEach((card) => card.classList.remove("active"));
  8878. // 找到标题匹配的文件夹元素
  8879. const targetFolder = Array.from(allFolderCards).find((card) =>
  8880. card.textContent.includes(e.title)
  8881. );
  8882. if (targetFolder) {
  8883. targetFolder.classList.add("active");
  8884. }
  8885. }
  8886. emit("click", props.folder);
  8887. };
  8888. const handleFolderDblClick = (folder, e) => {
  8889. if (e) e.stopPropagation();
  8890. if (folder.children?.length) {
  8891. showChildren.value = true;
  8892. const pathInfo = {
  8893. title: folder.title,
  8894. folder: folder,
  8895. };
  8896. const currentPath = eventBus.getState("folderPath") || [];
  8897. if (!currentPath.some((item) => item.title === folder.title)) {
  8898. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  8899. currentFolder.value = folder;
  8900. }
  8901. }
  8902. };
  8903. const goBack = (targetFolder) => {
  8904. if (targetFolder === null) {
  8905. // 返回根目录
  8906. eventBus.publish("folderPath", []);
  8907. } else {
  8908. currentFolder.value = targetFolder;
  8909. }
  8910. };
  8911. return {
  8912. currentFolder,
  8913. showChildren,
  8914. onItemClick,
  8915. handleFolderDblClick,
  8916. goBack,
  8917. };
  8918. },
  8919. render() {
  8920. return h(
  8921. "div",
  8922. {
  8923. class: "page-container",
  8924. style: {
  8925. position: "fixed",
  8926. top: 0,
  8927. left: 0,
  8928. width: "100%",
  8929. height: "100%",
  8930. background: "var(--lightgray)",
  8931. padding: "20px 0",
  8932. zIndex: 1000,
  8933. },
  8934. },
  8935. [
  8936. // 搜索栏
  8937. h("div", { class: "search-bar" }, [
  8938. h("div", { class: "search-bar-contaienr" }, [
  8939. h(SsBreadcrumb, {
  8940. level: {
  8941. onBack: this.goBack,
  8942. },
  8943. }),
  8944. ]),
  8945. ]),
  8946. // 内容区域
  8947. h(
  8948. "div",
  8949. {
  8950. class: "content-area item-content-area",
  8951. style: { gap: "20px" },
  8952. },
  8953. [
  8954. ...(this.currentFolder.children || []).map((child, index) =>
  8955. h(child.children ? SsFolderCard : SsListCard, {
  8956. key: index,
  8957. item: child,
  8958. onClick: (e) => this.onItemClick(e),
  8959. onDblclick: (e) => this.handleFolderDblClick(child, e),
  8960. })
  8961. ),
  8962. ]
  8963. ),
  8964. ]
  8965. );
  8966. },
  8967. };
  8968. // ss-page分页
  8969. const SsPage = {
  8970. name: "SsPage",
  8971. props: {
  8972. total: {
  8973. type: Number,
  8974. required: true,
  8975. },
  8976. size: {
  8977. type: Number,
  8978. default: 10,
  8979. },
  8980. page: {
  8981. type: Number,
  8982. default: 1,
  8983. },
  8984. onChange: {
  8985. type: Function,
  8986. default: () => {},
  8987. },
  8988. },
  8989. setup(props) {
  8990. const totalItems = ref(props.total); // 总条目数
  8991. const totalPages = ref(Math.ceil(props.total / props.size));
  8992. const currentPage = ref(props.page); // 当前页码
  8993. // 计算显示的信息
  8994. const pageInfo = ref(
  8995. `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`
  8996. );
  8997. // 上一页的逻辑
  8998. const goToPreviousPage = (e) => {
  8999. e.preventDefault(); // 阻止默认行为
  9000. if (currentPage.value > 1) {
  9001. currentPage.value -= 1;
  9002. updatePageInfo();
  9003. props.onChange?.({
  9004. pageNo: currentPage.value, // 当前页码
  9005. rowNumPer: props.size, // 每页条数
  9006. rowNum: props.total, // 总记录数
  9007. });
  9008. }
  9009. };
  9010. // 下一页的逻辑
  9011. const goToNextPage = (e) => {
  9012. e.preventDefault(); // 阻止默认行为
  9013. if (currentPage.value < totalPages.value) {
  9014. currentPage.value += 1;
  9015. updatePageInfo();
  9016. props.onChange?.({
  9017. pageNo: currentPage.value, // 当前页码
  9018. rowNumPer: props.size, // 每页条数
  9019. rowNum: props.total, // 总记录数
  9020. });
  9021. }
  9022. };
  9023. // 更新页码信息的函数
  9024. const updatePageInfo = () => {
  9025. pageInfo.value = `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`;
  9026. };
  9027. return {
  9028. pageInfo,
  9029. totalPages,
  9030. goToPreviousPage,
  9031. goToNextPage,
  9032. };
  9033. },
  9034. render(props, { slots, emit }) {
  9035. return Vue.h("div", { class: "pager-container" }, [
  9036. Vue.h("input", { type: "hidden", name: "rowNum", value: props.total }),
  9037. Vue.h("input", {
  9038. type: "hidden",
  9039. name: "rowNumPer",
  9040. value: props.size,
  9041. }),
  9042. Vue.h("input", {
  9043. type: "hidden",
  9044. name: "pageCount",
  9045. value: this.totalPages,
  9046. }),
  9047. Vue.h("input", { type: "hidden", name: "pageNo", value: props.page }),
  9048. Vue.h("div", { class: "pager-content" }, [
  9049. Vue.h("div", { class: "info" }, this.pageInfo),
  9050. Vue.h(
  9051. "div",
  9052. { class: "btn" },
  9053. Vue.h(
  9054. "button",
  9055. { onClick: (e) => this.goToPreviousPage(e) },
  9056. "上一页"
  9057. )
  9058. ),
  9059. Vue.h(
  9060. "div",
  9061. { class: "btn" },
  9062. Vue.h("button", { onClick: (e) => this.goToNextPage(e) }, "下一页")
  9063. ),
  9064. ]),
  9065. ]);
  9066. },
  9067. };
  9068. // ss-right-info 一级页面右边栏
  9069. const SSRightInfo = {
  9070. name: "SSRightInfo",
  9071. setup() {
  9072. // 初始化响应式数据
  9073. const item = ref({
  9074. thumb: "images/example/project-img.png", // 更换为适合你项目的实际路径
  9075. title: "工业和信息化产业高质量发展资金",
  9076. });
  9077. return {
  9078. item,
  9079. };
  9080. },
  9081. render() {
  9082. return Vue.h("div", { class: "info-container" }, [
  9083. Vue.h("div", { class: "header" }, [
  9084. Vue.h("div", [
  9085. Vue.h("img", {
  9086. src: this.item.thumb,
  9087. class: "imgUnHandle",
  9088. style: { "object-fit": "cover", width: "100%", height: "100%" },
  9089. }), // 将 ImageViewer 替换为 img 标签
  9090. ]),
  9091. Vue.h("div", [Vue.h("div", this.item.title)]),
  9092. ]),
  9093. Vue.h("div", { class: "section-container" }, [
  9094. Vue.h("div", { class: "section" }, [
  9095. Vue.h("div", { class: "title" }, "合同"),
  9096. Vue.h("div", { class: "text" }, "合同总金额:42,399,320"),
  9097. Vue.h(
  9098. "div",
  9099. { class: "a" },
  9100. "《工业和信息化产业高质量发展资金补助合同》"
  9101. ),
  9102. ]),
  9103. Vue.h("div", { class: "section" }, [
  9104. Vue.h("div", { class: "title" }, "发票"),
  9105. Vue.h("div", { class: "text" }, "应开发票总额:42,399,320"),
  9106. Vue.h("div", { class: "text" }, "已开发票金额:17,235,345"),
  9107. Vue.h("div", { class: "text" }, "未开发票金额:25,163,975"),
  9108. ]),
  9109. Vue.h("div", { class: "section" }, [
  9110. Vue.h("div", { class: "title" }, "项目组成员"),
  9111. Vue.h("div", { class: "text" }, "我司:3人"),
  9112. Vue.h("div", { class: "text" }, "对方:2人"),
  9113. Vue.h("div", { class: "text" }, "项目负责人:张三"),
  9114. ]),
  9115. Vue.h("div", { class: "section" }, [
  9116. Vue.h("div", { class: "title" }, "采购"),
  9117. Vue.h("div", { class: "text" }, "总额:999,320"),
  9118. Vue.h("div", { class: "text" }, "已付金额:335,345"),
  9119. Vue.h("div", { class: "text" }, "未付金额:663,975"),
  9120. ]),
  9121. ]),
  9122. ]);
  9123. },
  9124. };
  9125. //
  9126. const SsSuccessPopup = {
  9127. name: "SsSuccessPopup",
  9128. props: {
  9129. right: {
  9130. type: String,
  9131. default: "20px",
  9132. },
  9133. bottom: {
  9134. type: String,
  9135. default: "calc(100% + 5px)",
  9136. },
  9137. },
  9138. setup(props, { expose }) {
  9139. // 响应式状态:是否可见
  9140. const visible = ref(false);
  9141. // 计算样式
  9142. const style = computed(() => {
  9143. return {
  9144. "--message-dialog-right": props.right,
  9145. "--message-dialog-bottom": props.bottom,
  9146. };
  9147. });
  9148. // 显示对话框的方法
  9149. const show = () => {
  9150. visible.value = true;
  9151. };
  9152. // 隐藏对话框的方法
  9153. const hide = () => {
  9154. visible.value = false;
  9155. };
  9156. // 将方法暴露给外部使用
  9157. expose({ show, hide });
  9158. // 返回渲染函数
  9159. return () => {
  9160. if (!visible.value) return null;
  9161. const SsIcon = resolveComponent("ss-icon");
  9162. return h(
  9163. "div",
  9164. {
  9165. class: "success-popup",
  9166. style: style.value,
  9167. onClick: (e) => e.stopPropagation(),
  9168. },
  9169. [
  9170. h("div", { class: "left" }, [
  9171. h("div", { class: "icon" }, [
  9172. h(SsIcon, { name: "check", size: "36px" }),
  9173. ]),
  9174. ]),
  9175. h("div", { class: "right" }, [
  9176. h("div", { class: "title" }, "提交成功"),
  9177. h("div", { class: "desc" }, "您的信息已成功提交。"),
  9178. ]),
  9179. ]
  9180. );
  9181. };
  9182. },
  9183. };
  9184. const SsErrorDialog = {
  9185. name: "SsErrorDialog",
  9186. setup(props, { emit }) {
  9187. const visible = ref(false);
  9188. const style = computed(() => {
  9189. return {};
  9190. });
  9191. const show = () => {
  9192. visible.value = true;
  9193. };
  9194. const hide = () => {
  9195. visible.value = false;
  9196. };
  9197. const onBack = () => {
  9198. emit("back");
  9199. hide();
  9200. };
  9201. return {
  9202. visible,
  9203. style,
  9204. show,
  9205. hide,
  9206. onBack,
  9207. };
  9208. },
  9209. render() {
  9210. const SsIcon = resolveComponent("ss-icon");
  9211. return this.visible
  9212. ? h(
  9213. "div",
  9214. {
  9215. class: "errorDialog",
  9216. style: this.style,
  9217. onClick: (event) => event.stopPropagation(),
  9218. },
  9219. [
  9220. h("div", { class: "body" }, [
  9221. h("div", { class: "left" }, [
  9222. h("div", { class: "icon" }, [
  9223. h(SsIcon, { name: "close", size: "36px" }),
  9224. ]),
  9225. ]),
  9226. h("div", { class: "right" }, [
  9227. h("div", { class: "title" }, "操作失败"),
  9228. h("div", { class: "desc" }, "请点击返回以继续。"),
  9229. ]),
  9230. ]),
  9231. h("div", { class: "footer" }, [
  9232. h("div", { class: "left" }),
  9233. h("div", { class: "right" }, [
  9234. h(
  9235. "div",
  9236. {
  9237. class: "btn",
  9238. onClick: this.onBack,
  9239. },
  9240. [h(SsIcon, { name: "arrow-left-line" }), h("div", "返回")]
  9241. ),
  9242. ]),
  9243. ]),
  9244. ]
  9245. )
  9246. : null;
  9247. },
  9248. };
  9249. /**
  9250. * 审核链条
  9251. * @name ss-verify
  9252. * @param { Array } verify-list 审核节点列表
  9253. * @property { Array } verify-list 审核节点列表
  9254. * @example <ss-verify :verify-list="verifyList"></ss-verify>
  9255. * verify-list [
  9256. * {
  9257. * groupName: "", // 群组名称
  9258. * open: true, // 默认是否展开
  9259. * children:[ //群组里的人员
  9260. * {
  9261. * thumb: "images/example/user-4.png", // 头像
  9262. * name: "李丽思 ", // 姓名
  9263. * role: "人事处处长", // 角色
  9264. * description: "同意。", // 审核意见
  9265. * time: "09:38 08/11", // 审核时间
  9266. * video: false, // false不显示/true显示 视频icon
  9267. * link: false, // false不显示/true显示 链接icon 后续应该是附件
  9268. * }
  9269. * ]
  9270. * }
  9271. * ]
  9272. */
  9273. const SsVerify = {
  9274. name: "SsVerify",
  9275. props: {
  9276. verifyList: {
  9277. type: Array,
  9278. required: true,
  9279. },
  9280. },
  9281. setup(props) {
  9282. const toggleOpen = (item) => {
  9283. item.open = !item.open;
  9284. };
  9285. onMounted(() => {
  9286. setTimeout(() => {
  9287. const lastOpenGroup = document.querySelector(".group-item-last-open");
  9288. console.log("lastOpenGroup", lastOpenGroup);
  9289. if (lastOpenGroup) {
  9290. const nodes = $(lastOpenGroup).find(".verify-node-container");
  9291. if (nodes.length) {
  9292. let totalHeight = 0;
  9293. const gudingHeight = 100;
  9294. if (nodes.length === 1) {
  9295. totalHeight = gudingHeight;
  9296. } else {
  9297. // 累加除最后一个节点外的所有节点高度
  9298. for (let i = 0; i < nodes.length - 1; i++) {
  9299. totalHeight += $(nodes[i]).outerHeight();
  9300. }
  9301. totalHeight += gudingHeight;
  9302. }
  9303. console.log("节点信息:", {
  9304. 节点总数: nodes.length,
  9305. 计算后的高度: totalHeight,
  9306. });
  9307. lastOpenGroup.style.setProperty(
  9308. "--group-line-height",
  9309. `${totalHeight}px`
  9310. );
  9311. }
  9312. }
  9313. }, 0);
  9314. });
  9315. return {
  9316. toggleOpen,
  9317. };
  9318. },
  9319. render() {
  9320. const SsIcon = resolveComponent("ss-icon");
  9321. const SsCommonIcon = resolveComponent("ss-common-icon");
  9322. const SsVerifyNode = resolveComponent("ss-verify-node");
  9323. return h(
  9324. "div",
  9325. { class: "verify-nodes" },
  9326. this.verifyList.map((item, i) =>
  9327. h(
  9328. "div",
  9329. {
  9330. key: i,
  9331. class: {
  9332. "group-item": true,
  9333. "group-item-last-open":
  9334. i === this.verifyList.length - 1 && item.open,
  9335. },
  9336. },
  9337. [
  9338. h(
  9339. "div",
  9340. {
  9341. class: "group-item-title",
  9342. onClick: () => this.toggleOpen(item),
  9343. },
  9344. [
  9345. h("div", { class: "icon" }, [
  9346. item.open
  9347. ? h(SsCommonIcon, { class: "common-icon-folder-open" })
  9348. : h(SsCommonIcon, { class: "common-icon-folder-close" }),
  9349. h(
  9350. "div",
  9351. {
  9352. class: "num",
  9353. style: { top: item.open ? "60%" : "55%" },
  9354. },
  9355. item.children?.length || 0
  9356. ),
  9357. ]),
  9358. h("div", { class: "name" }, item.groupName),
  9359. ]
  9360. ),
  9361. item.open && item.children?.length > 0
  9362. ? h(
  9363. "div",
  9364. { class: "group-item-children" },
  9365. item.children.map((citem, j) =>
  9366. h(SsVerifyNode, {
  9367. key: j,
  9368. item: citem,
  9369. // isGroup: i + 1 !== this.verifyList.length,
  9370. isGroup: true,
  9371. })
  9372. )
  9373. )
  9374. : null,
  9375. ]
  9376. )
  9377. )
  9378. );
  9379. },
  9380. };
  9381. /**
  9382. * 审核页面的审核节点
  9383. * @name ss-verify-node
  9384. * @param {Object} item 审核节点信息
  9385. * @param {Boolean} isGroup 是否为分组节点
  9386. */
  9387. const SsVerifyNode = {
  9388. name: "SsVerifyNode",
  9389. props: {
  9390. item: {
  9391. type: Object,
  9392. required: true,
  9393. },
  9394. isGroup: {
  9395. type: Boolean,
  9396. default: false,
  9397. },
  9398. },
  9399. render() {
  9400. const SsIcon = resolveComponent("ss-icon");
  9401. const SsCommonIcon = resolveComponent("ss-common-icon");
  9402. return Vue.h("div", { class: "verify-node-container" }, [
  9403. Vue.h("div", { class: "info" }, [
  9404. Vue.h("div", { class: "avatar" }, [
  9405. Vue.h("img", {
  9406. src: this.item.thumb,
  9407. style: {
  9408. width: "50px",
  9409. height: "50px",
  9410. borderRadius: "50%",
  9411. },
  9412. }),
  9413. ]),
  9414. Vue.h("div", { class: "desc" }, [
  9415. Vue.h("div", this.item.name),
  9416. Vue.h("div", this.item.role),
  9417. ]),
  9418. Vue.h("div", { class: "link" }, [
  9419. Vue.h("div", [
  9420. this.item.video
  9421. ? Vue.h(SsCommonIcon, { class: "common-icon-video" })
  9422. : null,
  9423. this.item.link
  9424. ? Vue.h(SsCommonIcon, {
  9425. class: "common-icon-paper-clip",
  9426. })
  9427. : null,
  9428. ]),
  9429. ]),
  9430. ]),
  9431. Vue.h(
  9432. "div",
  9433. {
  9434. class: {
  9435. description: true,
  9436. link: this.isGroup,
  9437. },
  9438. attrs: { "data-num": "3" },
  9439. },
  9440. [Vue.h("div", this.item.description)]
  9441. ),
  9442. Vue.h("div", { class: "time" }, this.item.time),
  9443. ]);
  9444. },
  9445. };
  9446. /**
  9447. * 智能识别图片的左侧图片播放 可以放大缩小旋转图片
  9448. * @name ss-orc-img-box
  9449. * @param { Object } image-obj 包含图片的url, 和图片的名称
  9450. *
  9451. */
  9452. const SsOrcImgBox = {
  9453. name: "SsOrcImgBox",
  9454. props: {
  9455. imageObj: {
  9456. type: Object,
  9457. required: true,
  9458. },
  9459. },
  9460. setup(props) {
  9461. const zoom = ref(1);
  9462. const rotation = ref(0);
  9463. const containerWidth = ref(0);
  9464. const containerHeight = ref(0);
  9465. const container = ref(null);
  9466. const imgPosition = ref({ x: 0, y: 0 });
  9467. const isDragging = ref(false);
  9468. const lastMousePosition = ref({ x: 0, y: 0 });
  9469. const imgStyle = computed(() => ({
  9470. width: `${zoom.value * 100}%`,
  9471. height: `${zoom.value * 100}%`,
  9472. transform: `rotate(${rotation.value}deg) translate(${imgPosition.value.x}px, ${imgPosition.value.y}px)`,
  9473. transformOrigin: "center center",
  9474. cursor: isDragging.value ? "grabbing" : "grab",
  9475. }));
  9476. const resetZoom = () => {
  9477. zoom.value = 1;
  9478. rotation.value = rotation.value + 90;
  9479. imgPosition.value = { x: 0, y: 0 };
  9480. };
  9481. const handleRangeChange = (event) => {
  9482. const value = event.target.value / 50; // 0 到 100 映射到 0 到 2 的缩放
  9483. zoom.value = Math.max(value, 0.1); // 设置最小缩放值为 0.1
  9484. };
  9485. const updateImgBoxDimensions = () => {
  9486. if (container.value) {
  9487. containerWidth.value = container.value.clientWidth;
  9488. containerHeight.value = container.value.clientHeight;
  9489. }
  9490. };
  9491. const onMouseDown = (event) => {
  9492. isDragging.value = true;
  9493. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  9494. };
  9495. const onMouseMove = (event) => {
  9496. if (isDragging.value) {
  9497. const dx = event.clientX - lastMousePosition.value.x;
  9498. const dy = event.clientY - lastMousePosition.value.y;
  9499. // 防止旋转后拖动的x,y反转
  9500. // 首先将当前旋转角度从度数转换为弧度,因为 JavaScript 的 Math 库使用弧度
  9501. const angle = rotation.value * (Math.PI / 180);
  9502. // 使用基本的二维旋转矩阵将原始位移 dx 和 dy 转换为旋转后的位移 rotatedDx 和 rotatedDy。
  9503. const rotatedDx = dx * Math.cos(angle) + dy * Math.sin(angle);
  9504. const rotatedDy = dy * Math.cos(angle) - dx * Math.sin(angle);
  9505. imgPosition.value = {
  9506. x: imgPosition.value.x + rotatedDx,
  9507. y: imgPosition.value.y + rotatedDy,
  9508. };
  9509. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  9510. }
  9511. };
  9512. const onMouseUp = () => {
  9513. isDragging.value = false;
  9514. };
  9515. onMounted(() => {
  9516. nextTick(() => {
  9517. updateImgBoxDimensions();
  9518. window.addEventListener("resize", updateImgBoxDimensions);
  9519. window.addEventListener("mousemove", onMouseMove);
  9520. window.addEventListener("mouseup", onMouseUp);
  9521. });
  9522. });
  9523. return {
  9524. zoom,
  9525. rotation,
  9526. container,
  9527. imgStyle,
  9528. resetZoom,
  9529. handleRangeChange,
  9530. containerWidth,
  9531. containerHeight,
  9532. onMouseDown,
  9533. imgPosition,
  9534. };
  9535. },
  9536. render() {
  9537. const SsIcon = resolveComponent("ss-icon");
  9538. return h("div", { class: "ocr-img-box" }, [
  9539. h("div", { class: "img-bar" }, [
  9540. h("div", this.imageObj.name),
  9541. h("div", { class: "action-bar" }, [
  9542. h("div", { class: "ocr-img-range-box" }, [
  9543. h("input", {
  9544. type: "range",
  9545. min: 0,
  9546. max: 100,
  9547. value: this.zoom * 50, // 初始位置为50
  9548. onInput: this.handleRangeChange,
  9549. }),
  9550. h("span", { class: "line" }),
  9551. ]),
  9552. h(SsIcon, {
  9553. name: "reset",
  9554. size: "26px",
  9555. onClick: this.resetZoom,
  9556. }),
  9557. ]),
  9558. ]),
  9559. h("div", { class: "img-viewer", ref: "container" }, [
  9560. h(
  9561. "div",
  9562. {
  9563. class: "img-box",
  9564. style: {
  9565. width: `${this.containerWidth}px`,
  9566. height: `${this.containerHeight}px`,
  9567. overflow: "hidden",
  9568. position: "relative",
  9569. },
  9570. },
  9571. [
  9572. h("img", {
  9573. src: this.imageObj.thumb,
  9574. style: this.imgStyle,
  9575. class: "zoomable-img",
  9576. onMousedown: this.onMouseDown,
  9577. }),
  9578. ]
  9579. ),
  9580. ]),
  9581. ]);
  9582. },
  9583. };
  9584. // 搜索输入框组件
  9585. const SsSearchInput = {
  9586. name: "SsSearchInput",
  9587. props: {
  9588. name: String,
  9589. placeholder: String,
  9590. width: {
  9591. type: String,
  9592. default: "100px",
  9593. },
  9594. modelValue: String,
  9595. },
  9596. emits: ["update:modelValue", "search"],
  9597. setup(props, { emit }) {
  9598. const handleInput = (e) => {
  9599. emit("update:modelValue", e.target.value);
  9600. };
  9601. const handleKeyup = (e) => {
  9602. if (e.key === "Enter") {
  9603. emit("search");
  9604. }
  9605. };
  9606. return { handleInput, handleKeyup };
  9607. },
  9608. render() {
  9609. return h(
  9610. "div",
  9611. {
  9612. class: "input",
  9613. style: this.width ? { width: this.width } : undefined,
  9614. },
  9615. [
  9616. h("input", {
  9617. name: this.name,
  9618. placeholder: this.placeholder,
  9619. value: this.modelValue,
  9620. onInput: this.handleInput,
  9621. onKeyup: this.handleKeyup,
  9622. }),
  9623. ]
  9624. );
  9625. },
  9626. };
  9627. const SsNump = {
  9628. name: "SsNump",
  9629. props: {
  9630. onchange: {
  9631. type: String,
  9632. required: false,
  9633. },
  9634. name: String,
  9635. defVal: {
  9636. type: Number,
  9637. default: 0,
  9638. },
  9639. minVal: Number,
  9640. maxVal: Number,
  9641. tabIndex: {
  9642. type: Number,
  9643. default: -1,
  9644. },
  9645. desc: String,
  9646. width: {
  9647. type: String,
  9648. default: "60px",
  9649. },
  9650. modelValue: Number,
  9651. decWidth: {
  9652. type: String,
  9653. default: "45px",
  9654. },
  9655. incWidth: {
  9656. type: String,
  9657. default: "45px",
  9658. },
  9659. },
  9660. emits: ["update:modelValue", "update:inputValue"],
  9661. setup(props, { emit }) {
  9662. const inputValue = ref(props.defVal);
  9663. const callGlobalOnchg = (value) => {
  9664. if (
  9665. props.onchange &&
  9666. typeof props.onchange === "string" &&
  9667. typeof window !== "undefined" &&
  9668. typeof window[props.onchange] === "function"
  9669. ) {
  9670. try {
  9671. window[props.onchange](value);
  9672. } catch (error) {
  9673. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  9674. }
  9675. }
  9676. };
  9677. watch(
  9678. () => props.modelValue,
  9679. (newVal) => callGlobalOnchg(newVal)
  9680. );
  9681. watch(inputValue, (value) => callGlobalOnchg(value));
  9682. const refreshNump = () => {
  9683. const input = document.getElementsByName(props.name)[0];
  9684. if (input) {
  9685. input.value = inputValue.value;
  9686. }
  9687. const decEl = document.getElementById("dec" + props.name);
  9688. const incEl = document.getElementById("inc" + props.name);
  9689. if (!decEl || !incEl) {
  9690. return;
  9691. }
  9692. if (props.defVal > inputValue.value) {
  9693. decEl.innerText = "-" + (props.defVal - inputValue.value);
  9694. } else if (props.defVal < inputValue.value) {
  9695. incEl.innerText = "+" + (inputValue.value - props.defVal);
  9696. } else {
  9697. decEl.innerText = "-";
  9698. incEl.innerText = "+";
  9699. }
  9700. };
  9701. const setDefVal = (defVal) => {
  9702. inputValue.value = defVal;
  9703. refreshNump();
  9704. emit("update:modelValue", inputValue.value);
  9705. };
  9706. onMounted(() => {
  9707. window[props.name] = setDefVal;
  9708. inputValue.value = props.defVal;
  9709. refreshNump();
  9710. emit("update:modelValue", inputValue.value);
  9711. emit("update:inputValue", inputValue.value);
  9712. });
  9713. const onChange = (event) => {
  9714. let value = parseInt(event.target.value, 10) || 0;
  9715. if (props.maxVal && value > props.maxVal) {
  9716. value = props.maxVal;
  9717. }
  9718. if (props.minVal && value < props.minVal) {
  9719. value = props.minVal;
  9720. }
  9721. inputValue.value = value;
  9722. refreshNump();
  9723. emit("update:modelValue", inputValue.value);
  9724. };
  9725. const decClick = (event) => {
  9726. event.preventDefault();
  9727. if (!props.minVal || inputValue.value > props.minVal) {
  9728. inputValue.value -= 1;
  9729. }
  9730. refreshNump();
  9731. emit("update:modelValue", inputValue.value);
  9732. };
  9733. const incClick = (event) => {
  9734. event.preventDefault();
  9735. if (!props.maxVal || inputValue.value < props.maxVal) {
  9736. inputValue.value += 1;
  9737. }
  9738. refreshNump();
  9739. emit("update:modelValue", inputValue.value);
  9740. };
  9741. const handleKeyup = (event) => {
  9742. if (event.key === "Enter") {
  9743. event.preventDefault();
  9744. const nextFocus = document.querySelector(
  9745. `input[tabIndex="${event.target.tabIndex + 1}"]`
  9746. );
  9747. if (nextFocus) {
  9748. nextFocus.focus();
  9749. }
  9750. }
  9751. };
  9752. const handleKeydown = (event) => {
  9753. if (event.key === "Enter") {
  9754. event.preventDefault();
  9755. }
  9756. };
  9757. return {
  9758. inputValue,
  9759. setDefVal,
  9760. refreshNump,
  9761. onChange,
  9762. handleKeyup,
  9763. handleKeydown,
  9764. decClick,
  9765. incClick,
  9766. };
  9767. },
  9768. render() {
  9769. return h("div", { class: "nump-bar-container" }, [
  9770. this.desc &&
  9771. h(
  9772. "span",
  9773. { style: { paddingRight: "10px" } },
  9774. this.desc + (this.maxVal ? `(${this.maxVal})` : "")
  9775. ),
  9776. h(
  9777. "button",
  9778. {
  9779. class: "dec-button",
  9780. type: "button",
  9781. style: { width: this.decWidth },
  9782. onClick: this.decClick,
  9783. },
  9784. [h("span", { id: "dec" + this.name }, "-")]
  9785. ),
  9786. h("input", {
  9787. name: this.name,
  9788. maxVal: this.maxVal,
  9789. value: this.modelValue,
  9790. tabindex: this.tabIndex,
  9791. onInput: this.onChange,
  9792. onKeyup: this.handleKeyup,
  9793. onKeydown: this.handleKeydown,
  9794. style: { width: this.width },
  9795. }),
  9796. h(
  9797. "button",
  9798. {
  9799. class: "inc-button",
  9800. type: "button",
  9801. style: { width: this.incWidth },
  9802. onClick: this.incClick,
  9803. },
  9804. [h("span", { id: "inc" + this.name }, "+")]
  9805. ),
  9806. ]);
  9807. },
  9808. };
  9809. // ss-search-date-picker 日期时间选择器组件
  9810. const SsSearchDatePicker = {
  9811. name: "SsSearchDatePicker",
  9812. props: {
  9813. modelValue: {
  9814. type: [String, Number, Date],
  9815. default: "",
  9816. },
  9817. name: {
  9818. type: String,
  9819. required: true,
  9820. },
  9821. type: {
  9822. type: String,
  9823. default: "date",
  9824. validator: (value) => ["date", "datetime", "time"].includes(value),
  9825. },
  9826. fmt: {
  9827. type: String,
  9828. default: null,
  9829. },
  9830. placeholder: {
  9831. type: String,
  9832. default: "",
  9833. },
  9834. width: {
  9835. type: String,
  9836. default: "100%",
  9837. },
  9838. },
  9839. emits: ["update:modelValue"],
  9840. setup(props, { emit }) {
  9841. const errMsg = ref("");
  9842. const validate = () => {
  9843. if (window.ssVm) {
  9844. const result = window.ssVm.validateField(props.name);
  9845. console.log("validate", window.ssVm.validateField(props.name));
  9846. errMsg.value = result.valid ? "" : result.message;
  9847. }
  9848. };
  9849. // 根据type确定默认格式
  9850. const defaultFormat = computed(() => {
  9851. switch (props.type) {
  9852. case "datetime":
  9853. return "YYYY-MM-DD HH:mm:ss";
  9854. case "date":
  9855. return "YYYY-MM-DD";
  9856. case "time":
  9857. return "HH:mm:ss";
  9858. }
  9859. });
  9860. const convertJavaFormatToElement = (javaFormat) => {
  9861. if (!javaFormat) return null;
  9862. return javaFormat
  9863. .replace("yyyy", "YYYY")
  9864. .replace("MM", "MM")
  9865. .replace("dd", "DD")
  9866. .replace("HH", "HH")
  9867. .replace("mm", "mm")
  9868. .replace("ss", "ss");
  9869. };
  9870. const finalFormat = computed(() => {
  9871. if (props.fmt) {
  9872. return convertJavaFormatToElement(props.fmt);
  9873. }
  9874. return defaultFormat.value;
  9875. });
  9876. // 使用 resolveComponent 获取组件
  9877. const ElDatePicker = resolveComponent("ElDatePicker");
  9878. const ElTimePicker = resolveComponent("ElTimePicker");
  9879. const SsFormIcon = resolveComponent("SsFormIcon");
  9880. const ElIcon = resolveComponent("ElIcon");
  9881. let useTimePicker = true;
  9882. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  9883. if (props.fmt) {
  9884. //有fmt属性,则以fmt属性优先判断类型
  9885. if (/[dMy]/.test(props.fmt)) {
  9886. //如果有传入日期格式,且含年月日
  9887. useTimePicker = false;
  9888. } else {
  9889. useTimePicker = true;
  9890. }
  9891. } else if (props.type !== "time") {
  9892. useTimePicker = false;
  9893. }
  9894. const dateType = computed(() => {
  9895. const fmt = props.fmt || "";
  9896. if (fmt.includes("HH:mm:ss")) {
  9897. return "datetime";
  9898. } else if (fmt.includes("HH:mm")) {
  9899. return "datetime";
  9900. } else if (fmt.includes("mm:ss")) {
  9901. return "time";
  9902. }
  9903. return "date";
  9904. });
  9905. const handleValueUpdate = (val) => {
  9906. emit("update:modelValue", val);
  9907. emit("change", val); // 同时触发 change 事件
  9908. setTimeout(() => {
  9909. validate();
  9910. }, 50);
  9911. };
  9912. return () =>
  9913. h(
  9914. "div",
  9915. { class: "ss-search-date-picker", style: { width: props.width } },
  9916. [
  9917. h("input", {
  9918. type: "hidden",
  9919. name: props.name,
  9920. value: props.modelValue,
  9921. }),
  9922. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  9923. modelValue: props.modelValue,
  9924. "onUpdate:modelValue": handleValueUpdate,
  9925. type: dateType.value,
  9926. format: finalFormat.value,
  9927. "value-format": finalFormat.value,
  9928. clearable: true,
  9929. placeholder: props.placeholder,
  9930. class: "custom-date-picker", // 用于自定义样式
  9931. "time-arrow-control": props.type === "datetime", // 修改这里
  9932. size: "large", // 添加这一行,改为 large 尺寸
  9933. style: { width: "100%" },
  9934. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  9935. }),
  9936. ]
  9937. );
  9938. },
  9939. };
  9940. // 搜索按钮组件(包含下拉按钮)
  9941. const SsSearchButton = {
  9942. name: "SsSearchButton",
  9943. props: {
  9944. text: {
  9945. type: String,
  9946. required: true,
  9947. },
  9948. iconClass: {
  9949. type: String,
  9950. required: false,
  9951. },
  9952. opt: {
  9953. type: Array,
  9954. default: () => [],
  9955. },
  9956. checkId: {
  9957. type: String,
  9958. default: "0",
  9959. },
  9960. width: {
  9961. //add by Ben(20251225)
  9962. type: String,
  9963. required: false,
  9964. },
  9965. id: {
  9966. //add by Ben(20251225)
  9967. type: String,
  9968. required: false,
  9969. },
  9970. },
  9971. emits: ["click"],
  9972. setup(props, { emit }) {
  9973. const currentId = ref(props.checkId || "0");
  9974. const showPopup = ref(false);
  9975. const handleMouseEnter = () => {
  9976. showPopup.value = true;
  9977. };
  9978. const handleMouseLeave = () => {
  9979. showPopup.value = false;
  9980. };
  9981. // 添加点击事件处理,阻止默认行为
  9982. const handleClick = (e) => {
  9983. e.preventDefault();
  9984. if (props.opt?.length > 0) {
  9985. const selectedOption =
  9986. currentId.value === "0"
  9987. ? props.opt[0]
  9988. : props.opt.find((opt) => opt.id === currentId.value);
  9989. if (selectedOption) {
  9990. selectedOption.callback?.();
  9991. }
  9992. } else {
  9993. emit("click", e);
  9994. }
  9995. };
  9996. // 获取显示文本
  9997. const getDisplayText = () => {
  9998. if (!props.opt?.length) return props.text;
  9999. const selectedOption =
  10000. currentId.value === "0"
  10001. ? props.opt[0]
  10002. : props.opt.find((opt) => opt.id === currentId.value);
  10003. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  10004. };
  10005. return () =>
  10006. h(
  10007. "button",
  10008. {
  10009. class:
  10010. props.opt?.length > 0
  10011. ? "ss-drop-button ss-drop-button-more"
  10012. : "ss-drop-button",
  10013. type: "button", // 明确指定按钮类型为 button
  10014. onMouseenter: handleMouseEnter,
  10015. onMouseleave: handleMouseLeave,
  10016. onClick: handleClick, // 添加点击事件处理
  10017. style: { width: props.width }, //add by Ben(20251225)
  10018. id: props.id, //add by Ben(20251225)
  10019. },
  10020. [
  10021. props.iconClass
  10022. ? h("span", {
  10023. class: props.iconClass,
  10024. style: { fontFamily: "iconfont", marginRight: "5px" },
  10025. })
  10026. : null,
  10027. h("span", getDisplayText()),
  10028. props.opt.length > 0 &&
  10029. showPopup.value &&
  10030. h(
  10031. "div",
  10032. {
  10033. class: "popup",
  10034. },
  10035. props.opt.map((item) =>
  10036. h(
  10037. "div",
  10038. {
  10039. onClick: (e) => {
  10040. e.preventDefault(); // 选项点击也阻止默认行为
  10041. e.stopPropagation(); // 阻止事件冒泡
  10042. currentId.value = item.id; // 更新当前选中的ID
  10043. item.callback();
  10044. showPopup.value = false; // 选择后关闭弹窗
  10045. },
  10046. },
  10047. item.desc
  10048. )
  10049. )
  10050. ),
  10051. ]
  10052. );
  10053. },
  10054. };
  10055. // 下拉按钮组件
  10056. const SsDropButton = {
  10057. name: "SsDropButton",
  10058. props: {
  10059. text: {
  10060. type: String,
  10061. required: true,
  10062. },
  10063. iconClass: {
  10064. type: String,
  10065. required: true,
  10066. },
  10067. opt: {
  10068. type: Array,
  10069. default: () => [],
  10070. },
  10071. checkId: {
  10072. type: String,
  10073. default: "0",
  10074. },
  10075. onclick: {
  10076. type: Function,
  10077. default: null,
  10078. },
  10079. },
  10080. setup(props) {
  10081. const currentId = ref(props.checkId || "0");
  10082. const showPopup = ref(false);
  10083. const handleMouseEnter = () => {
  10084. showPopup.value = true;
  10085. };
  10086. const handleMouseLeave = () => {
  10087. showPopup.value = false;
  10088. };
  10089. // 添加点击事件处理,阻止默认行为
  10090. const handleClick = (e) => {
  10091. e.preventDefault();
  10092. if (props.opt?.length > 0) {
  10093. const selectedOption =
  10094. currentId.value === "0"
  10095. ? props.opt[0]
  10096. : props.opt.find((opt) => opt.id === currentId.value);
  10097. if (selectedOption) {
  10098. selectedOption.callback?.();
  10099. }
  10100. } else if (props.onclick) {
  10101. props.onclick();
  10102. }
  10103. };
  10104. // 获取显示文本
  10105. const getDisplayText = () => {
  10106. if (!props.opt?.length) return props.text;
  10107. const selectedOption =
  10108. currentId.value === "0"
  10109. ? props.opt[0]
  10110. : props.opt.find((opt) => opt.id === currentId.value);
  10111. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  10112. };
  10113. return () =>
  10114. h(
  10115. "button",
  10116. {
  10117. class:
  10118. props.opt?.length > 0
  10119. ? "ss-drop-button ss-drop-button-more"
  10120. : "ss-drop-button",
  10121. type: "button", // 明确指定按钮类型为 button
  10122. onMouseenter: handleMouseEnter,
  10123. onMouseleave: handleMouseLeave,
  10124. onClick: handleClick, // 添加点击事件处理
  10125. },
  10126. [
  10127. h("span", {
  10128. class: props.iconClass,
  10129. style: { fontFamily: "iconfont" },
  10130. }),
  10131. h("span", getDisplayText()),
  10132. props.opt.length > 0 &&
  10133. showPopup.value &&
  10134. h(
  10135. "div",
  10136. {
  10137. class: "popup",
  10138. },
  10139. props.opt.map((item) =>
  10140. h(
  10141. "div",
  10142. {
  10143. onClick: (e) => {
  10144. e.preventDefault(); // 选项点击也阻止默认行为
  10145. e.stopPropagation(); // 阻止事件冒泡
  10146. currentId.value = item.id; // 更新当前选中的ID
  10147. item.callback();
  10148. showPopup.value = false; // 选择后关闭弹窗
  10149. },
  10150. },
  10151. item.desc
  10152. )
  10153. )
  10154. ),
  10155. ]
  10156. );
  10157. },
  10158. };
  10159. /**
  10160. * 二级页面标签组件
  10161. * @name ss-sub-tab
  10162. * @description 用于展示二级页面的布局组件,包含左侧垂直标签导航(支持分组)和右侧iframe内容区
  10163. * @property {String} headerImage - 左侧顶部图片地址
  10164. * @property {Array} menuList - 菜单配置列表
  10165. * @property {Object} [activeMenu] - 当前选中的菜单项,不传则自动选择第一个可选菜单
  10166. * @property {Array} footerButtons - 底部按钮配置列表
  10167. */
  10168. /**
  10169. * SsSubTab 左侧菜单+iframe内容组件
  10170. * v3.0 改造:去掉顶部图片,改为图标+悬浮模式,iframe懒加载 by xu 20251216
  10171. */
  10172. const SsSubTab = {
  10173. name: "SsSubTab",
  10174. props: {
  10175. menuList: {
  10176. type: Array,
  10177. required: true,
  10178. },
  10179. activeMenu: {
  10180. type: String,
  10181. default: "",
  10182. },
  10183. footerButtons: {
  10184. type: Array,
  10185. default: () => [],
  10186. },
  10187. leftDisplay: {
  10188. type: Boolean,
  10189. default: true,
  10190. },
  10191. // v3.0 新增:菜单模式 collapse(悬浮展开) / fixed(始终收起) by xu 20251216
  10192. initialMode: {
  10193. type: String,
  10194. default: "collapse",
  10195. },
  10196. },
  10197. emits: ["menu-change", "footer-click"],
  10198. setup(props, { emit }) {
  10199. // v3.0 新增:默认图标映射,使用icon-biz图标 by xu 20251216
  10200. const defaultIcons = [
  10201. "icon-obj-ry", // 人员
  10202. "icon-obj-dw", // 单位
  10203. "icon-obj-gw", // 岗位
  10204. "icon-biz-rc", // 人才
  10205. "icon-biz-xc", // 巡查
  10206. "icon-biz-cl", // 材料
  10207. "icon-biz-men", // 门
  10208. "icon-obj-xy", // 协议
  10209. ];
  10210. //功能: SsSubTab 支持后端下发 iconName + pobj/cobj 两级菜单 by xu 20251222
  10211. const isTrue = (v) => v === true || v === "true" || v === 1 || v === "1"; //功能 by xu 20251222
  10212. const resolveIconClass = (iconNameOrClass, fallbackIndex) => {
  10213. //功能 by xu 20251222
  10214. const fallback = `menu-icon ${
  10215. defaultIcons[fallbackIndex % defaultIcons.length]
  10216. }`;
  10217. if (!iconNameOrClass) {
  10218. return fallback;
  10219. }
  10220. // 已经是完整 class(可能包含 menu-icon / menu-base-icon / 多个 class)
  10221. if (
  10222. typeof iconNameOrClass === "string" &&
  10223. iconNameOrClass.indexOf(" ") > -1
  10224. ) {
  10225. return iconNameOrClass;
  10226. }
  10227. const iconName = iconNameOrClass;
  10228. if (iconName === "menu-icon" || iconName === "menu-base-icon") {
  10229. return fallback;
  10230. }
  10231. // 业务图标库:icon-biz / icon-obj -> menu-icon
  10232. if (
  10233. typeof iconName === "string" &&
  10234. (iconName.indexOf("icon-obj-") === 0 ||
  10235. iconName.indexOf("icon-biz-") === 0)
  10236. ) {
  10237. return `menu-icon ${iconName}`;
  10238. }
  10239. // 默认认为是 icon-base 图标 -> menu-base-icon
  10240. return `menu-base-icon ${iconName}`;
  10241. };
  10242. const getMenuIcon = (item, index) => {
  10243. //功能 by xu 20251222
  10244. if (!item) {
  10245. return resolveIconClass(null, index);
  10246. }
  10247. //功能: 变动图标后端暂不正确,前端先写死为 icon-chg by xu 20251223
  10248. if (item.title === "变动" || item.name === "sys_bd") {
  10249. return resolveIconClass("icon-chg", index);
  10250. }
  10251. // 兼容旧字段 icon(优先使用)
  10252. if (item.icon) return resolveIconClass(item.icon, index);
  10253. // v3.0 使用后端下发 iconName
  10254. if (item.iconName) return resolveIconClass(item.iconName, index);
  10255. return resolveIconClass(null, index);
  10256. };
  10257. //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  10258. const getFooterIcon = (button) => {
  10259. //功能 by xu 20251224
  10260. if (!button) return "menu-base-icon icon-subm";
  10261. const iconNameOrClass =
  10262. button.iconClass || button.iconName || button.icon;
  10263. if (!iconNameOrClass) return "menu-base-icon icon-subm";
  10264. if (
  10265. typeof iconNameOrClass === "string" &&
  10266. iconNameOrClass.indexOf(" ") > -1
  10267. ) {
  10268. return iconNameOrClass;
  10269. }
  10270. return `menu-base-icon ${iconNameOrClass}`;
  10271. };
  10272. //功能: pobj/cobj 扁平结构转换为 children 树结构,兼容原 children 结构 by xu 20251222
  10273. const normalizeMenuList = (rawList) => {
  10274. if (!Array.isArray(rawList) || rawList.length === 0) {
  10275. return [];
  10276. }
  10277. const hasTree = rawList.some(
  10278. (it) => Array.isArray(it?.children) && it.children.length > 0
  10279. );
  10280. if (hasTree) {
  10281. return rawList.map((it) => ({
  10282. ...it,
  10283. __level: 1,
  10284. children: Array.isArray(it.children)
  10285. ? it.children.map((c) => ({ ...c, __level: 2 }))
  10286. : it.children,
  10287. }));
  10288. }
  10289. const hasMarker = rawList.some(
  10290. (it) => it && ("pobj" in it || "cobj" in it)
  10291. );
  10292. if (!hasMarker) {
  10293. return rawList.map((it) => ({ ...it, __level: 1 }));
  10294. }
  10295. const result = [];
  10296. let currentGroup = null;
  10297. for (const item of rawList) {
  10298. //功能: “变动”始终按一级处理(即使后端误传 pobj/cobj)by xu 20251223
  10299. const isChgItem =
  10300. item && (item.title === "变动" || item.name === "sys_bd");
  10301. if (isChgItem) {
  10302. result.push({ ...item, __level: 1 });
  10303. continue;
  10304. }
  10305. const isParent = isTrue(item?.pobj);
  10306. const isChild = isTrue(item?.cobj);
  10307. if (isParent) {
  10308. currentGroup = {
  10309. ...item,
  10310. __level: 1,
  10311. children: [],
  10312. };
  10313. result.push(currentGroup);
  10314. continue;
  10315. }
  10316. if (isChild && currentGroup) {
  10317. currentGroup.children.push({ ...item, __level: 2 });
  10318. continue;
  10319. }
  10320. //功能: 变动等无 pobj/cobj 的选项按一级展示(不挂到 children,也不打断当前分组)by xu 20251223
  10321. result.push({ ...item, __level: 1 });
  10322. }
  10323. return result;
  10324. };
  10325. const menuListComputed = computed(() =>
  10326. normalizeMenuList(props.menuList)
  10327. ); //功能 by xu 20251222
  10328. //功能: 分组展开状态(默认展开),避免 computed 生成对象导致 open 状态丢失 by xu 20251222
  10329. const groupOpenState = reactive({}); // { [key]: boolean }
  10330. const getGroupKey = (item) => item?.name || item?.title || ""; //功能 by xu 20251222
  10331. const isGroupOpen = (item) => {
  10332. //功能 by xu 20251222
  10333. const key = getGroupKey(item);
  10334. if (!key) return true;
  10335. return groupOpenState[key] !== false;
  10336. };
  10337. const toggleGroupOpen = (item) => {
  10338. //功能 by xu 20251222
  10339. const key = getGroupKey(item);
  10340. if (!key) return;
  10341. groupOpenState[key] = !isGroupOpen(item);
  10342. };
  10343. const getLevelClass = (item, fallbackLevel) => {
  10344. //功能 by xu 20251222
  10345. //功能: “变动”始终按一级样式处理 by xu 20251223
  10346. if (item && (item.title === "变动" || item.name === "sys_bd")) {
  10347. return "level-1";
  10348. }
  10349. const level = item?.__level || fallbackLevel || 1;
  10350. return level === 2 ? "level-2" : "level-1";
  10351. };
  10352. // v3.0 新增:菜单模式管理 by xu 20251216
  10353. const menuMode = ref(props.initialMode);
  10354. const isHovering = ref(false);
  10355. const toggleMenuMode = () => {
  10356. menuMode.value = menuMode.value === "collapse" ? "fixed" : "collapse";
  10357. };
  10358. //功能: 提供给旧UI弹窗顶部按钮调用的 API(替代点击 .menu-mode-toggle DOM)by xu 20251224
  10359. const registerSsSubTabApi = () => {
  10360. //功能 by xu 20251224
  10361. try {
  10362. window.SS = window.SS || {};
  10363. window.SS.dom = window.SS.dom || {};
  10364. //功能: 兼容小写 ss 命名空间(部分页面只引用 window.ss)by xu 20251224
  10365. window.ss = window.ss || window.SS;
  10366. window.ss.dom = window.ss.dom || window.SS.dom;
  10367. const api = {
  10368. toggleMenuMode,
  10369. getMenuMode: () => menuMode.value,
  10370. };
  10371. window.SS.dom.ssSubTabApi = api;
  10372. window.ss.dom.ssSubTabApi = api;
  10373. //功能: 多层弹窗(如 objPlay -> objInfo) 场景,将 API 注册到 topWindow 供按钮跨层调用 by xu 20251224
  10374. try {
  10375. const wdDialogId =
  10376. window.wd &&
  10377. wd.display &&
  10378. wd.display.getwdDialogId &&
  10379. wd.display.getwdDialogId();
  10380. if (wdDialogId && window.top) {
  10381. window.top.__ssSubTabApiMap = window.top.__ssSubTabApiMap || {};
  10382. window.top.__ssSubTabApiMap[wdDialogId] = api;
  10383. }
  10384. } catch (e) {}
  10385. try {
  10386. console.log(
  10387. "[SsSubTabApi] registered",
  10388. window.location && window.location.pathname
  10389. );
  10390. } catch (e) {}
  10391. } catch (e) {}
  10392. };
  10393. const unregisterSsSubTabApi = () => {
  10394. //功能 by xu 20251224
  10395. try {
  10396. //功能: 从 topWindow 解绑(避免弹窗关闭后残留)by xu 20251224
  10397. try {
  10398. const wdDialogId =
  10399. window.wd &&
  10400. wd.display &&
  10401. wd.display.getwdDialogId &&
  10402. wd.display.getwdDialogId();
  10403. if (
  10404. wdDialogId &&
  10405. window.top &&
  10406. window.top.__ssSubTabApiMap &&
  10407. window.top.__ssSubTabApiMap[wdDialogId]
  10408. ) {
  10409. delete window.top.__ssSubTabApiMap[wdDialogId];
  10410. }
  10411. } catch (e) {}
  10412. if (window.SS?.dom?.ssSubTabApi?.toggleMenuMode === toggleMenuMode) {
  10413. delete window.SS.dom.ssSubTabApi;
  10414. }
  10415. if (window.ss?.dom?.ssSubTabApi?.toggleMenuMode === toggleMenuMode) {
  10416. delete window.ss.dom.ssSubTabApi;
  10417. }
  10418. } catch (e) {}
  10419. };
  10420. //功能: 立即注册,避免 enable 早于 onMounted 导致“api not ready”by xu 20251224
  10421. registerSsSubTabApi(); //功能 by xu 20251224
  10422. onBeforeUnmount(unregisterSsSubTabApi); //功能 by xu 20251224
  10423. const onMouseEnter = () => {
  10424. if (menuMode.value === "collapse") {
  10425. isHovering.value = true;
  10426. }
  10427. };
  10428. const onMouseLeave = () => {
  10429. isHovering.value = false;
  10430. };
  10431. const isExpanded = computed(() => {
  10432. return menuMode.value === "collapse" && isHovering.value;
  10433. });
  10434. // v3.0 新增:iframe 懒加载,点击才加载 by xu 20251216
  10435. const loadedMenus = ref(new Set());
  10436. const isMenuLoaded = (menuName) => {
  10437. return loadedMenus.value.has(menuName);
  10438. };
  10439. // 根据标题找到对应的菜单项
  10440. const findMenuByTitle = (title) => {
  10441. for (const item of menuListComputed.value) {
  10442. //功能 by xu 20251222
  10443. if (item.children?.length > 0) {
  10444. const child = item.children.find((c) => c.title === title);
  10445. if (child) return child;
  10446. } else if (item.title === title) {
  10447. return item;
  10448. }
  10449. }
  10450. return null;
  10451. };
  10452. // 计算默认选中的菜单项
  10453. const defaultActiveMenu = computed(() => {
  10454. if (props.activeMenu) {
  10455. const menu = findMenuByTitle(props.activeMenu);
  10456. if (menu) return menu;
  10457. }
  10458. const firstItem = menuListComputed.value[0]; //功能 by xu 20251222
  10459. if (!firstItem) return null;
  10460. //功能: 默认选中第一个一级菜单(不默认跳到第一个二级)by xu 20251224
  10461. return firstItem;
  10462. });
  10463. const currentMenu = ref(defaultActiveMenu.value);
  10464. // 监听外部activeMenu变化
  10465. watch(
  10466. () => props.activeMenu,
  10467. (newTitle) => {
  10468. if (newTitle) {
  10469. const menu = findMenuByTitle(newTitle);
  10470. if (menu) {
  10471. currentMenu.value = menu;
  10472. }
  10473. }
  10474. }
  10475. );
  10476. // 初始化:默认选中项加入已加载集合
  10477. watch(
  10478. currentMenu,
  10479. (menu) => {
  10480. if (menu?.name) {
  10481. loadedMenus.value.add(menu.name);
  10482. }
  10483. },
  10484. { immediate: true }
  10485. );
  10486. // 选择菜单项时触发 menu-change 钩子
  10487. const selectItem = (item) => {
  10488. currentMenu.value = item;
  10489. // 标记为已加载
  10490. if (item.name) {
  10491. loadedMenus.value.add(item.name);
  10492. }
  10493. emit("menu-change", item);
  10494. };
  10495. // 处理底部按钮点击
  10496. const handleFooterClick = (button, index) => {
  10497. emit("footer-click", { button, index });
  10498. };
  10499. return {
  10500. menuListComputed, //功能 by xu 20251222
  10501. currentMenu,
  10502. selectItem,
  10503. handleFooterClick,
  10504. getFooterIcon, //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  10505. menuMode,
  10506. isHovering,
  10507. isExpanded,
  10508. toggleMenuMode,
  10509. onMouseEnter,
  10510. onMouseLeave,
  10511. isMenuLoaded,
  10512. getMenuIcon,
  10513. isGroupOpen, //功能 by xu 20251222
  10514. toggleGroupOpen, //功能 by xu 20251222
  10515. getLevelClass, //功能 by xu 20251222
  10516. };
  10517. },
  10518. template: `
  10519. <div class="project-edit-container">
  10520. <div class="left-side"
  10521. v-if="leftDisplay"
  10522. :data-mode="menuMode"
  10523. :class="{ 'is-expanded': isExpanded }"
  10524. @mouseenter="onMouseEnter"
  10525. @mouseleave="onMouseLeave">
  10526. <!-- 菜单内容 -->
  10527. <div class="menu-content">
  10528. <div class="scroll-view">
  10529. <template v-for="(menuItem, i) in menuListComputed" :key="i">
  10530. <!-- 分组菜单 -->
  10531. <div v-if="menuItem.children?.length > 0" class="group">
  10532. <!-- 功能: 一级(pobj)可点击进入,箭头仅控制展开/收起;二级点击不影响一级选中状态 by xu 20251223 -->
  10533. <div class="menu-item"
  10534. :class="[getLevelClass(menuItem, 1), { active: menuItem.name === currentMenu?.name }]"
  10535. @click="selectItem(menuItem)">
  10536. <ss-icon :class="getMenuIcon(menuItem, i)" />
  10537. <span class="menu-label">{{ menuItem.title }}</span>
  10538. <!-- 功能: 一级菜单有子项时显示 dot(参考全局左侧菜单)by xu 20251224 -->
  10539. <div class="has-children-dot"></div>
  10540. <div class="menu-tooltip">{{ menuItem.title }}</div>
  10541. </div>
  10542. <!-- 功能: 二级菜单始终展示,不做收缩展开 by xu 20251223 -->
  10543. <div class="group-detail">
  10544. <div v-for="(item, j) in menuItem.children"
  10545. :key="j"
  10546. class="menu-item"
  10547. :class="[getLevelClass(item, 2), { active: item.name === currentMenu?.name }]"
  10548. @click.stop="selectItem(item)">
  10549. <ss-icon :class="getMenuIcon(item, j)" />
  10550. <span class="menu-label">{{ item.title }}</span>
  10551. </div>
  10552. </div>
  10553. </div>
  10554. <!-- 普通菜单项 -->
  10555. <div v-else
  10556. class="menu-item"
  10557. :class="[getLevelClass(menuItem, 1), { active: menuItem.name === currentMenu?.name }]"
  10558. @click="selectItem(menuItem)">
  10559. <ss-icon :class="getMenuIcon(menuItem, i)" />
  10560. <span class="menu-label">{{ menuItem.title }}</span>
  10561. <div class="menu-tooltip">{{ menuItem.title }}</div>
  10562. </div>
  10563. </template>
  10564. </div>
  10565. </div>
  10566. <!-- 底部按钮 -->
  10567. <div v-if="footerButtons.length > 0"
  10568. class="sub-tab-menu-footer"
  10569. :class="{ 'has-text': !!footerButtons[0].text }"
  10570. @click="footerButtons[0].onclick">
  10571. <ss-icon :class="getFooterIcon(footerButtons[0])" />
  10572. <div class="footer-label" v-if="footerButtons[0].text">{{ footerButtons[0].text }}</div>
  10573. <ss-icon v-if="footerButtons.length > 1" class="footer-arrow" name="arrow-up" size="24px" />
  10574. <div v-if="footerButtons.length > 1" class="sub-tab-menu-popup">
  10575. <div v-for="(button, index) in footerButtons.slice(1)"
  10576. :key="index"
  10577. @click.stop="button.onclick">
  10578. {{ button.text }}
  10579. </div>
  10580. </div>
  10581. </div>
  10582. </div>
  10583. <!-- 右侧内容区域 - 懒加载 iframe -->
  10584. <div class="content-area fit-height-content" style="overflow: hidden;" :style="!leftDisplay ? { width: '100%' } : {}">
  10585. <template v-for="(menuItem, i) in menuList" :key="i">
  10586. <iframe
  10587. v-if="isMenuLoaded(menuItem.name)"
  10588. :src="menuItem.url"
  10589. style="height: 100%;width: 100%;"
  10590. frameborder="0"
  10591. class="sub-tab-iframe"
  10592. :id="i === 0 ? 'sub-tab-iframe' : ''"
  10593. v-show="currentMenu?.name === menuItem.name"
  10594. />
  10595. </template>
  10596. </div>
  10597. </div>
  10598. `,
  10599. };
  10600. // <iframe
  10601. // v-if="currentMenu?.url"
  10602. // :src="currentMenu.url"
  10603. // style="height: 100%;width: 100%;"
  10604. // frameborder="0"
  10605. // id="sub-tab-iframe"
  10606. // />
  10607. // ss-photo-upload 通用图片上传组件
  10608. const SsImgUpload = {
  10609. name: "SsImgUpload",
  10610. props: {
  10611. name: {
  10612. type: String,
  10613. required: true,
  10614. },
  10615. // 图片URL,用于回显
  10616. // url: {
  10617. // type: String,
  10618. // default: "",
  10619. // },
  10620. // 样式类名
  10621. class: {
  10622. type: String,
  10623. required: true,
  10624. },
  10625. // 裁剪配置
  10626. cropperOpt: {
  10627. type: Object,
  10628. default: () => ({
  10629. width: 360,
  10630. height: 360,
  10631. aspectRatio: 1,
  10632. }),
  10633. },
  10634. //上传图片url(未加图片名参数之前的部分)
  10635. ulUrl: {
  10636. type: String,
  10637. required: true,
  10638. },
  10639. //下载图片url(未加图片名参数之前的部分)
  10640. dlUrl: {
  10641. type: String,
  10642. required: true,
  10643. },
  10644. modelValue: [String, Number],
  10645. },
  10646. emits: ["update:modelValue"],
  10647. setup(props, { emit }) {
  10648. const inputId = Vue.computed(
  10649. () => `file_${Vue.getCurrentInstance().uid}`
  10650. );
  10651. //修改图片初始显示路径
  10652. let pathVal = ref(props.modelValue);
  10653. let picUrl = ref("");
  10654. if (props.modelValue) {
  10655. picUrl.value = props.dlUrl + "&path=" + props.modelValue;
  10656. }
  10657. Vue.onMounted(() => {
  10658. window.SS.cropper.init({
  10659. el: $(`#${inputId.value}`),
  10660. photoSize: {
  10661. width: props.cropperOpt.width,
  10662. height: props.cropperOpt.height,
  10663. },
  10664. aspectRatio: props.cropperOpt.aspectRatio,
  10665. uploadUrl: props.ulUrl,
  10666. success: (path) => {
  10667. pathVal.value = path;
  10668. picUrl.value = props.dlUrl + "&path=" + path;
  10669. emit("update:modelValue", path);
  10670. },
  10671. });
  10672. });
  10673. return () =>
  10674. h("div", { class: [props.class] }, [
  10675. h("input", {
  10676. type: "file",
  10677. accept: "image/*",
  10678. id: inputId.value,
  10679. style: { display: "none" },
  10680. }),
  10681. h("input", {
  10682. type: "hidden",
  10683. name: props.name,
  10684. value: pathVal.value,
  10685. }),
  10686. h(
  10687. "div",
  10688. {
  10689. style: {
  10690. width: "100%",
  10691. height: "100%",
  10692. },
  10693. onClick: () => $(`#${inputId.value}`).click(),
  10694. },
  10695. [
  10696. picUrl.value &&
  10697. h("img", {
  10698. src: picUrl.value,
  10699. style:
  10700. "width: 100%; height: 100%;object-fit: inherit;position: relative;z-index: 11;",
  10701. }),
  10702. ]
  10703. ),
  10704. ]);
  10705. },
  10706. };
  10707. // 初始化函数,负责创建和挂载 Vue 应用
  10708. // window.SS = { dom: {} };
  10709. /**
  10710. * 获取当前窗口的父窗口
  10711. * @returns {Window} 父窗口对象
  10712. */
  10713. window.SS.topWin = (function (p, c) {
  10714. while (p != c) {
  10715. c = p;
  10716. p = p.parent;
  10717. }
  10718. return c;
  10719. })(window.parent, window);
  10720. window.SS.createSsDialogInstance = createSsDialogInstance;
  10721. /**
  10722. * 创建弹窗
  10723. * @param {Object} setting
  10724. * @param {Function} callbackEvent
  10725. */
  10726. window.SS.openDialog = function (setting, callbackEvent) {
  10727. if (setting.params) {
  10728. const encodedParams = encodeURIComponent(JSON.stringify(setting.params));
  10729. setting.src +=
  10730. (setting.src.includes("?") ? "&" : "?") + "params=" + encodedParams;
  10731. }
  10732. if (window.parent && window.parent !== window) {
  10733. window.parent.SS.createSsDialogInstance(setting, callbackEvent);
  10734. } else {
  10735. createSsDialogInstance(setting, callbackEvent);
  10736. }
  10737. };
  10738. //关闭弹窗
  10739. window.SS.closeDialog = function () {
  10740. console.log("关闭弹窗");
  10741. if (topWindow.dialogInstances.length > 0) {
  10742. const instance = topWindow.dialogInstances.pop();
  10743. console.log("instance", instance);
  10744. console.log("instance.callbackEvent", instance.callbackEvent);
  10745. console.log(
  10746. "instance.callbackEvent.end",
  10747. typeof instance.callbackEvent === "function"
  10748. );
  10749. if (instance.callbackEvent) {
  10750. // 判断是否有end回调并执行
  10751. if (typeof instance.callbackEvent === "function") {
  10752. instance.callbackEvent();
  10753. }
  10754. if (typeof instance.callbackEvent.end === "function") {
  10755. instance.callbackEvent.end();
  10756. }
  10757. }
  10758. instance.app.unmount(); // 卸载最后一个实例
  10759. if (instance.container && instance.container.parentNode) {
  10760. instance.container.parentNode.removeChild(instance.container); // 移除容器
  10761. }
  10762. }
  10763. };
  10764. /**
  10765. * 裁剪插件
  10766. */
  10767. window.SS.cropper = {
  10768. init: function (setting) {
  10769. if (!window.top.SS) window.top.SS = {};
  10770. // 重要:确保 cropper 对象的完整初始化
  10771. if (!window.top.SS.cropper) {
  10772. window.top.SS.cropper = {
  10773. settings: new Map(),
  10774. _backupSettings: {},
  10775. getSetting: this.getSetting,
  10776. clearSetting: this.clearSetting,
  10777. debug: this.debug,
  10778. };
  10779. } else if (!window.top.SS.cropper.settings) {
  10780. // 如果 cropper 存在但 settings 不存在,重新初始化 settings
  10781. window.top.SS.cropper.settings = new Map();
  10782. window.top.SS.cropper._backupSettings = {};
  10783. }
  10784. const uploaderId = `uploader_${Date.now()}_${Math.random()
  10785. .toString(36)
  10786. .substr(2, 9)}`;
  10787. window.top.SS.cropper.settings.set(uploaderId, setting);
  10788. window.top.SS.cropper._backupSettings[uploaderId] = setting;
  10789. setting.box = setting.box || "1";
  10790. var winSetting = {
  10791. headerTitle: "图片裁剪",
  10792. src: "/js/cropper/cropper.jsp", //原来在"/newUI/page/cropper.jsp" Ben(20251205)
  10793. width: "900",
  10794. height: "500",
  10795. };
  10796. $(setting.el).change(function () {
  10797. if (!window.SS.cropper.verify(setting)) {
  10798. $(setting.el).val(""); // 清空文件选择
  10799. return false;
  10800. }
  10801. var files = this.files;
  10802. if (files && files.length) {
  10803. if (!window.SS.cropper.verifySize($(setting.el)[0], 5)) {
  10804. $(setting.el).val(""); // 清空文件选择
  10805. alert("文件大小不能超过5M,请重新选择");
  10806. return false;
  10807. }
  10808. var URL = window.URL || window.webkitURL;
  10809. var file = files[0];
  10810. setting.file = file;
  10811. if (
  10812. /^image\/\w+$/.test(file.type) &&
  10813. /\.(jpg|jpeg|png|)$/i.test(file.name)
  10814. ) {
  10815. var uploadedImageURL = URL.createObjectURL(file);
  10816. setting.data = uploadedImageURL;
  10817. setting.fileName = file.name;
  10818. // console.log()
  10819. winSetting.params = {
  10820. ...setting,
  10821. uploaderId,
  10822. };
  10823. console.log("ss-componets中change之后的winSetting", winSetting);
  10824. SS.openDialog(winSetting, {
  10825. success: function (win) {
  10826. console.log("裁剪插件成功");
  10827. // win.cropperSetting = setting;
  10828. },
  10829. end: function () {
  10830. console.log("裁剪插件结束");
  10831. $(setting.el).val(""); // 清空文件选择
  10832. },
  10833. });
  10834. } else {
  10835. alert("请选择图片文件,支持jpg、jpeg、png格式");
  10836. }
  10837. }
  10838. });
  10839. return uploaderId;
  10840. },
  10841. verify: function (setting) {
  10842. if (!setting) {
  10843. console.error(" cropper setting is not undefined! ");
  10844. return false;
  10845. }
  10846. if (!setting.el) {
  10847. console.error(" cropper setting.el is not undefined! ");
  10848. return false;
  10849. }
  10850. if (setting.photoSize) {
  10851. if (
  10852. (!setting.photoSize.width && setting.photoSize.height) ||
  10853. (!setting.photoSize.height && setting.photoSize.width)
  10854. ) {
  10855. console.error(
  10856. " cropper setting.photoSize { width, height } is not undefined! "
  10857. );
  10858. return false;
  10859. }
  10860. }
  10861. if (!setting.box) {
  10862. setting.box = "1";
  10863. }
  10864. if (!setting.aspectRatio) {
  10865. setting.aspectRatio = 1 / 1;
  10866. }
  10867. return true;
  10868. },
  10869. verifySize: function (fileEl, maxSize) {
  10870. // 判断是否为IE浏览器: /msie/i.test(navigator.userAgent) 为一个简单正则
  10871. var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  10872. var fileSize = 0;
  10873. if (isIE && !fileEl.files) {
  10874. // IE浏览器
  10875. var filePath = fileEl.value; // 获得上传文件的绝对路径
  10876. var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
  10877. var file = fileSystem.GetFile(filePath);
  10878. fileSize = file.Size; // 文件大小,单位:b
  10879. } else {
  10880. // 非IE浏览器
  10881. fileSize = fileEl.files[0].size;
  10882. }
  10883. var size = fileSize / 1024 / 1024;
  10884. return !(size > maxSize);
  10885. },
  10886. // 获取特定上传组件的setting
  10887. getSetting: function (uploaderId) {
  10888. if (!window.top.SS?.cropper) {
  10889. console.warn("顶层窗口中未找到 SS.cropper");
  10890. return null;
  10891. }
  10892. // 优先从 Map 中获取
  10893. let setting = window.top.SS.cropper.settings.get(uploaderId);
  10894. // 如果 Map 中没有,尝试从备份中获取
  10895. if (!setting && window.top.SS.cropper._backupSettings[uploaderId]) {
  10896. console.log("从备份中恢复 setting");
  10897. setting = window.top.SS.cropper._backupSettings[uploaderId];
  10898. // 恢复到 Map 中
  10899. window.top.SS.cropper.settings.set(uploaderId, setting);
  10900. }
  10901. return setting;
  10902. },
  10903. // 清理特定上传组件的setting
  10904. clearSetting: function (uploaderId) {
  10905. if (!window.top.SS?.cropper) return;
  10906. window.top.SS.cropper.settings.delete(uploaderId);
  10907. delete window.top.SS.cropper._backupSettings[uploaderId];
  10908. console.log(
  10909. "清理设置后的 Map size:",
  10910. window.top.SS.cropper.settings.size
  10911. );
  10912. },
  10913. };
  10914. /**
  10915. * 获取url中的参数
  10916. * @returns {Object}
  10917. */
  10918. window.SS.getQueryParams = function () {
  10919. const params = {};
  10920. const queryString = window.location.search.substring(1);
  10921. const pairs = queryString.split("&");
  10922. for (let i = 0; i < pairs.length; i++) {
  10923. const pair = pairs[i].split("=");
  10924. params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  10925. }
  10926. if (params.params) {
  10927. try {
  10928. params.params = JSON.parse(params.params);
  10929. } catch (e) {
  10930. console.error("Failed to parse params:", e);
  10931. }
  10932. }
  10933. return params;
  10934. };
  10935. /**
  10936. * 创建vue应用
  10937. * @param {Object} config 配置项
  10938. * @values {String} config.el 挂载的元素
  10939. * @values {Boolean} config.isDialogPage 是否是弹窗页面 决定了是否可以使用顶天立地
  10940. * @values {Object} config.vueOptions vue配置项
  10941. * @returns {Object} vue实例
  10942. */
  10943. window.ss = window.ss || window.SS;
  10944. window.ss.dom = window.ss.dom || window.SS.dom;
  10945. window.SS.dom._vueAppSeq =
  10946. window.SS.dom._vueAppSeq || window.ss.dom._vueAppSeq || 0;
  10947. window.SS.dom.vueApps = window.SS.dom.vueApps || window.ss.dom.vueApps || [];
  10948. window.ss.dom._vueAppSeq = window.SS.dom._vueAppSeq;
  10949. window.ss.dom.vueApps = window.SS.dom.vueApps;
  10950. window.SS.dom._registerVueApp = function ({ vm, el, appKey, scope, href }) {
  10951. if (!vm) return null;
  10952. const registry = window.SS.dom.vueApps || (window.SS.dom.vueApps = []);
  10953. const id = `vue-app-${++window.SS.dom._vueAppSeq}`;
  10954. const record = {
  10955. id,
  10956. el: el || "",
  10957. appKey: appKey || "",
  10958. scope: scope || "current",
  10959. href: href || window.location.href,
  10960. createdAt: Date.now(),
  10961. vm,
  10962. win: window,
  10963. };
  10964. registry.push(record);
  10965. window.SS.dom.currentApp = vm;
  10966. window.SS.dom.currentAppRecord = record;
  10967. if (window.ss && window.ss.dom) {
  10968. window.ss.dom.vueApps = registry;
  10969. window.ss.dom._vueAppSeq = window.SS.dom._vueAppSeq;
  10970. window.ss.dom.currentApp = vm;
  10971. window.ss.dom.currentAppRecord = record;
  10972. }
  10973. return record;
  10974. };
  10975. window.SS.dom._getVmData = function (vm) {
  10976. if (!vm) return null;
  10977. return vm.$data || vm;
  10978. };
  10979. window.SS.dom._hasVmKey = function (vm, key) {
  10980. if (!vm || !key) return false;
  10981. const data = window.SS.dom._getVmData(vm);
  10982. return key in vm || (!!data && key in data);
  10983. };
  10984. window.SS.dom._hasVmMethod = function (vm, methodName) {
  10985. return !!(vm && methodName && typeof vm[methodName] === "function");
  10986. };
  10987. window.SS.dom._normalizeBridgeOptions = function (
  10988. options = {},
  10989. defaults = {}
  10990. ) {
  10991. return {
  10992. scope: "chain",
  10993. ...defaults,
  10994. ...options,
  10995. };
  10996. };
  10997. window.SS.dom._matchVueRecord = function (record, options = {}) {
  10998. if (!record || !record.vm) return false;
  10999. if (options.appKey && record.appKey !== options.appKey) return false;
  11000. if (options.el && record.el !== options.el) return false;
  11001. if (options.id && record.id !== options.id) return false;
  11002. if (
  11003. options.dataKey &&
  11004. !window.SS.dom._hasVmKey(record.vm, options.dataKey)
  11005. ) {
  11006. return false;
  11007. }
  11008. if (
  11009. options.methodName &&
  11010. !window.SS.dom._hasVmMethod(record.vm, options.methodName)
  11011. ) {
  11012. return false;
  11013. }
  11014. if (typeof options.predicate === "function") {
  11015. try {
  11016. if (!options.predicate(record.vm, record)) {
  11017. return false;
  11018. }
  11019. } catch (e) {
  11020. return false;
  11021. }
  11022. }
  11023. return true;
  11024. };
  11025. window.SS.dom._getWindowVueRecord = function (targetWindow, options = {}) {
  11026. if (!targetWindow || !targetWindow.SS || !targetWindow.SS.dom) return null;
  11027. const registry = targetWindow.SS.dom.vueApps || [];
  11028. for (let i = registry.length - 1; i >= 0; i--) {
  11029. if (targetWindow.SS.dom._matchVueRecord(registry[i], options)) {
  11030. return registry[i];
  11031. }
  11032. }
  11033. const currentRecord = targetWindow.SS.dom.currentAppRecord;
  11034. if (targetWindow.SS.dom._matchVueRecord(currentRecord, options)) {
  11035. return currentRecord;
  11036. }
  11037. const currentVm = targetWindow.SS.dom.currentApp;
  11038. const fallbackRecord = currentVm
  11039. ? {
  11040. vm: currentVm,
  11041. win: targetWindow,
  11042. el: "",
  11043. appKey: "",
  11044. id: "",
  11045. }
  11046. : null;
  11047. if (targetWindow.SS.dom._matchVueRecord(fallbackRecord, options)) {
  11048. return fallbackRecord;
  11049. }
  11050. return null;
  11051. };
  11052. window.SS.dom.getVueAppRecord = function (options = {}) {
  11053. const scope = options.scope || "current";
  11054. if (scope === "current") {
  11055. return window.SS.dom._getWindowVueRecord(window, options);
  11056. }
  11057. if (scope === "top") {
  11058. try {
  11059. return window.SS.dom._getWindowVueRecord(window.top, options);
  11060. } catch (e) {
  11061. return null;
  11062. }
  11063. }
  11064. if (scope === "parent") {
  11065. try {
  11066. if (window.parent && window.parent !== window) {
  11067. return window.SS.dom._getWindowVueRecord(window.parent, options);
  11068. }
  11069. } catch (e) {
  11070. return null;
  11071. }
  11072. return null;
  11073. }
  11074. if (scope === "chain") {
  11075. let currentWindow = window;
  11076. while (currentWindow) {
  11077. try {
  11078. const record = window.SS.dom._getWindowVueRecord(
  11079. currentWindow,
  11080. options
  11081. );
  11082. if (record) {
  11083. return record;
  11084. }
  11085. } catch (e) {
  11086. return null;
  11087. }
  11088. if (currentWindow === currentWindow.parent) {
  11089. break;
  11090. }
  11091. currentWindow = currentWindow.parent;
  11092. }
  11093. return null;
  11094. }
  11095. return window.SS.dom._getWindowVueRecord(window, options);
  11096. };
  11097. window.SS.dom.getVueApp = function (options = {}) {
  11098. const record = window.SS.dom.getVueAppRecord(options);
  11099. return record ? record.vm : null;
  11100. };
  11101. window.SS.dom.getVmValue = function (key, options = {}) {
  11102. const vm = window.SS.dom.getVueApp(
  11103. window.SS.dom._normalizeBridgeOptions(options, { dataKey: key })
  11104. );
  11105. if (!vm) return undefined;
  11106. return vm[key];
  11107. };
  11108. window.SS.dom.setVmValue = function (key, value, options = {}) {
  11109. const vm = window.SS.dom.getVueApp(
  11110. window.SS.dom._normalizeBridgeOptions(options, { dataKey: key })
  11111. );
  11112. if (!vm) return false;
  11113. vm[key] = value;
  11114. return true;
  11115. };
  11116. window.SS.dom.callVmMethod = function (methodName, args = [], options = {}) {
  11117. const vm = window.SS.dom.getVueApp(
  11118. window.SS.dom._normalizeBridgeOptions(options, { methodName })
  11119. );
  11120. if (!vm || typeof vm[methodName] !== "function") {
  11121. return undefined;
  11122. }
  11123. return vm[methodName].apply(vm, args);
  11124. };
  11125. window.SS.dom.get = function (key, options = {}) {
  11126. return window.SS.dom.getVmValue(key, options);
  11127. };
  11128. window.SS.dom.set = function (key, value, options = {}) {
  11129. return window.SS.dom.setVmValue(key, value, options);
  11130. };
  11131. window.SS.dom.call = function (methodName, args = [], options = {}) {
  11132. return window.SS.dom.callVmMethod(methodName, args, options);
  11133. };
  11134. [
  11135. "_registerVueApp",
  11136. "_getVmData",
  11137. "_hasVmKey",
  11138. "_hasVmMethod",
  11139. "_normalizeBridgeOptions",
  11140. "_matchVueRecord",
  11141. "_getWindowVueRecord",
  11142. "getVueAppRecord",
  11143. "getVueApp",
  11144. "getVmValue",
  11145. "setVmValue",
  11146. "callVmMethod",
  11147. "get",
  11148. "set",
  11149. "call",
  11150. ].forEach((name) => {
  11151. window.ss.dom[name] = window.SS.dom[name];
  11152. });
  11153. window.SS.dom.initializeFormApp = function (config) {
  11154. const {
  11155. el,
  11156. isDialogPage = false,
  11157. appKey = "",
  11158. scope = "current",
  11159. ...vueOptions
  11160. } = config;
  11161. const app = createApp({
  11162. ...vueOptions,
  11163. });
  11164. if (isDialogPage) {
  11165. function checkScroll() {
  11166. const elements = document.querySelectorAll(".fit-height-content");
  11167. let hasScrollBar = false;
  11168. elements.forEach((el) => {
  11169. if (el.scrollHeight > el.clientHeight) {
  11170. hasScrollBar = true;
  11171. }
  11172. });
  11173. window.parent.postMessage({ hasScrollBar }, "*");
  11174. }
  11175. function addScrollListeners() {
  11176. const elements = document.querySelectorAll("div");
  11177. elements.forEach((el) => {
  11178. el.addEventListener("scroll", checkScroll);
  11179. });
  11180. }
  11181. const observer = new MutationObserver(() => {
  11182. addScrollListeners();
  11183. checkScroll();
  11184. });
  11185. observer.observe(document.body, {
  11186. childList: true,
  11187. subtree: true,
  11188. });
  11189. window.addEventListener("resize", checkScroll);
  11190. }
  11191. app.component("SsLoginIcon", SsLoginIcon);
  11192. app.component("SsMark", SsMark);
  11193. app.component("SsFullStyleHeader", SsFullStyleHeader);
  11194. app.component("SsDialog", SsDialog);
  11195. app.component("SsInp", SsInput);
  11196. app.component("SsObjp", SsObjp);
  11197. app.component("SsHidden", SsHidden);
  11198. app.component("SsCcp", SsCcp);
  11199. app.component("SsDatePicker", SsDatePicker);
  11200. app.component("SsIcon", SsIcon);
  11201. app.component("SsCommonIcon", SsCommonIcon);
  11202. app.component("SsBreadcrumb", SsBreadcrumb);
  11203. app.component("SsEditor", SsEditor);
  11204. app.component("SsDialogIcon", SsDialogIcon);
  11205. app.component("SsBottomButton", SsBottomButton);
  11206. app.component("ss-btn", SsBottomButton);
  11207. app.component("SsNavIcon", SsNavIcon);
  11208. app.component("SsHeaderIcon", SsHeaderIcon);
  11209. app.component("SsGolbalMenuIcon", SsGolbalMenuIcon);
  11210. app.component("SsCartListIcon", SsCartListIcon);
  11211. app.component("SsQuickIcon", SsQuickIcon);
  11212. app.component("SsFormIcon", SsFormIcon);
  11213. app.component("SsBottomDivIcon", SsBottomDivIcon);
  11214. app.component("SsEditorIcon", SsEditorIcon);
  11215. app.component("SsValidate", SsValidate);
  11216. app.component("SsOnoff", Ssonoff);
  11217. app.component("SsonoffArray", SsonoffArray);
  11218. app.component("SsTextarea", SsTextarea);
  11219. app.component("SsLoginInput", SsLoginInput);
  11220. app.component("SsLoginButton", SsLoginButton);
  11221. app.component("SsSearch", SsSearch);
  11222. app.component("SsCartItem", SsCartItem);
  11223. app.component("SsCartItem2", SsCartItem2);
  11224. app.component("SsListCard", SsListCard);
  11225. app.component("ss-cobj-card-list", SsCObjCardList);
  11226. app.component("SsFolderCard", SsFolderCard);
  11227. app.component("ss-sidebar", SsSidebar);
  11228. app.component("ss-sidebar-buttons", SsSidebarButtons);
  11229. app.component("ss-sidebar-chart", SsSidebarChart);
  11230. app.component("ss-sidebar-chart-hover", SsSidebarChartHover);
  11231. app.component("ss-sidebar-list", SsSidebarList);
  11232. app.component("ss-sidebar-report-table", SsSidebarReportTable);
  11233. app.component("SsFolderCartView", SsFolderCartView);
  11234. app.component("SsPage", SsPage);
  11235. app.component("SsRightInfo", SSRightInfo);
  11236. app.component("SsSuccessPopup", SsSuccessPopup);
  11237. app.component("SsErrorDialog", SsErrorDialog);
  11238. app.component("SsVerify", SsVerify);
  11239. app.component("SsVerifyNode", SsVerifyNode);
  11240. app.component("SsOrcImgBox", SsOrcImgBox);
  11241. app.component("ss-search-input", SsSearchInput);
  11242. app.component("ss-nump", SsNump);
  11243. app.component("ss-search-date-picker", SsSearchDatePicker);
  11244. app.component("ss-search-button", SsSearchButton);
  11245. app.component("ss-drop-button", SsDropButton);
  11246. app.component("ss-sub-tab", SsSubTab);
  11247. app.component("ss-img", SsImgUpload);
  11248. app.use(ElementPlus, {
  11249. locale: ElementPlusLocaleZhCn,
  11250. });
  11251. for (const componentName in IndexComponents) {
  11252. app.component(componentName, IndexComponents[componentName]);
  11253. }
  11254. for (const componentName in EchartComponents) {
  11255. app.component(componentName, EchartComponents[componentName]);
  11256. }
  11257. let vm;
  11258. try {
  11259. vm = app.mount(el);
  11260. vm.data = vueOptions.data();
  11261. window.SS.dom._registerVueApp({
  11262. vm,
  11263. el,
  11264. appKey,
  11265. scope,
  11266. href: window.location.href,
  11267. });
  11268. console.log("vm:", vm);
  11269. console.log("vueOptions:", vueOptions);
  11270. } catch (error) {
  11271. console.log("Mount failed:" + error);
  11272. }
  11273. return vm;
  11274. };
  11275. })();