ss-components.js 209 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474
  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 { isNum, toStyleStr } from "./tools.js";
  5. import { EVEN_VAR } from "./EventBus.js";
  6. // import * as elements from "../lib/element-plus.js";
  7. (function () {
  8. const {
  9. createApp,
  10. ref,
  11. reactive,
  12. watch,
  13. onMounted,
  14. onBeforeUnmount,
  15. h,
  16. computed,
  17. resolveComponent,
  18. watchEffect,
  19. nextTick,
  20. onVnodeMounted,
  21. Teleport,
  22. inject,
  23. provide,
  24. } = Vue;
  25. // 弹窗默认遮罩z-index
  26. let currentZIndex = 100;
  27. // 目前已存在的弹窗
  28. const topWindow = window.top;
  29. topWindow.dialogInstances = topWindow.dialogInstances || [];
  30. // 新建弹窗
  31. function createSsDialogInstance(setting, callbackEvent) {
  32. currentZIndex += 10; // 动态提升 z-index
  33. const container = document.createElement("div");
  34. document.body.appendChild(container);
  35. const app = Vue.createApp({
  36. render() {
  37. return h(SsDialog, {
  38. ...setting,
  39. zIndex: currentZIndex,
  40. onClose() {
  41. document.body.removeChild(container); // 仅移除弹窗容器
  42. const index = topWindow.dialogInstances.indexOf(app);
  43. if (index > -1) {
  44. topWindow.dialogInstances.splice(index, 1); // 移除实例
  45. }
  46. // 关闭后的回调
  47. if (callbackEvent && typeof callbackEvent === "function") {
  48. callbackEvent();
  49. }
  50. app.unmount(); // 仅卸载弹窗实例
  51. if (container.parentNode) {
  52. container.parentNode.removeChild(container); // 确保移除容器
  53. }
  54. },
  55. });
  56. },
  57. });
  58. topWindow.dialogInstances.push({ app, callbackEvent, container });
  59. app.component("ss-mark", SsMark); // 注册 ss-mark 组件
  60. app.component("ss-icon", SsIcon);
  61. app.component("ss-full-style-header", SsFullStyleHeader); // 注册 ss-full-style-header 组件
  62. app.mount(container);
  63. }
  64. // ss-breadcrumb 一级菜单页面面包屑
  65. const SsBreadcrumb = {
  66. name: "SsBreadcrumb",
  67. props: {
  68. level: {
  69. type: Object,
  70. default: null,
  71. },
  72. },
  73. setup(props) {
  74. const currentMenu = ref(null);
  75. const folderPath = ref([]);
  76. const eventBus = window.parent.sharedEventBus;
  77. // 监听页面变化
  78. onMounted(() => {
  79. // 获取初始页面
  80. currentMenu.value = eventBus.getState(EVEN_VAR.currentPage);
  81. folderPath.value = eventBus.getState("folderPath") || [];
  82. // 订阅页面变化
  83. eventBus.subscribe(EVEN_VAR.currentPage, (page) => {
  84. currentMenu.value = page;
  85. });
  86. eventBus.subscribe("folderPath", (path) => {
  87. folderPath.value = path || [];
  88. });
  89. });
  90. // 修改点击处理函数
  91. const handlePathClick = (index) => {
  92. if (props.level?.onBack) {
  93. // 截取到点击的位置,后面的路径会被销毁
  94. const newPath = folderPath.value.slice(0, index + 1);
  95. eventBus.publish("folderPath", newPath);
  96. // 返回到对应层级
  97. const targetFolder = newPath[newPath.length - 1]?.folder || null;
  98. props.level.onBack(targetFolder);
  99. }
  100. };
  101. const SsCommonIcon = resolveComponent("SsCommonIcon");
  102. return () =>
  103. h("div", { class: "bread-crumb" }, [
  104. currentMenu.value &&
  105. h(
  106. "div",
  107. {
  108. onClick: () => {
  109. if (props.level?.onBack) {
  110. eventBus.publish("folderPath", []);
  111. props.level.onBack(null); // 返回到根目录
  112. } else {
  113. eventBus.publish(EVEN_VAR.currentPage, currentMenu.value);
  114. }
  115. },
  116. },
  117. currentMenu.value.label || currentMenu.value.name
  118. ),
  119. ...(folderPath.value || [])
  120. .map((folder, index) => [
  121. h(SsCommonIcon, { class: "common-icon-arrow-right" }),
  122. h(
  123. "div",
  124. {
  125. class: "bread-crumb-item",
  126. onClick: () => handlePathClick(index),
  127. style: { cursor: "pointer" },
  128. },
  129. folder.title
  130. ),
  131. ])
  132. .flat(),
  133. ]);
  134. },
  135. };
  136. // ss-input form表单的输入
  137. const SsInput = {
  138. name: "SsInput",
  139. inheritAttrs: false, // 不直接继承属性到组件根元素
  140. props: {
  141. name: {
  142. type: String,
  143. required: true,
  144. default: "",
  145. },
  146. // 接收 v-model 绑定的值
  147. errTip: {
  148. type: String,
  149. },
  150. required: {
  151. type: Boolean,
  152. default: false,
  153. },
  154. placeholder: {
  155. type: String,
  156. default: "请输入",
  157. },
  158. defaultValue: [String, Number],
  159. modelValue: [String, Number],
  160. // 新增:附件配置
  161. fj: {
  162. type: Object,
  163. default: null,
  164. },
  165. // 新增:param 配置(用于附件功能)
  166. param: {
  167. type: Object,
  168. default: null,
  169. },
  170. // 新增:高度配置
  171. height: {
  172. type: String,
  173. default: "",
  174. },
  175. // 新增:是否允许回车换行,默认false禁止换行 by xu 20251212
  176. multiline: {
  177. type: Boolean,
  178. default: false,
  179. },
  180. },
  181. emits: ["update:modelValue", "input", "blur", "change"], // 允许更新 v-model 绑定的值
  182. setup(props, { emit }) {
  183. const errMsg = ref("");
  184. const inputRef = ref(null);
  185. const textareaRef = ref(null);
  186. const inputValue = ref(props.modelValue || props.defaultValue || "");
  187. const contentFloatingDiv = ref(false); // 控制浮动 DIV 的显示
  188. const floatingDivPosition = ref("bottom"); // 'bottom' 或 'top'
  189. const isFocused = ref(false); // 跟踪焦点状态
  190. // 附件相关变量(仅在传入 param 时初始化)
  191. let fjid = ref(null);
  192. let fjName = null;
  193. let mode = null;
  194. if (props.param && props.param.button) {
  195. fjid = ref(props.param.button.val);
  196. fjName = props.param.button.desc;
  197. mode = props.param.mode;
  198. }
  199. const showRequired = computed(() => {
  200. // 检查是否有验证规则(通过 window.ssVm 判断)
  201. const hasValidationRule = window.ssVm?.validations?.has(props.name);
  202. if (!hasValidationRule) return false;
  203. if (errMsg.value) return true;
  204. if (!inputValue.value) return true;
  205. return false;
  206. });
  207. // 计算floatdiv应该向上还是向下展开
  208. const calculateFloatingDivPosition = () => {
  209. nextTick(() => {
  210. const textarea = inputRef.value;
  211. if (!textarea) return;
  212. const rect = textarea.getBoundingClientRect();
  213. const viewportHeight = window.innerHeight;
  214. // 预估floatdiv的高度(最多5行 * 20px + 上下padding + border)
  215. const estimatedFloatDivHeight = 20 * 5 + 10 + 2; // 5行 + padding + border = 112px
  216. // 检查下方空间
  217. const spaceBelow = viewportHeight - rect.bottom;
  218. // 如果下方空间不足,且上方空间足够,则向上展开
  219. if (spaceBelow < estimatedFloatDivHeight && rect.top > estimatedFloatDivHeight) {
  220. floatingDivPosition.value = "top";
  221. } else {
  222. floatingDivPosition.value = "bottom";
  223. }
  224. });
  225. };
  226. // 计算floatdiv的top偏移量
  227. const getFloatingDivTop = computed(() => {
  228. if (props.height) {
  229. // 有height时,padding是5px
  230. return '5px';
  231. } else {
  232. // 没有height时是单行居中,需要计算居中位置
  233. // 假设input-container高度是32px(或者从CSS读取),单行20px
  234. // 居中偏移 = (容器高度 - 行高) / 2 = (32 - 20) / 2 = 6px
  235. return '6px';
  236. }
  237. });
  238. const validate = () => {
  239. if (window.ssVm) {
  240. const result = window.ssVm.validateField(props.name);
  241. console.log(result);
  242. errMsg.value = result.valid ? "" : result.message;
  243. }
  244. };
  245. // 使用 watch 监听 props.errTip 和 props.modelValue 的变化
  246. watch(
  247. () => props.errTip,
  248. (newVal) => {
  249. errMsg.value = newVal;
  250. },
  251. { immediate: true }
  252. );
  253. watch(
  254. () => props.modelValue,
  255. (newVal) => {
  256. inputValue.value = newVal;
  257. }
  258. );
  259. // 挂载时的逻辑
  260. onMounted(() => {
  261. errMsg.value = props.errTip;
  262. inputValue.value = props.modelValue || props.defaultValue || "";
  263. });
  264. // 计算并调整textarea的高度
  265. const adjustHeight = () => {
  266. nextTick(() => {
  267. const textarea = textareaRef.value;
  268. if (!textarea) return;
  269. // floatDiv的textarea始终自动计算高度,不受props.height影响
  270. // 重置高度以获得正确的scrollHeight
  271. textarea.style.height = "auto";
  272. // 计算新高度 - 统一限制为5行
  273. const lineHeight = parseInt(getComputedStyle(textarea).lineHeight, 10);
  274. const maxHeight = lineHeight * 5; // 统一为5行
  275. const newHeight = Math.min(textarea.scrollHeight, maxHeight);
  276. textarea.style.height = `${newHeight}px`;
  277. });
  278. };
  279. // 检查是否应该显示浮动窗口(需要同时满足:有焦点 + 内容超出)
  280. // 修复新增页面点击就出现floatdiv的问题 by xu 20251212
  281. const checkShouldShowFloatingDiv = () => {
  282. const textarea = inputRef.value;
  283. if (!textarea) return false;
  284. // 首先检查是否有内容,没有内容时不显示floatdiv by xu 20251212
  285. if (!inputValue.value || inputValue.value.toString().trim() === '') {
  286. console.log('[floatdiv] 内容为空,不显示floatdiv');
  287. return false;
  288. }
  289. // 判断内容是否超出 by xu 20251212
  290. // 同时检查横向和纵向溢出,任一方向溢出都应显示floatdiv
  291. // 纵向溢出需要加容差值,避免padding/border导致的误判 by xu 20251212
  292. const verticalTolerance = 5; // 容差值5px
  293. const isHorizontalOverflow = textarea.scrollWidth > textarea.clientWidth;
  294. const isVerticalOverflow = textarea.scrollHeight > textarea.clientHeight + verticalTolerance;
  295. const isOverflow = isHorizontalOverflow || isVerticalOverflow;
  296. console.log('[floatdiv] 溢出检测 - scrollWidth:', textarea.scrollWidth, 'clientWidth:', textarea.clientWidth, 'horizontalOverflow:', isHorizontalOverflow);
  297. console.log('[floatdiv] 溢出检测 - scrollHeight:', textarea.scrollHeight, 'clientHeight:', textarea.clientHeight, 'tolerance:', verticalTolerance, 'verticalOverflow:', isVerticalOverflow);
  298. const shouldShow = isFocused.value && isOverflow;
  299. console.log('[floatdiv] 最终判断 - isFocused:', isFocused.value, 'isOverflow:', isOverflow, 'shouldShow:', shouldShow);
  300. // 需要同时满足:有焦点 + 内容超出
  301. return shouldShow;
  302. };
  303. // 定义事件处理函数
  304. const onInput = (event) => {
  305. const newValue = event.target.value;
  306. inputValue.value = newValue;
  307. emit("update:modelValue", newValue);
  308. validate(); // 输入时验证
  309. nextTick(() => {
  310. // 检查是否需要显示浮动div
  311. contentFloatingDiv.value = checkShouldShowFloatingDiv();
  312. // 如果需要显示floatdiv,计算其位置
  313. if (contentFloatingDiv.value) {
  314. calculateFloatingDivPosition();
  315. }
  316. });
  317. adjustHeight();
  318. };
  319. const onFocus = (event) => {
  320. // 设置焦点状态为true
  321. isFocused.value = true;
  322. adjustHeight();
  323. // 检查是否应该显示浮动窗口
  324. nextTick(() => {
  325. contentFloatingDiv.value = checkShouldShowFloatingDiv();
  326. if (contentFloatingDiv.value) {
  327. calculateFloatingDivPosition();
  328. }
  329. });
  330. };
  331. // 失去焦点时进行验证
  332. const onBlur = (event) => {
  333. emit("blur", event.target);
  334. validate(); // 失焦时验证
  335. nextTick(() => {
  336. // 如果焦点不在 textarea 上,则隐藏浮动 div
  337. if (!document.activeElement.classList.contains("input-control")) {
  338. isFocused.value = false;
  339. contentFloatingDiv.value = false;
  340. }
  341. });
  342. };
  343. const onChange = (event) => {
  344. inputValue.value = event.target.value || "";
  345. emit("change", inputValue.value);
  346. };
  347. const onMouseover = (event) => {
  348. nextTick(() => {
  349. // setTimeout(contentFloatingDiv.value = true, 500)
  350. });
  351. };
  352. const onMouseleave = (event) => {
  353. // contentFloatingDiv.value = false
  354. };
  355. // 处理键盘按下事件,禁止回车换行 by xu 20251212
  356. const onKeydown = (event) => {
  357. // 如果不允许多行且按下的是回车键,阻止默认行为
  358. if (!props.multiline && event.key === 'Enter') {
  359. event.preventDefault();
  360. }
  361. };
  362. // 附件按钮点击处理(从 SsEditor 搬运)
  363. const onAttachmentClick = (e) => {
  364. e.preventDefault();
  365. if (!props.param || !props.param.button) {
  366. console.warn("未配置 param 参数");
  367. return;
  368. }
  369. console.log("附件点击了");
  370. console.log("param", props.param);
  371. console.log("cmsAddUrl", props.param.button.cmsAddUrl);
  372. // 如果 fjid 为空,先调用 cmsAddUrl 创建
  373. if (fjid.value == null || fjid.value == "") {
  374. $.ajax({
  375. type: "post",
  376. url: props.param.button.cmsAddUrl,
  377. async: false,
  378. data: {
  379. name: "fjid",
  380. ssNrObjName: "sh",
  381. ssNrObjId: "",
  382. },
  383. success: function (_fjid) {
  384. console.log("cmsAddUrl success", _fjid);
  385. fjid.value = _fjid;
  386. },
  387. });
  388. }
  389. // 构建参数字符串
  390. var str =
  391. "&nrid=T-" +
  392. fjid.value +
  393. "&objectId=" +
  394. fjid.value +
  395. "&objectName=" +
  396. fjName +
  397. "&callback=" +
  398. (window["fjidCallbackName"] || "");
  399. console.log("str", str);
  400. // 打开附件编辑对话框
  401. SS.openDialog({
  402. src: props.param.button.cmsUpdUrl + str,
  403. headerTitle: "编辑",
  404. width: 900,
  405. high: 664,
  406. zIndex: 51,
  407. });
  408. };
  409. return {
  410. errMsg,
  411. inputValue,
  412. showRequired,
  413. onInput,
  414. onBlur,
  415. onChange,
  416. onMouseover,
  417. onMouseleave,
  418. onKeydown, // 新增:键盘事件处理 by xu 20251212
  419. contentFloatingDiv,
  420. floatingDivPosition,
  421. getFloatingDivTop,
  422. inputRef,
  423. textareaRef,
  424. onFocus,
  425. onAttachmentClick,
  426. fjid, // 附件 ID,用于隐藏字段
  427. };
  428. },
  429. render() {
  430. const { resolveComponent, h } = Vue;
  431. const SsIcon = resolveComponent("ss-icon");
  432. const SsEditorIcon = resolveComponent("SsEditorIcon");
  433. // 构建主textarea的样式
  434. const mainTextareaStyle = {};
  435. if (this.height) {
  436. mainTextareaStyle.height = "auto"
  437. // mainTextareaStyle.paddingTop = '5px'; // 有高度时加上padding-top
  438. // mainTextareaStyle.paddingBottom = '5px'; // 有高度时加上padding-bottom
  439. } else {
  440. // 没有指定height时,固定为单行高度
  441. mainTextareaStyle.height = '20px'; // 行高20px
  442. mainTextareaStyle.lineHeight = '20px'; // 确保单行垂直居中
  443. mainTextareaStyle.display = 'flex';
  444. mainTextareaStyle.marginBottom = '5px';
  445. }
  446. // 如果有附件按钮,为按钮留出空间
  447. if (this.fj || this.param) {
  448. mainTextareaStyle.paddingRight = '75px';
  449. }
  450. const mainTextareaRows = this.height ? Math.floor(parseFloat('80px') / 20) : 1
  451. return h("div", { class: "input" }, [
  452. h("div", { class: "input-container", }, [
  453. h("div", { class: "input",style:"padding:5px 0" }, [
  454. h("textarea", {
  455. ref: "inputRef",
  456. class: "input-control",
  457. name: this.name,
  458. value: this.inputValue,
  459. onInput: this.onInput,
  460. onFocus: this.onFocus,
  461. onBlur: this.onBlur,
  462. onChange: this.onChange,
  463. onKeydown: this.onKeydown, // 新增:禁止回车换行 by xu 20251212
  464. placeholder: this.placeholder,
  465. onMouseover: this.onMouseover, // 监听鼠标悬停
  466. onMouseleave: this.onMouseleave, // 监听鼠标离开
  467. rows:mainTextareaRows,
  468. ...this.$attrs,
  469. style: mainTextareaStyle,
  470. autocomplete: "off",
  471. }),
  472. // 附件按钮(优先使用 param,兼容旧的 fj)
  473. this.param || this.fj
  474. ? h(
  475. "button",
  476. {
  477. type: "button",
  478. class: "fj-button",
  479. onClick: this.param ? this.onAttachmentClick : (e) => {
  480. e.preventDefault();
  481. console.log("附件配置:", this.fj);
  482. },
  483. },
  484. [
  485. h(SsEditorIcon, {
  486. class: "editor-icon-link",
  487. }),
  488. h("span", { class: "fj-button-text" }, "附件")
  489. ]
  490. )
  491. : null,
  492. // this.showRequired ? h("div", { class: "required" }) : null,
  493. ]),
  494. this.contentFloatingDiv || ""
  495. ? h("div", {
  496. class: "floating-div",
  497. style: this.floatingDivPosition === "bottom"
  498. ? {
  499. // 向下展开: 覆盖原输入框,top对齐首行
  500. top: this.getFloatingDivTop,
  501. bottom: 'auto',
  502. }
  503. : {
  504. // 向上展开: 同样覆盖原输入框,但从底部开始计算
  505. top: 'auto',
  506. bottom: this.height ? '5px' : '6px', // 对齐到原textarea的底部padding位置
  507. }
  508. }, [
  509. h("textarea", {
  510. ref: "textareaRef",
  511. class: "input-control",
  512. value: this.inputValue,
  513. onInput: this.onInput,
  514. onBlur: this.onBlur,
  515. onFocus: this.onFocus,
  516. onKeydown: this.onKeydown, // 新增:禁止回车换行 by xu 20251212
  517. onMouseover: this.onMouseover, // 监听鼠标悬停
  518. onMouseleave: this.onMouseleave, // 监听鼠标离开
  519. autocomplete: "off",
  520. onVnodeMounted: (vnode) => {
  521. vnode.el.focus();
  522. },
  523. }),
  524. ])
  525. : null,
  526. // this.errMsg ? h(SsValidate, { errMsg: this.errMsg }) : null,
  527. ]),
  528. // 附件相关的隐藏字段(仅在有 param 时才渲染)
  529. this.param && [
  530. // fjid 隐藏字段(只有当 fjid 有值时才渲染)
  531. this.fjid && this.fjid.value &&
  532. h("input", {
  533. type: "hidden",
  534. name: "fjid",
  535. value: this.fjid.value,
  536. }),
  537. // 其他隐藏字段根据 name 生成
  538. /* 去掉。文本框不需要(这是富文本才有的) Ben 20251205
  539. h("input", {
  540. type: "hidden",
  541. name: this.name.replace(/wj$/, "") + "Edit",
  542. value: this.inputValue
  543. }),
  544. */
  545. // h("input", {
  546. // type: "hidden",
  547. // name: this.name.replace(/wj$/, "") + "wj",
  548. // value: this.inputValue
  549. // }),
  550. /* 去掉。文本框不需要(这是富文本才有的) Ben 20251205
  551. h("input", {
  552. type: "hidden",
  553. name: "ueditorpath",
  554. value: this.name
  555. }),
  556. */
  557. ],
  558. ]);
  559. },
  560. };
  561. // ss-normal-input 登录输入
  562. const SsLoginInput = {
  563. name: "SsLoginInput",
  564. inheritAttrs: false,
  565. props: {
  566. errTip: {
  567. type: String,
  568. },
  569. type: {
  570. type: String,
  571. default: "text",
  572. },
  573. required: {
  574. type: Boolean,
  575. default: false,
  576. },
  577. placeholder: {
  578. type: String,
  579. default: "请输入",
  580. },
  581. name: {
  582. type: String,
  583. default: "",
  584. },
  585. defaultValue: [String, Number],
  586. modelValue: [String, Number],
  587. },
  588. emits: ["update:modelValue", "input", "blur", "change"], // 允许更新 v-model 绑定的值
  589. setup(props, { emit }) {
  590. const errMsg = ref("");
  591. const inputRef = ref(null);
  592. const textareaRef = ref(null);
  593. const inputValue = ref(props.modelValue || props.defaultValue || "");
  594. // 使用 watch 监听 props.errTip 和 props.modelValue 的变化
  595. watch(
  596. () => props.errTip,
  597. (newVal) => {
  598. errMsg.value = newVal;
  599. },
  600. { immediate: true }
  601. );
  602. watch(
  603. () => props.modelValue,
  604. (newVal) => {
  605. inputValue.value = newVal;
  606. }
  607. );
  608. // 挂载时的逻辑
  609. onMounted(() => {
  610. errMsg.value = props.errTip;
  611. inputValue.value = props.modelValue || props.defaultValue || "";
  612. });
  613. // 定义事件处理函数
  614. const onInput = (event) => {
  615. const newValue = event.target.value;
  616. inputValue.value = newValue;
  617. emit("update:modelValue", newValue);
  618. };
  619. return { inputValue, onInput, inputRef, textareaRef };
  620. },
  621. render() {
  622. return h("div", { class: "input" }, [
  623. h("div", { class: "input-container" }, [
  624. h("div", { class: "input" }, [
  625. h("input", {
  626. ref: "inputRef",
  627. class: "input-control",
  628. name: this.name,
  629. value: this.inputValue,
  630. onInput: this.onInput,
  631. type: this.type,
  632. placeholder: this.placeholder,
  633. required: this.required,
  634. ...this.$attrs,
  635. autocomplete: "off",
  636. }),
  637. this.required ? h("div", { class: "required" }) : null,
  638. ]),
  639. ]),
  640. ]);
  641. },
  642. };
  643. // ss-login-button
  644. const SsLoginButton = {
  645. name: "SsLoginButton",
  646. inheritAttrs: false,
  647. props: {
  648. class: {
  649. type: String,
  650. default: "",
  651. },
  652. text: {
  653. type: String,
  654. default: "",
  655. },
  656. type: {
  657. type: String,
  658. default: "button",
  659. },
  660. },
  661. emits: ["click"],
  662. setup(props, { emit }) {
  663. // 定义事件处理函数
  664. const onClick = (event) => {
  665. // 发射一个 'click' 事件,你可以传递所需的参数
  666. emit("click", event);
  667. };
  668. return { props, onClick };
  669. },
  670. render() {
  671. const SsIcon = resolveComponent("ss-icon");
  672. const SsLoginIcon = resolveComponent("ss-login-icon");
  673. return h(
  674. "button",
  675. { class: "login-button", type: this.type, onClick: this.onClick },
  676. [
  677. h("span", [h(SsLoginIcon, { class: this.class })]),
  678. h("span", {}, this.text),
  679. ]
  680. );
  681. },
  682. };
  683. // ss-objp 下拉选择
  684. const SsObjp = {
  685. name: "SsObjp",
  686. inheritAttrs: false,
  687. props: {
  688. onchange: { //在此属性传入onChange的window全局回调函数,函数唯一参数是当前选中值 Ben(20251217)
  689. type: String,
  690. required: false,
  691. },
  692. filter: {
  693. type: String,
  694. required: false,
  695. },
  696. cb: {
  697. type: String,
  698. required: true,
  699. },
  700. url: {
  701. type: String,
  702. required: true,
  703. },
  704. name: {
  705. type: String,
  706. required: true,
  707. },
  708. width: {
  709. type: String,
  710. default: "100%",
  711. },
  712. placeholder: {
  713. type: String,
  714. default: "请选择",
  715. },
  716. inp: {
  717. type: Boolean,
  718. default: false,
  719. },
  720. opt: {
  721. type: Array,
  722. default: () => [],
  723. },
  724. errTip: String,
  725. defaultValue: [String, Number],
  726. modelValue: [String, Number],
  727. direction: {
  728. type: String,
  729. default: "bottom",
  730. },
  731. },
  732. emits: ["update:modelValue", "input", "blur", "change"],
  733. setup(props, { emit }) {
  734. const canInput = props.inp;
  735. const errMsg = Vue.ref(props.errTip);
  736. const selectItem = Vue.ref({});
  737. let inputText = Vue.ref(""); // 用于存储输入框的文本
  738. const popupWinVisible = Vue.ref(false);
  739. const filteredOptions = Vue.ref(props.opt);
  740. const popupDirection = Vue.ref("bottom");
  741. const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
  742. // const showRequired = Vue.computed(() => {
  743. // const hasValidationRule = window.ssVm?.validations?.has(props.name);
  744. // if (!hasValidationRule) return false;
  745. // if (errMsg.value) return true;
  746. // if (!selectItem.value?.value) return true;
  747. // return false;
  748. // });
  749. const validate = () => {
  750. if (window.ssVm) {
  751. const result = window.ssVm.validateField(props.name);
  752. // console.log("validate", window.ssVm.validateField(props.name));
  753. errMsg.value = result.valid ? "" : result.message;
  754. }
  755. };
  756. //在objPicker界面,选中value对应的项
  757. const updateSelectItem = () => {
  758. // console.log(props.opt);
  759. const item = props.opt.find((it) => it.value === props.modelValue);
  760. if (item) {
  761. selectItem.value = item;
  762. inputText.value = item.label;
  763. } else {
  764. selectItem.value = { label: "", value: "" };
  765. inputText.value = "";
  766. }
  767. // validate();
  768. };
  769. Vue.watch(
  770. () => props.errTip,
  771. (newVal) => {
  772. errMsg.value = newVal;
  773. }
  774. );
  775. Vue.watch(() => props.modelValue, updateSelectItem, { immediate: true });
  776. Vue.watch(
  777. () => props.opt,
  778. (newVal) => {
  779. updateSelectItem();
  780. filteredOptions.value = [...newVal];
  781. // console.log("filteredOptions", filteredOptions.value);
  782. }
  783. );
  784. //初始化objPicker在页面刚打开时的默认值
  785. async function initDefaultValue() {
  786. try {
  787. if (props.url && props.cb && props.modelValue) {
  788. let objectPickerParam;
  789. let url = props.url;
  790. //如果有定义过滤器
  791. if (props.filter) {
  792. //包含HTML实体的JSON字符串转为JSON对象,如原字符串是{&quot;dwid&quot;:&quot;88&quot;},注意key也必需用单引号包着
  793. // const decodedString = props.filter.replace(/&quot;/g, '"'); // 转换为: {"dwid":"88"}
  794. // objectPickerParam = JSON.parse(decodedString); // 转为json对象
  795. const filterObj = props.filter; // 转为json对象
  796. for (let k in filterObj) {
  797. let v = filterObj[k];
  798. url += "&" + k + "=" + v;
  799. }
  800. objectPickerParam = props.filter; // 转为json对象
  801. objectPickerParam["input"] = props.inp;
  802. objectPickerParam["codebook"] = props.cb;
  803. // alert(url);
  804. } else {
  805. objectPickerParam = { input: props.inp, codebook: props.cb };
  806. }
  807. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  808. const params = new URLSearchParams();
  809. params.append("objectpickerparam", objectPickerParamStr);
  810. params.append("objectpickertype", "2");
  811. params.append("objectpickervalue", props.modelValue); //需回显的值
  812. // alert("1params:"+JSON.stringify(params));
  813. axios
  814. .post(props.url, params, {
  815. headers: {
  816. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  817. },
  818. })
  819. .then((response) => {
  820. // alert(JSON.stringify(response.data));
  821. if ("timeout" == response.data.statusText) {
  822. alert("网络超时!");
  823. return;
  824. }
  825. if (response.data.result) {
  826. const keys = Object.keys(response.data.result);
  827. if (keys.length === 1) {
  828. let code = keys[0];
  829. let desc = response.data.result[keys[0]];
  830. if (props.opt)
  831. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  832. else {
  833. props.opt = [];
  834. }
  835. props.opt.push({ label: desc, value: code });
  836. updateSelectItem();
  837. // alert('props.opt:'+JSON.stringify(props.opt));
  838. }
  839. }
  840. });
  841. }
  842. } catch (error) {
  843. // callback(null, error.message); // 失败回调,传递错误
  844. }
  845. }
  846. // Vue.onMounted(updateSelectItem);
  847. const doSelectItem = (item) => {
  848. emit("update:modelValue", item.value);
  849. selectItem.value = item;
  850. inputText.value = item.label;
  851. hidePopup();
  852. nextTick(() => {
  853. console.log(item.value + "@@@props.modelValue:" + props.modelValue);
  854. validate();
  855. if (window.ssVm) {
  856. // 遍历所有验证规则,找到依赖当前字段的规则
  857. for (const [field, rules] of window.ssVm.validations.entries()) {
  858. for (const rule of rules) {
  859. if (rule.opt?.relField === props.name) {
  860. // console.log("Found dependent field:", field); // 调试日志
  861. window.ssVm.validateField(field);
  862. }
  863. }
  864. }
  865. }
  866. });
  867. callGlobalOnchg(item.value); // 值变化时尝试调用全局onchange回调函数 Ben(20251217)
  868. };
  869. // 用于调用全局onchange回调函数 Ben(20251217)
  870. const callGlobalOnchg = (value) => {
  871. // 检查 onchange 属性是否提供了有效的函数名
  872. if (props.onchange && typeof props.onchange === 'string') {
  873. // 检查 window 对象上是否存在该函数
  874. if (typeof window !== 'undefined' && window[props.onchange] && typeof window[props.onchange] === 'function') {
  875. try {
  876. window[props.onchange](value) // 调用全局函数,并传入当前选中值
  877. } catch (error) {
  878. console.error(`调用全局函数 ${props.onchange} 时出错:`, error)
  879. }
  880. } else {
  881. console.warn(`全局函数 ${props.onchange} 未定义或不是一个函数。`)
  882. }
  883. }
  884. }
  885. //可录入的objPicker,更新下拉菜单选项
  886. async function updateOptionBYInputText(inpTxt) {
  887. try {
  888. let objectPickerParam;
  889. let url = props.url;
  890. if (props.url && props.cb) {
  891. //如果有定义过滤器
  892. if (props.filter) {
  893. const filterObj = props.filter; // 转为json对象
  894. for (let k in filterObj) {
  895. let v = filterObj[k];
  896. url += "&" + k + "=" + v;
  897. }
  898. //包含HTML实体的JSON字符串转为JSON对象,如原字符串是{&quot;dwid&quot;:&quot;88&quot;},注意key也必需用单引号包着
  899. // const decodedString = props.filter.replace(/&quot;/g, '"'); // 转换为: {"dwid":"88"}
  900. // objectPickerParam = JSON.parse(decodedString); // 转为json对象
  901. objectPickerParam = props.filter;
  902. objectPickerParam["input"] = props.inp;
  903. objectPickerParam["codebook"] = props.cb;
  904. // alert(url);
  905. } else {
  906. objectPickerParam = { input: props.inp, codebook: props.cb };
  907. }
  908. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  909. const params = new URLSearchParams();
  910. params.append("objectpickerparam", objectPickerParamStr);
  911. params.append("objectpickertype", "1");
  912. if (props.inp && props.inp === true) {//把"true"改为true Ben(20251209)
  913. params.append("objectpickersearchAll", 0); //只查录入的值
  914. params.append("objectpickerinput", inpTxt); //录入的值
  915. } else {
  916. params.append("objectpickersearchAll", 1);
  917. }
  918. axios
  919. .post(url, params, {
  920. headers: {
  921. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  922. },
  923. })
  924. .then((response) => {
  925. if ("timeout" == response.data.statusText) {
  926. alert("网络超时!");
  927. return;
  928. }
  929. // 先清空选项 by xu 20251212
  930. if (props.opt) {
  931. props.opt.length = 0;
  932. } else {
  933. props.opt = [];
  934. }
  935. if (response.data.result) {
  936. const keys = Object.keys(response.data.result);
  937. // console.log("params:"+params+"@@response.data:"+JSON.stringify(response.data));
  938. if (keys.length > 0) {
  939. for (let k in response.data.result) {
  940. props.opt.push({
  941. label: response.data.result[k],
  942. value: k,
  943. });
  944. }
  945. // console.log('###inpTxt:'+inpTxt+';');
  946. if (
  947. props.inp &&
  948. props.inp === true && //把"true"改为true Ben(20251209)
  949. inpTxt.length > 0
  950. ) {
  951. //对于可录入的,用已录入的值作过滤
  952. filteredOptions.value = props.opt.filter((option) =>
  953. option.label
  954. .toLowerCase()
  955. .includes(inputText.value.toLowerCase())
  956. );
  957. // 可录入的objPicker,当搜索结果只有一项时,自动选中这一项 by xu 20251212
  958. if (filteredOptions.value.length === 1) {
  959. const autoSelectItem = filteredOptions.value[0];
  960. console.log("[objp] 搜索结果只有一项,自动选中:", autoSelectItem);
  961. doSelectItem(autoSelectItem);
  962. return; // 自动选中后直接返回,不需要显示popup
  963. }
  964. filteredOptions.value.unshift({ label: "", value: "" });
  965. // console.log('###做了过滤:'+inputText.value.toLowerCase()+';');
  966. } else {
  967. filteredOptions.value = props.opt;
  968. filteredOptions.value.unshift({ label: "", value: "" });
  969. }
  970. console.log("props.opt11:" + JSON.stringify(props.opt));
  971. } else {
  972. // 没有数据时,清空过滤选项 by xu 20251212
  973. filteredOptions.value = [];
  974. console.log("[objp] 接口返回空数据");
  975. }
  976. } else {
  977. // result不存在时,清空过滤选项 by xu 20251212
  978. filteredOptions.value = [];
  979. console.log("[objp] 接口返回无result");
  980. }
  981. // 无论是否有数据,都显示popup by xu 20251212
  982. if (!popupWinVisible.value) {
  983. popupWinVisible.value = true;
  984. }
  985. });
  986. }
  987. } catch (error) {
  988. // callback(null, error.message); // 失败回调,传递错误
  989. }
  990. }
  991. // 计算弹出方向和最大高度的方法 by xu 20251212
  992. // 当空间不足时限制popup高度并显示滚动条
  993. const calculatePopupDirection = () => {
  994. // 1. 获取select容器元素
  995. const selectEl = document
  996. .querySelector(`[name="${props.name}"]`)
  997. ?.closest(".select-container");
  998. if (!selectEl) return;
  999. // 2. 获取位置信息
  1000. const selectRect = selectEl.getBoundingClientRect();
  1001. const viewportHeight = window.innerHeight;
  1002. // 3. 计算上下可用空间
  1003. const spaceBelow = viewportHeight - selectRect.bottom - 10; // 减10px留边距
  1004. const spaceAbove = selectRect.top - 10; // 减10px留边距
  1005. // 4. popup预估高度(假设每项36px,最多显示8项 + padding)
  1006. const estimatedPopupHeight = 300;
  1007. const minPopupHeight = 100; // 最小高度
  1008. console.log('[popup] 空间计算 - spaceAbove:', spaceAbove, 'spaceBelow:', spaceBelow, 'estimatedHeight:', estimatedPopupHeight);
  1009. // 5. 判断方向和最大高度 by xu 20251212
  1010. if (spaceBelow >= estimatedPopupHeight) {
  1011. // 下方空间足够,向下展开,不限制高度
  1012. popupDirection.value = "bottom";
  1013. popupMaxHeight.value = "none";
  1014. console.log('[popup] 向下展开,空间充足');
  1015. } else if (spaceAbove >= estimatedPopupHeight) {
  1016. // 上方空间足够,向上展开,不限制高度
  1017. popupDirection.value = "top";
  1018. popupMaxHeight.value = "none";
  1019. console.log('[popup] 向上展开,空间充足');
  1020. } else {
  1021. // 上下空间都不足,选择空间大的方向,并限制高度出滚动条
  1022. if (spaceBelow >= spaceAbove) {
  1023. popupDirection.value = "bottom";
  1024. popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px";
  1025. console.log('[popup] 向下展开,空间不足,限制高度:', popupMaxHeight.value);
  1026. } else {
  1027. popupDirection.value = "top";
  1028. popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px";
  1029. console.log('[popup] 向上展开,空间不足,限制高度:', popupMaxHeight.value);
  1030. }
  1031. }
  1032. };
  1033. //点击下拉菜单的文本区域时,会触发的方法
  1034. function togglePopup() {
  1035. //可录入的objPicker,更新下拉菜单选项
  1036. updateOptionBYInputText(inputText.value);
  1037. // popupWinVisible.value = !popupWinVisible.value;
  1038. Vue.nextTick(() => {
  1039. calculatePopupDirection();
  1040. });
  1041. }
  1042. const hidePopup = () => {
  1043. popupWinVisible.value = false;
  1044. };
  1045. //点击下拉菜单的三角形时,会触发的方法
  1046. // 添加toggle逻辑,点击时切换显示/隐藏 by xu 20251212
  1047. const suffixClick = () => {
  1048. // 如果popup已显示,则关闭 by xu 20251212
  1049. if (popupWinVisible.value) {
  1050. hidePopup();
  1051. console.log("[objp] 点三角关闭popup");
  1052. return;
  1053. }
  1054. //可录入的objPicker,更新下拉菜单选项
  1055. updateOptionBYInputText("");
  1056. Vue.nextTick(() => {
  1057. calculatePopupDirection();
  1058. });
  1059. console.log("[objp] 点三角打开popup");
  1060. };
  1061. //可录入的objPicker,录入项变化时,会触发
  1062. async function handleInputChange(event) {
  1063. inputText.value = event.target.value;
  1064. if (!inputText.value) {
  1065. inputText.value = "";
  1066. }
  1067. //可录入的objPicker,更新下拉菜单选项
  1068. updateOptionBYInputText(inputText.value);
  1069. // filteredOptions.value = props.opt.filter((option) =>
  1070. // option.label.toLowerCase().includes(inputText.value.toLowerCase())
  1071. // );
  1072. // if (!popupWinVisible.value) {
  1073. // popupWinVisible.value = true; // 确保下拉框在输入时打开
  1074. // }
  1075. }
  1076. Vue.onMounted(() => {
  1077. initDefaultValue();
  1078. window.addEventListener("resize", calculatePopupDirection);
  1079. });
  1080. Vue.onUnmounted(() => {
  1081. window.removeEventListener("resize", calculatePopupDirection);
  1082. });
  1083. return {
  1084. errMsg,
  1085. selectItem,
  1086. inputText,
  1087. canInput,
  1088. filteredOptions,
  1089. popupWinVisible,
  1090. popupDirection,
  1091. popupMaxHeight, // 添加popup最大高度 by xu 20251212
  1092. suffixClick,
  1093. togglePopup,
  1094. hidePopup,
  1095. doSelectItem,
  1096. handleInputChange,
  1097. };
  1098. },
  1099. template: `
  1100. <div class="input" style="position: relative" :style="{width: width}">
  1101. <div class="select-container" @mouseleave="hidePopup">
  1102. <div class="input" @click="togglePopup">
  1103. <input
  1104. type="hidden"
  1105. :name="name"
  1106. :value="selectItem.value"
  1107. .value="selectItem.value"
  1108. />
  1109. <input
  1110. v-model="inputText"
  1111. @input="handleInputChange"
  1112. v-if="canInput"
  1113. :placeholder="placeholder"
  1114. />
  1115. <input
  1116. v-else
  1117. :placeholder="placeholder"
  1118. :value="selectItem.label"
  1119. disabled
  1120. style="pointer-events: none;"
  1121. />
  1122. <div class="suffix" @click.stop="suffixClick">
  1123. <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
  1124. </div>
  1125. </div>
  1126. <!-- popup弹出层,添加maxHeight和overflowY支持空间不足时滚动 by xu 20251212 -->
  1127. <div v-show="popupWinVisible" class="popup-win" :class="popupDirection" :style="{ maxHeight: popupMaxHeight, overflowY: popupMaxHeight !== 'none' ? 'auto' : 'visible' }">
  1128. <div v-if="opt && opt.length && filteredOptions.length > 0" class="popup-content">
  1129. <div class="content-area">
  1130. <div v-for="(item, index) in filteredOptions" :key="index" @click="doSelectItem(item)" :class="{ active: item.value === selectItem.value }">
  1131. <span class="check-icon">
  1132. <ss-form-icon class="form-icon-select-checked" />
  1133. </span>
  1134. <span>{{ item.label }}</span>
  1135. </div>
  1136. </div>
  1137. </div>
  1138. <div v-else class="popup-content"><div class="content-area"><div class="content-area"> <span>无选项</span></div></div></div>
  1139. </div>
  1140. </div>
  1141. </div>
  1142. `,
  1143. };
  1144. // ss-hidden 隐藏字段组件
  1145. const SsHidden = {
  1146. name: "SsHidden",
  1147. props: {
  1148. modelValue: String,
  1149. name: {
  1150. type: String,
  1151. required: true,
  1152. },
  1153. rule: {
  1154. type: String,
  1155. required: true,
  1156. },
  1157. param: {
  1158. type: String,
  1159. required: true,
  1160. },
  1161. url: {
  1162. type: String,
  1163. required: true,
  1164. },
  1165. },
  1166. emits: ["update:modelValue"],
  1167. setup(props, { emit }) {
  1168. const errMsg = Vue.ref("");
  1169. const validate = () => {
  1170. if (window.ssVm) {
  1171. const result = window.ssVm.validateField(props.name);
  1172. console.log("validate", window.ssVm.validateField(props.name));
  1173. errMsg.value = result.valid ? "" : result.message;
  1174. }
  1175. };
  1176. Vue.onMounted(() => {
  1177. /**
  1178. * 初始化级联菜单值初始值思路:
  1179. * 1. 带隐藏字段(即带编码规则)的级联菜单
  1180. * 在隐藏字段这,可以取到要回显的值和编码规则,从而计算出各级下拉菜单要回显的值。
  1181. * 然后通过ajax取各级级联菜单的值回显。
  1182. * 2. 不带隐藏字段的级联,只能在各个下拉菜单的setup事件中通过ajax取回显值回显
  1183. */
  1184. // 当同组级联下拉菜单选中值变化时,会调用本隐藏字段下面这方法设置隐藏字段值
  1185. window.addEventListener(
  1186. "cascader-setHiddenVal-" + props.name,
  1187. (event) => {
  1188. const { value } = event.detail;
  1189. emit("update:modelValue", value);
  1190. console.log(value);
  1191. setTimeout(() => {
  1192. validate();
  1193. }, 50);
  1194. }
  1195. );
  1196. // 如果有初始值,触发回显过程
  1197. if (props.modelValue) {
  1198. console.log("级联隐藏字段,开始回显,初始值:", props.modelValue);
  1199. triggerCascaderEcho(props.modelValue);
  1200. validate();
  1201. }
  1202. });
  1203. // 触发级联回显
  1204. const triggerCascaderEcho = (code) => {
  1205. /**
  1206. * 开始回显,初始值: 440304
  1207. * 解析后的所有值: Array(3)0: "440000"1: "440300"2: "440304"length: 3[[Prototype]]: Array(0)
  1208. */
  1209. const values = parseHiddenCodeForAll(code, props.rule);
  1210. console.log("解析后的所有值:", values);
  1211. // 转换为 JSON 对象
  1212. // const paramObj = JSON.parse(props.param);
  1213. const paramObj = props.param;
  1214. let selectArr = paramObj.fieldOrd; //保存本组级联菜单项的数组,如:['hksheng','hkshi','hkxian']
  1215. if (selectArr.length != values.length) {
  1216. // alert('属性'+props.name+'的值'+code+'与级联菜单中下拉菜单的数目不匹配!');
  1217. return;
  1218. }
  1219. // 按顺序触发回显,并增加延迟确保数据加载
  1220. /**
  1221. * 通过隐藏字段的setup事件,
  1222. * 循环遍历各级下拉菜单,并触发定义在下拉菜单中的'cascader-echo'事件,
  1223. * 在此事件中完成每个下拉菜单回显值操作(只取当前要回显的键值对显示,
  1224. * 下拉菜单所有的值,在点击下拉菜单时,才通过ajax取)。
  1225. */
  1226. values.forEach((value, index) => {
  1227. if (value) {
  1228. setTimeout(() => {
  1229. let upperVal = undefined;
  1230. if (index != 0) {
  1231. upperVal = values[index - 1];
  1232. }
  1233. const echoEvent = new CustomEvent(
  1234. "cascader-echo-" + selectArr[index],
  1235. {
  1236. detail: {
  1237. name: props.name,
  1238. value: value,
  1239. // level: index + 1,
  1240. isAuto: true, // 标记为自动回显
  1241. upperVal: upperVal,
  1242. },
  1243. }
  1244. );
  1245. console.log(props.name + "--upperValue:" + upperVal);
  1246. window.dispatchEvent(echoEvent);
  1247. }, index * 500); // 每级增加500ms延迟
  1248. }
  1249. });
  1250. };
  1251. // 解析所有级别的代码
  1252. const parseHiddenCodeForAll = (code, rule) => {
  1253. if (!code || !rule) return [];
  1254. // 获取规则中每段的长度
  1255. const segments = [];
  1256. let currentChar = rule[0];
  1257. let currentLength = 1;
  1258. for (let i = 1; i < rule.length; i++) {
  1259. if (rule[i] === currentChar) {
  1260. currentLength++;
  1261. } else {
  1262. segments.push(currentLength);
  1263. currentChar = rule[i];
  1264. currentLength = 1;
  1265. }
  1266. }
  1267. segments.push(currentLength);
  1268. // 解析每一级的值
  1269. const values = [];
  1270. let position = 0;
  1271. segments.forEach((length, index) => {
  1272. const value = code
  1273. .substring(0, position + length)
  1274. .padEnd(rule.length, "0");
  1275. values.push(value);
  1276. position += length;
  1277. });
  1278. return values;
  1279. };
  1280. watchEffect(() => {});
  1281. return {};
  1282. },
  1283. template: `<input type="hidden" :name="name" :value="modelValue">`,
  1284. };
  1285. // ss-cascader 级联选择器
  1286. const SsCcp = {
  1287. name: "SsCcp",
  1288. inheritAttrs: false,
  1289. props: {
  1290. modelValue: String,
  1291. name: {
  1292. type: String,
  1293. required: true,
  1294. },
  1295. level: {
  1296. type: Number,
  1297. required: true,
  1298. },
  1299. opt: {
  1300. type: Array,
  1301. default: () => [],
  1302. },
  1303. placeholder: {
  1304. type: String,
  1305. default: "请选择",
  1306. },
  1307. width: {
  1308. type: String,
  1309. default: "150px",
  1310. },
  1311. direction: {
  1312. type: String,
  1313. default: "bottom",
  1314. },
  1315. mode: {
  1316. type: String,
  1317. default: "1",
  1318. },
  1319. //级联菜单配置参数,如果是数组,则代表本下拉菜单是多套级联菜单共用的第一级菜单。如果是对象,则只有一套级联菜单用此下拉菜单。
  1320. param: {
  1321. type: String,
  1322. required: true,
  1323. },
  1324. //向后台拿数据的url
  1325. url: {
  1326. type: String,
  1327. required: true,
  1328. },
  1329. },
  1330. emits: ["update:modelValue", "change"],
  1331. setup(props, { emit }) {
  1332. // alert('级联菜单初始化:'+props.name+':--:'+props.modelValue);
  1333. const selectItem = Vue.ref({ label: props.placeholder, value: "" });
  1334. const popupWinVisible = Vue.ref(false);
  1335. const isAutoEcho = Vue.ref(false); // 用于标记是否是自动回显
  1336. const upperValue = Vue.ref(""); //上级下拉菜单当前值,在初始化下拉菜单默认值时,和上级下拉菜单的值变化时,修改此upperValue变量
  1337. const popupDirection = Vue.ref("bottom");
  1338. const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
  1339. //有隐藏字段的下拉菜单,加载菜单项并展开事件
  1340. // 被上级下拉菜单选中值后,触发本下拉菜单刷新菜单项并弹出显示
  1341. window.addEventListener("cascader-open-" + props.name, async (event) => {
  1342. const { upperVal } = event.detail;
  1343. upperValue.value = upperVal;
  1344. console.log(
  1345. "22props.name:" +
  1346. props.name +
  1347. ",22props.upperValue:" +
  1348. upperValue.value
  1349. );
  1350. selectItem.value = ""; //清除本下拉菜单当前选中的值
  1351. emit("update:modelValue", ""); //通知父级
  1352. //清空下拉菜单,并设置第一项的值为placeholder
  1353. clearAndInit1stOpt();
  1354. //下个下拉菜单名
  1355. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1356. if (nextSelName) {
  1357. //清下个下拉菜单选中值和选项
  1358. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  1359. detail: {},
  1360. });
  1361. window.dispatchEvent(event);
  1362. }
  1363. showPopup();
  1364. });
  1365. //设置mode2的下级下拉菜单的上级菜单当前值
  1366. function setNextSelectUpperValue() {
  1367. //设置下级菜单的上级菜单当前值upperValue
  1368. let paramArr = undefined;
  1369. if (Array.isArray(props.param)) {
  1370. paramArr = props.param;
  1371. } else {
  1372. paramArr = [];
  1373. paramArr.push(props.param);
  1374. }
  1375. for (const oneParam of paramArr) {
  1376. //下个下拉菜单名
  1377. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  1378. if (nextSelName) {
  1379. setTimeout(() => {
  1380. const openNextEvent = new CustomEvent(
  1381. "cascade-setUpperVal-" + nextSelName,
  1382. {
  1383. detail: {
  1384. upperVal: props.modelValue,
  1385. },
  1386. }
  1387. );
  1388. window.dispatchEvent(openNextEvent);
  1389. }, 100);
  1390. }
  1391. } // end for
  1392. }
  1393. // 把上级 级联下拉菜单的值,设置进本组件的事件
  1394. window.addEventListener("cascade-setUpperVal-" + props.name, (event) => {
  1395. // alert('props.name:'+props.name+',props.upperValue:'+event.detail.upperVal);
  1396. const { upperVal } = event.detail;
  1397. upperValue.value = upperVal;
  1398. // console.log('props.name:'+props.name+',props.upperValue:'+upperValue.value);
  1399. });
  1400. //清空下拉菜单,并设置第一项的值为空
  1401. function clearAndInit1stOpt() {
  1402. if (props.opt)
  1403. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  1404. else {
  1405. props.opt = [];
  1406. }
  1407. props.opt.push({ label: "", value: "" });
  1408. }
  1409. //获取下一级下拉菜单,如果下一级下拉菜单不存在,则返回undefined
  1410. function getNextSel(selName, selNameArr) {
  1411. // 检查参数有效性
  1412. if (!Array.isArray(selNameArr) || selNameArr.length === 0) {
  1413. return undefined;
  1414. }
  1415. // 查找当前元素的索引
  1416. const currentIndex = selNameArr.indexOf(selName);
  1417. // 如果元素不存在或已经是最后一个元素,返回undefined
  1418. if (currentIndex === -1 || currentIndex === selNameArr.length - 1) {
  1419. return undefined;
  1420. }
  1421. // 返回下一个元素
  1422. return selNameArr[currentIndex + 1];
  1423. }
  1424. // 处理选择事件
  1425. const doSelectItem = (item) => {
  1426. selectItem.value = item;
  1427. emit("update:modelValue", item.value); //修改本下拉菜单在vue中保存的值
  1428. // alert('item.value:'+item.value);
  1429. if (props.mode === "1") {
  1430. // mode 1 模式:修改隐藏字段值
  1431. let event = new CustomEvent(
  1432. "cascader-setHiddenVal-" + props.param.combField,
  1433. {
  1434. detail: {
  1435. value: item.value,
  1436. },
  1437. }
  1438. );
  1439. window.dispatchEvent(event);
  1440. }
  1441. emit("change", item.value); //触发配置的change方法
  1442. //设置下级菜单的上级菜单当前值upperValue
  1443. let paramArr = undefined;
  1444. if (Array.isArray(props.param)) {
  1445. paramArr = props.param;
  1446. } else {
  1447. paramArr = [];
  1448. paramArr.push(props.param);
  1449. }
  1450. for (const oneParam of paramArr) {
  1451. //下个下拉菜单名
  1452. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  1453. if (nextSelName) {
  1454. setTimeout(() => {
  1455. const openNextEvent = new CustomEvent(
  1456. "cascader-open-" + nextSelName,
  1457. {
  1458. detail: {
  1459. upperVal: item.value,
  1460. },
  1461. }
  1462. );
  1463. window.dispatchEvent(openNextEvent);
  1464. }, 100);
  1465. }
  1466. } // end for
  1467. hidePopup();
  1468. //下个下拉菜单名
  1469. // let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1470. // if(nextSelName){
  1471. // // //设置下一级下拉菜单中保存的本下拉菜单值(upperValue)
  1472. // // event = new CustomEvent('cascade-setUpperVal-'+nextSelName, {
  1473. // // detail: {
  1474. // // value: item.value
  1475. // // }
  1476. // // });
  1477. // // window.dispatchEvent(event);
  1478. //
  1479. // //触发下一级下拉菜单,重新初始化下拉菜单项并弹出显示
  1480. // event = new CustomEvent('cascader-open-' +nextSelName, {
  1481. // detail: {
  1482. // upperVal: item.value
  1483. // }
  1484. // });
  1485. // window.dispatchEvent(event);
  1486. // }
  1487. // 只在手动选择时自动展开下一级
  1488. // if (!isAutoEcho.value) {
  1489. // const nextLevel = props.level + 1;
  1490. // setTimeout(() => {
  1491. // const openNextEvent = new CustomEvent('open-next-cascader', {
  1492. // detail: {
  1493. // name: props.name,
  1494. // level: nextLevel
  1495. // }
  1496. // });
  1497. // window.dispatchEvent(openNextEvent);
  1498. // }, 100);
  1499. // }
  1500. };
  1501. // 监听下一级展开事件 (仅 mode 2)
  1502. window.addEventListener("cascade-open", (event) => {
  1503. if (props.mode === "2") {
  1504. const { level } = event.detail;
  1505. if (level === props.level) {
  1506. popupWinVisible.value = true;
  1507. }
  1508. }
  1509. });
  1510. if (props.mode === "1") {
  1511. //如果是有隐藏字段的下拉菜单
  1512. // 监听回显事件
  1513. window.addEventListener(
  1514. "cascader-echo-" + props.name,
  1515. async (event) => {
  1516. const { name, value, isAuto, upperVal } = event.detail;
  1517. // level,
  1518. if (upperVal) {
  1519. upperValue.value = upperVal;
  1520. console.log(
  1521. "value:" +
  1522. value +
  1523. ",upperValue:" +
  1524. upperValue +
  1525. ",初始化级联组件时props.name:" +
  1526. props.name
  1527. );
  1528. }
  1529. // if (name === props.name && level === props.level) {
  1530. // 设置自动回显标记
  1531. isAutoEcho.value = true;
  1532. // if (props.opt.length === 0) {
  1533. // const loadDataEvent = new CustomEvent('cascader-load-data', {
  1534. // detail: {
  1535. // name: props.name,
  1536. // level: props.level,
  1537. // value: value
  1538. // }
  1539. // });
  1540. // window.dispatchEvent(loadDataEvent);
  1541. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  1542. //Vue.watch用于监听数据的变化,并在数据变化时执行特定的回调函数。
  1543. //这段代码使用了 Vue.js 的 watch API 来监听 props.opt 的变化,如果props.opt有变化,则自动
  1544. // const unwatch = Vue.watch(
  1545. // () => props.opt, // 监听的数据源(props.opt)
  1546. // (newOptions) => { // 回调函数
  1547. // if (newOptions.length > 0) { // 条件判断
  1548. // matchAndSelect(value); // 执行逻辑
  1549. // unwatch(); // 停止监听
  1550. // }
  1551. // },
  1552. // { immediate: true } // 配置:立即触发一次
  1553. // );
  1554. // } else {
  1555. // matchAndSelect(value);
  1556. // }
  1557. // 初始化级联菜单在页面刚打开时的默认值
  1558. async function initDefaultValue(value) {
  1559. try {
  1560. // alert(1);
  1561. if (props.url && props.param
  1562. // && props.modelValue 对于有rule编码规则的级联菜单(即mode=1),modelValue一定是空的,所以注释掉,修复mode=1的级联菜单无法回显问题。Ben(20251124)
  1563. ) {
  1564. // alert(2);
  1565. /**
  1566. * let objectPickerParam=
  1567. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  1568. * "\"name\":\"hksheng\"," +
  1569. * "\"cascadingName\":\"dq\",\"cascadingInputsName\":\"hkdqm\"," +
  1570. * "\"codebook\":\"sheng\"}",
  1571. * "objectpickertype":2,
  1572. * "objectpickervalue":"440000"
  1573. * };
  1574. */
  1575. const objectPickerParam = {
  1576. input: "false",
  1577. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  1578. name: props.name, //本下拉菜单名
  1579. cascadingName: props.param.name, //级联菜单名
  1580. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  1581. codebook: props.param.codebook,
  1582. };
  1583. const objectPickerParamStr =
  1584. JSON.stringify(objectPickerParam);
  1585. const params = new URLSearchParams();
  1586. params.append("objectpickerparam", objectPickerParamStr);
  1587. params.append("objectpickertype", "2");
  1588. params.append("objectpickervalue", value); //需回显的值
  1589. axios
  1590. .post(props.url, params, {
  1591. headers: {
  1592. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1593. },
  1594. })
  1595. .then((response) => {
  1596. // alert(JSON.stringify(response.data));
  1597. if ("timeout" == response.data.statusText) {
  1598. alert("网络超时!");
  1599. return;
  1600. }
  1601. if (response.data.result) {
  1602. const keys = Object.keys(response.data.result);
  1603. if (keys.length === 1) {
  1604. let code = keys[0];
  1605. let desc = response.data.result[keys[0]];
  1606. clearAndInit1stOpt();
  1607. props.opt.push({ label: desc, value: code });
  1608. if (value) matchAndSelect(value);
  1609. // updateSelectItem();
  1610. // alert('props.opt:'+JSON.stringify(props.opt));
  1611. }
  1612. }
  1613. });
  1614. }
  1615. } catch (error) {
  1616. alert(error);
  1617. // callback(null, error.message); // 失败回调,传递错误
  1618. }
  1619. }
  1620. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  1621. initDefaultValue(value);
  1622. // 延迟重置自动回显标记
  1623. setTimeout(() => {
  1624. isAutoEcho.value = false;
  1625. }, 500);
  1626. }
  1627. );
  1628. // 被上级下拉菜单触发的,清除选中值和下拉菜单选项
  1629. window.addEventListener(
  1630. "cascader-cleanOpt-" + props.name,
  1631. async (event) => {
  1632. upperValue.value = "";
  1633. selectItem.value = ""; //清除本下拉菜单当前选中的值
  1634. emit("update:modelValue", ""); //通知父级
  1635. //清空所有下拉菜单项
  1636. if (props.opt) {
  1637. props.opt.length = 0;
  1638. } else {
  1639. props.opt = [];
  1640. }
  1641. //下个下拉菜单名
  1642. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1643. // alert('nextSelName:'+nextSelName+'--,props.name:'+props.name);
  1644. if (nextSelName) {
  1645. //清下个下拉菜单选中值和选项
  1646. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  1647. detail: {},
  1648. });
  1649. window.dispatchEvent(event);
  1650. }
  1651. }
  1652. );
  1653. } else if (props.mode === "2") {
  1654. //没隐藏字段的下拉菜单,在这初始化默认值
  1655. let needInitParam = undefined;
  1656. if (Array.isArray(props.param)) {
  1657. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  1658. console.log("needInitParam最后一项:" + JSON.stringify(needInitParam));
  1659. } else {
  1660. needInitParam = props.param;
  1661. }
  1662. // 初始化级联菜单在页面刚打开时的默认值
  1663. async function initDefaultValue(value, param) {
  1664. try {
  1665. // alert(1);
  1666. if (props.url && param && props.modelValue) {
  1667. // alert(2);
  1668. /**
  1669. * let param=
  1670. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"rylbm,gwid\"," +
  1671. * "\"name\":\"gwid\",\"cascadingName\":\"rylb_gw\"," +
  1672. * "\"codebook\":\"gwByRylb\"}",
  1673. * "objectpickertype":2,
  1674. * "objectpickervalue":"102121"};
  1675. */
  1676. // alert('props.name:'+props.name+',props.param.fieldOrd:'+props.param.fieldOrd);
  1677. const objectPickerParam = {
  1678. input: "false",
  1679. cascadingLevel: param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  1680. name: props.name, //本下拉菜单名
  1681. cascadingName: param.name, //级联菜单名
  1682. codebook: param.codebook,
  1683. };
  1684. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  1685. const sendParams = new URLSearchParams();
  1686. sendParams.append("objectpickerparam", objectPickerParamStr);
  1687. sendParams.append("objectpickertype", "2");
  1688. sendParams.append("objectpickervalue", value); //需回显的值
  1689. axios
  1690. .post(props.url, sendParams, {
  1691. headers: {
  1692. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1693. },
  1694. })
  1695. .then((response) => {
  1696. // alert(JSON.stringify(response.data));
  1697. if ("timeout" == response.data.statusText) {
  1698. alert("网络超时!");
  1699. return;
  1700. }
  1701. if (response.data.result) {
  1702. const keys = Object.keys(response.data.result);
  1703. console.log(
  1704. "name:" +
  1705. props.name +
  1706. ",@@级联初始化默认值value:" +
  1707. value +
  1708. "--param:" +
  1709. JSON.stringify(param) +
  1710. "--objectPickerParamStr:" +
  1711. objectPickerParamStr +
  1712. "--response.data:" +
  1713. JSON.stringify(response.data)
  1714. );
  1715. if (keys.length === 1) {
  1716. let code = keys[0];
  1717. let desc = response.data.result[keys[0]];
  1718. if (props.opt)
  1719. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  1720. else {
  1721. props.opt = [];
  1722. }
  1723. props.opt.push({ label: desc, value: code });
  1724. if (value) matchAndSelect(value);
  1725. console.log(
  1726. "GOOD mode2回显的默认值:" +
  1727. JSON.stringify({ label: desc, value: code }) +
  1728. "--props.param:" +
  1729. JSON.stringify(param)
  1730. );
  1731. // updateSelectItem();
  1732. // alert('props.opt:'+JSON.stringify(props.opt));
  1733. }
  1734. }
  1735. });
  1736. }
  1737. } catch (error) {
  1738. alert(error);
  1739. // callback(null, error.message); // 失败回调,传递错误
  1740. }
  1741. // 重置自动回显标记
  1742. isAutoEcho.value = false;
  1743. }
  1744. // 初始化级联菜单在页面刚打开时的默认值
  1745. initDefaultValue(props.modelValue, needInitParam);
  1746. //设置mode2的下级下拉菜单的上级菜单当前值
  1747. setNextSelectUpperValue();
  1748. }
  1749. //选中要回显的默认值
  1750. const matchAndSelect = (value) => {
  1751. const matchedOption = props.opt.find((opt) => opt.value === value);
  1752. if (matchedOption) {
  1753. selectItem.value = matchedOption;
  1754. emit("update:modelValue", value);
  1755. emit("change", value);
  1756. }
  1757. };
  1758. // 计算弹出方向和最大高度的方法 by xu 20251212
  1759. // 当空间不足时限制popup高度并显示滚动条
  1760. const calculatePopupDirection = () => {
  1761. // 1. 获取select容器元素
  1762. const selectEl = document.querySelector(
  1763. `[name="${props.name}"]`
  1764. )?.nextElementSibling;
  1765. console.log("selectEl:" + selectEl, props.name);
  1766. if (!selectEl) return;
  1767. // 2. 获取位置信息
  1768. const selectRect = selectEl.getBoundingClientRect();
  1769. const viewportHeight = window.innerHeight;
  1770. // 3. 计算上下可用空间 by xu 20251212
  1771. const spaceBelow = viewportHeight - selectRect.bottom - 10; // 减10px留边距
  1772. const spaceAbove = selectRect.top - 10; // 减10px留边距
  1773. // 4. popup预估高度(假设每项36px,最多显示8项 + padding)
  1774. const estimatedPopupHeight = 300;
  1775. const minPopupHeight = 100; // 最小高度
  1776. console.log('[popup] 空间计算 - spaceAbove:', spaceAbove, 'spaceBelow:', spaceBelow, 'estimatedHeight:', estimatedPopupHeight);
  1777. // 5. 判断方向和最大高度 by xu 20251212
  1778. if (spaceBelow >= estimatedPopupHeight) {
  1779. // 下方空间足够,向下展开,不限制高度
  1780. popupDirection.value = "bottom";
  1781. popupMaxHeight.value = "none";
  1782. console.log('[popup] 向下展开,空间充足');
  1783. } else if (spaceAbove >= estimatedPopupHeight) {
  1784. // 上方空间足够,向上展开,不限制高度
  1785. popupDirection.value = "top";
  1786. popupMaxHeight.value = "none";
  1787. console.log('[popup] 向上展开,空间充足');
  1788. } else {
  1789. // 上下空间都不足,选择空间大的方向,并限制高度出滚动条
  1790. if (spaceBelow >= spaceAbove) {
  1791. popupDirection.value = "bottom";
  1792. popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px";
  1793. console.log('[popup] 向下展开,空间不足,限制高度:', popupMaxHeight.value);
  1794. } else {
  1795. popupDirection.value = "top";
  1796. popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px";
  1797. console.log('[popup] 向上展开,空间不足,限制高度:', popupMaxHeight.value);
  1798. }
  1799. }
  1800. };
  1801. //级联菜单点击事件
  1802. const togglePopup = () => {
  1803. if (!popupWinVisible.value) {
  1804. //如果当前下拉菜单是隐藏的,先ajax重新加载下拉菜单项,再显示。
  1805. showPopup();
  1806. } else {
  1807. hidePopup();
  1808. }
  1809. };
  1810. //显示下拉菜单,在此之前先清除下拉菜单项
  1811. const showPopup = () => {
  1812. //清空下拉菜单,并设置第一项的值为空
  1813. clearAndInit1stOpt();
  1814. Vue.nextTick(() => {
  1815. calculatePopupDirection();
  1816. });
  1817. let url = props.url;
  1818. let filterObj = props.param.filter;
  1819. if (filterObj) {
  1820. for (let k in filterObj) {
  1821. let v = filterObj[k];
  1822. url += "&" + k + "=" + v;
  1823. }
  1824. }
  1825. if (props.mode === "1") {
  1826. //如果是有隐藏字段的下拉菜单
  1827. console.log("666url:" + url);
  1828. // alert('url:'+url);
  1829. // 获取级联菜单所有下拉菜单项
  1830. async function getSelectItems(value) {
  1831. try {
  1832. // alert(1);
  1833. if (props.url && props.param) {
  1834. // alert(2);
  1835. /**
  1836. * param={"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  1837. * "\"name\":\"hksheng\",\"cascadingName\":\"dq\"," +
  1838. * "\"cascadingInputsName\":\"hkdqm\",\"codebook\":\"sheng\"}",
  1839. * "objectpickertype":1,//2表示获取要回显的一项,1表示获取所有下拉菜单项
  1840. * "upperValue":"440000"
  1841. * };
  1842. */
  1843. const objectPickerParam = {
  1844. input: "false",
  1845. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  1846. name: props.name, //本下拉菜单名
  1847. cascadingName: props.param.name, //级联菜单名
  1848. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  1849. codebook: props.param.codebook,
  1850. };
  1851. console.log("mode1 upperValue.value:" + upperValue.value);
  1852. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  1853. const params = new URLSearchParams();
  1854. params.append("objectpickerparam", objectPickerParamStr);
  1855. params.append("objectpickertype", "1");
  1856. if (upperValue.value) {
  1857. params.append("upperValue", upperValue.value);
  1858. }
  1859. // params.append('objectpickervalue', value); //需回显的值
  1860. axios
  1861. .post(url, params, {
  1862. headers: {
  1863. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1864. },
  1865. })
  1866. .then((response) => {
  1867. if ("timeout" == response.data.statusText) {
  1868. alert("网络超时!");
  1869. return;
  1870. }
  1871. if (response.data.result) {
  1872. const keys = Object.keys(response.data.result);
  1873. console.log(
  1874. "params:" +
  1875. params +
  1876. "@@response.data:" +
  1877. JSON.stringify(response.data)
  1878. );
  1879. if (keys.length > 0) {
  1880. for (let k in response.data.result) {
  1881. props.opt.push({
  1882. label: response.data.result[k],
  1883. value: k,
  1884. });
  1885. }
  1886. console.log("props.opt11:" + JSON.stringify(props.opt));
  1887. } else {
  1888. // 没有数据时打印日志 by xu 20251212
  1889. console.log("[ccp mode1] 接口返回空数据");
  1890. }
  1891. } else {
  1892. // result不存在时打印日志 by xu 20251212
  1893. console.log("[ccp mode1] 接口返回无result");
  1894. }
  1895. // 无论是否有数据,都显示popup by xu 20251212
  1896. if (!popupWinVisible.value) {
  1897. popupWinVisible.value = true;
  1898. }
  1899. });
  1900. }
  1901. } catch (error) {
  1902. alert(error);
  1903. // callback(null, error.message); // 失败回调,传递错误
  1904. }
  1905. }
  1906. getSelectItems(props.modelValue);
  1907. } else if (props.mode === "2") {
  1908. //没隐藏字段的下拉菜单
  1909. let needInitParam = undefined;
  1910. if (Array.isArray(props.param)) {
  1911. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  1912. console.log(
  1913. "needInitParam最后一项:" + JSON.stringify(needInitParam)
  1914. );
  1915. } else {
  1916. needInitParam = props.param;
  1917. }
  1918. // 获取级联菜单所有下拉菜单项
  1919. async function getSelectItems(value, sendParam) {
  1920. try {
  1921. // alert(1);
  1922. if (props.url && sendParam) {
  1923. // alert(2);
  1924. /**
  1925. * param="{\"input\":\"false\",\"cascadingLevel\":\"dwid,sjryid\",
  1926. * \"ryid\":\"111121\",\"name\":\"sjryid\",
  1927. * \"cascadingName\":\"dw_sjry\",\"codebook\":\"sjryByDw\"}"
  1928. */
  1929. const objectPickerParam = {
  1930. input: "false",
  1931. cascadingLevel: sendParam.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  1932. name: props.name, //本下拉菜单名
  1933. cascadingName: sendParam.name, //级联菜单名
  1934. codebook: sendParam.codebook,
  1935. };
  1936. console.log("mode2 upperValue.value:" + upperValue.value);
  1937. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  1938. const params = new URLSearchParams();
  1939. params.append("objectpickerparam", objectPickerParamStr);
  1940. params.append("objectpickertype", "1");
  1941. if (upperValue.value) {
  1942. params.append("upperValue", upperValue.value);
  1943. }
  1944. // params.append('objectpickervalue', value); //需回显的值
  1945. axios
  1946. .post(url, params, {
  1947. headers: {
  1948. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1949. },
  1950. })
  1951. .then((response) => {
  1952. if ("timeout" == response.data.statusText) {
  1953. alert("网络超时!");
  1954. return;
  1955. }
  1956. if (response.data.result) {
  1957. const keys = Object.keys(response.data.result);
  1958. console.log(
  1959. "params:" +
  1960. params +
  1961. "@@response.data:" +
  1962. JSON.stringify(response.data)
  1963. );
  1964. if (keys.length > 0) {
  1965. for (let k in response.data.result) {
  1966. props.opt.push({
  1967. label: response.data.result[k],
  1968. value: k,
  1969. });
  1970. }
  1971. console.log("props.opt11:" + JSON.stringify(props.opt));
  1972. } else {
  1973. // 没有数据时打印日志 by xu 20251212
  1974. console.log("[ccp mode2] 接口返回空数据");
  1975. }
  1976. } else {
  1977. // result不存在时打印日志 by xu 20251212
  1978. console.log("[ccp mode2] 接口返回无result");
  1979. }
  1980. // 无论是否有数据,都显示popup by xu 20251212
  1981. if (!popupWinVisible.value) {
  1982. popupWinVisible.value = true;
  1983. }
  1984. });
  1985. }
  1986. } catch (error) {
  1987. alert(error);
  1988. // callback(null, error.message); // 失败回调,传递错误
  1989. }
  1990. }
  1991. getSelectItems(props.modelValue, needInitParam);
  1992. // popupWinVisible.value = !popupWinVisible.value;
  1993. }
  1994. };
  1995. const hidePopup = () => {
  1996. popupWinVisible.value = false;
  1997. };
  1998. // 合并所有的 onMounted 逻辑
  1999. Vue.onMounted(() => {
  2000. window.addEventListener("resize", calculatePopupDirection);
  2001. // 1. 监听展开下一级事件
  2002. window.addEventListener("open-next-cascader", (event) => {
  2003. const { name, level } = event.detail;
  2004. if (name === props.name && level === props.level) {
  2005. popupWinVisible.value = true;
  2006. }
  2007. });
  2008. // 2. 监听级联事件
  2009. window.addEventListener("cascader-change", (event) => {
  2010. const { name, level, value } = event.detail;
  2011. if (name === props.name && level < props.level) {
  2012. selectItem.value = { label: "", value: "" };
  2013. emit("update:modelValue", "");
  2014. if (ssHidden) {
  2015. ssHidden.updateValue(value);
  2016. }
  2017. }
  2018. });
  2019. });
  2020. Vue.onUnmounted(() => {
  2021. window.removeEventListener("resize", calculatePopupDirection);
  2022. });
  2023. // 监听值变化,处理回显 (mode 2)
  2024. Vue.watch(
  2025. () => props.modelValue,
  2026. (newVal) => {
  2027. if (props.mode === "2" && newVal) {
  2028. // 使用 watchEffect 替代嵌套的 watch
  2029. Vue.watchEffect(() => {
  2030. if (props.opt.length > 0) {
  2031. const matchedOption = props.opt.find(
  2032. (opt) => opt.value === newVal
  2033. );
  2034. if (matchedOption) {
  2035. selectItem.value = matchedOption;
  2036. }
  2037. }
  2038. });
  2039. } else {
  2040. // 原有的值变化处理
  2041. const item = props.opt.find((it) => it.value === newVal);
  2042. if (item) {
  2043. selectItem.value = item;
  2044. } else {
  2045. selectItem.value = { label: "", value: "" };
  2046. }
  2047. }
  2048. },
  2049. { immediate: true }
  2050. );
  2051. // 监听选项变化,当数据加载完成时进行匹配
  2052. Vue.watch(
  2053. () => props.opt,
  2054. (newOptions) => {
  2055. if (newOptions.length > 0) {
  2056. const matchedOption = newOptions.find(
  2057. (opt) => opt.value === selectItem.value.value
  2058. );
  2059. if (matchedOption) {
  2060. selectItem.value = matchedOption;
  2061. emit("update:modelValue", matchedOption.value);
  2062. emit("change", matchedOption.value);
  2063. }
  2064. }
  2065. }
  2066. );
  2067. return {
  2068. selectItem,
  2069. popupWinVisible,
  2070. popupDirection,
  2071. popupMaxHeight, // 添加popup最大高度 by xu 20251212
  2072. togglePopup,
  2073. hidePopup,
  2074. doSelectItem,
  2075. };
  2076. },
  2077. template: `
  2078. <div class="input ss-ccp-container" style="position: relative" :style="{width: width}">
  2079. <input type="hidden" :name="name" :value="modelValue">
  2080. <div class="select-container" @mouseleave="hidePopup">
  2081. <div class="input" @click="togglePopup">
  2082. <input
  2083. type="hidden"
  2084. :name="name"
  2085. :value="selectItem.value"
  2086. />
  2087. <input
  2088. :placeholder="placeholder"
  2089. :value="selectItem.label"
  2090. disabled
  2091. style="pointer-events: none;"
  2092. />
  2093. <div class="suffix">
  2094. <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
  2095. </div>
  2096. </div>
  2097. <!-- popup弹出层,添加maxHeight和overflowY支持空间不足时滚动 by xu 20251212 -->
  2098. <div v-show="popupWinVisible" class="popup-win " :class="popupDirection" :style="{ maxHeight: popupMaxHeight, overflowY: popupMaxHeight !== 'none' ? 'auto' : 'visible' }">
  2099. <div v-if="opt && opt.length > 0" class="popup-content">
  2100. <div class="content-area">
  2101. <div
  2102. v-for="(item, index) in opt"
  2103. :key="index"
  2104. @click="doSelectItem(item)"
  2105. :class="{ active: item.value === selectItem.value }"
  2106. >
  2107. <span class="check-icon">
  2108. <ss-form-icon class="form-icon-select-checked" />
  2109. </span>
  2110. <span>{{ item.label }}</span>
  2111. </div>
  2112. </div>
  2113. </div>
  2114. <div v-else class="popup-content">
  2115. <div class="content-area">
  2116. <div class="content-area">
  2117. <span>无选项</span>
  2118. </div>
  2119. </div>
  2120. </div>
  2121. </div>
  2122. </div>
  2123. </div>
  2124. `,
  2125. };
  2126. // ss-date-picker 日期时间选择器组件
  2127. const SsDatePicker = {
  2128. name: "SsDatePicker",
  2129. props: {
  2130. modelValue: {
  2131. type: [String, Number, Date],
  2132. default: "",
  2133. },
  2134. name: {
  2135. type: String,
  2136. required: true,
  2137. },
  2138. type: {
  2139. type: String,
  2140. default: "date",
  2141. validator: (value) => ["date", "datetime", "time"].includes(value),
  2142. },
  2143. fmt: {
  2144. type: String,
  2145. default: null,
  2146. },
  2147. placeholder: {
  2148. type: String,
  2149. default: "",
  2150. },
  2151. width: {
  2152. type: String,
  2153. default: "100%",
  2154. },
  2155. },
  2156. emits: ["update:modelValue"],
  2157. setup(props, { emit }) {
  2158. const errMsg = ref("");
  2159. const validate = () => {
  2160. if (window.ssVm) {
  2161. const result = window.ssVm.validateField(props.name);
  2162. console.log("validate", window.ssVm.validateField(props.name));
  2163. errMsg.value = result.valid ? "" : result.message;
  2164. }
  2165. };
  2166. // 根据type确定默认格式
  2167. const defaultFormat = computed(() => {
  2168. switch (props.type) {
  2169. case "datetime":
  2170. return "YYYY-MM-DD HH:mm:ss";
  2171. case "date":
  2172. return "YYYY-MM-DD";
  2173. case "time":
  2174. return "HH:mm:ss";
  2175. }
  2176. });
  2177. const convertJavaFormatToElement = (javaFormat) => {
  2178. if (!javaFormat) return null;
  2179. return javaFormat
  2180. .replace("yyyy", "YYYY")
  2181. .replace("MM", "MM")
  2182. .replace("dd", "DD")
  2183. .replace("HH", "HH")
  2184. .replace("mm", "mm")
  2185. .replace("ss", "ss");
  2186. };
  2187. const finalFormat = computed(() => {
  2188. if (props.fmt) {
  2189. return convertJavaFormatToElement(props.fmt);
  2190. }
  2191. return defaultFormat.value;
  2192. });
  2193. // 使用 resolveComponent 获取组件
  2194. const ElDatePicker = resolveComponent("ElDatePicker");
  2195. const ElTimePicker = resolveComponent("ElTimePicker");
  2196. const SsFormIcon = resolveComponent("SsFormIcon");
  2197. const ElIcon = resolveComponent("ElIcon");
  2198. const handleValueUpdate = (val) => {
  2199. emit("update:modelValue", val);
  2200. emit("change", val); // 同时触发 change 事件
  2201. setTimeout(() => {
  2202. validate();
  2203. }, 50);
  2204. };
  2205. const dateType = computed(() => {
  2206. const fmt = props.fmt || "";
  2207. if (fmt.includes("HH:mm:ss")) {
  2208. return "datetime";
  2209. } else if (fmt.includes("HH:mm")) {
  2210. return "datetime";
  2211. } else if (fmt.includes("mm:ss")) {
  2212. return "time";
  2213. }
  2214. return "date";
  2215. });
  2216. let useTimePicker = true;
  2217. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  2218. if (props.fmt) {
  2219. //有fmt属性,则以fmt属性优先判断类型
  2220. if (/[dMy]/.test(props.fmt)) {
  2221. //如果有传入日期格式,且含年月日
  2222. useTimePicker = false;
  2223. } else {
  2224. useTimePicker = true;
  2225. }
  2226. } else if (props.type !== "time") {
  2227. useTimePicker = false;
  2228. }
  2229. return () =>
  2230. h("div", { class: "ss-date-picker", style: { width: props.width } }, [
  2231. h("input", {
  2232. type: "hidden",
  2233. name: props.name,
  2234. value: props.modelValue,
  2235. }),
  2236. // 选择组件
  2237. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  2238. modelValue: props.modelValue,
  2239. "onUpdate:modelValue": handleValueUpdate,
  2240. type: dateType.value,
  2241. format: finalFormat.value,
  2242. "value-format": finalFormat.value,
  2243. clearable: true,
  2244. placeholder: props.placeholder,
  2245. class: "custom-date-picker", // 用于自定义样式
  2246. "time-arrow-control": props.type === "datetime", // 修改这里
  2247. size: "large", // 添加这一行,改为 large 尺寸
  2248. style: { width: "100%" },
  2249. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  2250. }),
  2251. ]);
  2252. },
  2253. };
  2254. // ss-icon 图标
  2255. // v3.0 增加 class 属性分支:有 class 走新逻辑,否则走 v1.0 逻辑 by xu 20251212
  2256. // v3.0 用法: <ss-icon class="icon-obj-ry menu-icon" />
  2257. // v1.0 用法: <ss-icon name="setting" size="20px" />
  2258. const SsIcon = {
  2259. name: "SsIcon",
  2260. // v3.0 禁用 class 透传,手动处理 by xu 20251215
  2261. inheritAttrs: false,
  2262. props: {
  2263. // v1.0: 以下为旧属性
  2264. name: { type: String },
  2265. size: { type: [Number, String], default: 16 },
  2266. unit: { type: String, default: "px" },
  2267. color: String,
  2268. type: {
  2269. type: String,
  2270. default: ssIcon.name,
  2271. validator: function (value) {
  2272. return [ssIcon, commonIcon].some((icon) => icon.name === value);
  2273. },
  2274. },
  2275. },
  2276. emits: ["update:modelValue", "input", "blur", "change"],
  2277. setup(props, { emit, attrs }) {
  2278. // v3.0 分支:有 class 属性时直接渲染(从 attrs 获取) by xu 20251215
  2279. if (attrs.class) {
  2280. return () => h("i", { class: attrs.class + ' icon-container' });
  2281. }
  2282. // v1.0 分支:原有逻辑
  2283. const useIconType = computed(() => {
  2284. return [ssIcon, commonIcon].find(
  2285. (iconConfig) => iconConfig.name === props.type
  2286. );
  2287. });
  2288. const iconName = computed(() => {
  2289. const iconConfig = useIconType.value; // 注意:使用 .value 来访问响应式引用的值
  2290. if (!iconConfig) {
  2291. console.error(`Icon type "${props.type}" not found.`);
  2292. return "";
  2293. }
  2294. const iconType = iconConfig.types[props.name];
  2295. if (!iconType) {
  2296. console.error(
  2297. `Icon name "${props.name}" not found in type "${props.type}".`
  2298. );
  2299. return "";
  2300. }
  2301. return `${iconConfig.prefix}${iconType}`;
  2302. });
  2303. // 类似地,你可以计算 fontFamily 和 style
  2304. const fontFamily = computed(() => {
  2305. return useIconType.value ? useIconType.value.family : "";
  2306. });
  2307. // console.log(iconName.value,fontFamily.value)
  2308. const style = computed(() => {
  2309. const sizeStyle = isNum(props.size)
  2310. ? `${props.size}${props.unit}`
  2311. : props.size;
  2312. const styleObj = {
  2313. fontSize: sizeStyle,
  2314. color: props.color || "",
  2315. };
  2316. return toStyleStr(styleObj);
  2317. });
  2318. // 使用渲染函数定义模板逻辑
  2319. return () =>
  2320. h("i", {
  2321. class: ["icon-container", iconName.value, fontFamily.value],
  2322. style: style.value,
  2323. });
  2324. },
  2325. };
  2326. // 通用icon
  2327. const SsCommonIcon = {
  2328. name: "SsCommonIcon",
  2329. props: {
  2330. class: {
  2331. type: String,
  2332. required: true,
  2333. },
  2334. },
  2335. setup(props) {
  2336. return () =>
  2337. h("i", {
  2338. class: props.class + " common-icon",
  2339. });
  2340. },
  2341. };
  2342. // 登录页icon
  2343. const SsLoginIcon = {
  2344. name: "SsLoginIcon",
  2345. props: {
  2346. class: {
  2347. type: String,
  2348. required: true,
  2349. },
  2350. },
  2351. setup(props) {
  2352. return () =>
  2353. h("div", {
  2354. class: props.class + " login-icon",
  2355. });
  2356. },
  2357. };
  2358. // 弹窗icon
  2359. const SsDialogIcon = {
  2360. name: "SsDialogIcon",
  2361. props: {
  2362. class: {
  2363. type: String,
  2364. required: true,
  2365. },
  2366. },
  2367. setup(props) {
  2368. return () =>
  2369. h("i", {
  2370. class: props.class + " dialog-icon",
  2371. });
  2372. },
  2373. };
  2374. // 全局左侧导航图标组件
  2375. const SsNavIcon = {
  2376. name: "SsNavIcon",
  2377. props: {
  2378. class: {
  2379. type: String,
  2380. required: true,
  2381. },
  2382. },
  2383. setup(props) {
  2384. return () =>
  2385. h("div", {
  2386. class: props.class + " nav-icon",
  2387. });
  2388. },
  2389. };
  2390. // 顶部工具栏图标组件
  2391. const SsHeaderIcon = {
  2392. name: "SsHeaderIcon",
  2393. props: {
  2394. class: {
  2395. type: String,
  2396. required: true,
  2397. },
  2398. },
  2399. setup(props) {
  2400. return () =>
  2401. h("div", {
  2402. class: props.class + " header-icon",
  2403. });
  2404. },
  2405. };
  2406. // 全局菜单图标组件
  2407. const SsGolbalMenuIcon = {
  2408. name: "SsGolbalMenuIcon",
  2409. props: {
  2410. class: {
  2411. type: String,
  2412. required: true,
  2413. },
  2414. },
  2415. setup(props) {
  2416. return () =>
  2417. h("div", {
  2418. class: props.class + " global-menu-icon",
  2419. });
  2420. },
  2421. };
  2422. // 全局查询列表卡片图标
  2423. const SsCartListIcon = {
  2424. name: "SsCartListIcon",
  2425. props: {
  2426. class: {
  2427. type: String,
  2428. required: true,
  2429. },
  2430. },
  2431. setup(props) {
  2432. return () =>
  2433. h("div", {
  2434. class: props.class + " cart-list-icon",
  2435. });
  2436. },
  2437. };
  2438. // 全局底部工具栏图标组件
  2439. const SsQuickIcon = {
  2440. name: "SsQuickIcon",
  2441. props: {
  2442. class: {
  2443. type: String,
  2444. required: true,
  2445. },
  2446. },
  2447. setup(props) {
  2448. return () =>
  2449. h("div", {
  2450. class: props.class + " quick-icon",
  2451. });
  2452. },
  2453. };
  2454. // 表单组件icon
  2455. const SsFormIcon = {
  2456. name: "SsFormIcon",
  2457. props: {
  2458. class: {
  2459. type: String,
  2460. required: true,
  2461. },
  2462. },
  2463. setup(props) {
  2464. return () =>
  2465. h("div", {
  2466. class: props.class + " form-icon",
  2467. });
  2468. },
  2469. };
  2470. // 弹窗底部按钮icon
  2471. const SsBottomDivIcon = {
  2472. name: "SsBottomDivIcon",
  2473. props: {
  2474. class: {
  2475. type: String,
  2476. required: true,
  2477. },
  2478. },
  2479. setup(props) {
  2480. return () =>
  2481. h("div", {
  2482. class: props.class + " bottom-div-icon",
  2483. });
  2484. },
  2485. };
  2486. // editor组件icon
  2487. const SsEditorIcon = {
  2488. name: "SsEditorIcon",
  2489. props: {
  2490. class: {
  2491. type: String,
  2492. required: true,
  2493. },
  2494. },
  2495. setup(props) {
  2496. return () =>
  2497. h("i", {
  2498. class: props.class + " editor-icon",
  2499. });
  2500. },
  2501. };
  2502. // ss-validate校验器
  2503. const SsValidate = {
  2504. name: "SsValidate",
  2505. props: {
  2506. errMsg: { type: String },
  2507. textAlign: { type: String, default: "left" },
  2508. style: { type: Object, default: () => ({}) },
  2509. },
  2510. template: `<div class="validate-vline"></div>
  2511. <div class="validate-tip" :style="style">
  2512. <div class="tip" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  2513. <div class="tip-more" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  2514. </div>`,
  2515. };
  2516. // ss-onoff-array 多选按钮 数组形式
  2517. const SsonoffArray = {
  2518. name: "SsonoffArray",
  2519. props: {
  2520. name: {
  2521. type: String,
  2522. required: true,
  2523. },
  2524. opt: {
  2525. type: Array,
  2526. default: () => [],
  2527. },
  2528. defaultValue: [String, Number, Array],
  2529. modelValue: [String, Number, Array],
  2530. multiple: {
  2531. // 新增多选模式属性
  2532. type: Boolean,
  2533. default: false,
  2534. },
  2535. // 是否允许一项都不选,默认true允许 by xu 20251212
  2536. null: {
  2537. type: Boolean,
  2538. default: true,
  2539. },
  2540. },
  2541. emits: ["update:modelValue"], // 允许更新 v-model 绑定的值
  2542. setup(props, { emit }) {
  2543. console.log("多选按钮", props.opt);
  2544. // 使用数组来存储选中值
  2545. const checkedValue = ref(
  2546. props.multiple
  2547. ? Array.isArray(props.defaultValue)
  2548. ? props.defaultValue
  2549. : []
  2550. : props.defaultValue
  2551. );
  2552. const errMsg = ref(props.errTip);
  2553. // 生成icon名字
  2554. const genIconName = (itemValue) => {
  2555. if (props.multiple) {
  2556. return checkedValue.value.includes(itemValue)
  2557. ? "form-icon-onoff-checked"
  2558. : "form-icon-onoff-unchecked";
  2559. }
  2560. return checkedValue.value === itemValue
  2561. ? "form-icon-onoff-checked"
  2562. : "form-icon-onoff-unchecked";
  2563. };
  2564. // 选中项
  2565. const selectItem = (value) => {
  2566. if (props.multiple) {
  2567. // 多选模式
  2568. const index = checkedValue.value.indexOf(value);
  2569. if (index === -1) {
  2570. checkedValue.value = [...checkedValue.value, value];
  2571. } else {
  2572. // 取消选中当前项
  2573. const newValue = checkedValue.value.filter((v) => v !== value);
  2574. // 如果不允许为空且取消后为空,则阻止取消操作 by xu 20251212
  2575. if (!props.null && newValue.length === 0) {
  2576. return; // 阻止取消最后一项
  2577. }
  2578. checkedValue.value = newValue;
  2579. }
  2580. } else {
  2581. // 单选模式
  2582. // 如果点击的是当前已选中的项,判断是否允许取消 by xu 20251212
  2583. if (checkedValue.value === value) {
  2584. if (!props.null) {
  2585. return; // 不允许为空时,阻止取消
  2586. }
  2587. checkedValue.value = ""; // 允许为空时,取消选中
  2588. } else {
  2589. checkedValue.value = value;
  2590. }
  2591. }
  2592. emit("update:modelValue", checkedValue.value);
  2593. nextTick(() => {
  2594. // 触发验证
  2595. if (window.ssVm) {
  2596. window.ssVm.validateField(props.name);
  2597. }
  2598. });
  2599. };
  2600. return { checkedValue, genIconName, selectItem };
  2601. },
  2602. // 使用渲染函数定义模板逻辑
  2603. render() {
  2604. const SsFormIcon = resolveComponent("ss-form-icon");
  2605. return h("div", { class: "radio-container" }, [
  2606. // 根据情况创建 input
  2607. this.multiple
  2608. ? this.checkedValue.length
  2609. ? // 多选且有选中值:为选中项创建 input
  2610. this.checkedValue.map((value) =>
  2611. h("input", {
  2612. type: "checkbox",
  2613. name: this.name,
  2614. value: value,
  2615. checked: true,
  2616. style: { display: "none" },
  2617. })
  2618. )
  2619. : // 多选但没有选中值:创建一个空值 input
  2620. h("input", {
  2621. type: "hidden",
  2622. name: this.name,
  2623. value: "",
  2624. })
  2625. : // 单选模式:创建一个 input
  2626. h("input", {
  2627. type: "hidden",
  2628. name: this.name,
  2629. value: this.checkedValue || "",
  2630. }),
  2631. this.opt.map((item, i) =>
  2632. h(
  2633. "div",
  2634. {
  2635. key: i,
  2636. class: {
  2637. checked: this.multiple
  2638. ? this.checkedValue.includes(item.value)
  2639. : this.checkedValue === item.value,
  2640. },
  2641. style: { width: item.width },
  2642. onClick: () => this.selectItem(item.value),
  2643. },
  2644. [
  2645. h("span", null, item.label),
  2646. h("div", { class: "mark" }, [
  2647. h(SsFormIcon, {
  2648. class: this.genIconName(item.value),
  2649. }),
  2650. ]),
  2651. ]
  2652. )
  2653. ),
  2654. ]);
  2655. },
  2656. };
  2657. // ss-onoff 一个按钮
  2658. const Ssonoff = {
  2659. name: "Ssonoff",
  2660. props: {
  2661. name: {
  2662. type: String,
  2663. required: true,
  2664. },
  2665. label: {
  2666. type: String,
  2667. required: true,
  2668. },
  2669. value: {
  2670. type: [String, Number],
  2671. required: true,
  2672. },
  2673. width: {
  2674. type: String,
  2675. default: "",
  2676. },
  2677. modelValue: [String, Number, Array],
  2678. multiple: {
  2679. type: Boolean,
  2680. default: false,
  2681. },
  2682. null: {
  2683. type: Boolean,
  2684. default: true,
  2685. },
  2686. },
  2687. emits: ["update:modelValue"],
  2688. setup(props, { emit }) {
  2689. const parseModelValue = (val) => {
  2690. if (!val) return [];
  2691. // 如果以逗号开头,去掉开头的逗号
  2692. const cleanValue = val.toString().replace(/^,+/, "");
  2693. if (cleanValue.includes("|")) {
  2694. return cleanValue.split("|");
  2695. }
  2696. if (cleanValue.includes(",")) {
  2697. return cleanValue.split(",");
  2698. }
  2699. return [cleanValue];
  2700. };
  2701. // 判断当前按钮是否选中
  2702. const isChecked = computed(() => {
  2703. if (props.multiple) {
  2704. const currentValue = parseModelValue(props.modelValue);
  2705. return currentValue.includes(props.value.toString());
  2706. // return Array.isArray(props.modelValue) && props.modelValue.includes(props.value);
  2707. }
  2708. return (props.modelValue+'') === (props.value+'');//强转为字符串类型再比较(改之前是数字类型和字符串类型作比较,永远为false) Ben 20251206
  2709. });
  2710. // 切换选中状态
  2711. const toggleSelect = () => {
  2712. if (props.multiple) {
  2713. const currentValue = parseModelValue(props.modelValue);
  2714. const index = currentValue.indexOf(props.value.toString());
  2715. let newValue;
  2716. if (index === -1) {
  2717. // 选中当前项
  2718. newValue = [...currentValue, props.value];
  2719. } else {
  2720. // 取消选中当前项
  2721. const filteredValue = currentValue.filter((v) => v !== props.value.toString());
  2722. // 如果不允许为空且取消后为空,则阻止取消操作
  2723. if (!props.null && filteredValue.length === 0) {
  2724. return; // 阻止取消最后一项
  2725. }
  2726. newValue = filteredValue;
  2727. }
  2728. emit("update:modelValue", newValue.join(","));
  2729. } else {
  2730. // 单选模式
  2731. const currentValue = parseModelValue(props.modelValue);
  2732. const isCurrentlySelected = currentValue.includes(props.value.toString());
  2733. if (!isCurrentlySelected) {
  2734. // 选中当前项
  2735. emit("update:modelValue", props.value);
  2736. } else {
  2737. // 取消选中当前项
  2738. // 如果不允许为空且当前只有这一项被选中,则阻止取消操作
  2739. if (!props.null && currentValue.length === 1) {
  2740. return; // 阻止取消唯一选中项
  2741. }
  2742. emit("update:modelValue", "");
  2743. }
  2744. }
  2745. nextTick(() => {
  2746. // 触发验证
  2747. if (window.ssVm) {
  2748. window.ssVm.validateField(props.name);
  2749. }
  2750. });
  2751. };
  2752. return { isChecked, toggleSelect };
  2753. },
  2754. render() {
  2755. const SsFormIcon = resolveComponent("ss-form-icon");
  2756. return h("div", { class: "radio-container2" }, [
  2757. // 隐藏的表单元素
  2758. this.multiple
  2759. ? h("input", {
  2760. type: "hidden",
  2761. name: `${this.name}`, // 多选模式下使用数组形式的 name
  2762. value: this.isChecked ? this.value : "",
  2763. })
  2764. : this.isChecked &&
  2765. h("input", {
  2766. // 只有当前按钮被选中时才创建 input
  2767. type: "hidden",
  2768. name: this.name,
  2769. value: this.value,
  2770. }),
  2771. // 按钮显示
  2772. h(
  2773. "div",
  2774. {
  2775. class: { checked: this.isChecked },
  2776. style: { width: this.width },
  2777. onClick: this.toggleSelect,
  2778. },
  2779. [
  2780. h("span", null, this.label),
  2781. h("div", { class: "mark" }, [
  2782. h(SsFormIcon, {
  2783. class: this.isChecked
  2784. ? "form-icon-onoff-checked"
  2785. : "form-icon-onoff-unchecked",
  2786. }),
  2787. ]),
  2788. ]
  2789. ),
  2790. ]);
  2791. },
  2792. };
  2793. // ss-textarea
  2794. const SsTextarea = {
  2795. name: "SsTextarea",
  2796. props: {
  2797. name: {
  2798. type: String,
  2799. required: true,
  2800. },
  2801. placeholder: {
  2802. type: String,
  2803. default: "请输入",
  2804. },
  2805. defaultValue: [String, Number],
  2806. modelValue: [String, Number],
  2807. },
  2808. emits: ["update:modelValue"],
  2809. setup(props, { emit }) {
  2810. const inputValue = ref(props.modelValue || props.defaultValue || "");
  2811. // 监听 modelValue 变化
  2812. watch(
  2813. () => props.modelValue,
  2814. (newVal) => {
  2815. inputValue.value = newVal;
  2816. }
  2817. );
  2818. // 输入事件处理
  2819. const onInput = (event) => {
  2820. const newValue = event.target.value;
  2821. inputValue.value = newValue;
  2822. emit("update:modelValue", newValue);
  2823. // 触发验证
  2824. if (window.ssVm) {
  2825. window.ssVm.validateField(props.name);
  2826. }
  2827. };
  2828. // 失焦时验证
  2829. const onBlur = () => {
  2830. if (window.ssVm) {
  2831. window.ssVm.validateField(props.name);
  2832. }
  2833. };
  2834. return { inputValue, onInput, onBlur };
  2835. },
  2836. render() {
  2837. return h("div", { class: "textarea-container" }, [
  2838. h("div", { class: "textarea" }, [
  2839. // 添加隐藏的 input 用于验证
  2840. h("input", {
  2841. type: "hidden",
  2842. name: this.name,
  2843. value: this.inputValue || "",
  2844. }),
  2845. h("textarea", {
  2846. placeholder: this.placeholder,
  2847. value: this.inputValue,
  2848. onInput: this.onInput,
  2849. onBlur: this.onBlur,
  2850. }),
  2851. ]),
  2852. ]);
  2853. },
  2854. };
  2855. // ss-editor 富文本编辑器 基于Jodit
  2856. const SsEditor = {
  2857. name: "SsEditor",
  2858. props: {
  2859. modelValue: {
  2860. type: String,
  2861. default: "",
  2862. },
  2863. name: {
  2864. type: String,
  2865. default: "",
  2866. },
  2867. url: {
  2868. type: String,
  2869. default: "",
  2870. },
  2871. height: {
  2872. type: [Number, String],
  2873. default: 400,
  2874. },
  2875. placeholder: {
  2876. type: String,
  2877. default: "请输入内容",
  2878. },
  2879. readonly: {
  2880. type: Boolean,
  2881. default: false,
  2882. },
  2883. uploadUrl: {
  2884. type: String,
  2885. default: "/ulByHttp",//原值为“upload” Ben(20251205)
  2886. },
  2887. param: {
  2888. type: Object,
  2889. default: () => ({}),
  2890. },
  2891. },
  2892. emits: ["update:modelValue", "ready", "change"],
  2893. setup(props, { emit }) {
  2894. const SsEditorIcon = resolveComponent("SsEditorIcon");
  2895. const editorRef = ref(null);
  2896. let editorContent = '';//保存富文本编辑器里面的富文本内容
  2897. const uniqueId = "editor-" + Date.now();
  2898. const errMsg = Vue.ref("");
  2899. let fjid = ref(props.param.button.val);
  2900. let fjName = props.param.button.desc;
  2901. let mode = props.param.mode;
  2902. const validate = () => {
  2903. if (window.ssVm) {
  2904. const result = window.ssVm.validateField(props.name);
  2905. console.log("validate", window.ssVm.validateField(props.name));
  2906. errMsg.value = result.valid ? "" : result.message;
  2907. }
  2908. };
  2909. onMounted(() => {
  2910. validate();
  2911. const editor = Jodit.make(`#${uniqueId}`, {
  2912. height: props.height,
  2913. placeholder: props.placeholder,
  2914. readonly: props.readonly,
  2915. language: "zh_cn",
  2916. i18n: {
  2917. zh_cn: {
  2918. Link: "链接",
  2919. URL: "链接",
  2920. "No follow": "无跟踪",
  2921. "Class name": "类名",
  2922. Image: "图片",
  2923. File: "文件",
  2924. "Line height": "行高",
  2925. Alternative: "描述",
  2926. "Alternative text": "描述",
  2927. "Lower Alpha": "小写字母",
  2928. "Upper Alpha": "大写字母",
  2929. "Upper Roman": "大写罗马数字",
  2930. "Lower Roman": "小写罗马数字",
  2931. "Lower Greek": "小写希腊字母",
  2932. "Lower Letter": "小写字母",
  2933. "Upper Letter": "大写字母",
  2934. },
  2935. },
  2936. showXPathInStatusbar: false,
  2937. showCharsCounter: false,
  2938. showWordsCounter: false,
  2939. allowResizeY: false,
  2940. toolbarSticky: false,
  2941. statusbar: false,
  2942. uploader: {
  2943. url: props.uploadUrl,
  2944. format: "json",
  2945. method: "POST",
  2946. filesVariableName: function (i) {
  2947. return "imgs[" + i + "]";
  2948. },
  2949. headers: {
  2950. Accept: "application/json",
  2951. },
  2952. prepareData: function (formData) {
  2953. // 这里可以在发送前处理表单数据
  2954. return formData;
  2955. },
  2956. isSuccess: function (resp) {
  2957. console.log("isSuccess resp:", resp);
  2958. return resp.code === 0;
  2959. },
  2960. getMessage: function (resp) {
  2961. console.log("getMessage resp:", resp);
  2962. return resp.msg || "上传失败";
  2963. },
  2964. process: function (resp) {
  2965. console.log("process resp:", resp);
  2966. return resp.data.url;
  2967. },
  2968. error: function (e) {
  2969. console.error("上传失败:", e.message);
  2970. },
  2971. defaultHandlerSuccess: function (resp) {
  2972. console.log("上传成功:", resp);
  2973. },
  2974. defaultHandlerError: function (err) {
  2975. console.error("上传错误:", err);
  2976. },
  2977. contentType: function (requestData) {
  2978. // 可以根据需要修改 Content-Type
  2979. return false; // 让浏览器自动设置
  2980. },
  2981. },
  2982. // 自定义字体列表
  2983. controls: {
  2984. font: {
  2985. list: {
  2986. Arial: "Arial",
  2987. SimSun: "宋体",
  2988. SimHei: "黑体",
  2989. "Microsoft YaHei": "微软雅黑",
  2990. KaiTi: "楷体",
  2991. FangSong: "仿宋",
  2992. "Times New Roman": "Times New Roman",
  2993. "Courier New": "Courier New",
  2994. },
  2995. },
  2996. customLinkButton: {
  2997. name: "link",
  2998. tooltip: "附件",
  2999. exec: function (editor) {
  3000. // 按钮点击时的处理函数
  3001. console.log("附件点击了");
  3002. console.log("param", props.param);
  3003. console.log("cmsAddUrl",props.param.button.cmsAddUrl);
  3004. if (fjid.value == null || fjid.value == "") {
  3005. $.ajax({
  3006. type: "post",
  3007. url: props.param.button.cmsAddUrl,
  3008. async: false,
  3009. data: {
  3010. name: "fjid",
  3011. ssNrObjName: "sh",
  3012. ssNrObjId: "",
  3013. },
  3014. success: function (_fjid) {
  3015. console.log("cmsAddUrl success", _fjid);
  3016. fjid.value = _fjid;
  3017. },
  3018. });
  3019. }
  3020. var str =
  3021. "&nrid=T-" +
  3022. fjid.value +
  3023. "&objectId=" +
  3024. fjid.value +
  3025. "&objectName=" +
  3026. fjName +
  3027. "&callback=" +
  3028. (window["fjidCallbackName"] || "");
  3029. console.log("str", str);
  3030. SS.openDialog({
  3031. src: props.param.button.cmsUpdUrl + str,
  3032. headerTitle: "编辑",
  3033. width: 900,
  3034. high: 664,
  3035. zIndex:51
  3036. });
  3037. // ss.display.showComponent({
  3038. // show: ["wdDialog"],
  3039. // url: props.param.button.cmsUpdUrl + str,
  3040. // title: "编辑",
  3041. // width: 900,
  3042. // high: 664,
  3043. // });
  3044. },
  3045. },
  3046. },
  3047. toolbarAdaptive: true,
  3048. buttons: [
  3049. "fullsize",
  3050. "bold",
  3051. "italic",
  3052. "underline",
  3053. "strikethrough",
  3054. "eraser",
  3055. "|",
  3056. "font",
  3057. "fontsize",
  3058. "brush",
  3059. "paragraph",
  3060. "|",
  3061. "left",
  3062. "center",
  3063. "right",
  3064. "justify",
  3065. "|",
  3066. "ul",
  3067. "ol",
  3068. "indent",
  3069. "outdent",
  3070. "|",
  3071. "image",
  3072. "table",
  3073. "customLinkButton",
  3074. "print",
  3075. "|",
  3076. "undo",
  3077. "redo",
  3078. "find",
  3079. ],
  3080. // 中等宽度时显示的按钮
  3081. buttonsMD: [
  3082. "fullsize",
  3083. "bold",
  3084. "italic",
  3085. "underline",
  3086. "strikethrough",
  3087. "eraser",
  3088. "|",
  3089. "font",
  3090. "fontsize",
  3091. "brush",
  3092. "paragraph",
  3093. "|",
  3094. "font",
  3095. "fontsize",
  3096. "|",
  3097. "left",
  3098. "center",
  3099. "right",
  3100. "justify",
  3101. "|",
  3102. "image",
  3103. "customLinkButton",
  3104. "|",
  3105. "dots", // 其余按钮会自动进入 dots 菜单
  3106. ],
  3107. // 小屏幕时显示的按钮
  3108. buttonsSM: ["fullsize", "bold", "italic", "|", "image", "|", "dots"],
  3109. // 超小屏幕时显示的按钮
  3110. buttonsXS: ["fullsize", "bold", "|", "dots"],
  3111. // 设置响应式断点
  3112. sizeLG: 1024, // 大屏幕
  3113. sizeMD: 768, // 中等屏幕
  3114. sizeSM: 576, // 小屏幕
  3115. // 自定义图标
  3116. getIcon: function (name, clearName) {
  3117. // 定义图标映射
  3118. const iconMap = {
  3119. bold: "editor-icon-bold",
  3120. italic: "editor-icon-italic",
  3121. underline: "editor-icon-underline",
  3122. strikethrough: "editor-icon-strikethrough",
  3123. eraser: "editor-icon-eraser",
  3124. copyformat: "editor-icon-copyformat",
  3125. font: "editor-icon-font",
  3126. fontsize: "editor-icon-fontsize",
  3127. brush: "editor-icon-brush",
  3128. paragraph: "editor-icon-paragraph",
  3129. left: "editor-icon-align-left",
  3130. center: "editor-icon-align-center",
  3131. right: "editor-icon-align-right",
  3132. justify: "editor-icon-align-justify",
  3133. ul: "editor-icon-ul",
  3134. ol: "editor-icon-ol",
  3135. indent: "editor-icon-indent",
  3136. outdent: "editor-icon-outdent",
  3137. image: "editor-icon-image",
  3138. file: "editor-icon-file",
  3139. video: "editor-icon-video",
  3140. table: "editor-icon-table",
  3141. link: "editor-icon-link",
  3142. source: "editor-icon-source",
  3143. eye: "editor-icon-preview",
  3144. fullsize: "editor-icon-fullsize",
  3145. shrink: "editor-icon-fullsize-exit", // 添加退出全屏图标
  3146. print: "editor-icon-print",
  3147. undo: "editor-icon-undo",
  3148. redo: "editor-icon-redo",
  3149. search: "editor-icon-find",
  3150. selectall: "editor-icon-selectall",
  3151. };
  3152. // 获取对应的图标类名
  3153. const iconClass = iconMap[clearName] || iconMap[name];
  3154. if (iconClass) {
  3155. // 返回带有我们自定义图标类的 span 元素
  3156. return `<span class="editor-icon ${iconClass}"></span>`;
  3157. }
  3158. return null;
  3159. },
  3160. });
  3161. // 设置初始值
  3162. editor.value = editorContent;
  3163. // editor.value = props.modelValue;
  3164. // 监听变化
  3165. editor.events.on("change", () => {
  3166. // emit("update:modelValue", editor.value);
  3167. editorContent = editor.value;
  3168. // alert('editorContent:'+editorContent);
  3169. let contentElements = document.getElementsByName(props.name.replace(/wj$/, "") + "Edit");
  3170. if(contentElements.length>0){
  3171. contentElements[0].value = editorContent;
  3172. }
  3173. emit("change", editor.value);
  3174. setTimeout(() => {
  3175. validate();
  3176. }, 50);
  3177. });
  3178. // 保存编辑器实例
  3179. editorRef.value = editor;
  3180. emit("ready", editor);
  3181. //回显编辑器富文本文件
  3182. if (props.url ) {
  3183. const params = new URLSearchParams();
  3184. if(mode)
  3185. params.append("mode", mode);
  3186. if(props.modelValue)
  3187. params.append("path", props.modelValue);
  3188. // alert('props.url:'+props.url+',props.modelValue:'+props.modelValue);
  3189. axios
  3190. .post(props.url, params, {
  3191. headers: {
  3192. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  3193. },
  3194. })
  3195. .then((response) => {
  3196. // alert(JSON.stringify(response.data));
  3197. if ("timeout" == response.data.statusText) {
  3198. alert("网络超时!");
  3199. return;
  3200. }
  3201. let content = response.data.content;
  3202. if (content) {
  3203. // editor.value = content;
  3204. editorRef.value.value = content;
  3205. editorContent = content;
  3206. // alert('editor.value:'+editor.value)
  3207. }
  3208. let filePath = response.data.path;
  3209. // alert('response.data:'+JSON.stringify(response.data));
  3210. if(filePath){
  3211. props.modelValue = filePath;
  3212. emit("update:modelValue", filePath);
  3213. }
  3214. });
  3215. }
  3216. });
  3217. // 监听值变化
  3218. watch(
  3219. // () => props.modelValue,
  3220. () => editorContent,
  3221. (newValue) => {
  3222. if (editorRef.value && newValue !== editorRef.value.value) {
  3223. editorRef.value.value = newValue || "";
  3224. }
  3225. }
  3226. );
  3227. // 监听只读状态变化
  3228. watch(
  3229. () => props.readonly,
  3230. (newValue) => {
  3231. if (editorRef.value) {
  3232. editorRef.value.setReadOnly(newValue);
  3233. }
  3234. }
  3235. );
  3236. // 组件销毁时清理
  3237. onBeforeUnmount(() => {
  3238. if (editorRef.value) {
  3239. editorRef.value.destruct();
  3240. }
  3241. });
  3242. return () =>
  3243. h("div", { class: "ss-editor-container" }, [
  3244. fjid.value &&
  3245. h("input", {
  3246. type: "hidden",
  3247. name: "fjid",
  3248. value: fjid.value,
  3249. }),
  3250. h("input", {
  3251. type: "hidden",
  3252. name: props.name.replace(/wj$/, "") + "Edit",
  3253. value: editorContent
  3254. // value: props.modelValue,
  3255. }),
  3256. h("input", {
  3257. type: "hidden",
  3258. name: props.name.replace(/wj$/, "") + "wj",
  3259. value: props.modelValue
  3260. // value: props.url
  3261. }),
  3262. h("input", { type: "hidden", name: "ueditorpath", value: "mswj" }),
  3263. h("textarea", { id: uniqueId }),
  3264. ]);
  3265. },
  3266. };
  3267. // 弹窗右边图标
  3268. const SsFullStyleHeader = {
  3269. name: "SsFullStyleHeader",
  3270. props: {
  3271. title: {
  3272. type: String,
  3273. default: "标题",
  3274. },
  3275. },
  3276. emits: ["close"],
  3277. setup(props, { emit }) {
  3278. // console.log(props.title)
  3279. const onClose = () => {
  3280. emit("close");
  3281. };
  3282. const SsIcon = resolveComponent("ss-icon");
  3283. return () =>
  3284. h("div", { class: "header-container" }, [
  3285. h("div", { class: "title" }, props.title),
  3286. h("div", { class: "handle-bar" }, [
  3287. h("div", { class: "left-bar" }, [
  3288. h(SsDialogIcon, { class: "dialog-icon-download" }),
  3289. h(SsDialogIcon, { class: "dialog-icon-print" }),
  3290. h(SsDialogIcon, { class: "dialog-icon-setting" }),
  3291. h(SsDialogIcon, { class: "dialog-icon-collect" }),
  3292. h(SsDialogIcon, { class: "dialog-icon-help" }),
  3293. h(SsDialogIcon, { class: "dialog-icon-full-screen" }),
  3294. h(SsDialogIcon, { class: "dialog-icon-lock" }),
  3295. ]),
  3296. h("div", { class: "close-bar", onClick: onClose }, [
  3297. h(SsDialogIcon, { class: "dialog-icon-close" }),
  3298. ]),
  3299. ]),
  3300. ]);
  3301. },
  3302. };
  3303. // ss-dialog弹窗
  3304. const SsDialog = {
  3305. name: "SsDialog",
  3306. props: {
  3307. src: {
  3308. type: String,
  3309. },
  3310. headerTitle: {
  3311. type: String,
  3312. // required: true,
  3313. default: "弹窗",
  3314. },
  3315. width: {
  3316. type: String,
  3317. default: "1400",
  3318. },
  3319. height: {
  3320. type: String,
  3321. default: "600",
  3322. },
  3323. params: {
  3324. type: Object,
  3325. default: () => ({}),
  3326. },
  3327. zIndex: {
  3328. type: Number,
  3329. default: 1000,
  3330. },
  3331. },
  3332. emits: ["close"],
  3333. setup(props, { slots, emit }) {
  3334. // 关闭窗口方法
  3335. const onClose = () => {
  3336. emit("close");
  3337. };
  3338. const showHeader = ref(true);
  3339. const headerVisible = ref(false);
  3340. const popupHieght = ref(props.height);
  3341. // 状态:存储位置信息
  3342. const position = reactive({
  3343. // 页面居中
  3344. x: (window.innerWidth - props.width) / 2,
  3345. y: (window.innerHeight - popupHieght.value) / 2,
  3346. isDragging: false,
  3347. offsetX: 0,
  3348. offsetY: 0,
  3349. });
  3350. // 鼠标按下时设置起始坐标并开始拖拽
  3351. const startDrag = (event) => {
  3352. position.isDragging = true;
  3353. position.offsetX = event.clientX - position.x;
  3354. position.offsetY = event.clientY - position.y;
  3355. };
  3356. // 鼠标移动时更新位置
  3357. const onDrag = (event) => {
  3358. if (position.isDragging) {
  3359. position.x = event.clientX - position.offsetX;
  3360. position.y = event.clientY - position.offsetY;
  3361. }
  3362. };
  3363. // 鼠标放开时结束拖拽
  3364. const endDrag = () => {
  3365. position.isDragging = false;
  3366. };
  3367. // 监听来自 iframe 的消息
  3368. const handleMessage = (event) => {
  3369. // 顶天立地
  3370. if (event.data && typeof event.data.hasScrollBar !== "undefined") {
  3371. if (event.data.hasScrollBar) {
  3372. // console.log(event);
  3373. position.y = 10;
  3374. showHeader.value = false;
  3375. headerVisible.value = true;
  3376. popupHieght.value = window.innerHeight - 20;
  3377. // console.log(popupHieght.value);
  3378. document.querySelector(".body").style.height = "100%";
  3379. document.querySelector(".body").style.paddingTop = "30px";
  3380. document.querySelector(".header-container ").style.position =
  3381. "absolute";
  3382. document.querySelector(".header-container ").style.zIndex = "10";
  3383. }
  3384. }
  3385. };
  3386. // 鼠标移入关闭按钮区域时显示头部
  3387. const onMouseEnterCloseButton = () => {
  3388. headerVisible.value = false;
  3389. };
  3390. // 鼠标移出关闭按钮区域时隐藏头部
  3391. const onMouseLeaveCloseButton = () => {
  3392. headerVisible.value = true;
  3393. };
  3394. // 在组件挂载时添加全局事件监听器
  3395. Vue.onMounted(() => {
  3396. // 如果传过来的高度大于窗口高度,则设置为窗口高度减去20 否则保持传过来的高度
  3397. popupHieght.value =
  3398. popupHieght.value > window.innerHeight
  3399. ? window.innerHeight - 20
  3400. : popupHieght.value;
  3401. const container = document.querySelector(".header-container");
  3402. if (container) {
  3403. container.addEventListener("mousedown", startDrag);
  3404. }
  3405. document.addEventListener("mousemove", onDrag);
  3406. document.addEventListener("mouseup", endDrag);
  3407. window.addEventListener("message", handleMessage);
  3408. });
  3409. // 在组件卸载时移除全局事件监听器
  3410. Vue.onUnmounted(() => {
  3411. document.removeEventListener("mousemove", onDrag);
  3412. document.removeEventListener("mouseup", endDrag);
  3413. window.removeEventListener("message", handleMessage);
  3414. });
  3415. const SsMark = resolveComponent("ss-mark");
  3416. const SsFullStyleHeader = resolveComponent("ss-full-style-header");
  3417. // render函数定义组件结构
  3418. return () =>
  3419. h(
  3420. Teleport,
  3421. { to: "body" }, // 使用 Teleport 将弹窗内容挂载到 body
  3422. h(SsMark, { }, [
  3423. h(
  3424. "div",
  3425. {
  3426. class: "popup-container",
  3427. style: {
  3428. position: "absolute",
  3429. left: `${position.x}px`,
  3430. top: `${position.y}px`,
  3431. width: props.width + "px",
  3432. height: popupHieght.value + "px",
  3433. zIndex: props.zIndex, // 确保弹窗在最上层
  3434. },
  3435. },
  3436. [
  3437. h(SsFullStyleHeader, {
  3438. class: "header",
  3439. title: props.headerTitle,
  3440. onClose: onClose,
  3441. onMousedown: startDrag, // 绑定拖动事件
  3442. onMouseUp: endDrag,
  3443. ...(!showHeader.value && {
  3444. onMouseenter: onMouseEnterCloseButton,
  3445. onMouseleave: onMouseLeaveCloseButton,
  3446. }),
  3447. style: {
  3448. cursor: position.isDragging ? "grabbing" : "grab",
  3449. visibility: headerVisible.value ? "hidden" : "visible",
  3450. },
  3451. }),
  3452. h(
  3453. "div",
  3454. {
  3455. class: "body",
  3456. style: {},
  3457. },
  3458. [
  3459. h("iframe", {
  3460. src: props.src,
  3461. frameborder: 0,
  3462. style: { width: "100%", height: "100%" },
  3463. }),
  3464. ]
  3465. ),
  3466. headerVisible.value &&
  3467. h("div", {
  3468. class: "close-button",
  3469. onMouseenter: onMouseEnterCloseButton,
  3470. onMouseleave: onMouseLeaveCloseButton,
  3471. style: {
  3472. position: "absolute",
  3473. top: "0",
  3474. right: "0",
  3475. // background: 'black',
  3476. width: "60px",
  3477. height: "60px",
  3478. cursor: "pointer",
  3479. },
  3480. }),
  3481. ]
  3482. ),
  3483. ])
  3484. );
  3485. },
  3486. };
  3487. // ss-mark遮罩层
  3488. const SsMark = {
  3489. name: "SsMark",
  3490. setup(props, { slots, emit }) {
  3491. return () =>
  3492. h("div", { class: "dialog-container" }, [
  3493. h("div", { class: "mark-content" }, [
  3494. h("div", { class: "dialog-contianer" }, [
  3495. slots.default ? slots.default() : "",
  3496. ]),
  3497. ]),
  3498. ]);
  3499. },
  3500. };
  3501. // ss-bottom-button 底部按钮
  3502. // 修改支持更多按钮 by xu 20251211
  3503. const SsBottomButton = {
  3504. name: "SsBottomButton",
  3505. props: {
  3506. text: {
  3507. type: String,
  3508. required: false,
  3509. },
  3510. type: {
  3511. type: String,
  3512. default: "button",
  3513. },
  3514. iconClass: {
  3515. type: String,
  3516. },
  3517. class: {
  3518. type: String,
  3519. default: "",
  3520. },
  3521. onclick: {
  3522. type: [Function, String],
  3523. default: null,
  3524. },
  3525. // 修改支持更多按钮 by xu 20251211
  3526. more: {
  3527. type: [Boolean, String],
  3528. default: false,
  3529. },
  3530. },
  3531. setup(props, { emit }) {
  3532. const SsBottomDivIcon = Vue.resolveComponent("ss-bottom-div-icon");
  3533. const showDropdown = Vue.ref(false);
  3534. // 修改支持更多按钮 by xu 20251211
  3535. const moreKey = Vue.computed(() => {
  3536. const val = props.more;
  3537. if (val === false || val === null || typeof val === "undefined") {
  3538. return null;
  3539. }
  3540. if (val === true || val === "" || val === "true") {
  3541. return "moreChg";
  3542. }
  3543. return val;
  3544. });
  3545. // 从配置中读取按钮信息和下拉选项
  3546. const config = Vue.computed(() => {
  3547. if (moreKey.value && window.ss && window.ss.dom && window.ss.dom.btnElemConfig) {
  3548. return window.ss.dom.btnElemConfig[moreKey.value] || {};
  3549. }
  3550. return {};
  3551. });
  3552. const buttonText = Vue.computed(() => {
  3553. return props.text || config.value.desc || '';
  3554. });
  3555. const dropOptions = Vue.computed(() => {
  3556. return config.value.dropOptions || [];
  3557. });
  3558. const hasDropdown = Vue.computed(() => {
  3559. return dropOptions.value.length > 0;
  3560. });
  3561. const handleMouseEnter = () => {
  3562. if (hasDropdown.value) {
  3563. showDropdown.value = true;
  3564. }
  3565. };
  3566. const handleMouseLeave = () => {
  3567. showDropdown.value = false;
  3568. };
  3569. const handleDropItemClick = (option) => {
  3570. if (option.callback && typeof option.callback === 'function') {
  3571. option.callback();
  3572. }
  3573. showDropdown.value = false;
  3574. };
  3575. return () =>
  3576. h(
  3577. "div",
  3578. {
  3579. class: "ss-bottom-button-wrapper",
  3580. onMouseenter: handleMouseEnter,
  3581. onMouseleave: handleMouseLeave,
  3582. },
  3583. [
  3584. h(
  3585. "button",
  3586. {
  3587. class: props.class,
  3588. onClick: (e) => {
  3589. e.stopPropagation();
  3590. if (props.onclick) {
  3591. // 如果是函数直接调用
  3592. if (typeof props.onclick === "function") {
  3593. props.onclick(e);
  3594. } else if (typeof props.onclick === "string") {
  3595. // 如果是字符串,使用直接的方法执行
  3596. // 临时存储按钮元素到全局变量
  3597. window.__ss_current_button = e.currentTarget;
  3598. // 直接执行代码,使用eval以保留原始上下文
  3599. try {
  3600. eval(props.onclick);
  3601. } finally {
  3602. // 清理全局变量
  3603. delete window.__ss_current_button;
  3604. }
  3605. }
  3606. }
  3607. },
  3608. type: props.type,
  3609. },
  3610. [
  3611. h("span", null, [
  3612. h(SsBottomDivIcon, {
  3613. class: props.iconClass,
  3614. }),
  3615. ]),
  3616. h("span", null, buttonText.value),
  3617. ]
  3618. ),
  3619. // 渲染下拉菜单
  3620. hasDropdown.value && showDropdown.value
  3621. ? h(
  3622. "div",
  3623. {
  3624. class: "ss-bottom-button-dropdown",
  3625. },
  3626. dropOptions.value.map((option) =>
  3627. h(
  3628. "div",
  3629. {
  3630. class: "ss-bottom-button-dropdown-item",
  3631. onClick: (e) => {
  3632. e.stopPropagation();
  3633. handleDropItemClick(option);
  3634. },
  3635. },
  3636. option.desc
  3637. )
  3638. )
  3639. )
  3640. : null,
  3641. ]
  3642. );
  3643. },
  3644. };
  3645. // ss-search搜索框
  3646. const SsSearch = {
  3647. name: "SsSearch",
  3648. props: {
  3649. theme: {
  3650. type: String,
  3651. default: "light",
  3652. validator: function (value) {
  3653. return ["dark", "light"].includes(value);
  3654. },
  3655. },
  3656. placeholder: {
  3657. type: String,
  3658. default: "请输入搜索条件",
  3659. },
  3660. },
  3661. setup(props, { emit }) {
  3662. const onClick = () => {
  3663. console.log("Search clicked");
  3664. emit("click");
  3665. };
  3666. const SsIcon = Vue.resolveComponent("ss-icon");
  3667. return () =>
  3668. Vue.h(
  3669. "div",
  3670. {
  3671. class: ["search-container", props.theme],
  3672. onClick: onClick,
  3673. },
  3674. [
  3675. Vue.h("input", {
  3676. placeholder: props.placeholder,
  3677. disabled: true,
  3678. }),
  3679. Vue.h(SsIcon, {
  3680. name: "search-result",
  3681. size: "20px",
  3682. }),
  3683. ]
  3684. );
  3685. },
  3686. };
  3687. // ss-cart-item 菜单页面的卡片 左右结构
  3688. const SsCartItem = {
  3689. name: "SsCartItem",
  3690. props: {
  3691. active: Boolean,
  3692. item: {
  3693. type: Object,
  3694. default: () => ({
  3695. thumb: "images/example/project-img.png",
  3696. title: "广州(国际)科技成果转化天河基地专",
  3697. description: "佳能中国广州分公司",
  3698. all: 50,
  3699. finish: 5,
  3700. }),
  3701. },
  3702. },
  3703. setup(props, { emit }) {
  3704. const item = props.item;
  3705. const itemWidth = Vue.computed(() => {
  3706. const containerWidth =
  3707. document.body.clientWidth || document.body.scrollWidth - 520;
  3708. const halfWidth = containerWidth / 2;
  3709. if (halfWidth < 480) {
  3710. return Math.min(containerWidth, 702) + "px";
  3711. } else {
  3712. return Math.min(halfWidth, 702) + "px";
  3713. }
  3714. });
  3715. const onItemClick = (e) => {
  3716. emit("click", e);
  3717. };
  3718. return {
  3719. item,
  3720. itemWidth,
  3721. onItemClick,
  3722. };
  3723. },
  3724. render() {
  3725. const SsIcon = Vue.resolveComponent("ss-icon");
  3726. return Vue.h(
  3727. "div",
  3728. {
  3729. class: { "item-container": true, active: this.active },
  3730. onClick: this.onItemClick,
  3731. style: { width: this.itemWidth },
  3732. },
  3733. [
  3734. Vue.h("div", { class: "header" }, [
  3735. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  3736. ]),
  3737. Vue.h("div", { class: "body" }, [
  3738. Vue.h("div", { class: "left" }, [
  3739. Vue.h("img", {
  3740. src: this.item.thumb,
  3741. alt: "Thumbnail",
  3742. class: "imgUnHandle",
  3743. style: { "object-fit": "cover", width: "100%", height: "100%" },
  3744. }),
  3745. ]),
  3746. Vue.h("div", { class: "right" }, [
  3747. Vue.h("div", { class: "title" }, this.item.title),
  3748. Vue.h("div", { class: "desc" }, this.item.description),
  3749. Vue.h("div", { class: "progress" }, [
  3750. Vue.h(
  3751. "div",
  3752. {
  3753. style: {
  3754. width: `${(this.item.finish / this.item.all) * 100}%`,
  3755. },
  3756. },
  3757. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  3758. ),
  3759. ]),
  3760. ]),
  3761. ]),
  3762. ]
  3763. );
  3764. },
  3765. };
  3766. // ss-cart-item2 菜单页面的卡片 上下结构
  3767. const SsCartItem2 = {
  3768. name: "SsCartItem2",
  3769. props: {
  3770. active: Boolean,
  3771. item: {
  3772. type: Object,
  3773. default: () => ({
  3774. thumb: "images/example/project-img.png",
  3775. title: "广州(国际)科技成果转化天河基地专",
  3776. description: "佳能中国广州分公司",
  3777. all: 50,
  3778. finish: 5,
  3779. }),
  3780. },
  3781. },
  3782. setup(props, { emit }) {
  3783. const item = props.item;
  3784. const itemWidth = Vue.computed(() => {
  3785. const containerWidth =
  3786. document.body.clientWidth || document.body.scrollWidth - 520;
  3787. const halfWidth = containerWidth / 2;
  3788. if (halfWidth < 480) {
  3789. return Math.min(containerWidth, 702) + "px";
  3790. } else {
  3791. return Math.min(halfWidth, 702) + "px";
  3792. }
  3793. });
  3794. const onItemClick = (e) => {
  3795. emit("click", e);
  3796. };
  3797. return {
  3798. item,
  3799. itemWidth,
  3800. onItemClick,
  3801. };
  3802. },
  3803. render() {
  3804. const SsIcon = Vue.resolveComponent("ss-icon");
  3805. return Vue.h(
  3806. "div",
  3807. {
  3808. class: { "item-container2": true, active: this.active },
  3809. onClick: this.onItemClick,
  3810. style: { width: this.itemWidth },
  3811. },
  3812. [
  3813. Vue.h("div", { class: "action-bar" }, [
  3814. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  3815. ]),
  3816. Vue.h("div", { class: "header" }, [
  3817. Vue.h("div", { class: "title" }, `${this.item.title}`),
  3818. ]),
  3819. Vue.h("div", { class: "body" }, [
  3820. Vue.h("div", { class: "left" }, [
  3821. Vue.h("img", {
  3822. src: this.item.thumb,
  3823. alt: "Thumbnail",
  3824. class: "imgUnHandle",
  3825. style: { "object-fit": "cover", width: "100%", height: "100%" },
  3826. }),
  3827. ]),
  3828. Vue.h("div", { class: "right" }, [
  3829. Vue.h("div", { class: "content" }, this.item.description),
  3830. Vue.h("div", { class: "tip" }, [
  3831. Vue.h("div", { class: "progress" }, [
  3832. Vue.h(
  3833. "div",
  3834. {
  3835. style: {
  3836. width: `${(this.item.finish / this.item.all) * 100}%`,
  3837. },
  3838. },
  3839. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  3840. ),
  3841. ]),
  3842. ]),
  3843. ]),
  3844. ]),
  3845. ]
  3846. );
  3847. },
  3848. };
  3849. // ss-list-card 通用列表卡片
  3850. const SsListCard = {
  3851. name: "SsListCard",
  3852. props: {
  3853. item: {
  3854. type: Object,
  3855. required: true,
  3856. },
  3857. },
  3858. emits: ["click", "change"],
  3859. setup(props, { emit }) {
  3860. const item = props.item;
  3861. const itemWidth = Vue.computed(() => {
  3862. const containerWidth =
  3863. document.body.clientWidth || document.body.scrollWidth;
  3864. if (containerWidth > 1200) {
  3865. return "30%";
  3866. }
  3867. return "45%";
  3868. });
  3869. const onItemClick = (e) => {
  3870. // 清除所有类型卡片的 active 状态
  3871. const allListCards = document.querySelectorAll(
  3872. ".knowledge-item-container"
  3873. );
  3874. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  3875. allListCards.forEach((card) => card.classList.remove("active"));
  3876. allFolderCards.forEach((card) => card.classList.remove("active"));
  3877. // 设置当前项的 active 状态
  3878. e.currentTarget.classList.add("active");
  3879. props.item.onclick();
  3880. };
  3881. const onItemChange = (e, icon, index) => {
  3882. e.stopPropagation(); // 阻止事件冒泡到卡片
  3883. props.item.buttons[0].onclick();
  3884. // emit("change", { item: props.item, icon, index });
  3885. };
  3886. return {
  3887. item,
  3888. itemWidth,
  3889. onItemClick,
  3890. onItemChange,
  3891. };
  3892. },
  3893. data() {
  3894. return {
  3895. showButtons: false,
  3896. };
  3897. },
  3898. render() {
  3899. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  3900. return Vue.h(
  3901. "div",
  3902. {
  3903. class: { "knowledge-item-container": true, active: this.item.active },
  3904. onClick: this.onItemClick,
  3905. style: { width: this.itemWidth },
  3906. },
  3907. [
  3908. this.item?.buttons?.length > 0 &&
  3909. Vue.h(
  3910. "div",
  3911. {
  3912. class: "header",
  3913. onMouseenter: () => (this.showButtons = true),
  3914. onMouseleave: () => (this.showButtons = false),
  3915. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  3916. },
  3917. [
  3918. // 只在有按钮时渲染设置图标
  3919. // this.item?.buttons?.length > 0 &&
  3920. Vue.h("div", {
  3921. class: "cart-list-setting cart-list-icon",
  3922. title: this.item?.buttons?.[0]?.title,
  3923. }),
  3924. // 鼠标移入时显示按钮列表,与图标同级
  3925. // this.item?.buttons?.length > 0 &&
  3926. this.showButtons &&
  3927. this.item?.buttons?.length > 1 &&
  3928. Vue.h(
  3929. "div",
  3930. {
  3931. class: "cart-list-button-popup",
  3932. },
  3933. this.item.buttons.map((btn) =>
  3934. Vue.h(
  3935. "div",
  3936. {
  3937. onClick: (e) => {
  3938. e.stopPropagation();
  3939. btn.onclick?.();
  3940. },
  3941. },
  3942. [
  3943. // 如果有 class,显示对应的图标
  3944. btn.class &&
  3945. Vue.h(SsCartListIcon, {
  3946. class: [btn.class],
  3947. }),
  3948. // 显示按钮文本
  3949. Vue.h("span", null, btn.title),
  3950. ]
  3951. )
  3952. )
  3953. ),
  3954. ]
  3955. ),
  3956. Vue.h("div", { class: "body" }, [
  3957. Vue.h("div", { class: "box-header" }, [
  3958. Vue.h("div", `${this.item.title}`),
  3959. ]),
  3960. Vue.h(
  3961. "div",
  3962. {
  3963. class: !this.item.thumb ? "no-thumb box-body" : "box-body",
  3964. },
  3965. [
  3966. this.item.thumb
  3967. ? Vue.h("div", { class: "left" }, [
  3968. Vue.h("img", {
  3969. src: this.item.thumb,
  3970. alt: "Thumbnail",
  3971. class: "imgUnHandle",
  3972. style: {
  3973. "object-fit": "cover",
  3974. width: "100%",
  3975. height: "100%",
  3976. },
  3977. }),
  3978. ])
  3979. : null,
  3980. Vue.h("div", { class: "right" }, [
  3981. ...this.item.tags.map((tag) => {
  3982. const [key, value] = Object.entries(tag)[0];
  3983. return Vue.h(
  3984. "div",
  3985. {
  3986. class: "title",
  3987. title: `${key}: ${value}`,
  3988. },
  3989. `${key}: ${value}`
  3990. );
  3991. }),
  3992. ]),
  3993. ]
  3994. ),
  3995. ]),
  3996. ]
  3997. );
  3998. },
  3999. };
  4000. // ss-folder-card 文件夹卡片
  4001. const SsFolderCard = {
  4002. name: "SsFolderCard",
  4003. props: {
  4004. item: {
  4005. type: Object,
  4006. required: true,
  4007. },
  4008. },
  4009. data() {
  4010. return {
  4011. showButtons: false,
  4012. };
  4013. },
  4014. emits: ["click", "change"],
  4015. setup(props, { emit }) {
  4016. const item = props.item;
  4017. const showChildren = ref(false);
  4018. const eventBus = window.parent.sharedEventBus;
  4019. const itemWidth = Vue.computed(() => {
  4020. const containerWidth =
  4021. document.body.clientWidth || document.body.scrollWidth;
  4022. return containerWidth > 1200 ? "45%" : "90%";
  4023. });
  4024. onMounted(() => {
  4025. eventBus.subscribe("folderPath", (path) => {
  4026. const currentPath = path || [];
  4027. // 如果当前文件夹不在路径中,则销毁视图
  4028. if (
  4029. !currentPath.some((item) => item.folder.title === props.item.title)
  4030. ) {
  4031. showChildren.value = false;
  4032. }
  4033. });
  4034. });
  4035. const onItemClick = (e) => {
  4036. if (e && e.stopPropagation) {
  4037. e.stopPropagation();
  4038. }
  4039. // 单击只处理 active 状态
  4040. if (e && e.currentTarget) {
  4041. const allListCards = document.querySelectorAll(
  4042. ".knowledge-item-container"
  4043. );
  4044. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  4045. allListCards.forEach((card) => card.classList.remove("active"));
  4046. allFolderCards.forEach((card) => card.classList.remove("active"));
  4047. e.currentTarget.classList.add("active");
  4048. } else {
  4049. // 如果是数据对象,需要找到对应的 DOM 元素
  4050. const allListCards = document.querySelectorAll(
  4051. ".knowledge-item-container"
  4052. );
  4053. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  4054. allListCards.forEach((card) => card.classList.remove("active"));
  4055. allFolderCards.forEach((card) => card.classList.remove("active"));
  4056. // 找到标题匹配的文件夹元素
  4057. const targetFolder = Array.from(allFolderCards).find((card) =>
  4058. card.textContent.includes(e.title)
  4059. );
  4060. if (targetFolder) {
  4061. targetFolder.classList.add("active");
  4062. }
  4063. }
  4064. emit("click", item);
  4065. };
  4066. // 修改双击处理函数
  4067. const handleFolderDblClick = (folder, e) => {
  4068. if (e) e.stopPropagation();
  4069. if (folder.children?.length) {
  4070. showChildren.value = true;
  4071. const pathInfo = {
  4072. title: folder.title,
  4073. folder: folder,
  4074. };
  4075. const currentPath = eventBus.getState("folderPath") || [];
  4076. if (!currentPath.some((item) => item.title === folder.title)) {
  4077. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  4078. }
  4079. }
  4080. };
  4081. const onItemChange = (e, icon, index) => {
  4082. e.stopPropagation();
  4083. props.item.buttons[0].onclick();
  4084. // emit("change", { item: props.item, icon, index });
  4085. };
  4086. return {
  4087. item,
  4088. itemWidth,
  4089. showChildren,
  4090. onItemClick,
  4091. onItemChange,
  4092. handleFolderDblClick,
  4093. };
  4094. },
  4095. render() {
  4096. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  4097. if (this.showChildren) {
  4098. return h(SsFolderCartView, {
  4099. folder: this.item,
  4100. });
  4101. }
  4102. return Vue.h(
  4103. "div",
  4104. {
  4105. class: { "ss-folder-list": true, active: this.item.active },
  4106. onClick: (e) => {
  4107. e.stopPropagation();
  4108. this.onItemClick(e);
  4109. },
  4110. onDblclick: (e) => this.handleFolderDblClick(this.item, e),
  4111. style: { width: this.itemWidth },
  4112. },
  4113. [
  4114. // 文件夹特有的装饰元素
  4115. Vue.h("div", { class: "ss-folder-list-trapezoid" }),
  4116. Vue.h("div", { class: "ss-folder-list-top-transparent" }),
  4117. Vue.h("div", { class: "ss-folder-list-top" }),
  4118. Vue.h("div", { class: "ss-folder-list-right" }),
  4119. // header 部分(按钮)
  4120. this.item?.buttons?.length > 0 &&
  4121. Vue.h(
  4122. "div",
  4123. {
  4124. class: "header",
  4125. onMouseenter: () => (this.showButtons = true),
  4126. onMouseleave: () => (this.showButtons = false),
  4127. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  4128. },
  4129. [
  4130. // this.item?.buttons?.length > 0 &&
  4131. Vue.h("div", {
  4132. class: "cart-list-setting cart-list-icon",
  4133. title: this.item?.buttons?.[0]?.title,
  4134. }),
  4135. // this.item?.buttons?.length > 0 &&
  4136. this.showButtons &&
  4137. this.item?.buttons?.length > 1 &&
  4138. Vue.h(
  4139. "div",
  4140. {
  4141. class: "cart-list-button-popup",
  4142. },
  4143. this.item.buttons.map((btn) =>
  4144. Vue.h(
  4145. "div",
  4146. {
  4147. onClick: (e) => {
  4148. e.stopPropagation();
  4149. btn.onclick?.();
  4150. },
  4151. },
  4152. [
  4153. btn.class &&
  4154. Vue.h(SsCartListIcon, {
  4155. class: [btn.class],
  4156. }),
  4157. Vue.h("span", null, btn.title),
  4158. ]
  4159. )
  4160. )
  4161. ),
  4162. ]
  4163. ),
  4164. // body 部分
  4165. Vue.h("div", { class: "body" }, [
  4166. Vue.h("div", { class: "box-header" }, [
  4167. Vue.h("div", null, this.item.title),
  4168. ]),
  4169. Vue.h(
  4170. "div",
  4171. {
  4172. class: !this.item.thumb ? "no-thumb box-body" : "box-body",
  4173. },
  4174. [
  4175. this.item.thumb
  4176. ? Vue.h("div", { class: "left" }, [
  4177. Vue.h("img", {
  4178. src: this.item.thumb,
  4179. alt: "Thumbnail",
  4180. class: "imgUnHandle",
  4181. style: {
  4182. "object-fit": "cover",
  4183. width: "100%",
  4184. height: "100%",
  4185. },
  4186. }),
  4187. ])
  4188. : null,
  4189. Vue.h("div", { class: "right" }, [
  4190. ...this.item.tags.map((tag) => {
  4191. const [key, value] = Object.entries(tag)[0];
  4192. return Vue.h(
  4193. "div",
  4194. {
  4195. class: "title",
  4196. title: `${key}: ${value}`,
  4197. },
  4198. `${key}: ${value}`
  4199. );
  4200. }),
  4201. ]),
  4202. ]
  4203. ),
  4204. ]),
  4205. ]
  4206. );
  4207. },
  4208. };
  4209. // SsFolderCartView 组件 - 用于显示文件夹内容
  4210. const SsFolderCartView = {
  4211. name: "SsFolderCartView",
  4212. props: {
  4213. folder: {
  4214. type: Object,
  4215. required: true,
  4216. },
  4217. },
  4218. emits: ["click"],
  4219. setup(props, { emit }) {
  4220. const eventBus = window.parent.sharedEventBus;
  4221. const currentFolder = ref(props.folder);
  4222. const showChildren = ref(false);
  4223. const onItemClick = (e) => {
  4224. if (e && e.stopPropagation) {
  4225. e.stopPropagation();
  4226. }
  4227. // 单击只处理 active 状态
  4228. if (e && e.currentTarget) {
  4229. const allListCards = document.querySelectorAll(
  4230. ".knowledge-item-container"
  4231. );
  4232. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  4233. allListCards.forEach((card) => card.classList.remove("active"));
  4234. allFolderCards.forEach((card) => card.classList.remove("active"));
  4235. e.currentTarget.classList.add("active");
  4236. } else {
  4237. // 如果是数据对象,需要找到对应的 DOM 元素
  4238. const allListCards = document.querySelectorAll(
  4239. ".knowledge-item-container"
  4240. );
  4241. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  4242. allListCards.forEach((card) => card.classList.remove("active"));
  4243. allFolderCards.forEach((card) => card.classList.remove("active"));
  4244. // 找到标题匹配的文件夹元素
  4245. const targetFolder = Array.from(allFolderCards).find((card) =>
  4246. card.textContent.includes(e.title)
  4247. );
  4248. if (targetFolder) {
  4249. targetFolder.classList.add("active");
  4250. }
  4251. }
  4252. emit("click", props.folder);
  4253. };
  4254. const handleFolderDblClick = (folder, e) => {
  4255. if (e) e.stopPropagation();
  4256. if (folder.children?.length) {
  4257. showChildren.value = true;
  4258. const pathInfo = {
  4259. title: folder.title,
  4260. folder: folder,
  4261. };
  4262. const currentPath = eventBus.getState("folderPath") || [];
  4263. if (!currentPath.some((item) => item.title === folder.title)) {
  4264. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  4265. currentFolder.value = folder;
  4266. }
  4267. }
  4268. };
  4269. const goBack = (targetFolder) => {
  4270. if (targetFolder === null) {
  4271. // 返回根目录
  4272. eventBus.publish("folderPath", []);
  4273. } else {
  4274. currentFolder.value = targetFolder;
  4275. }
  4276. };
  4277. return {
  4278. currentFolder,
  4279. showChildren,
  4280. onItemClick,
  4281. handleFolderDblClick,
  4282. goBack,
  4283. };
  4284. },
  4285. render() {
  4286. return h(
  4287. "div",
  4288. {
  4289. class: "page-container",
  4290. style: {
  4291. position: "fixed",
  4292. top: 0,
  4293. left: 0,
  4294. width: "100%",
  4295. height: "100%",
  4296. background: "var(--lightgray)",
  4297. padding: "20px 0",
  4298. zIndex: 1000,
  4299. },
  4300. },
  4301. [
  4302. // 搜索栏
  4303. h("div", { class: "search-bar" }, [
  4304. h("div", { class: "search-bar-contaienr" }, [
  4305. h(SsBreadcrumb, {
  4306. level: {
  4307. onBack: this.goBack,
  4308. },
  4309. }),
  4310. ]),
  4311. ]),
  4312. // 内容区域
  4313. h(
  4314. "div",
  4315. {
  4316. class: "content-area item-content-area",
  4317. style: { gap: "20px" },
  4318. },
  4319. [
  4320. ...(this.currentFolder.children || []).map((child, index) =>
  4321. h(child.children ? SsFolderCard : SsListCard, {
  4322. key: index,
  4323. item: child,
  4324. onClick: (e) => this.onItemClick(e),
  4325. onDblclick: (e) => this.handleFolderDblClick(child, e),
  4326. })
  4327. ),
  4328. ]
  4329. ),
  4330. ]
  4331. );
  4332. },
  4333. };
  4334. // ss-page分页
  4335. const SsPage = {
  4336. name: "SsPage",
  4337. props: {
  4338. total: {
  4339. type: Number,
  4340. required: true,
  4341. },
  4342. size: {
  4343. type: Number,
  4344. default: 10,
  4345. },
  4346. page: {
  4347. type: Number,
  4348. default: 1,
  4349. },
  4350. onChange: {
  4351. type: Function,
  4352. default: () => {},
  4353. },
  4354. },
  4355. setup(props) {
  4356. const totalItems = ref(props.total); // 总条目数
  4357. const totalPages = ref(Math.ceil(props.total / props.size));
  4358. const currentPage = ref(props.page); // 当前页码
  4359. // 计算显示的信息
  4360. const pageInfo = ref(
  4361. `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`
  4362. );
  4363. // 上一页的逻辑
  4364. const goToPreviousPage = (e) => {
  4365. e.preventDefault(); // 阻止默认行为
  4366. if (currentPage.value > 1) {
  4367. currentPage.value -= 1;
  4368. updatePageInfo();
  4369. props.onChange?.({
  4370. pageNo: currentPage.value, // 当前页码
  4371. rowNumPer: props.size, // 每页条数
  4372. rowNum: props.total, // 总记录数
  4373. });
  4374. }
  4375. };
  4376. // 下一页的逻辑
  4377. const goToNextPage = (e) => {
  4378. e.preventDefault(); // 阻止默认行为
  4379. if (currentPage.value < totalPages.value) {
  4380. currentPage.value += 1;
  4381. updatePageInfo();
  4382. props.onChange?.({
  4383. pageNo: currentPage.value, // 当前页码
  4384. rowNumPer: props.size, // 每页条数
  4385. rowNum: props.total, // 总记录数
  4386. });
  4387. }
  4388. };
  4389. // 更新页码信息的函数
  4390. const updatePageInfo = () => {
  4391. pageInfo.value = `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`;
  4392. };
  4393. return {
  4394. pageInfo,
  4395. totalPages,
  4396. goToPreviousPage,
  4397. goToNextPage,
  4398. };
  4399. },
  4400. render(props, { slots, emit }) {
  4401. return Vue.h("div", { class: "pager-container" }, [
  4402. Vue.h("input", { type: "hidden", name: "rowNum", value: props.total }),
  4403. Vue.h("input", {
  4404. type: "hidden",
  4405. name: "rowNumPer",
  4406. value: props.size,
  4407. }),
  4408. Vue.h("input", {
  4409. type: "hidden",
  4410. name: "pageCount",
  4411. value: this.totalPages,
  4412. }),
  4413. Vue.h("input", { type: "hidden", name: "pageNo", value: props.page }),
  4414. Vue.h("div", { class: "pager-content" }, [
  4415. Vue.h("div", { class: "info" }, this.pageInfo),
  4416. Vue.h(
  4417. "div",
  4418. { class: "btn" },
  4419. Vue.h(
  4420. "button",
  4421. { onClick: (e) => this.goToPreviousPage(e) },
  4422. "上一页"
  4423. )
  4424. ),
  4425. Vue.h(
  4426. "div",
  4427. { class: "btn" },
  4428. Vue.h("button", { onClick: (e) => this.goToNextPage(e) }, "下一页")
  4429. ),
  4430. ]),
  4431. ]);
  4432. },
  4433. };
  4434. // ss-right-info 一级页面右边栏
  4435. const SSRightInfo = {
  4436. name: "SSRightInfo",
  4437. setup() {
  4438. // 初始化响应式数据
  4439. const item = ref({
  4440. thumb: "images/example/project-img.png", // 更换为适合你项目的实际路径
  4441. title: "工业和信息化产业高质量发展资金",
  4442. });
  4443. return {
  4444. item,
  4445. };
  4446. },
  4447. render() {
  4448. return Vue.h("div", { class: "info-container" }, [
  4449. Vue.h("div", { class: "header" }, [
  4450. Vue.h("div", [
  4451. Vue.h("img", {
  4452. src: this.item.thumb,
  4453. class: "imgUnHandle",
  4454. style: { "object-fit": "cover", width: "100%", height: "100%" },
  4455. }), // 将 ImageViewer 替换为 img 标签
  4456. ]),
  4457. Vue.h("div", [Vue.h("div", this.item.title)]),
  4458. ]),
  4459. Vue.h("div", { class: "section-container" }, [
  4460. Vue.h("div", { class: "section" }, [
  4461. Vue.h("div", { class: "title" }, "合同"),
  4462. Vue.h("div", { class: "text" }, "合同总金额:42,399,320"),
  4463. Vue.h(
  4464. "div",
  4465. { class: "a" },
  4466. "《工业和信息化产业高质量发展资金补助合同》"
  4467. ),
  4468. ]),
  4469. Vue.h("div", { class: "section" }, [
  4470. Vue.h("div", { class: "title" }, "发票"),
  4471. Vue.h("div", { class: "text" }, "应开发票总额:42,399,320"),
  4472. Vue.h("div", { class: "text" }, "已开发票金额:17,235,345"),
  4473. Vue.h("div", { class: "text" }, "未开发票金额:25,163,975"),
  4474. ]),
  4475. Vue.h("div", { class: "section" }, [
  4476. Vue.h("div", { class: "title" }, "项目组成员"),
  4477. Vue.h("div", { class: "text" }, "我司:3人"),
  4478. Vue.h("div", { class: "text" }, "对方:2人"),
  4479. Vue.h("div", { class: "text" }, "项目负责人:张三"),
  4480. ]),
  4481. Vue.h("div", { class: "section" }, [
  4482. Vue.h("div", { class: "title" }, "采购"),
  4483. Vue.h("div", { class: "text" }, "总额:999,320"),
  4484. Vue.h("div", { class: "text" }, "已付金额:335,345"),
  4485. Vue.h("div", { class: "text" }, "未付金额:663,975"),
  4486. ]),
  4487. ]),
  4488. ]);
  4489. },
  4490. };
  4491. //
  4492. const SsSuccessPopup = {
  4493. name: "SsSuccessPopup",
  4494. props: {
  4495. right: {
  4496. type: String,
  4497. default: "20px",
  4498. },
  4499. bottom: {
  4500. type: String,
  4501. default: "calc(100% + 5px)",
  4502. },
  4503. },
  4504. setup(props, { expose }) {
  4505. // 响应式状态:是否可见
  4506. const visible = ref(false);
  4507. // 计算样式
  4508. const style = computed(() => {
  4509. return {
  4510. "--message-dialog-right": props.right,
  4511. "--message-dialog-bottom": props.bottom,
  4512. };
  4513. });
  4514. // 显示对话框的方法
  4515. const show = () => {
  4516. visible.value = true;
  4517. };
  4518. // 隐藏对话框的方法
  4519. const hide = () => {
  4520. visible.value = false;
  4521. };
  4522. // 将方法暴露给外部使用
  4523. expose({ show, hide });
  4524. // 返回渲染函数
  4525. return () => {
  4526. if (!visible.value) return null;
  4527. const SsIcon = resolveComponent("ss-icon");
  4528. return h(
  4529. "div",
  4530. {
  4531. class: "success-popup",
  4532. style: style.value,
  4533. onClick: (e) => e.stopPropagation(),
  4534. },
  4535. [
  4536. h("div", { class: "left" }, [
  4537. h("div", { class: "icon" }, [
  4538. h(SsIcon, { name: "check", size: "36px" }),
  4539. ]),
  4540. ]),
  4541. h("div", { class: "right" }, [
  4542. h("div", { class: "title" }, "提交成功"),
  4543. h("div", { class: "desc" }, "您的信息已成功提交。"),
  4544. ]),
  4545. ]
  4546. );
  4547. };
  4548. },
  4549. };
  4550. const SsErrorDialog = {
  4551. name: "SsErrorDialog",
  4552. setup(props, { emit }) {
  4553. const visible = ref(false);
  4554. const style = computed(() => {
  4555. return {};
  4556. });
  4557. const show = () => {
  4558. visible.value = true;
  4559. };
  4560. const hide = () => {
  4561. visible.value = false;
  4562. };
  4563. const onBack = () => {
  4564. emit("back");
  4565. hide();
  4566. };
  4567. return {
  4568. visible,
  4569. style,
  4570. show,
  4571. hide,
  4572. onBack,
  4573. };
  4574. },
  4575. render() {
  4576. const SsIcon = resolveComponent("ss-icon");
  4577. return this.visible
  4578. ? h(
  4579. "div",
  4580. {
  4581. class: "errorDialog",
  4582. style: this.style,
  4583. onClick: (event) => event.stopPropagation(),
  4584. },
  4585. [
  4586. h("div", { class: "body" }, [
  4587. h("div", { class: "left" }, [
  4588. h("div", { class: "icon" }, [
  4589. h(SsIcon, { name: "close", size: "36px" }),
  4590. ]),
  4591. ]),
  4592. h("div", { class: "right" }, [
  4593. h("div", { class: "title" }, "操作失败"),
  4594. h("div", { class: "desc" }, "请点击返回以继续。"),
  4595. ]),
  4596. ]),
  4597. h("div", { class: "footer" }, [
  4598. h("div", { class: "left" }),
  4599. h("div", { class: "right" }, [
  4600. h(
  4601. "div",
  4602. {
  4603. class: "btn",
  4604. onClick: this.onBack,
  4605. },
  4606. [h(SsIcon, { name: "arrow-left-line" }), h("div", "返回")]
  4607. ),
  4608. ]),
  4609. ]),
  4610. ]
  4611. )
  4612. : null;
  4613. },
  4614. };
  4615. /**
  4616. * 审核链条
  4617. * @name ss-verify
  4618. * @param { Array } verify-list 审核节点列表
  4619. * @property { Array } verify-list 审核节点列表
  4620. * @example <ss-verify :verify-list="verifyList"></ss-verify>
  4621. * verify-list [
  4622. * {
  4623. * groupName: "", // 群组名称
  4624. * open: true, // 默认是否展开
  4625. * children:[ //群组里的人员
  4626. * {
  4627. * thumb: "images/example/user-4.png", // 头像
  4628. * name: "李丽思 ", // 姓名
  4629. * role: "人事处处长", // 角色
  4630. * description: "同意。", // 审核意见
  4631. * time: "09:38 08/11", // 审核时间
  4632. * video: false, // false不显示/true显示 视频icon
  4633. * link: false, // false不显示/true显示 链接icon 后续应该是附件
  4634. * }
  4635. * ]
  4636. * }
  4637. * ]
  4638. */
  4639. const SsVerify = {
  4640. name: "SsVerify",
  4641. props: {
  4642. verifyList: {
  4643. type: Array,
  4644. required: true,
  4645. },
  4646. },
  4647. setup(props) {
  4648. const toggleOpen = (item) => {
  4649. item.open = !item.open;
  4650. };
  4651. onMounted(() => {
  4652. setTimeout(() => {
  4653. const lastOpenGroup = document.querySelector(".group-item-last-open");
  4654. console.log("lastOpenGroup", lastOpenGroup);
  4655. if (lastOpenGroup) {
  4656. const nodes = $(lastOpenGroup).find(".verify-node-container");
  4657. if (nodes.length) {
  4658. let totalHeight = 0;
  4659. const gudingHeight = 100;
  4660. if (nodes.length === 1) {
  4661. totalHeight = gudingHeight;
  4662. } else {
  4663. // 累加除最后一个节点外的所有节点高度
  4664. for (let i = 0; i < nodes.length - 1; i++) {
  4665. totalHeight += $(nodes[i]).outerHeight();
  4666. }
  4667. totalHeight += gudingHeight;
  4668. }
  4669. console.log("节点信息:", {
  4670. 节点总数: nodes.length,
  4671. 计算后的高度: totalHeight,
  4672. });
  4673. lastOpenGroup.style.setProperty(
  4674. "--group-line-height",
  4675. `${totalHeight}px`
  4676. );
  4677. }
  4678. }
  4679. }, 0);
  4680. });
  4681. return {
  4682. toggleOpen,
  4683. };
  4684. },
  4685. render() {
  4686. const SsIcon = resolveComponent("ss-icon");
  4687. const SsCommonIcon = resolveComponent("ss-common-icon");
  4688. const SsVerifyNode = resolveComponent("ss-verify-node");
  4689. return h(
  4690. "div",
  4691. { class: "verify-nodes" },
  4692. this.verifyList.map((item, i) =>
  4693. h(
  4694. "div",
  4695. {
  4696. key: i,
  4697. class: {
  4698. "group-item": true,
  4699. "group-item-last-open":
  4700. i === this.verifyList.length - 1 && item.open,
  4701. },
  4702. },
  4703. [
  4704. h(
  4705. "div",
  4706. {
  4707. class: "group-item-title",
  4708. onClick: () => this.toggleOpen(item),
  4709. },
  4710. [
  4711. h("div", { class: "icon" }, [
  4712. item.open
  4713. ? h(SsCommonIcon, { class: "common-icon-folder-open" })
  4714. : h(SsCommonIcon, { class: "common-icon-folder-close" }),
  4715. h(
  4716. "div",
  4717. {
  4718. class: "num",
  4719. style: { top: item.open ? "60%" : "55%" },
  4720. },
  4721. item.children?.length || 0
  4722. ),
  4723. ]),
  4724. h("div", { class: "name" }, item.groupName),
  4725. ]
  4726. ),
  4727. item.open && item.children?.length > 0
  4728. ? h(
  4729. "div",
  4730. { class: "group-item-children" },
  4731. item.children.map((citem, j) =>
  4732. h(SsVerifyNode, {
  4733. key: j,
  4734. item: citem,
  4735. // isGroup: i + 1 !== this.verifyList.length,
  4736. isGroup: true,
  4737. })
  4738. )
  4739. )
  4740. : null,
  4741. ]
  4742. )
  4743. )
  4744. );
  4745. },
  4746. };
  4747. /**
  4748. * 审核页面的审核节点
  4749. * @name ss-verify-node
  4750. * @param {Object} item 审核节点信息
  4751. * @param {Boolean} isGroup 是否为分组节点
  4752. */
  4753. const SsVerifyNode = {
  4754. name: "SsVerifyNode",
  4755. props: {
  4756. item: {
  4757. type: Object,
  4758. required: true,
  4759. },
  4760. isGroup: {
  4761. type: Boolean,
  4762. default: false,
  4763. },
  4764. },
  4765. render() {
  4766. const SsIcon = resolveComponent("ss-icon");
  4767. const SsCommonIcon = resolveComponent("ss-common-icon");
  4768. return Vue.h("div", { class: "verify-node-container" }, [
  4769. Vue.h("div", { class: "info" }, [
  4770. Vue.h("div", { class: "avatar" }, [
  4771. Vue.h("img", {
  4772. src: this.item.thumb,
  4773. style: {
  4774. width: "50px",
  4775. height: "50px",
  4776. borderRadius: "50%",
  4777. },
  4778. }),
  4779. ]),
  4780. Vue.h("div", { class: "desc" }, [
  4781. Vue.h("div", this.item.name),
  4782. Vue.h("div", this.item.role),
  4783. ]),
  4784. Vue.h("div", { class: "link" }, [
  4785. Vue.h("div", [
  4786. this.item.video
  4787. ? Vue.h(SsCommonIcon, { class: "common-icon-video" })
  4788. : null,
  4789. this.item.link
  4790. ? Vue.h(SsCommonIcon, {
  4791. class: "common-icon-paper-clip",
  4792. })
  4793. : null,
  4794. ]),
  4795. ]),
  4796. ]),
  4797. Vue.h(
  4798. "div",
  4799. {
  4800. class: {
  4801. description: true,
  4802. link: this.isGroup,
  4803. },
  4804. attrs: { "data-num": "3" },
  4805. },
  4806. [Vue.h("div", this.item.description)]
  4807. ),
  4808. Vue.h("div", { class: "time" }, this.item.time),
  4809. ]);
  4810. },
  4811. };
  4812. /**
  4813. * 智能识别图片的左侧图片播放 可以放大缩小旋转图片
  4814. * @name ss-orc-img-box
  4815. * @param { Object } image-obj 包含图片的url, 和图片的名称
  4816. *
  4817. */
  4818. const SsOrcImgBox = {
  4819. name: "SsOrcImgBox",
  4820. props: {
  4821. imageObj: {
  4822. type: Object,
  4823. required: true,
  4824. },
  4825. },
  4826. setup(props) {
  4827. const zoom = ref(1);
  4828. const rotation = ref(0);
  4829. const containerWidth = ref(0);
  4830. const containerHeight = ref(0);
  4831. const container = ref(null);
  4832. const imgPosition = ref({ x: 0, y: 0 });
  4833. const isDragging = ref(false);
  4834. const lastMousePosition = ref({ x: 0, y: 0 });
  4835. const imgStyle = computed(() => ({
  4836. width: `${zoom.value * 100}%`,
  4837. height: `${zoom.value * 100}%`,
  4838. transform: `rotate(${rotation.value}deg) translate(${imgPosition.value.x}px, ${imgPosition.value.y}px)`,
  4839. transformOrigin: "center center",
  4840. cursor: isDragging.value ? "grabbing" : "grab",
  4841. }));
  4842. const resetZoom = () => {
  4843. zoom.value = 1;
  4844. rotation.value = rotation.value + 90;
  4845. imgPosition.value = { x: 0, y: 0 };
  4846. };
  4847. const handleRangeChange = (event) => {
  4848. const value = event.target.value / 50; // 0 到 100 映射到 0 到 2 的缩放
  4849. zoom.value = Math.max(value, 0.1); // 设置最小缩放值为 0.1
  4850. };
  4851. const updateImgBoxDimensions = () => {
  4852. if (container.value) {
  4853. containerWidth.value = container.value.clientWidth;
  4854. containerHeight.value = container.value.clientHeight;
  4855. }
  4856. };
  4857. const onMouseDown = (event) => {
  4858. isDragging.value = true;
  4859. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  4860. };
  4861. const onMouseMove = (event) => {
  4862. if (isDragging.value) {
  4863. const dx = event.clientX - lastMousePosition.value.x;
  4864. const dy = event.clientY - lastMousePosition.value.y;
  4865. // 防止旋转后拖动的x,y反转
  4866. // 首先将当前旋转角度从度数转换为弧度,因为 JavaScript 的 Math 库使用弧度
  4867. const angle = rotation.value * (Math.PI / 180);
  4868. // 使用基本的二维旋转矩阵将原始位移 dx 和 dy 转换为旋转后的位移 rotatedDx 和 rotatedDy。
  4869. const rotatedDx = dx * Math.cos(angle) + dy * Math.sin(angle);
  4870. const rotatedDy = dy * Math.cos(angle) - dx * Math.sin(angle);
  4871. imgPosition.value = {
  4872. x: imgPosition.value.x + rotatedDx,
  4873. y: imgPosition.value.y + rotatedDy,
  4874. };
  4875. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  4876. }
  4877. };
  4878. const onMouseUp = () => {
  4879. isDragging.value = false;
  4880. };
  4881. onMounted(() => {
  4882. nextTick(() => {
  4883. updateImgBoxDimensions();
  4884. window.addEventListener("resize", updateImgBoxDimensions);
  4885. window.addEventListener("mousemove", onMouseMove);
  4886. window.addEventListener("mouseup", onMouseUp);
  4887. });
  4888. });
  4889. return {
  4890. zoom,
  4891. rotation,
  4892. container,
  4893. imgStyle,
  4894. resetZoom,
  4895. handleRangeChange,
  4896. containerWidth,
  4897. containerHeight,
  4898. onMouseDown,
  4899. imgPosition,
  4900. };
  4901. },
  4902. render() {
  4903. const SsIcon = resolveComponent("ss-icon");
  4904. return h("div", { class: "ocr-img-box" }, [
  4905. h("div", { class: "img-bar" }, [
  4906. h("div", this.imageObj.name),
  4907. h("div", { class: "action-bar" }, [
  4908. h("div", { class: "ocr-img-range-box" }, [
  4909. h("input", {
  4910. type: "range",
  4911. min: 0,
  4912. max: 100,
  4913. value: this.zoom * 50, // 初始位置为50
  4914. onInput: this.handleRangeChange,
  4915. }),
  4916. h("span", { class: "line" }),
  4917. ]),
  4918. h(SsIcon, {
  4919. name: "reset",
  4920. size: "26px",
  4921. onClick: this.resetZoom,
  4922. }),
  4923. ]),
  4924. ]),
  4925. h("div", { class: "img-viewer", ref: "container" }, [
  4926. h(
  4927. "div",
  4928. {
  4929. class: "img-box",
  4930. style: {
  4931. width: `${this.containerWidth}px`,
  4932. height: `${this.containerHeight}px`,
  4933. overflow: "hidden",
  4934. position: "relative",
  4935. },
  4936. },
  4937. [
  4938. h("img", {
  4939. src: this.imageObj.thumb,
  4940. style: this.imgStyle,
  4941. class: "zoomable-img",
  4942. onMousedown: this.onMouseDown,
  4943. }),
  4944. ]
  4945. ),
  4946. ]),
  4947. ]);
  4948. },
  4949. };
  4950. // 搜索输入框组件
  4951. const SsSearchInput = {
  4952. name: "SsSearchInput",
  4953. props: {
  4954. name: String,
  4955. placeholder: String,
  4956. width: {
  4957. type: String,
  4958. default: "100px",
  4959. },
  4960. modelValue: String,
  4961. },
  4962. emits: ["update:modelValue", "search"],
  4963. setup(props, { emit }) {
  4964. const handleInput = (e) => {
  4965. emit("update:modelValue", e.target.value);
  4966. };
  4967. const handleKeyup = (e) => {
  4968. if (e.key === "Enter") {
  4969. emit("search");
  4970. }
  4971. };
  4972. return { handleInput, handleKeyup };
  4973. },
  4974. render() {
  4975. return h(
  4976. "div",
  4977. {
  4978. class: "input",
  4979. style: this.width ? { width: this.width } : undefined,
  4980. },
  4981. [
  4982. h("input", {
  4983. name: this.name,
  4984. placeholder: this.placeholder,
  4985. value: this.modelValue,
  4986. onInput: this.handleInput,
  4987. onKeyup: this.handleKeyup,
  4988. }),
  4989. ]
  4990. );
  4991. },
  4992. };
  4993. // ss-search-date-picker 日期时间选择器组件
  4994. const SsSearchDatePicker = {
  4995. name: "SsSearchDatePicker",
  4996. props: {
  4997. modelValue: {
  4998. type: [String, Number, Date],
  4999. default: "",
  5000. },
  5001. name: {
  5002. type: String,
  5003. required: true,
  5004. },
  5005. type: {
  5006. type: String,
  5007. default: "date",
  5008. validator: (value) => ["date", "datetime", "time"].includes(value),
  5009. },
  5010. fmt: {
  5011. type: String,
  5012. default: null,
  5013. },
  5014. placeholder: {
  5015. type: String,
  5016. default: "",
  5017. },
  5018. width: {
  5019. type: String,
  5020. default: "100%",
  5021. },
  5022. },
  5023. emits: ["update:modelValue"],
  5024. setup(props, { emit }) {
  5025. const errMsg = ref("");
  5026. const validate = () => {
  5027. if (window.ssVm) {
  5028. const result = window.ssVm.validateField(props.name);
  5029. console.log("validate", window.ssVm.validateField(props.name));
  5030. errMsg.value = result.valid ? "" : result.message;
  5031. }
  5032. };
  5033. // 根据type确定默认格式
  5034. const defaultFormat = computed(() => {
  5035. switch (props.type) {
  5036. case "datetime":
  5037. return "YYYY-MM-DD HH:mm:ss";
  5038. case "date":
  5039. return "YYYY-MM-DD";
  5040. case "time":
  5041. return "HH:mm:ss";
  5042. }
  5043. });
  5044. const convertJavaFormatToElement = (javaFormat) => {
  5045. if (!javaFormat) return null;
  5046. return javaFormat
  5047. .replace("yyyy", "YYYY")
  5048. .replace("MM", "MM")
  5049. .replace("dd", "DD")
  5050. .replace("HH", "HH")
  5051. .replace("mm", "mm")
  5052. .replace("ss", "ss");
  5053. };
  5054. const finalFormat = computed(() => {
  5055. if (props.fmt) {
  5056. return convertJavaFormatToElement(props.fmt);
  5057. }
  5058. return defaultFormat.value;
  5059. });
  5060. // 使用 resolveComponent 获取组件
  5061. const ElDatePicker = resolveComponent("ElDatePicker");
  5062. const ElTimePicker = resolveComponent("ElTimePicker");
  5063. const SsFormIcon = resolveComponent("SsFormIcon");
  5064. const ElIcon = resolveComponent("ElIcon");
  5065. let useTimePicker = true;
  5066. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  5067. if (props.fmt) {
  5068. //有fmt属性,则以fmt属性优先判断类型
  5069. if (/[dMy]/.test(props.fmt)) {
  5070. //如果有传入日期格式,且含年月日
  5071. useTimePicker = false;
  5072. } else {
  5073. useTimePicker = true;
  5074. }
  5075. } else if (props.type !== "time") {
  5076. useTimePicker = false;
  5077. }
  5078. const dateType = computed(() => {
  5079. const fmt = props.fmt || "";
  5080. if (fmt.includes("HH:mm:ss")) {
  5081. return "datetime";
  5082. } else if (fmt.includes("HH:mm")) {
  5083. return "datetime";
  5084. } else if (fmt.includes("mm:ss")) {
  5085. return "time";
  5086. }
  5087. return "date";
  5088. });
  5089. const handleValueUpdate = (val) => {
  5090. emit("update:modelValue", val);
  5091. emit("change", val); // 同时触发 change 事件
  5092. setTimeout(() => {
  5093. validate();
  5094. }, 50);
  5095. };
  5096. return () =>
  5097. h(
  5098. "div",
  5099. { class: "ss-search-date-picker", style: { width: props.width } },
  5100. [
  5101. h("input", {
  5102. type: "hidden",
  5103. name: props.name,
  5104. value: props.modelValue,
  5105. }),
  5106. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  5107. modelValue: props.modelValue,
  5108. "onUpdate:modelValue": handleValueUpdate,
  5109. type: dateType.value,
  5110. format: finalFormat.value,
  5111. "value-format": finalFormat.value,
  5112. clearable: true,
  5113. placeholder: props.placeholder,
  5114. class: "custom-date-picker", // 用于自定义样式
  5115. "time-arrow-control": props.type === "datetime", // 修改这里
  5116. size: "large", // 添加这一行,改为 large 尺寸
  5117. style: { width: "100%" },
  5118. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  5119. }),
  5120. ]
  5121. );
  5122. },
  5123. };
  5124. // 搜索按钮组件(包含下拉按钮)
  5125. const SsSearchButton = {
  5126. name: "SsSearchButton",
  5127. props: {
  5128. text: {
  5129. type: String,
  5130. required: true,
  5131. },
  5132. iconClass: {
  5133. type: String,
  5134. required: false,
  5135. },
  5136. opt: {
  5137. type: Array,
  5138. default: () => [],
  5139. },
  5140. checkId: {
  5141. type: String,
  5142. default: "0",
  5143. },
  5144. },
  5145. emits: ["click"],
  5146. setup(props, { emit }) {
  5147. const currentId = ref(props.checkId || "0");
  5148. const showPopup = ref(false);
  5149. const handleMouseEnter = () => {
  5150. showPopup.value = true;
  5151. };
  5152. const handleMouseLeave = () => {
  5153. showPopup.value = false;
  5154. };
  5155. // 添加点击事件处理,阻止默认行为
  5156. const handleClick = (e) => {
  5157. e.preventDefault();
  5158. if (props.opt?.length > 0) {
  5159. const selectedOption =
  5160. currentId.value === "0"
  5161. ? props.opt[0]
  5162. : props.opt.find((opt) => opt.id === currentId.value);
  5163. if (selectedOption) {
  5164. selectedOption.callback?.();
  5165. }
  5166. } else {
  5167. emit("click", e);
  5168. }
  5169. };
  5170. // 获取显示文本
  5171. const getDisplayText = () => {
  5172. if (!props.opt?.length) return props.text;
  5173. const selectedOption =
  5174. currentId.value === "0"
  5175. ? props.opt[0]
  5176. : props.opt.find((opt) => opt.id === currentId.value);
  5177. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  5178. };
  5179. return () =>
  5180. h(
  5181. "button",
  5182. {
  5183. class:
  5184. props.opt?.length > 0
  5185. ? "ss-drop-button ss-drop-button-more"
  5186. : "ss-drop-button",
  5187. type: "button", // 明确指定按钮类型为 button
  5188. onMouseenter: handleMouseEnter,
  5189. onMouseleave: handleMouseLeave,
  5190. onClick: handleClick, // 添加点击事件处理
  5191. },
  5192. [
  5193. props.iconClass
  5194. ? h("span", {
  5195. class: props.iconClass,
  5196. style: { fontFamily: "iconfont", marginRight: "5px" },
  5197. })
  5198. : null,
  5199. h("span", getDisplayText()),
  5200. props.opt.length > 0 &&
  5201. showPopup.value &&
  5202. h(
  5203. "div",
  5204. {
  5205. class: "popup",
  5206. },
  5207. props.opt.map((item) =>
  5208. h(
  5209. "div",
  5210. {
  5211. onClick: (e) => {
  5212. e.preventDefault(); // 选项点击也阻止默认行为
  5213. e.stopPropagation(); // 阻止事件冒泡
  5214. currentId.value = item.id; // 更新当前选中的ID
  5215. item.callback();
  5216. showPopup.value = false; // 选择后关闭弹窗
  5217. },
  5218. },
  5219. item.desc
  5220. )
  5221. )
  5222. ),
  5223. ]
  5224. );
  5225. },
  5226. };
  5227. // 下拉按钮组件
  5228. const SsDropButton = {
  5229. name: "SsDropButton",
  5230. props: {
  5231. text: {
  5232. type: String,
  5233. required: true,
  5234. },
  5235. iconClass: {
  5236. type: String,
  5237. required: true,
  5238. },
  5239. opt: {
  5240. type: Array,
  5241. default: () => [],
  5242. },
  5243. checkId: {
  5244. type: String,
  5245. default: "0",
  5246. },
  5247. onclick: {
  5248. type: Function,
  5249. default: null,
  5250. },
  5251. },
  5252. setup(props) {
  5253. const currentId = ref(props.checkId || "0");
  5254. const showPopup = ref(false);
  5255. const handleMouseEnter = () => {
  5256. showPopup.value = true;
  5257. };
  5258. const handleMouseLeave = () => {
  5259. showPopup.value = false;
  5260. };
  5261. // 添加点击事件处理,阻止默认行为
  5262. const handleClick = (e) => {
  5263. e.preventDefault();
  5264. if (props.opt?.length > 0) {
  5265. const selectedOption =
  5266. currentId.value === "0"
  5267. ? props.opt[0]
  5268. : props.opt.find((opt) => opt.id === currentId.value);
  5269. if (selectedOption) {
  5270. selectedOption.callback?.();
  5271. }
  5272. } else if (props.onclick) {
  5273. props.onclick();
  5274. }
  5275. };
  5276. // 获取显示文本
  5277. const getDisplayText = () => {
  5278. if (!props.opt?.length) return props.text;
  5279. const selectedOption =
  5280. currentId.value === "0"
  5281. ? props.opt[0]
  5282. : props.opt.find((opt) => opt.id === currentId.value);
  5283. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  5284. };
  5285. return () =>
  5286. h(
  5287. "button",
  5288. {
  5289. class:
  5290. props.opt?.length > 0
  5291. ? "ss-drop-button ss-drop-button-more"
  5292. : "ss-drop-button",
  5293. type: "button", // 明确指定按钮类型为 button
  5294. onMouseenter: handleMouseEnter,
  5295. onMouseleave: handleMouseLeave,
  5296. onClick: handleClick, // 添加点击事件处理
  5297. },
  5298. [
  5299. h("span", {
  5300. class: props.iconClass,
  5301. style: { fontFamily: "iconfont" },
  5302. }),
  5303. h("span", getDisplayText()),
  5304. props.opt.length > 0 &&
  5305. showPopup.value &&
  5306. h(
  5307. "div",
  5308. {
  5309. class: "popup",
  5310. },
  5311. props.opt.map((item) =>
  5312. h(
  5313. "div",
  5314. {
  5315. onClick: (e) => {
  5316. e.preventDefault(); // 选项点击也阻止默认行为
  5317. e.stopPropagation(); // 阻止事件冒泡
  5318. currentId.value = item.id; // 更新当前选中的ID
  5319. item.callback();
  5320. showPopup.value = false; // 选择后关闭弹窗
  5321. },
  5322. },
  5323. item.desc
  5324. )
  5325. )
  5326. ),
  5327. ]
  5328. );
  5329. },
  5330. };
  5331. /**
  5332. * 二级页面标签组件
  5333. * @name ss-sub-tab
  5334. * @description 用于展示二级页面的布局组件,包含左侧垂直标签导航(支持分组)和右侧iframe内容区
  5335. * @property {String} headerImage - 左侧顶部图片地址
  5336. * @property {Array} menuList - 菜单配置列表
  5337. * @property {Object} [activeMenu] - 当前选中的菜单项,不传则自动选择第一个可选菜单
  5338. * @property {Array} footerButtons - 底部按钮配置列表
  5339. */
  5340. /**
  5341. * SsSubTab 左侧菜单+iframe内容组件
  5342. * v3.0 改造:去掉顶部图片,改为图标+悬浮模式,iframe懒加载 by xu 20251216
  5343. */
  5344. const SsSubTab = {
  5345. name: "SsSubTab",
  5346. props: {
  5347. menuList: {
  5348. type: Array,
  5349. required: true,
  5350. },
  5351. activeMenu: {
  5352. type: String,
  5353. default: "",
  5354. },
  5355. footerButtons: {
  5356. type: Array,
  5357. default: () => [],
  5358. },
  5359. leftDisplay: {
  5360. type: Boolean,
  5361. default: true,
  5362. },
  5363. // v3.0 新增:菜单模式 collapse(悬浮展开) / fixed(始终收起) by xu 20251216
  5364. initialMode: {
  5365. type: String,
  5366. default: 'collapse',
  5367. },
  5368. },
  5369. emits: ["menu-change", "footer-click"],
  5370. setup(props, { emit }) {
  5371. // v3.0 新增:默认图标映射,使用icon-biz图标 by xu 20251216
  5372. const defaultIcons = [
  5373. 'icon-obj-ry', // 人员
  5374. 'icon-obj-dw', // 单位
  5375. 'icon-obj-gw', // 岗位
  5376. 'icon-biz-rc', // 人才
  5377. 'icon-biz-xc', // 巡查
  5378. 'icon-biz-cl', // 材料
  5379. 'icon-biz-men', // 门
  5380. 'icon-obj-xy' // 协议
  5381. ];
  5382. const getMenuIcon = (item, index) => {
  5383. if (item.icon) return item.icon;
  5384. // 返回完整的 class:menu-icon (字体族) + 具体图标类
  5385. return 'menu-icon ' + defaultIcons[index % defaultIcons.length];
  5386. };
  5387. // v3.0 新增:菜单模式管理 by xu 20251216
  5388. const menuMode = ref(props.initialMode);
  5389. const isHovering = ref(false);
  5390. const toggleMenuMode = () => {
  5391. menuMode.value = menuMode.value === 'collapse' ? 'fixed' : 'collapse';
  5392. };
  5393. const onMouseEnter = () => {
  5394. if (menuMode.value === 'collapse') {
  5395. isHovering.value = true;
  5396. }
  5397. };
  5398. const onMouseLeave = () => {
  5399. isHovering.value = false;
  5400. };
  5401. const isExpanded = computed(() => {
  5402. return menuMode.value === 'collapse' && isHovering.value;
  5403. });
  5404. // v3.0 新增:iframe 懒加载,点击才加载 by xu 20251216
  5405. const loadedMenus = ref(new Set());
  5406. const isMenuLoaded = (menuName) => {
  5407. return loadedMenus.value.has(menuName);
  5408. };
  5409. // 根据标题找到对应的菜单项
  5410. const findMenuByTitle = (title) => {
  5411. for (const item of props.menuList) {
  5412. if (item.children?.length > 0) {
  5413. const child = item.children.find((c) => c.title === title);
  5414. if (child) return child;
  5415. } else if (item.title === title) {
  5416. return item;
  5417. }
  5418. }
  5419. return null;
  5420. };
  5421. // 计算默认选中的菜单项
  5422. const defaultActiveMenu = computed(() => {
  5423. if (props.activeMenu) {
  5424. const menu = findMenuByTitle(props.activeMenu);
  5425. if (menu) return menu;
  5426. }
  5427. const firstItem = props.menuList[0];
  5428. if (!firstItem) return null;
  5429. return firstItem.children?.length > 0
  5430. ? firstItem.children[0]
  5431. : firstItem;
  5432. });
  5433. const currentMenu = ref(defaultActiveMenu.value);
  5434. // 监听外部activeMenu变化
  5435. watch(
  5436. () => props.activeMenu,
  5437. (newTitle) => {
  5438. if (newTitle) {
  5439. const menu = findMenuByTitle(newTitle);
  5440. if (menu) {
  5441. currentMenu.value = menu;
  5442. }
  5443. }
  5444. }
  5445. );
  5446. // 初始化:默认选中项加入已加载集合
  5447. watch(currentMenu, (menu) => {
  5448. if (menu?.name) {
  5449. loadedMenus.value.add(menu.name);
  5450. }
  5451. }, { immediate: true });
  5452. // 选择菜单项时触发 menu-change 钩子
  5453. const selectItem = (item) => {
  5454. currentMenu.value = item;
  5455. // 标记为已加载
  5456. if (item.name) {
  5457. loadedMenus.value.add(item.name);
  5458. }
  5459. emit("menu-change", item);
  5460. };
  5461. // 处理底部按钮点击
  5462. const handleFooterClick = (button, index) => {
  5463. emit("footer-click", { button, index });
  5464. };
  5465. return {
  5466. currentMenu,
  5467. selectItem,
  5468. handleFooterClick,
  5469. menuMode,
  5470. isHovering,
  5471. isExpanded,
  5472. toggleMenuMode,
  5473. onMouseEnter,
  5474. onMouseLeave,
  5475. isMenuLoaded,
  5476. getMenuIcon,
  5477. };
  5478. },
  5479. template: `
  5480. <div class="project-edit-container">
  5481. <div class="left-side"
  5482. v-if="leftDisplay"
  5483. :data-mode="menuMode"
  5484. :class="{ 'is-expanded': isExpanded }"
  5485. @mouseenter="onMouseEnter"
  5486. @mouseleave="onMouseLeave">
  5487. <!-- 菜单内容 -->
  5488. <div class="menu-content">
  5489. <div class="scroll-view">
  5490. <template v-for="(menuItem, i) in menuList" :key="i">
  5491. <!-- 分组菜单 -->
  5492. <div v-if="menuItem.children?.length > 0" class="group">
  5493. <div class="menu-item" @click="menuItem.open = !menuItem.open">
  5494. <ss-icon :class="getMenuIcon(menuItem, i)" />
  5495. <span class="menu-label">{{ menuItem.title }}</span>
  5496. <span class="arrow">
  5497. <ss-icon :class="menuItem.open ? 'menu-icon icon-jiantou-shang' : 'menu-icon icon-jiantou-xia'" />
  5498. </span>
  5499. <div class="menu-tooltip">{{ menuItem.title }}</div>
  5500. </div>
  5501. <div v-show="menuItem.open" class="group-detail">
  5502. <div v-for="(item, j) in menuItem.children"
  5503. :key="j"
  5504. class="menu-item"
  5505. :class="{ active: item.name === currentMenu?.name }"
  5506. @click="selectItem(item)">
  5507. <ss-icon :class="getMenuIcon(item, j)" />
  5508. <span class="menu-label">{{ item.title }}</span>
  5509. <span class="menu-item-point" v-if="item.cgxList || item.objectList"></span>
  5510. </div>
  5511. </div>
  5512. </div>
  5513. <!-- 普通菜单项 -->
  5514. <div v-else
  5515. class="menu-item"
  5516. :class="{ active: menuItem.name === currentMenu?.name }"
  5517. @click="selectItem(menuItem)">
  5518. <ss-icon :class="getMenuIcon(menuItem, i)" />
  5519. <span class="menu-label">{{ menuItem.title }}</span>
  5520. <span class="menu-item-point" v-if="menuItem.cgxList || menuItem.objectList"></span>
  5521. <div class="menu-tooltip">{{ menuItem.title }}</div>
  5522. </div>
  5523. </template>
  5524. </div>
  5525. </div>
  5526. <!-- v3.0 模式切换按钮,只显示图标 by xu 20251216 -->
  5527. <div class="menu-mode-toggle" @click="toggleMenuMode">
  5528. <ss-icon class="menu-base-icon icon-qiehuan" />
  5529. </div>
  5530. <!-- 底部按钮 -->
  5531. <div v-if="footerButtons.length > 0"
  5532. class="sub-tab-menu-footer"
  5533. @click="footerButtons[0].onclick">
  5534. <div>{{ footerButtons[0].text }}</div>
  5535. <ss-icon v-if="footerButtons.length > 1" name="arrow-up" size="24px" />
  5536. <div v-if="footerButtons.length > 1" class="sub-tab-menu-popup">
  5537. <div v-for="(button, index) in footerButtons.slice(1)"
  5538. :key="index"
  5539. @click.stop="button.onclick">
  5540. {{ button.text }}
  5541. </div>
  5542. </div>
  5543. </div>
  5544. </div>
  5545. <!-- 右侧内容区域 - 懒加载 iframe -->
  5546. <div class="content-area fit-height-content" style="overflow: hidden;" :style="!leftDisplay ? { width: '100%' } : {}">
  5547. <template v-for="(menuItem, i) in menuList" :key="i">
  5548. <iframe
  5549. v-if="isMenuLoaded(menuItem.name)"
  5550. :src="menuItem.url"
  5551. style="height: 100%;width: 100%;"
  5552. frameborder="0"
  5553. class="sub-tab-iframe"
  5554. :id="i === 0 ? 'sub-tab-iframe' : ''"
  5555. v-show="currentMenu?.name === menuItem.name"
  5556. />
  5557. </template>
  5558. </div>
  5559. </div>
  5560. `,
  5561. };
  5562. // <iframe
  5563. // v-if="currentMenu?.url"
  5564. // :src="currentMenu.url"
  5565. // style="height: 100%;width: 100%;"
  5566. // frameborder="0"
  5567. // id="sub-tab-iframe"
  5568. // />
  5569. // ss-photo-upload 通用图片上传组件
  5570. const SsImgUpload = {
  5571. name: "SsImgUpload",
  5572. props: {
  5573. name: {
  5574. type: String,
  5575. required: true,
  5576. },
  5577. // 图片URL,用于回显
  5578. // url: {
  5579. // type: String,
  5580. // default: "",
  5581. // },
  5582. // 样式类名
  5583. class: {
  5584. type: String,
  5585. required: true,
  5586. },
  5587. // 裁剪配置
  5588. cropperOpt: {
  5589. type: Object,
  5590. default: () => ({
  5591. width: 360,
  5592. height: 360,
  5593. aspectRatio: 1,
  5594. }),
  5595. },
  5596. //上传图片url(未加图片名参数之前的部分)
  5597. ulUrl: {
  5598. type: String,
  5599. required: true,
  5600. },
  5601. //下载图片url(未加图片名参数之前的部分)
  5602. dlUrl: {
  5603. type: String,
  5604. required: true,
  5605. },
  5606. modelValue: [String, Number],
  5607. },
  5608. emits: ["update:modelValue"],
  5609. setup(props, { emit }) {
  5610. const inputId = Vue.computed(
  5611. () => `file_${Vue.getCurrentInstance().uid}`
  5612. );
  5613. //修改图片初始显示路径
  5614. let pathVal = ref(props.modelValue);
  5615. let picUrl = ref("");
  5616. if (props.modelValue) {
  5617. picUrl.value = props.dlUrl + "&path=" + props.modelValue;
  5618. }
  5619. Vue.onMounted(() => {
  5620. window.SS.cropper.init({
  5621. el: $(`#${inputId.value}`),
  5622. photoSize: {
  5623. width: props.cropperOpt.width,
  5624. height: props.cropperOpt.height,
  5625. },
  5626. aspectRatio: props.cropperOpt.aspectRatio,
  5627. uploadUrl: props.ulUrl,
  5628. success: (path) => {
  5629. pathVal.value = path;
  5630. picUrl.value = props.dlUrl + "&path=" + path;
  5631. emit("update:modelValue", path);
  5632. },
  5633. });
  5634. });
  5635. return () =>
  5636. h("div", { class: [props.class] }, [
  5637. h("input", {
  5638. type: "file",
  5639. accept: "image/*",
  5640. id: inputId.value,
  5641. style: { display: "none" },
  5642. }),
  5643. h("input", {
  5644. type: "hidden",
  5645. name: props.name,
  5646. value: pathVal.value,
  5647. }),
  5648. h(
  5649. "div",
  5650. {
  5651. style: {
  5652. width: "100%",
  5653. height: "100%",
  5654. },
  5655. onClick: () => $(`#${inputId.value}`).click(),
  5656. },
  5657. [
  5658. picUrl.value &&
  5659. h("img", {
  5660. src: picUrl.value,
  5661. style:
  5662. "width: 100%; height: 100%;object-fit: inherit;position: relative;z-index: 11;",
  5663. }),
  5664. ]
  5665. ),
  5666. ]);
  5667. },
  5668. };
  5669. // 初始化函数,负责创建和挂载 Vue 应用
  5670. // window.SS = { dom: {} };
  5671. /**
  5672. * 获取当前窗口的父窗口
  5673. * @returns {Window} 父窗口对象
  5674. */
  5675. window.SS.topWin = (function (p, c) {
  5676. while (p != c) {
  5677. c = p;
  5678. p = p.parent;
  5679. }
  5680. return c;
  5681. })(window.parent, window);
  5682. window.SS.createSsDialogInstance = createSsDialogInstance;
  5683. /**
  5684. * 创建弹窗
  5685. * @param {Object} setting
  5686. * @param {Function} callbackEvent
  5687. */
  5688. window.SS.openDialog = function (setting, callbackEvent) {
  5689. if (setting.params) {
  5690. const encodedParams = encodeURIComponent(JSON.stringify(setting.params));
  5691. setting.src +=
  5692. (setting.src.includes("?") ? "&" : "?") + "params=" + encodedParams;
  5693. }
  5694. if (window.parent && window.parent !== window) {
  5695. window.parent.SS.createSsDialogInstance(setting, callbackEvent);
  5696. } else {
  5697. createSsDialogInstance(setting, callbackEvent);
  5698. }
  5699. };
  5700. //关闭弹窗
  5701. window.SS.closeDialog = function () {
  5702. console.log("关闭弹窗");
  5703. if (topWindow.dialogInstances.length > 0) {
  5704. const instance = topWindow.dialogInstances.pop();
  5705. console.log("instance", instance);
  5706. console.log("instance.callbackEvent", instance.callbackEvent);
  5707. console.log(
  5708. "instance.callbackEvent.end",
  5709. typeof instance.callbackEvent === "function"
  5710. );
  5711. if (instance.callbackEvent) {
  5712. // 判断是否有end回调并执行
  5713. if (typeof instance.callbackEvent === "function") {
  5714. instance.callbackEvent();
  5715. }
  5716. if (typeof instance.callbackEvent.end === "function") {
  5717. instance.callbackEvent.end();
  5718. }
  5719. }
  5720. instance.app.unmount(); // 卸载最后一个实例
  5721. if (instance.container && instance.container.parentNode) {
  5722. instance.container.parentNode.removeChild(instance.container); // 移除容器
  5723. }
  5724. }
  5725. };
  5726. /**
  5727. * 裁剪插件
  5728. */
  5729. window.SS.cropper = {
  5730. init: function (setting) {
  5731. if (!window.top.SS) window.top.SS = {};
  5732. // 重要:确保 cropper 对象的完整初始化
  5733. if (!window.top.SS.cropper) {
  5734. window.top.SS.cropper = {
  5735. settings: new Map(),
  5736. _backupSettings: {},
  5737. getSetting: this.getSetting,
  5738. clearSetting: this.clearSetting,
  5739. debug: this.debug,
  5740. };
  5741. } else if (!window.top.SS.cropper.settings) {
  5742. // 如果 cropper 存在但 settings 不存在,重新初始化 settings
  5743. window.top.SS.cropper.settings = new Map();
  5744. window.top.SS.cropper._backupSettings = {};
  5745. }
  5746. const uploaderId = `uploader_${Date.now()}_${Math.random()
  5747. .toString(36)
  5748. .substr(2, 9)}`;
  5749. window.top.SS.cropper.settings.set(uploaderId, setting);
  5750. window.top.SS.cropper._backupSettings[uploaderId] = setting;
  5751. setting.box = setting.box || "1";
  5752. var winSetting = {
  5753. headerTitle: "图片裁剪",
  5754. src: "/js/cropper/cropper.jsp",//原来在"/newUI/page/cropper.jsp" Ben(20251205)
  5755. width: "900",
  5756. height: "500",
  5757. };
  5758. $(setting.el).change(function () {
  5759. if (!window.SS.cropper.verify(setting)) {
  5760. $(setting.el).val(""); // 清空文件选择
  5761. return false;
  5762. }
  5763. var files = this.files;
  5764. if (files && files.length) {
  5765. if (!window.SS.cropper.verifySize($(setting.el)[0], 5)) {
  5766. $(setting.el).val(""); // 清空文件选择
  5767. alert("文件大小不能超过5M,请重新选择");
  5768. return false;
  5769. }
  5770. var URL = window.URL || window.webkitURL;
  5771. var file = files[0];
  5772. setting.file = file;
  5773. if (
  5774. /^image\/\w+$/.test(file.type) &&
  5775. /\.(jpg|jpeg|png|)$/i.test(file.name)
  5776. ) {
  5777. var uploadedImageURL = URL.createObjectURL(file);
  5778. setting.data = uploadedImageURL;
  5779. setting.fileName = file.name;
  5780. // console.log()
  5781. winSetting.params = {
  5782. ...setting,
  5783. uploaderId,
  5784. };
  5785. console.log("ss-componets中change之后的winSetting", winSetting);
  5786. SS.openDialog(winSetting, {
  5787. success: function (win) {
  5788. console.log("裁剪插件成功");
  5789. // win.cropperSetting = setting;
  5790. },
  5791. end: function () {
  5792. console.log("裁剪插件结束");
  5793. $(setting.el).val(""); // 清空文件选择
  5794. },
  5795. });
  5796. } else {
  5797. alert("请选择图片文件,支持jpg、jpeg、png格式");
  5798. }
  5799. }
  5800. });
  5801. return uploaderId;
  5802. },
  5803. verify: function (setting) {
  5804. if (!setting) {
  5805. console.error(" cropper setting is not undefined! ");
  5806. return false;
  5807. }
  5808. if (!setting.el) {
  5809. console.error(" cropper setting.el is not undefined! ");
  5810. return false;
  5811. }
  5812. if (setting.photoSize) {
  5813. if (
  5814. (!setting.photoSize.width && setting.photoSize.height) ||
  5815. (!setting.photoSize.height && setting.photoSize.width)
  5816. ) {
  5817. console.error(
  5818. " cropper setting.photoSize { width, height } is not undefined! "
  5819. );
  5820. return false;
  5821. }
  5822. }
  5823. if (!setting.box) {
  5824. setting.box = "1";
  5825. }
  5826. if (!setting.aspectRatio) {
  5827. setting.aspectRatio = 1 / 1;
  5828. }
  5829. return true;
  5830. },
  5831. verifySize: function (fileEl, maxSize) {
  5832. // 判断是否为IE浏览器: /msie/i.test(navigator.userAgent) 为一个简单正则
  5833. var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  5834. var fileSize = 0;
  5835. if (isIE && !fileEl.files) {
  5836. // IE浏览器
  5837. var filePath = fileEl.value; // 获得上传文件的绝对路径
  5838. var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
  5839. var file = fileSystem.GetFile(filePath);
  5840. fileSize = file.Size; // 文件大小,单位:b
  5841. } else {
  5842. // 非IE浏览器
  5843. fileSize = fileEl.files[0].size;
  5844. }
  5845. var size = fileSize / 1024 / 1024;
  5846. return !(size > maxSize);
  5847. },
  5848. // 获取特定上传组件的setting
  5849. getSetting: function (uploaderId) {
  5850. if (!window.top.SS?.cropper) {
  5851. console.warn("顶层窗口中未找到 SS.cropper");
  5852. return null;
  5853. }
  5854. // 优先从 Map 中获取
  5855. let setting = window.top.SS.cropper.settings.get(uploaderId);
  5856. // 如果 Map 中没有,尝试从备份中获取
  5857. if (!setting && window.top.SS.cropper._backupSettings[uploaderId]) {
  5858. console.log("从备份中恢复 setting");
  5859. setting = window.top.SS.cropper._backupSettings[uploaderId];
  5860. // 恢复到 Map 中
  5861. window.top.SS.cropper.settings.set(uploaderId, setting);
  5862. }
  5863. return setting;
  5864. },
  5865. // 清理特定上传组件的setting
  5866. clearSetting: function (uploaderId) {
  5867. if (!window.top.SS?.cropper) return;
  5868. window.top.SS.cropper.settings.delete(uploaderId);
  5869. delete window.top.SS.cropper._backupSettings[uploaderId];
  5870. console.log(
  5871. "清理设置后的 Map size:",
  5872. window.top.SS.cropper.settings.size
  5873. );
  5874. },
  5875. };
  5876. /**
  5877. * 获取url中的参数
  5878. * @returns {Object}
  5879. */
  5880. window.SS.getQueryParams = function () {
  5881. const params = {};
  5882. const queryString = window.location.search.substring(1);
  5883. const pairs = queryString.split("&");
  5884. for (let i = 0; i < pairs.length; i++) {
  5885. const pair = pairs[i].split("=");
  5886. params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  5887. }
  5888. if (params.params) {
  5889. try {
  5890. params.params = JSON.parse(params.params);
  5891. } catch (e) {
  5892. console.error("Failed to parse params:", e);
  5893. }
  5894. }
  5895. return params;
  5896. };
  5897. /**
  5898. * 创建vue应用
  5899. * @param {Object} config 配置项
  5900. * @values {String} config.el 挂载的元素
  5901. * @values {Boolean} config.isDialogPage 是否是弹窗页面 决定了是否可以使用顶天立地
  5902. * @values {Object} config.vueOptions vue配置项
  5903. * @returns {Object} vue实例
  5904. */
  5905. window.SS.dom.initializeFormApp = function (config) {
  5906. const { el, isDialogPage = false, ...vueOptions } = config;
  5907. const app = createApp({
  5908. ...vueOptions,
  5909. });
  5910. // 如果是弹窗iframe里面的html的话 给当前的页面挂上事件 实现顶天立地的效果
  5911. if (isDialogPage) {
  5912. function checkScroll() {
  5913. // 选出所有fit-height-content的元素 如果有滚动条
  5914. const elements = document.querySelectorAll(".fit-height-content");
  5915. let hasScrollBar = false;
  5916. // 检查元素是否有滚动条 检查当前窗口的所有元素
  5917. // 如果有滚动条,则将结果设置为true
  5918. elements.forEach((el) => {
  5919. if (el.scrollHeight > el.clientHeight) {
  5920. hasScrollBar = true;
  5921. }
  5922. });
  5923. // 将结果发送给父窗口
  5924. window.parent.postMessage({ hasScrollBar }, "*");
  5925. }
  5926. function addScrollListeners() {
  5927. const elements = document.querySelectorAll("div");
  5928. elements.forEach((el) => {
  5929. el.addEventListener("scroll", checkScroll);
  5930. });
  5931. }
  5932. const observer = new MutationObserver((mutations) => {
  5933. addScrollListeners();
  5934. checkScroll();
  5935. });
  5936. observer.observe(document.body, {
  5937. childList: true,
  5938. subtree: true,
  5939. });
  5940. window.addEventListener("resize", checkScroll);
  5941. }
  5942. // 注册组件
  5943. app.component("SsLoginIcon", SsLoginIcon);
  5944. app.component("SsMark", SsMark);
  5945. app.component("SsFullStyleHeader", SsFullStyleHeader);
  5946. app.component("SsDialog", SsDialog);
  5947. app.component("SsInput", SsInput);
  5948. app.component("SsObjp", SsObjp);
  5949. app.component("SsHidden", SsHidden);
  5950. app.component("SsCcp", SsCcp);
  5951. app.component("SsDatePicker", SsDatePicker);
  5952. app.component("SsIcon", SsIcon);
  5953. app.component("SsCommonIcon", SsCommonIcon);
  5954. app.component("SsBreadcrumb", SsBreadcrumb);
  5955. app.component("SsEditor", SsEditor);
  5956. app.component("SsDialogIcon", SsDialogIcon);
  5957. app.component("SsBottomButton", SsBottomButton);
  5958. app.component("SsNavIcon", SsNavIcon);
  5959. app.component("SsHeaderIcon", SsHeaderIcon);
  5960. app.component("SsGolbalMenuIcon", SsGolbalMenuIcon);
  5961. app.component("SsCartListIcon", SsCartListIcon);
  5962. app.component("SsQuickIcon", SsQuickIcon);
  5963. app.component("SsFormIcon", SsFormIcon);
  5964. app.component("SsBottomDivIcon", SsBottomDivIcon);
  5965. app.component("SsEditorIcon", SsEditorIcon);
  5966. app.component("SsValidate", SsValidate);
  5967. app.component("SsOnoff", Ssonoff);
  5968. app.component("SsonoffArray", SsonoffArray);
  5969. app.component("SsTextarea", SsTextarea);
  5970. app.component("SsLoginInput", SsLoginInput);
  5971. app.component("SsLoginButton", SsLoginButton);
  5972. app.component("SsSearch", SsSearch);
  5973. app.component("SsCartItem", SsCartItem);
  5974. app.component("SsCartItem2", SsCartItem2);
  5975. app.component("SsListCard", SsListCard);
  5976. app.component("SsFolderCard", SsFolderCard);
  5977. app.component("SsFolderCartView", SsFolderCartView);
  5978. app.component("SsPage", SsPage);
  5979. app.component("SsRightInfo", SSRightInfo);
  5980. app.component("SsSuccessPopup", SsSuccessPopup);
  5981. app.component("SsErrorDialog", SsErrorDialog);
  5982. app.component("SsVerify", SsVerify);
  5983. app.component("SsVerifyNode", SsVerifyNode);
  5984. app.component("SsOrcImgBox", SsOrcImgBox);
  5985. app.component("ss-search-input", SsSearchInput);
  5986. app.component("ss-search-date-picker", SsSearchDatePicker);
  5987. app.component("ss-search-button", SsSearchButton);
  5988. app.component("ss-drop-button", SsDropButton);
  5989. app.component("ss-sub-tab", SsSubTab);
  5990. app.component("ss-img", SsImgUpload);
  5991. // 设置为中文
  5992. app.use(ElementPlus, {
  5993. locale: ElementPlusLocaleZhCn,
  5994. });
  5995. // console.log(ElementPlus);
  5996. // 确保 ElementPlusIconsVue
  5997. // if (window.ElementPlusIconsVue) {
  5998. // // 注册 Element Plus 图标组件
  5999. // for (const [key, component] of Object.entries(
  6000. // window.ElementPlusIconsVue
  6001. // )) {
  6002. // console.log(key, component);
  6003. // app.component(key, component);
  6004. // }
  6005. // }
  6006. // 挂载首页的组件
  6007. for (const componentName in IndexComponents) {
  6008. app.component(componentName, IndexComponents[componentName]);
  6009. }
  6010. // 挂载echarts的组件
  6011. for (const componentName in EchartComponents) {
  6012. app.component(componentName, EchartComponents[componentName]);
  6013. }
  6014. // 挂载 Vue 应用
  6015. let vm ;
  6016. try {
  6017. vm = app.mount(el);
  6018. vm.data = vueOptions.data();
  6019. console.log("vm:",vm)
  6020. console.log("vueOptions:",vueOptions)
  6021. } catch (error) {
  6022. alert('Mount failed:'+ error);//vue Mount失败报错 Ben(20251206)
  6023. }
  6024. return vm;
  6025. };
  6026. })();