ss-components.js 200 KB

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