ss-components.js 366 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425
  1. import { ssIcon, commonIcon } from "./icon-config.js";
  2. import * as IndexComponents from "./ss-index-components.js";
  3. import * as EchartComponents from "./ss-echarts-compnents.js";
  4. import {
  5. isNum,
  6. toStyleStr,
  7. buildThumbUrl,
  8. openServiceDialog,
  9. pickSearchParams,
  10. } from "./tools.js"; // 功能说明:组件内统一构建缩略图URL、打开服务弹窗,减少 JSP 层字段转换 by xu 20260122
  11. import { EVEN_VAR } from "./EventBus.js";
  12. // import * as elements from "../lib/element-plus.js";
  13. (function () {
  14. const {
  15. createApp,
  16. ref,
  17. reactive,
  18. watch,
  19. onMounted,
  20. onBeforeUnmount,
  21. h,
  22. computed,
  23. resolveComponent,
  24. watchEffect,
  25. nextTick,
  26. onVnodeMounted,
  27. Teleport,
  28. inject,
  29. provide,
  30. } = Vue;
  31. // 弹窗默认遮罩z-index
  32. let currentZIndex = 100;
  33. // 目前已存在的弹窗
  34. const topWindow = window.top;
  35. topWindow.dialogInstances = topWindow.dialogInstances || [];
  36. // 新建弹窗
  37. function createSsDialogInstance(setting, callbackEvent) {
  38. currentZIndex += 10; // 动态提升 z-index
  39. const container = document.createElement("div");
  40. document.body.appendChild(container);
  41. const app = Vue.createApp({
  42. render() {
  43. return h(SsDialog, {
  44. ...setting,
  45. zIndex: currentZIndex,
  46. onClose() {
  47. document.body.removeChild(container); // 仅移除弹窗容器
  48. const index = topWindow.dialogInstances.indexOf(app);
  49. if (index > -1) {
  50. topWindow.dialogInstances.splice(index, 1); // 移除实例
  51. }
  52. // 关闭后的回调
  53. if (callbackEvent && typeof callbackEvent === "function") {
  54. callbackEvent();
  55. }
  56. app.unmount(); // 仅卸载弹窗实例
  57. if (container.parentNode) {
  58. container.parentNode.removeChild(container); // 确保移除容器
  59. }
  60. },
  61. });
  62. },
  63. });
  64. topWindow.dialogInstances.push({ app, callbackEvent, container });
  65. app.component("ss-mark", SsMark); // 注册 ss-mark 组件
  66. app.component("ss-icon", SsIcon);
  67. app.component("ss-full-style-header", SsFullStyleHeader); // 注册 ss-full-style-header 组件
  68. app.mount(container);
  69. }
  70. // ss-breadcrumb 一级菜单页面面包屑
  71. const SsBreadcrumb = {
  72. name: "SsBreadcrumb",
  73. props: {
  74. level: {
  75. type: Object,
  76. default: null,
  77. },
  78. },
  79. setup(props) {
  80. const currentMenu = ref(null);
  81. const folderPath = ref([]);
  82. const eventBus = window.parent.sharedEventBus;
  83. // 监听页面变化
  84. onMounted(() => {
  85. // 获取初始页面
  86. currentMenu.value = eventBus.getState(EVEN_VAR.currentPage);
  87. folderPath.value = eventBus.getState("folderPath") || [];
  88. // 订阅页面变化
  89. eventBus.subscribe(EVEN_VAR.currentPage, (page) => {
  90. currentMenu.value = page;
  91. });
  92. eventBus.subscribe("folderPath", (path) => {
  93. folderPath.value = path || [];
  94. });
  95. });
  96. // 修改点击处理函数
  97. const handlePathClick = (index) => {
  98. if (props.level?.onBack) {
  99. // 截取到点击的位置,后面的路径会被销毁
  100. const newPath = folderPath.value.slice(0, index + 1);
  101. eventBus.publish("folderPath", newPath);
  102. // 返回到对应层级
  103. const targetFolder = newPath[newPath.length - 1]?.folder || null;
  104. props.level.onBack(targetFolder);
  105. }
  106. };
  107. const SsCommonIcon = resolveComponent("SsCommonIcon");
  108. return () =>
  109. h("div", { class: "bread-crumb" }, [
  110. currentMenu.value &&
  111. h(
  112. "div",
  113. {
  114. onClick: () => {
  115. if (props.level?.onBack) {
  116. eventBus.publish("folderPath", []);
  117. props.level.onBack(null); // 返回到根目录
  118. } else {
  119. eventBus.publish(EVEN_VAR.currentPage, currentMenu.value);
  120. }
  121. },
  122. },
  123. currentMenu.value.label || currentMenu.value.name
  124. ),
  125. ...(folderPath.value || [])
  126. .map((folder, index) => [
  127. h(SsCommonIcon, { class: "common-icon-arrow-right" }),
  128. h(
  129. "div",
  130. {
  131. class: "bread-crumb-item",
  132. onClick: () => handlePathClick(index),
  133. style: { cursor: "pointer" },
  134. },
  135. folder.title
  136. ),
  137. ])
  138. .flat(),
  139. ]);
  140. },
  141. };
  142. // ss-input form表单的输入
  143. const SsInput = {
  144. name: "SsInp", //把SsInput改为SsInp Ben(20251225)
  145. inheritAttrs: false, // 不直接继承属性到组件根元素
  146. props: {
  147. name: {
  148. type: String,
  149. required: true,
  150. default: "",
  151. },
  152. // 接收 v-model 绑定的值
  153. errTip: {
  154. type: String,
  155. },
  156. required: {
  157. type: Boolean,
  158. default: false,
  159. },
  160. placeholder: {
  161. type: String,
  162. default: "请输入",
  163. },
  164. defaultValue: [String, Number],
  165. modelValue: [String, Number],
  166. // 新增:附件配置
  167. fj: {
  168. type: Object,
  169. default: null,
  170. },
  171. // 新增:param 配置(用于附件功能)
  172. param: {
  173. type: Object,
  174. default: null,
  175. },
  176. // 新增:高度配置
  177. height: {
  178. type: String,
  179. default: "",
  180. },
  181. // 功能说明:传 height 时允许回车换行(多行输入);未传 height 默认单行 by xu 20260204
  182. },
  183. emits: ["update:modelValue", "input", "blur", "change"], // 允许更新 v-model 绑定的值
  184. setup(props, { emit }) {
  185. const errMsg = ref("");
  186. const inputRef = ref(null);
  187. const textareaRef = ref(null);
  188. const inputValue = ref(props.modelValue || props.defaultValue || "");
  189. const contentFloatingDiv = ref(false); // 控制浮动 DIV 的显示
  190. const floatingDivPosition = ref("bottom"); // 'bottom' 或 'top'
  191. const isFocused = ref(false); // 跟踪焦点状态
  192. // 附件相关变量(仅在传入 param 时初始化)
  193. let fjid = ref(null);
  194. let fjName = null;
  195. let mode = null;
  196. if (props.param && props.param.button) {
  197. fjid = ref(props.param.button.val);
  198. fjName = props.param.button.desc;
  199. mode = props.param.mode;
  200. }
  201. const showRequired = computed(() => {
  202. // 检查是否有验证规则(通过 window.ssVm 判断)
  203. const hasValidationRule = window.ssVm?.validations?.has(props.name);
  204. if (!hasValidationRule) return false;
  205. if (errMsg.value) return true;
  206. if (!inputValue.value) return true;
  207. return false;
  208. });
  209. // 计算floatdiv应该向上还是向下展开
  210. const calculateFloatingDivPosition = () => {
  211. nextTick(() => {
  212. const textarea = inputRef.value;
  213. if (!textarea) return;
  214. const rect = textarea.getBoundingClientRect();
  215. const viewportHeight = window.innerHeight;
  216. // 预估floatdiv的高度(最多5行 * 20px + 上下padding + border)
  217. const estimatedFloatDivHeight = 20 * 5 + 10 + 2; // 5行 + padding + border = 112px
  218. // 检查下方空间
  219. const spaceBelow = viewportHeight - rect.bottom;
  220. // 如果下方空间不足,且上方空间足够,则向上展开
  221. if (
  222. spaceBelow < estimatedFloatDivHeight &&
  223. rect.top > estimatedFloatDivHeight
  224. ) {
  225. floatingDivPosition.value = "top";
  226. } else {
  227. floatingDivPosition.value = "bottom";
  228. }
  229. });
  230. };
  231. // 计算floatdiv的top偏移量
  232. const getFloatingDivTop = computed(() => {
  233. if (props.height) {
  234. // 有height时,padding是5px
  235. return "5px";
  236. } else {
  237. // 没有height时是单行居中,需要计算居中位置
  238. // 假设input-container高度是32px(或者从CSS读取),单行20px
  239. // 居中偏移 = (容器高度 - 行高) / 2 = (32 - 20) / 2 = 6px
  240. return "6px";
  241. }
  242. });
  243. const validate = () => {
  244. if (window.ssVm) {
  245. const result = window.ssVm.validateField(props.name);
  246. console.log(result);
  247. errMsg.value = result.valid ? "" : result.message;
  248. }
  249. };
  250. // 使用 watch 监听 props.errTip 和 props.modelValue 的变化
  251. watch(
  252. () => props.errTip,
  253. (newVal) => {
  254. errMsg.value = newVal;
  255. },
  256. { immediate: true }
  257. );
  258. watch(
  259. () => props.modelValue,
  260. (newVal) => {
  261. inputValue.value = newVal;
  262. }
  263. );
  264. // 挂载时的逻辑
  265. onMounted(() => {
  266. errMsg.value = props.errTip;
  267. inputValue.value = props.modelValue || props.defaultValue || "";
  268. });
  269. // 计算并调整textarea的高度
  270. const adjustHeight = () => {
  271. nextTick(() => {
  272. const textarea = textareaRef.value;
  273. if (!textarea) return;
  274. // floatDiv的textarea始终自动计算高度,不受props.height影响
  275. // 重置高度以获得正确的scrollHeight
  276. textarea.style.height = "auto";
  277. // 计算新高度 - 统一限制为5行
  278. const lineHeight = parseInt(
  279. getComputedStyle(textarea).lineHeight,
  280. 10
  281. );
  282. const maxHeight = lineHeight * 5; // 统一为5行
  283. const newHeight = Math.min(textarea.scrollHeight, maxHeight);
  284. textarea.style.height = `${newHeight}px`;
  285. });
  286. };
  287. // 检查是否应该显示浮动窗口(需要同时满足:有焦点 + 内容超出)
  288. // 修复新增页面点击就出现floatdiv的问题 by xu 20251212
  289. const checkShouldShowFloatingDiv = () => {
  290. const textarea = inputRef.value;
  291. if (!textarea) return false;
  292. // 首先检查是否有内容,没有内容时不显示floatdiv by xu 20251212
  293. if (!inputValue.value || inputValue.value.toString().trim() === "") {
  294. console.log("[floatdiv] 内容为空,不显示floatdiv");
  295. return false;
  296. }
  297. // 判断内容是否超出 by xu 20251212
  298. // 同时检查横向和纵向溢出,任一方向溢出都应显示floatdiv
  299. // 纵向溢出需要加容差值,避免padding/border导致的误判 by xu 20251212
  300. const verticalTolerance = 5; // 容差值5px
  301. const isHorizontalOverflow =
  302. textarea.scrollWidth > textarea.clientWidth;
  303. const isVerticalOverflow =
  304. textarea.scrollHeight > textarea.clientHeight + verticalTolerance;
  305. const isOverflow = isHorizontalOverflow || isVerticalOverflow;
  306. console.log(
  307. "[floatdiv] 溢出检测 - scrollWidth:",
  308. textarea.scrollWidth,
  309. "clientWidth:",
  310. textarea.clientWidth,
  311. "horizontalOverflow:",
  312. isHorizontalOverflow
  313. );
  314. console.log(
  315. "[floatdiv] 溢出检测 - scrollHeight:",
  316. textarea.scrollHeight,
  317. "clientHeight:",
  318. textarea.clientHeight,
  319. "tolerance:",
  320. verticalTolerance,
  321. "verticalOverflow:",
  322. isVerticalOverflow
  323. );
  324. const shouldShow = isFocused.value && isOverflow;
  325. console.log(
  326. "[floatdiv] 最终判断 - isFocused:",
  327. isFocused.value,
  328. "isOverflow:",
  329. isOverflow,
  330. "shouldShow:",
  331. shouldShow
  332. );
  333. // 需要同时满足:有焦点 + 内容超出
  334. return shouldShow;
  335. };
  336. // 定义事件处理函数
  337. const onInput = (event) => {
  338. const newValue = event.target.value;
  339. inputValue.value = newValue;
  340. emit("update:modelValue", newValue);
  341. validate(); // 输入时验证
  342. nextTick(() => {
  343. // 检查是否需要显示浮动div
  344. contentFloatingDiv.value = checkShouldShowFloatingDiv();
  345. // 如果需要显示floatdiv,计算其位置
  346. if (contentFloatingDiv.value) {
  347. calculateFloatingDivPosition();
  348. }
  349. });
  350. adjustHeight();
  351. };
  352. const onFocus = (event) => {
  353. // 设置焦点状态为true
  354. isFocused.value = true;
  355. adjustHeight();
  356. // 检查是否应该显示浮动窗口
  357. nextTick(() => {
  358. contentFloatingDiv.value = checkShouldShowFloatingDiv();
  359. if (contentFloatingDiv.value) {
  360. calculateFloatingDivPosition();
  361. }
  362. });
  363. };
  364. // 失去焦点时进行验证
  365. const onBlur = (event) => {
  366. emit("blur", event.target);
  367. validate(); // 失焦时验证
  368. nextTick(() => {
  369. // 如果焦点不在 textarea 上,则隐藏浮动 div
  370. if (!document.activeElement.classList.contains("input-control")) {
  371. isFocused.value = false;
  372. contentFloatingDiv.value = false;
  373. }
  374. });
  375. };
  376. const onChange = (event) => {
  377. inputValue.value = event.target.value || "";
  378. emit("change", inputValue.value);
  379. };
  380. const onMouseover = (event) => {
  381. nextTick(() => {
  382. // setTimeout(contentFloatingDiv.value = true, 500)
  383. });
  384. };
  385. const onMouseleave = (event) => {
  386. // contentFloatingDiv.value = false
  387. };
  388. // 功能说明:传了 height 视为多行允许回车;未传 height 拦截回车(单行表现) by xu 20260204
  389. const onKeydown = (event) => {
  390. const allowMultiline =
  391. typeof props.height === "string" && props.height.trim() !== "";
  392. if (!allowMultiline && event.key === "Enter") {
  393. event.preventDefault();
  394. }
  395. };
  396. // 附件按钮点击处理(从 SsEditor 搬运)
  397. const onAttachmentClick = (e) => {
  398. e.preventDefault();
  399. if (!props.param || !props.param.button) {
  400. console.warn("未配置 param 参数");
  401. return;
  402. }
  403. console.log("附件点击了");
  404. console.log("param", props.param);
  405. console.log("cmsAddUrl", props.param.button.cmsAddUrl);
  406. // 如果 fjid 为空,先调用 cmsAddUrl 创建
  407. if (fjid.value == null || fjid.value == "") {
  408. $.ajax({
  409. type: "post",
  410. url: props.param.button.cmsAddUrl,
  411. async: false,
  412. data: {
  413. name: "fjid",
  414. ssNrObjName: "sh",
  415. ssNrObjId: "",
  416. },
  417. success: function (_fjid) {
  418. console.log("cmsAddUrl success", _fjid);
  419. fjid.value = _fjid;
  420. },
  421. });
  422. }
  423. // 构建参数字符串
  424. var str =
  425. "&nrid=T-" +
  426. fjid.value +
  427. "&objectId=" +
  428. fjid.value +
  429. "&objectName=" +
  430. fjName +
  431. "&callback=" +
  432. (window["fjidCallbackName"] || "");
  433. console.log("str", str);
  434. // 打开附件编辑对话框
  435. SS.openDialog({
  436. src: props.param.button.cmsUpdUrl + str,
  437. headerTitle: "编辑",
  438. width: 900,
  439. high: 664,
  440. zIndex: 51,
  441. });
  442. };
  443. return {
  444. errMsg,
  445. inputValue,
  446. showRequired,
  447. onInput,
  448. onBlur,
  449. onChange,
  450. onMouseover,
  451. onMouseleave,
  452. onKeydown, // 新增:键盘事件处理 by xu 20251212
  453. contentFloatingDiv,
  454. floatingDivPosition,
  455. getFloatingDivTop,
  456. inputRef,
  457. textareaRef,
  458. onFocus,
  459. onAttachmentClick,
  460. fjid, // 附件 ID,用于隐藏字段
  461. };
  462. },
  463. render() {
  464. const { resolveComponent, h } = Vue;
  465. const SsIcon = resolveComponent("ss-icon");
  466. const SsEditorIcon = resolveComponent("SsEditorIcon");
  467. // 构建主textarea的样式
  468. const mainTextareaStyle = {};
  469. if (this.height) {
  470. mainTextareaStyle.height = "auto";
  471. // mainTextareaStyle.paddingTop = '5px'; // 有高度时加上padding-top
  472. // mainTextareaStyle.paddingBottom = '5px'; // 有高度时加上padding-bottom
  473. } else {
  474. // 没有指定height时,固定为单行高度
  475. mainTextareaStyle.height = "20px"; // 行高20px
  476. mainTextareaStyle.lineHeight = "20px"; // 确保单行垂直居中
  477. mainTextareaStyle.display = "flex";
  478. mainTextareaStyle.marginBottom = "5px";
  479. }
  480. // 如果有附件按钮,为按钮留出空间
  481. if (this.fj || (this.param && this.param.button)) {
  482. //加上&&this.param.button条件 Ben(20251221)
  483. mainTextareaStyle.paddingRight = "75px";
  484. }
  485. const mainTextareaRows = this.height
  486. ? Math.floor(parseFloat("80px") / 20)
  487. : 1;
  488. return h("div", { class: "input" }, [
  489. h("div", { class: "input-container" }, [
  490. h("div", { class: "input", style: "padding:5px 0" }, [
  491. h("textarea", {
  492. ref: "inputRef",
  493. class: "input-control",
  494. name: this.name,
  495. value: this.inputValue,
  496. onInput: this.onInput,
  497. onFocus: this.onFocus,
  498. onBlur: this.onBlur,
  499. onChange: this.onChange,
  500. onKeydown: this.onKeydown, // 新增:禁止回车换行 by xu 20251212
  501. placeholder: this.placeholder,
  502. onMouseover: this.onMouseover, // 监听鼠标悬停
  503. onMouseleave: this.onMouseleave, // 监听鼠标离开
  504. rows: mainTextareaRows,
  505. ...this.$attrs,
  506. style: mainTextareaStyle,
  507. autocomplete: "off",
  508. }),
  509. // 附件按钮(优先使用 param,兼容旧的 fj)
  510. this.fj || (this.param && this.param.button) //加上&&this.param.button条件 Ben(20251221)
  511. ? h(
  512. "button",
  513. {
  514. type: "button",
  515. class: "fj-button",
  516. onClick: this.param
  517. ? this.onAttachmentClick
  518. : (e) => {
  519. e.preventDefault();
  520. console.log("附件配置:", this.fj);
  521. },
  522. },
  523. [
  524. h(SsEditorIcon, {
  525. class: "editor-icon-link",
  526. }),
  527. h("span", { class: "fj-button-text" }, "附件"),
  528. ]
  529. )
  530. : null,
  531. // this.showRequired ? h("div", { class: "required" }) : null,
  532. ]),
  533. this.contentFloatingDiv || ""
  534. ? h(
  535. "div",
  536. {
  537. class: "floating-div",
  538. style:
  539. this.floatingDivPosition === "bottom"
  540. ? {
  541. // 向下展开: 覆盖原输入框,top对齐首行
  542. top: this.getFloatingDivTop,
  543. bottom: "auto",
  544. }
  545. : {
  546. // 向上展开: 同样覆盖原输入框,但从底部开始计算
  547. top: "auto",
  548. bottom: this.height ? "5px" : "6px", // 对齐到原textarea的底部padding位置
  549. },
  550. },
  551. [
  552. h("textarea", {
  553. ref: "textareaRef",
  554. class: "input-control",
  555. value: this.inputValue,
  556. onInput: this.onInput,
  557. onBlur: this.onBlur,
  558. onFocus: this.onFocus,
  559. onKeydown: this.onKeydown, // 新增:禁止回车换行 by xu 20251212
  560. onMouseover: this.onMouseover, // 监听鼠标悬停
  561. onMouseleave: this.onMouseleave, // 监听鼠标离开
  562. autocomplete: "off",
  563. onVnodeMounted: (vnode) => {
  564. vnode.el.focus();
  565. },
  566. }),
  567. ]
  568. )
  569. : null,
  570. // this.errMsg ? h(SsValidate, { errMsg: this.errMsg }) : null,
  571. ]),
  572. // 附件相关的隐藏字段(仅在有 param 时才渲染)
  573. this.param && [
  574. // fjid 隐藏字段(只有当 fjid 有值时才渲染)
  575. this.fjid &&
  576. this.fjid.value &&
  577. h("input", {
  578. type: "hidden",
  579. name: "fjid",
  580. value: this.fjid.value,
  581. }),
  582. // 其他隐藏字段根据 name 生成
  583. /* 去掉。文本框不需要(这是富文本才有的) Ben 20251205
  584. h("input", {
  585. type: "hidden",
  586. name: this.name.replace(/wj$/, "") + "Edit",
  587. value: this.inputValue
  588. }),
  589. */
  590. // h("input", {
  591. // type: "hidden",
  592. // name: this.name.replace(/wj$/, "") + "wj",
  593. // value: this.inputValue
  594. // }),
  595. /* 去掉。文本框不需要(这是富文本才有的) Ben 20251205
  596. h("input", {
  597. type: "hidden",
  598. name: "ueditorpath",
  599. value: this.name
  600. }),
  601. */
  602. ],
  603. ]);
  604. },
  605. };
  606. // ss-normal-input 登录输入
  607. const SsLoginInput = {
  608. name: "SsLoginInput",
  609. inheritAttrs: false,
  610. props: {
  611. errTip: {
  612. type: String,
  613. },
  614. type: {
  615. type: String,
  616. default: "text",
  617. },
  618. required: {
  619. type: Boolean,
  620. default: false,
  621. },
  622. placeholder: {
  623. type: String,
  624. default: "请输入",
  625. },
  626. name: {
  627. type: String,
  628. default: "",
  629. },
  630. defaultValue: [String, Number],
  631. modelValue: [String, Number],
  632. },
  633. emits: ["update:modelValue", "input", "blur", "change"], // 允许更新 v-model 绑定的值
  634. setup(props, { emit }) {
  635. const errMsg = ref("");
  636. const inputRef = ref(null);
  637. const textareaRef = ref(null);
  638. const inputValue = ref(props.modelValue || props.defaultValue || "");
  639. // 使用 watch 监听 props.errTip 和 props.modelValue 的变化
  640. watch(
  641. () => props.errTip,
  642. (newVal) => {
  643. errMsg.value = newVal;
  644. },
  645. { immediate: true }
  646. );
  647. watch(
  648. () => props.modelValue,
  649. (newVal) => {
  650. inputValue.value = newVal;
  651. }
  652. );
  653. // 挂载时的逻辑
  654. onMounted(() => {
  655. errMsg.value = props.errTip;
  656. inputValue.value = props.modelValue || props.defaultValue || "";
  657. });
  658. // 定义事件处理函数
  659. const onInput = (event) => {
  660. const newValue = event.target.value;
  661. inputValue.value = newValue;
  662. emit("update:modelValue", newValue);
  663. };
  664. return { inputValue, onInput, inputRef, textareaRef };
  665. },
  666. render() {
  667. return h("div", { class: "input" }, [
  668. h("div", { class: "input-container" }, [
  669. h("div", { class: "input" }, [
  670. h("input", {
  671. ref: "inputRef",
  672. class: "input-control",
  673. name: this.name,
  674. value: this.inputValue,
  675. onInput: this.onInput,
  676. type: this.type,
  677. placeholder: this.placeholder,
  678. required: this.required,
  679. ...this.$attrs,
  680. autocomplete: "off",
  681. }),
  682. this.required ? h("div", { class: "required" }) : null,
  683. ]),
  684. ]),
  685. ]);
  686. },
  687. };
  688. // ss-login-button
  689. const SsLoginButton = {
  690. name: "SsLoginButton",
  691. inheritAttrs: false,
  692. props: {
  693. class: {
  694. type: String,
  695. default: "",
  696. },
  697. text: {
  698. type: String,
  699. default: "",
  700. },
  701. type: {
  702. type: String,
  703. default: "button",
  704. },
  705. },
  706. emits: ["click"],
  707. setup(props, { emit }) {
  708. // 定义事件处理函数
  709. const onClick = (event) => {
  710. // 发射一个 'click' 事件,你可以传递所需的参数
  711. emit("click", event);
  712. };
  713. return { props, onClick };
  714. },
  715. render() {
  716. const SsIcon = resolveComponent("ss-icon");
  717. const SsLoginIcon = resolveComponent("ss-login-icon");
  718. return h(
  719. "button",
  720. { class: "login-button", type: this.type, onClick: this.onClick },
  721. [
  722. h("span", [h(SsLoginIcon, { class: this.class })]),
  723. h("span", {}, this.text),
  724. ]
  725. );
  726. },
  727. };
  728. // ss-objp 下拉选择
  729. const SsObjp = {
  730. name: "SsObjp",
  731. inheritAttrs: false,
  732. props: {
  733. onchange: {
  734. //在此属性传入onChange的window全局回调函数,函数唯一参数是当前选中值 Ben(20251217)
  735. type: String,
  736. required: false,
  737. },
  738. filter: {
  739. type: String,
  740. required: false,
  741. },
  742. cb: {
  743. type: String,
  744. required: true,
  745. },
  746. url: {
  747. type: String,
  748. required: true,
  749. },
  750. name: {
  751. type: String,
  752. required: true,
  753. },
  754. width: {
  755. type: String,
  756. default: "100%",
  757. },
  758. placeholder: {
  759. type: String,
  760. default: "请选择",
  761. },
  762. inp: {
  763. type: Boolean,
  764. default: false,
  765. },
  766. opt: {
  767. type: Array,
  768. default: () => [],
  769. },
  770. errTip: String,
  771. defaultValue: [String, Number],
  772. modelValue: [String, Number],
  773. direction: {
  774. type: String,
  775. default: "bottom",
  776. },
  777. },
  778. emits: ["update:modelValue", "input", "blur", "change"],
  779. setup(props, { emit }) {
  780. const canInput = props.inp;
  781. const errMsg = Vue.ref(props.errTip);
  782. const selectItem = Vue.ref({});
  783. let inputText = Vue.ref(""); // 用于存储输入框的文本
  784. const popupWinVisible = Vue.ref(false);
  785. const filteredOptions = Vue.ref(props.opt);
  786. const popupDirection = Vue.ref("bottom");
  787. const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
  788. const popupContentAreaMaxHeight = Vue.computed(() => {
  789. if (!popupMaxHeight.value || popupMaxHeight.value === "none")
  790. return null;
  791. const maxHeightNum = Number.parseFloat(popupMaxHeight.value);
  792. if (!Number.isFinite(maxHeightNum)) return null;
  793. // 功能说明:滚动条统一落在 .content-area(CSS 默认如此),因此需要扣掉 popup-win padding-top(10) 与 popup-content padding(15*2) by xu 20260126
  794. const contentAreaMaxHeight = Math.max(60, maxHeightNum - 40);
  795. return `${contentAreaMaxHeight}px`;
  796. });
  797. // 修复表格内下拉弹层被 overflow 截断:popup 使用 Teleport 到 body + fixed 定位 by xu 20260126
  798. const selectContainerRef = Vue.ref(null);
  799. const popupRef = Vue.ref(null);
  800. const teleportRootStyle = Vue.ref({
  801. position: "fixed",
  802. left: "0",
  803. top: "0",
  804. width: "0",
  805. height: "0",
  806. zIndex: 9999,
  807. pointerEvents: "none",
  808. });
  809. const popupLayerStyle = Vue.ref({
  810. position: "fixed",
  811. left: "0",
  812. top: "0",
  813. bottom: "auto", // 功能说明:覆盖 .popup-win.top 的 bottom 定位,避免 fixed 场景被撑高/错位 by xu 20260126
  814. minWidth: "0",
  815. zIndex: 9999,
  816. pointerEvents: "auto",
  817. });
  818. // const showRequired = Vue.computed(() => {
  819. // const hasValidationRule = window.ssVm?.validations?.has(props.name);
  820. // if (!hasValidationRule) return false;
  821. // if (errMsg.value) return true;
  822. // if (!selectItem.value?.value) return true;
  823. // return false;
  824. // });
  825. const validate = () => {
  826. if (window.ssVm) {
  827. const result = window.ssVm.validateField(props.name);
  828. // console.log("validate", window.ssVm.validateField(props.name));
  829. errMsg.value = result.valid ? "" : result.message;
  830. }
  831. };
  832. //在objPicker界面,选中value对应的项
  833. const updateSelectItem = () => {
  834. // console.log(props.opt);
  835. const item = props.opt.find((it) => it.value === props.modelValue);
  836. if (item) {
  837. selectItem.value = item;
  838. inputText.value = item.label;
  839. } else {
  840. selectItem.value = { label: "", value: "" };
  841. inputText.value = "";
  842. }
  843. // validate();
  844. };
  845. Vue.watch(
  846. () => props.errTip,
  847. (newVal) => {
  848. errMsg.value = newVal;
  849. }
  850. );
  851. Vue.watch(() => props.modelValue, updateSelectItem, { immediate: true });
  852. Vue.watch(
  853. () => props.opt,
  854. (newVal) => {
  855. updateSelectItem();
  856. filteredOptions.value = [...newVal];
  857. // console.log("filteredOptions", filteredOptions.value);
  858. }
  859. );
  860. //初始化objPicker在页面刚打开时的默认值
  861. async function initDefaultValue() {
  862. try {
  863. if (props.url && props.cb && props.modelValue) {
  864. let objectPickerParam;
  865. let url = props.url;
  866. //如果有定义过滤器
  867. if (props.filter) {
  868. //包含HTML实体的JSON字符串转为JSON对象,如原字符串是{&quot;dwid&quot;:&quot;88&quot;},注意key也必需用单引号包着
  869. // const decodedString = props.filter.replace(/&quot;/g, '"'); // 转换为: {"dwid":"88"}
  870. // objectPickerParam = JSON.parse(decodedString); // 转为json对象
  871. const filterObj = props.filter; // 转为json对象
  872. for (let k in filterObj) {
  873. let v = filterObj[k];
  874. url += "&" + k + "=" + v;
  875. }
  876. objectPickerParam = props.filter; // 转为json对象
  877. objectPickerParam["input"] = props.inp;
  878. objectPickerParam["codebook"] = props.cb;
  879. // alert(url);
  880. } else {
  881. objectPickerParam = { input: props.inp, codebook: props.cb };
  882. }
  883. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  884. const params = new URLSearchParams();
  885. params.append("objectpickerparam", objectPickerParamStr);
  886. params.append("objectpickertype", "2");
  887. params.append("objectpickervalue", props.modelValue); //需回显的值
  888. // alert("1params:"+JSON.stringify(params));
  889. axios
  890. .post(props.url, params, {
  891. headers: {
  892. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  893. },
  894. })
  895. .then((response) => {
  896. // alert(JSON.stringify(response.data));
  897. if ("timeout" == response.data.statusText) {
  898. alert("网络超时!");
  899. return;
  900. }
  901. if (response.data.result) {
  902. const keys = Object.keys(response.data.result);
  903. if (keys.length === 1) {
  904. let code = keys[0];
  905. let desc = response.data.result[keys[0]];
  906. if (props.opt)
  907. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  908. else {
  909. props.opt = [];
  910. }
  911. props.opt.push({ label: desc, value: code });
  912. updateSelectItem();
  913. // alert('props.opt:'+JSON.stringify(props.opt));
  914. }
  915. }
  916. });
  917. }
  918. } catch (error) {
  919. // callback(null, error.message); // 失败回调,传递错误
  920. }
  921. }
  922. // Vue.onMounted(updateSelectItem);
  923. const doSelectItem = (item) => {
  924. emit("update:modelValue", item.value);
  925. selectItem.value = item;
  926. inputText.value = item.label;
  927. hidePopup();
  928. nextTick(() => {
  929. console.log(item.value + "@@@props.modelValue:" + props.modelValue);
  930. validate();
  931. if (window.ssVm) {
  932. // 遍历所有验证规则,找到依赖当前字段的规则
  933. for (const [field, rules] of window.ssVm.validations.entries()) {
  934. for (const rule of rules) {
  935. if (rule.opt?.relField === props.name) {
  936. // console.log("Found dependent field:", field); // 调试日志
  937. window.ssVm.validateField(field);
  938. }
  939. }
  940. }
  941. }
  942. });
  943. callGlobalOnchg(item.value, item.label); // 值变化时尝试调用全局onchange回调函数 Ben(20251217)
  944. };
  945. // 用于调用全局onchange回调函数 Ben(20251217)
  946. const callGlobalOnchg = (value, desc) => {
  947. // 检查 onchange 属性是否提供了有效的函数名
  948. if (props.onchange && typeof props.onchange === "string") {
  949. // 检查 window 对象上是否存在该函数
  950. if (
  951. typeof window !== "undefined" &&
  952. window[props.onchange] &&
  953. typeof window[props.onchange] === "function"
  954. ) {
  955. try {
  956. window[props.onchange](value, desc); // 调用全局函数,并传入当前选中值
  957. } catch (error) {
  958. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  959. }
  960. } else {
  961. console.warn(`全局函数 ${props.onchange} 未定义或不是一个函数。`);
  962. }
  963. }
  964. };
  965. //可录入的objPicker,更新下拉菜单选项
  966. async function updateOptionBYInputText(inpTxt) {
  967. try {
  968. let objectPickerParam;
  969. let url = props.url;
  970. if (props.url && props.cb) {
  971. //如果有定义过滤器
  972. if (props.filter) {
  973. const filterObj = props.filter; // 转为json对象
  974. for (let k in filterObj) {
  975. let v = filterObj[k];
  976. url += "&" + k + "=" + v;
  977. }
  978. //包含HTML实体的JSON字符串转为JSON对象,如原字符串是{&quot;dwid&quot;:&quot;88&quot;},注意key也必需用单引号包着
  979. // const decodedString = props.filter.replace(/&quot;/g, '"'); // 转换为: {"dwid":"88"}
  980. // objectPickerParam = JSON.parse(decodedString); // 转为json对象
  981. objectPickerParam = props.filter;
  982. objectPickerParam["input"] = props.inp;
  983. objectPickerParam["codebook"] = props.cb;
  984. // alert(url);
  985. } else {
  986. objectPickerParam = { input: props.inp, codebook: props.cb };
  987. }
  988. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  989. const params = new URLSearchParams();
  990. params.append("objectpickerparam", objectPickerParamStr);
  991. params.append("objectpickertype", "1");
  992. if (props.inp && props.inp === true) {
  993. //把"true"改为true Ben(20251209)
  994. params.append("objectpickersearchAll", 0); //只查录入的值
  995. params.append("objectpickerinput", inpTxt); //录入的值
  996. } else {
  997. params.append("objectpickersearchAll", 1);
  998. }
  999. axios
  1000. .post(url, params, {
  1001. headers: {
  1002. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1003. },
  1004. })
  1005. .then((response) => {
  1006. if ("timeout" == response.data.statusText) {
  1007. alert("网络超时!");
  1008. return;
  1009. }
  1010. // 先清空选项 by xu 20251212
  1011. if (props.opt) {
  1012. props.opt.length = 0;
  1013. } else {
  1014. props.opt = [];
  1015. }
  1016. if (response.data.result) {
  1017. const keys = Object.keys(response.data.result);
  1018. // console.log("params:"+params+"@@response.data:"+JSON.stringify(response.data));
  1019. if (keys.length > 0) {
  1020. for (let k in response.data.result) {
  1021. props.opt.push({
  1022. label: response.data.result[k],
  1023. value: k,
  1024. });
  1025. }
  1026. // console.log('###inpTxt:'+inpTxt+';');
  1027. if (
  1028. props.inp &&
  1029. props.inp === true && //把"true"改为true Ben(20251209)
  1030. inpTxt.length > 0
  1031. ) {
  1032. //对于可录入的,用已录入的值作过滤
  1033. filteredOptions.value = props.opt.filter((option) =>
  1034. option.label
  1035. .toLowerCase()
  1036. .includes(inputText.value.toLowerCase())
  1037. );
  1038. // 可录入的objPicker,当搜索结果只有一项时,自动选中这一项 by xu 20251212
  1039. if (filteredOptions.value.length === 1) {
  1040. const autoSelectItem = filteredOptions.value[0];
  1041. console.log(
  1042. "[objp] 搜索结果只有一项,自动选中:",
  1043. autoSelectItem
  1044. );
  1045. doSelectItem(autoSelectItem);
  1046. return; // 自动选中后直接返回,不需要显示popup
  1047. }
  1048. filteredOptions.value.unshift({ label: "", value: "" });
  1049. // console.log('###做了过滤:'+inputText.value.toLowerCase()+';');
  1050. } else {
  1051. filteredOptions.value = props.opt;
  1052. filteredOptions.value.unshift({ label: "", value: "" });
  1053. }
  1054. console.log("props.opt11:" + JSON.stringify(props.opt));
  1055. } else {
  1056. // 没有数据时,清空过滤选项 by xu 20251212
  1057. filteredOptions.value = [];
  1058. console.log("[objp] 接口返回空数据");
  1059. }
  1060. } else {
  1061. // result不存在时,清空过滤选项 by xu 20251212
  1062. filteredOptions.value = [];
  1063. console.log("[objp] 接口返回无result");
  1064. }
  1065. // 无论是否有数据,都显示popup by xu 20251212
  1066. openPopup(); // Teleport 场景下统一打开并重定位 by xu 20260126
  1067. });
  1068. }
  1069. } catch (error) {
  1070. // callback(null, error.message); // 失败回调,传递错误
  1071. }
  1072. }
  1073. // 计算弹出方向和最大高度的方法 by xu 20251212
  1074. // 当空间不足时限制popup高度并显示滚动条
  1075. const calculatePopupDirection = () => {
  1076. const triggerEl =
  1077. selectContainerRef.value?.querySelector(".input") ||
  1078. selectContainerRef.value;
  1079. if (!triggerEl) return;
  1080. const selectRect = triggerEl.getBoundingClientRect();
  1081. const viewportHeight = window.innerHeight;
  1082. // 3. 计算上下可用空间
  1083. const spaceBelow = viewportHeight - selectRect.bottom - 10; // 减10px留边距
  1084. const spaceAbove = selectRect.top - 10; // 减10px留边距
  1085. // 4. popup预估高度(假设每项36px,最多显示8项 + padding)
  1086. const estimatedPopupHeight = 300;
  1087. const minPopupHeight = 100; // 最小高度
  1088. console.log(
  1089. "[popup] 空间计算 - spaceAbove:",
  1090. spaceAbove,
  1091. "spaceBelow:",
  1092. spaceBelow,
  1093. "estimatedHeight:",
  1094. estimatedPopupHeight
  1095. );
  1096. // 5. 判断方向和最大高度 by xu 20251212
  1097. if (spaceBelow >= estimatedPopupHeight) {
  1098. // 下方空间足够,向下展开,不限制高度
  1099. popupDirection.value = "bottom";
  1100. popupMaxHeight.value = "none";
  1101. console.log("[popup] 向下展开,空间充足");
  1102. } else if (spaceAbove >= estimatedPopupHeight) {
  1103. // 上方空间足够,向上展开,不限制高度
  1104. popupDirection.value = "top";
  1105. popupMaxHeight.value = "none";
  1106. console.log("[popup] 向上展开,空间充足");
  1107. } else {
  1108. // 上下空间都不足,选择空间大的方向,并限制高度出滚动条
  1109. if (spaceBelow >= spaceAbove) {
  1110. popupDirection.value = "bottom";
  1111. popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px";
  1112. console.log(
  1113. "[popup] 向下展开,空间不足,限制高度:",
  1114. popupMaxHeight.value
  1115. );
  1116. } else {
  1117. popupDirection.value = "top";
  1118. popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px";
  1119. console.log(
  1120. "[popup] 向上展开,空间不足,限制高度:",
  1121. popupMaxHeight.value
  1122. );
  1123. }
  1124. }
  1125. };
  1126. // Teleport popup 的定位(fixed) by xu 20260126
  1127. const updatePopupPosition = () => {
  1128. const triggerEl =
  1129. selectContainerRef.value?.querySelector(".input") ||
  1130. selectContainerRef.value;
  1131. if (!triggerEl) return;
  1132. const triggerRect = triggerEl.getBoundingClientRect();
  1133. const margin = 10;
  1134. const viewportWidth = window.innerWidth;
  1135. const viewportHeight = window.innerHeight;
  1136. const popupGap = 0; // 功能说明:定位不再做 -10 重叠,让 padding-top 自然形成间距 by xu 20260126
  1137. // 先给一个初始位置,确保下一帧可以测量弹层尺寸 by xu 20260126
  1138. popupLayerStyle.value = {
  1139. position: "fixed",
  1140. left: `${Math.max(margin, triggerRect.left)}px`,
  1141. top: `${Math.max(margin, triggerRect.bottom + popupGap)}px`, // 功能说明:与输入框底部对齐 by xu 20260126
  1142. bottom: "auto", // 功能说明:fixed 场景显式取消 bottom,避免与 top 同时生效 by xu 20260126
  1143. minWidth: `${Math.max(0, triggerRect.width)}px`,
  1144. zIndex: 9999,
  1145. pointerEvents: "auto",
  1146. };
  1147. Vue.nextTick(() => {
  1148. const popupEl = popupRef.value;
  1149. if (!popupEl) return;
  1150. const popupRect = popupEl.getBoundingClientRect();
  1151. const maxLeft = viewportWidth - popupRect.width - margin;
  1152. const left = Math.min(
  1153. Math.max(margin, triggerRect.left),
  1154. Math.max(margin, maxLeft)
  1155. );
  1156. let top;
  1157. if (popupDirection.value === "top") {
  1158. top = triggerRect.top - popupRect.height - popupGap; // 功能说明:向上展开时与输入框顶部对齐 by xu 20260126
  1159. top = Math.max(margin, top);
  1160. } else {
  1161. top = triggerRect.bottom + popupGap; // 功能说明:向下展开时与输入框底部对齐 by xu 20260126
  1162. if (top + popupRect.height > viewportHeight - margin) {
  1163. top = Math.max(
  1164. margin,
  1165. viewportHeight - popupRect.height - margin
  1166. );
  1167. }
  1168. }
  1169. popupLayerStyle.value = {
  1170. ...popupLayerStyle.value,
  1171. left: `${left}px`,
  1172. top: `${top}px`,
  1173. bottom: "auto", // 功能说明:无论 top/bottom 展开都用 top 定位,禁用 bottom by xu 20260126
  1174. };
  1175. });
  1176. };
  1177. const openPopup = () => {
  1178. if (!popupWinVisible.value) popupWinVisible.value = true;
  1179. Vue.nextTick(() => {
  1180. calculatePopupDirection();
  1181. updatePopupPosition();
  1182. });
  1183. };
  1184. // Teleport 场景下:滚动/缩放重定位 by xu 20260126
  1185. const handleViewportChange = () => {
  1186. if (!popupWinVisible.value) return;
  1187. calculatePopupDirection();
  1188. updatePopupPosition();
  1189. };
  1190. // Teleport 场景下:点击外部关闭 by xu 20260126
  1191. const onDocPointerDown = (event) => {
  1192. if (!popupWinVisible.value) return;
  1193. const target = event.target;
  1194. if (selectContainerRef.value?.contains(target)) return;
  1195. if (popupRef.value?.contains(target)) return;
  1196. hidePopup();
  1197. };
  1198. //点击下拉菜单的文本区域时,会触发的方法
  1199. function togglePopup() {
  1200. // 可录入的 objPicker,更新下拉菜单选项
  1201. updateOptionBYInputText(inputText.value);
  1202. // popupWinVisible.value = !popupWinVisible.value;
  1203. Vue.nextTick(() => {
  1204. calculatePopupDirection();
  1205. updatePopupPosition(); // Teleport 场景下同步定位 by xu 20260126
  1206. });
  1207. }
  1208. const hidePopup = () => {
  1209. popupWinVisible.value = false;
  1210. };
  1211. //点击下拉菜单的三角形时,会触发的方法
  1212. // 添加toggle逻辑,点击时切换显示/隐藏 by xu 20251212
  1213. const suffixClick = () => {
  1214. // 如果popup已显示,则关闭 by xu 20251212
  1215. if (popupWinVisible.value) {
  1216. hidePopup();
  1217. console.log("[objp] 点三角关闭popup");
  1218. return;
  1219. }
  1220. //可录入的objPicker,更新下拉菜单选项
  1221. updateOptionBYInputText("");
  1222. Vue.nextTick(() => {
  1223. calculatePopupDirection();
  1224. updatePopupPosition(); // Teleport 场景下同步定位 by xu 20260126
  1225. });
  1226. console.log("[objp] 点三角打开popup");
  1227. };
  1228. //可录入的objPicker,录入项变化时,会触发
  1229. async function handleInputChange(event) {
  1230. inputText.value = event.target.value;
  1231. if (!inputText.value) {
  1232. inputText.value = "";
  1233. }
  1234. //可录入的objPicker,更新下拉菜单选项
  1235. updateOptionBYInputText(inputText.value);
  1236. // filteredOptions.value = props.opt.filter((option) =>
  1237. // option.label.toLowerCase().includes(inputText.value.toLowerCase())
  1238. // );
  1239. // if (!popupWinVisible.value) {
  1240. // popupWinVisible.value = true; // 确保下拉框在输入时打开
  1241. // }
  1242. }
  1243. Vue.onMounted(() => {
  1244. initDefaultValue();
  1245. // Teleport 场景下:滚动/缩放需要重定位(scroll 用 capture 捕获容器滚动) by xu 20260126
  1246. window.addEventListener("resize", handleViewportChange);
  1247. window.addEventListener("scroll", handleViewportChange, true);
  1248. // 点击外部关闭(原本依赖 mouseleave,Teleport 后会误关) by xu 20260126
  1249. document.addEventListener("pointerdown", onDocPointerDown, true);
  1250. });
  1251. Vue.onUnmounted(() => {
  1252. window.removeEventListener("resize", handleViewportChange);
  1253. window.removeEventListener("scroll", handleViewportChange, true);
  1254. document.removeEventListener("pointerdown", onDocPointerDown, true);
  1255. });
  1256. return {
  1257. errMsg,
  1258. selectItem,
  1259. inputText,
  1260. canInput,
  1261. filteredOptions,
  1262. popupWinVisible,
  1263. popupDirection,
  1264. popupMaxHeight, // 添加popup最大高度 by xu 20251212
  1265. popupContentAreaMaxHeight,
  1266. selectContainerRef,
  1267. popupRef,
  1268. teleportRootStyle,
  1269. popupLayerStyle,
  1270. suffixClick,
  1271. togglePopup,
  1272. hidePopup,
  1273. doSelectItem,
  1274. handleInputChange,
  1275. };
  1276. },
  1277. template: `
  1278. <div class="input" style="position: relative" :style="{width: width}">
  1279. <div class="select-container" ref="selectContainerRef">
  1280. <div class="input" @click="togglePopup">
  1281. <input
  1282. type="hidden"
  1283. :name="name"
  1284. :value="selectItem.value"
  1285. .value="selectItem.value"
  1286. />
  1287. <input
  1288. v-model="inputText"
  1289. @input="handleInputChange"
  1290. v-if="canInput"
  1291. :placeholder="placeholder"
  1292. />
  1293. <input
  1294. v-else
  1295. :placeholder="placeholder"
  1296. :value="selectItem.label"
  1297. disabled
  1298. style="pointer-events: none;"
  1299. />
  1300. <div class="suffix" @click.stop="suffixClick">
  1301. <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
  1302. </div>
  1303. </div>
  1304. <!-- 修复表格内弹层被截断:popup Teleport 到 body by xu 20260126 -->
  1305. <teleport to="body">
  1306. <div v-show="popupWinVisible" class="select-container ss-objp-teleport-root" :style="teleportRootStyle">
  1307. <!-- popup弹出层,添加maxHeight和overflowY支持空间不足时滚动 by xu 20251212 -->
  1308. <div ref="popupRef" class="popup-win" :class="popupDirection" :style="[popupLayerStyle, { maxHeight: popupMaxHeight !== 'none' ? popupMaxHeight : 'none', overflowY: 'visible' }]">
  1309. <div v-if="opt && opt.length && filteredOptions.length > 0" class="popup-content">
  1310. <div class="content-area" :style="popupContentAreaMaxHeight ? { maxHeight: popupContentAreaMaxHeight, overflowY: 'auto' } : null">
  1311. <div v-for="(item, index) in filteredOptions" :key="index" @click="doSelectItem(item)" :class="{ active: item.value === selectItem.value }">
  1312. <span class="check-icon">
  1313. <ss-form-icon class="form-icon-select-checked" />
  1314. </span>
  1315. <span>{{ item.label }}</span>
  1316. </div>
  1317. </div>
  1318. </div>
  1319. <div v-else class="popup-content"><div class="content-area"><div class="content-area"> <span>无选项</span></div></div></div>
  1320. </div>
  1321. </div>
  1322. </teleport>
  1323. </div>
  1324. </div>
  1325. `,
  1326. };
  1327. // ss-hidden 隐藏字段组件
  1328. const SsHidden = {
  1329. name: "SsHidden",
  1330. props: {
  1331. modelValue: String,
  1332. name: {
  1333. type: String,
  1334. required: true,
  1335. },
  1336. rule: {
  1337. type: String,
  1338. required: true,
  1339. },
  1340. param: {
  1341. type: String,
  1342. required: true,
  1343. },
  1344. url: {
  1345. type: String,
  1346. required: true,
  1347. },
  1348. },
  1349. emits: ["update:modelValue"],
  1350. setup(props, { emit }) {
  1351. const errMsg = Vue.ref("");
  1352. const validate = () => {
  1353. if (window.ssVm) {
  1354. const result = window.ssVm.validateField(props.name);
  1355. console.log("validate", window.ssVm.validateField(props.name));
  1356. errMsg.value = result.valid ? "" : result.message;
  1357. }
  1358. };
  1359. Vue.onMounted(() => {
  1360. /**
  1361. * 初始化级联菜单值初始值思路:
  1362. * 1. 带隐藏字段(即带编码规则)的级联菜单
  1363. * 在隐藏字段这,可以取到要回显的值和编码规则,从而计算出各级下拉菜单要回显的值。
  1364. * 然后通过ajax取各级级联菜单的值回显。
  1365. * 2. 不带隐藏字段的级联,只能在各个下拉菜单的setup事件中通过ajax取回显值回显
  1366. */
  1367. // 当同组级联下拉菜单选中值变化时,会调用本隐藏字段下面这方法设置隐藏字段值
  1368. window.addEventListener(
  1369. "cascader-setHiddenVal-" + props.name,
  1370. (event) => {
  1371. const { value } = event.detail;
  1372. emit("update:modelValue", value);
  1373. console.log(value);
  1374. setTimeout(() => {
  1375. validate();
  1376. }, 50);
  1377. }
  1378. );
  1379. // 如果有初始值,触发回显过程
  1380. if (props.modelValue) {
  1381. console.log("级联隐藏字段,开始回显,初始值:", props.modelValue);
  1382. triggerCascaderEcho(props.modelValue);
  1383. validate();
  1384. }
  1385. });
  1386. // 触发级联回显
  1387. const triggerCascaderEcho = (code) => {
  1388. /**
  1389. * 开始回显,初始值: 440304
  1390. * 解析后的所有值: Array(3)0: "440000"1: "440300"2: "440304"length: 3[[Prototype]]: Array(0)
  1391. */
  1392. const values = parseHiddenCodeForAll(code, props.rule);
  1393. console.log("解析后的所有值:", values);
  1394. // 转换为 JSON 对象
  1395. // const paramObj = JSON.parse(props.param);
  1396. const paramObj = props.param;
  1397. let selectArr = paramObj.fieldOrd; //保存本组级联菜单项的数组,如:['hksheng','hkshi','hkxian']
  1398. if (selectArr.length != values.length) {
  1399. // alert('属性'+props.name+'的值'+code+'与级联菜单中下拉菜单的数目不匹配!');
  1400. return;
  1401. }
  1402. // 按顺序触发回显,并增加延迟确保数据加载
  1403. /**
  1404. * 通过隐藏字段的setup事件,
  1405. * 循环遍历各级下拉菜单,并触发定义在下拉菜单中的'cascader-echo'事件,
  1406. * 在此事件中完成每个下拉菜单回显值操作(只取当前要回显的键值对显示,
  1407. * 下拉菜单所有的值,在点击下拉菜单时,才通过ajax取)。
  1408. */
  1409. values.forEach((value, index) => {
  1410. if (value) {
  1411. setTimeout(() => {
  1412. let upperVal = undefined;
  1413. if (index != 0) {
  1414. upperVal = values[index - 1];
  1415. }
  1416. const echoEvent = new CustomEvent(
  1417. "cascader-echo-" + selectArr[index],
  1418. {
  1419. detail: {
  1420. name: props.name,
  1421. value: value,
  1422. // level: index + 1,
  1423. isAuto: true, // 标记为自动回显
  1424. upperVal: upperVal,
  1425. },
  1426. }
  1427. );
  1428. console.log(props.name + "--upperValue:" + upperVal);
  1429. window.dispatchEvent(echoEvent);
  1430. }, index * 500); // 每级增加500ms延迟
  1431. }
  1432. });
  1433. };
  1434. // 解析所有级别的代码
  1435. const parseHiddenCodeForAll = (code, rule) => {
  1436. if (!code || !rule) return [];
  1437. // 获取规则中每段的长度
  1438. const segments = [];
  1439. let currentChar = rule[0];
  1440. let currentLength = 1;
  1441. for (let i = 1; i < rule.length; i++) {
  1442. if (rule[i] === currentChar) {
  1443. currentLength++;
  1444. } else {
  1445. segments.push(currentLength);
  1446. currentChar = rule[i];
  1447. currentLength = 1;
  1448. }
  1449. }
  1450. segments.push(currentLength);
  1451. // 解析每一级的值
  1452. const values = [];
  1453. let position = 0;
  1454. segments.forEach((length, index) => {
  1455. const value = code
  1456. .substring(0, position + length)
  1457. .padEnd(rule.length, "0");
  1458. values.push(value);
  1459. position += length;
  1460. });
  1461. return values;
  1462. };
  1463. watchEffect(() => {});
  1464. return {};
  1465. },
  1466. template: `<input type="hidden" :name="name" :value="modelValue">`,
  1467. };
  1468. // ss-cascader 级联选择器
  1469. const SsCcp = {
  1470. name: "SsCcp",
  1471. inheritAttrs: false,
  1472. props: {
  1473. modelValue: String,
  1474. name: {
  1475. type: String,
  1476. required: true,
  1477. },
  1478. level: {
  1479. type: Number,
  1480. required: true,
  1481. },
  1482. opt: {
  1483. type: Array,
  1484. default: () => [],
  1485. },
  1486. placeholder: {
  1487. type: String,
  1488. default: "请选择",
  1489. },
  1490. width: {
  1491. type: String,
  1492. default: "150px",
  1493. },
  1494. direction: {
  1495. type: String,
  1496. default: "bottom",
  1497. },
  1498. mode: {
  1499. type: String,
  1500. default: "1",
  1501. },
  1502. //级联菜单配置参数,如果是数组,则代表本下拉菜单是多套级联菜单共用的第一级菜单。如果是对象,则只有一套级联菜单用此下拉菜单。
  1503. param: {
  1504. type: String,
  1505. required: true,
  1506. },
  1507. //向后台拿数据的url
  1508. url: {
  1509. type: String,
  1510. required: true,
  1511. },
  1512. },
  1513. emits: ["update:modelValue", "change"],
  1514. setup(props, { emit }) {
  1515. // alert('级联菜单初始化:'+props.name+':--:'+props.modelValue);
  1516. const selectItem = Vue.ref({ label: props.placeholder, value: "" });
  1517. const popupWinVisible = Vue.ref(false);
  1518. const isAutoEcho = Vue.ref(false); // 用于标记是否是自动回显
  1519. const upperValue = Vue.ref(""); //上级下拉菜单当前值,在初始化下拉菜单默认值时,和上级下拉菜单的值变化时,修改此upperValue变量
  1520. const popupDirection = Vue.ref("bottom");
  1521. const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
  1522. //有隐藏字段的下拉菜单,加载菜单项并展开事件
  1523. // 被上级下拉菜单选中值后,触发本下拉菜单刷新菜单项并弹出显示
  1524. window.addEventListener("cascader-open-" + props.name, async (event) => {
  1525. const { upperVal } = event.detail;
  1526. upperValue.value = upperVal;
  1527. console.log(
  1528. "22props.name:" +
  1529. props.name +
  1530. ",22props.upperValue:" +
  1531. upperValue.value
  1532. );
  1533. selectItem.value = ""; //清除本下拉菜单当前选中的值
  1534. emit("update:modelValue", ""); //通知父级
  1535. //清空下拉菜单,并设置第一项的值为placeholder
  1536. clearAndInit1stOpt();
  1537. //下个下拉菜单名
  1538. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1539. if (nextSelName) {
  1540. //清下个下拉菜单选中值和选项
  1541. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  1542. detail: {},
  1543. });
  1544. window.dispatchEvent(event);
  1545. }
  1546. showPopup();
  1547. });
  1548. //设置mode2的下级下拉菜单的上级菜单当前值
  1549. function setNextSelectUpperValue() {
  1550. //设置下级菜单的上级菜单当前值upperValue
  1551. let paramArr = undefined;
  1552. if (Array.isArray(props.param)) {
  1553. paramArr = props.param;
  1554. } else {
  1555. paramArr = [];
  1556. paramArr.push(props.param);
  1557. }
  1558. for (const oneParam of paramArr) {
  1559. //下个下拉菜单名
  1560. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  1561. if (nextSelName) {
  1562. setTimeout(() => {
  1563. const openNextEvent = new CustomEvent(
  1564. "cascade-setUpperVal-" + nextSelName,
  1565. {
  1566. detail: {
  1567. upperVal: props.modelValue,
  1568. },
  1569. }
  1570. );
  1571. window.dispatchEvent(openNextEvent);
  1572. }, 100);
  1573. }
  1574. } // end for
  1575. }
  1576. // 把上级 级联下拉菜单的值,设置进本组件的事件
  1577. window.addEventListener("cascade-setUpperVal-" + props.name, (event) => {
  1578. // alert('props.name:'+props.name+',props.upperValue:'+event.detail.upperVal);
  1579. const { upperVal } = event.detail;
  1580. upperValue.value = upperVal;
  1581. // console.log('props.name:'+props.name+',props.upperValue:'+upperValue.value);
  1582. });
  1583. //清空下拉菜单,并设置第一项的值为空
  1584. function clearAndInit1stOpt() {
  1585. if (props.opt)
  1586. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  1587. else {
  1588. props.opt = [];
  1589. }
  1590. props.opt.push({ label: "", value: "" });
  1591. }
  1592. //获取下一级下拉菜单,如果下一级下拉菜单不存在,则返回undefined
  1593. function getNextSel(selName, selNameArr) {
  1594. // 检查参数有效性
  1595. if (!Array.isArray(selNameArr) || selNameArr.length === 0) {
  1596. return undefined;
  1597. }
  1598. // 查找当前元素的索引
  1599. const currentIndex = selNameArr.indexOf(selName);
  1600. // 如果元素不存在或已经是最后一个元素,返回undefined
  1601. if (currentIndex === -1 || currentIndex === selNameArr.length - 1) {
  1602. return undefined;
  1603. }
  1604. // 返回下一个元素
  1605. return selNameArr[currentIndex + 1];
  1606. }
  1607. const validate = () => {
  1608. if (window.ssVm) {
  1609. return window.ssVm.validateField(props.name);
  1610. }
  1611. return { valid: true };
  1612. };
  1613. // 处理选择事件
  1614. const doSelectItem = (item) => {
  1615. selectItem.value = item;
  1616. emit("update:modelValue", item.value); //修改本下拉菜单在vue中保存的值
  1617. // alert('item.value:'+item.value);
  1618. if (props.mode === "1") {
  1619. // mode 1 模式:修改隐藏字段值
  1620. let event = new CustomEvent(
  1621. "cascader-setHiddenVal-" + props.param.combField,
  1622. {
  1623. detail: {
  1624. value: item.value,
  1625. },
  1626. }
  1627. );
  1628. window.dispatchEvent(event);
  1629. }
  1630. emit("change", item.value); //触发配置的change方法
  1631. nextTick(() => {
  1632. validate();
  1633. if (window.ssVm) {
  1634. for (const [field, rules] of window.ssVm.validations.entries()) {
  1635. for (const rule of rules) {
  1636. if (rule.options?.relField) {
  1637. const relFields = String(rule.options.relField)
  1638. .split(",")
  1639. .map((name) => name.trim())
  1640. .filter(Boolean);
  1641. if (relFields.includes(props.name)) {
  1642. window.ssVm.validateField(field);
  1643. }
  1644. }
  1645. }
  1646. }
  1647. }
  1648. });
  1649. //设置下级菜单的上级菜单当前值upperValue
  1650. let paramArr = undefined;
  1651. if (Array.isArray(props.param)) {
  1652. paramArr = props.param;
  1653. } else {
  1654. paramArr = [];
  1655. paramArr.push(props.param);
  1656. }
  1657. for (const oneParam of paramArr) {
  1658. //下个下拉菜单名
  1659. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  1660. if (nextSelName) {
  1661. setTimeout(() => {
  1662. const openNextEvent = new CustomEvent(
  1663. "cascader-open-" + nextSelName,
  1664. {
  1665. detail: {
  1666. upperVal: item.value,
  1667. },
  1668. }
  1669. );
  1670. window.dispatchEvent(openNextEvent);
  1671. }, 100);
  1672. }
  1673. } // end for
  1674. hidePopup();
  1675. //下个下拉菜单名
  1676. // let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1677. // if(nextSelName){
  1678. // // //设置下一级下拉菜单中保存的本下拉菜单值(upperValue)
  1679. // // event = new CustomEvent('cascade-setUpperVal-'+nextSelName, {
  1680. // // detail: {
  1681. // // value: item.value
  1682. // // }
  1683. // // });
  1684. // // window.dispatchEvent(event);
  1685. //
  1686. // //触发下一级下拉菜单,重新初始化下拉菜单项并弹出显示
  1687. // event = new CustomEvent('cascader-open-' +nextSelName, {
  1688. // detail: {
  1689. // upperVal: item.value
  1690. // }
  1691. // });
  1692. // window.dispatchEvent(event);
  1693. // }
  1694. // 只在手动选择时自动展开下一级
  1695. // if (!isAutoEcho.value) {
  1696. // const nextLevel = props.level + 1;
  1697. // setTimeout(() => {
  1698. // const openNextEvent = new CustomEvent('open-next-cascader', {
  1699. // detail: {
  1700. // name: props.name,
  1701. // level: nextLevel
  1702. // }
  1703. // });
  1704. // window.dispatchEvent(openNextEvent);
  1705. // }, 100);
  1706. // }
  1707. };
  1708. // 监听下一级展开事件 (仅 mode 2)
  1709. window.addEventListener("cascade-open", (event) => {
  1710. if (props.mode === "2") {
  1711. const { level } = event.detail;
  1712. if (level === props.level) {
  1713. popupWinVisible.value = true;
  1714. }
  1715. }
  1716. });
  1717. if (props.mode === "1") {
  1718. //如果是有隐藏字段的下拉菜单
  1719. // 监听回显事件
  1720. window.addEventListener(
  1721. "cascader-echo-" + props.name,
  1722. async (event) => {
  1723. const { name, value, isAuto, upperVal } = event.detail;
  1724. // level,
  1725. if (upperVal) {
  1726. upperValue.value = upperVal;
  1727. console.log(
  1728. "value:" +
  1729. value +
  1730. ",upperValue:" +
  1731. upperValue +
  1732. ",初始化级联组件时props.name:" +
  1733. props.name
  1734. );
  1735. }
  1736. // if (name === props.name && level === props.level) {
  1737. // 设置自动回显标记
  1738. isAutoEcho.value = true;
  1739. // if (props.opt.length === 0) {
  1740. // const loadDataEvent = new CustomEvent('cascader-load-data', {
  1741. // detail: {
  1742. // name: props.name,
  1743. // level: props.level,
  1744. // value: value
  1745. // }
  1746. // });
  1747. // window.dispatchEvent(loadDataEvent);
  1748. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  1749. //Vue.watch用于监听数据的变化,并在数据变化时执行特定的回调函数。
  1750. //这段代码使用了 Vue.js 的 watch API 来监听 props.opt 的变化,如果props.opt有变化,则自动
  1751. // const unwatch = Vue.watch(
  1752. // () => props.opt, // 监听的数据源(props.opt)
  1753. // (newOptions) => { // 回调函数
  1754. // if (newOptions.length > 0) { // 条件判断
  1755. // matchAndSelect(value); // 执行逻辑
  1756. // unwatch(); // 停止监听
  1757. // }
  1758. // },
  1759. // { immediate: true } // 配置:立即触发一次
  1760. // );
  1761. // } else {
  1762. // matchAndSelect(value);
  1763. // }
  1764. // 初始化级联菜单在页面刚打开时的默认值
  1765. async function initDefaultValue(value) {
  1766. try {
  1767. // alert(1);
  1768. if (
  1769. props.url &&
  1770. props.param
  1771. // && props.modelValue 对于有rule编码规则的级联菜单(即mode=1),modelValue一定是空的,所以注释掉,修复mode=1的级联菜单无法回显问题。Ben(20251124)
  1772. ) {
  1773. // alert(2);
  1774. /**
  1775. * let objectPickerParam=
  1776. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  1777. * "\"name\":\"hksheng\"," +
  1778. * "\"cascadingName\":\"dq\",\"cascadingInputsName\":\"hkdqm\"," +
  1779. * "\"codebook\":\"sheng\"}",
  1780. * "objectpickertype":2,
  1781. * "objectpickervalue":"440000"
  1782. * };
  1783. */
  1784. const objectPickerParam = {
  1785. input: "false",
  1786. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  1787. name: props.name, //本下拉菜单名
  1788. cascadingName: props.param.name, //级联菜单名
  1789. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  1790. codebook: props.param.codebook,
  1791. };
  1792. const objectPickerParamStr =
  1793. JSON.stringify(objectPickerParam);
  1794. const params = new URLSearchParams();
  1795. params.append("objectpickerparam", objectPickerParamStr);
  1796. params.append("objectpickertype", "2");
  1797. params.append("objectpickervalue", value); //需回显的值
  1798. axios
  1799. .post(props.url, params, {
  1800. headers: {
  1801. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1802. },
  1803. })
  1804. .then((response) => {
  1805. // alert(JSON.stringify(response.data));
  1806. if ("timeout" == response.data.statusText) {
  1807. alert("网络超时!");
  1808. return;
  1809. }
  1810. if (response.data.result) {
  1811. const keys = Object.keys(response.data.result);
  1812. if (keys.length === 1) {
  1813. let code = keys[0];
  1814. let desc = response.data.result[keys[0]];
  1815. clearAndInit1stOpt();
  1816. props.opt.push({ label: desc, value: code });
  1817. if (value) matchAndSelect(value);
  1818. // updateSelectItem();
  1819. // alert('props.opt:'+JSON.stringify(props.opt));
  1820. }
  1821. }
  1822. });
  1823. }
  1824. } catch (error) {
  1825. alert(error);
  1826. // callback(null, error.message); // 失败回调,传递错误
  1827. }
  1828. }
  1829. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  1830. initDefaultValue(value);
  1831. // 延迟重置自动回显标记
  1832. setTimeout(() => {
  1833. isAutoEcho.value = false;
  1834. }, 500);
  1835. }
  1836. );
  1837. // 被上级下拉菜单触发的,清除选中值和下拉菜单选项
  1838. window.addEventListener(
  1839. "cascader-cleanOpt-" + props.name,
  1840. async (event) => {
  1841. upperValue.value = "";
  1842. selectItem.value = ""; //清除本下拉菜单当前选中的值
  1843. emit("update:modelValue", ""); //通知父级
  1844. //清空所有下拉菜单项
  1845. if (props.opt) {
  1846. props.opt.length = 0;
  1847. } else {
  1848. props.opt = [];
  1849. }
  1850. //下个下拉菜单名
  1851. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1852. // alert('nextSelName:'+nextSelName+'--,props.name:'+props.name);
  1853. if (nextSelName) {
  1854. //清下个下拉菜单选中值和选项
  1855. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  1856. detail: {},
  1857. });
  1858. window.dispatchEvent(event);
  1859. }
  1860. }
  1861. );
  1862. } else if (props.mode === "2") {
  1863. //没隐藏字段的下拉菜单,在这初始化默认值
  1864. let needInitParam = undefined;
  1865. if (Array.isArray(props.param)) {
  1866. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  1867. console.log("needInitParam最后一项:" + JSON.stringify(needInitParam));
  1868. } else {
  1869. needInitParam = props.param;
  1870. }
  1871. // 初始化级联菜单在页面刚打开时的默认值
  1872. async function initDefaultValue(value, param) {
  1873. try {
  1874. // alert(1);
  1875. if (props.url && param && props.modelValue) {
  1876. // alert(2);
  1877. /**
  1878. * let param=
  1879. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"rylbm,gwid\"," +
  1880. * "\"name\":\"gwid\",\"cascadingName\":\"rylb_gw\"," +
  1881. * "\"codebook\":\"gwByRylb\"}",
  1882. * "objectpickertype":2,
  1883. * "objectpickervalue":"102121"};
  1884. */
  1885. // alert('props.name:'+props.name+',props.param.fieldOrd:'+props.param.fieldOrd);
  1886. const objectPickerParam = {
  1887. input: "false",
  1888. cascadingLevel: param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  1889. name: props.name, //本下拉菜单名
  1890. cascadingName: param.name, //级联菜单名
  1891. codebook: param.codebook,
  1892. };
  1893. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  1894. const sendParams = new URLSearchParams();
  1895. sendParams.append("objectpickerparam", objectPickerParamStr);
  1896. sendParams.append("objectpickertype", "2");
  1897. sendParams.append("objectpickervalue", value); //需回显的值
  1898. axios
  1899. .post(props.url, sendParams, {
  1900. headers: {
  1901. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1902. },
  1903. })
  1904. .then((response) => {
  1905. // alert(JSON.stringify(response.data));
  1906. if ("timeout" == response.data.statusText) {
  1907. alert("网络超时!");
  1908. return;
  1909. }
  1910. if (response.data.result) {
  1911. const keys = Object.keys(response.data.result);
  1912. console.log(
  1913. "name:" +
  1914. props.name +
  1915. ",@@级联初始化默认值value:" +
  1916. value +
  1917. "--param:" +
  1918. JSON.stringify(param) +
  1919. "--objectPickerParamStr:" +
  1920. objectPickerParamStr +
  1921. "--response.data:" +
  1922. JSON.stringify(response.data)
  1923. );
  1924. if (keys.length === 1) {
  1925. let code = keys[0];
  1926. let desc = response.data.result[keys[0]];
  1927. if (props.opt)
  1928. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  1929. else {
  1930. props.opt = [];
  1931. }
  1932. props.opt.push({ label: desc, value: code });
  1933. if (value) matchAndSelect(value);
  1934. console.log(
  1935. "GOOD mode2回显的默认值:" +
  1936. JSON.stringify({ label: desc, value: code }) +
  1937. "--props.param:" +
  1938. JSON.stringify(param)
  1939. );
  1940. // updateSelectItem();
  1941. // alert('props.opt:'+JSON.stringify(props.opt));
  1942. }
  1943. }
  1944. });
  1945. }
  1946. } catch (error) {
  1947. alert(error);
  1948. // callback(null, error.message); // 失败回调,传递错误
  1949. }
  1950. // 重置自动回显标记
  1951. isAutoEcho.value = false;
  1952. }
  1953. // 初始化级联菜单在页面刚打开时的默认值
  1954. initDefaultValue(props.modelValue, needInitParam);
  1955. //设置mode2的下级下拉菜单的上级菜单当前值
  1956. setNextSelectUpperValue();
  1957. }
  1958. //选中要回显的默认值
  1959. const matchAndSelect = (value) => {
  1960. const matchedOption = props.opt.find((opt) => opt.value === value);
  1961. if (matchedOption) {
  1962. selectItem.value = matchedOption;
  1963. emit("update:modelValue", value);
  1964. emit("change", value);
  1965. }
  1966. };
  1967. // 计算弹出方向和最大高度的方法 by xu 20251212
  1968. // 当空间不足时限制popup高度并显示滚动条
  1969. const calculatePopupDirection = () => {
  1970. // 1. 获取select容器元素
  1971. const selectEl = document.querySelector(
  1972. `[name="${props.name}"]`
  1973. )?.nextElementSibling;
  1974. console.log("selectEl:" + selectEl, props.name);
  1975. if (!selectEl) return;
  1976. // 2. 获取位置信息
  1977. const selectRect = selectEl.getBoundingClientRect();
  1978. const viewportHeight = window.innerHeight;
  1979. // 3. 计算上下可用空间 by xu 20251212
  1980. const spaceBelow = viewportHeight - selectRect.bottom - 10; // 减10px留边距
  1981. const spaceAbove = selectRect.top - 10; // 减10px留边距
  1982. // 4. popup预估高度(假设每项36px,最多显示8项 + padding)
  1983. const estimatedPopupHeight = 300;
  1984. const minPopupHeight = 100; // 最小高度
  1985. console.log(
  1986. "[popup] 空间计算 - spaceAbove:",
  1987. spaceAbove,
  1988. "spaceBelow:",
  1989. spaceBelow,
  1990. "estimatedHeight:",
  1991. estimatedPopupHeight
  1992. );
  1993. // 5. 判断方向和最大高度 by xu 20251212
  1994. if (spaceBelow >= estimatedPopupHeight) {
  1995. // 下方空间足够,向下展开,不限制高度
  1996. popupDirection.value = "bottom";
  1997. popupMaxHeight.value = "none";
  1998. console.log("[popup] 向下展开,空间充足");
  1999. } else if (spaceAbove >= estimatedPopupHeight) {
  2000. // 上方空间足够,向上展开,不限制高度
  2001. popupDirection.value = "top";
  2002. popupMaxHeight.value = "none";
  2003. console.log("[popup] 向上展开,空间充足");
  2004. } else {
  2005. // 上下空间都不足,选择空间大的方向,并限制高度出滚动条
  2006. if (spaceBelow >= spaceAbove) {
  2007. popupDirection.value = "bottom";
  2008. popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px";
  2009. console.log(
  2010. "[popup] 向下展开,空间不足,限制高度:",
  2011. popupMaxHeight.value
  2012. );
  2013. } else {
  2014. popupDirection.value = "top";
  2015. popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px";
  2016. console.log(
  2017. "[popup] 向上展开,空间不足,限制高度:",
  2018. popupMaxHeight.value
  2019. );
  2020. }
  2021. }
  2022. };
  2023. //级联菜单点击事件
  2024. const togglePopup = () => {
  2025. if (!popupWinVisible.value) {
  2026. //如果当前下拉菜单是隐藏的,先ajax重新加载下拉菜单项,再显示。
  2027. showPopup();
  2028. } else {
  2029. hidePopup();
  2030. }
  2031. };
  2032. //显示下拉菜单,在此之前先清除下拉菜单项
  2033. const showPopup = () => {
  2034. //清空下拉菜单,并设置第一项的值为空
  2035. clearAndInit1stOpt();
  2036. Vue.nextTick(() => {
  2037. calculatePopupDirection();
  2038. });
  2039. let url = props.url;
  2040. let filterObj = props.param.filter;
  2041. if (filterObj) {
  2042. for (let k in filterObj) {
  2043. let v = filterObj[k];
  2044. url += "&" + k + "=" + v;
  2045. }
  2046. }
  2047. if (props.mode === "1") {
  2048. //如果是有隐藏字段的下拉菜单
  2049. console.log("666url:" + url);
  2050. // alert('url:'+url);
  2051. // 获取级联菜单所有下拉菜单项
  2052. async function getSelectItems(value) {
  2053. try {
  2054. // alert(1);
  2055. if (props.url && props.param) {
  2056. // alert(2);
  2057. /**
  2058. * param={"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  2059. * "\"name\":\"hksheng\",\"cascadingName\":\"dq\"," +
  2060. * "\"cascadingInputsName\":\"hkdqm\",\"codebook\":\"sheng\"}",
  2061. * "objectpickertype":1,//2表示获取要回显的一项,1表示获取所有下拉菜单项
  2062. * "upperValue":"440000"
  2063. * };
  2064. */
  2065. const objectPickerParam = {
  2066. input: "false",
  2067. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2068. name: props.name, //本下拉菜单名
  2069. cascadingName: props.param.name, //级联菜单名
  2070. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  2071. codebook: props.param.codebook,
  2072. };
  2073. console.log("mode1 upperValue.value:" + upperValue.value);
  2074. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2075. const params = new URLSearchParams();
  2076. params.append("objectpickerparam", objectPickerParamStr);
  2077. params.append("objectpickertype", "1");
  2078. if (upperValue.value) {
  2079. params.append("upperValue", upperValue.value);
  2080. }
  2081. // params.append('objectpickervalue', value); //需回显的值
  2082. axios
  2083. .post(url, params, {
  2084. headers: {
  2085. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2086. },
  2087. })
  2088. .then((response) => {
  2089. if ("timeout" == response.data.statusText) {
  2090. alert("网络超时!");
  2091. return;
  2092. }
  2093. if (response.data.result) {
  2094. const keys = Object.keys(response.data.result);
  2095. console.log(
  2096. "params:" +
  2097. params +
  2098. "@@response.data:" +
  2099. JSON.stringify(response.data)
  2100. );
  2101. if (keys.length > 0) {
  2102. for (let k in response.data.result) {
  2103. props.opt.push({
  2104. label: response.data.result[k],
  2105. value: k,
  2106. });
  2107. }
  2108. console.log("props.opt11:" + JSON.stringify(props.opt));
  2109. } else {
  2110. // 没有数据时打印日志 by xu 20251212
  2111. console.log("[ccp mode1] 接口返回空数据");
  2112. }
  2113. } else {
  2114. // result不存在时打印日志 by xu 20251212
  2115. console.log("[ccp mode1] 接口返回无result");
  2116. }
  2117. // 无论是否有数据,都显示popup by xu 20251212
  2118. if (!popupWinVisible.value) {
  2119. popupWinVisible.value = true;
  2120. }
  2121. });
  2122. }
  2123. } catch (error) {
  2124. alert(error);
  2125. // callback(null, error.message); // 失败回调,传递错误
  2126. }
  2127. }
  2128. getSelectItems(props.modelValue);
  2129. } else if (props.mode === "2") {
  2130. //没隐藏字段的下拉菜单
  2131. let needInitParam = undefined;
  2132. if (Array.isArray(props.param)) {
  2133. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  2134. console.log(
  2135. "needInitParam最后一项:" + JSON.stringify(needInitParam)
  2136. );
  2137. } else {
  2138. needInitParam = props.param;
  2139. }
  2140. // 获取级联菜单所有下拉菜单项
  2141. async function getSelectItems(value, sendParam) {
  2142. try {
  2143. // alert(1);
  2144. if (props.url && sendParam) {
  2145. // alert(2);
  2146. /**
  2147. * param="{\"input\":\"false\",\"cascadingLevel\":\"dwid,sjryid\",
  2148. * \"ryid\":\"111121\",\"name\":\"sjryid\",
  2149. * \"cascadingName\":\"dw_sjry\",\"codebook\":\"sjryByDw\"}"
  2150. */
  2151. const objectPickerParam = {
  2152. input: "false",
  2153. cascadingLevel: sendParam.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2154. name: props.name, //本下拉菜单名
  2155. cascadingName: sendParam.name, //级联菜单名
  2156. codebook: sendParam.codebook,
  2157. };
  2158. console.log("mode2 upperValue.value:" + upperValue.value);
  2159. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2160. const params = new URLSearchParams();
  2161. params.append("objectpickerparam", objectPickerParamStr);
  2162. params.append("objectpickertype", "1");
  2163. if (upperValue.value) {
  2164. params.append("upperValue", upperValue.value);
  2165. }
  2166. // params.append('objectpickervalue', value); //需回显的值
  2167. axios
  2168. .post(url, params, {
  2169. headers: {
  2170. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2171. },
  2172. })
  2173. .then((response) => {
  2174. if ("timeout" == response.data.statusText) {
  2175. alert("网络超时!");
  2176. return;
  2177. }
  2178. if (response.data.result) {
  2179. const keys = Object.keys(response.data.result);
  2180. console.log(
  2181. "params:" +
  2182. params +
  2183. "@@response.data:" +
  2184. JSON.stringify(response.data)
  2185. );
  2186. if (keys.length > 0) {
  2187. for (let k in response.data.result) {
  2188. props.opt.push({
  2189. label: response.data.result[k],
  2190. value: k,
  2191. });
  2192. }
  2193. console.log("props.opt11:" + JSON.stringify(props.opt));
  2194. } else {
  2195. // 没有数据时打印日志 by xu 20251212
  2196. console.log("[ccp mode2] 接口返回空数据");
  2197. }
  2198. } else {
  2199. // result不存在时打印日志 by xu 20251212
  2200. console.log("[ccp mode2] 接口返回无result");
  2201. }
  2202. // 无论是否有数据,都显示popup by xu 20251212
  2203. if (!popupWinVisible.value) {
  2204. popupWinVisible.value = true;
  2205. }
  2206. });
  2207. }
  2208. } catch (error) {
  2209. alert(error);
  2210. // callback(null, error.message); // 失败回调,传递错误
  2211. }
  2212. }
  2213. getSelectItems(props.modelValue, needInitParam);
  2214. // popupWinVisible.value = !popupWinVisible.value;
  2215. }
  2216. };
  2217. const hidePopup = () => {
  2218. popupWinVisible.value = false;
  2219. };
  2220. // 合并所有的 onMounted 逻辑
  2221. Vue.onMounted(() => {
  2222. window.addEventListener("resize", calculatePopupDirection);
  2223. // 1. 监听展开下一级事件
  2224. window.addEventListener("open-next-cascader", (event) => {
  2225. const { name, level } = event.detail;
  2226. if (name === props.name && level === props.level) {
  2227. popupWinVisible.value = true;
  2228. }
  2229. });
  2230. // 2. 监听级联事件
  2231. window.addEventListener("cascader-change", (event) => {
  2232. const { name, level, value } = event.detail;
  2233. if (name === props.name && level < props.level) {
  2234. selectItem.value = { label: "", value: "" };
  2235. emit("update:modelValue", "");
  2236. if (ssHidden) {
  2237. ssHidden.updateValue(value);
  2238. }
  2239. }
  2240. });
  2241. });
  2242. Vue.onUnmounted(() => {
  2243. window.removeEventListener("resize", calculatePopupDirection);
  2244. });
  2245. // 监听值变化,处理回显 (mode 2)
  2246. Vue.watch(
  2247. () => props.modelValue,
  2248. (newVal) => {
  2249. if (props.mode === "2" && newVal) {
  2250. // 使用 watchEffect 替代嵌套的 watch
  2251. Vue.watchEffect(() => {
  2252. if (props.opt.length > 0) {
  2253. const matchedOption = props.opt.find(
  2254. (opt) => opt.value === newVal
  2255. );
  2256. if (matchedOption) {
  2257. selectItem.value = matchedOption;
  2258. }
  2259. }
  2260. });
  2261. } else {
  2262. // 原有的值变化处理
  2263. const item = props.opt.find((it) => it.value === newVal);
  2264. if (item) {
  2265. selectItem.value = item;
  2266. } else {
  2267. selectItem.value = { label: "", value: "" };
  2268. }
  2269. }
  2270. },
  2271. { immediate: true }
  2272. );
  2273. // 监听选项变化,当数据加载完成时进行匹配
  2274. Vue.watch(
  2275. () => props.opt,
  2276. (newOptions) => {
  2277. if (newOptions.length > 0) {
  2278. const matchedOption = newOptions.find(
  2279. (opt) => opt.value === selectItem.value.value
  2280. );
  2281. if (matchedOption) {
  2282. selectItem.value = matchedOption;
  2283. emit("update:modelValue", matchedOption.value);
  2284. emit("change", matchedOption.value);
  2285. }
  2286. }
  2287. }
  2288. );
  2289. return {
  2290. selectItem,
  2291. popupWinVisible,
  2292. popupDirection,
  2293. popupMaxHeight, // 添加popup最大高度 by xu 20251212
  2294. togglePopup,
  2295. hidePopup,
  2296. doSelectItem,
  2297. };
  2298. },
  2299. template: `
  2300. <div class="input ss-ccp-container" style="position: relative" :style="{width: width}">
  2301. <input type="hidden" :name="name" :value="modelValue">
  2302. <div class="select-container" @mouseleave="hidePopup">
  2303. <div class="input" @click="togglePopup">
  2304. <input
  2305. type="hidden"
  2306. :name="name"
  2307. :value="selectItem.value"
  2308. />
  2309. <input
  2310. :placeholder="placeholder"
  2311. :value="selectItem.label"
  2312. disabled
  2313. style="pointer-events: none;"
  2314. />
  2315. <div class="suffix">
  2316. <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
  2317. </div>
  2318. </div>
  2319. <!-- popup弹出层,添加maxHeight和overflowY支持空间不足时滚动 by xu 20251212 -->
  2320. <div v-show="popupWinVisible" class="popup-win " :class="popupDirection" :style="{ maxHeight: popupMaxHeight, overflowY: popupMaxHeight !== 'none' ? 'auto' : 'visible' }">
  2321. <div v-if="opt && opt.length > 0" class="popup-content">
  2322. <div class="content-area">
  2323. <div
  2324. v-for="(item, index) in opt"
  2325. :key="index"
  2326. @click="doSelectItem(item)"
  2327. :class="{ active: item.value === selectItem.value }"
  2328. >
  2329. <span class="check-icon">
  2330. <ss-form-icon class="form-icon-select-checked" />
  2331. </span>
  2332. <span>{{ item.label }}</span>
  2333. </div>
  2334. </div>
  2335. </div>
  2336. <div v-else class="popup-content">
  2337. <div class="content-area">
  2338. <div class="content-area">
  2339. <span>无选项</span>
  2340. </div>
  2341. </div>
  2342. </div>
  2343. </div>
  2344. </div>
  2345. </div>
  2346. `,
  2347. };
  2348. // ss-date-picker 日期时间选择器组件
  2349. const SsDatePicker = {
  2350. name: "SsDatePicker",
  2351. props: {
  2352. modelValue: {
  2353. type: [String, Number, Date],
  2354. default: "",
  2355. },
  2356. name: {
  2357. type: String,
  2358. required: true,
  2359. },
  2360. type: {
  2361. type: String,
  2362. default: "date",
  2363. validator: (value) => ["date", "datetime", "time"].includes(value),
  2364. },
  2365. fmt: {
  2366. type: String,
  2367. default: null,
  2368. },
  2369. placeholder: {
  2370. type: String,
  2371. default: "",
  2372. },
  2373. width: {
  2374. type: String,
  2375. default: "100%",
  2376. },
  2377. },
  2378. emits: ["update:modelValue"],
  2379. setup(props, { emit }) {
  2380. const errMsg = ref("");
  2381. const validate = () => {
  2382. if (window.ssVm) {
  2383. const result = window.ssVm.validateField(props.name);
  2384. console.log("validate", window.ssVm.validateField(props.name));
  2385. errMsg.value = result.valid ? "" : result.message;
  2386. }
  2387. };
  2388. // 根据type确定默认格式
  2389. const defaultFormat = computed(() => {
  2390. switch (props.type) {
  2391. case "datetime":
  2392. return "YYYY-MM-DD HH:mm:ss";
  2393. case "date":
  2394. return "YYYY-MM-DD";
  2395. case "time":
  2396. return "HH:mm:ss";
  2397. }
  2398. });
  2399. const convertJavaFormatToElement = (javaFormat) => {
  2400. if (!javaFormat) return null;
  2401. return javaFormat
  2402. .replace("yyyy", "YYYY")
  2403. .replace("MM", "MM")
  2404. .replace("dd", "DD")
  2405. .replace("HH", "HH")
  2406. .replace("mm", "mm")
  2407. .replace("ss", "ss");
  2408. };
  2409. const finalFormat = computed(() => {
  2410. if (props.fmt) {
  2411. return convertJavaFormatToElement(props.fmt);
  2412. }
  2413. return defaultFormat.value;
  2414. });
  2415. // 使用 resolveComponent 获取组件
  2416. const ElDatePicker = resolveComponent("ElDatePicker");
  2417. const ElTimePicker = resolveComponent("ElTimePicker");
  2418. const SsFormIcon = resolveComponent("SsFormIcon");
  2419. const ElIcon = resolveComponent("ElIcon");
  2420. const handleValueUpdate = (val) => {
  2421. emit("update:modelValue", val);
  2422. emit("change", val); // 同时触发 change 事件
  2423. setTimeout(() => {
  2424. validate();
  2425. }, 50);
  2426. };
  2427. const dateType = computed(() => {
  2428. const fmt = props.fmt || "";
  2429. if (fmt.includes("HH:mm:ss")) {
  2430. return "datetime";
  2431. } else if (fmt.includes("HH:mm")) {
  2432. return "datetime";
  2433. } else if (fmt.includes("mm:ss")) {
  2434. return "time";
  2435. }
  2436. return "date";
  2437. });
  2438. let useTimePicker = true;
  2439. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  2440. if (props.fmt) {
  2441. //有fmt属性,则以fmt属性优先判断类型
  2442. if (/[dMy]/.test(props.fmt)) {
  2443. //如果有传入日期格式,且含年月日
  2444. useTimePicker = false;
  2445. } else {
  2446. useTimePicker = true;
  2447. }
  2448. } else if (props.type !== "time") {
  2449. useTimePicker = false;
  2450. }
  2451. return () =>
  2452. h("div", { class: "ss-date-picker", style: { width: props.width } }, [
  2453. h("input", {
  2454. type: "hidden",
  2455. name: props.name,
  2456. value: props.modelValue,
  2457. }),
  2458. // 选择组件
  2459. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  2460. modelValue: props.modelValue,
  2461. "onUpdate:modelValue": handleValueUpdate,
  2462. type: dateType.value,
  2463. format: finalFormat.value,
  2464. "value-format": finalFormat.value,
  2465. clearable: true,
  2466. placeholder: props.placeholder,
  2467. class: "custom-date-picker", // 用于自定义样式
  2468. "time-arrow-control": props.type === "datetime", // 修改这里
  2469. size: "large", // 添加这一行,改为 large 尺寸
  2470. style: { width: "100%" },
  2471. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  2472. }),
  2473. ]);
  2474. },
  2475. };
  2476. // ss-icon 图标
  2477. // v3.0 增加 class 属性分支:有 class 走新逻辑,否则走 v1.0 逻辑 by xu 20251212
  2478. // v3.0 用法: <ss-icon class="icon-obj-ry menu-icon" />
  2479. // v1.0 用法: <ss-icon name="setting" size="20px" />
  2480. const SsIcon = {
  2481. name: "SsIcon",
  2482. // v3.0 禁用 class 透传,手动处理 by xu 20251215
  2483. inheritAttrs: false,
  2484. props: {
  2485. // v1.0: 以下为旧属性
  2486. name: { type: String },
  2487. size: { type: [Number, String], default: 16 },
  2488. unit: { type: String, default: "px" },
  2489. color: String,
  2490. type: {
  2491. type: String,
  2492. default: ssIcon.name,
  2493. validator: function (value) {
  2494. return [ssIcon, commonIcon].some((icon) => icon.name === value);
  2495. },
  2496. },
  2497. },
  2498. emits: ["update:modelValue", "input", "blur", "change"],
  2499. setup(props, { emit, attrs }) {
  2500. // v3.0 分支:有 class 属性时直接渲染(从 attrs 获取) by xu 20251215
  2501. if (attrs.class) {
  2502. return () =>
  2503. h("i", { ...attrs, class: attrs.class + " icon-container" });
  2504. }
  2505. // v1.0 分支:原有逻辑
  2506. const useIconType = computed(() => {
  2507. return [ssIcon, commonIcon].find(
  2508. (iconConfig) => iconConfig.name === props.type
  2509. );
  2510. });
  2511. const iconName = computed(() => {
  2512. const iconConfig = useIconType.value; // 注意:使用 .value 来访问响应式引用的值
  2513. if (!iconConfig) {
  2514. console.error(`Icon type "${props.type}" not found.`);
  2515. return "";
  2516. }
  2517. const iconType = iconConfig.types[props.name];
  2518. if (!iconType) {
  2519. console.error(
  2520. `Icon name "${props.name}" not found in type "${props.type}".`
  2521. );
  2522. return "";
  2523. }
  2524. return `${iconConfig.prefix}${iconType}`;
  2525. });
  2526. // 类似地,你可以计算 fontFamily 和 style
  2527. const fontFamily = computed(() => {
  2528. return useIconType.value ? useIconType.value.family : "";
  2529. });
  2530. // console.log(iconName.value,fontFamily.value)
  2531. const style = computed(() => {
  2532. const sizeStyle = isNum(props.size)
  2533. ? `${props.size}${props.unit}`
  2534. : props.size;
  2535. const styleObj = {
  2536. fontSize: sizeStyle,
  2537. color: props.color || "",
  2538. };
  2539. return toStyleStr(styleObj);
  2540. });
  2541. // 使用渲染函数定义模板逻辑
  2542. return () =>
  2543. h("i", {
  2544. class: ["icon-container", iconName.value, fontFamily.value],
  2545. style: style.value,
  2546. });
  2547. },
  2548. };
  2549. // 通用icon
  2550. const SsCommonIcon = {
  2551. name: "SsCommonIcon",
  2552. props: {
  2553. class: {
  2554. type: String,
  2555. required: true,
  2556. },
  2557. },
  2558. setup(props) {
  2559. return () =>
  2560. h("i", {
  2561. class: props.class + " common-icon",
  2562. });
  2563. },
  2564. };
  2565. // 登录页icon
  2566. const SsLoginIcon = {
  2567. name: "SsLoginIcon",
  2568. props: {
  2569. class: {
  2570. type: String,
  2571. required: true,
  2572. },
  2573. },
  2574. setup(props) {
  2575. return () =>
  2576. h("div", {
  2577. class: props.class + " login-icon",
  2578. });
  2579. },
  2580. };
  2581. // 弹窗icon
  2582. const SsDialogIcon = {
  2583. name: "SsDialogIcon",
  2584. props: {
  2585. class: {
  2586. type: String,
  2587. required: true,
  2588. },
  2589. },
  2590. setup(props) {
  2591. return () =>
  2592. h("i", {
  2593. class: props.class + " dialog-icon",
  2594. });
  2595. },
  2596. };
  2597. // 全局左侧导航图标组件
  2598. const SsNavIcon = {
  2599. name: "SsNavIcon",
  2600. props: {
  2601. class: {
  2602. type: String,
  2603. required: true,
  2604. },
  2605. },
  2606. setup(props) {
  2607. return () =>
  2608. h("div", {
  2609. class: props.class + " nav-icon",
  2610. });
  2611. },
  2612. };
  2613. // 顶部工具栏图标组件
  2614. const SsHeaderIcon = {
  2615. name: "SsHeaderIcon",
  2616. props: {
  2617. class: {
  2618. type: String,
  2619. required: true,
  2620. },
  2621. },
  2622. setup(props) {
  2623. return () =>
  2624. h("div", {
  2625. class: props.class + " header-icon",
  2626. });
  2627. },
  2628. };
  2629. // 全局菜单图标组件
  2630. const SsGolbalMenuIcon = {
  2631. name: "SsGolbalMenuIcon",
  2632. props: {
  2633. class: {
  2634. type: String,
  2635. required: true,
  2636. },
  2637. },
  2638. setup(props) {
  2639. return () =>
  2640. h("div", {
  2641. class: props.class + " global-menu-icon",
  2642. });
  2643. },
  2644. };
  2645. // 全局查询列表卡片图标
  2646. const SsCartListIcon = {
  2647. name: "SsCartListIcon",
  2648. props: {
  2649. class: {
  2650. type: String,
  2651. required: true,
  2652. },
  2653. },
  2654. setup(props) {
  2655. return () =>
  2656. h("div", {
  2657. class: props.class + " cart-list-icon",
  2658. });
  2659. },
  2660. };
  2661. // 全局底部工具栏图标组件
  2662. const SsQuickIcon = {
  2663. name: "SsQuickIcon",
  2664. props: {
  2665. class: {
  2666. type: String,
  2667. required: true,
  2668. },
  2669. },
  2670. setup(props) {
  2671. return () =>
  2672. h("div", {
  2673. class: props.class + " quick-icon",
  2674. });
  2675. },
  2676. };
  2677. // 表单组件icon
  2678. const SsFormIcon = {
  2679. name: "SsFormIcon",
  2680. props: {
  2681. class: {
  2682. type: String,
  2683. required: true,
  2684. },
  2685. },
  2686. setup(props) {
  2687. return () =>
  2688. h("div", {
  2689. class: props.class + " form-icon",
  2690. });
  2691. },
  2692. };
  2693. // 弹窗底部按钮icon
  2694. const SsBottomDivIcon = {
  2695. name: "SsBottomDivIcon",
  2696. props: {
  2697. class: {
  2698. type: String,
  2699. required: true,
  2700. },
  2701. },
  2702. setup(props) {
  2703. return () =>
  2704. h("div", {
  2705. class: props.class + " bottom-div-icon",
  2706. });
  2707. },
  2708. };
  2709. // editor组件icon
  2710. const SsEditorIcon = {
  2711. name: "SsEditorIcon",
  2712. props: {
  2713. class: {
  2714. type: String,
  2715. required: true,
  2716. },
  2717. },
  2718. setup(props) {
  2719. return () =>
  2720. h("i", {
  2721. class: props.class + " editor-icon",
  2722. });
  2723. },
  2724. };
  2725. // ss-validate校验器
  2726. const SsValidate = {
  2727. name: "SsValidate",
  2728. props: {
  2729. errMsg: { type: String },
  2730. textAlign: { type: String, default: "left" },
  2731. style: { type: Object, default: () => ({}) },
  2732. },
  2733. template: `<div class="validate-vline"></div>
  2734. <div class="validate-tip" :style="style">
  2735. <div class="tip" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  2736. <div class="tip-more" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  2737. </div>`,
  2738. };
  2739. // ss-onoff-array 多选按钮 数组形式
  2740. const SsonoffArray = {
  2741. name: "SsonoffArray",
  2742. props: {
  2743. name: {
  2744. type: String,
  2745. required: true,
  2746. },
  2747. opt: {
  2748. type: Array,
  2749. default: () => [],
  2750. },
  2751. defaultValue: [String, Number, Array],
  2752. modelValue: [String, Number, Array],
  2753. multiple: {
  2754. // 新增多选模式属性
  2755. type: Boolean,
  2756. default: false,
  2757. },
  2758. // 是否允许一项都不选,默认true允许 by xu 20251212
  2759. null: {
  2760. type: Boolean,
  2761. default: true,
  2762. },
  2763. },
  2764. emits: ["update:modelValue"], // 允许更新 v-model 绑定的值
  2765. setup(props, { emit }) {
  2766. console.log("多选按钮", props.opt);
  2767. // 使用数组来存储选中值
  2768. const checkedValue = ref(
  2769. props.multiple
  2770. ? Array.isArray(props.defaultValue)
  2771. ? props.defaultValue
  2772. : []
  2773. : props.defaultValue
  2774. );
  2775. const errMsg = ref(props.errTip);
  2776. // 生成icon名字
  2777. const genIconName = (itemValue) => {
  2778. if (props.multiple) {
  2779. return checkedValue.value.includes(itemValue)
  2780. ? "form-icon-onoff-checked"
  2781. : "form-icon-onoff-unchecked";
  2782. }
  2783. return checkedValue.value === itemValue
  2784. ? "form-icon-onoff-checked"
  2785. : "form-icon-onoff-unchecked";
  2786. };
  2787. // 选中项
  2788. const selectItem = (value) => {
  2789. if (props.multiple) {
  2790. // 多选模式
  2791. const index = checkedValue.value.indexOf(value);
  2792. if (index === -1) {
  2793. checkedValue.value = [...checkedValue.value, value];
  2794. } else {
  2795. // 取消选中当前项
  2796. const newValue = checkedValue.value.filter((v) => v !== value);
  2797. // 如果不允许为空且取消后为空,则阻止取消操作 by xu 20251212
  2798. if (!props.null && newValue.length === 0) {
  2799. return; // 阻止取消最后一项
  2800. }
  2801. checkedValue.value = newValue;
  2802. }
  2803. } else {
  2804. // 单选模式
  2805. // 如果点击的是当前已选中的项,判断是否允许取消 by xu 20251212
  2806. if (checkedValue.value === value) {
  2807. if (!props.null) {
  2808. return; // 不允许为空时,阻止取消
  2809. }
  2810. checkedValue.value = ""; // 允许为空时,取消选中
  2811. } else {
  2812. checkedValue.value = value;
  2813. }
  2814. }
  2815. emit("update:modelValue", checkedValue.value);
  2816. nextTick(() => {
  2817. // 触发验证
  2818. if (window.ssVm) {
  2819. window.ssVm.validateField(props.name);
  2820. }
  2821. });
  2822. };
  2823. return { checkedValue, genIconName, selectItem };
  2824. },
  2825. // 使用渲染函数定义模板逻辑
  2826. render() {
  2827. const SsFormIcon = resolveComponent("ss-form-icon");
  2828. return h("div", { class: "radio-container" }, [
  2829. // 根据情况创建 input
  2830. this.multiple
  2831. ? this.checkedValue.length
  2832. ? // 多选且有选中值:为选中项创建 input
  2833. this.checkedValue.map((value) =>
  2834. h("input", {
  2835. type: "checkbox",
  2836. name: this.name,
  2837. value: value,
  2838. checked: true,
  2839. style: { display: "none" },
  2840. })
  2841. )
  2842. : // 多选但没有选中值:创建一个空值 input
  2843. h("input", {
  2844. type: "hidden",
  2845. name: this.name,
  2846. value: "",
  2847. })
  2848. : // 单选模式:创建一个 input
  2849. h("input", {
  2850. type: "hidden",
  2851. name: this.name,
  2852. value: this.checkedValue || "",
  2853. }),
  2854. this.opt.map((item, i) =>
  2855. h(
  2856. "div",
  2857. {
  2858. key: i,
  2859. class: {
  2860. checked: this.multiple
  2861. ? this.checkedValue.includes(item.value)
  2862. : this.checkedValue === item.value,
  2863. },
  2864. style: { width: item.width },
  2865. onClick: () => this.selectItem(item.value),
  2866. },
  2867. [
  2868. h("span", null, item.label),
  2869. h("div", { class: "mark" }, [
  2870. h(SsFormIcon, {
  2871. class: this.genIconName(item.value),
  2872. }),
  2873. ]),
  2874. ]
  2875. )
  2876. ),
  2877. ]);
  2878. },
  2879. };
  2880. // ss-onoff 一个按钮
  2881. const Ssonoff = {
  2882. name: "Ssonoff",
  2883. props: {
  2884. name: {
  2885. type: String,
  2886. required: true,
  2887. },
  2888. label: {
  2889. type: String,
  2890. required: true,
  2891. },
  2892. value: {
  2893. type: [String, Number],
  2894. required: true,
  2895. },
  2896. width: {
  2897. type: String,
  2898. default: "",
  2899. },
  2900. modelValue: [String, Number, Array],
  2901. multiple: {
  2902. type: Boolean,
  2903. default: false,
  2904. },
  2905. null: {
  2906. type: Boolean,
  2907. default: true,
  2908. },
  2909. },
  2910. emits: ["update:modelValue"],
  2911. setup(props, { emit }) {
  2912. const parseModelValue = (val) => {
  2913. if (!val) return [];
  2914. // 如果以逗号开头,去掉开头的逗号
  2915. const cleanValue = val.toString().replace(/^,+/, "");
  2916. if (cleanValue.includes("|")) {
  2917. return cleanValue.split("|");
  2918. }
  2919. if (cleanValue.includes(",")) {
  2920. return cleanValue.split(",");
  2921. }
  2922. return [cleanValue];
  2923. };
  2924. // 判断当前按钮是否选中
  2925. const isChecked = computed(() => {
  2926. if (props.multiple) {
  2927. const currentValue = parseModelValue(props.modelValue);
  2928. return currentValue.includes(props.value.toString());
  2929. // return Array.isArray(props.modelValue) && props.modelValue.includes(props.value);
  2930. }
  2931. return props.modelValue + "" === props.value + ""; //强转为字符串类型再比较(改之前是数字类型和字符串类型作比较,永远为false) Ben 20251206
  2932. });
  2933. // 切换选中状态
  2934. const toggleSelect = () => {
  2935. if (props.multiple) {
  2936. const currentValue = parseModelValue(props.modelValue);
  2937. const index = currentValue.indexOf(props.value.toString());
  2938. let newValue;
  2939. if (index === -1) {
  2940. // 选中当前项
  2941. newValue = [...currentValue, props.value];
  2942. } else {
  2943. // 取消选中当前项
  2944. const filteredValue = currentValue.filter(
  2945. (v) => v !== props.value.toString()
  2946. );
  2947. // 如果不允许为空且取消后为空,则阻止取消操作
  2948. if (!props.null && filteredValue.length === 0) {
  2949. return; // 阻止取消最后一项
  2950. }
  2951. newValue = filteredValue;
  2952. }
  2953. emit("update:modelValue", newValue.join(","));
  2954. } else {
  2955. // 单选模式
  2956. const currentValue = parseModelValue(props.modelValue);
  2957. const isCurrentlySelected = currentValue.includes(
  2958. props.value.toString()
  2959. );
  2960. if (!isCurrentlySelected) {
  2961. // 选中当前项
  2962. emit("update:modelValue", props.value);
  2963. } else {
  2964. // 取消选中当前项
  2965. // 如果不允许为空且当前只有这一项被选中,则阻止取消操作
  2966. if (!props.null && currentValue.length === 1) {
  2967. return; // 阻止取消唯一选中项
  2968. }
  2969. emit("update:modelValue", "");
  2970. }
  2971. }
  2972. nextTick(() => {
  2973. // 触发验证
  2974. if (window.ssVm) {
  2975. window.ssVm.validateField(props.name);
  2976. }
  2977. });
  2978. };
  2979. return { isChecked, toggleSelect };
  2980. },
  2981. render() {
  2982. const SsFormIcon = resolveComponent("ss-form-icon");
  2983. return h("div", { class: "radio-container2" }, [
  2984. // 隐藏的表单元素
  2985. this.multiple
  2986. ? h("input", {
  2987. type: "hidden",
  2988. name: `${this.name}`, // 多选模式下使用数组形式的 name
  2989. value: this.isChecked ? this.value : "",
  2990. })
  2991. : this.isChecked &&
  2992. h("input", {
  2993. // 只有当前按钮被选中时才创建 input
  2994. type: "hidden",
  2995. name: this.name,
  2996. value: this.value,
  2997. }),
  2998. // 按钮显示
  2999. h(
  3000. "div",
  3001. {
  3002. class: { checked: this.isChecked },
  3003. style: { width: this.width },
  3004. onClick: this.toggleSelect,
  3005. },
  3006. [
  3007. h("span", null, this.label),
  3008. h("div", { class: "mark" }, [
  3009. h(SsFormIcon, {
  3010. class: this.isChecked
  3011. ? "form-icon-onoff-checked"
  3012. : "form-icon-onoff-unchecked",
  3013. }),
  3014. ]),
  3015. ]
  3016. ),
  3017. ]);
  3018. },
  3019. };
  3020. // ss-textarea
  3021. const SsTextarea = {
  3022. name: "SsTextarea",
  3023. props: {
  3024. name: {
  3025. type: String,
  3026. required: true,
  3027. },
  3028. placeholder: {
  3029. type: String,
  3030. default: "请输入",
  3031. },
  3032. defaultValue: [String, Number],
  3033. modelValue: [String, Number],
  3034. },
  3035. emits: ["update:modelValue"],
  3036. setup(props, { emit }) {
  3037. const inputValue = ref(props.modelValue || props.defaultValue || "");
  3038. // 监听 modelValue 变化
  3039. watch(
  3040. () => props.modelValue,
  3041. (newVal) => {
  3042. inputValue.value = newVal;
  3043. }
  3044. );
  3045. // 输入事件处理
  3046. const onInput = (event) => {
  3047. const newValue = event.target.value;
  3048. inputValue.value = newValue;
  3049. emit("update:modelValue", newValue);
  3050. // 触发验证
  3051. if (window.ssVm) {
  3052. window.ssVm.validateField(props.name);
  3053. }
  3054. };
  3055. // 失焦时验证
  3056. const onBlur = () => {
  3057. if (window.ssVm) {
  3058. window.ssVm.validateField(props.name);
  3059. }
  3060. };
  3061. return { inputValue, onInput, onBlur };
  3062. },
  3063. render() {
  3064. return h("div", { class: "textarea-container" }, [
  3065. h("div", { class: "textarea" }, [
  3066. // 添加隐藏的 input 用于验证
  3067. h("input", {
  3068. type: "hidden",
  3069. name: this.name,
  3070. value: this.inputValue || "",
  3071. }),
  3072. h("textarea", {
  3073. placeholder: this.placeholder,
  3074. value: this.inputValue,
  3075. onInput: this.onInput,
  3076. onBlur: this.onBlur,
  3077. }),
  3078. ]),
  3079. ]);
  3080. },
  3081. };
  3082. // ss-editor 富文本编辑器 基于Jodit
  3083. const SsEditor = {
  3084. name: "SsEditor",
  3085. props: {
  3086. modelValue: {
  3087. type: String,
  3088. default: "",
  3089. },
  3090. name: {
  3091. type: String,
  3092. default: "",
  3093. },
  3094. url: {
  3095. type: String,
  3096. default: "",
  3097. },
  3098. height: {
  3099. type: [Number, String],
  3100. default: 400,
  3101. },
  3102. placeholder: {
  3103. type: String,
  3104. default: "请输入内容",
  3105. },
  3106. readonly: {
  3107. type: Boolean,
  3108. default: false,
  3109. },
  3110. uploadUrl: {
  3111. type: String,
  3112. default: "/ulByHttp", //原值为“upload” Ben(20251205)
  3113. },
  3114. param: {
  3115. type: Object,
  3116. default: () => ({}),
  3117. },
  3118. },
  3119. emits: ["update:modelValue", "ready", "change"],
  3120. setup(props, { emit }) {
  3121. const SsEditorIcon = resolveComponent("SsEditorIcon");
  3122. const editorRef = ref(null);
  3123. let editorContent = ""; //保存富文本编辑器里面的富文本内容
  3124. const uniqueId = "editor-" + Date.now();
  3125. const errMsg = Vue.ref("");
  3126. let fjid = ref(props.param.button.val);
  3127. let fjName = props.param.button.desc;
  3128. let mode = props.param.mode;
  3129. const validate = () => {
  3130. if (window.ssVm) {
  3131. const result = window.ssVm.validateField(props.name);
  3132. console.log("validate", window.ssVm.validateField(props.name));
  3133. errMsg.value = result.valid ? "" : result.message;
  3134. }
  3135. };
  3136. onMounted(() => {
  3137. validate();
  3138. const editor = Jodit.make(`#${uniqueId}`, {
  3139. height: props.height,
  3140. placeholder: props.placeholder,
  3141. readonly: props.readonly,
  3142. language: "zh_cn",
  3143. i18n: {
  3144. zh_cn: {
  3145. Link: "链接",
  3146. URL: "链接",
  3147. "No follow": "无跟踪",
  3148. "Class name": "类名",
  3149. Image: "图片",
  3150. File: "文件",
  3151. "Line height": "行高",
  3152. Alternative: "描述",
  3153. "Alternative text": "描述",
  3154. "Lower Alpha": "小写字母",
  3155. "Upper Alpha": "大写字母",
  3156. "Upper Roman": "大写罗马数字",
  3157. "Lower Roman": "小写罗马数字",
  3158. "Lower Greek": "小写希腊字母",
  3159. "Lower Letter": "小写字母",
  3160. "Upper Letter": "大写字母",
  3161. },
  3162. },
  3163. showXPathInStatusbar: false,
  3164. showCharsCounter: false,
  3165. showWordsCounter: false,
  3166. allowResizeY: false,
  3167. toolbarSticky: false,
  3168. statusbar: false,
  3169. uploader: {
  3170. url: props.uploadUrl,
  3171. format: "json",
  3172. method: "POST",
  3173. filesVariableName: function (i) {
  3174. return "imgs[" + i + "]";
  3175. },
  3176. headers: {
  3177. Accept: "application/json",
  3178. },
  3179. prepareData: function (formData) {
  3180. // 这里可以在发送前处理表单数据
  3181. return formData;
  3182. },
  3183. isSuccess: function (resp) {
  3184. console.log("isSuccess resp:", resp);
  3185. return resp.code === 0;
  3186. },
  3187. getMessage: function (resp) {
  3188. console.log("getMessage resp:", resp);
  3189. return resp.msg || "上传失败";
  3190. },
  3191. process: function (resp) {
  3192. console.log("process resp:", resp);
  3193. return resp.data.url;
  3194. },
  3195. error: function (e) {
  3196. console.error("上传失败:", e.message);
  3197. },
  3198. defaultHandlerSuccess: function (resp) {
  3199. console.log("上传成功:", resp);
  3200. },
  3201. defaultHandlerError: function (err) {
  3202. console.error("上传错误:", err);
  3203. },
  3204. contentType: function (requestData) {
  3205. // 可以根据需要修改 Content-Type
  3206. return false; // 让浏览器自动设置
  3207. },
  3208. },
  3209. // 自定义字体列表
  3210. controls: {
  3211. font: {
  3212. list: {
  3213. Arial: "Arial",
  3214. SimSun: "宋体",
  3215. SimHei: "黑体",
  3216. "Microsoft YaHei": "微软雅黑",
  3217. KaiTi: "楷体",
  3218. FangSong: "仿宋",
  3219. "Times New Roman": "Times New Roman",
  3220. "Courier New": "Courier New",
  3221. },
  3222. },
  3223. customLinkButton: {
  3224. name: "link",
  3225. tooltip: "附件",
  3226. exec: function (editor) {
  3227. // 按钮点击时的处理函数
  3228. console.log("附件点击了");
  3229. console.log("param", props.param);
  3230. console.log("cmsAddUrl", props.param.button.cmsAddUrl);
  3231. if (fjid.value == null || fjid.value == "") {
  3232. $.ajax({
  3233. type: "post",
  3234. url: props.param.button.cmsAddUrl,
  3235. async: false,
  3236. data: {
  3237. name: "fjid",
  3238. ssNrObjName: "sh",
  3239. ssNrObjId: "",
  3240. },
  3241. success: function (_fjid) {
  3242. console.log("cmsAddUrl success", _fjid);
  3243. fjid.value = _fjid;
  3244. },
  3245. });
  3246. }
  3247. var str =
  3248. "&nrid=T-" +
  3249. fjid.value +
  3250. "&objectId=" +
  3251. fjid.value +
  3252. "&objectName=" +
  3253. fjName +
  3254. "&callback=" +
  3255. (window["fjidCallbackName"] || "");
  3256. console.log("str", str);
  3257. SS.openDialog({
  3258. src: props.param.button.cmsUpdUrl + str,
  3259. headerTitle: "编辑",
  3260. width: 900,
  3261. high: 664,
  3262. zIndex: 51,
  3263. });
  3264. // ss.display.showComponent({
  3265. // show: ["wdDialog"],
  3266. // url: props.param.button.cmsUpdUrl + str,
  3267. // title: "编辑",
  3268. // width: 900,
  3269. // high: 664,
  3270. // });
  3271. },
  3272. },
  3273. },
  3274. toolbarAdaptive: true,
  3275. buttons: [
  3276. "fullsize",
  3277. "bold",
  3278. "italic",
  3279. "underline",
  3280. "strikethrough",
  3281. "eraser",
  3282. "|",
  3283. "font",
  3284. "fontsize",
  3285. "brush",
  3286. "paragraph",
  3287. "|",
  3288. "left",
  3289. "center",
  3290. "right",
  3291. "justify",
  3292. "|",
  3293. "ul",
  3294. "ol",
  3295. "indent",
  3296. "outdent",
  3297. "|",
  3298. "image",
  3299. "table",
  3300. "customLinkButton",
  3301. "print",
  3302. "|",
  3303. "undo",
  3304. "redo",
  3305. "find",
  3306. ],
  3307. // 中等宽度时显示的按钮
  3308. buttonsMD: [
  3309. "fullsize",
  3310. "bold",
  3311. "italic",
  3312. "underline",
  3313. "strikethrough",
  3314. "eraser",
  3315. "|",
  3316. "font",
  3317. "fontsize",
  3318. "brush",
  3319. "paragraph",
  3320. "|",
  3321. "font",
  3322. "fontsize",
  3323. "|",
  3324. "left",
  3325. "center",
  3326. "right",
  3327. "justify",
  3328. "|",
  3329. "image",
  3330. "customLinkButton",
  3331. "|",
  3332. "dots", // 其余按钮会自动进入 dots 菜单
  3333. ],
  3334. // 小屏幕时显示的按钮
  3335. buttonsSM: ["fullsize", "bold", "italic", "|", "image", "|", "dots"],
  3336. // 超小屏幕时显示的按钮
  3337. buttonsXS: ["fullsize", "bold", "|", "dots"],
  3338. // 设置响应式断点
  3339. sizeLG: 1024, // 大屏幕
  3340. sizeMD: 768, // 中等屏幕
  3341. sizeSM: 576, // 小屏幕
  3342. // 自定义图标
  3343. getIcon: function (name, clearName) {
  3344. // 定义图标映射
  3345. const iconMap = {
  3346. bold: "editor-icon-bold",
  3347. italic: "editor-icon-italic",
  3348. underline: "editor-icon-underline",
  3349. strikethrough: "editor-icon-strikethrough",
  3350. eraser: "editor-icon-eraser",
  3351. copyformat: "editor-icon-copyformat",
  3352. font: "editor-icon-font",
  3353. fontsize: "editor-icon-fontsize",
  3354. brush: "editor-icon-brush",
  3355. paragraph: "editor-icon-paragraph",
  3356. left: "editor-icon-align-left",
  3357. center: "editor-icon-align-center",
  3358. right: "editor-icon-align-right",
  3359. justify: "editor-icon-align-justify",
  3360. ul: "editor-icon-ul",
  3361. ol: "editor-icon-ol",
  3362. indent: "editor-icon-indent",
  3363. outdent: "editor-icon-outdent",
  3364. image: "editor-icon-image",
  3365. file: "editor-icon-file",
  3366. video: "editor-icon-video",
  3367. table: "editor-icon-table",
  3368. link: "editor-icon-link",
  3369. source: "editor-icon-source",
  3370. eye: "editor-icon-preview",
  3371. fullsize: "editor-icon-fullsize",
  3372. shrink: "editor-icon-fullsize-exit", // 添加退出全屏图标
  3373. print: "editor-icon-print",
  3374. undo: "editor-icon-undo",
  3375. redo: "editor-icon-redo",
  3376. search: "editor-icon-find",
  3377. selectall: "editor-icon-selectall",
  3378. };
  3379. // 获取对应的图标类名
  3380. const iconClass = iconMap[clearName] || iconMap[name];
  3381. if (iconClass) {
  3382. // 返回带有我们自定义图标类的 span 元素
  3383. return `<span class="editor-icon ${iconClass}"></span>`;
  3384. }
  3385. return null;
  3386. },
  3387. });
  3388. // 设置初始值
  3389. editor.value = editorContent;
  3390. // editor.value = props.modelValue;
  3391. // 监听变化
  3392. editor.events.on("change", () => {
  3393. // emit("update:modelValue", editor.value);
  3394. editorContent = editor.value;
  3395. // alert('editorContent:'+editorContent);
  3396. let contentElements = document.getElementsByName(
  3397. props.name.replace(/wj$/, "") + "Edit"
  3398. );
  3399. if (contentElements.length > 0) {
  3400. contentElements[0].value = editorContent;
  3401. }
  3402. emit("change", editor.value);
  3403. setTimeout(() => {
  3404. validate();
  3405. }, 50);
  3406. });
  3407. // 保存编辑器实例
  3408. editorRef.value = editor;
  3409. emit("ready", editor);
  3410. //回显编辑器富文本文件
  3411. if (props.url) {
  3412. const params = new URLSearchParams();
  3413. if (mode) params.append("mode", mode);
  3414. if (props.modelValue) params.append("path", props.modelValue);
  3415. // alert('props.url:'+props.url+',props.modelValue:'+props.modelValue);
  3416. axios
  3417. .post(props.url, params, {
  3418. headers: {
  3419. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  3420. },
  3421. })
  3422. .then((response) => {
  3423. // alert(JSON.stringify(response.data));
  3424. if ("timeout" == response.data.statusText) {
  3425. alert("网络超时!");
  3426. return;
  3427. }
  3428. let content = response.data.content;
  3429. if (content) {
  3430. // editor.value = content;
  3431. editorRef.value.value = content;
  3432. editorContent = content;
  3433. // alert('editor.value:'+editor.value)
  3434. }
  3435. let filePath = response.data.path;
  3436. // alert('response.data:'+JSON.stringify(response.data));
  3437. if (filePath) {
  3438. props.modelValue = filePath;
  3439. emit("update:modelValue", filePath);
  3440. }
  3441. });
  3442. }
  3443. });
  3444. // 监听值变化
  3445. watch(
  3446. // () => props.modelValue,
  3447. () => editorContent,
  3448. (newValue) => {
  3449. if (editorRef.value && newValue !== editorRef.value.value) {
  3450. editorRef.value.value = newValue || "";
  3451. }
  3452. }
  3453. );
  3454. // 监听只读状态变化
  3455. watch(
  3456. () => props.readonly,
  3457. (newValue) => {
  3458. if (editorRef.value) {
  3459. editorRef.value.setReadOnly(newValue);
  3460. }
  3461. }
  3462. );
  3463. // 组件销毁时清理
  3464. onBeforeUnmount(() => {
  3465. if (editorRef.value) {
  3466. editorRef.value.destruct();
  3467. }
  3468. });
  3469. return () =>
  3470. h("div", { class: "ss-editor-container" }, [
  3471. fjid.value &&
  3472. h("input", {
  3473. type: "hidden",
  3474. name: "fjid",
  3475. value: fjid.value,
  3476. }),
  3477. h("input", {
  3478. type: "hidden",
  3479. name: props.name.replace(/wj$/, "") + "Edit",
  3480. value: editorContent,
  3481. // value: props.modelValue,
  3482. }),
  3483. h("input", {
  3484. type: "hidden",
  3485. name: props.name.replace(/wj$/, "") + "wj",
  3486. value: props.modelValue,
  3487. // value: props.url
  3488. }),
  3489. h("input", { type: "hidden", name: "ueditorpath", value: "mswj" }),
  3490. h("textarea", { id: uniqueId }),
  3491. ]);
  3492. },
  3493. };
  3494. // 弹窗右边图标
  3495. const SsFullStyleHeader = {
  3496. name: "SsFullStyleHeader",
  3497. props: {
  3498. title: {
  3499. type: String,
  3500. default: "标题",
  3501. },
  3502. },
  3503. emits: ["close"],
  3504. setup(props, { emit }) {
  3505. // console.log(props.title)
  3506. const onClose = () => {
  3507. emit("close");
  3508. };
  3509. const SsIcon = resolveComponent("ss-icon");
  3510. return () =>
  3511. h("div", { class: "header-container" }, [
  3512. h("div", { class: "title" }, props.title),
  3513. h("div", { class: "handle-bar" }, [
  3514. h("div", { class: "left-bar" }, [
  3515. h(SsDialogIcon, { class: "dialog-icon-download" }),
  3516. h(SsDialogIcon, { class: "dialog-icon-print" }),
  3517. h(SsDialogIcon, { class: "dialog-icon-setting" }),
  3518. h(SsDialogIcon, { class: "dialog-icon-collect" }),
  3519. h(SsDialogIcon, { class: "dialog-icon-help" }),
  3520. h(SsDialogIcon, { class: "dialog-icon-full-screen" }),
  3521. h(SsDialogIcon, { class: "dialog-icon-lock" }),
  3522. ]),
  3523. h("div", { class: "close-bar", onClick: onClose }, [
  3524. h(SsDialogIcon, { class: "dialog-icon-close" }),
  3525. ]),
  3526. ]),
  3527. ]);
  3528. },
  3529. };
  3530. // ss-dialog弹窗
  3531. const SsDialog = {
  3532. name: "SsDialog",
  3533. props: {
  3534. src: {
  3535. type: String,
  3536. },
  3537. headerTitle: {
  3538. type: String,
  3539. // required: true,
  3540. default: "弹窗",
  3541. },
  3542. width: {
  3543. type: String,
  3544. default: "1400",
  3545. },
  3546. height: {
  3547. type: String,
  3548. default: "600",
  3549. },
  3550. params: {
  3551. type: Object,
  3552. default: () => ({}),
  3553. },
  3554. zIndex: {
  3555. type: Number,
  3556. default: 1000,
  3557. },
  3558. },
  3559. emits: ["close"],
  3560. setup(props, { slots, emit }) {
  3561. // 关闭窗口方法
  3562. const onClose = () => {
  3563. emit("close");
  3564. };
  3565. const showHeader = ref(true);
  3566. const headerVisible = ref(false);
  3567. const popupHieght = ref(props.height);
  3568. // 状态:存储位置信息
  3569. const position = reactive({
  3570. // 页面居中
  3571. x: (window.innerWidth - props.width) / 2,
  3572. y: (window.innerHeight - popupHieght.value) / 2,
  3573. isDragging: false,
  3574. offsetX: 0,
  3575. offsetY: 0,
  3576. });
  3577. // 鼠标按下时设置起始坐标并开始拖拽
  3578. const startDrag = (event) => {
  3579. position.isDragging = true;
  3580. position.offsetX = event.clientX - position.x;
  3581. position.offsetY = event.clientY - position.y;
  3582. };
  3583. // 鼠标移动时更新位置
  3584. const onDrag = (event) => {
  3585. if (position.isDragging) {
  3586. position.x = event.clientX - position.offsetX;
  3587. position.y = event.clientY - position.offsetY;
  3588. }
  3589. };
  3590. // 鼠标放开时结束拖拽
  3591. const endDrag = () => {
  3592. position.isDragging = false;
  3593. };
  3594. // 监听来自 iframe 的消息
  3595. const handleMessage = (event) => {
  3596. // 顶天立地
  3597. if (event.data && typeof event.data.hasScrollBar !== "undefined") {
  3598. if (event.data.hasScrollBar) {
  3599. // console.log(event);
  3600. position.y = 10;
  3601. showHeader.value = false;
  3602. headerVisible.value = true;
  3603. popupHieght.value = window.innerHeight - 20;
  3604. // console.log(popupHieght.value);
  3605. document.querySelector(".body").style.height = "100%";
  3606. document.querySelector(".body").style.paddingTop = "30px";
  3607. document.querySelector(".header-container ").style.position =
  3608. "absolute";
  3609. document.querySelector(".header-container ").style.zIndex = "10";
  3610. }
  3611. }
  3612. };
  3613. // 鼠标移入关闭按钮区域时显示头部
  3614. const onMouseEnterCloseButton = () => {
  3615. headerVisible.value = false;
  3616. };
  3617. // 鼠标移出关闭按钮区域时隐藏头部
  3618. const onMouseLeaveCloseButton = () => {
  3619. headerVisible.value = true;
  3620. };
  3621. // 在组件挂载时添加全局事件监听器
  3622. Vue.onMounted(() => {
  3623. // 如果传过来的高度大于窗口高度,则设置为窗口高度减去20 否则保持传过来的高度
  3624. popupHieght.value =
  3625. popupHieght.value > window.innerHeight
  3626. ? window.innerHeight - 20
  3627. : popupHieght.value;
  3628. const container = document.querySelector(".header-container");
  3629. if (container) {
  3630. container.addEventListener("mousedown", startDrag);
  3631. }
  3632. document.addEventListener("mousemove", onDrag);
  3633. document.addEventListener("mouseup", endDrag);
  3634. window.addEventListener("message", handleMessage);
  3635. });
  3636. // 在组件卸载时移除全局事件监听器
  3637. Vue.onUnmounted(() => {
  3638. document.removeEventListener("mousemove", onDrag);
  3639. document.removeEventListener("mouseup", endDrag);
  3640. window.removeEventListener("message", handleMessage);
  3641. });
  3642. const SsMark = resolveComponent("ss-mark");
  3643. const SsFullStyleHeader = resolveComponent("ss-full-style-header");
  3644. // render函数定义组件结构
  3645. return () =>
  3646. h(
  3647. Teleport,
  3648. { to: "body" }, // 使用 Teleport 将弹窗内容挂载到 body
  3649. h(SsMark, {}, [
  3650. h(
  3651. "div",
  3652. {
  3653. class: "popup-container",
  3654. style: {
  3655. position: "absolute",
  3656. left: `${position.x}px`,
  3657. top: `${position.y}px`,
  3658. width: props.width + "px",
  3659. height: popupHieght.value + "px",
  3660. zIndex: props.zIndex, // 确保弹窗在最上层
  3661. },
  3662. },
  3663. [
  3664. h(SsFullStyleHeader, {
  3665. class: "header",
  3666. title: props.headerTitle,
  3667. onClose: onClose,
  3668. onMousedown: startDrag, // 绑定拖动事件
  3669. onMouseUp: endDrag,
  3670. ...(!showHeader.value && {
  3671. onMouseenter: onMouseEnterCloseButton,
  3672. onMouseleave: onMouseLeaveCloseButton,
  3673. }),
  3674. style: {
  3675. cursor: position.isDragging ? "grabbing" : "grab",
  3676. visibility: headerVisible.value ? "hidden" : "visible",
  3677. },
  3678. }),
  3679. h(
  3680. "div",
  3681. {
  3682. class: "body",
  3683. style: {},
  3684. },
  3685. [
  3686. h("iframe", {
  3687. src: props.src,
  3688. frameborder: 0,
  3689. style: { width: "100%", height: "100%" },
  3690. }),
  3691. ]
  3692. ),
  3693. headerVisible.value &&
  3694. h("div", {
  3695. class: "close-button",
  3696. onMouseenter: onMouseEnterCloseButton,
  3697. onMouseleave: onMouseLeaveCloseButton,
  3698. style: {
  3699. position: "absolute",
  3700. top: "0",
  3701. right: "0",
  3702. // background: 'black',
  3703. width: "60px",
  3704. height: "60px",
  3705. cursor: "pointer",
  3706. },
  3707. }),
  3708. ]
  3709. ),
  3710. ])
  3711. );
  3712. },
  3713. };
  3714. // ss-mark遮罩层
  3715. const SsMark = {
  3716. name: "SsMark",
  3717. setup(props, { slots, emit }) {
  3718. return () =>
  3719. h("div", { class: "dialog-container" }, [
  3720. h("div", { class: "mark-content" }, [
  3721. h("div", { class: "dialog-contianer" }, [
  3722. slots.default ? slots.default() : "",
  3723. ]),
  3724. ]),
  3725. ]);
  3726. },
  3727. };
  3728. // ss-bottom-button 底部按钮
  3729. // 修改支持更多按钮 by xu 20251211
  3730. const SsBottomButton = {
  3731. name: "SsBottomButton",
  3732. props: {
  3733. text: {
  3734. type: String,
  3735. required: false,
  3736. },
  3737. type: {
  3738. type: String,
  3739. default: "button",
  3740. },
  3741. iconClass: {
  3742. type: String,
  3743. },
  3744. class: {
  3745. type: String,
  3746. default: "",
  3747. },
  3748. onclick: {
  3749. type: [Function, String],
  3750. default: null,
  3751. },
  3752. // 修改支持更多按钮 by xu 20251211
  3753. more: {
  3754. type: [Boolean, String],
  3755. default: false,
  3756. },
  3757. },
  3758. setup(props, { emit }) {
  3759. const SsBottomDivIcon = Vue.resolveComponent("ss-bottom-div-icon");
  3760. const showDropdown = Vue.ref(false);
  3761. // 修改支持更多按钮 by xu 20251211
  3762. const moreKey = Vue.computed(() => {
  3763. const val = props.more;
  3764. if (val === false || val === null || typeof val === "undefined") {
  3765. return null;
  3766. }
  3767. if (val === true || val === "" || val === "true") {
  3768. return "moreChg";
  3769. }
  3770. return val;
  3771. });
  3772. // 从配置中读取按钮信息和下拉选项
  3773. const config = Vue.computed(() => {
  3774. if (
  3775. moreKey.value &&
  3776. window.ss &&
  3777. window.ss.dom &&
  3778. window.ss.dom.btnElemConfig
  3779. ) {
  3780. return window.ss.dom.btnElemConfig[moreKey.value] || {};
  3781. }
  3782. return {};
  3783. });
  3784. const buttonText = Vue.computed(() => {
  3785. return props.text || config.value.desc || "";
  3786. });
  3787. const dropOptions = Vue.computed(() => {
  3788. return config.value.dropOptions || [];
  3789. });
  3790. const hasDropdown = Vue.computed(() => {
  3791. return dropOptions.value.length > 0;
  3792. });
  3793. const handleMouseEnter = () => {
  3794. if (hasDropdown.value) {
  3795. showDropdown.value = true;
  3796. }
  3797. };
  3798. const handleMouseLeave = () => {
  3799. showDropdown.value = false;
  3800. };
  3801. const handleDropItemClick = (option) => {
  3802. if (option.callback && typeof option.callback === "function") {
  3803. option.callback();
  3804. }
  3805. showDropdown.value = false;
  3806. };
  3807. return () =>
  3808. h(
  3809. "div",
  3810. {
  3811. class: "ss-bottom-button-wrapper",
  3812. onMouseenter: handleMouseEnter,
  3813. onMouseleave: handleMouseLeave,
  3814. },
  3815. [
  3816. h(
  3817. "button",
  3818. {
  3819. class: props.class,
  3820. onClick: (e) => {
  3821. e.stopPropagation();
  3822. emit("click", e);
  3823. if (props.onclick) {
  3824. // 如果是函数直接调用
  3825. if (typeof props.onclick === "function") {
  3826. props.onclick(e);
  3827. } else if (typeof props.onclick === "string") {
  3828. // 如果是字符串,使用直接的方法执行
  3829. // 临时存储按钮元素到全局变量
  3830. window.__ss_current_button = e.currentTarget;
  3831. // 直接执行代码,使用eval以保留原始上下文
  3832. try {
  3833. eval(props.onclick);
  3834. } finally {
  3835. // 清理全局变量
  3836. delete window.__ss_current_button;
  3837. }
  3838. }
  3839. }
  3840. },
  3841. type: props.type,
  3842. },
  3843. [
  3844. h("span", null, [
  3845. h(SsBottomDivIcon, {
  3846. class: props.iconClass,
  3847. }),
  3848. ]),
  3849. h("span", null, buttonText.value),
  3850. ]
  3851. ),
  3852. // 渲染下拉菜单
  3853. hasDropdown.value && showDropdown.value
  3854. ? h(
  3855. "div",
  3856. {
  3857. class: "ss-bottom-button-dropdown",
  3858. },
  3859. dropOptions.value.map((option) =>
  3860. h(
  3861. "div",
  3862. {
  3863. class: "ss-bottom-button-dropdown-item",
  3864. onClick: (e) => {
  3865. e.stopPropagation();
  3866. handleDropItemClick(option);
  3867. },
  3868. },
  3869. option.desc
  3870. )
  3871. )
  3872. )
  3873. : null,
  3874. ]
  3875. );
  3876. },
  3877. };
  3878. // ss-search搜索框
  3879. const SsSearch = {
  3880. name: "SsSearch",
  3881. props: {
  3882. theme: {
  3883. type: String,
  3884. default: "light",
  3885. validator: function (value) {
  3886. return ["dark", "light"].includes(value);
  3887. },
  3888. },
  3889. placeholder: {
  3890. type: String,
  3891. default: "请输入搜索条件",
  3892. },
  3893. },
  3894. setup(props, { emit }) {
  3895. const onClick = () => {
  3896. console.log("Search clicked");
  3897. emit("click");
  3898. };
  3899. const SsIcon = Vue.resolveComponent("ss-icon");
  3900. return () =>
  3901. Vue.h(
  3902. "div",
  3903. {
  3904. class: ["search-container", props.theme],
  3905. onClick: onClick,
  3906. },
  3907. [
  3908. Vue.h("input", {
  3909. placeholder: props.placeholder,
  3910. disabled: true,
  3911. }),
  3912. Vue.h(SsIcon, {
  3913. name: "search-result",
  3914. size: "20px",
  3915. }),
  3916. ]
  3917. );
  3918. },
  3919. };
  3920. // ss-cart-item 菜单页面的卡片 左右结构
  3921. const SsCartItem = {
  3922. name: "SsCartItem",
  3923. props: {
  3924. active: Boolean,
  3925. item: {
  3926. type: Object,
  3927. default: () => ({
  3928. thumb: "images/example/project-img.png",
  3929. title: "广州(国际)科技成果转化天河基地专",
  3930. description: "佳能中国广州分公司",
  3931. all: 50,
  3932. finish: 5,
  3933. }),
  3934. },
  3935. },
  3936. setup(props, { emit }) {
  3937. const item = props.item;
  3938. const itemWidth = Vue.computed(() => {
  3939. const containerWidth =
  3940. document.body.clientWidth || document.body.scrollWidth - 520;
  3941. const halfWidth = containerWidth / 2;
  3942. if (halfWidth < 480) {
  3943. return Math.min(containerWidth, 702) + "px";
  3944. } else {
  3945. return Math.min(halfWidth, 702) + "px";
  3946. }
  3947. });
  3948. const onItemClick = (e) => {
  3949. emit("click", e);
  3950. };
  3951. return {
  3952. item,
  3953. itemWidth,
  3954. onItemClick,
  3955. };
  3956. },
  3957. render() {
  3958. const SsIcon = Vue.resolveComponent("ss-icon");
  3959. return Vue.h(
  3960. "div",
  3961. {
  3962. class: { "item-container": true, active: this.active },
  3963. onClick: this.onItemClick,
  3964. style: { width: this.itemWidth },
  3965. },
  3966. [
  3967. Vue.h("div", { class: "header" }, [
  3968. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  3969. ]),
  3970. Vue.h("div", { class: "body" }, [
  3971. Vue.h("div", { class: "left" }, [
  3972. Vue.h("img", {
  3973. src: this.item.thumb,
  3974. alt: "Thumbnail",
  3975. class: "imgUnHandle",
  3976. style: { "object-fit": "cover", width: "100%", height: "100%" },
  3977. }),
  3978. ]),
  3979. Vue.h("div", { class: "right" }, [
  3980. Vue.h("div", { class: "title" }, this.item.title),
  3981. Vue.h("div", { class: "desc" }, this.item.description),
  3982. Vue.h("div", { class: "progress" }, [
  3983. Vue.h(
  3984. "div",
  3985. {
  3986. style: {
  3987. width: `${(this.item.finish / this.item.all) * 100}%`,
  3988. },
  3989. },
  3990. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  3991. ),
  3992. ]),
  3993. ]),
  3994. ]),
  3995. ]
  3996. );
  3997. },
  3998. };
  3999. // ss-cart-item2 菜单页面的卡片 上下结构
  4000. const SsCartItem2 = {
  4001. name: "SsCartItem2",
  4002. props: {
  4003. active: Boolean,
  4004. item: {
  4005. type: Object,
  4006. default: () => ({
  4007. thumb: "images/example/project-img.png",
  4008. title: "广州(国际)科技成果转化天河基地专",
  4009. description: "佳能中国广州分公司",
  4010. all: 50,
  4011. finish: 5,
  4012. }),
  4013. },
  4014. },
  4015. setup(props, { emit }) {
  4016. const item = props.item;
  4017. const itemWidth = Vue.computed(() => {
  4018. const containerWidth =
  4019. document.body.clientWidth || document.body.scrollWidth - 520;
  4020. const halfWidth = containerWidth / 2;
  4021. if (halfWidth < 480) {
  4022. return Math.min(containerWidth, 702) + "px";
  4023. } else {
  4024. return Math.min(halfWidth, 702) + "px";
  4025. }
  4026. });
  4027. const onItemClick = (e) => {
  4028. emit("click", e);
  4029. };
  4030. return {
  4031. item,
  4032. itemWidth,
  4033. onItemClick,
  4034. };
  4035. },
  4036. render() {
  4037. const SsIcon = Vue.resolveComponent("ss-icon");
  4038. return Vue.h(
  4039. "div",
  4040. {
  4041. class: { "item-container2": true, active: this.active },
  4042. onClick: this.onItemClick,
  4043. style: { width: this.itemWidth },
  4044. },
  4045. [
  4046. Vue.h("div", { class: "action-bar" }, [
  4047. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  4048. ]),
  4049. Vue.h("div", { class: "header" }, [
  4050. Vue.h("div", { class: "title" }, `${this.item.title}`),
  4051. ]),
  4052. Vue.h("div", { class: "body" }, [
  4053. Vue.h("div", { class: "left" }, [
  4054. Vue.h("img", {
  4055. src: this.item.thumb,
  4056. alt: "Thumbnail",
  4057. class: "imgUnHandle",
  4058. style: { "object-fit": "cover", width: "100%", height: "100%" },
  4059. }),
  4060. ]),
  4061. Vue.h("div", { class: "right" }, [
  4062. Vue.h("div", { class: "content" }, this.item.description),
  4063. Vue.h("div", { class: "tip" }, [
  4064. Vue.h("div", { class: "progress" }, [
  4065. Vue.h(
  4066. "div",
  4067. {
  4068. style: {
  4069. width: `${(this.item.finish / this.item.all) * 100}%`,
  4070. },
  4071. },
  4072. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  4073. ),
  4074. ]),
  4075. ]),
  4076. ]),
  4077. ]),
  4078. ]
  4079. );
  4080. },
  4081. };
  4082. /**
  4083. * SsListCard - 列表卡片组件
  4084. *
  4085. * @description 用于显示列表项的卡片组件,支持缩略图、标签、状态、操作按钮和选择功能
  4086. *
  4087. * @prop {Object} item - 卡片数据对象
  4088. * @prop {String} item.title - 卡片标题
  4089. * @prop {String} [item.thumb] - 缩略图 URL(可选)
  4090. * @prop {String} [item.thumbType] - 缩略图类型:'thumbnail'(缩略图)或默认(证件照)
  4091. * @prop {String} [item.status] - 卡片状态:'available'(可用-绿色)、'unavailable'(不可用-黄色)、'disabled'(禁用-红色)
  4092. * @prop {Array} item.tags - 标签数组,格式:[{键: 值}, ...]
  4093. * @prop {Function} item.onclick - 点击卡片的回调函数
  4094. * @prop {Array} [item.buttons] - 操作按钮数组(可选),显示在右上角齿轮
  4095. * @prop {Array} [item.statusIcons] - 状态图标数组(可选),显示在右上角,格式:[{class: '图标类名', title: '提示文字'}, ...]
  4096. *
  4097. * @example
  4098. * // 基础用法
  4099. * const item = {
  4100. * title: "卡片标题",
  4101. * tags: [
  4102. * { 类型: '文档' },
  4103. * { 状态: '进行中' }
  4104. * ],
  4105. * onclick: () => console.log('点击了卡片')
  4106. * };
  4107. *
  4108. * @example
  4109. * // 带缩略图和状态
  4110. * const item = {
  4111. * title: "场地预定",
  4112. * thumbType: 'thumbnail',
  4113. * thumb: "https://example.com/image.jpg",
  4114. * status: "available", // 绿色背景
  4115. * tags: [{ 容量: '50人' }],
  4116. * onclick: () => {}
  4117. * };
  4118. *
  4119. * @example
  4120. * // 带操作按钮和状态图标
  4121. * const item = {
  4122. * title: "会议室A",
  4123. * tags: [{ 楼层: '3F' }],
  4124. * onclick: () => {},
  4125. * // 右上角操作按钮(齿轮)
  4126. * buttons: [{
  4127. * class: 'cart-list-setting',
  4128. * title: '编辑',
  4129. * onclick: () => console.log('编辑')
  4130. * }],
  4131. * // 右上角状态图标(在齿轮右边)
  4132. * statusIcons: [{
  4133. * class: 'icon-emoji',
  4134. * title: '清洁中'
  4135. * }]
  4136. * };
  4137. *
  4138. * @features
  4139. * - 卡片选择:鼠标悬停右下角显示选择角标,点击切换选中状态,选中后显示底部深灰色线条
  4140. * - 状态颜色:根据 status 字段显示不同背景色(可用/不可用/禁用)
  4141. * - 图片类型:支持证件照(73×100px)和缩略图(180×100px)两种尺寸
  4142. * - 操作按钮:右上角齿轮,hover 显示,支持多个按钮下拉菜单
  4143. * - 状态图标:右上角显示状态图标,齿轮会根据图标数量自动左移
  4144. *
  4145. * @author xu
  4146. * @date 20260105
  4147. */
  4148. // 组件文档补全(JSDoc) by xu 20260108
  4149. /**
  4150. * SsListCard(左侧对象卡片)
  4151. *
  4152. * 用途:
  4153. * - 渲染左侧卡片(标题 + tags)
  4154. * - 右下角“角标”用于选中/取消选中(不会触发卡片 click)
  4155. *
  4156. * 调用示例:
  4157. * ```html
  4158. * <ss-list-card :item="item" @toggle-select="handleToggleSelect" @click="openDetail"></ss-list-card>
  4159. * ```
  4160. *
  4161. * Props:
  4162. * - `item`:卡片数据对象(建议含 `id/title/tags[]`;内部会读写 `item._ssSelected` 作为选中态)
  4163. *
  4164. * Emits:
  4165. * - `toggle-select`:点击角标触发,参数 `{ item, selected }`
  4166. * - `click`:点击卡片主体触发(用于打开详情等)
  4167. */
  4168. const SsListCard = {
  4169. name: "SsListCard",
  4170. props: {
  4171. ssObjName: { type: String, default: "" }, // 功能:业务对象名(用于默认缩略图 icon) by xu 20260109
  4172. cardClickAction: { type: String, default: "view" }, // 功能:卡片主体点击动作(view=查看;single=单选互斥) by xu 20260109
  4173. item: {
  4174. type: Object,
  4175. required: true,
  4176. },
  4177. },
  4178. emits: ["click", "change", "toggle-select"],
  4179. setup(props, { emit }) {
  4180. const item = props.item;
  4181. // 移除 itemWidth 计算属性,不再需要 by xu 20260105
  4182. // 判断卡片类型 by xu 20260105
  4183. const cardType = Vue.computed(() => {
  4184. // 支持“无图但保留缩略图占位”(同一业务列表图片形态一致) by xu 20260109
  4185. if (!item.thumb && !item.thumbType) return ""; // 业务列表“无图”形态
  4186. // 根据 thumbType 字段判断,如果没有则默认为证件照
  4187. return item.thumbType === "thumbnail" ? "card-thumbnail" : "card-photo";
  4188. });
  4189. // 判断状态类型 - 场地预定状态 by xu 20260105
  4190. const statusClass = Vue.computed(() => {
  4191. if (!item.status) return ""; // 无状态,默认白色
  4192. // 映射状态值到 CSS 类名
  4193. const statusMap = {
  4194. available: "status-available",
  4195. unavailable: "status-unavailable",
  4196. disabled: "status-disabled",
  4197. };
  4198. return statusMap[item.status] || "";
  4199. });
  4200. const onItemClick = (e) => {
  4201. // 清除所有类型卡片的 active 状态(卡片主体点击仅做 active 高亮) by xu 20260109
  4202. const allListCards = document.querySelectorAll(
  4203. ".knowledge-item-container"
  4204. );
  4205. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  4206. allListCards.forEach((card) => card.classList.remove("active"));
  4207. allFolderCards.forEach((card) => card.classList.remove("active"));
  4208. // 设置当前项的 active 状态
  4209. e.currentTarget.classList.add("active");
  4210. // 卡片主体点击动作由页面级配置控制 by xu 20260109
  4211. if (props.cardClickAction === "view") {
  4212. props.item.onclick?.();
  4213. // 通知父级:卡片点击(查看) by xu 20260109
  4214. emit("click", props.item);
  4215. }
  4216. };
  4217. const onItemChange = (e, icon, index) => {
  4218. e.stopPropagation(); // 阻止事件冒泡到卡片
  4219. props.item.buttons[0].onclick();
  4220. // emit("change", { item: props.item, icon, index });
  4221. };
  4222. return {
  4223. item,
  4224. cardType,
  4225. statusClass,
  4226. onItemClick,
  4227. onItemChange,
  4228. };
  4229. },
  4230. data() {
  4231. return {
  4232. showButtons: false,
  4233. selected: false, // 选择状态 by xu 20260105
  4234. showTextPopover: false, // 功能:右侧文字区 hover 展示全量 by xu 20260108
  4235. textPopoverType: "", // second-summary / second-tags / third / third-full by xu 20260108
  4236. textPopoverBottom: 0, // 功能:popover 从当前省略行位置向上展开 by xu 20260108
  4237. hideTextPopoverTimer: null, // 功能:鼠标从省略行移到浮层的缓冲 by xu 20260108
  4238. textPopoverPayload: null, // { kind, text?, lines? } by xu 20260108
  4239. ellipsisVisible: {
  4240. // 功能:只在真实出现 ... 时才显示命中区/允许 goheight by xu 20260109
  4241. secondSummary: false,
  4242. secondTags: false,
  4243. third: false,
  4244. thirdFull: false,
  4245. },
  4246. };
  4247. },
  4248. methods: {
  4249. __allowSelect() {
  4250. // 功能说明:无 rbarObj 时禁用选中能力(隐藏右下角勾选并禁止 toggle) by xu 20260122
  4251. try {
  4252. if (this?.$root && this.$root.hasObjPanel === false) return false;
  4253. if (
  4254. typeof window !== "undefined" &&
  4255. window.__objListVm &&
  4256. window.__objListVm.hasObjPanel === false
  4257. )
  4258. return false;
  4259. } catch (_) {}
  4260. return true;
  4261. },
  4262. // 切换选择状态(对外 emit,支持方案A父级 state 中转) by xu 20260106
  4263. toggleSelect(e) {
  4264. e.stopPropagation();
  4265. if (!this.__allowSelect()) return; // 功能说明:无 rbarObj 时禁止选中 by xu 20260122
  4266. // 使用 item 上的状态,便于父级/右侧边栏反向同步 by xu 20260106
  4267. this.item._ssSelected = !this.item?._ssSelected;
  4268. this.$emit("toggle-select", {
  4269. item: this.item,
  4270. selected: !!this.item?._ssSelected,
  4271. });
  4272. },
  4273. // 卡片主体点击=单选互斥:只有“本次切到选中”才清理其他选中 by xu 20260109
  4274. toggleSelectExclusive(e) {
  4275. e?.stopPropagation?.();
  4276. if (!this.__allowSelect()) return; // 功能说明:无 rbarObj 时禁止选中 by xu 20260122
  4277. this.item._ssSelected = !this.item?._ssSelected;
  4278. const selected = !!this.item?._ssSelected;
  4279. this.$emit("toggle-select", {
  4280. item: this.item,
  4281. selected,
  4282. exclusive: true,
  4283. });
  4284. },
  4285. // 功能:无缩略图时,用业务对象 icon 做默认图(ss-icon + icon-obj-xx) by xu 20260109
  4286. getBizThumbIconClass() {
  4287. const name = String(
  4288. this.ssObjName ||
  4289. this.item?.ssObjName ||
  4290. this.$root?.ssObjName ||
  4291. window?.ss?.dom?.ssObjName ||
  4292. ""
  4293. ).trim();
  4294. if (!name) return "";
  4295. return `icon-obj-${name}`;
  4296. },
  4297. // 功能:构造右侧文字区 4 行(摘要/类目或标签/对象号) by xu 20260108
  4298. buildRightTextLines() {
  4299. const item = this.item || {};
  4300. const summary = String(item?.desc ?? "").trim(); // 后端字段后续映射 by xu 20260108
  4301. const objNum = String(item?.objNum ?? "").trim(); // 后端字段后续映射 by xu 20260108
  4302. const categoryArr = Array.isArray(item?.category) ? item.category : [];
  4303. const tagsArr = Array.isArray(item?.tags) ? item.tags : [];
  4304. const hasTags = tagsArr.length > 0;
  4305. const hasCategory = categoryArr.length > 0;
  4306. // 第二部分(L1-L3):摘要优先,其次物品参数 by xu 20260108
  4307. const secondKind = summary ? "summary" : hasTags ? "tags" : "";
  4308. const hasSecond = !!secondKind;
  4309. // 第三部分(L4):对象号优先,其次类目 by xu 20260108
  4310. const thirdKind = objNum ? "objNum" : hasCategory ? "category" : "";
  4311. const hasThird = !!thirdKind;
  4312. const thirdFull = !hasSecond && hasThird; // 第二部分为空则第三部分占满 4 行 by xu 20260108
  4313. const secondFull = hasSecond && !hasThird && secondKind === "tags"; // 仅标签时占满 4 行(不留空行) by xu 20260109
  4314. const toValueText = (obj) => {
  4315. // 功能说明:类目/物品参数回显展示 key: value(否则只显示值看不懂) by xu 20260114
  4316. const [k, v] = Object.entries(obj || {})[0] || ["", ""];
  4317. const key = k !== undefined && k !== null ? String(k).trim() : "";
  4318. const val = v !== undefined && v !== null ? String(v).trim() : "";
  4319. if (key && val) return `${key}:${val}`;
  4320. if (val) return val;
  4321. if (key) return key;
  4322. return "";
  4323. };
  4324. const toLineList = (arr) =>
  4325. (arr || [])
  4326. .map(toValueText)
  4327. .map((s) => String(s ?? "").trim())
  4328. .filter(Boolean);
  4329. const flat = (arr) => toLineList(arr).join(" ");
  4330. // 第二部分 tags:默认 3 行;仅标签时占满 4 行(避免底部空一行) by xu 20260109
  4331. const secondTagsMaxLines = secondFull ? 4 : 3;
  4332. const secondTagsLinesFull = toLineList(tagsArr);
  4333. const secondTagsHead = secondTagsLinesFull.slice(
  4334. 0,
  4335. Math.max(0, secondTagsMaxLines - 1)
  4336. );
  4337. const secondTagsTail = secondTagsLinesFull.slice(
  4338. Math.max(0, secondTagsMaxLines - 1)
  4339. );
  4340. const secondTagsLast =
  4341. secondTagsTail.length <= 1
  4342. ? secondTagsTail[0] || ""
  4343. : secondTagsTail.join(" "); // 功能:最后一行平铺剩余 by xu 20260108
  4344. // 第三部分类目:卡片上串成一行;goheight 展开时一条一行 by xu 20260109
  4345. const categoryLinesFull = toLineList(categoryArr);
  4346. const categoryLine = categoryLinesFull.join(" ");
  4347. const thirdText =
  4348. thirdKind === "objNum"
  4349. ? objNum
  4350. : thirdKind === "category"
  4351. ? categoryLine
  4352. : "";
  4353. return {
  4354. secondKind,
  4355. thirdKind,
  4356. hasSecond,
  4357. hasThird,
  4358. thirdFull,
  4359. secondFull,
  4360. summary,
  4361. secondTagsMaxLines,
  4362. secondTagsHead,
  4363. secondTagsLast,
  4364. secondTagsLinesFull,
  4365. objNum,
  4366. categoryLine,
  4367. categoryLinesFull,
  4368. thirdText,
  4369. };
  4370. },
  4371. measureTextOverflowByLines(text, maxLines, width) {
  4372. const w = Number(width) || 0;
  4373. if (!w || !text) return false;
  4374. const probe = document.createElement("div");
  4375. probe.style.position = "fixed";
  4376. probe.style.left = "-99999px";
  4377. probe.style.top = "0";
  4378. probe.style.width = w + "px";
  4379. probe.style.fontSize = "18px";
  4380. probe.style.lineHeight = "24px";
  4381. probe.style.whiteSpace = "normal";
  4382. probe.style.wordBreak = "break-word";
  4383. probe.style.visibility = "hidden";
  4384. probe.textContent = text;
  4385. document.body.appendChild(probe);
  4386. const h = probe.getBoundingClientRect().height || 0;
  4387. document.body.removeChild(probe);
  4388. return h > maxLines * 24 + 1;
  4389. },
  4390. measureSingleLineOverflow(text, width) {
  4391. const w = Number(width) || 0;
  4392. if (!w || !text) return false;
  4393. const probe = document.createElement("span");
  4394. probe.style.position = "fixed";
  4395. probe.style.left = "-99999px";
  4396. probe.style.top = "0";
  4397. probe.style.display = "inline-block";
  4398. probe.style.maxWidth = w + "px";
  4399. probe.style.fontSize = "18px";
  4400. probe.style.lineHeight = "24px";
  4401. probe.style.whiteSpace = "nowrap";
  4402. probe.style.visibility = "hidden";
  4403. probe.textContent = text;
  4404. document.body.appendChild(probe);
  4405. const overflow =
  4406. (probe.scrollWidth || 0) > (probe.clientWidth || w) + 1;
  4407. document.body.removeChild(probe);
  4408. return overflow;
  4409. },
  4410. // 功能:根据当前卡片宽度刷新「是否出现 ...」状态(用于控制命中区显示) by xu 20260109
  4411. refreshEllipsisVisible() {
  4412. try {
  4413. const right = this.$el?.querySelector?.(".right");
  4414. const rawWidth =
  4415. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  4416. const width = Math.max(0, Math.round(rawWidth)); // 修复:内容区不再使用 padding-right 预留,测量按真实宽度 by xu 20260109
  4417. const model = this.buildRightTextLines();
  4418. const next = {
  4419. secondSummary: false,
  4420. secondTags: false,
  4421. third: false,
  4422. thirdFull: false,
  4423. };
  4424. if (model.secondKind === "summary" && model.summary) {
  4425. next.secondSummary = this.measureTextOverflowByLines(
  4426. model.summary,
  4427. 3,
  4428. width
  4429. );
  4430. }
  4431. if (model.secondKind === "tags") {
  4432. // 功能说明:tags 采用「最后一行平铺剩余」策略,是否出现 ... 仅取决于最后一行是否溢出(数量多但平铺放得下不算溢出) by xu 20260114
  4433. next.secondTags = this.measureSingleLineOverflow(
  4434. model.secondTagsLast,
  4435. width
  4436. );
  4437. }
  4438. if (model.hasThird && !model.thirdFull) {
  4439. next.third = this.measureSingleLineOverflow(model.thirdText, width);
  4440. }
  4441. if (model.hasThird && model.thirdFull) {
  4442. next.thirdFull = this.measureTextOverflowByLines(
  4443. model.thirdText,
  4444. 4,
  4445. width
  4446. );
  4447. }
  4448. const prev = this.ellipsisVisible || {};
  4449. const changed =
  4450. prev.secondSummary !== next.secondSummary ||
  4451. prev.secondTags !== next.secondTags ||
  4452. prev.third !== next.third ||
  4453. prev.thirdFull !== next.thirdFull;
  4454. if (changed) this.ellipsisVisible = next;
  4455. } catch (e) {
  4456. // ignore by xu 20260109
  4457. }
  4458. },
  4459. showTextPopoverFor(el, kind) {
  4460. // 调试开关:window.__SS_LISTCARD_DEBUG__ = true 时打印 hover/溢出判断日志 by xu 20260108
  4461. const debug =
  4462. typeof window !== "undefined" && !!window.__SS_LISTCARD_DEBUG__;
  4463. if (debug) {
  4464. console.log("[SsListCard] ellipsis hover", {
  4465. kind,
  4466. el: el?.className,
  4467. });
  4468. }
  4469. const model = this.buildRightTextLines();
  4470. const lineEl = el?.closest?.(".ss-card-text__line") || el;
  4471. const right = lineEl?.closest?.(".right") || el?.closest?.(".right");
  4472. const rawWidth =
  4473. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  4474. const width = Math.max(0, Math.round(rawWidth)); // 修复:内容区不再预留 padding-right,测量按真实宽度 by xu 20260109
  4475. const textEl =
  4476. kind === "second-summary"
  4477. ? lineEl?.querySelector?.(".ss-card-text__secondSummary")
  4478. : kind === "second-tags"
  4479. ? lineEl?.querySelector?.(".ss-card-text__tagLineLast")
  4480. : kind === "third"
  4481. ? lineEl?.querySelector?.(".ss-card-text__thirdLine")
  4482. : lineEl?.querySelector?.(".ss-card-text__thirdFull");
  4483. let payload = null;
  4484. // 仅当真实会出现 ... 时才允许 goheight(避免“没超出也能出 goheight”) by xu 20260109
  4485. const overflowed =
  4486. kind === "second-summary"
  4487. ? this.measureTextOverflowByLines(model.summary, 3, width)
  4488. : kind === "second-tags"
  4489. ? this.measureSingleLineOverflow(model.secondTagsLast, width) // 功能说明:同 refreshEllipsisVisible,tags 仅看最后一行是否溢出 by xu 20260114
  4490. : kind === "third"
  4491. ? this.measureSingleLineOverflow(model.thirdText, width)
  4492. : this.measureTextOverflowByLines(model.thirdText, 4, width);
  4493. if (!overflowed) return;
  4494. if (kind === "second-summary") {
  4495. if (model.summary) payload = { kind, text: model.summary };
  4496. } else if (kind === "second-tags") {
  4497. if (
  4498. Array.isArray(model.secondTagsLinesFull) &&
  4499. model.secondTagsLinesFull.length
  4500. ) {
  4501. payload = { kind, lines: model.secondTagsLinesFull };
  4502. }
  4503. } else if (kind === "third") {
  4504. if (
  4505. model.thirdKind === "category" &&
  4506. Array.isArray(model.categoryLinesFull) &&
  4507. model.categoryLinesFull.length
  4508. ) {
  4509. payload = { kind, lines: model.categoryLinesFull }; // 功能:类目展开一条一行 by xu 20260109
  4510. } else if (model.thirdText) {
  4511. payload = { kind, text: model.thirdText };
  4512. }
  4513. } else if (kind === "third-full") {
  4514. if (
  4515. model.thirdKind === "category" &&
  4516. Array.isArray(model.categoryLinesFull) &&
  4517. model.categoryLinesFull.length
  4518. ) {
  4519. payload = { kind, lines: model.categoryLinesFull }; // 功能:类目占满模式展开一条一行 by xu 20260109
  4520. } else if (model.thirdText) {
  4521. payload = { kind, text: model.thirdText };
  4522. }
  4523. }
  4524. if (debug) {
  4525. console.log("[SsListCard] ellipsis decide", {
  4526. kind,
  4527. rawWidth: Math.round(rawWidth),
  4528. width,
  4529. hasPayload: !!payload,
  4530. textEl: textEl?.className,
  4531. textClient: textEl
  4532. ? {
  4533. cw: textEl.clientWidth,
  4534. ch: textEl.clientHeight,
  4535. sw: textEl.scrollWidth,
  4536. sh: textEl.scrollHeight,
  4537. }
  4538. : null,
  4539. });
  4540. }
  4541. if (!payload) return;
  4542. this.clearHideTextPopoverTimer();
  4543. const container = lineEl?.closest?.(".right");
  4544. const containerRect = container?.getBoundingClientRect?.();
  4545. const lineRect = lineEl?.getBoundingClientRect?.();
  4546. if (containerRect && lineRect) {
  4547. const bottom = Math.max(
  4548. 0,
  4549. Math.round(containerRect.bottom - lineRect.bottom)
  4550. );
  4551. this.textPopoverBottom = bottom;
  4552. } else {
  4553. this.textPopoverBottom = 0;
  4554. }
  4555. this.textPopoverPayload = payload;
  4556. this.textPopoverType = kind;
  4557. this.showTextPopover = true;
  4558. if (debug) console.log("[SsListCard] goheight show", payload);
  4559. },
  4560. isOverflowing(el) {
  4561. if (!el) return false;
  4562. // 单行/多行省略统一判断:scroll 尺寸大于 client 尺寸即认为有 ... by xu 20260108
  4563. return (
  4564. (el.scrollWidth &&
  4565. el.clientWidth &&
  4566. el.scrollWidth > el.clientWidth + 1) ||
  4567. (el.scrollHeight &&
  4568. el.clientHeight &&
  4569. el.scrollHeight > el.clientHeight + 1)
  4570. );
  4571. },
  4572. isSummaryOverflowing(el) {
  4573. if (!el) return false;
  4574. // -webkit-line-clamp 场景下 scrollHeight 不稳定,改用“无 clamp 的离屏测量”判断是否超过 2 行 by xu 20260108
  4575. const text = String(this.item?.desc ?? "").trim();
  4576. if (!text) return false;
  4577. const rect = el.getBoundingClientRect?.();
  4578. const width = rect?.width || el.clientWidth || 0;
  4579. if (!width) return false;
  4580. const probe = document.createElement("div");
  4581. probe.style.position = "fixed";
  4582. probe.style.left = "-99999px";
  4583. probe.style.top = "0";
  4584. probe.style.width = width + "px";
  4585. probe.style.fontSize = "18px";
  4586. probe.style.lineHeight = "24px";
  4587. probe.style.whiteSpace = "normal";
  4588. probe.style.wordBreak = "break-word";
  4589. probe.style.visibility = "hidden";
  4590. probe.textContent = text;
  4591. document.body.appendChild(probe);
  4592. const h = probe.getBoundingClientRect().height || 0;
  4593. document.body.removeChild(probe);
  4594. return h > 48 + 1;
  4595. },
  4596. clearHideTextPopoverTimer() {
  4597. if (this.hideTextPopoverTimer) {
  4598. clearTimeout(this.hideTextPopoverTimer);
  4599. this.hideTextPopoverTimer = null;
  4600. }
  4601. },
  4602. // 修复 goheight hover 无响应:移除重复方法覆盖,统一使用上面的 showTextPopoverFor(el, kind) by xu 20260109
  4603. hideTextPopoverLater() {
  4604. this.clearHideTextPopoverTimer();
  4605. this.hideTextPopoverTimer = setTimeout(() => {
  4606. this.showTextPopover = false;
  4607. this.textPopoverType = "";
  4608. this.textPopoverPayload = null;
  4609. }, 120);
  4610. },
  4611. hideTextPopover() {
  4612. this.clearHideTextPopoverTimer();
  4613. this.showTextPopover = false;
  4614. this.textPopoverType = "";
  4615. this.textPopoverPayload = null;
  4616. },
  4617. // 功能:新需求下不在 updated 内做测量,避免死循环 by xu 20260108
  4618. },
  4619. mounted() {
  4620. // 无需在 mounted/updated 里做 overflow 测量(避免死循环),只在 hover 触发时判断 by xu 20260108
  4621. // 仅用于控制“...命中区是否显示”,不会触发循环更新 by xu 20260109
  4622. this.$nextTick?.(() => {
  4623. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  4624. });
  4625. this.__ssListCardResizeHandler = () => this.refreshEllipsisVisible?.(); // 功能:窗口变化时刷新 ... 显示 by xu 20260109
  4626. window.addEventListener?.("resize", this.__ssListCardResizeHandler);
  4627. },
  4628. updated() {
  4629. // 卡片数据更新后刷新一次 ... 显示状态(避免“宽度/内容变了但命中区不变”) by xu 20260109
  4630. this.$nextTick?.(() => {
  4631. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  4632. });
  4633. },
  4634. beforeUnmount() {
  4635. // 清理 timer,避免残留导致异常 by xu 20260108
  4636. this.clearHideTextPopoverTimer?.();
  4637. if (this.__ssListCardResizeHandler) {
  4638. window.removeEventListener?.("resize", this.__ssListCardResizeHandler);
  4639. this.__ssListCardResizeHandler = null;
  4640. }
  4641. },
  4642. render() {
  4643. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  4644. const SsIcon = Vue.resolveComponent("ss-icon");
  4645. const hasThumbArea = !!(this.item?.thumb || this.item?.thumbType); // 功能:无图但有 thumbType 时仍保留占位 by xu 20260109
  4646. const thumbSrc = (() => {
  4647. // 功能说明:兼容 thumb 为 raw path 或 {val}/{value},组件内统一转为 dlByHttp URL by xu 20260122
  4648. const t = this.item?.thumb;
  4649. if (!t) return "";
  4650. if (typeof t === "string") {
  4651. const s = t.trim();
  4652. if (!s) return "";
  4653. // 已经是 URL/绝对路径则直接使用;否则按 path 构建 dlByHttp by xu 20260122
  4654. if (
  4655. /^https?:\/\//i.test(s) ||
  4656. s.startsWith("/service?") ||
  4657. s.startsWith("/")
  4658. )
  4659. return s;
  4660. return buildThumbUrl(s);
  4661. }
  4662. return buildThumbUrl(t);
  4663. })();
  4664. return Vue.h(
  4665. "div",
  4666. {
  4667. class: {
  4668. "knowledge-item-container": true,
  4669. active: this.item.active,
  4670. [this.cardType]: !!this.cardType, // 动态添加卡片类型类名 by xu 20260105
  4671. [this.statusClass]: !!this.statusClass,
  4672. },
  4673. onClick: (e) => {
  4674. this.onItemClick?.(e);
  4675. if (this.__allowSelect() && this.cardClickAction === "single") {
  4676. // 功能说明:无 rbarObj 时不允许单选互斥 by xu 20260122
  4677. this.toggleSelectExclusive?.(e);
  4678. }
  4679. }, // 功能:卡片主体点击动作(view/single) by xu 20260109
  4680. // 移除固定宽度,由 CSS min-width 控制 by xu 20260105
  4681. },
  4682. [
  4683. // 右上角状态图标区域 by xu 20260105
  4684. this.item?.statusIcons?.length > 0 &&
  4685. Vue.h(
  4686. "div",
  4687. { class: "card-status-icons" },
  4688. this.item.statusIcons.map((icon) =>
  4689. Vue.h(SsIcon, {
  4690. class: `status-icon ${icon.class}`,
  4691. title: icon.title,
  4692. })
  4693. )
  4694. ),
  4695. this.item?.buttons?.length > 0 &&
  4696. Vue.h(
  4697. "div",
  4698. {
  4699. class: "header",
  4700. style:
  4701. this.item?.statusIcons?.length > 0
  4702. ? {
  4703. right: `${this.item.statusIcons.length * 48}px`,
  4704. borderTopRightRadius: "0",
  4705. }
  4706. : {},
  4707. onMouseenter: () => (this.showButtons = true),
  4708. onMouseleave: () => (this.showButtons = false),
  4709. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  4710. },
  4711. [
  4712. // 只在有按钮时渲染设置图标
  4713. // this.item?.buttons?.length > 0 &&
  4714. Vue.h("div", {
  4715. class: "cart-list-setting cart-list-icon",
  4716. title: this.item?.buttons?.[0]?.title,
  4717. }),
  4718. // 鼠标移入时显示按钮列表,与图标同级
  4719. // this.item?.buttons?.length > 0 &&
  4720. this.showButtons &&
  4721. this.item?.buttons?.length > 1 &&
  4722. Vue.h(
  4723. "div",
  4724. {
  4725. class: "cart-list-button-popup",
  4726. },
  4727. this.item.buttons.map((btn) =>
  4728. Vue.h(
  4729. "div",
  4730. {
  4731. onClick: (e) => {
  4732. e.stopPropagation();
  4733. btn.onclick?.();
  4734. },
  4735. },
  4736. [
  4737. // 如果有 class,显示对应的图标
  4738. btn.class &&
  4739. Vue.h(SsCartListIcon, {
  4740. class: [btn.class],
  4741. }),
  4742. // 显示按钮文本
  4743. Vue.h("span", null, btn.title),
  4744. ]
  4745. )
  4746. )
  4747. ),
  4748. ]
  4749. ),
  4750. Vue.h("div", { class: "body" }, [
  4751. Vue.h("div", { class: "box-header" }, [
  4752. Vue.h("div", `${this.item.title}`),
  4753. ]),
  4754. Vue.h(
  4755. "div",
  4756. {
  4757. class: !hasThumbArea ? "no-thumb box-body" : "box-body",
  4758. },
  4759. [
  4760. hasThumbArea
  4761. ? thumbSrc
  4762. ? Vue.h("div", { class: "left" }, [
  4763. Vue.h("img", {
  4764. src: thumbSrc,
  4765. alt: "Thumbnail",
  4766. class: "imgUnHandle",
  4767. style: {
  4768. "object-fit": "cover",
  4769. width: "100%",
  4770. height: "100%",
  4771. },
  4772. }),
  4773. ])
  4774. : Vue.h(
  4775. // 功能:无图占位(ss-icon + biz icon,居中) by xu 20260109
  4776. "div",
  4777. { class: "left ss-objlist-thumbPlaceholder" },
  4778. [
  4779. Vue.h(SsIcon, {
  4780. class: `${this.getBizThumbIconClass()} ss-objlist-thumbIcon`,
  4781. }),
  4782. ]
  4783. )
  4784. : null,
  4785. Vue.h(
  4786. "div",
  4787. {
  4788. class: "right",
  4789. },
  4790. (() => {
  4791. const model = this.buildRightTextLines(); // 功能:右侧文字区新规则(第二部分/第三部分优先级) by xu 20260108
  4792. const hasAny = !!(model?.hasSecond || model?.hasThird);
  4793. if (!hasAny) return [];
  4794. const children = [];
  4795. // 第二部分:L1-L3(摘要优先,其次 tags;不足留空;超出 L3 ...) by xu 20260108
  4796. if (model.hasSecond) {
  4797. if (model.secondKind === "summary") {
  4798. children.push(
  4799. Vue.h(
  4800. "div",
  4801. {
  4802. class:
  4803. "ss-card-text__line ss-card-text__secondBlock",
  4804. },
  4805. [
  4806. Vue.h(
  4807. "div",
  4808. {
  4809. class: "ss-card-text__secondSummary",
  4810. title: model.summary,
  4811. },
  4812. model.summary
  4813. ),
  4814. Vue.h("span", {
  4815. class: [
  4816. "ss-card-text__ellipsisHit",
  4817. "ss-card-text__ellipsisHit--second",
  4818. this.ellipsisVisible?.secondSummary
  4819. ? "is-on"
  4820. : "",
  4821. ],
  4822. title: "查看完整摘要",
  4823. onMouseenter: (e) =>
  4824. this.showTextPopoverFor(
  4825. e?.currentTarget,
  4826. "second-summary"
  4827. ),
  4828. onClick: (e) => {
  4829. e?.stopPropagation?.();
  4830. this.showTextPopoverFor(
  4831. e?.currentTarget,
  4832. "second-summary"
  4833. );
  4834. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  4835. onMouseleave: () => this.hideTextPopoverLater(),
  4836. }),
  4837. ]
  4838. )
  4839. );
  4840. } else if (model.secondKind === "tags") {
  4841. children.push(
  4842. Vue.h(
  4843. "div",
  4844. {
  4845. class: [
  4846. "ss-card-text__line",
  4847. model.secondFull
  4848. ? "ss-card-text__secondFullBlock"
  4849. : "ss-card-text__secondBlock",
  4850. ],
  4851. },
  4852. [
  4853. // 功能:仅标签时占满 4 行 by xu 20260109
  4854. Vue.h(
  4855. "div",
  4856. { class: "ss-card-text__secondTags" },
  4857. [
  4858. ...model.secondTagsHead.map((t) =>
  4859. Vue.h(
  4860. "div",
  4861. {
  4862. class: "ss-card-text__tagLine",
  4863. title: t,
  4864. },
  4865. t
  4866. )
  4867. ),
  4868. // 第三行:平铺剩余(可能为空) by xu 20260108
  4869. Vue.h(
  4870. "div",
  4871. {
  4872. class:
  4873. "ss-card-text__tagLine is-last ss-card-text__tagLineLast",
  4874. title: model.secondTagsLast,
  4875. },
  4876. model.secondTagsLast
  4877. ),
  4878. ].filter(Boolean)
  4879. ),
  4880. // 只在最后一行出现 ... 时才触发 goheight by xu 20260108
  4881. Vue.h("span", {
  4882. class: [
  4883. "ss-card-text__ellipsisHit",
  4884. "ss-card-text__ellipsisHit--second",
  4885. this.ellipsisVisible?.secondTags
  4886. ? "is-on"
  4887. : "",
  4888. ],
  4889. title: "查看完整物品参数",
  4890. onMouseenter: (e) =>
  4891. this.showTextPopoverFor(
  4892. e?.currentTarget,
  4893. "second-tags"
  4894. ),
  4895. onClick: (e) => {
  4896. e?.stopPropagation?.();
  4897. this.showTextPopoverFor(
  4898. e?.currentTarget,
  4899. "second-tags"
  4900. );
  4901. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  4902. onMouseleave: () => this.hideTextPopoverLater(),
  4903. }),
  4904. ]
  4905. )
  4906. );
  4907. }
  4908. }
  4909. // 第三部分:默认 L4;第二部分为空则占满 L1-L4 by xu 20260108
  4910. if (model.hasThird) {
  4911. if (model.thirdFull) {
  4912. children.push(
  4913. Vue.h(
  4914. "div",
  4915. {
  4916. class:
  4917. "ss-card-text__line ss-card-text__thirdFullBlock",
  4918. },
  4919. [
  4920. Vue.h(
  4921. "div",
  4922. {
  4923. class: "ss-card-text__thirdFull",
  4924. title: model.thirdText,
  4925. },
  4926. model.thirdText
  4927. ),
  4928. Vue.h("span", {
  4929. class: [
  4930. "ss-card-text__ellipsisHit",
  4931. "ss-card-text__ellipsisHit--third",
  4932. this.ellipsisVisible?.thirdFull
  4933. ? "is-on"
  4934. : "",
  4935. ],
  4936. title: "查看完整信息",
  4937. onMouseenter: (e) =>
  4938. this.showTextPopoverFor(
  4939. e?.currentTarget,
  4940. "third-full"
  4941. ),
  4942. onClick: (e) => {
  4943. e?.stopPropagation?.();
  4944. this.showTextPopoverFor(
  4945. e?.currentTarget,
  4946. "third-full"
  4947. );
  4948. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  4949. onMouseleave: () => this.hideTextPopoverLater(),
  4950. }),
  4951. ]
  4952. )
  4953. );
  4954. } else {
  4955. children.push(
  4956. Vue.h(
  4957. "div",
  4958. {
  4959. class:
  4960. "ss-card-text__line ss-card-text__thirdLineWrap",
  4961. },
  4962. [
  4963. Vue.h(
  4964. "div",
  4965. {
  4966. class: "ss-card-text__thirdLine",
  4967. title: model.thirdText,
  4968. },
  4969. model.thirdText
  4970. ),
  4971. Vue.h("span", {
  4972. class: [
  4973. "ss-card-text__ellipsisHit",
  4974. "ss-card-text__ellipsisHit--third",
  4975. this.ellipsisVisible?.third ? "is-on" : "",
  4976. ],
  4977. title: "查看完整信息",
  4978. onMouseenter: (e) =>
  4979. this.showTextPopoverFor(
  4980. e?.currentTarget,
  4981. "third"
  4982. ),
  4983. onClick: (e) => {
  4984. e?.stopPropagation?.();
  4985. this.showTextPopoverFor(
  4986. e?.currentTarget,
  4987. "third"
  4988. );
  4989. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  4990. onMouseleave: () => this.hideTextPopoverLater(),
  4991. }),
  4992. ]
  4993. )
  4994. );
  4995. }
  4996. }
  4997. // hover 展开浮层:宽度=右侧文字区,底对齐向上展开,带阴影 by xu 20260108
  4998. // popover 作为 `.right` 的 sibling 渲染,避免被 `.ss-card-text{overflow:hidden}` 裁剪 by xu 20260108
  4999. const popover =
  5000. this.showTextPopover &&
  5001. Vue.h(
  5002. "div",
  5003. {
  5004. class: "ss-card-text-popover",
  5005. style: { bottom: this.textPopoverBottom + "px" },
  5006. onMouseenter: () => {
  5007. this.clearHideTextPopoverTimer();
  5008. this.showTextPopover = true;
  5009. },
  5010. onMouseleave: () => this.hideTextPopoverLater(),
  5011. },
  5012. (() => {
  5013. const p = this.textPopoverPayload || {};
  5014. if (p.kind === "second-summary" && p.text) {
  5015. return [
  5016. Vue.h(
  5017. "div",
  5018. { class: "ss-card-text-popover__summary" },
  5019. p.text
  5020. ),
  5021. ];
  5022. }
  5023. if (Array.isArray(p.lines)) {
  5024. return [
  5025. Vue.h(
  5026. "div",
  5027. { class: "ss-card-text-popover__kvlist" },
  5028. p.lines.map((t) =>
  5029. Vue.h(
  5030. "div",
  5031. { class: "ss-card-text-popover__kv" },
  5032. t
  5033. )
  5034. )
  5035. ),
  5036. ];
  5037. }
  5038. if (
  5039. (p.kind === "third" || p.kind === "third-full") &&
  5040. p.text
  5041. ) {
  5042. return [
  5043. Vue.h(
  5044. "div",
  5045. { class: "ss-card-text-popover__objno" },
  5046. p.text
  5047. ),
  5048. ];
  5049. }
  5050. return [];
  5051. })()
  5052. );
  5053. return [
  5054. Vue.h("div", { class: "ss-card-text" }, children),
  5055. popover,
  5056. ];
  5057. })()
  5058. ),
  5059. ]
  5060. ),
  5061. ]),
  5062. // 右下角卡片选择图标 by xu 20260105
  5063. this.__allowSelect()
  5064. ? Vue.h(SsIcon, {
  5065. class: this.item?._ssSelected
  5066. ? "card-icon icon-cardChk-on"
  5067. : "card-icon icon-cardChk",
  5068. onClick: this.toggleSelect,
  5069. })
  5070. : null,
  5071. // 选中后底部线条 by xu 20260105
  5072. this.__allowSelect() &&
  5073. this.item?._ssSelected &&
  5074. Vue.h("div", { class: "select-bottom-line" }),
  5075. ]
  5076. );
  5077. },
  5078. };
  5079. // 二级对象卡片:复用一级对象新卡片布局/省略浮层,但去掉勾选与 single 选中,仅支持点击查看 by xu 20260115
  5080. const SsCObjCardList = {
  5081. name: "SsCObjCardList",
  5082. props: {
  5083. ssObjName: { type: String, default: "" }, // 功能说明:业务对象名(用于默认缩略图 icon) by xu 20260115
  5084. item: {
  5085. type: Object,
  5086. required: true,
  5087. },
  5088. },
  5089. emits: ["click", "change"],
  5090. setup(props, { emit }) {
  5091. const item = props.item;
  5092. const cardType = Vue.computed(() => {
  5093. if (!item.thumb && !item.thumbType) return "";
  5094. return item.thumbType === "thumbnail" ? "card-thumbnail" : "card-photo";
  5095. });
  5096. const statusClass = Vue.computed(() => {
  5097. if (!item.status) return "";
  5098. const statusMap = {
  5099. available: "status-available",
  5100. unavailable: "status-unavailable",
  5101. disabled: "status-disabled",
  5102. };
  5103. return statusMap[item.status] || "";
  5104. });
  5105. const onItemClick = (e) => {
  5106. // 清除所有类型卡片的 active 状态(保持与一级对象一致) by xu 20260115
  5107. const allListCards = document.querySelectorAll(
  5108. ".knowledge-item-container"
  5109. );
  5110. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  5111. allListCards.forEach((card) => card.classList.remove("active"));
  5112. allFolderCards.forEach((card) => card.classList.remove("active"));
  5113. e.currentTarget.classList.add("active");
  5114. // 二级对象卡片:点击仅查看(调用 item.onclick) by xu 20260115
  5115. props.item.onclick?.();
  5116. emit("click", props.item);
  5117. };
  5118. const onItemChange = (e) => {
  5119. e.stopPropagation();
  5120. props.item.buttons?.[0]?.onclick?.();
  5121. };
  5122. return { item, cardType, statusClass, onItemClick, onItemChange };
  5123. },
  5124. data() {
  5125. return {
  5126. showButtons: false,
  5127. showTextPopover: false, // 功能:右侧文字区 hover 展示全量 by xu 20260115
  5128. textPopoverType: "", // second-summary / second-tags / third / third-full by xu 20260115
  5129. textPopoverBottom: 0, // 功能:popover 从当前省略行位置向上展开 by xu 20260115
  5130. hideTextPopoverTimer: null, // 功能:鼠标从省略行移到浮层的缓冲 by xu 20260115
  5131. textPopoverPayload: null, // { kind, text?, lines? } by xu 20260115
  5132. ellipsisVisible: {
  5133. secondSummary: false,
  5134. secondTags: false,
  5135. third: false,
  5136. thirdFull: false,
  5137. }, // 功能:只在真实出现 ... 时才显示命中区/允许 goheight by xu 20260115
  5138. };
  5139. },
  5140. methods: {
  5141. getBizThumbIconClass() {
  5142. // 功能:无缩略图时,用业务对象 icon 做默认图(ss-icon + icon-obj-xx) by xu 20260115
  5143. const name = String(
  5144. this.ssObjName ||
  5145. this.item?.ssObjName ||
  5146. this.$root?.ssObjName ||
  5147. window?.ss?.dom?.ssObjName ||
  5148. ""
  5149. ).trim();
  5150. if (!name) return "";
  5151. return "icon-obj-" + name;
  5152. },
  5153. buildRightTextLines() {
  5154. // 功能:沿用一级对象卡片右侧文字区规则 by xu 20260115
  5155. const item = this.item || {};
  5156. const summary = String(item?.desc ?? "").trim();
  5157. const objNum = String(item?.objNum ?? "").trim();
  5158. const categoryArr = Array.isArray(item?.category) ? item.category : [];
  5159. const tagsArr = Array.isArray(item?.tags) ? item.tags : [];
  5160. const hasTags = tagsArr.length > 0;
  5161. const hasCategory = categoryArr.length > 0;
  5162. const secondKind = summary ? "summary" : hasTags ? "tags" : "";
  5163. const hasSecond = !!secondKind;
  5164. const thirdKind = objNum ? "objNum" : hasCategory ? "category" : "";
  5165. const hasThird = !!thirdKind;
  5166. const thirdFull = !hasSecond && hasThird;
  5167. const secondFull = hasSecond && !hasThird && secondKind === "tags";
  5168. const toValueText = (obj) => {
  5169. // 功能说明:类目/物品参数回显展示 key: value(否则只显示值看不懂) by xu 20260115
  5170. const [k, v] = Object.entries(obj || {})[0] || ["", ""];
  5171. const key = k !== undefined && k !== null ? String(k).trim() : "";
  5172. const val = v !== undefined && v !== null ? String(v).trim() : "";
  5173. if (key && val) return key + ":" + val;
  5174. if (val) return val;
  5175. if (key) return key;
  5176. return "";
  5177. };
  5178. const toLineList = (arr) =>
  5179. (arr || [])
  5180. .map(toValueText)
  5181. .map((s) => String(s ?? "").trim())
  5182. .filter(Boolean);
  5183. const secondTagsMaxLines = secondFull ? 4 : 3;
  5184. const secondTagsLinesFull = toLineList(tagsArr);
  5185. const secondTagsHead = secondTagsLinesFull.slice(
  5186. 0,
  5187. Math.max(0, secondTagsMaxLines - 1)
  5188. );
  5189. const secondTagsTail = secondTagsLinesFull.slice(
  5190. Math.max(0, secondTagsMaxLines - 1)
  5191. );
  5192. const secondTagsLast =
  5193. secondTagsTail.length <= 1
  5194. ? secondTagsTail[0] || ""
  5195. : secondTagsTail.join(" ");
  5196. const categoryLinesFull = toLineList(categoryArr);
  5197. const categoryLine = categoryLinesFull.join(" ");
  5198. const thirdText =
  5199. thirdKind === "objNum"
  5200. ? objNum
  5201. : thirdKind === "category"
  5202. ? categoryLine
  5203. : "";
  5204. return {
  5205. secondKind,
  5206. thirdKind,
  5207. hasSecond,
  5208. hasThird,
  5209. thirdFull,
  5210. secondFull,
  5211. summary,
  5212. secondTagsMaxLines,
  5213. secondTagsHead,
  5214. secondTagsLast,
  5215. secondTagsLinesFull,
  5216. objNum,
  5217. categoryLine,
  5218. categoryLinesFull,
  5219. thirdText,
  5220. };
  5221. },
  5222. measureTextOverflowByLines(text, maxLines, width) {
  5223. const w = Number(width) || 0;
  5224. if (!w || !text) return false;
  5225. const probe = document.createElement("div");
  5226. probe.style.position = "fixed";
  5227. probe.style.left = "-99999px";
  5228. probe.style.top = "0";
  5229. probe.style.width = w + "px";
  5230. probe.style.fontSize = "18px";
  5231. probe.style.lineHeight = "24px";
  5232. probe.style.whiteSpace = "normal";
  5233. probe.style.wordBreak = "break-word";
  5234. probe.style.visibility = "hidden";
  5235. probe.textContent = text;
  5236. document.body.appendChild(probe);
  5237. const h = probe.getBoundingClientRect().height || 0;
  5238. document.body.removeChild(probe);
  5239. return h > maxLines * 24 + 1;
  5240. },
  5241. measureSingleLineOverflow(text, width) {
  5242. const w = Number(width) || 0;
  5243. if (!w || !text) return false;
  5244. const probe = document.createElement("span");
  5245. probe.style.position = "fixed";
  5246. probe.style.left = "-99999px";
  5247. probe.style.top = "0";
  5248. probe.style.display = "inline-block";
  5249. probe.style.maxWidth = w + "px";
  5250. probe.style.fontSize = "18px";
  5251. probe.style.lineHeight = "24px";
  5252. probe.style.whiteSpace = "nowrap";
  5253. probe.style.visibility = "hidden";
  5254. probe.textContent = text;
  5255. document.body.appendChild(probe);
  5256. const overflow =
  5257. (probe.scrollWidth || 0) > (probe.clientWidth || w) + 1;
  5258. document.body.removeChild(probe);
  5259. return overflow;
  5260. },
  5261. refreshEllipsisVisible() {
  5262. // 功能:刷新「是否出现 ...」状态(用于控制命中区显示) by xu 20260115
  5263. try {
  5264. const right = this.$el?.querySelector?.(".right");
  5265. const rawWidth =
  5266. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  5267. const width = Math.max(0, Math.round(rawWidth));
  5268. const model = this.buildRightTextLines();
  5269. const next = {
  5270. secondSummary: false,
  5271. secondTags: false,
  5272. third: false,
  5273. thirdFull: false,
  5274. };
  5275. if (model.secondKind === "summary" && model.summary) {
  5276. next.secondSummary = this.measureTextOverflowByLines(
  5277. model.summary,
  5278. 3,
  5279. width
  5280. );
  5281. }
  5282. if (model.secondKind === "tags") {
  5283. next.secondTags = this.measureSingleLineOverflow(
  5284. model.secondTagsLast,
  5285. width
  5286. ); // 功能说明:tags 仅看最后一行是否溢出 by xu 20260115
  5287. }
  5288. if (model.hasThird && !model.thirdFull) {
  5289. next.third = this.measureSingleLineOverflow(model.thirdText, width);
  5290. }
  5291. if (model.hasThird && model.thirdFull) {
  5292. next.thirdFull = this.measureTextOverflowByLines(
  5293. model.thirdText,
  5294. 4,
  5295. width
  5296. );
  5297. }
  5298. const prev = this.ellipsisVisible || {};
  5299. const changed =
  5300. prev.secondSummary !== next.secondSummary ||
  5301. prev.secondTags !== next.secondTags ||
  5302. prev.third !== next.third ||
  5303. prev.thirdFull !== next.thirdFull;
  5304. if (changed) this.ellipsisVisible = next;
  5305. } catch (e) {
  5306. // ignore by xu 20260115
  5307. }
  5308. },
  5309. clearHideTextPopoverTimer() {
  5310. if (this.hideTextPopoverTimer) {
  5311. clearTimeout(this.hideTextPopoverTimer);
  5312. this.hideTextPopoverTimer = null;
  5313. }
  5314. },
  5315. hideTextPopoverLater() {
  5316. this.clearHideTextPopoverTimer();
  5317. this.hideTextPopoverTimer = setTimeout(() => {
  5318. this.showTextPopover = false;
  5319. this.textPopoverType = "";
  5320. this.textPopoverPayload = null;
  5321. }, 120);
  5322. },
  5323. showTextPopoverFor(el, kind) {
  5324. const model = this.buildRightTextLines();
  5325. const lineEl = el?.closest?.(".ss-card-text__line") || el;
  5326. const right = lineEl?.closest?.(".right") || el?.closest?.(".right");
  5327. const rawWidth =
  5328. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  5329. const width = Math.max(0, Math.round(rawWidth));
  5330. const overflowed =
  5331. kind === "second-summary"
  5332. ? this.measureTextOverflowByLines(model.summary, 3, width)
  5333. : kind === "second-tags"
  5334. ? this.measureSingleLineOverflow(model.secondTagsLast, width)
  5335. : kind === "third"
  5336. ? this.measureSingleLineOverflow(model.thirdText, width)
  5337. : this.measureTextOverflowByLines(model.thirdText, 4, width);
  5338. if (!overflowed) return;
  5339. let payload = null;
  5340. if (kind === "second-summary") {
  5341. if (model.summary) payload = { kind, text: model.summary };
  5342. } else if (kind === "second-tags") {
  5343. if (
  5344. Array.isArray(model.secondTagsLinesFull) &&
  5345. model.secondTagsLinesFull.length
  5346. ) {
  5347. payload = { kind, lines: model.secondTagsLinesFull };
  5348. }
  5349. } else if (kind === "third") {
  5350. if (
  5351. model.thirdKind === "category" &&
  5352. Array.isArray(model.categoryLinesFull) &&
  5353. model.categoryLinesFull.length
  5354. ) {
  5355. payload = { kind, lines: model.categoryLinesFull };
  5356. } else if (model.thirdText) {
  5357. payload = { kind, text: model.thirdText };
  5358. }
  5359. } else if (kind === "third-full") {
  5360. if (
  5361. model.thirdKind === "category" &&
  5362. Array.isArray(model.categoryLinesFull) &&
  5363. model.categoryLinesFull.length
  5364. ) {
  5365. payload = { kind, lines: model.categoryLinesFull };
  5366. } else if (model.thirdText) {
  5367. payload = { kind, text: model.thirdText };
  5368. }
  5369. }
  5370. if (!payload) return;
  5371. this.clearHideTextPopoverTimer();
  5372. const container = lineEl?.closest?.(".right");
  5373. const containerRect = container?.getBoundingClientRect?.();
  5374. const lineRect = lineEl?.getBoundingClientRect?.();
  5375. if (containerRect && lineRect) {
  5376. const bottom = Math.max(
  5377. 0,
  5378. Math.round(containerRect.bottom - lineRect.bottom)
  5379. );
  5380. this.textPopoverBottom = bottom;
  5381. } else {
  5382. this.textPopoverBottom = 0;
  5383. }
  5384. this.textPopoverPayload = payload;
  5385. this.textPopoverType = kind;
  5386. this.showTextPopover = true;
  5387. },
  5388. },
  5389. mounted() {
  5390. this.$nextTick?.(() => {
  5391. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5392. });
  5393. this.__ssCObjCardResizeHandler = () => this.refreshEllipsisVisible?.(); // 功能说明:窗口变化时刷新 ... 显示 by xu 20260115
  5394. window.addEventListener?.("resize", this.__ssCObjCardResizeHandler);
  5395. },
  5396. updated() {
  5397. this.$nextTick?.(() => {
  5398. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5399. });
  5400. },
  5401. beforeUnmount() {
  5402. this.clearHideTextPopoverTimer?.();
  5403. if (this.__ssCObjCardResizeHandler) {
  5404. window.removeEventListener?.("resize", this.__ssCObjCardResizeHandler);
  5405. this.__ssCObjCardResizeHandler = null;
  5406. }
  5407. },
  5408. render() {
  5409. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  5410. const SsIcon = Vue.resolveComponent("ss-icon");
  5411. const hasThumbArea = !!(this.item?.thumb || this.item?.thumbType);
  5412. const thumbSrc = (() => {
  5413. // 功能说明:兼容 thumb 为 raw path 或 {val}/{value},组件内统一转为 dlByHttp URL by xu 20260122
  5414. const t = this.item?.thumb;
  5415. if (!t) return "";
  5416. if (typeof t === "string") {
  5417. const s = t.trim();
  5418. if (!s) return "";
  5419. if (
  5420. /^https?:\/\//i.test(s) ||
  5421. s.startsWith("/service?") ||
  5422. s.startsWith("/")
  5423. )
  5424. return s;
  5425. return buildThumbUrl(s);
  5426. }
  5427. return buildThumbUrl(t);
  5428. })();
  5429. return Vue.h(
  5430. "div",
  5431. {
  5432. class: {
  5433. "knowledge-item-container": true,
  5434. active: this.item.active,
  5435. [this.cardType]: !!this.cardType,
  5436. [this.statusClass]: !!this.statusClass,
  5437. },
  5438. onClick: (e) => this.onItemClick?.(e), // 功能说明:二级对象卡片点击仅查看 by xu 20260115
  5439. },
  5440. [
  5441. this.item?.statusIcons?.length > 0 &&
  5442. Vue.h(
  5443. "div",
  5444. { class: "card-status-icons" },
  5445. this.item.statusIcons.map((icon) =>
  5446. Vue.h(SsIcon, {
  5447. class: "status-icon " + icon.class,
  5448. title: icon.title,
  5449. })
  5450. )
  5451. ),
  5452. this.item?.buttons?.length > 0 &&
  5453. Vue.h(
  5454. "div",
  5455. {
  5456. class: "header",
  5457. style:
  5458. this.item?.statusIcons?.length > 0
  5459. ? {
  5460. right: String(this.item.statusIcons.length * 48) + "px",
  5461. borderTopRightRadius: "0",
  5462. }
  5463. : {},
  5464. onMouseenter: () => (this.showButtons = true),
  5465. onMouseleave: () => (this.showButtons = false),
  5466. onClick: (e) => this.onItemChange(e),
  5467. },
  5468. [
  5469. Vue.h("div", {
  5470. class: "cart-list-setting cart-list-icon",
  5471. title: this.item?.buttons?.[0]?.title,
  5472. }),
  5473. this.showButtons &&
  5474. this.item?.buttons?.length > 1 &&
  5475. Vue.h(
  5476. "div",
  5477. { class: "cart-list-button-popup" },
  5478. this.item.buttons.map((btn) =>
  5479. Vue.h(
  5480. "div",
  5481. {
  5482. onClick: (e) => {
  5483. e.stopPropagation();
  5484. btn.onclick?.();
  5485. },
  5486. },
  5487. [
  5488. btn.class &&
  5489. Vue.h(SsCartListIcon, { class: [btn.class] }),
  5490. Vue.h("span", null, btn.title),
  5491. ]
  5492. )
  5493. )
  5494. ),
  5495. ]
  5496. ),
  5497. Vue.h("div", { class: "body" }, [
  5498. Vue.h("div", { class: "box-header" }, [
  5499. Vue.h("div", String(this.item.title || "")),
  5500. ]),
  5501. Vue.h(
  5502. "div",
  5503. { class: !hasThumbArea ? "no-thumb box-body" : "box-body" },
  5504. [
  5505. hasThumbArea
  5506. ? thumbSrc
  5507. ? Vue.h("div", { class: "left" }, [
  5508. Vue.h("img", {
  5509. src: thumbSrc,
  5510. alt: "Thumbnail",
  5511. class: "imgUnHandle",
  5512. style: {
  5513. "object-fit": "cover",
  5514. width: "100%",
  5515. height: "100%",
  5516. },
  5517. }),
  5518. ])
  5519. : Vue.h(
  5520. "div",
  5521. { class: "left ss-objlist-thumbPlaceholder" },
  5522. [
  5523. Vue.h(SsIcon, {
  5524. class:
  5525. this.getBizThumbIconClass() +
  5526. " ss-objlist-thumbIcon",
  5527. }),
  5528. ]
  5529. )
  5530. : null,
  5531. Vue.h(
  5532. "div",
  5533. { class: "right" },
  5534. (() => {
  5535. const model = this.buildRightTextLines();
  5536. const hasAny = !!(model?.hasSecond || model?.hasThird);
  5537. if (!hasAny) return [];
  5538. const children = [];
  5539. if (model.hasSecond && model.secondKind === "summary") {
  5540. children.push(
  5541. Vue.h(
  5542. "div",
  5543. {
  5544. class:
  5545. "ss-card-text__line ss-card-text__secondBlock",
  5546. },
  5547. [
  5548. Vue.h(
  5549. "div",
  5550. {
  5551. class: "ss-card-text__secondSummary",
  5552. title: model.summary,
  5553. },
  5554. model.summary
  5555. ),
  5556. Vue.h("span", {
  5557. class: [
  5558. "ss-card-text__ellipsisHit",
  5559. "ss-card-text__ellipsisHit--second",
  5560. this.ellipsisVisible?.secondSummary
  5561. ? "is-on"
  5562. : "",
  5563. ],
  5564. title: "查看完整信息",
  5565. onMouseenter: (e) =>
  5566. this.showTextPopoverFor(
  5567. e?.currentTarget,
  5568. "second-summary"
  5569. ),
  5570. onClick: (e) => {
  5571. e?.stopPropagation?.();
  5572. this.showTextPopoverFor(
  5573. e?.currentTarget,
  5574. "second-summary"
  5575. );
  5576. },
  5577. onMouseleave: () => this.hideTextPopoverLater(),
  5578. }),
  5579. ]
  5580. )
  5581. );
  5582. }
  5583. if (model.hasSecond && model.secondKind === "tags") {
  5584. children.push(
  5585. Vue.h(
  5586. "div",
  5587. {
  5588. class: [
  5589. "ss-card-text__line",
  5590. model.secondFull
  5591. ? "ss-card-text__secondFullBlock"
  5592. : "ss-card-text__secondBlock",
  5593. ],
  5594. },
  5595. [
  5596. Vue.h(
  5597. "div",
  5598. { class: "ss-card-text__secondTags" },
  5599. [
  5600. ...model.secondTagsHead.map((t) =>
  5601. Vue.h(
  5602. "div",
  5603. {
  5604. class: "ss-card-text__tagLine",
  5605. title: t,
  5606. },
  5607. t
  5608. )
  5609. ),
  5610. Vue.h(
  5611. "div",
  5612. {
  5613. class:
  5614. "ss-card-text__tagLine is-last ss-card-text__tagLineLast",
  5615. title: model.secondTagsLast,
  5616. },
  5617. model.secondTagsLast
  5618. ),
  5619. ]
  5620. ),
  5621. Vue.h("span", {
  5622. class: [
  5623. "ss-card-text__ellipsisHit",
  5624. "ss-card-text__ellipsisHit--second",
  5625. this.ellipsisVisible?.secondTags ? "is-on" : "",
  5626. ],
  5627. title: "查看完整信息",
  5628. onMouseenter: (e) =>
  5629. this.showTextPopoverFor(
  5630. e?.currentTarget,
  5631. "second-tags"
  5632. ),
  5633. onClick: (e) => {
  5634. e?.stopPropagation?.();
  5635. this.showTextPopoverFor(
  5636. e?.currentTarget,
  5637. "second-tags"
  5638. );
  5639. },
  5640. onMouseleave: () => this.hideTextPopoverLater(),
  5641. }),
  5642. ]
  5643. )
  5644. );
  5645. }
  5646. if (model.hasThird) {
  5647. if (model.thirdFull) {
  5648. children.push(
  5649. Vue.h(
  5650. "div",
  5651. {
  5652. class:
  5653. "ss-card-text__line ss-card-text__thirdFullBlock",
  5654. },
  5655. [
  5656. Vue.h(
  5657. "div",
  5658. {
  5659. class: "ss-card-text__thirdFull",
  5660. title: model.thirdText,
  5661. },
  5662. model.thirdText
  5663. ),
  5664. Vue.h("span", {
  5665. class: [
  5666. "ss-card-text__ellipsisHit",
  5667. "ss-card-text__ellipsisHit--third",
  5668. this.ellipsisVisible?.thirdFull
  5669. ? "is-on"
  5670. : "",
  5671. ],
  5672. title: "查看完整信息",
  5673. onMouseenter: (e) =>
  5674. this.showTextPopoverFor(
  5675. e?.currentTarget,
  5676. "third-full"
  5677. ),
  5678. onClick: (e) => {
  5679. e?.stopPropagation?.();
  5680. this.showTextPopoverFor(
  5681. e?.currentTarget,
  5682. "third-full"
  5683. );
  5684. },
  5685. onMouseleave: () => this.hideTextPopoverLater(),
  5686. }),
  5687. ]
  5688. )
  5689. );
  5690. } else {
  5691. children.push(
  5692. Vue.h(
  5693. "div",
  5694. {
  5695. class:
  5696. "ss-card-text__line ss-card-text__thirdLineWrap",
  5697. },
  5698. [
  5699. Vue.h(
  5700. "div",
  5701. {
  5702. class: "ss-card-text__thirdLine",
  5703. title: model.thirdText,
  5704. },
  5705. model.thirdText
  5706. ),
  5707. Vue.h("span", {
  5708. class: [
  5709. "ss-card-text__ellipsisHit",
  5710. "ss-card-text__ellipsisHit--third",
  5711. this.ellipsisVisible?.third ? "is-on" : "",
  5712. ],
  5713. title: "查看完整信息",
  5714. onMouseenter: (e) =>
  5715. this.showTextPopoverFor(
  5716. e?.currentTarget,
  5717. "third"
  5718. ),
  5719. onClick: (e) => {
  5720. e?.stopPropagation?.();
  5721. this.showTextPopoverFor(
  5722. e?.currentTarget,
  5723. "third"
  5724. );
  5725. },
  5726. onMouseleave: () => this.hideTextPopoverLater(),
  5727. }),
  5728. ]
  5729. )
  5730. );
  5731. }
  5732. }
  5733. const popover =
  5734. this.showTextPopover &&
  5735. Vue.h(
  5736. "div",
  5737. {
  5738. class: "ss-card-text-popover",
  5739. style: { bottom: this.textPopoverBottom + "px" },
  5740. onMouseenter: () => {
  5741. this.clearHideTextPopoverTimer();
  5742. this.showTextPopover = true;
  5743. },
  5744. onMouseleave: () => this.hideTextPopoverLater(),
  5745. },
  5746. (() => {
  5747. const p = this.textPopoverPayload || {};
  5748. if (p.kind === "second-summary" && p.text) {
  5749. return [
  5750. Vue.h(
  5751. "div",
  5752. { class: "ss-card-text-popover__summary" },
  5753. p.text
  5754. ),
  5755. ];
  5756. }
  5757. if (Array.isArray(p.lines)) {
  5758. return [
  5759. Vue.h(
  5760. "div",
  5761. { class: "ss-card-text-popover__kvlist" },
  5762. p.lines.map((t) =>
  5763. Vue.h(
  5764. "div",
  5765. { class: "ss-card-text-popover__kv" },
  5766. t
  5767. )
  5768. )
  5769. ),
  5770. ];
  5771. }
  5772. if (
  5773. (p.kind === "third" || p.kind === "third-full") &&
  5774. p.text
  5775. ) {
  5776. return [
  5777. Vue.h(
  5778. "div",
  5779. { class: "ss-card-text-popover__objno" },
  5780. p.text
  5781. ),
  5782. ];
  5783. }
  5784. return [];
  5785. })()
  5786. );
  5787. return [
  5788. Vue.h("div", { class: "ss-card-text" }, children),
  5789. popover,
  5790. ];
  5791. })()
  5792. ),
  5793. ]
  5794. ),
  5795. ]),
  5796. ]
  5797. );
  5798. },
  5799. };
  5800. // ss-sidebar 右侧边栏(容器 + 子组件),用于 objList 右侧区域 by xu 20260106
  5801. // 组件文档补全(JSDoc) by xu 20260108
  5802. /**
  5803. * SsSidebarButtons(右侧边栏顶部按钮栏)
  5804. *
  5805. * 用途:
  5806. * - 渲染 objList 右侧顶部快捷操作(预定/入住/退房/清洁...)
  5807. * - 内部复用 `ss-search-button`(项目现有按钮样式/交互)
  5808. *
  5809. * 调用示例:
  5810. * ```html
  5811. * <ss-sidebar-buttons :items="sidebarButtons" />
  5812. * ```
  5813. *
  5814. * Props:
  5815. * - `items`: 按钮配置数组
  5816. * - `{ id, text, icon?, onClick? }`
  5817. *
  5818. * Emits:
  5819. * - `click`:点击按钮时触发,参数为按钮对象
  5820. */
  5821. const SsSidebarButtons = {
  5822. name: "SsSidebarButtons",
  5823. props: {
  5824. items: { type: Array, default: () => [] },
  5825. },
  5826. emits: ["click"],
  5827. render() {
  5828. const SsSearchButton = Vue.resolveComponent("ss-search-button");
  5829. const items = this.items || [];
  5830. if (!items.length) return null;
  5831. return Vue.h(
  5832. "div",
  5833. { class: "ss-sidebar-actions" },
  5834. items.map((btn) =>
  5835. // 顶部操作按钮复用 ss-search-button(先 mock 固定按钮) by xu 20260106
  5836. Vue.h(SsSearchButton, {
  5837. text: btn?.text ?? "",
  5838. iconClass: btn?.iconClass ?? "",
  5839. opt: btn?.opt ?? [],
  5840. checkId: btn?.checkId ?? "0",
  5841. width: btn?.width,
  5842. id: btn?.id,
  5843. onClick: (e) => {
  5844. e?.stopPropagation?.();
  5845. btn?.onClick?.(btn);
  5846. this.$emit("click", btn);
  5847. },
  5848. })
  5849. )
  5850. );
  5851. },
  5852. };
  5853. // 组件文档补全(JSDoc) by xu 20260108
  5854. /**
  5855. * SsSidebarChart(ECharts 容器渲染)
  5856. *
  5857. * 用途:
  5858. * - 仅负责 echarts init / setOption / resize / dispose
  5859. * - 被 `ss-sidebar-chart-hover` 与图表面板复用
  5860. *
  5861. * 调用示例:
  5862. * ```html
  5863. * <ss-sidebar-chart :options="option" height="220px" />
  5864. * ```
  5865. *
  5866. * Props:
  5867. * - `options`:ECharts option(Object)
  5868. * - `height`:容器高度(String)
  5869. */
  5870. const SsSidebarChart = {
  5871. name: "SsSidebarChart",
  5872. props: {
  5873. options: { type: Object, default: () => ({}) },
  5874. height: { type: String, default: "200px" },
  5875. },
  5876. setup(props) {
  5877. const elRef = Vue.ref(null);
  5878. let chart = null;
  5879. const renderChart = () => {
  5880. if (!elRef.value || !window.echarts) return;
  5881. if (!chart) {
  5882. chart = window.echarts.init(elRef.value);
  5883. }
  5884. chart.setOption(props.options || {}, true);
  5885. };
  5886. const resizeChart = () => {
  5887. chart?.resize?.();
  5888. };
  5889. Vue.onMounted(() => {
  5890. renderChart();
  5891. window.addEventListener("resize", resizeChart);
  5892. });
  5893. Vue.onBeforeUnmount(() => {
  5894. window.removeEventListener("resize", resizeChart);
  5895. chart?.dispose?.();
  5896. chart = null;
  5897. });
  5898. Vue.watch(
  5899. () => props.options,
  5900. () => {
  5901. renderChart();
  5902. },
  5903. { deep: true }
  5904. );
  5905. return { elRef };
  5906. },
  5907. render() {
  5908. return Vue.h("div", {
  5909. ref: "elRef",
  5910. style: {
  5911. width: "100%",
  5912. height: this.height,
  5913. // 图表容器不加 padding/border,由外层布局控制 by xu 20260106
  5914. background: "transparent",
  5915. border: "none",
  5916. "border-radius": "0",
  5917. },
  5918. });
  5919. },
  5920. };
  5921. // ss-sidebar-chart-hover:hover 弹出左侧大图(支持图钉/全屏) by xu 20260106
  5922. // 组件文档补全(JSDoc) by xu 20260108
  5923. /**
  5924. * SsSidebarChartHover(小图 + hover 左侧大图预览 + 图钉固定 + 全屏)
  5925. *
  5926. * 用途:
  5927. * - 右侧统计图小卡片:hover 时在左侧弹出大图预览
  5928. * - 预览头部:左侧图标+标题;右侧固定/全屏按钮(icon-base)
  5929. * - 全屏:方案A(浏览器 Fullscreen API)
  5930. *
  5931. * 调用示例(由 ss-sidebar chart panel 内部调用):
  5932. * ```html
  5933. * <ss-sidebar-chart-hover
  5934. * title="校舍建筑面积和总体分布"
  5935. * icon-class="menu-icon icon-obj-jzw"
  5936. * :options="option"
  5937. * height="220px"
  5938. * />
  5939. * ```
  5940. *
  5941. * Props:
  5942. * - `title/iconClass/icon`:用于预览/全屏 header 显示(与面板 header 一致)
  5943. * - `options`:ECharts option
  5944. * - `height`:小图高度
  5945. * - `previewWidth/previewHeight`:预览建议尺寸(会按视口自适应)
  5946. */
  5947. const SsSidebarChartHover = {
  5948. name: "SsSidebarChartHover",
  5949. props: {
  5950. // hover 大图标题/图标(与小图面板 header 一致) by xu 20260108
  5951. title: { type: String, default: "" },
  5952. iconClass: { type: String, default: "" },
  5953. icon: { type: String, default: "" },
  5954. options: { type: Object, default: () => ({}) },
  5955. height: { type: String, default: "220px" },
  5956. // hover 弹窗建议尺寸:默认 1000x650(比例由逻辑统一管控),实际渲染会按比例自适应视口 by xu 20260115
  5957. previewWidth: { type: Number, default: 1000 },
  5958. previewHeight: { type: Number, default: 650 },
  5959. },
  5960. setup(props) {
  5961. const triggerRef = Vue.ref(null);
  5962. const fullscreenRef = Vue.ref(null);
  5963. const open = Vue.ref(false);
  5964. const pinned = Vue.ref(false);
  5965. const fullscreen = Vue.ref(false);
  5966. const hoveringTrigger = Vue.ref(false);
  5967. const hoveringPreview = Vue.ref(false);
  5968. const previewStyle = Vue.ref({});
  5969. let closeTimer = null;
  5970. const updatePreviewPosition = () => {
  5971. const el = triggerRef.value;
  5972. if (!el) return;
  5973. const rect = el.getBoundingClientRect();
  5974. // 功能说明:优先使用 visualViewport(避免浏览器 UI/缩放导致可视区与 innerHeight 偏差,出现预览被遮挡约 70px) by xu 20260116
  5975. const docEl = document.documentElement;
  5976. const vv = window.visualViewport;
  5977. let viewportLeft = Number(vv?.offsetLeft ?? 0) || 0;
  5978. let viewportTop = Number(vv?.offsetTop ?? 0) || 0;
  5979. let vw =
  5980. Number(vv?.width ?? 0) ||
  5981. Number(docEl?.clientWidth || 0) ||
  5982. window.innerWidth;
  5983. let vh =
  5984. Number(vv?.height ?? 0) ||
  5985. Number(docEl?.clientHeight || 0) ||
  5986. window.innerHeight;
  5987. // 功能说明:若页面在 iframe 内,父页面可能裁切 iframe 可见区域(overflow/弹窗容器),需要用“iframe可见区域”做二次约束 by xu 20260116
  5988. try {
  5989. const inIframe = window.top && window.top !== window;
  5990. const frameEl = window.frameElement;
  5991. if (inIframe && frameEl && window.top?.document) {
  5992. const topVv = window.top.visualViewport;
  5993. const topDocEl = window.top.document.documentElement;
  5994. const topVw =
  5995. Number(topVv?.width ?? 0) ||
  5996. Number(topDocEl?.clientWidth || 0) ||
  5997. window.top.innerWidth;
  5998. const topVh =
  5999. Number(topVv?.height ?? 0) ||
  6000. Number(topDocEl?.clientHeight || 0) ||
  6001. window.top.innerHeight;
  6002. const fr = frameEl.getBoundingClientRect?.();
  6003. if (fr && fr.width > 0 && fr.height > 0) {
  6004. const visibleW = Math.max(
  6005. 0,
  6006. Math.min(fr.right, topVw) - Math.max(fr.left, 0)
  6007. );
  6008. const visibleH = Math.max(
  6009. 0,
  6010. Math.min(fr.bottom, topVh) - Math.max(fr.top, 0)
  6011. );
  6012. if (visibleW > 0) {
  6013. vw = Math.min(vw, visibleW);
  6014. viewportLeft = Math.max(0, -fr.left); // iframe内坐标系偏移(左侧被裁切时) by xu 20260116
  6015. }
  6016. if (visibleH > 0) {
  6017. vh = Math.min(vh, visibleH);
  6018. viewportTop = Math.max(0, -fr.top); // iframe内坐标系偏移(顶部被裁切时) by xu 20260116
  6019. }
  6020. }
  6021. }
  6022. } catch (_) {}
  6023. // 预览窗尺寸:优先保证“完整可见”,其次再尽量对齐右侧 header 顶部 by xu 20260116
  6024. const viewportPaddingX = 40;
  6025. const viewportPaddingTop = 20;
  6026. const viewportPaddingBottom = 10;
  6027. // 功能说明:hover 预览框不要覆盖右侧栏,优先放在 ss-sidebar 左侧;必要时动态缩小宽度 by xu 20260115
  6028. const sidebarEl = el.closest ? el.closest(".ss-sidebar") : null;
  6029. const sidebarRect = sidebarEl?.getBoundingClientRect?.();
  6030. const maxWidthByViewport = Math.max(240, vw - viewportPaddingX);
  6031. const maxWidthByLeftSpace = sidebarRect
  6032. ? Math.max(
  6033. 240,
  6034. sidebarRect.left - viewportPaddingX - 14 /* gapFromSidebar */
  6035. )
  6036. : maxWidthByViewport;
  6037. // 功能说明:预览框尺寸按比例(默认 5:3)缩放,并提供最大/最小值约束 by xu 20260115
  6038. const ratio = 3 / 5;
  6039. const minWidth = 320;
  6040. const minHeight = 240;
  6041. const maxHeightByViewport = Math.max(
  6042. minHeight,
  6043. vh - viewportPaddingTop - viewportPaddingBottom
  6044. );
  6045. const maxWidthByProp = Number(props.previewWidth) || 1000;
  6046. const maxHeightByProp = Number(props.previewHeight) || 650;
  6047. // 优先按高度撑满可视区(保证预览完整可见),再根据左侧可用宽度回退 by xu 20260116
  6048. const maxHeight = Math.min(maxHeightByProp, maxHeightByViewport);
  6049. let height = Math.max(minHeight, maxHeight);
  6050. let width = Math.round(height / ratio);
  6051. width = Math.min(
  6052. width,
  6053. maxWidthByProp,
  6054. maxWidthByViewport,
  6055. maxWidthByLeftSpace
  6056. );
  6057. width = Math.max(minWidth, width);
  6058. height = Math.round(width * ratio);
  6059. if (height > maxHeight) {
  6060. height = maxHeight;
  6061. width = Math.round(height / ratio);
  6062. }
  6063. // 默认贴着小图左侧弹出,右边缘与小图左边缘轻微重叠,避免 1px 缝隙导致 hover 闪断 by xu 20260108
  6064. const overlap = 2;
  6065. const gapFromSidebar = 14; // 功能说明:弹窗与右侧边栏留出距离(更不贴近) by xu 20260108
  6066. // 优先:贴在 sidebar 左侧(不压住右侧栏内容) by xu 20260115
  6067. let left = sidebarRect
  6068. ? sidebarRect.left - gapFromSidebar - width + overlap
  6069. : rect.left - width - gapFromSidebar + overlap;
  6070. // 如果左侧空间不足,则贴右侧(兜底,同样重叠) by xu 20260108
  6071. if (left < 0) left = rect.right + gapFromSidebar - overlap;
  6072. left = Math.max(
  6073. viewportLeft,
  6074. Math.min(left, viewportLeft + vw - width)
  6075. );
  6076. // top:优先保证完整可见,然后才贴近 header 顶部 by xu 20260116
  6077. let headerEl = el;
  6078. while (headerEl && !headerEl.classList?.contains("ss-sidebar-panel")) {
  6079. headerEl = headerEl.parentElement;
  6080. }
  6081. let headerRect = headerEl
  6082. ?.querySelector(".ss-sidebar-panel__header")
  6083. ?.getBoundingClientRect();
  6084. let top = headerRect?.top ?? rect.top;
  6085. top = Math.max(
  6086. viewportTop + viewportPaddingTop,
  6087. Math.min(top, viewportTop + vh - height - viewportPaddingBottom)
  6088. );
  6089. previewStyle.value = {
  6090. position: "fixed",
  6091. left: `${Math.round(left)}px`,
  6092. top: `${Math.round(top)}px`,
  6093. width: `${width}px`,
  6094. height: `${height}px`,
  6095. zIndex: 2147483647, // 功能说明:提高层级到接近浏览器上限,避免仍被页面固定栏/弹窗遮挡 by xu 20260116
  6096. };
  6097. };
  6098. const clearCloseTimer = () => {
  6099. if (closeTimer) {
  6100. clearTimeout(closeTimer);
  6101. closeTimer = null;
  6102. }
  6103. };
  6104. const scheduleClose = () => {
  6105. clearCloseTimer();
  6106. if (pinned.value || fullscreen.value) return;
  6107. if (hoveringTrigger.value || hoveringPreview.value) return; // 功能:鼠标在小图/大图之间移动不关闭 by xu 20260108
  6108. closeTimer = setTimeout(() => {
  6109. open.value = false;
  6110. }, 100);
  6111. };
  6112. const openPreview = () => {
  6113. clearCloseTimer();
  6114. updatePreviewPosition();
  6115. open.value = true;
  6116. };
  6117. const togglePin = () => {
  6118. pinned.value = !pinned.value;
  6119. if (pinned.value) {
  6120. open.value = true;
  6121. updatePreviewPosition();
  6122. }
  6123. };
  6124. const toggleFullscreen = () => {
  6125. // 全屏:采用浏览器 Fullscreen API(方案A),不使用遮罩弹窗 by xu 20260108
  6126. if (!fullscreen.value) {
  6127. open.value = false; // 避免同时渲染预览与全屏 by xu 20260108
  6128. fullscreen.value = true;
  6129. Vue.nextTick(() => {
  6130. const el = fullscreenRef.value;
  6131. if (el?.requestFullscreen) {
  6132. el.requestFullscreen().catch(() => {
  6133. // requestFullscreen 失败则回退为非全屏状态 by xu 20260108
  6134. fullscreen.value = false;
  6135. });
  6136. } else {
  6137. fullscreen.value = false;
  6138. }
  6139. });
  6140. } else {
  6141. if (document?.exitFullscreen) {
  6142. document.exitFullscreen().catch(() => {});
  6143. }
  6144. }
  6145. };
  6146. const handleFullscreenChange = () => {
  6147. const isFs = !!document.fullscreenElement;
  6148. fullscreen.value = isFs; // 功能说明:同步 ESC/系统退出全屏状态 by xu 20260108
  6149. if (isFs) {
  6150. open.value = false;
  6151. clearCloseTimer();
  6152. return;
  6153. }
  6154. // 退出全屏后:若固定或仍 hover,则恢复预览,否则关闭 by xu 20260108
  6155. if (pinned.value || hoveringTrigger.value || hoveringPreview.value) {
  6156. open.value = true;
  6157. updatePreviewPosition();
  6158. } else {
  6159. open.value = false;
  6160. }
  6161. };
  6162. Vue.onMounted(() => {
  6163. window.addEventListener("resize", updatePreviewPosition);
  6164. window.addEventListener("scroll", updatePreviewPosition, true);
  6165. document.addEventListener("fullscreenchange", handleFullscreenChange); // 功能说明:监听全屏状态变化 by xu 20260108
  6166. });
  6167. Vue.onBeforeUnmount(() => {
  6168. clearCloseTimer();
  6169. window.removeEventListener("resize", updatePreviewPosition);
  6170. window.removeEventListener("scroll", updatePreviewPosition, true);
  6171. document.removeEventListener(
  6172. "fullscreenchange",
  6173. handleFullscreenChange
  6174. );
  6175. });
  6176. return {
  6177. triggerRef,
  6178. fullscreenRef,
  6179. open,
  6180. pinned,
  6181. fullscreen,
  6182. hoveringTrigger,
  6183. hoveringPreview,
  6184. previewStyle,
  6185. openPreview,
  6186. scheduleClose,
  6187. clearCloseTimer,
  6188. togglePin,
  6189. toggleFullscreen,
  6190. };
  6191. },
  6192. render() {
  6193. const SsIcon = Vue.resolveComponent("ss-icon");
  6194. const Chart = Vue.resolveComponent("ss-sidebar-chart");
  6195. const hasHeader = !!(this.title || this.iconClass || this.icon); // 功能:hover 大图显示左侧图标+标题 by xu 20260108
  6196. const previewContent = Vue.h(
  6197. "div",
  6198. {
  6199. class: { "ss-sidebar-chart-preview": true, "is-pinned": this.pinned },
  6200. style: this.previewStyle,
  6201. onMouseenter: () => {
  6202. this.hoveringPreview = true;
  6203. this.clearCloseTimer();
  6204. },
  6205. onMouseleave: () => {
  6206. this.hoveringPreview = false;
  6207. this.scheduleClose();
  6208. },
  6209. },
  6210. [
  6211. hasHeader
  6212. ? Vue.h(
  6213. "div",
  6214. {
  6215. class:
  6216. "ss-sidebar-panel__header ss-sidebar-chart-preview__header",
  6217. },
  6218. [
  6219. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  6220. this.iconClass
  6221. ? Vue.h(SsIcon, {
  6222. class: this.iconClass + " ss-sidebar-panel__icon",
  6223. })
  6224. : this.icon
  6225. ? Vue.h(SsIcon, {
  6226. name: this.icon,
  6227. size: "16px",
  6228. class: "ss-sidebar-panel__icon",
  6229. })
  6230. : null,
  6231. Vue.h("span", null, this.title || "统计图"),
  6232. ]),
  6233. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6234. Vue.h(
  6235. "button",
  6236. {
  6237. type: "button",
  6238. class: {
  6239. "ss-sidebar-chart-tool": true,
  6240. "is-active": this.pinned,
  6241. },
  6242. title: this.pinned ? "取消固定" : "固定",
  6243. onClick: (e) => {
  6244. e.stopPropagation();
  6245. this.togglePin();
  6246. },
  6247. },
  6248. // 功能说明:右侧栏 hover 工具图标使用 ss-sidebar-base-icon(不复用左侧 menu-base-icon) by xu 20260123
  6249. [
  6250. Vue.h(SsIcon, {
  6251. class: this.pinned
  6252. ? "ss-sidebar-base-icon icon-fix-bold"
  6253. : "ss-sidebar-base-icon icon-fix",
  6254. }),
  6255. ]
  6256. ),
  6257. Vue.h(
  6258. "button",
  6259. {
  6260. type: "button",
  6261. class: "ss-sidebar-chart-tool",
  6262. title: "全屏",
  6263. onClick: (e) => {
  6264. e.stopPropagation();
  6265. this.toggleFullscreen();
  6266. },
  6267. },
  6268. [
  6269. Vue.h(SsIcon, {
  6270. class: this.fullscreen
  6271. ? "ss-sidebar-base-icon icon-fs-exit"
  6272. : "ss-sidebar-base-icon icon-fs",
  6273. }),
  6274. ]
  6275. ),
  6276. ]),
  6277. ]
  6278. )
  6279. : Vue.h(
  6280. "div",
  6281. {
  6282. class:
  6283. "ss-sidebar-chart-preview__header ss-sidebar-chart-preview__header--simple",
  6284. },
  6285. [
  6286. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6287. Vue.h(
  6288. "button",
  6289. {
  6290. type: "button",
  6291. class: {
  6292. "ss-sidebar-chart-tool": true,
  6293. "is-active": this.pinned,
  6294. },
  6295. title: this.pinned ? "取消固定" : "固定",
  6296. onClick: (e) => {
  6297. e.stopPropagation();
  6298. this.togglePin();
  6299. },
  6300. },
  6301. [
  6302. Vue.h(SsIcon, {
  6303. class: this.pinned
  6304. ? "ss-sidebar-base-icon icon-fix-bold"
  6305. : "ss-sidebar-base-icon icon-fix",
  6306. }),
  6307. ]
  6308. ),
  6309. Vue.h(
  6310. "button",
  6311. {
  6312. type: "button",
  6313. class: "ss-sidebar-chart-tool",
  6314. title: "全屏",
  6315. onClick: (e) => {
  6316. e.stopPropagation();
  6317. this.toggleFullscreen();
  6318. },
  6319. },
  6320. [
  6321. Vue.h(SsIcon, {
  6322. class: this.fullscreen
  6323. ? "ss-sidebar-base-icon icon-chk-on"
  6324. : "ss-sidebar-base-icon icon-chk",
  6325. }),
  6326. ]
  6327. ),
  6328. ]),
  6329. ]
  6330. ),
  6331. Vue.h("div", { class: "ss-sidebar-chart-preview__body" }, [
  6332. Vue.h(Chart, { options: this.options, height: "100%" }),
  6333. ]),
  6334. ]
  6335. );
  6336. const fullscreenContent =
  6337. this.fullscreen &&
  6338. Vue.h(
  6339. "div",
  6340. {
  6341. ref: "fullscreenRef",
  6342. class: "ss-sidebar-chart-fullscreen",
  6343. },
  6344. [
  6345. Vue.h(
  6346. "div",
  6347. {
  6348. class:
  6349. "ss-sidebar-panel__header ss-sidebar-chart-fullscreen__header",
  6350. },
  6351. [
  6352. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  6353. this.iconClass
  6354. ? Vue.h(SsIcon, {
  6355. class: this.iconClass + " ss-sidebar-panel__icon",
  6356. })
  6357. : this.icon
  6358. ? Vue.h(SsIcon, {
  6359. name: this.icon,
  6360. size: "16px",
  6361. class: "ss-sidebar-panel__icon",
  6362. })
  6363. : null,
  6364. Vue.h("span", null, this.title || "统计图"),
  6365. ]),
  6366. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6367. Vue.h(
  6368. "button",
  6369. {
  6370. type: "button",
  6371. class: {
  6372. "ss-sidebar-chart-tool": true,
  6373. "is-active": this.pinned,
  6374. },
  6375. title: this.pinned ? "取消固定" : "固定",
  6376. onClick: (e) => {
  6377. e.stopPropagation();
  6378. this.togglePin();
  6379. },
  6380. },
  6381. [
  6382. Vue.h(SsIcon, {
  6383. class: this.pinned
  6384. ? "ss-sidebar-base-icon icon-fix-bold"
  6385. : "ss-sidebar-base-icon icon-fix",
  6386. }),
  6387. ]
  6388. ),
  6389. Vue.h(
  6390. "button",
  6391. {
  6392. type: "button",
  6393. class: "ss-sidebar-chart-tool",
  6394. title: "退出全屏",
  6395. onClick: (e) => {
  6396. e.stopPropagation();
  6397. this.toggleFullscreen();
  6398. },
  6399. },
  6400. [
  6401. Vue.h(SsIcon, {
  6402. class: "ss-sidebar-base-icon icon-fs-exit",
  6403. }),
  6404. ]
  6405. ),
  6406. ]),
  6407. ]
  6408. ),
  6409. Vue.h("div", { class: "ss-sidebar-chart-fullscreen__body" }, [
  6410. Vue.h(Chart, { options: this.options, height: "100%" }),
  6411. ]),
  6412. ]
  6413. );
  6414. return Vue.h("div", { class: "ss-sidebar-chart-hover" }, [
  6415. Vue.h(
  6416. "div",
  6417. {
  6418. ref: "triggerRef",
  6419. class: "ss-sidebar-chart-hover__trigger",
  6420. onMouseenter: () => {
  6421. this.hoveringTrigger = true;
  6422. this.openPreview();
  6423. },
  6424. onMouseleave: () => {
  6425. this.hoveringTrigger = false;
  6426. this.scheduleClose();
  6427. },
  6428. },
  6429. [Vue.h(Chart, { options: this.options, height: this.height })]
  6430. ),
  6431. (this.open || this.fullscreen) &&
  6432. Vue.h(Vue.Teleport, { to: "body" }, [
  6433. this.open ? previewContent : null,
  6434. fullscreenContent || null,
  6435. ]),
  6436. ]);
  6437. },
  6438. };
  6439. // 组件文档补全(JSDoc) by xu 20260108
  6440. /**
  6441. * SsSidebarList(右侧业务面板:人员/已选/服务/预定...)
  6442. *
  6443. * 用途:
  6444. * - 统一渲染面板 header(图标/标题/数量/右侧按钮)
  6445. * - 统一渲染 list(固定行高、hover、右侧移除按钮等)
  6446. *
  6447. * 调用示例(由 ss-sidebar 通过 panels 配置驱动):
  6448. * ```js
  6449. * { type:'list', title:'已选', iconClass:'menu-icon icon-obj-xcd', mode:'selected', items:selectedItems, closable:true }
  6450. * ```
  6451. *
  6452. * Props(核心):
  6453. * - `title`:header 标题
  6454. * - `iconClass/icon`:header 图标(优先 iconClass)
  6455. * - `count`:数量回显(图表面板可不传)
  6456. * - `closable`:是否显示“清空”按钮(触发 emit clear)
  6457. * - `headerFilters`:header 条件数组(组件名 + props),用于联调接口搜索
  6458. * - `headerSearchButton`:是否显示搜索按钮(触发 emit search)
  6459. * - `items`:列表数据
  6460. * - `mode`:`selected` 时右侧按钮语义为“移除”
  6461. * - `itemLayout`:`simple` / `person`(人员号槽位)
  6462. * - `itemAction`:是否显示 item 右侧操作按钮(hover 才出现)
  6463. *
  6464. * Emits:
  6465. * - `remove(item)`:点击 item 右侧移除
  6466. * - `clear()`:点击 header 清空
  6467. * - `search({keyword, filters})`:点击 header 搜索
  6468. */
  6469. const SsSidebarList = {
  6470. name: "SsSidebarList",
  6471. props: {
  6472. title: { type: String, default: "" },
  6473. // header 图标:优先使用 iconClass(走 ss-icon v3.0 class 分支) by xu 20260106
  6474. iconClass: { type: String, default: "" },
  6475. icon: { type: String, default: "" }, // 兼容旧写法(ss-icon name)
  6476. count: { type: [Number, String], default: "" },
  6477. // 选中类分区:右侧关闭按钮=清空分区数据 by xu 20260106
  6478. closable: { type: Boolean, default: false },
  6479. searchable: { type: Boolean, default: false },
  6480. // 搜索框是否放在 header 内(人员块需要该布局) by xu 20260106
  6481. searchInHeader: { type: Boolean, default: false },
  6482. // header 搜索:下拉条件 + 搜索按钮(适合“人员”块) by xu 20260106
  6483. headerFilters: { type: Array, default: () => [] },
  6484. headerSearchButton: { type: Boolean, default: false },
  6485. searchPlaceholder: { type: String, default: "搜索" },
  6486. // 列表项布局:simple(仅标题) / person(标题+人员号槽位) by xu 20260106
  6487. itemLayout: { type: String, default: "simple" },
  6488. itemAction: { type: Boolean, default: true },
  6489. collapsible: { type: Boolean, default: true }, // 功能说明:是否允许双击 header 折叠/展开 by xu 20260116
  6490. collapsed: { type: Boolean, default: false }, // 功能说明:折叠态仅展示 header by xu 20260116
  6491. items: { type: Array, default: () => [] },
  6492. mode: { type: String, default: "search" }, // search / selected
  6493. },
  6494. emits: ["select", "remove", "clear", "search", "toggle-collapse"],
  6495. data() {
  6496. return {
  6497. keyword: "",
  6498. filterValues: {},
  6499. }; // 功能说明:折叠状态完全由 props.collapsed 驱动,避免多面板复用导致状态不同步 by xu 20260116
  6500. },
  6501. created() {
  6502. // header 下拉条件默认值初始化 by xu 20260106
  6503. (this.headerFilters || []).forEach((f) => {
  6504. if (!f || !f.key) return;
  6505. if (this.filterValues[f.key] !== undefined) return;
  6506. const first = f?.options?.[0]?.value ?? "";
  6507. this.filterValues[f.key] = f.value !== undefined ? f.value : first;
  6508. });
  6509. },
  6510. methods: {
  6511. __shouldIgnoreHeaderToggle(e) {
  6512. // 功能说明:忽略工具区/输入区触发折叠,避免误触 by xu 20260116
  6513. const t = e?.target;
  6514. if (!t || !t.closest) return false;
  6515. if (t.closest(".ss-sidebar-panel__tools")) return true;
  6516. if (t.closest(".ss-sidebar-panel__filters")) return true;
  6517. if (t.closest("input,textarea,select,button")) return true;
  6518. return false;
  6519. },
  6520. __toggleCollapseInternal(e, source) {
  6521. if (!this.collapsible) return;
  6522. if (this.__shouldIgnoreHeaderToggle(e)) return;
  6523. const nextCollapsed = !this.collapsed;
  6524. console.log("[SsSidebarList] toggle emit", {
  6525. title: this.title,
  6526. source,
  6527. to: nextCollapsed,
  6528. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  6529. // 功能说明:由父组件(SsSidebar.toggleSectionCollapse)统一控制 section 高度与折叠数组 by xu 20260116
  6530. this.$emit("toggle-collapse");
  6531. },
  6532. },
  6533. render() {
  6534. const items = this.items || [];
  6535. const SsIcon = Vue.resolveComponent("ss-icon");
  6536. const isSelectedMode = this.mode === "selected";
  6537. const activeKeyword = this.filterValues?.keyword ?? this.keyword; // 功能:keyword 优先取 headerFilters.keyword by xu 20260106
  6538. const hasHeaderKeyword = (this.headerFilters || []).some(
  6539. (f) => f?.key === "keyword"
  6540. ); // 功能:header 内 keyword 过滤 by xu 20260106
  6541. const renderHeaderFilter = (f) => {
  6542. if (!f) return null;
  6543. const key = f.key;
  6544. const componentName = f.component;
  6545. if (!key || !componentName) return null;
  6546. const Comp = Vue.resolveComponent(componentName);
  6547. if (!Comp) return null;
  6548. const modelValue = this.filterValues[key];
  6549. const props = f.props || {};
  6550. return Vue.h(Comp, {
  6551. ...props,
  6552. modelValue,
  6553. "onUpdate:modelValue": (v) => {
  6554. this.filterValues[key] = v;
  6555. },
  6556. });
  6557. };
  6558. const filteredItems =
  6559. this.searchable && activeKeyword
  6560. ? items.filter((it) =>
  6561. String(it?.title ?? "")
  6562. .toLowerCase()
  6563. .includes(String(activeKeyword).toLowerCase())
  6564. )
  6565. : items;
  6566. if (!filteredItems.length && !this.title) return null;
  6567. if (this.collapsed) {
  6568. return Vue.h("div", { class: "ss-sidebar-panel" }, [
  6569. this.title
  6570. ? Vue.h(
  6571. "div",
  6572. {
  6573. class: "ss-sidebar-panel__header",
  6574. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  6575. onDblclick: (e) => {
  6576. e?.preventDefault?.();
  6577. e?.stopPropagation?.();
  6578. console.log("[SsSidebarList] header dblclick", {
  6579. title: this.title,
  6580. collapsed: true,
  6581. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  6582. this.__toggleCollapseInternal(e, "dblclick");
  6583. },
  6584. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  6585. },
  6586. [
  6587. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  6588. this.iconClass
  6589. ? Vue.h(SsIcon, {
  6590. class: this.iconClass + " ss-sidebar-panel__icon",
  6591. })
  6592. : this.icon
  6593. ? Vue.h(SsIcon, {
  6594. name: this.icon,
  6595. size: "16px",
  6596. class: "ss-sidebar-panel__icon",
  6597. })
  6598. : null,
  6599. Vue.h("span", null, this.title),
  6600. this.count !== ""
  6601. ? Vue.h(
  6602. "span",
  6603. { class: "ss-sidebar-panel__count" },
  6604. `(${this.count})`
  6605. )
  6606. : null,
  6607. ]),
  6608. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6609. this.closable
  6610. ? Vue.h(
  6611. "button",
  6612. {
  6613. type: "button",
  6614. class: "ss-sidebar-icon-btn ss-sidebar-header-btn",
  6615. title: "清空",
  6616. onClick: (e) => {
  6617. e.stopPropagation();
  6618. this.$emit("clear");
  6619. },
  6620. },
  6621. [
  6622. Vue.h(SsIcon, {
  6623. class: "ss-sidebar-base-icon icon-cl",
  6624. }),
  6625. ] // 功能说明:右侧栏“已选”清空按钮图标使用 ss-sidebar-base-icon by xu 20260123
  6626. )
  6627. : null,
  6628. ]),
  6629. ]
  6630. )
  6631. : null,
  6632. ]);
  6633. }
  6634. return Vue.h("div", { class: "ss-sidebar-panel" }, [
  6635. this.title
  6636. ? Vue.h(
  6637. "div",
  6638. {
  6639. class: "ss-sidebar-panel__header",
  6640. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  6641. onDblclick: (e) => {
  6642. e?.preventDefault?.();
  6643. e?.stopPropagation?.();
  6644. console.log("[SsSidebarList] header dblclick", {
  6645. title: this.title,
  6646. collapsed: false,
  6647. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  6648. this.__toggleCollapseInternal(e, "dblclick");
  6649. },
  6650. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  6651. },
  6652. [
  6653. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  6654. // 图标 + 标题(每个分区都有) by xu 20260106
  6655. this.iconClass
  6656. ? Vue.h(SsIcon, {
  6657. class: this.iconClass + " ss-sidebar-panel__icon",
  6658. })
  6659. : this.icon
  6660. ? Vue.h(SsIcon, {
  6661. name: this.icon,
  6662. size: "16px",
  6663. class: "ss-sidebar-panel__icon",
  6664. })
  6665. : null,
  6666. Vue.h("span", null, this.title),
  6667. // 数量回显:图表分区可不传 count by xu 20260106
  6668. this.count !== ""
  6669. ? Vue.h(
  6670. "span",
  6671. { class: "ss-sidebar-panel__count" },
  6672. `(${this.count})`
  6673. )
  6674. : null,
  6675. ]),
  6676. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6677. // header 条件(例如下拉框)+ 右侧搜索按钮 by xu 20260106
  6678. this.headerFilters?.length
  6679. ? Vue.h(
  6680. "div",
  6681. { class: "ss-sidebar-panel__filters" },
  6682. this.headerFilters
  6683. .map(renderHeaderFilter)
  6684. .filter(Boolean)
  6685. )
  6686. : null,
  6687. this.headerSearchButton
  6688. ? Vue.h(
  6689. "button",
  6690. {
  6691. type: "button",
  6692. class: "ss-sidebar-icon-btn",
  6693. title: "搜索",
  6694. onClick: (e) => {
  6695. e.stopPropagation();
  6696. this.$emit("search", {
  6697. // headerFilters 内也可能包含 keyword by xu 20260106
  6698. keyword: activeKeyword,
  6699. filters: { ...(this.filterValues || {}) },
  6700. });
  6701. },
  6702. },
  6703. [Vue.h(SsIcon, { name: "search", size: "14px" })]
  6704. )
  6705. : null,
  6706. // 人员块:搜索框在 header 内 by xu 20260106
  6707. this.searchable &&
  6708. this.searchInHeader &&
  6709. !this.headerSearchButton
  6710. ? Vue.h(
  6711. "div",
  6712. { class: "ss-sidebar-panel__searchInline" },
  6713. [
  6714. Vue.h(
  6715. "div",
  6716. { class: "ss-sidebar-search is-inline" },
  6717. [
  6718. Vue.h(SsIcon, {
  6719. name: "search",
  6720. size: "14px",
  6721. class: "ss-sidebar-search__prefix",
  6722. }),
  6723. Vue.h("input", {
  6724. class: "ss-sidebar-search__input",
  6725. value: this.keyword,
  6726. placeholder: this.searchPlaceholder,
  6727. onInput: (e) => {
  6728. this.keyword = e?.target?.value ?? "";
  6729. },
  6730. }),
  6731. ]
  6732. ),
  6733. ]
  6734. )
  6735. : null,
  6736. this.closable
  6737. ? Vue.h(
  6738. "button",
  6739. {
  6740. type: "button",
  6741. class: "ss-sidebar-icon-btn ss-sidebar-header-btn",
  6742. title: "清空",
  6743. onClick: (e) => {
  6744. e.stopPropagation();
  6745. this.$emit("clear");
  6746. },
  6747. },
  6748. // 清空按钮使用 icon-base 的 icon-cl by xu 20260106
  6749. [
  6750. Vue.h(SsIcon, {
  6751. class: "ss-sidebar-base-icon icon-cl",
  6752. }),
  6753. ] // 功能说明:右侧栏清空按钮图标使用 ss-sidebar-base-icon by xu 20260123
  6754. )
  6755. : null,
  6756. ]),
  6757. ]
  6758. )
  6759. : null,
  6760. // 非 header 内搜索:独立一行 by xu 20260106
  6761. // headerSearchButton/headerFilters 已覆盖搜索能力时,不再额外渲染独立搜索行 by xu 20260106
  6762. this.searchable &&
  6763. !this.searchInHeader &&
  6764. !this.headerSearchButton &&
  6765. !hasHeaderKeyword
  6766. ? Vue.h("div", { class: "ss-sidebar-panel__search" }, [
  6767. Vue.h("div", { class: "ss-sidebar-search" }, [
  6768. Vue.h(SsIcon, {
  6769. name: "search",
  6770. size: "14px",
  6771. class: "ss-sidebar-search__prefix",
  6772. }),
  6773. Vue.h("input", {
  6774. class: "ss-sidebar-search__input",
  6775. value: this.keyword,
  6776. placeholder: this.searchPlaceholder,
  6777. onInput: (e) => {
  6778. this.keyword = e?.target?.value ?? "";
  6779. },
  6780. }),
  6781. ]),
  6782. ])
  6783. : null,
  6784. Vue.h(
  6785. "div",
  6786. { class: "ss-sidebar-list" },
  6787. filteredItems.map((item, idx) => {
  6788. const title = item?.title ?? "";
  6789. const tags = item?.tags || [];
  6790. const isPersonLayout = this.itemLayout === "person";
  6791. const hasTags = !isPersonLayout && tags?.length > 0; // 列表项垂直对齐:有 tags 顶对齐 by xu 20260106
  6792. return Vue.h(
  6793. "div",
  6794. {
  6795. class: {
  6796. "ss-sidebar-list-item": true,
  6797. "is-first": idx === 0,
  6798. "is-person": isPersonLayout,
  6799. "has-tags": hasTags,
  6800. },
  6801. },
  6802. [
  6803. Vue.h("div", { class: "ss-sidebar-list-item__main" }, [
  6804. Vue.h(
  6805. "div",
  6806. { class: "ss-sidebar-list-item__title" },
  6807. Vue.h(
  6808. "span",
  6809. {
  6810. style: {
  6811. "white-space": "nowrap",
  6812. overflow: "hidden",
  6813. "text-overflow": "ellipsis",
  6814. },
  6815. },
  6816. title
  6817. )
  6818. ),
  6819. // 非人员布局才显示 tags by xu 20260106
  6820. !isPersonLayout && tags?.length
  6821. ? Vue.h(
  6822. "div",
  6823. { class: "ss-sidebar-list-item__tags" },
  6824. tags.map((tag) => {
  6825. const [k, v] = Object.entries(tag)[0] || ["", ""];
  6826. return Vue.h(
  6827. "span",
  6828. { class: "ss-sidebar-tag", title: `${k}: ${v}` },
  6829. `${k}: ${v}`
  6830. );
  6831. })
  6832. )
  6833. : null,
  6834. ]),
  6835. // 人员布局:中间保留“人员号”槽位 by xu 20260106
  6836. isPersonLayout
  6837. ? Vue.h(
  6838. "div",
  6839. {
  6840. class: "ss-sidebar-list-item__meta",
  6841. title: String(item?.meta ?? ""),
  6842. },
  6843. item?.meta ?? ""
  6844. )
  6845. : null,
  6846. this.itemAction
  6847. ? Vue.h(
  6848. "button",
  6849. {
  6850. type: "button",
  6851. class: {
  6852. // item 操作按钮:默认无背景/无边框,hover 才高亮 by xu 20260106
  6853. "ss-sidebar-item-btn": true,
  6854. },
  6855. title: isSelectedMode ? "移除" : "选择",
  6856. onClick: (e) => {
  6857. e.stopPropagation();
  6858. if (isSelectedMode) this.$emit("remove", item);
  6859. else this.$emit("select", item);
  6860. },
  6861. },
  6862. [
  6863. // item 移除图标使用 icon-base 的 icon-cl by xu 20260106
  6864. isSelectedMode
  6865. ? Vue.h(SsIcon, {
  6866. class: "ss-sidebar-base-icon icon-cl",
  6867. }) // 功能说明:右侧栏 item 移除图标使用 ss-sidebar-base-icon by xu 20260123
  6868. : Vue.h(SsIcon, { name: "check", size: "14px" }),
  6869. ]
  6870. )
  6871. : null,
  6872. ]
  6873. );
  6874. })
  6875. ),
  6876. ]);
  6877. },
  6878. };
  6879. // ss-sidebar-report-table:右侧“统计表/报表”面板(pstatList grtjlbm=51 聚拢渲染) by xu 20260115
  6880. const SsSidebarReportTable = {
  6881. name: "SsSidebarReportTable",
  6882. props: {
  6883. title: { type: String, default: "" },
  6884. iconClass: { type: String, default: "" },
  6885. icon: { type: String, default: "" },
  6886. items: { type: Array, default: () => [] }, // pstatList(grtjlbm=51) 数组
  6887. onOpen: { type: Function, default: null }, // (srv, ctx) => void
  6888. collapsible: { type: Boolean, default: true }, // 功能说明:是否允许双击 header 折叠/展开 by xu 20260116
  6889. collapsed: { type: Boolean, default: false }, // 功能说明:折叠态仅展示 header by xu 20260116
  6890. },
  6891. emits: ["open", "toggle-collapse"],
  6892. data() {
  6893. return {}; // 功能说明:折叠状态完全由 props.collapsed 驱动 by xu 20260116
  6894. },
  6895. methods: {
  6896. __toggleCollapseInternal(e, source) {
  6897. if (!this.collapsible) return;
  6898. const next = !this.collapsed;
  6899. console.log("[SsSidebarReportTable] toggle emit", {
  6900. title: this.title,
  6901. source,
  6902. to: next,
  6903. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  6904. this.$emit("toggle-collapse");
  6905. },
  6906. },
  6907. render() {
  6908. const SsIcon = Vue.resolveComponent("ss-icon");
  6909. const list = this.items || [];
  6910. if (!this.title && !list.length) return null;
  6911. const header = this.title
  6912. ? Vue.h(
  6913. "div",
  6914. {
  6915. class: "ss-sidebar-panel__header",
  6916. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  6917. onDblclick: (e) => {
  6918. e?.preventDefault?.();
  6919. e?.stopPropagation?.();
  6920. console.log("[SsSidebarReportTable] header dblclick", {
  6921. title: this.title,
  6922. collapsed: this.collapsed,
  6923. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  6924. this.__toggleCollapseInternal(e, "dblclick");
  6925. },
  6926. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  6927. },
  6928. [
  6929. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  6930. this.iconClass
  6931. ? Vue.h(SsIcon, {
  6932. class: this.iconClass + " ss-sidebar-panel__icon",
  6933. })
  6934. : this.icon
  6935. ? Vue.h(SsIcon, {
  6936. name: this.icon,
  6937. size: "16px",
  6938. class: "ss-sidebar-panel__icon",
  6939. })
  6940. : null,
  6941. Vue.h("span", null, this.title),
  6942. ]),
  6943. Vue.h("div", { class: "ss-sidebar-panel__tools" }),
  6944. ]
  6945. )
  6946. : null;
  6947. const renderReport = (report) => {
  6948. const title = String(report?.mc ?? "");
  6949. const mx = Array.isArray(report?.grtjmxList) ? report.grtjmxList : [];
  6950. if (!title && !mx.length) return null;
  6951. // 功能说明:每个报表对象渲染为一个 table(有边框、无圆角、表间距10px;样式由 base.css 统一控制) by xu 20260115
  6952. const cols = Math.max(1, mx.length);
  6953. // 功能说明:table 外层包一层 wrap,子项过多时支持横向滚动 by xu 20260115
  6954. return Vue.h("div", { class: "ss-sidebar-report-table-wrap" }, [
  6955. Vue.h("table", { class: "ss-sidebar-report-table" }, [
  6956. Vue.h("thead", null, [
  6957. Vue.h("tr", null, [
  6958. Vue.h(
  6959. "th",
  6960. { class: "ss-sidebar-report-table__title", colspan: cols },
  6961. Vue.h(
  6962. "div",
  6963. { class: "ss-sidebar-report-table__title-content" },
  6964. [
  6965. Vue.h("span", { class: "ss-sidebar-report-table__dot" }),
  6966. Vue.h(
  6967. "span",
  6968. { class: "ss-sidebar-report-table__title-text", title },
  6969. title
  6970. ),
  6971. ]
  6972. )
  6973. ),
  6974. ]),
  6975. ]),
  6976. Vue.h("tbody", null, [
  6977. Vue.h(
  6978. "tr",
  6979. null,
  6980. mx.map((cell) => {
  6981. const text = String(cell?.mc ?? "");
  6982. const srv = {
  6983. servName: cell?.fwm ?? "",
  6984. dest: cell?.bjm ?? "",
  6985. title: text,
  6986. width: cell?.width,
  6987. height: cell?.height,
  6988. minHeight: cell?.height,
  6989. maxHeight: cell?.height,
  6990. showTitle: text,
  6991. };
  6992. return Vue.h(
  6993. "td",
  6994. {
  6995. class: "ss-sidebar-report-table__cell",
  6996. title: text,
  6997. onClick: (e) => {
  6998. e?.stopPropagation?.();
  6999. try {
  7000. this.onOpen?.(srv, { report, cell });
  7001. } catch (_) {}
  7002. this.$emit("open", { report, cell, srv });
  7003. },
  7004. },
  7005. text
  7006. );
  7007. })
  7008. ),
  7009. ]),
  7010. ]),
  7011. ]);
  7012. };
  7013. // 功能说明:报表面板增加独立 class,便于 base.css 统一控制 padding/间距 by xu 20260115
  7014. return Vue.h(
  7015. "div",
  7016. { class: "ss-sidebar-panel ss-sidebar-report-panel" },
  7017. [
  7018. header,
  7019. this.collapsed
  7020. ? null
  7021. : Vue.h(
  7022. "div",
  7023. // 功能说明:报表列表滚动/高度样式下沉到 base.css,避免写在 DOM 上 by xu 20260115
  7024. { class: "ss-sidebar-report__list" },
  7025. list.map(renderReport).filter(Boolean)
  7026. ),
  7027. ]
  7028. );
  7029. },
  7030. };
  7031. // 组件文档补全(JSDoc) by xu 20260108
  7032. /**
  7033. * SsSidebar(objList 右侧边栏容器)
  7034. *
  7035. * 用途:
  7036. * - 统一渲染顶部按钮栏(buttons)
  7037. * - 统一渲染中间业务面板(list panels,可拖拽调高度)
  7038. * - 统一渲染底部图表(chart panels,内部用 ss-sidebar-chart-hover)
  7039. *
  7040. * 调用示例:
  7041. * ```html
  7042. * <ss-sidebar :buttons="sidebarButtons" :panels="sidebarPanels" @remove="handleSidebarRemove" />
  7043. * ```
  7044. *
  7045. * Props:
  7046. * - `buttons`:顶部按钮配置数组
  7047. * - `panels`:分区配置数组(`type: 'list' | 'chart'`)
  7048. *
  7049. * Events(向外透传):
  7050. * - `remove(item)`:来自 list 面板移除
  7051. * - `select(item)`:来自 list 面板选择(如后续需要)
  7052. */
  7053. const SsSidebar = {
  7054. name: "SsSidebar",
  7055. props: {
  7056. buttons: { type: Array, default: () => [] },
  7057. charts: { type: Array, default: () => [] },
  7058. list: { type: Array, default: () => [] }, // legacy
  7059. listMode: { type: String, default: "search" }, // legacy
  7060. panels: { type: Array, default: () => [] },
  7061. },
  7062. emits: ["select", "remove"],
  7063. data() {
  7064. return {
  7065. // 业务面板高度(索引 -> px) by xu 20260106
  7066. sectionHeights: [],
  7067. sectionCollapsed: [], // 功能说明:面板折叠状态(sectionPanels 索引) by xu 20260116
  7068. sectionHeightsExpanded: [], // 功能说明:面板展开高度缓存(用于折叠后恢复) by xu 20260116
  7069. chartCollapsed: [], // 功能说明:图表面板折叠状态(chartPanels 索引) by xu 20260116
  7070. chartHeaderTitleDownAt: [], // 功能说明:双击检测绑定到 chart 标题区 by xu 20260116
  7071. reportCollapsed: [], // 功能说明:报表面板折叠状态(reportPanels 索引) by xu 20260116
  7072. resizeTimer: null,
  7073. resizing: false,
  7074. resizeIndex: -1,
  7075. resizeStartY: 0,
  7076. resizeStartPrev: 0,
  7077. resizeStartNext: 0,
  7078. __resizeMoveHandler: null, // 功能说明:显式绑定 this 的 pointermove handler,避免 addEventListener 场景 this 丢失导致拖拽无效 by xu 20260122
  7079. __resizeEndHandler: null, // 功能说明:显式绑定 this 的 pointerup handler,确保能正确结束拖拽 by xu 20260122
  7080. __resizeCancelHandler: null, // 功能说明:显式绑定 this 的 pointercancel handler,触控取消也能收尾 by xu 20260122
  7081. __resizePrevSectionEl: null, // 功能说明:拖拽时直接写 DOM 高度(修复响应式更新不生效) by xu 20260122
  7082. __resizeNextSectionEl: null, // 功能说明:拖拽时直接写 DOM 高度(修复响应式更新不生效) by xu 20260122
  7083. };
  7084. },
  7085. methods: {
  7086. // 初始化默认高度(只在第一次/面板数量变化时补齐) by xu 20260106
  7087. ensureSectionHeights(sectionCount) {
  7088. if (!Array.isArray(this.sectionHeights)) this.sectionHeights = [];
  7089. if (this.sectionHeights.length === sectionCount) return;
  7090. const next = [];
  7091. for (let i = 0; i < sectionCount; i++) {
  7092. next[i] = this.sectionHeights[i] ?? 190; // 默认高度 by xu 20260106
  7093. }
  7094. this.sectionHeights = next;
  7095. // 功能说明:面板数量变化时补齐折叠/缓存数组长度 by xu 20260116
  7096. this.sectionCollapsed = Array.from(
  7097. { length: sectionCount },
  7098. (_, i) => !!this.sectionCollapsed?.[i]
  7099. );
  7100. this.sectionHeightsExpanded = Array.from(
  7101. { length: sectionCount },
  7102. (_, i) => this.sectionHeightsExpanded?.[i] ?? null
  7103. );
  7104. },
  7105. toggleSectionCollapse(index) {
  7106. // 功能说明:双击 header 折叠/展开 section 面板(仅控制高度与内容渲染) by xu 20260116
  7107. const i = Number(index);
  7108. if (isNaN(i) || i < 0) return;
  7109. // 功能说明:加更细粒度日志,定位“多面板折叠无视觉效果”的根因(高度是否真的变、DOM 是否更新) by xu 20260116
  7110. const collapsedHeight = 37; // 功能说明:header(35) + panel 边框(2),避免 flex shrink 导致 header 变 25px by xu 20260116
  7111. const cur = !!this.sectionCollapsed?.[i];
  7112. console.log("[SsSidebar] toggleSectionCollapse", {
  7113. index: i,
  7114. to: !cur,
  7115. prevHeight: this.sectionHeights?.[i],
  7116. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7117. if (!cur) {
  7118. this.sectionHeightsExpanded[i] = this.sectionHeights[i] ?? 190;
  7119. this.sectionHeights.splice(i, 1, collapsedHeight);
  7120. } else {
  7121. const restore =
  7122. Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  7123. this.sectionHeights.splice(i, 1, restore);
  7124. }
  7125. this.sectionCollapsed.splice(i, 1, !cur);
  7126. console.log("[SsSidebar] section state(after)", {
  7127. index: i,
  7128. height: this.sectionHeights?.[i],
  7129. collapsed: this.sectionCollapsed?.[i],
  7130. allHeights: Array.from(this.sectionHeights || []),
  7131. allCollapsed: Array.from(this.sectionCollapsed || []),
  7132. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7133. Vue.nextTick(() => {
  7134. try {
  7135. const root = this.$el;
  7136. const sections = root?.querySelectorAll?.(".ss-sidebar-section");
  7137. const el = sections?.[i];
  7138. const rectH = el?.getBoundingClientRect?.().height;
  7139. console.log("[SsSidebar] section dom(beforeFix)", {
  7140. index: i,
  7141. styleHeight: el?.style?.height,
  7142. rectH,
  7143. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7144. // 功能说明:若渲染未把 height patch 到 DOM,则在 nextTick 强制同步一次(并打印) by xu 20260116
  7145. const targetH =
  7146. (Number(this.sectionHeights?.[i] ?? 190) || 190) + "px";
  7147. if (el && el.style && el.style.height !== targetH) {
  7148. el.style.height = targetH;
  7149. }
  7150. if (el?.classList) {
  7151. el.classList.toggle("is-collapsed", !!this.sectionCollapsed?.[i]);
  7152. }
  7153. const rectAfter = el?.getBoundingClientRect?.().height;
  7154. console.log("[SsSidebar] section dom(afterFix)", {
  7155. index: i,
  7156. styleHeight: el?.style?.height,
  7157. rectH: rectAfter,
  7158. targetH,
  7159. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7160. } catch (err) {
  7161. console.log("[SsSidebar] section dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7162. }
  7163. });
  7164. },
  7165. toggleChartCollapse(index) {
  7166. // 功能说明:双击 header 折叠/展开底部 chart 面板(隐藏/显示 chart-hover) by xu 20260116
  7167. const i = Number(index);
  7168. if (isNaN(i) || i < 0) return;
  7169. const cur = !!this.chartCollapsed?.[i];
  7170. console.log("[SsSidebar] toggleChartCollapse", { index: i, to: !cur }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7171. this.chartCollapsed.splice(i, 1, !cur);
  7172. console.log("[SsSidebar] chart state(after)", {
  7173. index: i,
  7174. collapsed: this.chartCollapsed?.[i],
  7175. allCollapsed: Array.from(this.chartCollapsed || []),
  7176. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7177. Vue.nextTick(() => {
  7178. try {
  7179. const root = this.$el;
  7180. const el = root?.querySelector?.(
  7181. `.ss-sidebar-chart-panel[data-chart-idx="${i}"]`
  7182. );
  7183. console.log("[SsSidebar] chart dom(beforeFix)", {
  7184. index: i,
  7185. found: !!el,
  7186. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7187. if (el?.classList)
  7188. el.classList.toggle("is-collapsed", !!this.chartCollapsed?.[i]);
  7189. console.log("[SsSidebar] chart dom(afterFix)", {
  7190. index: i,
  7191. collapsed: !!this.chartCollapsed?.[i],
  7192. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7193. } catch (err) {
  7194. console.log("[SsSidebar] chart dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7195. }
  7196. });
  7197. },
  7198. toggleReportCollapse(index) {
  7199. // 功能说明:双击 header 折叠/展开底部 report-table 面板(隐藏/显示表格) by xu 20260116
  7200. const i = Number(index);
  7201. if (isNaN(i) || i < 0) return;
  7202. const cur = !!this.reportCollapsed?.[i];
  7203. console.log("[SsSidebar] toggleReportCollapse", { index: i, to: !cur }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7204. this.reportCollapsed.splice(i, 1, !cur);
  7205. console.log("[SsSidebar] report state(after)", {
  7206. index: i,
  7207. collapsed: this.reportCollapsed?.[i],
  7208. allCollapsed: Array.from(this.reportCollapsed || []),
  7209. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7210. Vue.nextTick(() => {
  7211. try {
  7212. const root = this.$el;
  7213. const el = root?.querySelector?.(
  7214. `.ss-sidebar-report-panel[data-report-idx="${i}"]`
  7215. );
  7216. console.log("[SsSidebar] report dom(beforeFix)", {
  7217. index: i,
  7218. found: !!el,
  7219. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7220. if (el?.classList)
  7221. el.classList.toggle("is-collapsed", !!this.reportCollapsed?.[i]);
  7222. console.log("[SsSidebar] report dom(afterFix)", {
  7223. index: i,
  7224. collapsed: !!this.reportCollapsed?.[i],
  7225. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7226. } catch (err) {
  7227. console.log("[SsSidebar] report dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7228. }
  7229. });
  7230. },
  7231. startResize(index, e) {
  7232. if (e?.preventDefault) e.preventDefault();
  7233. if (e?.stopPropagation) e.stopPropagation();
  7234. if (this.resizing) return;
  7235. // 长按 0.5s 后才进入拖拽调高度 by xu 20260106
  7236. clearTimeout(this.resizeTimer);
  7237. // 功能说明:修复“长按拖拽偶发失效/卡死”——pointerup 早于 500ms 时必须取消 timer,否则 timer 触发后进入 resizing=true 且再也收不到 pointerup,导致后续都无法拖拽 by xu 20260122
  7238. const pointerId = e?.pointerId;
  7239. const cancelPendingResize = (ev) => {
  7240. try {
  7241. if (
  7242. pointerId != null &&
  7243. ev?.pointerId != null &&
  7244. ev.pointerId !== pointerId
  7245. )
  7246. return;
  7247. } catch (_) {}
  7248. clearTimeout(this.resizeTimer);
  7249. this.resizeTimer = null;
  7250. document.removeEventListener("pointerup", cancelPendingResize, true);
  7251. document.removeEventListener(
  7252. "pointercancel",
  7253. cancelPendingResize,
  7254. true
  7255. );
  7256. };
  7257. // 功能说明:用 document+capture 监听,避免 window 监听在部分容器/iframe 场景丢事件导致拖拽无响应 by xu 20260122
  7258. document.addEventListener("pointerup", cancelPendingResize, {
  7259. passive: false,
  7260. once: true,
  7261. capture: true,
  7262. });
  7263. document.addEventListener("pointercancel", cancelPendingResize, {
  7264. passive: false,
  7265. once: true,
  7266. capture: true,
  7267. });
  7268. const startY = e?.clientY ?? 0;
  7269. const gapEl = e?.currentTarget;
  7270. // 功能说明:记录 gap 前后 section 节点,拖拽过程中直接写入 style.height,避免某些环境下 Vue render 不刷新导致“拖拽无视觉变化” by xu 20260122
  7271. this.__resizePrevSectionEl = gapEl?.previousElementSibling || null;
  7272. this.__resizeNextSectionEl = gapEl?.nextElementSibling || null;
  7273. this.resizeTimer = setTimeout(() => {
  7274. // 定时器触发后进入拖拽态,移除“取消等待”监听,避免误取消 by xu 20260122
  7275. document.removeEventListener("pointerup", cancelPendingResize, true);
  7276. document.removeEventListener(
  7277. "pointercancel",
  7278. cancelPendingResize,
  7279. true
  7280. );
  7281. this.resizing = true;
  7282. this.resizeIndex = index;
  7283. this.resizeStartY = startY;
  7284. this.resizeStartPrev = this.sectionHeights[index] ?? 190;
  7285. this.resizeStartNext = this.sectionHeights[index + 1] ?? 190;
  7286. gapEl?.classList?.add("is-active");
  7287. try {
  7288. if (gapEl?.setPointerCapture && pointerId != null)
  7289. gapEl.setPointerCapture(pointerId);
  7290. } catch (_) {} // 功能说明:捕获 pointer,避免拖拽过程中移出窗口导致 pointermove 丢失 by xu 20260122
  7291. // 功能说明:用 document+capture,确保拖拽时 pointermove/up 不会被中途 stopPropagation 影响 by xu 20260122
  7292. document.addEventListener(
  7293. "pointermove",
  7294. this.__resizeMoveHandler || this.onResizeMove,
  7295. { passive: false, capture: true }
  7296. );
  7297. document.addEventListener(
  7298. "pointerup",
  7299. this.__resizeEndHandler || this.endResize,
  7300. { passive: false, once: true, capture: true }
  7301. );
  7302. document.addEventListener(
  7303. "pointercancel",
  7304. this.__resizeCancelHandler || this.endResize,
  7305. { passive: false, once: true, capture: true }
  7306. ); // 功能说明:触控/手势取消时也要结束拖拽 by xu 20260122
  7307. }, 500);
  7308. },
  7309. onResizeMove(e) {
  7310. if (!this.resizing) return;
  7311. if (e?.preventDefault) e.preventDefault();
  7312. const dy = (e?.clientY ?? 0) - this.resizeStartY;
  7313. const minPanelHeight = 83; // header(35) + listMin(48) by xu 20260106
  7314. const prev = Math.max(minPanelHeight, this.resizeStartPrev + dy);
  7315. const next = Math.max(minPanelHeight, this.resizeStartNext - dy);
  7316. // 若其中一个达到最小值,则停止继续挤压 by xu 20260106
  7317. const adjustedDy = prev - this.resizeStartPrev;
  7318. const nextAdjusted = this.resizeStartNext - adjustedDy;
  7319. const appliedPrev = prev;
  7320. const appliedNext = Math.max(minPanelHeight, nextAdjusted);
  7321. this.sectionHeights.splice(this.resizeIndex, 1, appliedPrev);
  7322. this.sectionHeights.splice(this.resizeIndex + 1, 1, appliedNext);
  7323. // 功能说明:强制触发一次 sectionHeights 引用变化,避免某些运行时环境下 splice 未触发视图更新导致“拖拽没反应” by xu 20260122
  7324. this.sectionHeights = (this.sectionHeights || []).slice();
  7325. // 功能说明:兜底——直接写 DOM 的 height,确保视觉立即响应(用于排查/修复某些环境下 render 不更新) by xu 20260122
  7326. try {
  7327. if (this.__resizePrevSectionEl?.style)
  7328. this.__resizePrevSectionEl.style.height = appliedPrev + "px";
  7329. if (this.__resizeNextSectionEl?.style)
  7330. this.__resizeNextSectionEl.style.height = appliedNext + "px";
  7331. } catch (_) {}
  7332. },
  7333. endResize(e) {
  7334. clearTimeout(this.resizeTimer);
  7335. this.resizeTimer = null;
  7336. if (!this.resizing) return;
  7337. if (e?.preventDefault) e.preventDefault();
  7338. const activeGaps = document.querySelectorAll(
  7339. ".ss-sidebar-gap.is-active"
  7340. );
  7341. activeGaps.forEach((g) => g.classList.remove("is-active"));
  7342. this.resizing = false;
  7343. this.resizeIndex = -1;
  7344. this.__resizePrevSectionEl = null; // 功能说明:释放 DOM 引用,避免内存泄漏 by xu 20260122
  7345. this.__resizeNextSectionEl = null; // 功能说明:释放 DOM 引用,避免内存泄漏 by xu 20260122
  7346. document.removeEventListener(
  7347. "pointermove",
  7348. this.__resizeMoveHandler || this.onResizeMove,
  7349. true
  7350. );
  7351. document.removeEventListener(
  7352. "pointercancel",
  7353. this.__resizeCancelHandler || this.endResize,
  7354. true
  7355. ); // 功能说明:清理 cancel 监听,避免残留 by xu 20260122
  7356. },
  7357. },
  7358. mounted() {
  7359. clearTimeout(this.resizeTimer);
  7360. this.resizeTimer = null;
  7361. // 功能说明:绑定拖拽事件 handler(用于 add/removeEventListener) by xu 20260122
  7362. if (!this.__resizeMoveHandler)
  7363. this.__resizeMoveHandler = (e) => this.onResizeMove?.(e);
  7364. if (!this.__resizeEndHandler)
  7365. this.__resizeEndHandler = (e) => this.endResize?.(e);
  7366. if (!this.__resizeCancelHandler)
  7367. this.__resizeCancelHandler = (e) => this.endResize?.(e);
  7368. // 功能说明:暂时回退为固定底部留白方案(CSS 控制),后续再定位遮挡根因 by xu 20260115
  7369. },
  7370. beforeUnmount() {
  7371. clearTimeout(this.resizeTimer);
  7372. this.resizeTimer = null;
  7373. document.removeEventListener(
  7374. "pointermove",
  7375. this.__resizeMoveHandler || this.onResizeMove,
  7376. true
  7377. );
  7378. document.removeEventListener(
  7379. "pointerup",
  7380. this.__resizeEndHandler || this.endResize,
  7381. true
  7382. );
  7383. document.removeEventListener(
  7384. "pointercancel",
  7385. this.__resizeCancelHandler || this.endResize,
  7386. true
  7387. );
  7388. },
  7389. render() {
  7390. const SsSidebarButtonsComp = Vue.resolveComponent("ss-sidebar-buttons");
  7391. const SsSidebarChartComp = Vue.resolveComponent("ss-sidebar-chart");
  7392. const SsSidebarListComp = Vue.resolveComponent("ss-sidebar-list");
  7393. const SsSidebarReportTableComp = Vue.resolveComponent(
  7394. "ss-sidebar-report-table"
  7395. );
  7396. const SsIcon = Vue.resolveComponent("ss-icon");
  7397. // 支持 panels(多分区),list/listMode 作为 legacy 兜底 by xu 20260106
  7398. const panels = (this.panels || []).length
  7399. ? this.panels
  7400. : this.list?.length
  7401. ? [
  7402. {
  7403. type: "list",
  7404. title: "已选",
  7405. icon: "",
  7406. mode: this.listMode,
  7407. items: this.list,
  7408. },
  7409. ]
  7410. : [];
  7411. // 功能说明:右侧栏强制移除“对象”tab(兼容后端返回 rbarObj/rbarobj 或直接返回中文“对象”标题) by xu 20260116
  7412. const panelsNoObj = (panels || []).filter((p) => {
  7413. const k = String(p?._tabKey ?? "")
  7414. .trim()
  7415. .toLowerCase();
  7416. const t = String(p?.title ?? "").trim();
  7417. if (k === "rbarobj") return false;
  7418. if (t === "对象") return false;
  7419. return true;
  7420. });
  7421. // 功能说明:report-table 作为底部报表区(放在统计图下面),不参与可拖拽 section 面板 by xu 20260115
  7422. const sectionPanels = panelsNoObj.filter(
  7423. (p) => p?.type !== "chart" && p?.type !== "report-table"
  7424. );
  7425. const chartPanels = panelsNoObj.filter((p) => p?.type === "chart");
  7426. const reportPanels = panelsNoObj.filter(
  7427. (p) => p?.type === "report-table"
  7428. );
  7429. this.ensureSectionHeights(sectionPanels.length);
  7430. // 功能说明:补齐 chart/report 折叠数组长度 by xu 20260116
  7431. this.chartCollapsed = Array.from(
  7432. { length: chartPanels.length },
  7433. (_, i) => !!this.chartCollapsed?.[i]
  7434. );
  7435. this.chartHeaderTitleDownAt = Array.from(
  7436. { length: chartPanels.length },
  7437. (_, i) => this.chartHeaderTitleDownAt?.[i] ?? 0
  7438. );
  7439. this.reportCollapsed = Array.from(
  7440. { length: reportPanels.length },
  7441. (_, i) => !!this.reportCollapsed?.[i]
  7442. );
  7443. return Vue.h("div", { class: "ss-sidebar" }, [
  7444. this.buttons?.length
  7445. ? Vue.h(SsSidebarButtonsComp, { items: this.buttons })
  7446. : null,
  7447. Vue.h(
  7448. "div",
  7449. { class: "ss-sidebar__inner" },
  7450. [
  7451. ...(this.charts || []).map((c) =>
  7452. Vue.h(SsSidebarChartComp, {
  7453. options: c?.options || {},
  7454. height: c?.height || "200px",
  7455. })
  7456. ),
  7457. // 可拖拽的业务面板容器 by xu 20260106
  7458. Vue.h(
  7459. "div",
  7460. { class: "ss-sidebar-sections", style: { flex: "0 0 auto" } }, // 功能说明:禁止 flex shrink,避免面板很多时 header 被压缩成一条线 by xu 20260116
  7461. sectionPanels.flatMap((p, idx) => {
  7462. // 功能说明:section 面板支持 list / report-table 两种渲染 by xu 20260115
  7463. const panelContent =
  7464. p?.type === "report-table"
  7465. ? Vue.h(SsSidebarReportTableComp, {
  7466. key: `ss-sidebar-report-in-section-${idx}-${
  7467. p?.title ?? ""
  7468. }`, // 功能说明:加 key 防止多面板时组件实例复用导致折叠态不更新 by xu 20260116
  7469. title: p?.title ?? "",
  7470. icon: p?.icon ?? "",
  7471. iconClass: p?.iconClass ?? "",
  7472. items: p?.items || [],
  7473. onOpen: (srv, ctx) => p?.onOpen?.(srv, ctx),
  7474. })
  7475. : Vue.h(SsSidebarListComp, {
  7476. key: `ss-sidebar-list-${idx}-${p?.title ?? ""}`, // 功能说明:加 key 防止多面板时组件实例复用导致折叠态不更新 by xu 20260116
  7477. title: p?.title ?? "",
  7478. icon: p?.icon ?? "",
  7479. count: p?.count ?? p?.items?.length ?? "",
  7480. closable: !!p?.closable,
  7481. searchable: !!p?.searchable,
  7482. searchInHeader: !!p?.searchInHeader,
  7483. headerFilters: p?.headerFilters || [],
  7484. headerSearchButton: !!p?.headerSearchButton,
  7485. searchPlaceholder: p?.searchPlaceholder ?? "搜索",
  7486. itemLayout: p?.itemLayout ?? "simple",
  7487. itemAction: p?.itemAction ?? true, // 功能说明:面板可配置是否显示 hover 操作按钮(之前未透传导致总显示) by xu 20260114
  7488. collapsible: true, // 功能说明:双击 header 可折叠/展开 by xu 20260116
  7489. collapsed: !!this.sectionCollapsed?.[idx], // 功能说明:折叠态仅展示 header by xu 20260116
  7490. onToggleCollapse: () =>
  7491. this.toggleSectionCollapse?.(idx), // 功能说明:折叠事件回调 by xu 20260116
  7492. iconClass: p?.iconClass ?? "",
  7493. items: p?.items || [],
  7494. mode: p?.mode || "search",
  7495. onSelect: (item) => this.$emit("select", item),
  7496. onRemove: (item) => this.$emit("remove", item),
  7497. // closable = 清空分区数据 by xu 20260106
  7498. onClear: () => p?.onClear?.(),
  7499. onSearch: (payload) => p?.onSearch?.(payload),
  7500. });
  7501. const section = Vue.h(
  7502. "div",
  7503. {
  7504. class: {
  7505. "ss-sidebar-section": true,
  7506. "is-collapsed": !!this.sectionCollapsed?.[idx],
  7507. }, // 功能说明:折叠态加 class,配合 CSS 裁剪溢出(否则高度变了内容仍 overflow visible) by xu 20260116
  7508. key: `ss-sidebar-section-${idx}-${p?.type ?? "list"}-${
  7509. p?.title ?? ""
  7510. }`, // 功能说明:加 key 保证 section 节点稳定更新 by xu 20260116
  7511. style: {
  7512. height: (this.sectionHeights[idx] ?? 190) + "px",
  7513. flex: "0 0 auto",
  7514. }, // 功能说明:禁止 flex shrink,避免折叠/展开后 header 高度被挤压 by xu 20260116
  7515. },
  7516. [
  7517. Vue.h("div", { class: "ss-sidebar-section__content" }, [
  7518. panelContent,
  7519. ]),
  7520. ]
  7521. );
  7522. const gap =
  7523. idx < sectionPanels.length - 1
  7524. ? Vue.h("div", {
  7525. class: "ss-sidebar-gap",
  7526. onPointerdown: (e) => this.startResize(idx, e),
  7527. })
  7528. : null;
  7529. return gap ? [section, gap] : [section];
  7530. })
  7531. ),
  7532. // 图表区固定在底部(hover 弹出大图) by xu 20260106
  7533. ...chartPanels.map((p, chartIdx) =>
  7534. Vue.h(
  7535. "div",
  7536. {
  7537. class: {
  7538. "ss-sidebar-panel": true,
  7539. "ss-sidebar-chart-panel": true,
  7540. "is-collapsed": !!this.chartCollapsed?.[chartIdx],
  7541. }, // 功能说明:图表折叠态加 class,DOM 兜底隐藏内容 by xu 20260116
  7542. style: { flex: "0 0 auto", minHeight: "37px" }, // 功能说明:禁止 flex shrink + 折叠态最小高度兜底,避免 header 被压扁 by xu 20260116
  7543. "data-chart-idx": chartIdx, // 功能说明:便于 toggleChartCollapse nextTick 精确定位 DOM by xu 20260116
  7544. key: `ss-sidebar-chart-${chartIdx}-${p?.title ?? ""}`, // 功能说明:加 key 防止多图表时实例复用 by xu 20260116
  7545. },
  7546. [
  7547. p?.title
  7548. ? Vue.h(
  7549. "div",
  7550. {
  7551. class: "ss-sidebar-panel__header",
  7552. // 功能说明:折叠触发绑定到整个 header(仅 dblclick,避免双击触发两次) by xu 20260116
  7553. onDblclick: (e) => {
  7554. e?.preventDefault?.();
  7555. e?.stopPropagation?.();
  7556. console.log("[SsSidebar] chart header dblclick", {
  7557. idx: chartIdx,
  7558. title: p?.title,
  7559. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7560. this.toggleChartCollapse?.(chartIdx);
  7561. },
  7562. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  7563. },
  7564. [
  7565. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7566. p?.iconClass
  7567. ? Vue.h(SsIcon, {
  7568. class:
  7569. p.iconClass + " ss-sidebar-panel__icon",
  7570. })
  7571. : p?.icon
  7572. ? Vue.h(SsIcon, {
  7573. name: p.icon,
  7574. size: "16px",
  7575. class: "ss-sidebar-panel__icon",
  7576. })
  7577. : null,
  7578. Vue.h("span", null, p.title),
  7579. ]),
  7580. Vue.h("div", { class: "ss-sidebar-panel__tools" }),
  7581. ]
  7582. )
  7583. : null,
  7584. // hover 大图也展示与 header 一致的图标/标题 by xu 20260108
  7585. this.chartCollapsed?.[chartIdx]
  7586. ? null
  7587. : Vue.h(Vue.resolveComponent("ss-sidebar-chart-hover"), {
  7588. title: p?.title ?? "",
  7589. iconClass: p?.iconClass ?? "",
  7590. icon: p?.icon ?? "",
  7591. options: p?.options || {},
  7592. height: p?.height || "240px",
  7593. }),
  7594. ]
  7595. )
  7596. ),
  7597. // 功能说明:统计表(report-table)放在统计图下面,统一走 ss-sidebar-report-table 渲染 by xu 20260115
  7598. ...reportPanels.map((p, reportIdx) =>
  7599. // 功能说明:report-table 顶部也需要折叠态 class/定位属性,DOM 兜底隐藏内容 by xu 20260116
  7600. Vue.h(
  7601. "div",
  7602. {
  7603. class: {
  7604. "ss-sidebar-report-panel-wrap": true,
  7605. "ss-sidebar-report-panel": true,
  7606. "is-collapsed": !!this.reportCollapsed?.[reportIdx],
  7607. }, // 功能说明:报表折叠态加 class,DOM 兜底隐藏内容 by xu 20260116
  7608. style: { flex: "0 0 auto", minHeight: "37px" }, // 功能说明:禁止 flex shrink + 折叠态最小高度兜底,避免 header 被压扁 by xu 20260116
  7609. "data-report-idx": reportIdx, // 功能说明:便于 toggleReportCollapse nextTick 精确定位 DOM by xu 20260116
  7610. key: `ss-sidebar-report-wrap-${reportIdx}-${p?.title ?? ""}`, // 功能说明:加 key 防止多面板时实例复用导致折叠态不更新 by xu 20260116
  7611. },
  7612. [
  7613. // 功能说明:ss-sidebar-report-table 自带 ss-sidebar-panel 外壳,这里不重复包裹 by xu 20260115
  7614. Vue.h(SsSidebarReportTableComp, {
  7615. key: `ss-sidebar-report-${reportIdx}-${p?.title ?? ""}`, // 功能说明:加 key 防止多面板时实例复用导致折叠态不更新 by xu 20260116
  7616. title: p?.title ?? "",
  7617. icon: p?.icon ?? "",
  7618. iconClass: p?.iconClass ?? "",
  7619. items: p?.items || [],
  7620. collapsible: true, // 功能说明:允许双击 header 折叠/展开 by xu 20260116
  7621. collapsed: !!this.reportCollapsed?.[reportIdx], // 功能说明:折叠态隐藏表格 by xu 20260116
  7622. onToggleCollapse: () =>
  7623. this.toggleReportCollapse?.(reportIdx), // 功能说明:报表折叠事件回调 by xu 20260116
  7624. onOpen: (srv, ctx) => p?.onOpen?.(srv, ctx),
  7625. }),
  7626. ]
  7627. )
  7628. ),
  7629. ].filter(Boolean)
  7630. ),
  7631. ]);
  7632. },
  7633. };
  7634. // ss-folder-card 文件夹卡片
  7635. const SsFolderCard = {
  7636. name: "SsFolderCard",
  7637. props: {
  7638. item: {
  7639. type: Object,
  7640. required: true,
  7641. },
  7642. },
  7643. data() {
  7644. return {
  7645. showButtons: false,
  7646. };
  7647. },
  7648. emits: ["click", "change"],
  7649. setup(props, { emit }) {
  7650. const item = props.item;
  7651. const showChildren = ref(false);
  7652. const eventBus = window.parent.sharedEventBus;
  7653. const itemWidth = Vue.computed(() => {
  7654. // 功能说明:页面改为 grid 等分布局后,卡片宽度交给容器控制,这里固定 100% by xu 20260116
  7655. return "100%";
  7656. });
  7657. onMounted(() => {
  7658. eventBus.subscribe("folderPath", (path) => {
  7659. const currentPath = path || [];
  7660. // 如果当前文件夹不在路径中,则销毁视图
  7661. if (
  7662. !currentPath.some((item) => item.folder.title === props.item.title)
  7663. ) {
  7664. showChildren.value = false;
  7665. }
  7666. });
  7667. });
  7668. const onItemClick = (e) => {
  7669. if (e && e.stopPropagation) {
  7670. e.stopPropagation();
  7671. }
  7672. // 单击只处理 active 状态
  7673. if (e && e.currentTarget) {
  7674. const allListCards = document.querySelectorAll(
  7675. ".knowledge-item-container"
  7676. );
  7677. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  7678. allListCards.forEach((card) => card.classList.remove("active"));
  7679. allFolderCards.forEach((card) => card.classList.remove("active"));
  7680. e.currentTarget.classList.add("active");
  7681. } else {
  7682. // 如果是数据对象,需要找到对应的 DOM 元素
  7683. const allListCards = document.querySelectorAll(
  7684. ".knowledge-item-container"
  7685. );
  7686. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  7687. allListCards.forEach((card) => card.classList.remove("active"));
  7688. allFolderCards.forEach((card) => card.classList.remove("active"));
  7689. // 找到标题匹配的文件夹元素
  7690. const targetFolder = Array.from(allFolderCards).find((card) =>
  7691. card.textContent.includes(e.title)
  7692. );
  7693. if (targetFolder) {
  7694. targetFolder.classList.add("active");
  7695. }
  7696. }
  7697. emit("click", item);
  7698. };
  7699. // 修改双击处理函数
  7700. const handleFolderDblClick = (folder, e) => {
  7701. if (e) e.stopPropagation();
  7702. if (folder.children?.length) {
  7703. showChildren.value = true;
  7704. const pathInfo = {
  7705. title: folder.title,
  7706. folder: folder,
  7707. };
  7708. const currentPath = eventBus.getState("folderPath") || [];
  7709. if (!currentPath.some((item) => item.title === folder.title)) {
  7710. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  7711. }
  7712. }
  7713. };
  7714. const onItemChange = (e, icon, index) => {
  7715. e.stopPropagation();
  7716. props.item.buttons[0].onclick();
  7717. // emit("change", { item: props.item, icon, index });
  7718. };
  7719. return {
  7720. item,
  7721. itemWidth,
  7722. showChildren,
  7723. onItemClick,
  7724. onItemChange,
  7725. handleFolderDblClick,
  7726. };
  7727. },
  7728. render() {
  7729. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  7730. if (this.showChildren) {
  7731. return h(SsFolderCartView, {
  7732. folder: this.item,
  7733. });
  7734. }
  7735. return Vue.h(
  7736. "div",
  7737. {
  7738. class: { "ss-folder-list": true, active: this.item.active },
  7739. onClick: (e) => {
  7740. e.stopPropagation();
  7741. this.onItemClick(e);
  7742. },
  7743. onDblclick: (e) => this.handleFolderDblClick(this.item, e),
  7744. style: { width: this.itemWidth },
  7745. },
  7746. [
  7747. // 文件夹特有的装饰元素
  7748. Vue.h("div", { class: "ss-folder-list-trapezoid" }),
  7749. Vue.h("div", { class: "ss-folder-list-top-transparent" }),
  7750. Vue.h("div", { class: "ss-folder-list-top" }),
  7751. Vue.h("div", { class: "ss-folder-list-right" }),
  7752. // header 部分(按钮)
  7753. this.item?.buttons?.length > 0 &&
  7754. Vue.h(
  7755. "div",
  7756. {
  7757. class: "header",
  7758. onMouseenter: () => (this.showButtons = true),
  7759. onMouseleave: () => (this.showButtons = false),
  7760. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  7761. },
  7762. [
  7763. // this.item?.buttons?.length > 0 &&
  7764. Vue.h("div", {
  7765. class: "cart-list-setting cart-list-icon",
  7766. title: this.item?.buttons?.[0]?.title,
  7767. }),
  7768. // this.item?.buttons?.length > 0 &&
  7769. this.showButtons &&
  7770. this.item?.buttons?.length > 1 &&
  7771. Vue.h(
  7772. "div",
  7773. {
  7774. class: "cart-list-button-popup",
  7775. },
  7776. this.item.buttons.map((btn) =>
  7777. Vue.h(
  7778. "div",
  7779. {
  7780. onClick: (e) => {
  7781. e.stopPropagation();
  7782. btn.onclick?.();
  7783. },
  7784. },
  7785. [
  7786. btn.class &&
  7787. Vue.h(SsCartListIcon, {
  7788. class: [btn.class],
  7789. }),
  7790. Vue.h("span", null, btn.title),
  7791. ]
  7792. )
  7793. )
  7794. ),
  7795. ]
  7796. ),
  7797. // body 部分
  7798. Vue.h("div", { class: "body" }, [
  7799. Vue.h("div", { class: "box-header" }, [
  7800. Vue.h("div", null, this.item.title),
  7801. ]),
  7802. Vue.h(
  7803. "div",
  7804. {
  7805. class: !this.item.thumb ? "no-thumb box-body" : "box-body",
  7806. },
  7807. [
  7808. this.item.thumb
  7809. ? Vue.h("div", { class: "left" }, [
  7810. Vue.h("img", {
  7811. src: this.item.thumb,
  7812. alt: "Thumbnail",
  7813. class: "imgUnHandle",
  7814. style: {
  7815. "object-fit": "cover",
  7816. width: "100%",
  7817. height: "100%",
  7818. },
  7819. }),
  7820. ])
  7821. : null,
  7822. Vue.h("div", { class: "right" }, [
  7823. ...this.item.tags.map((tag) => {
  7824. const [key, value] = Object.entries(tag)[0];
  7825. return Vue.h(
  7826. "div",
  7827. {
  7828. class: "title",
  7829. title: `${key}: ${value}`,
  7830. },
  7831. `${key}: ${value}`
  7832. );
  7833. }),
  7834. ]),
  7835. ]
  7836. ),
  7837. ]),
  7838. ]
  7839. );
  7840. },
  7841. };
  7842. // SsFolderCartView 组件 - 用于显示文件夹内容
  7843. const SsFolderCartView = {
  7844. name: "SsFolderCartView",
  7845. props: {
  7846. folder: {
  7847. type: Object,
  7848. required: true,
  7849. },
  7850. },
  7851. emits: ["click"],
  7852. setup(props, { emit }) {
  7853. const eventBus = window.parent.sharedEventBus;
  7854. const currentFolder = ref(props.folder);
  7855. const showChildren = ref(false);
  7856. const onItemClick = (e) => {
  7857. if (e && e.stopPropagation) {
  7858. e.stopPropagation();
  7859. }
  7860. // 单击只处理 active 状态
  7861. if (e && e.currentTarget) {
  7862. const allListCards = document.querySelectorAll(
  7863. ".knowledge-item-container"
  7864. );
  7865. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  7866. allListCards.forEach((card) => card.classList.remove("active"));
  7867. allFolderCards.forEach((card) => card.classList.remove("active"));
  7868. e.currentTarget.classList.add("active");
  7869. } else {
  7870. // 如果是数据对象,需要找到对应的 DOM 元素
  7871. const allListCards = document.querySelectorAll(
  7872. ".knowledge-item-container"
  7873. );
  7874. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  7875. allListCards.forEach((card) => card.classList.remove("active"));
  7876. allFolderCards.forEach((card) => card.classList.remove("active"));
  7877. // 找到标题匹配的文件夹元素
  7878. const targetFolder = Array.from(allFolderCards).find((card) =>
  7879. card.textContent.includes(e.title)
  7880. );
  7881. if (targetFolder) {
  7882. targetFolder.classList.add("active");
  7883. }
  7884. }
  7885. emit("click", props.folder);
  7886. };
  7887. const handleFolderDblClick = (folder, e) => {
  7888. if (e) e.stopPropagation();
  7889. if (folder.children?.length) {
  7890. showChildren.value = true;
  7891. const pathInfo = {
  7892. title: folder.title,
  7893. folder: folder,
  7894. };
  7895. const currentPath = eventBus.getState("folderPath") || [];
  7896. if (!currentPath.some((item) => item.title === folder.title)) {
  7897. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  7898. currentFolder.value = folder;
  7899. }
  7900. }
  7901. };
  7902. const goBack = (targetFolder) => {
  7903. if (targetFolder === null) {
  7904. // 返回根目录
  7905. eventBus.publish("folderPath", []);
  7906. } else {
  7907. currentFolder.value = targetFolder;
  7908. }
  7909. };
  7910. return {
  7911. currentFolder,
  7912. showChildren,
  7913. onItemClick,
  7914. handleFolderDblClick,
  7915. goBack,
  7916. };
  7917. },
  7918. render() {
  7919. return h(
  7920. "div",
  7921. {
  7922. class: "page-container",
  7923. style: {
  7924. position: "fixed",
  7925. top: 0,
  7926. left: 0,
  7927. width: "100%",
  7928. height: "100%",
  7929. background: "var(--lightgray)",
  7930. padding: "20px 0",
  7931. zIndex: 1000,
  7932. },
  7933. },
  7934. [
  7935. // 搜索栏
  7936. h("div", { class: "search-bar" }, [
  7937. h("div", { class: "search-bar-contaienr" }, [
  7938. h(SsBreadcrumb, {
  7939. level: {
  7940. onBack: this.goBack,
  7941. },
  7942. }),
  7943. ]),
  7944. ]),
  7945. // 内容区域
  7946. h(
  7947. "div",
  7948. {
  7949. class: "content-area item-content-area",
  7950. style: { gap: "20px" },
  7951. },
  7952. [
  7953. ...(this.currentFolder.children || []).map((child, index) =>
  7954. h(child.children ? SsFolderCard : SsListCard, {
  7955. key: index,
  7956. item: child,
  7957. onClick: (e) => this.onItemClick(e),
  7958. onDblclick: (e) => this.handleFolderDblClick(child, e),
  7959. })
  7960. ),
  7961. ]
  7962. ),
  7963. ]
  7964. );
  7965. },
  7966. };
  7967. // ss-page分页
  7968. const SsPage = {
  7969. name: "SsPage",
  7970. props: {
  7971. total: {
  7972. type: Number,
  7973. required: true,
  7974. },
  7975. size: {
  7976. type: Number,
  7977. default: 10,
  7978. },
  7979. page: {
  7980. type: Number,
  7981. default: 1,
  7982. },
  7983. onChange: {
  7984. type: Function,
  7985. default: () => {},
  7986. },
  7987. },
  7988. setup(props) {
  7989. const totalItems = ref(props.total); // 总条目数
  7990. const totalPages = ref(Math.ceil(props.total / props.size));
  7991. const currentPage = ref(props.page); // 当前页码
  7992. // 计算显示的信息
  7993. const pageInfo = ref(
  7994. `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`
  7995. );
  7996. // 上一页的逻辑
  7997. const goToPreviousPage = (e) => {
  7998. e.preventDefault(); // 阻止默认行为
  7999. if (currentPage.value > 1) {
  8000. currentPage.value -= 1;
  8001. updatePageInfo();
  8002. props.onChange?.({
  8003. pageNo: currentPage.value, // 当前页码
  8004. rowNumPer: props.size, // 每页条数
  8005. rowNum: props.total, // 总记录数
  8006. });
  8007. }
  8008. };
  8009. // 下一页的逻辑
  8010. const goToNextPage = (e) => {
  8011. e.preventDefault(); // 阻止默认行为
  8012. if (currentPage.value < totalPages.value) {
  8013. currentPage.value += 1;
  8014. updatePageInfo();
  8015. props.onChange?.({
  8016. pageNo: currentPage.value, // 当前页码
  8017. rowNumPer: props.size, // 每页条数
  8018. rowNum: props.total, // 总记录数
  8019. });
  8020. }
  8021. };
  8022. // 更新页码信息的函数
  8023. const updatePageInfo = () => {
  8024. pageInfo.value = `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`;
  8025. };
  8026. return {
  8027. pageInfo,
  8028. totalPages,
  8029. goToPreviousPage,
  8030. goToNextPage,
  8031. };
  8032. },
  8033. render(props, { slots, emit }) {
  8034. return Vue.h("div", { class: "pager-container" }, [
  8035. Vue.h("input", { type: "hidden", name: "rowNum", value: props.total }),
  8036. Vue.h("input", {
  8037. type: "hidden",
  8038. name: "rowNumPer",
  8039. value: props.size,
  8040. }),
  8041. Vue.h("input", {
  8042. type: "hidden",
  8043. name: "pageCount",
  8044. value: this.totalPages,
  8045. }),
  8046. Vue.h("input", { type: "hidden", name: "pageNo", value: props.page }),
  8047. Vue.h("div", { class: "pager-content" }, [
  8048. Vue.h("div", { class: "info" }, this.pageInfo),
  8049. Vue.h(
  8050. "div",
  8051. { class: "btn" },
  8052. Vue.h(
  8053. "button",
  8054. { onClick: (e) => this.goToPreviousPage(e) },
  8055. "上一页"
  8056. )
  8057. ),
  8058. Vue.h(
  8059. "div",
  8060. { class: "btn" },
  8061. Vue.h("button", { onClick: (e) => this.goToNextPage(e) }, "下一页")
  8062. ),
  8063. ]),
  8064. ]);
  8065. },
  8066. };
  8067. // ss-right-info 一级页面右边栏
  8068. const SSRightInfo = {
  8069. name: "SSRightInfo",
  8070. setup() {
  8071. // 初始化响应式数据
  8072. const item = ref({
  8073. thumb: "images/example/project-img.png", // 更换为适合你项目的实际路径
  8074. title: "工业和信息化产业高质量发展资金",
  8075. });
  8076. return {
  8077. item,
  8078. };
  8079. },
  8080. render() {
  8081. return Vue.h("div", { class: "info-container" }, [
  8082. Vue.h("div", { class: "header" }, [
  8083. Vue.h("div", [
  8084. Vue.h("img", {
  8085. src: this.item.thumb,
  8086. class: "imgUnHandle",
  8087. style: { "object-fit": "cover", width: "100%", height: "100%" },
  8088. }), // 将 ImageViewer 替换为 img 标签
  8089. ]),
  8090. Vue.h("div", [Vue.h("div", this.item.title)]),
  8091. ]),
  8092. Vue.h("div", { class: "section-container" }, [
  8093. Vue.h("div", { class: "section" }, [
  8094. Vue.h("div", { class: "title" }, "合同"),
  8095. Vue.h("div", { class: "text" }, "合同总金额:42,399,320"),
  8096. Vue.h(
  8097. "div",
  8098. { class: "a" },
  8099. "《工业和信息化产业高质量发展资金补助合同》"
  8100. ),
  8101. ]),
  8102. Vue.h("div", { class: "section" }, [
  8103. Vue.h("div", { class: "title" }, "发票"),
  8104. Vue.h("div", { class: "text" }, "应开发票总额:42,399,320"),
  8105. Vue.h("div", { class: "text" }, "已开发票金额:17,235,345"),
  8106. Vue.h("div", { class: "text" }, "未开发票金额:25,163,975"),
  8107. ]),
  8108. Vue.h("div", { class: "section" }, [
  8109. Vue.h("div", { class: "title" }, "项目组成员"),
  8110. Vue.h("div", { class: "text" }, "我司:3人"),
  8111. Vue.h("div", { class: "text" }, "对方:2人"),
  8112. Vue.h("div", { class: "text" }, "项目负责人:张三"),
  8113. ]),
  8114. Vue.h("div", { class: "section" }, [
  8115. Vue.h("div", { class: "title" }, "采购"),
  8116. Vue.h("div", { class: "text" }, "总额:999,320"),
  8117. Vue.h("div", { class: "text" }, "已付金额:335,345"),
  8118. Vue.h("div", { class: "text" }, "未付金额:663,975"),
  8119. ]),
  8120. ]),
  8121. ]);
  8122. },
  8123. };
  8124. //
  8125. const SsSuccessPopup = {
  8126. name: "SsSuccessPopup",
  8127. props: {
  8128. right: {
  8129. type: String,
  8130. default: "20px",
  8131. },
  8132. bottom: {
  8133. type: String,
  8134. default: "calc(100% + 5px)",
  8135. },
  8136. },
  8137. setup(props, { expose }) {
  8138. // 响应式状态:是否可见
  8139. const visible = ref(false);
  8140. // 计算样式
  8141. const style = computed(() => {
  8142. return {
  8143. "--message-dialog-right": props.right,
  8144. "--message-dialog-bottom": props.bottom,
  8145. };
  8146. });
  8147. // 显示对话框的方法
  8148. const show = () => {
  8149. visible.value = true;
  8150. };
  8151. // 隐藏对话框的方法
  8152. const hide = () => {
  8153. visible.value = false;
  8154. };
  8155. // 将方法暴露给外部使用
  8156. expose({ show, hide });
  8157. // 返回渲染函数
  8158. return () => {
  8159. if (!visible.value) return null;
  8160. const SsIcon = resolveComponent("ss-icon");
  8161. return h(
  8162. "div",
  8163. {
  8164. class: "success-popup",
  8165. style: style.value,
  8166. onClick: (e) => e.stopPropagation(),
  8167. },
  8168. [
  8169. h("div", { class: "left" }, [
  8170. h("div", { class: "icon" }, [
  8171. h(SsIcon, { name: "check", size: "36px" }),
  8172. ]),
  8173. ]),
  8174. h("div", { class: "right" }, [
  8175. h("div", { class: "title" }, "提交成功"),
  8176. h("div", { class: "desc" }, "您的信息已成功提交。"),
  8177. ]),
  8178. ]
  8179. );
  8180. };
  8181. },
  8182. };
  8183. const SsErrorDialog = {
  8184. name: "SsErrorDialog",
  8185. setup(props, { emit }) {
  8186. const visible = ref(false);
  8187. const style = computed(() => {
  8188. return {};
  8189. });
  8190. const show = () => {
  8191. visible.value = true;
  8192. };
  8193. const hide = () => {
  8194. visible.value = false;
  8195. };
  8196. const onBack = () => {
  8197. emit("back");
  8198. hide();
  8199. };
  8200. return {
  8201. visible,
  8202. style,
  8203. show,
  8204. hide,
  8205. onBack,
  8206. };
  8207. },
  8208. render() {
  8209. const SsIcon = resolveComponent("ss-icon");
  8210. return this.visible
  8211. ? h(
  8212. "div",
  8213. {
  8214. class: "errorDialog",
  8215. style: this.style,
  8216. onClick: (event) => event.stopPropagation(),
  8217. },
  8218. [
  8219. h("div", { class: "body" }, [
  8220. h("div", { class: "left" }, [
  8221. h("div", { class: "icon" }, [
  8222. h(SsIcon, { name: "close", size: "36px" }),
  8223. ]),
  8224. ]),
  8225. h("div", { class: "right" }, [
  8226. h("div", { class: "title" }, "操作失败"),
  8227. h("div", { class: "desc" }, "请点击返回以继续。"),
  8228. ]),
  8229. ]),
  8230. h("div", { class: "footer" }, [
  8231. h("div", { class: "left" }),
  8232. h("div", { class: "right" }, [
  8233. h(
  8234. "div",
  8235. {
  8236. class: "btn",
  8237. onClick: this.onBack,
  8238. },
  8239. [h(SsIcon, { name: "arrow-left-line" }), h("div", "返回")]
  8240. ),
  8241. ]),
  8242. ]),
  8243. ]
  8244. )
  8245. : null;
  8246. },
  8247. };
  8248. /**
  8249. * 审核链条
  8250. * @name ss-verify
  8251. * @param { Array } verify-list 审核节点列表
  8252. * @property { Array } verify-list 审核节点列表
  8253. * @example <ss-verify :verify-list="verifyList"></ss-verify>
  8254. * verify-list [
  8255. * {
  8256. * groupName: "", // 群组名称
  8257. * open: true, // 默认是否展开
  8258. * children:[ //群组里的人员
  8259. * {
  8260. * thumb: "images/example/user-4.png", // 头像
  8261. * name: "李丽思 ", // 姓名
  8262. * role: "人事处处长", // 角色
  8263. * description: "同意。", // 审核意见
  8264. * time: "09:38 08/11", // 审核时间
  8265. * video: false, // false不显示/true显示 视频icon
  8266. * link: false, // false不显示/true显示 链接icon 后续应该是附件
  8267. * }
  8268. * ]
  8269. * }
  8270. * ]
  8271. */
  8272. const SsVerify = {
  8273. name: "SsVerify",
  8274. props: {
  8275. verifyList: {
  8276. type: Array,
  8277. required: true,
  8278. },
  8279. },
  8280. setup(props) {
  8281. const toggleOpen = (item) => {
  8282. item.open = !item.open;
  8283. };
  8284. onMounted(() => {
  8285. setTimeout(() => {
  8286. const lastOpenGroup = document.querySelector(".group-item-last-open");
  8287. console.log("lastOpenGroup", lastOpenGroup);
  8288. if (lastOpenGroup) {
  8289. const nodes = $(lastOpenGroup).find(".verify-node-container");
  8290. if (nodes.length) {
  8291. let totalHeight = 0;
  8292. const gudingHeight = 100;
  8293. if (nodes.length === 1) {
  8294. totalHeight = gudingHeight;
  8295. } else {
  8296. // 累加除最后一个节点外的所有节点高度
  8297. for (let i = 0; i < nodes.length - 1; i++) {
  8298. totalHeight += $(nodes[i]).outerHeight();
  8299. }
  8300. totalHeight += gudingHeight;
  8301. }
  8302. console.log("节点信息:", {
  8303. 节点总数: nodes.length,
  8304. 计算后的高度: totalHeight,
  8305. });
  8306. lastOpenGroup.style.setProperty(
  8307. "--group-line-height",
  8308. `${totalHeight}px`
  8309. );
  8310. }
  8311. }
  8312. }, 0);
  8313. });
  8314. return {
  8315. toggleOpen,
  8316. };
  8317. },
  8318. render() {
  8319. const SsIcon = resolveComponent("ss-icon");
  8320. const SsCommonIcon = resolveComponent("ss-common-icon");
  8321. const SsVerifyNode = resolveComponent("ss-verify-node");
  8322. return h(
  8323. "div",
  8324. { class: "verify-nodes" },
  8325. this.verifyList.map((item, i) =>
  8326. h(
  8327. "div",
  8328. {
  8329. key: i,
  8330. class: {
  8331. "group-item": true,
  8332. "group-item-last-open":
  8333. i === this.verifyList.length - 1 && item.open,
  8334. },
  8335. },
  8336. [
  8337. h(
  8338. "div",
  8339. {
  8340. class: "group-item-title",
  8341. onClick: () => this.toggleOpen(item),
  8342. },
  8343. [
  8344. h("div", { class: "icon" }, [
  8345. item.open
  8346. ? h(SsCommonIcon, { class: "common-icon-folder-open" })
  8347. : h(SsCommonIcon, { class: "common-icon-folder-close" }),
  8348. h(
  8349. "div",
  8350. {
  8351. class: "num",
  8352. style: { top: item.open ? "60%" : "55%" },
  8353. },
  8354. item.children?.length || 0
  8355. ),
  8356. ]),
  8357. h("div", { class: "name" }, item.groupName),
  8358. ]
  8359. ),
  8360. item.open && item.children?.length > 0
  8361. ? h(
  8362. "div",
  8363. { class: "group-item-children" },
  8364. item.children.map((citem, j) =>
  8365. h(SsVerifyNode, {
  8366. key: j,
  8367. item: citem,
  8368. // isGroup: i + 1 !== this.verifyList.length,
  8369. isGroup: true,
  8370. })
  8371. )
  8372. )
  8373. : null,
  8374. ]
  8375. )
  8376. )
  8377. );
  8378. },
  8379. };
  8380. /**
  8381. * 审核页面的审核节点
  8382. * @name ss-verify-node
  8383. * @param {Object} item 审核节点信息
  8384. * @param {Boolean} isGroup 是否为分组节点
  8385. */
  8386. const SsVerifyNode = {
  8387. name: "SsVerifyNode",
  8388. props: {
  8389. item: {
  8390. type: Object,
  8391. required: true,
  8392. },
  8393. isGroup: {
  8394. type: Boolean,
  8395. default: false,
  8396. },
  8397. },
  8398. render() {
  8399. const SsIcon = resolveComponent("ss-icon");
  8400. const SsCommonIcon = resolveComponent("ss-common-icon");
  8401. return Vue.h("div", { class: "verify-node-container" }, [
  8402. Vue.h("div", { class: "info" }, [
  8403. Vue.h("div", { class: "avatar" }, [
  8404. Vue.h("img", {
  8405. src: this.item.thumb,
  8406. style: {
  8407. width: "50px",
  8408. height: "50px",
  8409. borderRadius: "50%",
  8410. },
  8411. }),
  8412. ]),
  8413. Vue.h("div", { class: "desc" }, [
  8414. Vue.h("div", this.item.name),
  8415. Vue.h("div", this.item.role),
  8416. ]),
  8417. Vue.h("div", { class: "link" }, [
  8418. Vue.h("div", [
  8419. this.item.video
  8420. ? Vue.h(SsCommonIcon, { class: "common-icon-video" })
  8421. : null,
  8422. this.item.link
  8423. ? Vue.h(SsCommonIcon, {
  8424. class: "common-icon-paper-clip",
  8425. })
  8426. : null,
  8427. ]),
  8428. ]),
  8429. ]),
  8430. Vue.h(
  8431. "div",
  8432. {
  8433. class: {
  8434. description: true,
  8435. link: this.isGroup,
  8436. },
  8437. attrs: { "data-num": "3" },
  8438. },
  8439. [Vue.h("div", this.item.description)]
  8440. ),
  8441. Vue.h("div", { class: "time" }, this.item.time),
  8442. ]);
  8443. },
  8444. };
  8445. /**
  8446. * 智能识别图片的左侧图片播放 可以放大缩小旋转图片
  8447. * @name ss-orc-img-box
  8448. * @param { Object } image-obj 包含图片的url, 和图片的名称
  8449. *
  8450. */
  8451. const SsOrcImgBox = {
  8452. name: "SsOrcImgBox",
  8453. props: {
  8454. imageObj: {
  8455. type: Object,
  8456. required: true,
  8457. },
  8458. },
  8459. setup(props) {
  8460. const zoom = ref(1);
  8461. const rotation = ref(0);
  8462. const containerWidth = ref(0);
  8463. const containerHeight = ref(0);
  8464. const container = ref(null);
  8465. const imgPosition = ref({ x: 0, y: 0 });
  8466. const isDragging = ref(false);
  8467. const lastMousePosition = ref({ x: 0, y: 0 });
  8468. const imgStyle = computed(() => ({
  8469. width: `${zoom.value * 100}%`,
  8470. height: `${zoom.value * 100}%`,
  8471. transform: `rotate(${rotation.value}deg) translate(${imgPosition.value.x}px, ${imgPosition.value.y}px)`,
  8472. transformOrigin: "center center",
  8473. cursor: isDragging.value ? "grabbing" : "grab",
  8474. }));
  8475. const resetZoom = () => {
  8476. zoom.value = 1;
  8477. rotation.value = rotation.value + 90;
  8478. imgPosition.value = { x: 0, y: 0 };
  8479. };
  8480. const handleRangeChange = (event) => {
  8481. const value = event.target.value / 50; // 0 到 100 映射到 0 到 2 的缩放
  8482. zoom.value = Math.max(value, 0.1); // 设置最小缩放值为 0.1
  8483. };
  8484. const updateImgBoxDimensions = () => {
  8485. if (container.value) {
  8486. containerWidth.value = container.value.clientWidth;
  8487. containerHeight.value = container.value.clientHeight;
  8488. }
  8489. };
  8490. const onMouseDown = (event) => {
  8491. isDragging.value = true;
  8492. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  8493. };
  8494. const onMouseMove = (event) => {
  8495. if (isDragging.value) {
  8496. const dx = event.clientX - lastMousePosition.value.x;
  8497. const dy = event.clientY - lastMousePosition.value.y;
  8498. // 防止旋转后拖动的x,y反转
  8499. // 首先将当前旋转角度从度数转换为弧度,因为 JavaScript 的 Math 库使用弧度
  8500. const angle = rotation.value * (Math.PI / 180);
  8501. // 使用基本的二维旋转矩阵将原始位移 dx 和 dy 转换为旋转后的位移 rotatedDx 和 rotatedDy。
  8502. const rotatedDx = dx * Math.cos(angle) + dy * Math.sin(angle);
  8503. const rotatedDy = dy * Math.cos(angle) - dx * Math.sin(angle);
  8504. imgPosition.value = {
  8505. x: imgPosition.value.x + rotatedDx,
  8506. y: imgPosition.value.y + rotatedDy,
  8507. };
  8508. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  8509. }
  8510. };
  8511. const onMouseUp = () => {
  8512. isDragging.value = false;
  8513. };
  8514. onMounted(() => {
  8515. nextTick(() => {
  8516. updateImgBoxDimensions();
  8517. window.addEventListener("resize", updateImgBoxDimensions);
  8518. window.addEventListener("mousemove", onMouseMove);
  8519. window.addEventListener("mouseup", onMouseUp);
  8520. });
  8521. });
  8522. return {
  8523. zoom,
  8524. rotation,
  8525. container,
  8526. imgStyle,
  8527. resetZoom,
  8528. handleRangeChange,
  8529. containerWidth,
  8530. containerHeight,
  8531. onMouseDown,
  8532. imgPosition,
  8533. };
  8534. },
  8535. render() {
  8536. const SsIcon = resolveComponent("ss-icon");
  8537. return h("div", { class: "ocr-img-box" }, [
  8538. h("div", { class: "img-bar" }, [
  8539. h("div", this.imageObj.name),
  8540. h("div", { class: "action-bar" }, [
  8541. h("div", { class: "ocr-img-range-box" }, [
  8542. h("input", {
  8543. type: "range",
  8544. min: 0,
  8545. max: 100,
  8546. value: this.zoom * 50, // 初始位置为50
  8547. onInput: this.handleRangeChange,
  8548. }),
  8549. h("span", { class: "line" }),
  8550. ]),
  8551. h(SsIcon, {
  8552. name: "reset",
  8553. size: "26px",
  8554. onClick: this.resetZoom,
  8555. }),
  8556. ]),
  8557. ]),
  8558. h("div", { class: "img-viewer", ref: "container" }, [
  8559. h(
  8560. "div",
  8561. {
  8562. class: "img-box",
  8563. style: {
  8564. width: `${this.containerWidth}px`,
  8565. height: `${this.containerHeight}px`,
  8566. overflow: "hidden",
  8567. position: "relative",
  8568. },
  8569. },
  8570. [
  8571. h("img", {
  8572. src: this.imageObj.thumb,
  8573. style: this.imgStyle,
  8574. class: "zoomable-img",
  8575. onMousedown: this.onMouseDown,
  8576. }),
  8577. ]
  8578. ),
  8579. ]),
  8580. ]);
  8581. },
  8582. };
  8583. // 搜索输入框组件
  8584. const SsSearchInput = {
  8585. name: "SsSearchInput",
  8586. props: {
  8587. name: String,
  8588. placeholder: String,
  8589. width: {
  8590. type: String,
  8591. default: "100px",
  8592. },
  8593. modelValue: String,
  8594. },
  8595. emits: ["update:modelValue", "search"],
  8596. setup(props, { emit }) {
  8597. const handleInput = (e) => {
  8598. emit("update:modelValue", e.target.value);
  8599. };
  8600. const handleKeyup = (e) => {
  8601. if (e.key === "Enter") {
  8602. emit("search");
  8603. }
  8604. };
  8605. return { handleInput, handleKeyup };
  8606. },
  8607. render() {
  8608. return h(
  8609. "div",
  8610. {
  8611. class: "input",
  8612. style: this.width ? { width: this.width } : undefined,
  8613. },
  8614. [
  8615. h("input", {
  8616. name: this.name,
  8617. placeholder: this.placeholder,
  8618. value: this.modelValue,
  8619. onInput: this.handleInput,
  8620. onKeyup: this.handleKeyup,
  8621. }),
  8622. ]
  8623. );
  8624. },
  8625. };
  8626. // ss-search-date-picker 日期时间选择器组件
  8627. const SsSearchDatePicker = {
  8628. name: "SsSearchDatePicker",
  8629. props: {
  8630. modelValue: {
  8631. type: [String, Number, Date],
  8632. default: "",
  8633. },
  8634. name: {
  8635. type: String,
  8636. required: true,
  8637. },
  8638. type: {
  8639. type: String,
  8640. default: "date",
  8641. validator: (value) => ["date", "datetime", "time"].includes(value),
  8642. },
  8643. fmt: {
  8644. type: String,
  8645. default: null,
  8646. },
  8647. placeholder: {
  8648. type: String,
  8649. default: "",
  8650. },
  8651. width: {
  8652. type: String,
  8653. default: "100%",
  8654. },
  8655. },
  8656. emits: ["update:modelValue"],
  8657. setup(props, { emit }) {
  8658. const errMsg = ref("");
  8659. const validate = () => {
  8660. if (window.ssVm) {
  8661. const result = window.ssVm.validateField(props.name);
  8662. console.log("validate", window.ssVm.validateField(props.name));
  8663. errMsg.value = result.valid ? "" : result.message;
  8664. }
  8665. };
  8666. // 根据type确定默认格式
  8667. const defaultFormat = computed(() => {
  8668. switch (props.type) {
  8669. case "datetime":
  8670. return "YYYY-MM-DD HH:mm:ss";
  8671. case "date":
  8672. return "YYYY-MM-DD";
  8673. case "time":
  8674. return "HH:mm:ss";
  8675. }
  8676. });
  8677. const convertJavaFormatToElement = (javaFormat) => {
  8678. if (!javaFormat) return null;
  8679. return javaFormat
  8680. .replace("yyyy", "YYYY")
  8681. .replace("MM", "MM")
  8682. .replace("dd", "DD")
  8683. .replace("HH", "HH")
  8684. .replace("mm", "mm")
  8685. .replace("ss", "ss");
  8686. };
  8687. const finalFormat = computed(() => {
  8688. if (props.fmt) {
  8689. return convertJavaFormatToElement(props.fmt);
  8690. }
  8691. return defaultFormat.value;
  8692. });
  8693. // 使用 resolveComponent 获取组件
  8694. const ElDatePicker = resolveComponent("ElDatePicker");
  8695. const ElTimePicker = resolveComponent("ElTimePicker");
  8696. const SsFormIcon = resolveComponent("SsFormIcon");
  8697. const ElIcon = resolveComponent("ElIcon");
  8698. let useTimePicker = true;
  8699. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  8700. if (props.fmt) {
  8701. //有fmt属性,则以fmt属性优先判断类型
  8702. if (/[dMy]/.test(props.fmt)) {
  8703. //如果有传入日期格式,且含年月日
  8704. useTimePicker = false;
  8705. } else {
  8706. useTimePicker = true;
  8707. }
  8708. } else if (props.type !== "time") {
  8709. useTimePicker = false;
  8710. }
  8711. const dateType = computed(() => {
  8712. const fmt = props.fmt || "";
  8713. if (fmt.includes("HH:mm:ss")) {
  8714. return "datetime";
  8715. } else if (fmt.includes("HH:mm")) {
  8716. return "datetime";
  8717. } else if (fmt.includes("mm:ss")) {
  8718. return "time";
  8719. }
  8720. return "date";
  8721. });
  8722. const handleValueUpdate = (val) => {
  8723. emit("update:modelValue", val);
  8724. emit("change", val); // 同时触发 change 事件
  8725. setTimeout(() => {
  8726. validate();
  8727. }, 50);
  8728. };
  8729. return () =>
  8730. h(
  8731. "div",
  8732. { class: "ss-search-date-picker", style: { width: props.width } },
  8733. [
  8734. h("input", {
  8735. type: "hidden",
  8736. name: props.name,
  8737. value: props.modelValue,
  8738. }),
  8739. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  8740. modelValue: props.modelValue,
  8741. "onUpdate:modelValue": handleValueUpdate,
  8742. type: dateType.value,
  8743. format: finalFormat.value,
  8744. "value-format": finalFormat.value,
  8745. clearable: true,
  8746. placeholder: props.placeholder,
  8747. class: "custom-date-picker", // 用于自定义样式
  8748. "time-arrow-control": props.type === "datetime", // 修改这里
  8749. size: "large", // 添加这一行,改为 large 尺寸
  8750. style: { width: "100%" },
  8751. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  8752. }),
  8753. ]
  8754. );
  8755. },
  8756. };
  8757. // 搜索按钮组件(包含下拉按钮)
  8758. const SsSearchButton = {
  8759. name: "SsSearchButton",
  8760. props: {
  8761. text: {
  8762. type: String,
  8763. required: true,
  8764. },
  8765. iconClass: {
  8766. type: String,
  8767. required: false,
  8768. },
  8769. opt: {
  8770. type: Array,
  8771. default: () => [],
  8772. },
  8773. checkId: {
  8774. type: String,
  8775. default: "0",
  8776. },
  8777. width: {
  8778. //add by Ben(20251225)
  8779. type: String,
  8780. required: false,
  8781. },
  8782. id: {
  8783. //add by Ben(20251225)
  8784. type: String,
  8785. required: false,
  8786. },
  8787. },
  8788. emits: ["click"],
  8789. setup(props, { emit }) {
  8790. const currentId = ref(props.checkId || "0");
  8791. const showPopup = ref(false);
  8792. const handleMouseEnter = () => {
  8793. showPopup.value = true;
  8794. };
  8795. const handleMouseLeave = () => {
  8796. showPopup.value = false;
  8797. };
  8798. // 添加点击事件处理,阻止默认行为
  8799. const handleClick = (e) => {
  8800. e.preventDefault();
  8801. if (props.opt?.length > 0) {
  8802. const selectedOption =
  8803. currentId.value === "0"
  8804. ? props.opt[0]
  8805. : props.opt.find((opt) => opt.id === currentId.value);
  8806. if (selectedOption) {
  8807. selectedOption.callback?.();
  8808. }
  8809. } else {
  8810. emit("click", e);
  8811. }
  8812. };
  8813. // 获取显示文本
  8814. const getDisplayText = () => {
  8815. if (!props.opt?.length) return props.text;
  8816. const selectedOption =
  8817. currentId.value === "0"
  8818. ? props.opt[0]
  8819. : props.opt.find((opt) => opt.id === currentId.value);
  8820. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  8821. };
  8822. return () =>
  8823. h(
  8824. "button",
  8825. {
  8826. class:
  8827. props.opt?.length > 0
  8828. ? "ss-drop-button ss-drop-button-more"
  8829. : "ss-drop-button",
  8830. type: "button", // 明确指定按钮类型为 button
  8831. onMouseenter: handleMouseEnter,
  8832. onMouseleave: handleMouseLeave,
  8833. onClick: handleClick, // 添加点击事件处理
  8834. style: { width: props.width }, //add by Ben(20251225)
  8835. id: props.id, //add by Ben(20251225)
  8836. },
  8837. [
  8838. props.iconClass
  8839. ? h("span", {
  8840. class: props.iconClass,
  8841. style: { fontFamily: "iconfont", marginRight: "5px" },
  8842. })
  8843. : null,
  8844. h("span", getDisplayText()),
  8845. props.opt.length > 0 &&
  8846. showPopup.value &&
  8847. h(
  8848. "div",
  8849. {
  8850. class: "popup",
  8851. },
  8852. props.opt.map((item) =>
  8853. h(
  8854. "div",
  8855. {
  8856. onClick: (e) => {
  8857. e.preventDefault(); // 选项点击也阻止默认行为
  8858. e.stopPropagation(); // 阻止事件冒泡
  8859. currentId.value = item.id; // 更新当前选中的ID
  8860. item.callback();
  8861. showPopup.value = false; // 选择后关闭弹窗
  8862. },
  8863. },
  8864. item.desc
  8865. )
  8866. )
  8867. ),
  8868. ]
  8869. );
  8870. },
  8871. };
  8872. // 下拉按钮组件
  8873. const SsDropButton = {
  8874. name: "SsDropButton",
  8875. props: {
  8876. text: {
  8877. type: String,
  8878. required: true,
  8879. },
  8880. iconClass: {
  8881. type: String,
  8882. required: true,
  8883. },
  8884. opt: {
  8885. type: Array,
  8886. default: () => [],
  8887. },
  8888. checkId: {
  8889. type: String,
  8890. default: "0",
  8891. },
  8892. onclick: {
  8893. type: Function,
  8894. default: null,
  8895. },
  8896. },
  8897. setup(props) {
  8898. const currentId = ref(props.checkId || "0");
  8899. const showPopup = ref(false);
  8900. const handleMouseEnter = () => {
  8901. showPopup.value = true;
  8902. };
  8903. const handleMouseLeave = () => {
  8904. showPopup.value = false;
  8905. };
  8906. // 添加点击事件处理,阻止默认行为
  8907. const handleClick = (e) => {
  8908. e.preventDefault();
  8909. if (props.opt?.length > 0) {
  8910. const selectedOption =
  8911. currentId.value === "0"
  8912. ? props.opt[0]
  8913. : props.opt.find((opt) => opt.id === currentId.value);
  8914. if (selectedOption) {
  8915. selectedOption.callback?.();
  8916. }
  8917. } else if (props.onclick) {
  8918. props.onclick();
  8919. }
  8920. };
  8921. // 获取显示文本
  8922. const getDisplayText = () => {
  8923. if (!props.opt?.length) return props.text;
  8924. const selectedOption =
  8925. currentId.value === "0"
  8926. ? props.opt[0]
  8927. : props.opt.find((opt) => opt.id === currentId.value);
  8928. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  8929. };
  8930. return () =>
  8931. h(
  8932. "button",
  8933. {
  8934. class:
  8935. props.opt?.length > 0
  8936. ? "ss-drop-button ss-drop-button-more"
  8937. : "ss-drop-button",
  8938. type: "button", // 明确指定按钮类型为 button
  8939. onMouseenter: handleMouseEnter,
  8940. onMouseleave: handleMouseLeave,
  8941. onClick: handleClick, // 添加点击事件处理
  8942. },
  8943. [
  8944. h("span", {
  8945. class: props.iconClass,
  8946. style: { fontFamily: "iconfont" },
  8947. }),
  8948. h("span", getDisplayText()),
  8949. props.opt.length > 0 &&
  8950. showPopup.value &&
  8951. h(
  8952. "div",
  8953. {
  8954. class: "popup",
  8955. },
  8956. props.opt.map((item) =>
  8957. h(
  8958. "div",
  8959. {
  8960. onClick: (e) => {
  8961. e.preventDefault(); // 选项点击也阻止默认行为
  8962. e.stopPropagation(); // 阻止事件冒泡
  8963. currentId.value = item.id; // 更新当前选中的ID
  8964. item.callback();
  8965. showPopup.value = false; // 选择后关闭弹窗
  8966. },
  8967. },
  8968. item.desc
  8969. )
  8970. )
  8971. ),
  8972. ]
  8973. );
  8974. },
  8975. };
  8976. /**
  8977. * 二级页面标签组件
  8978. * @name ss-sub-tab
  8979. * @description 用于展示二级页面的布局组件,包含左侧垂直标签导航(支持分组)和右侧iframe内容区
  8980. * @property {String} headerImage - 左侧顶部图片地址
  8981. * @property {Array} menuList - 菜单配置列表
  8982. * @property {Object} [activeMenu] - 当前选中的菜单项,不传则自动选择第一个可选菜单
  8983. * @property {Array} footerButtons - 底部按钮配置列表
  8984. */
  8985. /**
  8986. * SsSubTab 左侧菜单+iframe内容组件
  8987. * v3.0 改造:去掉顶部图片,改为图标+悬浮模式,iframe懒加载 by xu 20251216
  8988. */
  8989. const SsSubTab = {
  8990. name: "SsSubTab",
  8991. props: {
  8992. menuList: {
  8993. type: Array,
  8994. required: true,
  8995. },
  8996. activeMenu: {
  8997. type: String,
  8998. default: "",
  8999. },
  9000. footerButtons: {
  9001. type: Array,
  9002. default: () => [],
  9003. },
  9004. leftDisplay: {
  9005. type: Boolean,
  9006. default: true,
  9007. },
  9008. // v3.0 新增:菜单模式 collapse(悬浮展开) / fixed(始终收起) by xu 20251216
  9009. initialMode: {
  9010. type: String,
  9011. default: "collapse",
  9012. },
  9013. },
  9014. emits: ["menu-change", "footer-click"],
  9015. setup(props, { emit }) {
  9016. // v3.0 新增:默认图标映射,使用icon-biz图标 by xu 20251216
  9017. const defaultIcons = [
  9018. "icon-obj-ry", // 人员
  9019. "icon-obj-dw", // 单位
  9020. "icon-obj-gw", // 岗位
  9021. "icon-biz-rc", // 人才
  9022. "icon-biz-xc", // 巡查
  9023. "icon-biz-cl", // 材料
  9024. "icon-biz-men", // 门
  9025. "icon-obj-xy", // 协议
  9026. ];
  9027. //功能: SsSubTab 支持后端下发 iconName + pobj/cobj 两级菜单 by xu 20251222
  9028. const isTrue = (v) => v === true || v === "true" || v === 1 || v === "1"; //功能 by xu 20251222
  9029. const resolveIconClass = (iconNameOrClass, fallbackIndex) => {
  9030. //功能 by xu 20251222
  9031. const fallback = `menu-icon ${
  9032. defaultIcons[fallbackIndex % defaultIcons.length]
  9033. }`;
  9034. if (!iconNameOrClass) {
  9035. return fallback;
  9036. }
  9037. // 已经是完整 class(可能包含 menu-icon / menu-base-icon / 多个 class)
  9038. if (
  9039. typeof iconNameOrClass === "string" &&
  9040. iconNameOrClass.indexOf(" ") > -1
  9041. ) {
  9042. return iconNameOrClass;
  9043. }
  9044. const iconName = iconNameOrClass;
  9045. if (iconName === "menu-icon" || iconName === "menu-base-icon") {
  9046. return fallback;
  9047. }
  9048. // 业务图标库:icon-biz / icon-obj -> menu-icon
  9049. if (
  9050. typeof iconName === "string" &&
  9051. (iconName.indexOf("icon-obj-") === 0 ||
  9052. iconName.indexOf("icon-biz-") === 0)
  9053. ) {
  9054. return `menu-icon ${iconName}`;
  9055. }
  9056. // 默认认为是 icon-base 图标 -> menu-base-icon
  9057. return `menu-base-icon ${iconName}`;
  9058. };
  9059. const getMenuIcon = (item, index) => {
  9060. //功能 by xu 20251222
  9061. if (!item) {
  9062. return resolveIconClass(null, index);
  9063. }
  9064. //功能: 变动图标后端暂不正确,前端先写死为 icon-chg by xu 20251223
  9065. if (item.title === "变动" || item.name === "sys_bd") {
  9066. return resolveIconClass("icon-chg", index);
  9067. }
  9068. // 兼容旧字段 icon(优先使用)
  9069. if (item.icon) return resolveIconClass(item.icon, index);
  9070. // v3.0 使用后端下发 iconName
  9071. if (item.iconName) return resolveIconClass(item.iconName, index);
  9072. return resolveIconClass(null, index);
  9073. };
  9074. //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  9075. const getFooterIcon = (button) => {
  9076. //功能 by xu 20251224
  9077. if (!button) return "menu-base-icon icon-subm";
  9078. const iconNameOrClass =
  9079. button.iconClass || button.iconName || button.icon;
  9080. if (!iconNameOrClass) return "menu-base-icon icon-subm";
  9081. if (
  9082. typeof iconNameOrClass === "string" &&
  9083. iconNameOrClass.indexOf(" ") > -1
  9084. ) {
  9085. return iconNameOrClass;
  9086. }
  9087. return `menu-base-icon ${iconNameOrClass}`;
  9088. };
  9089. //功能: pobj/cobj 扁平结构转换为 children 树结构,兼容原 children 结构 by xu 20251222
  9090. const normalizeMenuList = (rawList) => {
  9091. if (!Array.isArray(rawList) || rawList.length === 0) {
  9092. return [];
  9093. }
  9094. const hasTree = rawList.some(
  9095. (it) => Array.isArray(it?.children) && it.children.length > 0
  9096. );
  9097. if (hasTree) {
  9098. return rawList.map((it) => ({
  9099. ...it,
  9100. __level: 1,
  9101. children: Array.isArray(it.children)
  9102. ? it.children.map((c) => ({ ...c, __level: 2 }))
  9103. : it.children,
  9104. }));
  9105. }
  9106. const hasMarker = rawList.some(
  9107. (it) => it && ("pobj" in it || "cobj" in it)
  9108. );
  9109. if (!hasMarker) {
  9110. return rawList.map((it) => ({ ...it, __level: 1 }));
  9111. }
  9112. const result = [];
  9113. let currentGroup = null;
  9114. for (const item of rawList) {
  9115. //功能: “变动”始终按一级处理(即使后端误传 pobj/cobj)by xu 20251223
  9116. const isChgItem =
  9117. item && (item.title === "变动" || item.name === "sys_bd");
  9118. if (isChgItem) {
  9119. result.push({ ...item, __level: 1 });
  9120. continue;
  9121. }
  9122. const isParent = isTrue(item?.pobj);
  9123. const isChild = isTrue(item?.cobj);
  9124. if (isParent) {
  9125. currentGroup = {
  9126. ...item,
  9127. __level: 1,
  9128. children: [],
  9129. };
  9130. result.push(currentGroup);
  9131. continue;
  9132. }
  9133. if (isChild && currentGroup) {
  9134. currentGroup.children.push({ ...item, __level: 2 });
  9135. continue;
  9136. }
  9137. //功能: 变动等无 pobj/cobj 的选项按一级展示(不挂到 children,也不打断当前分组)by xu 20251223
  9138. result.push({ ...item, __level: 1 });
  9139. }
  9140. return result;
  9141. };
  9142. const menuListComputed = computed(() =>
  9143. normalizeMenuList(props.menuList)
  9144. ); //功能 by xu 20251222
  9145. //功能: 分组展开状态(默认展开),避免 computed 生成对象导致 open 状态丢失 by xu 20251222
  9146. const groupOpenState = reactive({}); // { [key]: boolean }
  9147. const getGroupKey = (item) => item?.name || item?.title || ""; //功能 by xu 20251222
  9148. const isGroupOpen = (item) => {
  9149. //功能 by xu 20251222
  9150. const key = getGroupKey(item);
  9151. if (!key) return true;
  9152. return groupOpenState[key] !== false;
  9153. };
  9154. const toggleGroupOpen = (item) => {
  9155. //功能 by xu 20251222
  9156. const key = getGroupKey(item);
  9157. if (!key) return;
  9158. groupOpenState[key] = !isGroupOpen(item);
  9159. };
  9160. const getLevelClass = (item, fallbackLevel) => {
  9161. //功能 by xu 20251222
  9162. //功能: “变动”始终按一级样式处理 by xu 20251223
  9163. if (item && (item.title === "变动" || item.name === "sys_bd")) {
  9164. return "level-1";
  9165. }
  9166. const level = item?.__level || fallbackLevel || 1;
  9167. return level === 2 ? "level-2" : "level-1";
  9168. };
  9169. // v3.0 新增:菜单模式管理 by xu 20251216
  9170. const menuMode = ref(props.initialMode);
  9171. const isHovering = ref(false);
  9172. const toggleMenuMode = () => {
  9173. menuMode.value = menuMode.value === "collapse" ? "fixed" : "collapse";
  9174. };
  9175. //功能: 提供给旧UI弹窗顶部按钮调用的 API(替代点击 .menu-mode-toggle DOM)by xu 20251224
  9176. const registerSsSubTabApi = () => {
  9177. //功能 by xu 20251224
  9178. try {
  9179. window.SS = window.SS || {};
  9180. window.SS.dom = window.SS.dom || {};
  9181. //功能: 兼容小写 ss 命名空间(部分页面只引用 window.ss)by xu 20251224
  9182. window.ss = window.ss || window.SS;
  9183. window.ss.dom = window.ss.dom || window.SS.dom;
  9184. const api = {
  9185. toggleMenuMode,
  9186. getMenuMode: () => menuMode.value,
  9187. };
  9188. window.SS.dom.ssSubTabApi = api;
  9189. window.ss.dom.ssSubTabApi = api;
  9190. //功能: 多层弹窗(如 objPlay -> objInfo) 场景,将 API 注册到 topWindow 供按钮跨层调用 by xu 20251224
  9191. try {
  9192. const wdDialogId =
  9193. window.wd &&
  9194. wd.display &&
  9195. wd.display.getwdDialogId &&
  9196. wd.display.getwdDialogId();
  9197. if (wdDialogId && window.top) {
  9198. window.top.__ssSubTabApiMap = window.top.__ssSubTabApiMap || {};
  9199. window.top.__ssSubTabApiMap[wdDialogId] = api;
  9200. }
  9201. } catch (e) {}
  9202. try {
  9203. console.log(
  9204. "[SsSubTabApi] registered",
  9205. window.location && window.location.pathname
  9206. );
  9207. } catch (e) {}
  9208. } catch (e) {}
  9209. };
  9210. const unregisterSsSubTabApi = () => {
  9211. //功能 by xu 20251224
  9212. try {
  9213. //功能: 从 topWindow 解绑(避免弹窗关闭后残留)by xu 20251224
  9214. try {
  9215. const wdDialogId =
  9216. window.wd &&
  9217. wd.display &&
  9218. wd.display.getwdDialogId &&
  9219. wd.display.getwdDialogId();
  9220. if (
  9221. wdDialogId &&
  9222. window.top &&
  9223. window.top.__ssSubTabApiMap &&
  9224. window.top.__ssSubTabApiMap[wdDialogId]
  9225. ) {
  9226. delete window.top.__ssSubTabApiMap[wdDialogId];
  9227. }
  9228. } catch (e) {}
  9229. if (window.SS?.dom?.ssSubTabApi?.toggleMenuMode === toggleMenuMode) {
  9230. delete window.SS.dom.ssSubTabApi;
  9231. }
  9232. if (window.ss?.dom?.ssSubTabApi?.toggleMenuMode === toggleMenuMode) {
  9233. delete window.ss.dom.ssSubTabApi;
  9234. }
  9235. } catch (e) {}
  9236. };
  9237. //功能: 立即注册,避免 enable 早于 onMounted 导致“api not ready”by xu 20251224
  9238. registerSsSubTabApi(); //功能 by xu 20251224
  9239. onBeforeUnmount(unregisterSsSubTabApi); //功能 by xu 20251224
  9240. const onMouseEnter = () => {
  9241. if (menuMode.value === "collapse") {
  9242. isHovering.value = true;
  9243. }
  9244. };
  9245. const onMouseLeave = () => {
  9246. isHovering.value = false;
  9247. };
  9248. const isExpanded = computed(() => {
  9249. return menuMode.value === "collapse" && isHovering.value;
  9250. });
  9251. // v3.0 新增:iframe 懒加载,点击才加载 by xu 20251216
  9252. const loadedMenus = ref(new Set());
  9253. const isMenuLoaded = (menuName) => {
  9254. return loadedMenus.value.has(menuName);
  9255. };
  9256. // 根据标题找到对应的菜单项
  9257. const findMenuByTitle = (title) => {
  9258. for (const item of menuListComputed.value) {
  9259. //功能 by xu 20251222
  9260. if (item.children?.length > 0) {
  9261. const child = item.children.find((c) => c.title === title);
  9262. if (child) return child;
  9263. } else if (item.title === title) {
  9264. return item;
  9265. }
  9266. }
  9267. return null;
  9268. };
  9269. // 计算默认选中的菜单项
  9270. const defaultActiveMenu = computed(() => {
  9271. if (props.activeMenu) {
  9272. const menu = findMenuByTitle(props.activeMenu);
  9273. if (menu) return menu;
  9274. }
  9275. const firstItem = menuListComputed.value[0]; //功能 by xu 20251222
  9276. if (!firstItem) return null;
  9277. //功能: 默认选中第一个一级菜单(不默认跳到第一个二级)by xu 20251224
  9278. return firstItem;
  9279. });
  9280. const currentMenu = ref(defaultActiveMenu.value);
  9281. // 监听外部activeMenu变化
  9282. watch(
  9283. () => props.activeMenu,
  9284. (newTitle) => {
  9285. if (newTitle) {
  9286. const menu = findMenuByTitle(newTitle);
  9287. if (menu) {
  9288. currentMenu.value = menu;
  9289. }
  9290. }
  9291. }
  9292. );
  9293. // 初始化:默认选中项加入已加载集合
  9294. watch(
  9295. currentMenu,
  9296. (menu) => {
  9297. if (menu?.name) {
  9298. loadedMenus.value.add(menu.name);
  9299. }
  9300. },
  9301. { immediate: true }
  9302. );
  9303. // 选择菜单项时触发 menu-change 钩子
  9304. const selectItem = (item) => {
  9305. currentMenu.value = item;
  9306. // 标记为已加载
  9307. if (item.name) {
  9308. loadedMenus.value.add(item.name);
  9309. }
  9310. emit("menu-change", item);
  9311. };
  9312. // 处理底部按钮点击
  9313. const handleFooterClick = (button, index) => {
  9314. emit("footer-click", { button, index });
  9315. };
  9316. return {
  9317. menuListComputed, //功能 by xu 20251222
  9318. currentMenu,
  9319. selectItem,
  9320. handleFooterClick,
  9321. getFooterIcon, //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  9322. menuMode,
  9323. isHovering,
  9324. isExpanded,
  9325. toggleMenuMode,
  9326. onMouseEnter,
  9327. onMouseLeave,
  9328. isMenuLoaded,
  9329. getMenuIcon,
  9330. isGroupOpen, //功能 by xu 20251222
  9331. toggleGroupOpen, //功能 by xu 20251222
  9332. getLevelClass, //功能 by xu 20251222
  9333. };
  9334. },
  9335. template: `
  9336. <div class="project-edit-container">
  9337. <div class="left-side"
  9338. v-if="leftDisplay"
  9339. :data-mode="menuMode"
  9340. :class="{ 'is-expanded': isExpanded }"
  9341. @mouseenter="onMouseEnter"
  9342. @mouseleave="onMouseLeave">
  9343. <!-- 菜单内容 -->
  9344. <div class="menu-content">
  9345. <div class="scroll-view">
  9346. <template v-for="(menuItem, i) in menuListComputed" :key="i">
  9347. <!-- 分组菜单 -->
  9348. <div v-if="menuItem.children?.length > 0" class="group">
  9349. <!-- 功能: 一级(pobj)可点击进入,箭头仅控制展开/收起;二级点击不影响一级选中状态 by xu 20251223 -->
  9350. <div class="menu-item"
  9351. :class="[getLevelClass(menuItem, 1), { active: menuItem.name === currentMenu?.name }]"
  9352. @click="selectItem(menuItem)">
  9353. <ss-icon :class="getMenuIcon(menuItem, i)" />
  9354. <span class="menu-label">{{ menuItem.title }}</span>
  9355. <!-- 功能: 一级菜单有子项时显示 dot(参考全局左侧菜单)by xu 20251224 -->
  9356. <div class="has-children-dot"></div>
  9357. <div class="menu-tooltip">{{ menuItem.title }}</div>
  9358. </div>
  9359. <!-- 功能: 二级菜单始终展示,不做收缩展开 by xu 20251223 -->
  9360. <div class="group-detail">
  9361. <div v-for="(item, j) in menuItem.children"
  9362. :key="j"
  9363. class="menu-item"
  9364. :class="[getLevelClass(item, 2), { active: item.name === currentMenu?.name }]"
  9365. @click.stop="selectItem(item)">
  9366. <ss-icon :class="getMenuIcon(item, j)" />
  9367. <span class="menu-label">{{ item.title }}</span>
  9368. </div>
  9369. </div>
  9370. </div>
  9371. <!-- 普通菜单项 -->
  9372. <div v-else
  9373. class="menu-item"
  9374. :class="[getLevelClass(menuItem, 1), { active: menuItem.name === currentMenu?.name }]"
  9375. @click="selectItem(menuItem)">
  9376. <ss-icon :class="getMenuIcon(menuItem, i)" />
  9377. <span class="menu-label">{{ menuItem.title }}</span>
  9378. <div class="menu-tooltip">{{ menuItem.title }}</div>
  9379. </div>
  9380. </template>
  9381. </div>
  9382. </div>
  9383. <!-- 底部按钮 -->
  9384. <div v-if="footerButtons.length > 0"
  9385. class="sub-tab-menu-footer"
  9386. :class="{ 'has-text': !!footerButtons[0].text }"
  9387. @click="footerButtons[0].onclick">
  9388. <ss-icon :class="getFooterIcon(footerButtons[0])" />
  9389. <div class="footer-label" v-if="footerButtons[0].text">{{ footerButtons[0].text }}</div>
  9390. <ss-icon v-if="footerButtons.length > 1" class="footer-arrow" name="arrow-up" size="24px" />
  9391. <div v-if="footerButtons.length > 1" class="sub-tab-menu-popup">
  9392. <div v-for="(button, index) in footerButtons.slice(1)"
  9393. :key="index"
  9394. @click.stop="button.onclick">
  9395. {{ button.text }}
  9396. </div>
  9397. </div>
  9398. </div>
  9399. </div>
  9400. <!-- 右侧内容区域 - 懒加载 iframe -->
  9401. <div class="content-area fit-height-content" style="overflow: hidden;" :style="!leftDisplay ? { width: '100%' } : {}">
  9402. <template v-for="(menuItem, i) in menuList" :key="i">
  9403. <iframe
  9404. v-if="isMenuLoaded(menuItem.name)"
  9405. :src="menuItem.url"
  9406. style="height: 100%;width: 100%;"
  9407. frameborder="0"
  9408. class="sub-tab-iframe"
  9409. :id="i === 0 ? 'sub-tab-iframe' : ''"
  9410. v-show="currentMenu?.name === menuItem.name"
  9411. />
  9412. </template>
  9413. </div>
  9414. </div>
  9415. `,
  9416. };
  9417. // <iframe
  9418. // v-if="currentMenu?.url"
  9419. // :src="currentMenu.url"
  9420. // style="height: 100%;width: 100%;"
  9421. // frameborder="0"
  9422. // id="sub-tab-iframe"
  9423. // />
  9424. // ss-photo-upload 通用图片上传组件
  9425. const SsImgUpload = {
  9426. name: "SsImgUpload",
  9427. props: {
  9428. name: {
  9429. type: String,
  9430. required: true,
  9431. },
  9432. // 图片URL,用于回显
  9433. // url: {
  9434. // type: String,
  9435. // default: "",
  9436. // },
  9437. // 样式类名
  9438. class: {
  9439. type: String,
  9440. required: true,
  9441. },
  9442. // 裁剪配置
  9443. cropperOpt: {
  9444. type: Object,
  9445. default: () => ({
  9446. width: 360,
  9447. height: 360,
  9448. aspectRatio: 1,
  9449. }),
  9450. },
  9451. //上传图片url(未加图片名参数之前的部分)
  9452. ulUrl: {
  9453. type: String,
  9454. required: true,
  9455. },
  9456. //下载图片url(未加图片名参数之前的部分)
  9457. dlUrl: {
  9458. type: String,
  9459. required: true,
  9460. },
  9461. modelValue: [String, Number],
  9462. },
  9463. emits: ["update:modelValue"],
  9464. setup(props, { emit }) {
  9465. const inputId = Vue.computed(
  9466. () => `file_${Vue.getCurrentInstance().uid}`
  9467. );
  9468. //修改图片初始显示路径
  9469. let pathVal = ref(props.modelValue);
  9470. let picUrl = ref("");
  9471. if (props.modelValue) {
  9472. picUrl.value = props.dlUrl + "&path=" + props.modelValue;
  9473. }
  9474. Vue.onMounted(() => {
  9475. window.SS.cropper.init({
  9476. el: $(`#${inputId.value}`),
  9477. photoSize: {
  9478. width: props.cropperOpt.width,
  9479. height: props.cropperOpt.height,
  9480. },
  9481. aspectRatio: props.cropperOpt.aspectRatio,
  9482. uploadUrl: props.ulUrl,
  9483. success: (path) => {
  9484. pathVal.value = path;
  9485. picUrl.value = props.dlUrl + "&path=" + path;
  9486. emit("update:modelValue", path);
  9487. },
  9488. });
  9489. });
  9490. return () =>
  9491. h("div", { class: [props.class] }, [
  9492. h("input", {
  9493. type: "file",
  9494. accept: "image/*",
  9495. id: inputId.value,
  9496. style: { display: "none" },
  9497. }),
  9498. h("input", {
  9499. type: "hidden",
  9500. name: props.name,
  9501. value: pathVal.value,
  9502. }),
  9503. h(
  9504. "div",
  9505. {
  9506. style: {
  9507. width: "100%",
  9508. height: "100%",
  9509. },
  9510. onClick: () => $(`#${inputId.value}`).click(),
  9511. },
  9512. [
  9513. picUrl.value &&
  9514. h("img", {
  9515. src: picUrl.value,
  9516. style:
  9517. "width: 100%; height: 100%;object-fit: inherit;position: relative;z-index: 11;",
  9518. }),
  9519. ]
  9520. ),
  9521. ]);
  9522. },
  9523. };
  9524. // 初始化函数,负责创建和挂载 Vue 应用
  9525. // window.SS = { dom: {} };
  9526. /**
  9527. * 获取当前窗口的父窗口
  9528. * @returns {Window} 父窗口对象
  9529. */
  9530. window.SS.topWin = (function (p, c) {
  9531. while (p != c) {
  9532. c = p;
  9533. p = p.parent;
  9534. }
  9535. return c;
  9536. })(window.parent, window);
  9537. window.SS.createSsDialogInstance = createSsDialogInstance;
  9538. /**
  9539. * 创建弹窗
  9540. * @param {Object} setting
  9541. * @param {Function} callbackEvent
  9542. */
  9543. window.SS.openDialog = function (setting, callbackEvent) {
  9544. if (setting.params) {
  9545. const encodedParams = encodeURIComponent(JSON.stringify(setting.params));
  9546. setting.src +=
  9547. (setting.src.includes("?") ? "&" : "?") + "params=" + encodedParams;
  9548. }
  9549. if (window.parent && window.parent !== window) {
  9550. window.parent.SS.createSsDialogInstance(setting, callbackEvent);
  9551. } else {
  9552. createSsDialogInstance(setting, callbackEvent);
  9553. }
  9554. };
  9555. //关闭弹窗
  9556. window.SS.closeDialog = function () {
  9557. console.log("关闭弹窗");
  9558. if (topWindow.dialogInstances.length > 0) {
  9559. const instance = topWindow.dialogInstances.pop();
  9560. console.log("instance", instance);
  9561. console.log("instance.callbackEvent", instance.callbackEvent);
  9562. console.log(
  9563. "instance.callbackEvent.end",
  9564. typeof instance.callbackEvent === "function"
  9565. );
  9566. if (instance.callbackEvent) {
  9567. // 判断是否有end回调并执行
  9568. if (typeof instance.callbackEvent === "function") {
  9569. instance.callbackEvent();
  9570. }
  9571. if (typeof instance.callbackEvent.end === "function") {
  9572. instance.callbackEvent.end();
  9573. }
  9574. }
  9575. instance.app.unmount(); // 卸载最后一个实例
  9576. if (instance.container && instance.container.parentNode) {
  9577. instance.container.parentNode.removeChild(instance.container); // 移除容器
  9578. }
  9579. }
  9580. };
  9581. /**
  9582. * 裁剪插件
  9583. */
  9584. window.SS.cropper = {
  9585. init: function (setting) {
  9586. if (!window.top.SS) window.top.SS = {};
  9587. // 重要:确保 cropper 对象的完整初始化
  9588. if (!window.top.SS.cropper) {
  9589. window.top.SS.cropper = {
  9590. settings: new Map(),
  9591. _backupSettings: {},
  9592. getSetting: this.getSetting,
  9593. clearSetting: this.clearSetting,
  9594. debug: this.debug,
  9595. };
  9596. } else if (!window.top.SS.cropper.settings) {
  9597. // 如果 cropper 存在但 settings 不存在,重新初始化 settings
  9598. window.top.SS.cropper.settings = new Map();
  9599. window.top.SS.cropper._backupSettings = {};
  9600. }
  9601. const uploaderId = `uploader_${Date.now()}_${Math.random()
  9602. .toString(36)
  9603. .substr(2, 9)}`;
  9604. window.top.SS.cropper.settings.set(uploaderId, setting);
  9605. window.top.SS.cropper._backupSettings[uploaderId] = setting;
  9606. setting.box = setting.box || "1";
  9607. var winSetting = {
  9608. headerTitle: "图片裁剪",
  9609. src: "/js/cropper/cropper.jsp", //原来在"/newUI/page/cropper.jsp" Ben(20251205)
  9610. width: "900",
  9611. height: "500",
  9612. };
  9613. $(setting.el).change(function () {
  9614. if (!window.SS.cropper.verify(setting)) {
  9615. $(setting.el).val(""); // 清空文件选择
  9616. return false;
  9617. }
  9618. var files = this.files;
  9619. if (files && files.length) {
  9620. if (!window.SS.cropper.verifySize($(setting.el)[0], 5)) {
  9621. $(setting.el).val(""); // 清空文件选择
  9622. alert("文件大小不能超过5M,请重新选择");
  9623. return false;
  9624. }
  9625. var URL = window.URL || window.webkitURL;
  9626. var file = files[0];
  9627. setting.file = file;
  9628. if (
  9629. /^image\/\w+$/.test(file.type) &&
  9630. /\.(jpg|jpeg|png|)$/i.test(file.name)
  9631. ) {
  9632. var uploadedImageURL = URL.createObjectURL(file);
  9633. setting.data = uploadedImageURL;
  9634. setting.fileName = file.name;
  9635. // console.log()
  9636. winSetting.params = {
  9637. ...setting,
  9638. uploaderId,
  9639. };
  9640. console.log("ss-componets中change之后的winSetting", winSetting);
  9641. SS.openDialog(winSetting, {
  9642. success: function (win) {
  9643. console.log("裁剪插件成功");
  9644. // win.cropperSetting = setting;
  9645. },
  9646. end: function () {
  9647. console.log("裁剪插件结束");
  9648. $(setting.el).val(""); // 清空文件选择
  9649. },
  9650. });
  9651. } else {
  9652. alert("请选择图片文件,支持jpg、jpeg、png格式");
  9653. }
  9654. }
  9655. });
  9656. return uploaderId;
  9657. },
  9658. verify: function (setting) {
  9659. if (!setting) {
  9660. console.error(" cropper setting is not undefined! ");
  9661. return false;
  9662. }
  9663. if (!setting.el) {
  9664. console.error(" cropper setting.el is not undefined! ");
  9665. return false;
  9666. }
  9667. if (setting.photoSize) {
  9668. if (
  9669. (!setting.photoSize.width && setting.photoSize.height) ||
  9670. (!setting.photoSize.height && setting.photoSize.width)
  9671. ) {
  9672. console.error(
  9673. " cropper setting.photoSize { width, height } is not undefined! "
  9674. );
  9675. return false;
  9676. }
  9677. }
  9678. if (!setting.box) {
  9679. setting.box = "1";
  9680. }
  9681. if (!setting.aspectRatio) {
  9682. setting.aspectRatio = 1 / 1;
  9683. }
  9684. return true;
  9685. },
  9686. verifySize: function (fileEl, maxSize) {
  9687. // 判断是否为IE浏览器: /msie/i.test(navigator.userAgent) 为一个简单正则
  9688. var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  9689. var fileSize = 0;
  9690. if (isIE && !fileEl.files) {
  9691. // IE浏览器
  9692. var filePath = fileEl.value; // 获得上传文件的绝对路径
  9693. var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
  9694. var file = fileSystem.GetFile(filePath);
  9695. fileSize = file.Size; // 文件大小,单位:b
  9696. } else {
  9697. // 非IE浏览器
  9698. fileSize = fileEl.files[0].size;
  9699. }
  9700. var size = fileSize / 1024 / 1024;
  9701. return !(size > maxSize);
  9702. },
  9703. // 获取特定上传组件的setting
  9704. getSetting: function (uploaderId) {
  9705. if (!window.top.SS?.cropper) {
  9706. console.warn("顶层窗口中未找到 SS.cropper");
  9707. return null;
  9708. }
  9709. // 优先从 Map 中获取
  9710. let setting = window.top.SS.cropper.settings.get(uploaderId);
  9711. // 如果 Map 中没有,尝试从备份中获取
  9712. if (!setting && window.top.SS.cropper._backupSettings[uploaderId]) {
  9713. console.log("从备份中恢复 setting");
  9714. setting = window.top.SS.cropper._backupSettings[uploaderId];
  9715. // 恢复到 Map 中
  9716. window.top.SS.cropper.settings.set(uploaderId, setting);
  9717. }
  9718. return setting;
  9719. },
  9720. // 清理特定上传组件的setting
  9721. clearSetting: function (uploaderId) {
  9722. if (!window.top.SS?.cropper) return;
  9723. window.top.SS.cropper.settings.delete(uploaderId);
  9724. delete window.top.SS.cropper._backupSettings[uploaderId];
  9725. console.log(
  9726. "清理设置后的 Map size:",
  9727. window.top.SS.cropper.settings.size
  9728. );
  9729. },
  9730. };
  9731. /**
  9732. * 获取url中的参数
  9733. * @returns {Object}
  9734. */
  9735. window.SS.getQueryParams = function () {
  9736. const params = {};
  9737. const queryString = window.location.search.substring(1);
  9738. const pairs = queryString.split("&");
  9739. for (let i = 0; i < pairs.length; i++) {
  9740. const pair = pairs[i].split("=");
  9741. params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  9742. }
  9743. if (params.params) {
  9744. try {
  9745. params.params = JSON.parse(params.params);
  9746. } catch (e) {
  9747. console.error("Failed to parse params:", e);
  9748. }
  9749. }
  9750. return params;
  9751. };
  9752. /**
  9753. * 创建vue应用
  9754. * @param {Object} config 配置项
  9755. * @values {String} config.el 挂载的元素
  9756. * @values {Boolean} config.isDialogPage 是否是弹窗页面 决定了是否可以使用顶天立地
  9757. * @values {Object} config.vueOptions vue配置项
  9758. * @returns {Object} vue实例
  9759. */
  9760. window.SS.dom.initializeFormApp = function (config) {
  9761. const { el, isDialogPage = false, ...vueOptions } = config;
  9762. const app = createApp({
  9763. ...vueOptions,
  9764. });
  9765. // 如果是弹窗iframe里面的html的话 给当前的页面挂上事件 实现顶天立地的效果
  9766. if (isDialogPage) {
  9767. function checkScroll() {
  9768. // 选出所有fit-height-content的元素 如果有滚动条
  9769. const elements = document.querySelectorAll(".fit-height-content");
  9770. let hasScrollBar = false;
  9771. // 检查元素是否有滚动条 检查当前窗口的所有元素
  9772. // 如果有滚动条,则将结果设置为true
  9773. elements.forEach((el) => {
  9774. if (el.scrollHeight > el.clientHeight) {
  9775. hasScrollBar = true;
  9776. }
  9777. });
  9778. // 将结果发送给父窗口
  9779. window.parent.postMessage({ hasScrollBar }, "*");
  9780. }
  9781. function addScrollListeners() {
  9782. const elements = document.querySelectorAll("div");
  9783. elements.forEach((el) => {
  9784. el.addEventListener("scroll", checkScroll);
  9785. });
  9786. }
  9787. const observer = new MutationObserver((mutations) => {
  9788. addScrollListeners();
  9789. checkScroll();
  9790. });
  9791. observer.observe(document.body, {
  9792. childList: true,
  9793. subtree: true,
  9794. });
  9795. window.addEventListener("resize", checkScroll);
  9796. }
  9797. // 注册组件
  9798. app.component("SsLoginIcon", SsLoginIcon);
  9799. app.component("SsMark", SsMark);
  9800. app.component("SsFullStyleHeader", SsFullStyleHeader);
  9801. app.component("SsDialog", SsDialog);
  9802. app.component("SsInp", SsInput); //把SsInput改为SsInp Ben(20251225)
  9803. app.component("SsObjp", SsObjp);
  9804. app.component("SsHidden", SsHidden);
  9805. app.component("SsCcp", SsCcp);
  9806. app.component("SsDatePicker", SsDatePicker);
  9807. app.component("SsIcon", SsIcon);
  9808. app.component("SsCommonIcon", SsCommonIcon);
  9809. app.component("SsBreadcrumb", SsBreadcrumb);
  9810. app.component("SsEditor", SsEditor);
  9811. app.component("SsDialogIcon", SsDialogIcon);
  9812. app.component("SsBottomButton", SsBottomButton);
  9813. app.component("SsNavIcon", SsNavIcon);
  9814. app.component("SsHeaderIcon", SsHeaderIcon);
  9815. app.component("SsGolbalMenuIcon", SsGolbalMenuIcon);
  9816. app.component("SsCartListIcon", SsCartListIcon);
  9817. app.component("SsQuickIcon", SsQuickIcon);
  9818. app.component("SsFormIcon", SsFormIcon);
  9819. app.component("SsBottomDivIcon", SsBottomDivIcon);
  9820. app.component("SsEditorIcon", SsEditorIcon);
  9821. app.component("SsValidate", SsValidate);
  9822. app.component("SsOnoff", Ssonoff);
  9823. app.component("SsonoffArray", SsonoffArray);
  9824. app.component("SsTextarea", SsTextarea);
  9825. app.component("SsLoginInput", SsLoginInput);
  9826. app.component("SsLoginButton", SsLoginButton);
  9827. app.component("SsSearch", SsSearch);
  9828. app.component("SsCartItem", SsCartItem);
  9829. app.component("SsCartItem2", SsCartItem2);
  9830. app.component("SsListCard", SsListCard);
  9831. app.component("ss-cobj-card-list", SsCObjCardList); // 功能说明:二级对象列表使用旧卡片组件 ss-cobj-card-list by xu 20260115
  9832. app.component("SsFolderCard", SsFolderCard);
  9833. // 注册右侧边栏组件(ss-sidebar) by xu 20260106
  9834. app.component("ss-sidebar", SsSidebar);
  9835. app.component("ss-sidebar-buttons", SsSidebarButtons);
  9836. app.component("ss-sidebar-chart", SsSidebarChart);
  9837. app.component("ss-sidebar-chart-hover", SsSidebarChartHover);
  9838. app.component("ss-sidebar-list", SsSidebarList);
  9839. // 功能说明:注册右侧“统计表/报表”面板组件(ss-sidebar-report-table) by xu 20260115
  9840. app.component("ss-sidebar-report-table", SsSidebarReportTable);
  9841. app.component("SsFolderCartView", SsFolderCartView);
  9842. app.component("SsPage", SsPage);
  9843. app.component("SsRightInfo", SSRightInfo);
  9844. app.component("SsSuccessPopup", SsSuccessPopup);
  9845. app.component("SsErrorDialog", SsErrorDialog);
  9846. app.component("SsVerify", SsVerify);
  9847. app.component("SsVerifyNode", SsVerifyNode);
  9848. app.component("SsOrcImgBox", SsOrcImgBox);
  9849. app.component("ss-search-input", SsSearchInput);
  9850. app.component("ss-search-date-picker", SsSearchDatePicker);
  9851. app.component("ss-search-button", SsSearchButton);
  9852. app.component("ss-drop-button", SsDropButton);
  9853. app.component("ss-sub-tab", SsSubTab);
  9854. app.component("ss-img", SsImgUpload);
  9855. // 设置为中文
  9856. app.use(ElementPlus, {
  9857. locale: ElementPlusLocaleZhCn,
  9858. });
  9859. // console.log(ElementPlus);
  9860. // 确保 ElementPlusIconsVue
  9861. // if (window.ElementPlusIconsVue) {
  9862. // // 注册 Element Plus 图标组件
  9863. // for (const [key, component] of Object.entries(
  9864. // window.ElementPlusIconsVue
  9865. // )) {
  9866. // console.log(key, component);
  9867. // app.component(key, component);
  9868. // }
  9869. // }
  9870. // 挂载首页的组件
  9871. for (const componentName in IndexComponents) {
  9872. app.component(componentName, IndexComponents[componentName]);
  9873. }
  9874. // 挂载echarts的组件
  9875. for (const componentName in EchartComponents) {
  9876. app.component(componentName, EchartComponents[componentName]);
  9877. }
  9878. // 挂载 Vue 应用
  9879. let vm;
  9880. try {
  9881. vm = app.mount(el);
  9882. vm.data = vueOptions.data();
  9883. console.log("vm:", vm);
  9884. console.log("vueOptions:", vueOptions);
  9885. } catch (error) {
  9886. alert("Mount failed:" + error); //vue Mount失败报错 Ben(20251206)
  9887. }
  9888. return vm;
  9889. };
  9890. })();