ss-components.js 189 KB

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