ss-components.js 206 KB

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