ss-components.js 388 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210
  1. import { ssIcon, commonIcon } from "./icon-config.js";
  2. import * as IndexComponents from "./ss-index-components.js";
  3. import * as EchartComponents from "./ss-echarts-compnents.js";
  4. import {
  5. isNum,
  6. toStyleStr,
  7. buildThumbUrl,
  8. openServiceDialog,
  9. pickSearchParams,
  10. } from "./tools.js"; // 功能说明:组件内统一构建缩略图URL、打开服务弹窗,减少 JSP 层字段转换 by xu 20260122
  11. import { EVEN_VAR } from "./EventBus.js";
  12. // import * as elements from "../lib/element-plus.js";
  13. (function () {
  14. const {
  15. createApp,
  16. ref,
  17. reactive,
  18. watch,
  19. onMounted,
  20. onBeforeUnmount,
  21. h,
  22. computed,
  23. resolveComponent,
  24. watchEffect,
  25. nextTick,
  26. onVnodeMounted,
  27. Teleport,
  28. inject,
  29. provide,
  30. } = Vue;
  31. // 弹窗默认遮罩z-index
  32. let currentZIndex = 100;
  33. // 目前已存在的弹窗
  34. const topWindow = window.top;
  35. topWindow.dialogInstances = topWindow.dialogInstances || [];
  36. // 新建弹窗
  37. function createSsDialogInstance(setting, callbackEvent) {
  38. currentZIndex += 10; // 动态提升 z-index
  39. const container = document.createElement("div");
  40. document.body.appendChild(container);
  41. const app = Vue.createApp({
  42. render() {
  43. return h(SsDialog, {
  44. ...setting,
  45. zIndex: currentZIndex,
  46. onClose() {
  47. document.body.removeChild(container); // 仅移除弹窗容器
  48. const index = topWindow.dialogInstances.indexOf(app);
  49. if (index > -1) {
  50. topWindow.dialogInstances.splice(index, 1); // 移除实例
  51. }
  52. // 关闭后的回调
  53. if (callbackEvent && typeof callbackEvent === "function") {
  54. callbackEvent();
  55. }
  56. app.unmount(); // 仅卸载弹窗实例
  57. if (container.parentNode) {
  58. container.parentNode.removeChild(container); // 确保移除容器
  59. }
  60. },
  61. });
  62. },
  63. });
  64. topWindow.dialogInstances.push({ app, callbackEvent, container });
  65. app.component("ss-mark", SsMark); // 注册 ss-mark 组件
  66. app.component("ss-icon", SsIcon);
  67. app.component("ss-full-style-header", SsFullStyleHeader); // 注册 ss-full-style-header 组件
  68. app.mount(container);
  69. }
  70. // ss-breadcrumb 一级菜单页面面包屑
  71. const SsBreadcrumb = {
  72. name: "SsBreadcrumb",
  73. props: {
  74. level: {
  75. type: Object,
  76. default: null,
  77. },
  78. },
  79. setup(props) {
  80. const currentMenu = ref(null);
  81. const folderPath = ref([]);
  82. const eventBus = window.parent.sharedEventBus;
  83. // 监听页面变化
  84. onMounted(() => {
  85. // 获取初始页面
  86. currentMenu.value = eventBus.getState(EVEN_VAR.currentPage);
  87. folderPath.value = eventBus.getState("folderPath") || [];
  88. // 订阅页面变化
  89. eventBus.subscribe(EVEN_VAR.currentPage, (page) => {
  90. currentMenu.value = page;
  91. });
  92. eventBus.subscribe("folderPath", (path) => {
  93. folderPath.value = path || [];
  94. });
  95. });
  96. // 修改点击处理函数
  97. const handlePathClick = (index) => {
  98. if (props.level?.onBack) {
  99. // 截取到点击的位置,后面的路径会被销毁
  100. const newPath = folderPath.value.slice(0, index + 1);
  101. eventBus.publish("folderPath", newPath);
  102. // 返回到对应层级
  103. const targetFolder = newPath[newPath.length - 1]?.folder || null;
  104. props.level.onBack(targetFolder);
  105. }
  106. };
  107. const SsCommonIcon = resolveComponent("SsCommonIcon");
  108. return () =>
  109. h("div", { class: "bread-crumb" }, [
  110. currentMenu.value &&
  111. h(
  112. "div",
  113. {
  114. onClick: () => {
  115. if (props.level?.onBack) {
  116. eventBus.publish("folderPath", []);
  117. props.level.onBack(null); // 返回到根目录
  118. } else {
  119. eventBus.publish(EVEN_VAR.currentPage, currentMenu.value);
  120. }
  121. },
  122. },
  123. currentMenu.value.label || currentMenu.value.name
  124. ),
  125. ...(folderPath.value || [])
  126. .map((folder, index) => [
  127. h(SsCommonIcon, { class: "common-icon-arrow-right" }),
  128. h(
  129. "div",
  130. {
  131. class: "bread-crumb-item",
  132. onClick: () => handlePathClick(index),
  133. style: { cursor: "pointer" },
  134. },
  135. folder.title
  136. ),
  137. ])
  138. .flat(),
  139. ]);
  140. },
  141. };
  142. // ss-input form表单的输入
  143. const SsInput = {
  144. name: "SsInp", //把SsInput改为SsInp Ben(20251225)
  145. inheritAttrs: false, // 不直接继承属性到组件根元素
  146. props: {
  147. name: {
  148. type: String,
  149. required: true,
  150. default: "",
  151. },
  152. // 接收 v-model 绑定的值
  153. errTip: {
  154. type: String,
  155. },
  156. required: {
  157. type: Boolean,
  158. default: false,
  159. },
  160. placeholder: {
  161. type: String,
  162. default: "请输入",
  163. },
  164. defaultValue: [String, Number],
  165. modelValue: [String, Number],
  166. // 新增:附件配置
  167. fj: {
  168. type: Object,
  169. default: null,
  170. },
  171. // 新增:param 配置(用于附件功能)
  172. param: {
  173. type: Object,
  174. default: null,
  175. },
  176. // 新增:高度配置
  177. height: {
  178. type: String,
  179. default: "",
  180. },
  181. // 功能说明:传 height 时允许回车换行(多行输入);未传 height 默认单行 by xu 20260204
  182. },
  183. emits: ["update:modelValue", "input", "blur", "change"], // 允许更新 v-model 绑定的值
  184. setup(props, { emit }) {
  185. const errMsg = ref("");
  186. const inputRef = ref(null);
  187. const textareaRef = ref(null);
  188. const inputValue = ref(props.modelValue || props.defaultValue || "");
  189. const contentFloatingDiv = ref(false); // 控制浮动 DIV 的显示
  190. const floatingDivPosition = ref("bottom"); // 'bottom' 或 'top'
  191. const isFocused = ref(false); // 跟踪焦点状态
  192. // 附件相关变量(仅在传入 param 时初始化)
  193. let fjid = ref(null);
  194. let fjName = null;
  195. let mode = null;
  196. if (props.param && props.param.button) {
  197. fjid = ref(props.param.button.val);
  198. fjName = props.param.button.desc;
  199. mode = props.param.mode;
  200. }
  201. // 功能说明:只有存在非空校验(notNull)且值为空时,才显示红线 by xu 20260402
  202. const hasNotNullRule = () => {
  203. const validations = window.ssVm?.validations?.get(props.name);
  204. if (!validations || validations.length === 0) return false;
  205. return validations.some(v => v.ruleName && v.ruleName.includes('notNull'));
  206. };
  207. const showRequired = computed(() => {
  208. const validations = window.ssVm?.validations?.get(props.name);
  209. if (!validations || validations.length === 0) return false;
  210. // 检查是否存在 notNull 规则
  211. const hasNotNull = validations.some(v => v.ruleName && v.ruleName.includes('notNull'));
  212. // 有非空规则且值为空时显示红线
  213. if (hasNotNull && !inputValue.value) {
  214. return true;
  215. }
  216. return false;
  217. });
  218. // 计算floatdiv应该向上还是向下展开
  219. const calculateFloatingDivPosition = () => {
  220. nextTick(() => {
  221. const textarea = inputRef.value;
  222. if (!textarea) return;
  223. const rect = textarea.getBoundingClientRect();
  224. const viewportHeight = window.innerHeight;
  225. // 预估floatdiv的高度(最多5行 * 20px + 上下padding + border)
  226. const estimatedFloatDivHeight = 20 * 5 + 10 + 2; // 5行 + padding + border = 112px
  227. // 检查下方空间
  228. const spaceBelow = viewportHeight - rect.bottom;
  229. // 如果下方空间不足,且上方空间足够,则向上展开
  230. if (
  231. spaceBelow < estimatedFloatDivHeight &&
  232. rect.top > estimatedFloatDivHeight
  233. ) {
  234. floatingDivPosition.value = "top";
  235. } else {
  236. floatingDivPosition.value = "bottom";
  237. }
  238. });
  239. };
  240. // 计算floatdiv的top偏移量
  241. const getFloatingDivTop = computed(() => {
  242. if (props.height) {
  243. // 有height时,padding是5px
  244. return "5px";
  245. } else {
  246. // 没有height时是单行居中,需要计算居中位置
  247. // 假设input-container高度是32px(或者从CSS读取),单行20px
  248. // 居中偏移 = (容器高度 - 行高) / 2 = (32 - 20) / 2 = 6px
  249. return "6px";
  250. }
  251. });
  252. const validate = () => {
  253. if (window.ssVm) {
  254. const result = window.ssVm.validateField(props.name);
  255. errMsg.value = result.valid ? "" : result.message;
  256. }
  257. };
  258. // 使用 watch 监听 props.errTip 和 props.modelValue 的变化
  259. watch(
  260. () => props.errTip,
  261. (newVal) => {
  262. errMsg.value = newVal;
  263. },
  264. { immediate: true }
  265. );
  266. watch(
  267. () => props.modelValue,
  268. (newVal) => {
  269. inputValue.value = newVal;
  270. }
  271. );
  272. // 挂载时的逻辑
  273. onMounted(() => {
  274. errMsg.value = props.errTip;
  275. inputValue.value = props.modelValue || props.defaultValue || "";
  276. });
  277. // 计算并调整textarea的高度
  278. const adjustHeight = () => {
  279. nextTick(() => {
  280. const textarea = textareaRef.value;
  281. if (!textarea) return;
  282. // floatDiv的textarea始终自动计算高度,不受props.height影响
  283. // 重置高度以获得正确的scrollHeight
  284. textarea.style.height = "auto";
  285. // 计算新高度 - 统一限制为5行
  286. const lineHeight = parseInt(
  287. getComputedStyle(textarea).lineHeight,
  288. 10
  289. );
  290. const maxHeight = lineHeight * 5; // 统一为5行
  291. const newHeight = Math.min(textarea.scrollHeight, maxHeight);
  292. textarea.style.height = `${newHeight}px`;
  293. });
  294. };
  295. // 检查是否应该显示浮动窗口(需要同时满足:有焦点 + 内容超出)
  296. // 修复新增页面点击就出现floatdiv的问题 by xu 20251212
  297. const checkShouldShowFloatingDiv = () => {
  298. const textarea = inputRef.value;
  299. if (!textarea) return false;
  300. // 首先检查是否有内容,没有内容时不显示floatdiv by xu 20251212
  301. if (!inputValue.value || inputValue.value.toString().trim() === "") {
  302. console.log("[floatdiv] 内容为空,不显示floatdiv");
  303. return false;
  304. }
  305. // 判断内容是否超出 by xu 20251212
  306. // 同时检查横向和纵向溢出,任一方向溢出都应显示floatdiv
  307. // 纵向溢出需要加容差值,避免padding/border导致的误判 by xu 20251212
  308. const verticalTolerance = 5; // 容差值5px
  309. const isHorizontalOverflow =
  310. textarea.scrollWidth > textarea.clientWidth;
  311. const isVerticalOverflow =
  312. textarea.scrollHeight > textarea.clientHeight + verticalTolerance;
  313. const isOverflow = isHorizontalOverflow || isVerticalOverflow;
  314. console.log(
  315. "[floatdiv] 溢出检测 - scrollWidth:",
  316. textarea.scrollWidth,
  317. "clientWidth:",
  318. textarea.clientWidth,
  319. "horizontalOverflow:",
  320. isHorizontalOverflow
  321. );
  322. console.log(
  323. "[floatdiv] 溢出检测 - scrollHeight:",
  324. textarea.scrollHeight,
  325. "clientHeight:",
  326. textarea.clientHeight,
  327. "tolerance:",
  328. verticalTolerance,
  329. "verticalOverflow:",
  330. isVerticalOverflow
  331. );
  332. const shouldShow = isFocused.value && isOverflow;
  333. console.log(
  334. "[floatdiv] 最终判断 - isFocused:",
  335. isFocused.value,
  336. "isOverflow:",
  337. isOverflow,
  338. "shouldShow:",
  339. shouldShow
  340. );
  341. // 需要同时满足:有焦点 + 内容超出
  342. return shouldShow;
  343. };
  344. // 定义事件处理函数
  345. const onInput = (event) => {
  346. const newValue = event.target.value;
  347. inputValue.value = newValue;
  348. emit("update:modelValue", newValue);
  349. validate(); // 输入时验证
  350. nextTick(() => {
  351. // 检查是否需要显示浮动div
  352. contentFloatingDiv.value = checkShouldShowFloatingDiv();
  353. // 如果需要显示floatdiv,计算其位置
  354. if (contentFloatingDiv.value) {
  355. calculateFloatingDivPosition();
  356. }
  357. });
  358. adjustHeight();
  359. };
  360. const onFocus = (event) => {
  361. // 设置焦点状态为true
  362. isFocused.value = true;
  363. adjustHeight();
  364. // 检查是否应该显示浮动窗口
  365. nextTick(() => {
  366. contentFloatingDiv.value = checkShouldShowFloatingDiv();
  367. if (contentFloatingDiv.value) {
  368. calculateFloatingDivPosition();
  369. }
  370. });
  371. };
  372. // 失去焦点时进行验证
  373. const onBlur = (event) => {
  374. emit("blur", event.target);
  375. validate(); // 失焦时验证
  376. nextTick(() => {
  377. // 如果焦点不在 textarea 上,则隐藏浮动 div
  378. if (!document.activeElement.classList.contains("input-control")) {
  379. isFocused.value = false;
  380. contentFloatingDiv.value = false;
  381. }
  382. });
  383. };
  384. const onChange = (event) => {
  385. inputValue.value = event.target.value || "";
  386. emit("change", inputValue.value);
  387. };
  388. const onMouseover = (event) => {
  389. nextTick(() => {
  390. // setTimeout(contentFloatingDiv.value = true, 500)
  391. });
  392. };
  393. const onMouseleave = (event) => {
  394. // contentFloatingDiv.value = false
  395. };
  396. // 功能说明:传了 height 视为多行允许回车;未传 height 拦截回车(单行表现) by xu 20260204
  397. const onKeydown = (event) => {
  398. const allowMultiline =
  399. typeof props.height === "string" && props.height.trim() !== "";
  400. if (!allowMultiline && event.key === "Enter") {
  401. event.preventDefault();
  402. }
  403. };
  404. // 附件按钮点击处理(从 SsEditor 搬运)
  405. const onAttachmentClick = (e) => {
  406. e.preventDefault();
  407. if (!props.param || !props.param.button) {
  408. console.warn("未配置 param 参数");
  409. return;
  410. }
  411. console.log("附件点击了");
  412. console.log("param", props.param);
  413. console.log("cmsAddUrl", props.param.button.cmsAddUrl);
  414. // 如果 fjid 为空,先调用 cmsAddUrl 创建
  415. if (fjid.value == null || fjid.value == "") {
  416. $.ajax({
  417. type: "post",
  418. url: props.param.button.cmsAddUrl,
  419. async: false,
  420. data: {
  421. name: "fjid",
  422. ssNrObjName: "sh",
  423. ssNrObjId: "",
  424. },
  425. success: function (_fjid) {
  426. console.log("cmsAddUrl success", _fjid);
  427. fjid.value = _fjid;
  428. },
  429. });
  430. }
  431. // 构建参数字符串
  432. var str =
  433. "&nrid=T-" +
  434. fjid.value +
  435. "&objectId=" +
  436. fjid.value +
  437. "&objectName=" +
  438. fjName +
  439. "&callback=" +
  440. (window["fjidCallbackName"] || "");
  441. console.log("str", str);
  442. // 打开附件编辑对话框
  443. SS.openDialog({
  444. src: props.param.button.cmsUpdUrl + str,
  445. headerTitle: "编辑",
  446. width: 900,
  447. high: 664,
  448. zIndex: 51,
  449. });
  450. };
  451. return {
  452. errMsg,
  453. inputValue,
  454. showRequired,
  455. onInput,
  456. onBlur,
  457. onChange,
  458. onMouseover,
  459. onMouseleave,
  460. onKeydown, // 新增:键盘事件处理 by xu 20251212
  461. contentFloatingDiv,
  462. floatingDivPosition,
  463. getFloatingDivTop,
  464. inputRef,
  465. textareaRef,
  466. onFocus,
  467. onAttachmentClick,
  468. fjid, // 附件 ID,用于隐藏字段
  469. };
  470. },
  471. render() {
  472. const { resolveComponent, h } = Vue;
  473. const SsIcon = resolveComponent("ss-icon");
  474. const SsEditorIcon = resolveComponent("SsEditorIcon");
  475. // 构建主textarea的样式
  476. const mainTextareaStyle = {};
  477. if (this.height) {
  478. mainTextareaStyle.height = "auto";
  479. // mainTextareaStyle.paddingTop = '5px'; // 有高度时加上padding-top
  480. // mainTextareaStyle.paddingBottom = '5px'; // 有高度时加上padding-bottom
  481. } else {
  482. // 没有指定height时,固定为单行高度
  483. mainTextareaStyle.height = "20px"; // 行高20px
  484. mainTextareaStyle.lineHeight = "20px"; // 确保单行垂直居中
  485. mainTextareaStyle.display = "flex";
  486. mainTextareaStyle.marginBottom = "5px";
  487. }
  488. // 如果有附件按钮,为按钮留出空间
  489. if (this.fj || (this.param && this.param.button)) {
  490. //加上&&this.param.button条件 Ben(20251221)
  491. mainTextareaStyle.paddingRight = "75px";
  492. }
  493. const mainTextareaRows = this.height
  494. ? Math.floor(parseFloat("80px") / 20)
  495. : 1;
  496. return h("div", { class: "input" }, [
  497. h("div", { class: "input-container" }, [
  498. h("div", { class: "input", style: "padding:5px 0" }, [
  499. h("textarea", {
  500. ref: "inputRef",
  501. class: "input-control",
  502. name: this.name,
  503. value: this.inputValue,
  504. onInput: this.onInput,
  505. onFocus: this.onFocus,
  506. onBlur: this.onBlur,
  507. onChange: this.onChange,
  508. onKeydown: this.onKeydown, // 新增:禁止回车换行 by xu 20251212
  509. placeholder: this.placeholder,
  510. onMouseover: this.onMouseover, // 监听鼠标悬停
  511. onMouseleave: this.onMouseleave, // 监听鼠标离开
  512. rows: mainTextareaRows,
  513. ...this.$attrs,
  514. style: mainTextareaStyle,
  515. autocomplete: "off",
  516. }),
  517. // 附件按钮(优先使用 param,兼容旧的 fj)
  518. this.fj || (this.param && this.param.button) //加上&&this.param.button条件 Ben(20251221)
  519. ? h(
  520. "button",
  521. {
  522. type: "button",
  523. class: "fj-button",
  524. onClick: this.param
  525. ? this.onAttachmentClick
  526. : (e) => {
  527. e.preventDefault();
  528. console.log("附件配置:", this.fj);
  529. },
  530. },
  531. [
  532. h(SsEditorIcon, {
  533. class: "editor-icon-link",
  534. }),
  535. h("span", { class: "fj-button-text" }, "附件"),
  536. ]
  537. )
  538. : null,
  539. ]),
  540. this.contentFloatingDiv || ""
  541. ? h(
  542. "div",
  543. {
  544. class: "floating-div",
  545. style:
  546. this.floatingDivPosition === "bottom"
  547. ? {
  548. // 向下展开: 覆盖原输入框,top对齐首行
  549. top: this.getFloatingDivTop,
  550. bottom: "auto",
  551. }
  552. : {
  553. // 向上展开: 同样覆盖原输入框,但从底部开始计算
  554. top: "auto",
  555. bottom: this.height ? "5px" : "6px", // 对齐到原textarea的底部padding位置
  556. },
  557. },
  558. [
  559. h("textarea", {
  560. ref: "textareaRef",
  561. class: "input-control",
  562. value: this.inputValue,
  563. onInput: this.onInput,
  564. onBlur: this.onBlur,
  565. onFocus: this.onFocus,
  566. onKeydown: this.onKeydown, // 新增:禁止回车换行 by xu 20251212
  567. onMouseover: this.onMouseover, // 监听鼠标悬停
  568. onMouseleave: this.onMouseleave, // 监听鼠标离开
  569. autocomplete: "off",
  570. onVnodeMounted: (vnode) => {
  571. vnode.el.focus();
  572. },
  573. }),
  574. ]
  575. )
  576. : null,
  577. // this.errMsg ? h(SsValidate, { errMsg: this.errMsg }) : null,
  578. ]),
  579. // 附件相关的隐藏字段(仅在有 param 时才渲染)
  580. this.param && [
  581. // fjid 隐藏字段(只有当 fjid 有值时才渲染)
  582. this.fjid &&
  583. this.fjid.value &&
  584. h("input", {
  585. type: "hidden",
  586. name: "fjid",
  587. value: this.fjid.value,
  588. }),
  589. // 其他隐藏字段根据 name 生成
  590. /* 去掉。文本框不需要(这是富文本才有的) Ben 20251205
  591. h("input", {
  592. type: "hidden",
  593. name: this.name.replace(/wj$/, "") + "Edit",
  594. value: this.inputValue
  595. }),
  596. */
  597. // h("input", {
  598. // type: "hidden",
  599. // name: this.name.replace(/wj$/, "") + "wj",
  600. // value: this.inputValue
  601. // }),
  602. /* 去掉。文本框不需要(这是富文本才有的) Ben 20251205
  603. h("input", {
  604. type: "hidden",
  605. name: "ueditorpath",
  606. value: this.name
  607. }),
  608. */
  609. ],
  610. ]);
  611. },
  612. };
  613. // ss-normal-input 登录输入
  614. const SsLoginInput = {
  615. name: "SsLoginInput",
  616. inheritAttrs: false,
  617. props: {
  618. errTip: {
  619. type: String,
  620. },
  621. type: {
  622. type: String,
  623. default: "text",
  624. },
  625. required: {
  626. type: Boolean,
  627. default: false,
  628. },
  629. placeholder: {
  630. type: String,
  631. default: "请输入",
  632. },
  633. name: {
  634. type: String,
  635. default: "",
  636. },
  637. defaultValue: [String, Number],
  638. modelValue: [String, Number],
  639. },
  640. emits: ["update:modelValue", "input", "blur", "change"], // 允许更新 v-model 绑定的值
  641. setup(props, { emit }) {
  642. const errMsg = ref("");
  643. const inputRef = ref(null);
  644. const textareaRef = ref(null);
  645. const inputValue = ref(props.modelValue || props.defaultValue || "");
  646. // 使用 watch 监听 props.errTip 和 props.modelValue 的变化
  647. watch(
  648. () => props.errTip,
  649. (newVal) => {
  650. errMsg.value = newVal;
  651. },
  652. { immediate: true }
  653. );
  654. watch(
  655. () => props.modelValue,
  656. (newVal) => {
  657. inputValue.value = newVal;
  658. }
  659. );
  660. // 挂载时的逻辑
  661. onMounted(() => {
  662. errMsg.value = props.errTip;
  663. inputValue.value = props.modelValue || props.defaultValue || "";
  664. });
  665. // 定义事件处理函数
  666. const onInput = (event) => {
  667. const newValue = event.target.value;
  668. inputValue.value = newValue;
  669. emit("update:modelValue", newValue);
  670. };
  671. return { inputValue, onInput, inputRef, textareaRef };
  672. },
  673. render() {
  674. return h("div", { class: "input" }, [
  675. h("div", { class: "input-container" }, [
  676. h("div", { class: "input" }, [
  677. h("input", {
  678. ref: "inputRef",
  679. class: "input-control",
  680. name: this.name,
  681. value: this.inputValue,
  682. onInput: this.onInput,
  683. type: this.type,
  684. placeholder: this.placeholder,
  685. required: this.required,
  686. ...this.$attrs,
  687. autocomplete: "off",
  688. }),
  689. ]),
  690. ]),
  691. ]);
  692. },
  693. };
  694. // ss-login-button
  695. const SsLoginButton = {
  696. name: "SsLoginButton",
  697. inheritAttrs: false,
  698. props: {
  699. class: {
  700. type: String,
  701. default: "",
  702. },
  703. text: {
  704. type: String,
  705. default: "",
  706. },
  707. type: {
  708. type: String,
  709. default: "button",
  710. },
  711. },
  712. emits: ["click"],
  713. setup(props, { emit }) {
  714. // 定义事件处理函数
  715. const onClick = (event) => {
  716. // 发射一个 'click' 事件,你可以传递所需的参数
  717. emit("click", event);
  718. };
  719. return { props, onClick };
  720. },
  721. render() {
  722. const SsIcon = resolveComponent("ss-icon");
  723. const SsLoginIcon = resolveComponent("ss-login-icon");
  724. return h(
  725. "button",
  726. { class: "login-button", type: this.type, onClick: this.onClick },
  727. [
  728. h("span", [h(SsLoginIcon, { class: this.class })]),
  729. h("span", {}, this.text),
  730. ]
  731. );
  732. },
  733. };
  734. // ss-objp 下拉选择
  735. const SsObjp = {
  736. name: "SsObjp",
  737. inheritAttrs: false,
  738. props: {
  739. onchange: {
  740. //在此属性传入onChange的window全局回调函数,函数唯一参数是当前选中值 Ben(20251217)
  741. type: String,
  742. required: false,
  743. },
  744. filter: {
  745. type: String,
  746. required: false,
  747. },
  748. filterfield: {
  749. type: String,
  750. required: false,
  751. },
  752. // filterField: {
  753. // //此属性为页面表单元素的name用逗号分隔,作用为在向后台查询下拉菜单选项时,会带上这些name的表单元素的value值 Ben(20260313)
  754. // type: String,
  755. // required: false,
  756. // },
  757. cb: {
  758. type: String,
  759. required: true,
  760. },
  761. url: {
  762. type: String,
  763. required: true,
  764. },
  765. name: {
  766. type: String,
  767. required: true,
  768. },
  769. width: {
  770. type: String,
  771. default: "100%",
  772. },
  773. placeholder: {
  774. type: String,
  775. default: "请选择",
  776. },
  777. inp: {
  778. type: Boolean,
  779. default: false,
  780. },
  781. opt: {
  782. type: Array,
  783. default: () => [],
  784. },
  785. errTip: String,
  786. defaultValue: [String, Number],
  787. modelValue: [String, Number],
  788. direction: {
  789. type: String,
  790. default: "bottom",
  791. },
  792. },
  793. emits: ["update:modelValue", "input", "blur", "change"],
  794. setup(props, { emit }) {
  795. const canInput = props.inp;
  796. const errMsg = Vue.ref(props.errTip);
  797. const selectItem = Vue.ref({});
  798. let inputText = Vue.ref(""); // 用于存储输入框的文本
  799. const popupWinVisible = Vue.ref(false);
  800. const filteredOptions = Vue.ref(props.opt);
  801. const popupDirection = Vue.ref("bottom");
  802. const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
  803. const popupContentAreaMaxHeight = Vue.computed(() => {
  804. if (!popupMaxHeight.value || popupMaxHeight.value === "none")
  805. return null;
  806. const maxHeightNum = Number.parseFloat(popupMaxHeight.value);
  807. if (!Number.isFinite(maxHeightNum)) return null;
  808. // 功能说明:滚动条统一落在 .content-area(CSS 默认如此),因此需要扣掉 popup-win padding-top(10) 与 popup-content padding(15*2) by xu 20260126
  809. const contentAreaMaxHeight = Math.max(60, maxHeightNum - 40);
  810. return `${contentAreaMaxHeight}px`;
  811. });
  812. // 修复表格内下拉弹层被 overflow 截断:popup 使用 Teleport 到 body + fixed 定位 by xu 20260126
  813. const selectContainerRef = Vue.ref(null);
  814. const popupRef = Vue.ref(null);
  815. const teleportRootStyle = Vue.ref({
  816. position: "fixed",
  817. left: "0",
  818. top: "0",
  819. width: "0",
  820. height: "0",
  821. zIndex: 9999,
  822. pointerEvents: "none",
  823. });
  824. const popupLayerStyle = Vue.ref({
  825. position: "fixed",
  826. left: "0",
  827. top: "0",
  828. bottom: "auto", // 功能说明:覆盖 .popup-win.top 的 bottom 定位,避免 fixed 场景被撑高/错位 by xu 20260126
  829. minWidth: "0",
  830. zIndex: 9999,
  831. pointerEvents: "auto",
  832. });
  833. // const showRequired = Vue.computed(() => {
  834. // const hasValidationRule = window.ssVm?.validations?.has(props.name);
  835. // if (!hasValidationRule) return false;
  836. // if (errMsg.value) return true;
  837. // if (!selectItem.value?.value) return true;
  838. // return false;
  839. // });
  840. const validate = () => {
  841. if (window.ssVm) {
  842. const result = window.ssVm.validateField(props.name);
  843. // console.log("validate", window.ssVm.validateField(props.name));
  844. errMsg.value = result.valid ? "" : result.message;
  845. }
  846. };
  847. //在objPicker界面,选中value对应的项
  848. const updateSelectItem = () => {
  849. // console.log(props.opt);
  850. const item = props.opt.find((it) => it.value === props.modelValue);
  851. if (item) {
  852. selectItem.value = item;
  853. inputText.value = item.label;
  854. } else {
  855. selectItem.value = { label: "", value: "" };
  856. inputText.value = "";
  857. }
  858. // validate();
  859. };
  860. Vue.watch(
  861. () => props.errTip,
  862. (newVal) => {
  863. errMsg.value = newVal;
  864. }
  865. );
  866. Vue.watch(() => props.modelValue, updateSelectItem, { immediate: true });
  867. Vue.watch(
  868. () => props.opt,
  869. (newVal) => {
  870. updateSelectItem();
  871. filteredOptions.value = [...newVal];
  872. // console.log("filteredOptions", filteredOptions.value);
  873. }
  874. );
  875. //初始化objPicker在页面刚打开时的默认值
  876. async function initDefaultValue() {
  877. try {
  878. if (props.url && props.cb && props.modelValue) {
  879. let objectPickerParam;
  880. let url = props.url;
  881. //如果有定义过滤器
  882. if (props.filter) {
  883. //包含HTML实体的JSON字符串转为JSON对象,如原字符串是{&quot;dwid&quot;:&quot;88&quot;},注意key也必需用单引号包着
  884. // const decodedString = props.filter.replace(/&quot;/g, '"'); // 转换为: {"dwid":"88"}
  885. // objectPickerParam = JSON.parse(decodedString); // 转为json对象
  886. const filterObj = props.filter; // 转为json对象
  887. for (let k in filterObj) {
  888. let v = filterObj[k];
  889. url += "&" + k + "=" + v;
  890. }
  891. objectPickerParam = props.filter; // 转为json对象
  892. objectPickerParam["input"] = props.inp;
  893. objectPickerParam["codebook"] = props.cb;
  894. // alert(url);
  895. } else {
  896. objectPickerParam = { input: props.inp, codebook: props.cb };
  897. }
  898. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  899. const params = new URLSearchParams();
  900. params.append("objectpickerparam", objectPickerParamStr);
  901. params.append("objectpickertype", "2");
  902. params.append("objectpickervalue", props.modelValue); //需回显的值
  903. // alert("1params:"+JSON.stringify(params));
  904. axios
  905. .post(props.url, params, {
  906. headers: {
  907. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  908. },
  909. })
  910. .then((response) => {
  911. // alert(JSON.stringify(response.data));
  912. if ("timeout" == response.data.statusText) {
  913. alert("网络超时!");
  914. return;
  915. }
  916. if (response.data.result) {
  917. const keys = Object.keys(response.data.result);
  918. if (keys.length === 1) {
  919. let code = keys[0];
  920. let desc = response.data.result[keys[0]];
  921. if (props.opt)
  922. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  923. else {
  924. props.opt = [];
  925. }
  926. props.opt.push({ label: desc, value: code });
  927. updateSelectItem();
  928. // alert('props.opt:'+JSON.stringify(props.opt));
  929. }
  930. }
  931. });
  932. }
  933. } catch (error) {
  934. // callback(null, error.message); // 失败回调,传递错误
  935. }
  936. }
  937. // Vue.onMounted(updateSelectItem);
  938. const doSelectItem = (item) => {
  939. emit("update:modelValue", item.value);
  940. selectItem.value = item;
  941. inputText.value = item.label;
  942. hidePopup();
  943. nextTick(() => {
  944. console.log(item.value + "@@@props.modelValue:" + props.modelValue);
  945. validate();
  946. if (window.ssVm) {
  947. // 遍历所有验证规则,找到依赖当前字段的规则
  948. for (const [field, rules] of window.ssVm.validations.entries()) {
  949. for (const rule of rules) {
  950. if (rule.opt?.relField === props.name) {
  951. // console.log("Found dependent field:", field); // 调试日志
  952. window.ssVm.validateField(field);
  953. }
  954. }
  955. }
  956. }
  957. });
  958. callGlobalOnchg(item.value, item.label); // 值变化时尝试调用全局onchange回调函数 Ben(20251217)
  959. };
  960. // 用于调用全局onchange回调函数 Ben(20251217)
  961. const callGlobalOnchg = (value, desc) => {
  962. // 检查 onchange 属性是否提供了有效的函数名
  963. if (props.onchange && typeof props.onchange === "string") {
  964. // 检查 window 对象上是否存在该函数
  965. if (
  966. typeof window !== "undefined" &&
  967. window[props.onchange] &&
  968. typeof window[props.onchange] === "function"
  969. ) {
  970. try {
  971. window[props.onchange](value, desc); // 调用全局函数,并传入当前选中值
  972. } catch (error) {
  973. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  974. }
  975. } else {
  976. console.warn(`全局函数 ${props.onchange} 未定义或不是一个函数。`);
  977. }
  978. }
  979. };
  980. //可录入的objPicker,更新下拉菜单选项
  981. async function updateOptionBYInputText(inpTxt) {
  982. try {
  983. let objectPickerParam;
  984. let url = props.url;
  985. if (props.url && props.cb) {
  986. //如果有定义过滤器
  987. if (props.filter || props.filterfield) {
  988. let filterObj = props.filter;
  989. if (!props.filter) filterObj = {};
  990. if (props.filter) {
  991. const filterObj = props.filter; // 转为json对象
  992. for (let k in filterObj) {
  993. let v = filterObj[k];
  994. url += "&" + k + "=" + v;
  995. }
  996. }
  997. if (props.filterfield) {
  998. //加上filterfield的值过滤
  999. let filterfieldArr = props.filterfield.split(",");
  1000. for (var i = 0; i < filterfieldArr.length; i++) {
  1001. let fieldName = filterfieldArr[i];
  1002. let fields = document.getElementsByName(fieldName);
  1003. if (!fields || fields.length < 1) {
  1004. alert("下拉菜单配置的过滤条件" + fieldName + "不存在!");
  1005. continue;
  1006. }
  1007. let v = null;
  1008. for (let j = 0; j < fields.length; j++) {
  1009. if (fields[j].value) {
  1010. v = fields[j].value;
  1011. break;
  1012. }
  1013. }
  1014. // let field = document.getElementsByName(fieldName)[0];
  1015. // let v = field.value;
  1016. if (v) {
  1017. url += "&" + fieldName + "=" + v;
  1018. filterObj[fieldName] = v;
  1019. }
  1020. }
  1021. console.log("filterfield url:" + url);
  1022. }
  1023. //包含HTML实体的JSON字符串转为JSON对象,如原字符串是{&quot;dwid&quot;:&quot;88&quot;},注意key也必需用单引号包着
  1024. // const decodedString = props.filter.replace(/&quot;/g, '"'); // 转换为: {"dwid":"88"}
  1025. // objectPickerParam = JSON.parse(decodedString); // 转为json对象
  1026. objectPickerParam = filterObj;
  1027. objectPickerParam["input"] = props.inp;
  1028. objectPickerParam["codebook"] = props.cb;
  1029. // alert(url);
  1030. } else {
  1031. objectPickerParam = { input: props.inp, codebook: props.cb };
  1032. }
  1033. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  1034. const params = new URLSearchParams();
  1035. params.append("objectpickerparam", objectPickerParamStr);
  1036. params.append("objectpickertype", "1");
  1037. if (props.inp && props.inp === true) {
  1038. //把"true"改为true Ben(20251209)
  1039. params.append("objectpickersearchAll", 0); //只查录入的值
  1040. params.append("objectpickerinput", inpTxt); //录入的值
  1041. } else {
  1042. params.append("objectpickersearchAll", 1);
  1043. }
  1044. axios
  1045. .post(url, params, {
  1046. headers: {
  1047. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1048. },
  1049. })
  1050. .then((response) => {
  1051. if ("timeout" == response.data.statusText) {
  1052. alert("网络超时!");
  1053. return;
  1054. }
  1055. // 先清空选项 by xu 20251212
  1056. if (props.opt) {
  1057. props.opt.length = 0;
  1058. } else {
  1059. props.opt = [];
  1060. }
  1061. if (response.data.result) {
  1062. const keys = Object.keys(response.data.result);
  1063. // console.log("params:"+params+"@@response.data:"+JSON.stringify(response.data));
  1064. if (keys.length > 0) {
  1065. for (let k in response.data.result) {
  1066. props.opt.push({
  1067. label: response.data.result[k],
  1068. value: k,
  1069. });
  1070. }
  1071. // console.log('###inpTxt:'+inpTxt+';');
  1072. if (
  1073. props.inp &&
  1074. props.inp === true && //把"true"改为true Ben(20251209)
  1075. inpTxt.length > 0
  1076. ) {
  1077. //对于可录入的,用已录入的值作过滤
  1078. filteredOptions.value = props.opt.filter((option) =>
  1079. option.label
  1080. .toLowerCase()
  1081. .includes(inputText.value.toLowerCase())
  1082. );
  1083. // 可录入的objPicker,当搜索结果只有一项时,自动选中这一项 by xu 20251212
  1084. if (filteredOptions.value.length === 1) {
  1085. const autoSelectItem = filteredOptions.value[0];
  1086. console.log(
  1087. "[objp] 搜索结果只有一项,自动选中:",
  1088. autoSelectItem
  1089. );
  1090. doSelectItem(autoSelectItem);
  1091. return; // 自动选中后直接返回,不需要显示popup
  1092. }
  1093. filteredOptions.value.unshift({ label: "", value: "" });
  1094. // console.log('###做了过滤:'+inputText.value.toLowerCase()+';');
  1095. } else {
  1096. filteredOptions.value = props.opt;
  1097. filteredOptions.value.unshift({ label: "", value: "" });
  1098. }
  1099. console.log("props.opt11:" + JSON.stringify(props.opt));
  1100. } else {
  1101. // 没有数据时,清空过滤选项 by xu 20251212
  1102. filteredOptions.value = [];
  1103. console.log("[objp] 接口返回空数据");
  1104. }
  1105. } else {
  1106. // result不存在时,清空过滤选项 by xu 20251212
  1107. filteredOptions.value = [];
  1108. console.log("[objp] 接口返回无result");
  1109. }
  1110. // 无论是否有数据,都显示popup by xu 20251212
  1111. openPopup(); // Teleport 场景下统一打开并重定位 by xu 20260126
  1112. });
  1113. }
  1114. } catch (error) {
  1115. // callback(null, error.message); // 失败回调,传递错误
  1116. }
  1117. }
  1118. // 计算弹出方向和最大高度的方法 by xu 20251212
  1119. // 当空间不足时限制popup高度并显示滚动条
  1120. const calculatePopupDirection = () => {
  1121. const triggerEl =
  1122. selectContainerRef.value?.querySelector(".input") ||
  1123. selectContainerRef.value;
  1124. if (!triggerEl) return;
  1125. const selectRect = triggerEl.getBoundingClientRect();
  1126. const viewportHeight = window.innerHeight;
  1127. // 3. 计算上下可用空间
  1128. const spaceBelow = viewportHeight - selectRect.bottom - 10; // 减10px留边距
  1129. const spaceAbove = selectRect.top - 10; // 减10px留边距
  1130. // 4. popup预估高度(假设每项36px,最多显示8项 + padding)
  1131. const estimatedPopupHeight = 300;
  1132. const minPopupHeight = 100; // 最小高度
  1133. console.log(
  1134. "[popup] 空间计算 - spaceAbove:",
  1135. spaceAbove,
  1136. "spaceBelow:",
  1137. spaceBelow,
  1138. "estimatedHeight:",
  1139. estimatedPopupHeight
  1140. );
  1141. // 5. 判断方向和最大高度 by xu 20251212
  1142. if (spaceBelow >= estimatedPopupHeight) {
  1143. // 下方空间足够,向下展开,不限制高度
  1144. popupDirection.value = "bottom";
  1145. popupMaxHeight.value = "none";
  1146. console.log("[popup] 向下展开,空间充足");
  1147. } else if (spaceAbove >= estimatedPopupHeight) {
  1148. // 上方空间足够,向上展开,不限制高度
  1149. popupDirection.value = "top";
  1150. popupMaxHeight.value = "none";
  1151. console.log("[popup] 向上展开,空间充足");
  1152. } else {
  1153. // 上下空间都不足,选择空间大的方向,并限制高度出滚动条
  1154. if (spaceBelow >= spaceAbove) {
  1155. popupDirection.value = "bottom";
  1156. popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px";
  1157. console.log(
  1158. "[popup] 向下展开,空间不足,限制高度:",
  1159. popupMaxHeight.value
  1160. );
  1161. } else {
  1162. popupDirection.value = "top";
  1163. popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px";
  1164. console.log(
  1165. "[popup] 向上展开,空间不足,限制高度:",
  1166. popupMaxHeight.value
  1167. );
  1168. }
  1169. }
  1170. };
  1171. // Teleport popup 的定位(fixed) by xu 20260126
  1172. const updatePopupPosition = () => {
  1173. const triggerEl =
  1174. selectContainerRef.value?.querySelector(".input") ||
  1175. selectContainerRef.value;
  1176. if (!triggerEl) return;
  1177. const triggerRect = triggerEl.getBoundingClientRect();
  1178. const margin = 10;
  1179. const viewportWidth = window.innerWidth;
  1180. const viewportHeight = window.innerHeight;
  1181. const popupGap = 0; // 功能说明:定位不再做 -10 重叠,让 padding-top 自然形成间距 by xu 20260126
  1182. // 先给一个初始位置,确保下一帧可以测量弹层尺寸 by xu 20260126
  1183. popupLayerStyle.value = {
  1184. position: "fixed",
  1185. left: `${Math.max(margin, triggerRect.left)}px`,
  1186. top: `${Math.max(margin, triggerRect.bottom + popupGap)}px`, // 功能说明:与输入框底部对齐 by xu 20260126
  1187. bottom: "auto", // 功能说明:fixed 场景显式取消 bottom,避免与 top 同时生效 by xu 20260126
  1188. minWidth: `${Math.max(0, triggerRect.width)}px`,
  1189. zIndex: 9999,
  1190. pointerEvents: "auto",
  1191. };
  1192. Vue.nextTick(() => {
  1193. const popupEl = popupRef.value;
  1194. if (!popupEl) return;
  1195. const popupRect = popupEl.getBoundingClientRect();
  1196. const maxLeft = viewportWidth - popupRect.width - margin;
  1197. const left = Math.min(
  1198. Math.max(margin, triggerRect.left),
  1199. Math.max(margin, maxLeft)
  1200. );
  1201. let top;
  1202. if (popupDirection.value === "top") {
  1203. top = triggerRect.top - popupRect.height - popupGap; // 功能说明:向上展开时与输入框顶部对齐 by xu 20260126
  1204. top = Math.max(margin, top);
  1205. } else {
  1206. top = triggerRect.bottom + popupGap; // 功能说明:向下展开时与输入框底部对齐 by xu 20260126
  1207. if (top + popupRect.height > viewportHeight - margin) {
  1208. top = Math.max(
  1209. margin,
  1210. viewportHeight - popupRect.height - margin
  1211. );
  1212. }
  1213. }
  1214. popupLayerStyle.value = {
  1215. ...popupLayerStyle.value,
  1216. left: `${left}px`,
  1217. top: `${top}px`,
  1218. bottom: "auto", // 功能说明:无论 top/bottom 展开都用 top 定位,禁用 bottom by xu 20260126
  1219. };
  1220. });
  1221. };
  1222. const openPopup = () => {
  1223. if (!popupWinVisible.value) popupWinVisible.value = true;
  1224. Vue.nextTick(() => {
  1225. calculatePopupDirection();
  1226. updatePopupPosition();
  1227. });
  1228. };
  1229. // Teleport 场景下:滚动/缩放重定位 by xu 20260126
  1230. const handleViewportChange = () => {
  1231. if (!popupWinVisible.value) return;
  1232. calculatePopupDirection();
  1233. updatePopupPosition();
  1234. };
  1235. // Teleport 场景下:点击外部关闭 by xu 20260126
  1236. const onDocPointerDown = (event) => {
  1237. if (!popupWinVisible.value) return;
  1238. const target = event.target;
  1239. if (selectContainerRef.value?.contains(target)) return;
  1240. if (popupRef.value?.contains(target)) return;
  1241. hidePopup();
  1242. };
  1243. //点击下拉菜单的文本区域时,会触发的方法
  1244. function togglePopup() {
  1245. // 可录入的 objPicker,更新下拉菜单选项
  1246. updateOptionBYInputText(inputText.value);
  1247. // popupWinVisible.value = !popupWinVisible.value;
  1248. Vue.nextTick(() => {
  1249. calculatePopupDirection();
  1250. updatePopupPosition(); // Teleport 场景下同步定位 by xu 20260126
  1251. });
  1252. }
  1253. const hidePopup = () => {
  1254. popupWinVisible.value = false;
  1255. };
  1256. //点击下拉菜单的三角形时,会触发的方法
  1257. // 添加toggle逻辑,点击时切换显示/隐藏 by xu 20251212
  1258. const suffixClick = () => {
  1259. // 如果popup已显示,则关闭 by xu 20251212
  1260. if (popupWinVisible.value) {
  1261. hidePopup();
  1262. console.log("[objp] 点三角关闭popup");
  1263. return;
  1264. }
  1265. //可录入的objPicker,更新下拉菜单选项
  1266. updateOptionBYInputText("");
  1267. Vue.nextTick(() => {
  1268. calculatePopupDirection();
  1269. updatePopupPosition(); // Teleport 场景下同步定位 by xu 20260126
  1270. });
  1271. console.log("[objp] 点三角打开popup");
  1272. };
  1273. //可录入的objPicker,录入项变化时,会触发
  1274. async function handleInputChange(event) {
  1275. inputText.value = event.target.value;
  1276. if (!inputText.value) {
  1277. inputText.value = "";
  1278. }
  1279. //可录入的objPicker,更新下拉菜单选项
  1280. updateOptionBYInputText(inputText.value);
  1281. // filteredOptions.value = props.opt.filter((option) =>
  1282. // option.label.toLowerCase().includes(inputText.value.toLowerCase())
  1283. // );
  1284. // if (!popupWinVisible.value) {
  1285. // popupWinVisible.value = true; // 确保下拉框在输入时打开
  1286. // }
  1287. }
  1288. Vue.onMounted(() => {
  1289. initDefaultValue();
  1290. // Teleport 场景下:滚动/缩放需要重定位(scroll 用 capture 捕获容器滚动) by xu 20260126
  1291. window.addEventListener("resize", handleViewportChange);
  1292. window.addEventListener("scroll", handleViewportChange, true);
  1293. // 点击外部关闭(原本依赖 mouseleave,Teleport 后会误关) by xu 20260126
  1294. document.addEventListener("pointerdown", onDocPointerDown, true);
  1295. });
  1296. Vue.onUnmounted(() => {
  1297. window.removeEventListener("resize", handleViewportChange);
  1298. window.removeEventListener("scroll", handleViewportChange, true);
  1299. document.removeEventListener("pointerdown", onDocPointerDown, true);
  1300. });
  1301. return {
  1302. errMsg,
  1303. selectItem,
  1304. inputText,
  1305. canInput,
  1306. filteredOptions,
  1307. popupWinVisible,
  1308. popupDirection,
  1309. popupMaxHeight, // 添加popup最大高度 by xu 20251212
  1310. popupContentAreaMaxHeight,
  1311. selectContainerRef,
  1312. popupRef,
  1313. teleportRootStyle,
  1314. popupLayerStyle,
  1315. suffixClick,
  1316. togglePopup,
  1317. hidePopup,
  1318. doSelectItem,
  1319. handleInputChange,
  1320. };
  1321. },
  1322. template: `
  1323. <div class="input" style="position: relative" :style="{width: width}">
  1324. <div class="select-container" ref="selectContainerRef">
  1325. <div class="input" @click="togglePopup">
  1326. <input
  1327. type="hidden"
  1328. :name="name"
  1329. :value="selectItem.value"
  1330. .value="selectItem.value"
  1331. />
  1332. <input
  1333. v-model="inputText"
  1334. @input="handleInputChange"
  1335. v-if="canInput"
  1336. :placeholder="placeholder"
  1337. />
  1338. <input
  1339. v-else
  1340. :placeholder="placeholder"
  1341. :value="selectItem.label"
  1342. disabled
  1343. style="pointer-events: none;"
  1344. />
  1345. <div class="suffix" @click.stop="suffixClick">
  1346. <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
  1347. </div>
  1348. </div>
  1349. <!-- 修复表格内弹层被截断:popup Teleport 到 body by xu 20260126 -->
  1350. <teleport to="body">
  1351. <div v-show="popupWinVisible" class="select-container ss-objp-teleport-root" :style="teleportRootStyle">
  1352. <!-- popup弹出层,添加maxHeight和overflowY支持空间不足时滚动 by xu 20251212 -->
  1353. <div ref="popupRef" class="popup-win" :class="popupDirection" :style="[popupLayerStyle, { maxHeight: popupMaxHeight !== 'none' ? popupMaxHeight : 'none', overflowY: 'visible' }]">
  1354. <div v-if="opt && opt.length && filteredOptions.length > 0" class="popup-content">
  1355. <div class="content-area" :style="popupContentAreaMaxHeight ? { maxHeight: popupContentAreaMaxHeight, overflowY: 'auto' } : null">
  1356. <div v-for="(item, index) in filteredOptions" :key="index" @click="doSelectItem(item)" :class="{ active: item.value === selectItem.value }">
  1357. <span class="check-icon">
  1358. <ss-form-icon class="form-icon-select-checked" />
  1359. </span>
  1360. <span>{{ item.label }}</span>
  1361. </div>
  1362. </div>
  1363. </div>
  1364. <div v-else class="popup-content"><div class="content-area"><div class="content-area"> <span>无选项</span></div></div></div>
  1365. </div>
  1366. </div>
  1367. </teleport>
  1368. </div>
  1369. </div>
  1370. `,
  1371. };
  1372. // ss-hidden 隐藏字段组件
  1373. const SsHidden = {
  1374. name: "SsHidden",
  1375. props: {
  1376. modelValue: String,
  1377. name: {
  1378. type: String,
  1379. required: true,
  1380. },
  1381. rule: {
  1382. type: String,
  1383. required: true,
  1384. },
  1385. param: {
  1386. type: String,
  1387. required: true,
  1388. },
  1389. url: {
  1390. type: String,
  1391. required: true,
  1392. },
  1393. },
  1394. emits: ["update:modelValue"],
  1395. setup(props, { emit }) {
  1396. const errMsg = Vue.ref("");
  1397. const validate = () => {
  1398. if (window.ssVm) {
  1399. const result = window.ssVm.validateField(props.name);
  1400. console.log("validate", window.ssVm.validateField(props.name));
  1401. errMsg.value = result.valid ? "" : result.message;
  1402. }
  1403. };
  1404. Vue.onMounted(() => {
  1405. /**
  1406. * 初始化级联菜单值初始值思路:
  1407. * 1. 带隐藏字段(即带编码规则)的级联菜单
  1408. * 在隐藏字段这,可以取到要回显的值和编码规则,从而计算出各级下拉菜单要回显的值。
  1409. * 然后通过ajax取各级级联菜单的值回显。
  1410. * 2. 不带隐藏字段的级联,只能在各个下拉菜单的setup事件中通过ajax取回显值回显
  1411. */
  1412. // 当同组级联下拉菜单选中值变化时,会调用本隐藏字段下面这方法设置隐藏字段值
  1413. window.addEventListener(
  1414. "cascader-setHiddenVal-" + props.name,
  1415. (event) => {
  1416. const { value } = event.detail;
  1417. emit("update:modelValue", value);
  1418. console.log(value);
  1419. setTimeout(() => {
  1420. validate();
  1421. }, 50);
  1422. }
  1423. );
  1424. // 如果有初始值,触发回显过程
  1425. if (props.modelValue) {
  1426. console.log("级联隐藏字段,开始回显,初始值:", props.modelValue);
  1427. triggerCascaderEcho(props.modelValue);
  1428. validate();
  1429. }
  1430. });
  1431. // 触发级联回显
  1432. const triggerCascaderEcho = (code) => {
  1433. /**
  1434. * 开始回显,初始值: 440304
  1435. * 解析后的所有值: Array(3)0: "440000"1: "440300"2: "440304"length: 3[[Prototype]]: Array(0)
  1436. */
  1437. const values = parseHiddenCodeForAll(code, props.rule);
  1438. console.log("解析后的所有值:", values);
  1439. // 转换为 JSON 对象
  1440. // const paramObj = JSON.parse(props.param);
  1441. const paramObj = props.param;
  1442. let selectArr = paramObj.fieldOrd; //保存本组级联菜单项的数组,如:['hksheng','hkshi','hkxian']
  1443. if (selectArr.length != values.length) {
  1444. // alert('属性'+props.name+'的值'+code+'与级联菜单中下拉菜单的数目不匹配!');
  1445. return;
  1446. }
  1447. // 按顺序触发回显,并增加延迟确保数据加载
  1448. /**
  1449. * 通过隐藏字段的setup事件,
  1450. * 循环遍历各级下拉菜单,并触发定义在下拉菜单中的'cascader-echo'事件,
  1451. * 在此事件中完成每个下拉菜单回显值操作(只取当前要回显的键值对显示,
  1452. * 下拉菜单所有的值,在点击下拉菜单时,才通过ajax取)。
  1453. */
  1454. values.forEach((value, index) => {
  1455. if (value) {
  1456. setTimeout(() => {
  1457. let upperVal = undefined;
  1458. if (index != 0) {
  1459. upperVal = values[index - 1];
  1460. }
  1461. const echoEvent = new CustomEvent(
  1462. "cascader-echo-" + selectArr[index],
  1463. {
  1464. detail: {
  1465. name: props.name,
  1466. value: value,
  1467. // level: index + 1,
  1468. isAuto: true, // 标记为自动回显
  1469. upperVal: upperVal,
  1470. },
  1471. }
  1472. );
  1473. console.log(props.name + "--upperValue:" + upperVal);
  1474. window.dispatchEvent(echoEvent);
  1475. }, index * 500); // 每级增加500ms延迟
  1476. }
  1477. });
  1478. };
  1479. // 解析所有级别的代码
  1480. const parseHiddenCodeForAll = (code, rule) => {
  1481. if (!code || !rule) return [];
  1482. // 获取规则中每段的长度
  1483. const segments = [];
  1484. let currentChar = rule[0];
  1485. let currentLength = 1;
  1486. for (let i = 1; i < rule.length; i++) {
  1487. if (rule[i] === currentChar) {
  1488. currentLength++;
  1489. } else {
  1490. segments.push(currentLength);
  1491. currentChar = rule[i];
  1492. currentLength = 1;
  1493. }
  1494. }
  1495. segments.push(currentLength);
  1496. // 解析每一级的值
  1497. const values = [];
  1498. let position = 0;
  1499. segments.forEach((length, index) => {
  1500. const value = code
  1501. .substring(0, position + length)
  1502. .padEnd(rule.length, "0");
  1503. values.push(value);
  1504. position += length;
  1505. });
  1506. return values;
  1507. };
  1508. watchEffect(() => {});
  1509. return {};
  1510. },
  1511. template: `<input type="hidden" :name="name" :value="modelValue">`,
  1512. };
  1513. // ss-cascader 级联选择器
  1514. const SsCcp = {
  1515. name: "SsCcp",
  1516. inheritAttrs: false,
  1517. props: {
  1518. modelValue: String,
  1519. name: {
  1520. type: String,
  1521. required: true,
  1522. },
  1523. level: {
  1524. type: Number,
  1525. required: true,
  1526. },
  1527. opt: {
  1528. type: Array,
  1529. default: () => [],
  1530. },
  1531. placeholder: {
  1532. type: String,
  1533. default: "请选择",
  1534. },
  1535. width: {
  1536. type: String,
  1537. default: "150px",
  1538. },
  1539. direction: {
  1540. type: String,
  1541. default: "bottom",
  1542. },
  1543. mode: {
  1544. type: String,
  1545. default: "1",
  1546. },
  1547. //级联菜单配置参数,如果是数组,则代表本下拉菜单是多套级联菜单共用的第一级菜单。如果是对象,则只有一套级联菜单用此下拉菜单。
  1548. param: {
  1549. type: String,
  1550. required: true,
  1551. },
  1552. //向后台拿数据的url
  1553. url: {
  1554. type: String,
  1555. required: true,
  1556. },
  1557. },
  1558. emits: ["update:modelValue", "change"],
  1559. setup(props, { emit }) {
  1560. // alert('级联菜单初始化:'+props.name+':--:'+props.modelValue);
  1561. const selectItem = Vue.ref({ label: props.placeholder, value: "" });
  1562. const popupWinVisible = Vue.ref(false);
  1563. const isAutoEcho = Vue.ref(false); // 用于标记是否是自动回显
  1564. const upperValue = Vue.ref(""); //上级下拉菜单当前值,在初始化下拉菜单默认值时,和上级下拉菜单的值变化时,修改此upperValue变量
  1565. const popupDirection = Vue.ref("bottom");
  1566. const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
  1567. //有隐藏字段的下拉菜单,加载菜单项并展开事件
  1568. // 被上级下拉菜单选中值后,触发本下拉菜单刷新菜单项并弹出显示
  1569. window.addEventListener("cascader-open-" + props.name, async (event) => {
  1570. const { upperVal } = event.detail;
  1571. upperValue.value = upperVal;
  1572. console.log(
  1573. "22props.name:" +
  1574. props.name +
  1575. ",22props.upperValue:" +
  1576. upperValue.value
  1577. );
  1578. selectItem.value = ""; //清除本下拉菜单当前选中的值
  1579. emit("update:modelValue", ""); //通知父级
  1580. //清空下拉菜单,并设置第一项的值为placeholder
  1581. clearAndInit1stOpt();
  1582. //下个下拉菜单名
  1583. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1584. if (nextSelName) {
  1585. //清下个下拉菜单选中值和选项
  1586. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  1587. detail: {},
  1588. });
  1589. window.dispatchEvent(event);
  1590. }
  1591. showPopup();
  1592. });
  1593. //设置mode2的下级下拉菜单的上级菜单当前值
  1594. function setNextSelectUpperValue() {
  1595. //设置下级菜单的上级菜单当前值upperValue
  1596. let paramArr = undefined;
  1597. if (Array.isArray(props.param)) {
  1598. paramArr = props.param;
  1599. } else {
  1600. paramArr = [];
  1601. paramArr.push(props.param);
  1602. }
  1603. for (const oneParam of paramArr) {
  1604. //下个下拉菜单名
  1605. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  1606. if (nextSelName) {
  1607. setTimeout(() => {
  1608. const openNextEvent = new CustomEvent(
  1609. "cascade-setUpperVal-" + nextSelName,
  1610. {
  1611. detail: {
  1612. upperVal: props.modelValue,
  1613. },
  1614. }
  1615. );
  1616. window.dispatchEvent(openNextEvent);
  1617. }, 100);
  1618. }
  1619. } // end for
  1620. }
  1621. // 把上级 级联下拉菜单的值,设置进本组件的事件
  1622. window.addEventListener("cascade-setUpperVal-" + props.name, (event) => {
  1623. // alert('props.name:'+props.name+',props.upperValue:'+event.detail.upperVal);
  1624. const { upperVal } = event.detail;
  1625. upperValue.value = upperVal;
  1626. // console.log('props.name:'+props.name+',props.upperValue:'+upperValue.value);
  1627. });
  1628. //清空下拉菜单,并设置第一项的值为空
  1629. function clearAndInit1stOpt() {
  1630. if (props.opt)
  1631. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  1632. else {
  1633. props.opt = [];
  1634. }
  1635. props.opt.push({ label: "", value: "" });
  1636. }
  1637. //获取下一级下拉菜单,如果下一级下拉菜单不存在,则返回undefined
  1638. function getNextSel(selName, selNameArr) {
  1639. // 检查参数有效性
  1640. if (!Array.isArray(selNameArr) || selNameArr.length === 0) {
  1641. return undefined;
  1642. }
  1643. // 查找当前元素的索引
  1644. const currentIndex = selNameArr.indexOf(selName);
  1645. // 如果元素不存在或已经是最后一个元素,返回undefined
  1646. if (currentIndex === -1 || currentIndex === selNameArr.length - 1) {
  1647. return undefined;
  1648. }
  1649. // 返回下一个元素
  1650. return selNameArr[currentIndex + 1];
  1651. }
  1652. const validate = () => {
  1653. if (window.ssVm) {
  1654. return window.ssVm.validateField(props.name);
  1655. }
  1656. return { valid: true };
  1657. };
  1658. // 处理选择事件
  1659. const doSelectItem = (item) => {
  1660. selectItem.value = item;
  1661. emit("update:modelValue", item.value); //修改本下拉菜单在vue中保存的值
  1662. // alert('item.value:'+item.value);
  1663. if (props.mode === "1") {
  1664. // mode 1 模式:修改隐藏字段值
  1665. let event = new CustomEvent(
  1666. "cascader-setHiddenVal-" + props.param.combField,
  1667. {
  1668. detail: {
  1669. value: item.value,
  1670. },
  1671. }
  1672. );
  1673. window.dispatchEvent(event);
  1674. }
  1675. emit("change", item.value); //触发配置的change方法
  1676. nextTick(() => {
  1677. validate();
  1678. if (window.ssVm) {
  1679. for (const [field, rules] of window.ssVm.validations.entries()) {
  1680. for (const rule of rules) {
  1681. if (rule.options?.relField) {
  1682. const relFields = String(rule.options.relField)
  1683. .split(",")
  1684. .map((name) => name.trim())
  1685. .filter(Boolean);
  1686. if (relFields.includes(props.name)) {
  1687. window.ssVm.validateField(field);
  1688. }
  1689. }
  1690. }
  1691. }
  1692. }
  1693. });
  1694. //设置下级菜单的上级菜单当前值upperValue
  1695. let paramArr = undefined;
  1696. if (Array.isArray(props.param)) {
  1697. paramArr = props.param;
  1698. } else {
  1699. paramArr = [];
  1700. paramArr.push(props.param);
  1701. }
  1702. for (const oneParam of paramArr) {
  1703. //下个下拉菜单名
  1704. const nextSelName = getNextSel(props.name, oneParam.fieldOrd);
  1705. if (nextSelName) {
  1706. setTimeout(() => {
  1707. const openNextEvent = new CustomEvent(
  1708. "cascader-open-" + nextSelName,
  1709. {
  1710. detail: {
  1711. upperVal: item.value,
  1712. },
  1713. }
  1714. );
  1715. window.dispatchEvent(openNextEvent);
  1716. }, 100);
  1717. }
  1718. } // end for
  1719. hidePopup();
  1720. //下个下拉菜单名
  1721. // let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1722. // if(nextSelName){
  1723. // // //设置下一级下拉菜单中保存的本下拉菜单值(upperValue)
  1724. // // event = new CustomEvent('cascade-setUpperVal-'+nextSelName, {
  1725. // // detail: {
  1726. // // value: item.value
  1727. // // }
  1728. // // });
  1729. // // window.dispatchEvent(event);
  1730. //
  1731. // //触发下一级下拉菜单,重新初始化下拉菜单项并弹出显示
  1732. // event = new CustomEvent('cascader-open-' +nextSelName, {
  1733. // detail: {
  1734. // upperVal: item.value
  1735. // }
  1736. // });
  1737. // window.dispatchEvent(event);
  1738. // }
  1739. // 只在手动选择时自动展开下一级
  1740. // if (!isAutoEcho.value) {
  1741. // const nextLevel = props.level + 1;
  1742. // setTimeout(() => {
  1743. // const openNextEvent = new CustomEvent('open-next-cascader', {
  1744. // detail: {
  1745. // name: props.name,
  1746. // level: nextLevel
  1747. // }
  1748. // });
  1749. // window.dispatchEvent(openNextEvent);
  1750. // }, 100);
  1751. // }
  1752. };
  1753. // 监听下一级展开事件 (仅 mode 2)
  1754. window.addEventListener("cascade-open", (event) => {
  1755. if (props.mode === "2") {
  1756. const { level } = event.detail;
  1757. if (level === props.level) {
  1758. popupWinVisible.value = true;
  1759. }
  1760. }
  1761. });
  1762. if (props.mode === "1") {
  1763. //如果是有隐藏字段的下拉菜单
  1764. // 监听回显事件
  1765. window.addEventListener(
  1766. "cascader-echo-" + props.name,
  1767. async (event) => {
  1768. const { name, value, isAuto, upperVal } = event.detail;
  1769. // level,
  1770. if (upperVal) {
  1771. upperValue.value = upperVal;
  1772. console.log(
  1773. "value:" +
  1774. value +
  1775. ",upperValue:" +
  1776. upperValue +
  1777. ",初始化级联组件时props.name:" +
  1778. props.name
  1779. );
  1780. }
  1781. // if (name === props.name && level === props.level) {
  1782. // 设置自动回显标记
  1783. isAutoEcho.value = true;
  1784. // if (props.opt.length === 0) {
  1785. // const loadDataEvent = new CustomEvent('cascader-load-data', {
  1786. // detail: {
  1787. // name: props.name,
  1788. // level: props.level,
  1789. // value: value
  1790. // }
  1791. // });
  1792. // window.dispatchEvent(loadDataEvent);
  1793. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  1794. //Vue.watch用于监听数据的变化,并在数据变化时执行特定的回调函数。
  1795. //这段代码使用了 Vue.js 的 watch API 来监听 props.opt 的变化,如果props.opt有变化,则自动
  1796. // const unwatch = Vue.watch(
  1797. // () => props.opt, // 监听的数据源(props.opt)
  1798. // (newOptions) => { // 回调函数
  1799. // if (newOptions.length > 0) { // 条件判断
  1800. // matchAndSelect(value); // 执行逻辑
  1801. // unwatch(); // 停止监听
  1802. // }
  1803. // },
  1804. // { immediate: true } // 配置:立即触发一次
  1805. // );
  1806. // } else {
  1807. // matchAndSelect(value);
  1808. // }
  1809. // 初始化级联菜单在页面刚打开时的默认值
  1810. async function initDefaultValue(value) {
  1811. try {
  1812. // alert(1);
  1813. if (
  1814. props.url &&
  1815. props.param
  1816. // && props.modelValue 对于有rule编码规则的级联菜单(即mode=1),modelValue一定是空的,所以注释掉,修复mode=1的级联菜单无法回显问题。Ben(20251124)
  1817. ) {
  1818. // alert(2);
  1819. /**
  1820. * let objectPickerParam=
  1821. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  1822. * "\"name\":\"hksheng\"," +
  1823. * "\"cascadingName\":\"dq\",\"cascadingInputsName\":\"hkdqm\"," +
  1824. * "\"codebook\":\"sheng\"}",
  1825. * "objectpickertype":2,
  1826. * "objectpickervalue":"440000"
  1827. * };
  1828. */
  1829. const objectPickerParam = {
  1830. input: "false",
  1831. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  1832. name: props.name, //本下拉菜单名
  1833. cascadingName: props.param.name, //级联菜单名
  1834. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  1835. codebook: props.param.codebook,
  1836. };
  1837. const objectPickerParamStr =
  1838. JSON.stringify(objectPickerParam);
  1839. const params = new URLSearchParams();
  1840. params.append("objectpickerparam", objectPickerParamStr);
  1841. params.append("objectpickertype", "2");
  1842. params.append("objectpickervalue", value); //需回显的值
  1843. axios
  1844. .post(props.url, params, {
  1845. headers: {
  1846. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1847. },
  1848. })
  1849. .then((response) => {
  1850. // alert(JSON.stringify(response.data));
  1851. if ("timeout" == response.data.statusText) {
  1852. alert("网络超时!");
  1853. return;
  1854. }
  1855. if (response.data.result) {
  1856. const keys = Object.keys(response.data.result);
  1857. if (keys.length === 1) {
  1858. let code = keys[0];
  1859. let desc = response.data.result[keys[0]];
  1860. clearAndInit1stOpt();
  1861. props.opt.push({ label: desc, value: code });
  1862. if (value) matchAndSelect(value);
  1863. // updateSelectItem();
  1864. // alert('props.opt:'+JSON.stringify(props.opt));
  1865. }
  1866. }
  1867. });
  1868. }
  1869. } catch (error) {
  1870. alert(error);
  1871. // callback(null, error.message); // 失败回调,传递错误
  1872. }
  1873. }
  1874. //下面的代码只用于页面刚打开时,初始化级联菜单的回显值。
  1875. initDefaultValue(value);
  1876. // 延迟重置自动回显标记
  1877. setTimeout(() => {
  1878. isAutoEcho.value = false;
  1879. }, 500);
  1880. }
  1881. );
  1882. // 被上级下拉菜单触发的,清除选中值和下拉菜单选项
  1883. window.addEventListener(
  1884. "cascader-cleanOpt-" + props.name,
  1885. async (event) => {
  1886. upperValue.value = "";
  1887. selectItem.value = ""; //清除本下拉菜单当前选中的值
  1888. emit("update:modelValue", ""); //通知父级
  1889. //清空所有下拉菜单项
  1890. if (props.opt) {
  1891. props.opt.length = 0;
  1892. } else {
  1893. props.opt = [];
  1894. }
  1895. //下个下拉菜单名
  1896. let nextSelName = getNextSel(props.name, props.param.fieldOrd);
  1897. // alert('nextSelName:'+nextSelName+'--,props.name:'+props.name);
  1898. if (nextSelName) {
  1899. //清下个下拉菜单选中值和选项
  1900. event = new CustomEvent("cascader-cleanOpt-" + nextSelName, {
  1901. detail: {},
  1902. });
  1903. window.dispatchEvent(event);
  1904. }
  1905. }
  1906. );
  1907. } else if (props.mode === "2") {
  1908. //没隐藏字段的下拉菜单,在这初始化默认值
  1909. let needInitParam = undefined;
  1910. if (Array.isArray(props.param)) {
  1911. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  1912. console.log("needInitParam最后一项:" + JSON.stringify(needInitParam));
  1913. } else {
  1914. needInitParam = props.param;
  1915. }
  1916. // 初始化级联菜单在页面刚打开时的默认值
  1917. async function initDefaultValue(value, param) {
  1918. try {
  1919. // alert(1);
  1920. if (props.url && param && props.modelValue) {
  1921. // alert(2);
  1922. /**
  1923. * let param=
  1924. * {"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"rylbm,gwid\"," +
  1925. * "\"name\":\"gwid\",\"cascadingName\":\"rylb_gw\"," +
  1926. * "\"codebook\":\"gwByRylb\"}",
  1927. * "objectpickertype":2,
  1928. * "objectpickervalue":"102121"};
  1929. */
  1930. // alert('props.name:'+props.name+',props.param.fieldOrd:'+props.param.fieldOrd);
  1931. const objectPickerParam = {
  1932. input: "false",
  1933. cascadingLevel: param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  1934. name: props.name, //本下拉菜单名
  1935. cascadingName: param.name, //级联菜单名
  1936. codebook: param.codebook,
  1937. };
  1938. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  1939. const sendParams = new URLSearchParams();
  1940. sendParams.append("objectpickerparam", objectPickerParamStr);
  1941. sendParams.append("objectpickertype", "2");
  1942. sendParams.append("objectpickervalue", value); //需回显的值
  1943. axios
  1944. .post(props.url, sendParams, {
  1945. headers: {
  1946. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  1947. },
  1948. })
  1949. .then((response) => {
  1950. // alert(JSON.stringify(response.data));
  1951. if ("timeout" == response.data.statusText) {
  1952. alert("网络超时!");
  1953. return;
  1954. }
  1955. if (response.data.result) {
  1956. const keys = Object.keys(response.data.result);
  1957. console.log(
  1958. "name:" +
  1959. props.name +
  1960. ",@@级联初始化默认值value:" +
  1961. value +
  1962. "--param:" +
  1963. JSON.stringify(param) +
  1964. "--objectPickerParamStr:" +
  1965. objectPickerParamStr +
  1966. "--response.data:" +
  1967. JSON.stringify(response.data)
  1968. );
  1969. if (keys.length === 1) {
  1970. let code = keys[0];
  1971. let desc = response.data.result[keys[0]];
  1972. if (props.opt)
  1973. props.opt.length = 0; //通过修改数组的length属性,直接清空数组元素,内存会被自动释放。这是性能最优的方式
  1974. else {
  1975. props.opt = [];
  1976. }
  1977. props.opt.push({ label: desc, value: code });
  1978. if (value) matchAndSelect(value);
  1979. console.log(
  1980. "GOOD mode2回显的默认值:" +
  1981. JSON.stringify({ label: desc, value: code }) +
  1982. "--props.param:" +
  1983. JSON.stringify(param)
  1984. );
  1985. // updateSelectItem();
  1986. // alert('props.opt:'+JSON.stringify(props.opt));
  1987. }
  1988. }
  1989. });
  1990. }
  1991. } catch (error) {
  1992. alert(error);
  1993. // callback(null, error.message); // 失败回调,传递错误
  1994. }
  1995. // 重置自动回显标记
  1996. isAutoEcho.value = false;
  1997. }
  1998. // 初始化级联菜单在页面刚打开时的默认值
  1999. initDefaultValue(props.modelValue, needInitParam);
  2000. //设置mode2的下级下拉菜单的上级菜单当前值
  2001. setNextSelectUpperValue();
  2002. }
  2003. //选中要回显的默认值
  2004. const matchAndSelect = (value) => {
  2005. const matchedOption = props.opt.find((opt) => opt.value === value);
  2006. if (matchedOption) {
  2007. selectItem.value = matchedOption;
  2008. emit("update:modelValue", value);
  2009. emit("change", value);
  2010. }
  2011. };
  2012. // 计算弹出方向和最大高度的方法 by xu 20251212
  2013. // 当空间不足时限制popup高度并显示滚动条
  2014. const calculatePopupDirection = () => {
  2015. // 1. 获取select容器元素
  2016. const selectEl = document.querySelector(
  2017. `[name="${props.name}"]`
  2018. )?.nextElementSibling;
  2019. console.log("selectEl:" + selectEl, props.name);
  2020. if (!selectEl) return;
  2021. // 2. 获取位置信息
  2022. const selectRect = selectEl.getBoundingClientRect();
  2023. const viewportHeight = window.innerHeight;
  2024. // 3. 计算上下可用空间 by xu 20251212
  2025. const spaceBelow = viewportHeight - selectRect.bottom - 10; // 减10px留边距
  2026. const spaceAbove = selectRect.top - 10; // 减10px留边距
  2027. // 4. popup预估高度(假设每项36px,最多显示8项 + padding)
  2028. const estimatedPopupHeight = 300;
  2029. const minPopupHeight = 100; // 最小高度
  2030. console.log(
  2031. "[popup] 空间计算 - spaceAbove:",
  2032. spaceAbove,
  2033. "spaceBelow:",
  2034. spaceBelow,
  2035. "estimatedHeight:",
  2036. estimatedPopupHeight
  2037. );
  2038. // 5. 判断方向和最大高度 by xu 20251212
  2039. if (spaceBelow >= estimatedPopupHeight) {
  2040. // 下方空间足够,向下展开,不限制高度
  2041. popupDirection.value = "bottom";
  2042. popupMaxHeight.value = "none";
  2043. console.log("[popup] 向下展开,空间充足");
  2044. } else if (spaceAbove >= estimatedPopupHeight) {
  2045. // 上方空间足够,向上展开,不限制高度
  2046. popupDirection.value = "top";
  2047. popupMaxHeight.value = "none";
  2048. console.log("[popup] 向上展开,空间充足");
  2049. } else {
  2050. // 上下空间都不足,选择空间大的方向,并限制高度出滚动条
  2051. if (spaceBelow >= spaceAbove) {
  2052. popupDirection.value = "bottom";
  2053. popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px";
  2054. console.log(
  2055. "[popup] 向下展开,空间不足,限制高度:",
  2056. popupMaxHeight.value
  2057. );
  2058. } else {
  2059. popupDirection.value = "top";
  2060. popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px";
  2061. console.log(
  2062. "[popup] 向上展开,空间不足,限制高度:",
  2063. popupMaxHeight.value
  2064. );
  2065. }
  2066. }
  2067. };
  2068. //级联菜单点击事件
  2069. const togglePopup = () => {
  2070. if (!popupWinVisible.value) {
  2071. //如果当前下拉菜单是隐藏的,先ajax重新加载下拉菜单项,再显示。
  2072. showPopup();
  2073. } else {
  2074. hidePopup();
  2075. }
  2076. };
  2077. //显示下拉菜单,在此之前先清除下拉菜单项
  2078. const showPopup = () => {
  2079. //清空下拉菜单,并设置第一项的值为空
  2080. clearAndInit1stOpt();
  2081. Vue.nextTick(() => {
  2082. calculatePopupDirection();
  2083. });
  2084. let url = props.url;
  2085. let filterObj = props.param.filter;
  2086. if (filterObj) {
  2087. for (let k in filterObj) {
  2088. let v = filterObj[k];
  2089. url += "&" + k + "=" + v;
  2090. }
  2091. }
  2092. if (props.mode === "1") {
  2093. //如果是有隐藏字段的下拉菜单
  2094. console.log("666url:" + url);
  2095. // alert('url:'+url);
  2096. // 获取级联菜单所有下拉菜单项
  2097. async function getSelectItems(value) {
  2098. try {
  2099. // alert(1);
  2100. if (props.url && props.param) {
  2101. // alert(2);
  2102. /**
  2103. * param={"objectpickerparam":"{\"input\":\"false\",\"cascadingLevel\":\"hksheng,hkshi,hkxian\"," +
  2104. * "\"name\":\"hksheng\",\"cascadingName\":\"dq\"," +
  2105. * "\"cascadingInputsName\":\"hkdqm\",\"codebook\":\"sheng\"}",
  2106. * "objectpickertype":1,//2表示获取要回显的一项,1表示获取所有下拉菜单项
  2107. * "upperValue":"440000"
  2108. * };
  2109. */
  2110. const objectPickerParam = {
  2111. input: "false",
  2112. cascadingLevel: props.param.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2113. name: props.name, //本下拉菜单名
  2114. cascadingName: props.param.name, //级联菜单名
  2115. cascadingInputsName: props.param.combField, //对象属性,即隐藏字段名,如:hkdqm
  2116. codebook: props.param.codebook,
  2117. };
  2118. console.log("mode1 upperValue.value:" + upperValue.value);
  2119. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2120. const params = new URLSearchParams();
  2121. params.append("objectpickerparam", objectPickerParamStr);
  2122. params.append("objectpickertype", "1");
  2123. if (upperValue.value) {
  2124. params.append("upperValue", upperValue.value);
  2125. }
  2126. // params.append('objectpickervalue', value); //需回显的值
  2127. axios
  2128. .post(url, params, {
  2129. headers: {
  2130. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2131. },
  2132. })
  2133. .then((response) => {
  2134. if ("timeout" == response.data.statusText) {
  2135. alert("网络超时!");
  2136. return;
  2137. }
  2138. if (response.data.result) {
  2139. const keys = Object.keys(response.data.result);
  2140. console.log(
  2141. "params:" +
  2142. params +
  2143. "@@response.data:" +
  2144. JSON.stringify(response.data)
  2145. );
  2146. if (keys.length > 0) {
  2147. for (let k in response.data.result) {
  2148. props.opt.push({
  2149. label: response.data.result[k],
  2150. value: k,
  2151. });
  2152. }
  2153. console.log("props.opt11:" + JSON.stringify(props.opt));
  2154. } else {
  2155. // 没有数据时打印日志 by xu 20251212
  2156. console.log("[ccp mode1] 接口返回空数据");
  2157. }
  2158. } else {
  2159. // result不存在时打印日志 by xu 20251212
  2160. console.log("[ccp mode1] 接口返回无result");
  2161. }
  2162. // 无论是否有数据,都显示popup by xu 20251212
  2163. if (!popupWinVisible.value) {
  2164. popupWinVisible.value = true;
  2165. }
  2166. });
  2167. }
  2168. } catch (error) {
  2169. alert(error);
  2170. // callback(null, error.message); // 失败回调,传递错误
  2171. }
  2172. }
  2173. getSelectItems(props.modelValue);
  2174. } else if (props.mode === "2") {
  2175. //没隐藏字段的下拉菜单
  2176. let needInitParam = undefined;
  2177. if (Array.isArray(props.param)) {
  2178. needInitParam = props.param[props.param.length - 1]; //只初始化数组最后一项
  2179. console.log(
  2180. "needInitParam最后一项:" + JSON.stringify(needInitParam)
  2181. );
  2182. } else {
  2183. needInitParam = props.param;
  2184. }
  2185. // 获取级联菜单所有下拉菜单项
  2186. async function getSelectItems(value, sendParam) {
  2187. try {
  2188. // alert(1);
  2189. if (props.url && sendParam) {
  2190. // alert(2);
  2191. /**
  2192. * param="{\"input\":\"false\",\"cascadingLevel\":\"dwid,sjryid\",
  2193. * \"ryid\":\"111121\",\"name\":\"sjryid\",
  2194. * \"cascadingName\":\"dw_sjry\",\"codebook\":\"sjryByDw\"}"
  2195. */
  2196. const objectPickerParam = {
  2197. input: "false",
  2198. cascadingLevel: sendParam.fieldOrd.join(","), //如:"hksheng,hkshi,hkxian"
  2199. name: props.name, //本下拉菜单名
  2200. cascadingName: sendParam.name, //级联菜单名
  2201. codebook: sendParam.codebook,
  2202. };
  2203. console.log("mode2 upperValue.value:" + upperValue.value);
  2204. const objectPickerParamStr = JSON.stringify(objectPickerParam);
  2205. const params = new URLSearchParams();
  2206. params.append("objectpickerparam", objectPickerParamStr);
  2207. params.append("objectpickertype", "1");
  2208. if (upperValue.value) {
  2209. params.append("upperValue", upperValue.value);
  2210. }
  2211. // params.append('objectpickervalue', value); //需回显的值
  2212. axios
  2213. .post(url, params, {
  2214. headers: {
  2215. "Content-Type": "application/x-www-form-urlencoded", // 必须手动设置!
  2216. },
  2217. })
  2218. .then((response) => {
  2219. if ("timeout" == response.data.statusText) {
  2220. alert("网络超时!");
  2221. return;
  2222. }
  2223. if (response.data.result) {
  2224. const keys = Object.keys(response.data.result);
  2225. console.log(
  2226. "params:" +
  2227. params +
  2228. "@@response.data:" +
  2229. JSON.stringify(response.data)
  2230. );
  2231. if (keys.length > 0) {
  2232. for (let k in response.data.result) {
  2233. props.opt.push({
  2234. label: response.data.result[k],
  2235. value: k,
  2236. });
  2237. }
  2238. console.log("props.opt11:" + JSON.stringify(props.opt));
  2239. } else {
  2240. // 没有数据时打印日志 by xu 20251212
  2241. console.log("[ccp mode2] 接口返回空数据");
  2242. }
  2243. } else {
  2244. // result不存在时打印日志 by xu 20251212
  2245. console.log("[ccp mode2] 接口返回无result");
  2246. }
  2247. // 无论是否有数据,都显示popup by xu 20251212
  2248. if (!popupWinVisible.value) {
  2249. popupWinVisible.value = true;
  2250. }
  2251. });
  2252. }
  2253. } catch (error) {
  2254. alert(error);
  2255. // callback(null, error.message); // 失败回调,传递错误
  2256. }
  2257. }
  2258. getSelectItems(props.modelValue, needInitParam);
  2259. // popupWinVisible.value = !popupWinVisible.value;
  2260. }
  2261. };
  2262. const hidePopup = () => {
  2263. popupWinVisible.value = false;
  2264. };
  2265. // 合并所有的 onMounted 逻辑
  2266. Vue.onMounted(() => {
  2267. window.addEventListener("resize", calculatePopupDirection);
  2268. // 1. 监听展开下一级事件
  2269. window.addEventListener("open-next-cascader", (event) => {
  2270. const { name, level } = event.detail;
  2271. if (name === props.name && level === props.level) {
  2272. popupWinVisible.value = true;
  2273. }
  2274. });
  2275. // 2. 监听级联事件
  2276. window.addEventListener("cascader-change", (event) => {
  2277. const { name, level, value } = event.detail;
  2278. if (name === props.name && level < props.level) {
  2279. selectItem.value = { label: "", value: "" };
  2280. emit("update:modelValue", "");
  2281. if (ssHidden) {
  2282. ssHidden.updateValue(value);
  2283. }
  2284. }
  2285. });
  2286. });
  2287. Vue.onUnmounted(() => {
  2288. window.removeEventListener("resize", calculatePopupDirection);
  2289. });
  2290. // 监听值变化,处理回显 (mode 2)
  2291. Vue.watch(
  2292. () => props.modelValue,
  2293. (newVal) => {
  2294. if (props.mode === "2" && newVal) {
  2295. // 使用 watchEffect 替代嵌套的 watch
  2296. Vue.watchEffect(() => {
  2297. if (props.opt.length > 0) {
  2298. const matchedOption = props.opt.find(
  2299. (opt) => opt.value === newVal
  2300. );
  2301. if (matchedOption) {
  2302. selectItem.value = matchedOption;
  2303. }
  2304. }
  2305. });
  2306. } else {
  2307. // 原有的值变化处理
  2308. const item = props.opt.find((it) => it.value === newVal);
  2309. if (item) {
  2310. selectItem.value = item;
  2311. } else {
  2312. selectItem.value = { label: "", value: "" };
  2313. }
  2314. }
  2315. },
  2316. { immediate: true }
  2317. );
  2318. // 监听选项变化,当数据加载完成时进行匹配
  2319. Vue.watch(
  2320. () => props.opt,
  2321. (newOptions) => {
  2322. if (newOptions.length > 0) {
  2323. const matchedOption = newOptions.find(
  2324. (opt) => opt.value === selectItem.value.value
  2325. );
  2326. if (matchedOption) {
  2327. selectItem.value = matchedOption;
  2328. emit("update:modelValue", matchedOption.value);
  2329. emit("change", matchedOption.value);
  2330. }
  2331. }
  2332. }
  2333. );
  2334. return {
  2335. selectItem,
  2336. popupWinVisible,
  2337. popupDirection,
  2338. popupMaxHeight, // 添加popup最大高度 by xu 20251212
  2339. togglePopup,
  2340. hidePopup,
  2341. doSelectItem,
  2342. };
  2343. },
  2344. template: `
  2345. <div class="input ss-ccp-container" style="position: relative" :style="{width: width}">
  2346. <input type="hidden" :name="name" :value="modelValue">
  2347. <div class="select-container" @mouseleave="hidePopup">
  2348. <div class="input" @click="togglePopup">
  2349. <input
  2350. type="hidden"
  2351. :name="name"
  2352. :value="selectItem.value"
  2353. />
  2354. <input
  2355. :placeholder="placeholder"
  2356. :value="selectItem.label"
  2357. disabled
  2358. style="pointer-events: none;"
  2359. />
  2360. <div class="suffix">
  2361. <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
  2362. </div>
  2363. </div>
  2364. <!-- popup弹出层,添加maxHeight和overflowY支持空间不足时滚动 by xu 20251212 -->
  2365. <div v-show="popupWinVisible" class="popup-win " :class="popupDirection" :style="{ maxHeight: popupMaxHeight, overflowY: popupMaxHeight !== 'none' ? 'auto' : 'visible' }">
  2366. <div v-if="opt && opt.length > 0" class="popup-content">
  2367. <div class="content-area">
  2368. <div
  2369. v-for="(item, index) in opt"
  2370. :key="index"
  2371. @click="doSelectItem(item)"
  2372. :class="{ active: item.value === selectItem.value }"
  2373. >
  2374. <span class="check-icon">
  2375. <ss-form-icon class="form-icon-select-checked" />
  2376. </span>
  2377. <span>{{ item.label }}</span>
  2378. </div>
  2379. </div>
  2380. </div>
  2381. <div v-else class="popup-content">
  2382. <div class="content-area">
  2383. <div class="content-area">
  2384. <span>无选项</span>
  2385. </div>
  2386. </div>
  2387. </div>
  2388. </div>
  2389. </div>
  2390. </div>
  2391. `,
  2392. };
  2393. // ss-date-picker 日期时间选择器组件
  2394. const SsDatePicker = {
  2395. name: "SsDatePicker",
  2396. props: {
  2397. modelValue: {
  2398. type: [String, Number, Date],
  2399. default: "",
  2400. },
  2401. name: {
  2402. type: String,
  2403. required: true,
  2404. },
  2405. type: {
  2406. type: String,
  2407. default: "date",
  2408. validator: (value) => ["date", "datetime", "time"].includes(value),
  2409. },
  2410. fmt: {
  2411. type: String,
  2412. default: null,
  2413. },
  2414. placeholder: {
  2415. type: String,
  2416. default: "",
  2417. },
  2418. width: {
  2419. type: String,
  2420. default: "100%",
  2421. },
  2422. },
  2423. emits: ["update:modelValue"],
  2424. setup(props, { emit }) {
  2425. const errMsg = ref("");
  2426. const validate = () => {
  2427. if (window.ssVm) {
  2428. const result = window.ssVm.validateField(props.name);
  2429. console.log("validate", window.ssVm.validateField(props.name));
  2430. errMsg.value = result.valid ? "" : result.message;
  2431. }
  2432. };
  2433. // 根据type确定默认格式
  2434. const defaultFormat = computed(() => {
  2435. switch (props.type) {
  2436. case "datetime":
  2437. return "YYYY-MM-DD HH:mm:ss";
  2438. case "date":
  2439. return "YYYY-MM-DD";
  2440. case "time":
  2441. return "HH:mm:ss";
  2442. }
  2443. });
  2444. const convertJavaFormatToElement = (javaFormat) => {
  2445. if (!javaFormat) return null;
  2446. return javaFormat
  2447. .replace("yyyy", "YYYY")
  2448. .replace("MM", "MM")
  2449. .replace("dd", "DD")
  2450. .replace("HH", "HH")
  2451. .replace("mm", "mm")
  2452. .replace("ss", "ss");
  2453. };
  2454. const finalFormat = computed(() => {
  2455. if (props.fmt) {
  2456. return convertJavaFormatToElement(props.fmt);
  2457. }
  2458. return defaultFormat.value;
  2459. });
  2460. // 使用 resolveComponent 获取组件
  2461. const ElDatePicker = resolveComponent("ElDatePicker");
  2462. const ElTimePicker = resolveComponent("ElTimePicker");
  2463. const SsFormIcon = resolveComponent("SsFormIcon");
  2464. const ElIcon = resolveComponent("ElIcon");
  2465. const handleValueUpdate = (val) => {
  2466. emit("update:modelValue", val);
  2467. emit("change", val); // 同时触发 change 事件
  2468. setTimeout(() => {
  2469. validate();
  2470. }, 50);
  2471. };
  2472. const dateType = computed(() => {
  2473. const fmt = props.fmt || "";
  2474. if (fmt.includes("HH:mm:ss")) {
  2475. return "datetime";
  2476. } else if (fmt.includes("HH:mm")) {
  2477. return "datetime";
  2478. } else if (fmt.includes("mm:ss")) {
  2479. return "time";
  2480. }
  2481. return "date";
  2482. });
  2483. let useTimePicker = true;
  2484. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  2485. if (props.fmt) {
  2486. //有fmt属性,则以fmt属性优先判断类型
  2487. if (/[dMy]/.test(props.fmt)) {
  2488. //如果有传入日期格式,且含年月日
  2489. useTimePicker = false;
  2490. } else {
  2491. useTimePicker = true;
  2492. }
  2493. } else if (props.type !== "time") {
  2494. useTimePicker = false;
  2495. }
  2496. return () =>
  2497. h("div", { class: "ss-date-picker", style: { width: props.width } }, [
  2498. h("input", {
  2499. type: "hidden",
  2500. name: props.name,
  2501. value: props.modelValue,
  2502. }),
  2503. // 选择组件
  2504. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  2505. modelValue: props.modelValue,
  2506. "onUpdate:modelValue": handleValueUpdate,
  2507. type: dateType.value,
  2508. format: finalFormat.value,
  2509. "value-format": finalFormat.value,
  2510. clearable: true,
  2511. placeholder: props.placeholder,
  2512. class: "custom-date-picker", // 用于自定义样式
  2513. "time-arrow-control": props.type === "datetime", // 修改这里
  2514. size: "large", // 添加这一行,改为 large 尺寸
  2515. style: { width: "100%" },
  2516. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  2517. }),
  2518. ]);
  2519. },
  2520. };
  2521. // ss-icon 图标
  2522. // v3.0 增加 class 属性分支:有 class 走新逻辑,否则走 v1.0 逻辑 by xu 20251212
  2523. // v3.0 用法: <ss-icon class="icon-obj-ry menu-icon" />
  2524. // v1.0 用法: <ss-icon name="setting" size="20px" />
  2525. const SsIcon = {
  2526. name: "SsIcon",
  2527. // v3.0 禁用 class 透传,手动处理 by xu 20251215
  2528. inheritAttrs: false,
  2529. props: {
  2530. // v1.0: 以下为旧属性
  2531. name: { type: String },
  2532. size: { type: [Number, String], default: 16 },
  2533. unit: { type: String, default: "px" },
  2534. color: String,
  2535. type: {
  2536. type: String,
  2537. default: ssIcon.name,
  2538. validator: function (value) {
  2539. return [ssIcon, commonIcon].some((icon) => icon.name === value);
  2540. },
  2541. },
  2542. },
  2543. emits: ["update:modelValue", "input", "blur", "change"],
  2544. setup(props, { emit, attrs }) {
  2545. // v3.0 分支:有 class 属性时直接渲染(从 attrs 获取) by xu 20251215
  2546. if (attrs.class) {
  2547. return () =>
  2548. h("i", { ...attrs, class: attrs.class + " icon-container" });
  2549. }
  2550. // v1.0 分支:原有逻辑
  2551. const useIconType = computed(() => {
  2552. return [ssIcon, commonIcon].find(
  2553. (iconConfig) => iconConfig.name === props.type
  2554. );
  2555. });
  2556. const iconName = computed(() => {
  2557. const iconConfig = useIconType.value; // 注意:使用 .value 来访问响应式引用的值
  2558. if (!iconConfig) {
  2559. console.error(`Icon type "${props.type}" not found.`);
  2560. return "";
  2561. }
  2562. const iconType = iconConfig.types[props.name];
  2563. if (!iconType) {
  2564. console.error(
  2565. `Icon name "${props.name}" not found in type "${props.type}".`
  2566. );
  2567. return "";
  2568. }
  2569. return `${iconConfig.prefix}${iconType}`;
  2570. });
  2571. // 类似地,你可以计算 fontFamily 和 style
  2572. const fontFamily = computed(() => {
  2573. return useIconType.value ? useIconType.value.family : "";
  2574. });
  2575. // console.log(iconName.value,fontFamily.value)
  2576. const style = computed(() => {
  2577. const sizeStyle = isNum(props.size)
  2578. ? `${props.size}${props.unit}`
  2579. : props.size;
  2580. const styleObj = {
  2581. fontSize: sizeStyle,
  2582. color: props.color || "",
  2583. };
  2584. return toStyleStr(styleObj);
  2585. });
  2586. // 使用渲染函数定义模板逻辑
  2587. return () =>
  2588. h("i", {
  2589. class: ["icon-container", iconName.value, fontFamily.value],
  2590. style: style.value,
  2591. });
  2592. },
  2593. };
  2594. // 通用icon
  2595. const SsCommonIcon = {
  2596. name: "SsCommonIcon",
  2597. props: {
  2598. class: {
  2599. type: String,
  2600. required: true,
  2601. },
  2602. },
  2603. setup(props) {
  2604. return () =>
  2605. h("i", {
  2606. class: props.class + " common-icon",
  2607. });
  2608. },
  2609. };
  2610. // 登录页icon
  2611. const SsLoginIcon = {
  2612. name: "SsLoginIcon",
  2613. props: {
  2614. class: {
  2615. type: String,
  2616. required: true,
  2617. },
  2618. },
  2619. setup(props) {
  2620. return () =>
  2621. h("div", {
  2622. class: props.class + " login-icon",
  2623. });
  2624. },
  2625. };
  2626. // 弹窗icon
  2627. const SsDialogIcon = {
  2628. name: "SsDialogIcon",
  2629. props: {
  2630. class: {
  2631. type: String,
  2632. required: true,
  2633. },
  2634. },
  2635. setup(props) {
  2636. return () =>
  2637. h("i", {
  2638. class: props.class + " dialog-icon",
  2639. });
  2640. },
  2641. };
  2642. // 全局左侧导航图标组件
  2643. const SsNavIcon = {
  2644. name: "SsNavIcon",
  2645. props: {
  2646. class: {
  2647. type: String,
  2648. required: true,
  2649. },
  2650. },
  2651. setup(props) {
  2652. return () =>
  2653. h("div", {
  2654. class: props.class + " nav-icon",
  2655. });
  2656. },
  2657. };
  2658. // 顶部工具栏图标组件
  2659. const SsHeaderIcon = {
  2660. name: "SsHeaderIcon",
  2661. props: {
  2662. class: {
  2663. type: String,
  2664. required: true,
  2665. },
  2666. },
  2667. setup(props) {
  2668. return () =>
  2669. h("div", {
  2670. class: props.class + " header-icon",
  2671. });
  2672. },
  2673. };
  2674. // 全局菜单图标组件
  2675. const SsGolbalMenuIcon = {
  2676. name: "SsGolbalMenuIcon",
  2677. props: {
  2678. class: {
  2679. type: String,
  2680. required: true,
  2681. },
  2682. },
  2683. setup(props) {
  2684. return () =>
  2685. h("div", {
  2686. class: props.class + " global-menu-icon",
  2687. });
  2688. },
  2689. };
  2690. // 全局查询列表卡片图标
  2691. const SsCartListIcon = {
  2692. name: "SsCartListIcon",
  2693. props: {
  2694. class: {
  2695. type: String,
  2696. required: true,
  2697. },
  2698. },
  2699. setup(props) {
  2700. return () =>
  2701. h("div", {
  2702. class: props.class + " cart-list-icon",
  2703. });
  2704. },
  2705. };
  2706. // 全局底部工具栏图标组件
  2707. const SsQuickIcon = {
  2708. name: "SsQuickIcon",
  2709. props: {
  2710. class: {
  2711. type: String,
  2712. required: true,
  2713. },
  2714. },
  2715. setup(props) {
  2716. return () =>
  2717. h("div", {
  2718. class: props.class + " quick-icon",
  2719. });
  2720. },
  2721. };
  2722. // 表单组件icon
  2723. const SsFormIcon = {
  2724. name: "SsFormIcon",
  2725. props: {
  2726. class: {
  2727. type: String,
  2728. required: true,
  2729. },
  2730. },
  2731. setup(props) {
  2732. return () =>
  2733. h("div", {
  2734. class: props.class + " form-icon",
  2735. });
  2736. },
  2737. };
  2738. // 弹窗底部按钮icon
  2739. const SsBottomDivIcon = {
  2740. name: "SsBottomDivIcon",
  2741. props: {
  2742. class: {
  2743. type: String,
  2744. required: true,
  2745. },
  2746. },
  2747. setup(props) {
  2748. return () =>
  2749. h("div", {
  2750. class: props.class + " bottom-div-icon",
  2751. });
  2752. },
  2753. };
  2754. // editor组件icon
  2755. const SsEditorIcon = {
  2756. name: "SsEditorIcon",
  2757. props: {
  2758. class: {
  2759. type: String,
  2760. required: true,
  2761. },
  2762. },
  2763. setup(props) {
  2764. return () =>
  2765. h("i", {
  2766. class: props.class + " editor-icon",
  2767. });
  2768. },
  2769. };
  2770. // ss-validate校验器
  2771. const SsValidate = {
  2772. name: "SsValidate",
  2773. props: {
  2774. errMsg: { type: String },
  2775. textAlign: { type: String, default: "left" },
  2776. style: { type: Object, default: () => ({}) },
  2777. },
  2778. template: `<div class="validate-vline"></div>
  2779. <div class="validate-tip" :style="style">
  2780. <div class="tip" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  2781. <div class="tip-more" :style="{ textAlign: textAlign }">{{ errMsg }}</div>
  2782. </div>`,
  2783. };
  2784. // ss-onoff-array 多选按钮 数组形式
  2785. const SsonoffArray = {
  2786. name: "SsonoffArray",
  2787. props: {
  2788. name: {
  2789. type: String,
  2790. required: true,
  2791. },
  2792. opt: {
  2793. type: Array,
  2794. default: () => [],
  2795. },
  2796. defaultValue: [String, Number, Array],
  2797. modelValue: [String, Number, Array],
  2798. multiple: {
  2799. // 新增多选模式属性
  2800. type: Boolean,
  2801. default: false,
  2802. },
  2803. // 是否允许一项都不选,默认true允许 by xu 20251212
  2804. null: {
  2805. type: Boolean,
  2806. default: true,
  2807. },
  2808. },
  2809. emits: ["update:modelValue"], // 允许更新 v-model 绑定的值
  2810. setup(props, { emit }) {
  2811. console.log("多选按钮", props.opt);
  2812. // 使用数组来存储选中值
  2813. const checkedValue = ref(
  2814. props.multiple
  2815. ? Array.isArray(props.defaultValue)
  2816. ? props.defaultValue
  2817. : []
  2818. : props.defaultValue
  2819. );
  2820. const errMsg = ref(props.errTip);
  2821. // 生成icon名字
  2822. const genIconName = (itemValue) => {
  2823. if (props.multiple) {
  2824. return checkedValue.value.includes(itemValue)
  2825. ? "form-icon-onoff-checked"
  2826. : "form-icon-onoff-unchecked";
  2827. }
  2828. return checkedValue.value === itemValue
  2829. ? "form-icon-onoff-checked"
  2830. : "form-icon-onoff-unchecked";
  2831. };
  2832. // 选中项
  2833. const selectItem = (value) => {
  2834. if (props.multiple) {
  2835. // 多选模式
  2836. const index = checkedValue.value.indexOf(value);
  2837. if (index === -1) {
  2838. checkedValue.value = [...checkedValue.value, value];
  2839. } else {
  2840. // 取消选中当前项
  2841. const newValue = checkedValue.value.filter((v) => v !== value);
  2842. // 如果不允许为空且取消后为空,则阻止取消操作 by xu 20251212
  2843. if (!props.null && newValue.length === 0) {
  2844. return; // 阻止取消最后一项
  2845. }
  2846. checkedValue.value = newValue;
  2847. }
  2848. } else {
  2849. // 单选模式
  2850. // 如果点击的是当前已选中的项,判断是否允许取消 by xu 20251212
  2851. if (checkedValue.value === value) {
  2852. if (!props.null) {
  2853. return; // 不允许为空时,阻止取消
  2854. }
  2855. checkedValue.value = ""; // 允许为空时,取消选中
  2856. } else {
  2857. checkedValue.value = value;
  2858. }
  2859. }
  2860. emit("update:modelValue", checkedValue.value);
  2861. nextTick(() => {
  2862. // 触发验证
  2863. if (window.ssVm) {
  2864. window.ssVm.validateField(props.name);
  2865. }
  2866. });
  2867. };
  2868. return { checkedValue, genIconName, selectItem };
  2869. },
  2870. // 使用渲染函数定义模板逻辑
  2871. render() {
  2872. const SsFormIcon = resolveComponent("ss-form-icon");
  2873. return h("div", { class: "radio-container" }, [
  2874. // 根据情况创建 input
  2875. this.multiple
  2876. ? this.checkedValue.length
  2877. ? // 多选且有选中值:为选中项创建 input
  2878. this.checkedValue.map((value) =>
  2879. h("input", {
  2880. type: "checkbox",
  2881. name: this.name,
  2882. value: value,
  2883. checked: true,
  2884. style: { display: "none" },
  2885. })
  2886. )
  2887. : // 多选但没有选中值:创建一个空值 input
  2888. h("input", {
  2889. type: "hidden",
  2890. name: this.name,
  2891. value: "",
  2892. })
  2893. : // 单选模式:创建一个 input
  2894. h("input", {
  2895. type: "hidden",
  2896. name: this.name,
  2897. value: this.checkedValue || "",
  2898. }),
  2899. this.opt.map((item, i) =>
  2900. h(
  2901. "div",
  2902. {
  2903. key: i,
  2904. class: {
  2905. checked: this.multiple
  2906. ? this.checkedValue.includes(item.value)
  2907. : this.checkedValue === item.value,
  2908. },
  2909. style: { width: item.width },
  2910. onClick: () => this.selectItem(item.value),
  2911. },
  2912. [
  2913. h("span", null, item.label),
  2914. h("div", { class: "mark" }, [
  2915. h(SsFormIcon, {
  2916. class: this.genIconName(item.value),
  2917. }),
  2918. ]),
  2919. ]
  2920. )
  2921. ),
  2922. ]);
  2923. },
  2924. };
  2925. // ss-onoff 一个按钮
  2926. const Ssonoff = {
  2927. name: "Ssonoff",
  2928. props: {
  2929. name: {
  2930. type: String,
  2931. required: true,
  2932. },
  2933. label: {
  2934. type: String,
  2935. required: true,
  2936. },
  2937. value: {
  2938. type: [String, Number],
  2939. required: true,
  2940. },
  2941. width: {
  2942. type: String,
  2943. default: "",
  2944. },
  2945. onchange: {
  2946. // 在此属性传入 onChange 的 window 全局回调函数,第一参数是当前整组值 by Ben/xu(20260320)
  2947. type: String,
  2948. required: false,
  2949. },
  2950. modelValue: [String, Number, Array],
  2951. multiple: {
  2952. type: Boolean,
  2953. default: false,
  2954. },
  2955. null: {
  2956. type: Boolean,
  2957. default: true,
  2958. },
  2959. },
  2960. emits: ["update:modelValue", "change"],
  2961. setup(props, { emit }) {
  2962. const parseModelValue = (val) => {
  2963. if (Array.isArray(val)) {
  2964. return val
  2965. .map((item) => (item == null ? "" : item.toString()))
  2966. .filter(Boolean);
  2967. }
  2968. if (val == null || val === "") return [];
  2969. // 如果以逗号开头,去掉开头的逗号
  2970. const cleanValue = val.toString().replace(/^,+/, "");
  2971. if (!cleanValue) return [];
  2972. if (cleanValue.includes("|")) {
  2973. return cleanValue.split("|").filter(Boolean);
  2974. }
  2975. if (cleanValue.includes(",")) {
  2976. return cleanValue.split(",").filter(Boolean);
  2977. }
  2978. return [cleanValue];
  2979. };
  2980. const callGlobalOnchg = (groupValue) => {
  2981. if (props.onchange && typeof props.onchange === "string") {
  2982. if (
  2983. typeof window !== "undefined" &&
  2984. window[props.onchange] &&
  2985. typeof window[props.onchange] === "function"
  2986. ) {
  2987. try {
  2988. window[props.onchange](groupValue, props.value, props.label);
  2989. } catch (error) {
  2990. console.error(`调用全局函数 ${props.onchange} 时出错:`, error);
  2991. }
  2992. } else {
  2993. console.warn(`全局函数 ${props.onchange} 未定义或不是一个函数。`);
  2994. }
  2995. }
  2996. };
  2997. // 判断当前按钮是否选中
  2998. const isChecked = computed(() => {
  2999. if (props.multiple) {
  3000. const currentValue = parseModelValue(props.modelValue);
  3001. return currentValue.includes(props.value.toString());
  3002. }
  3003. return props.modelValue + "" === props.value + ""; //强转为字符串类型再比较(改之前是数字类型和字符串类型作比较,永远为false) Ben 20251206
  3004. });
  3005. // 切换选中状态
  3006. const toggleSelect = () => {
  3007. let newModelValue;
  3008. if (props.multiple) {
  3009. const currentValue = parseModelValue(props.modelValue);
  3010. const currentButtonValue = props.value.toString();
  3011. const index = currentValue.indexOf(currentButtonValue);
  3012. let newValue;
  3013. if (index === -1) {
  3014. // 选中当前项
  3015. newValue = [...currentValue, currentButtonValue];
  3016. } else {
  3017. // 取消选中当前项
  3018. const filteredValue = currentValue.filter(
  3019. (value) => value !== currentButtonValue
  3020. );
  3021. // 如果不允许为空且取消后为空,则阻止取消操作
  3022. if (!props.null && filteredValue.length === 0) {
  3023. return; // 阻止取消最后一项
  3024. }
  3025. newValue = filteredValue;
  3026. }
  3027. newModelValue = newValue.join(",");
  3028. } else {
  3029. // 单选模式
  3030. const currentValue = parseModelValue(props.modelValue);
  3031. const isCurrentlySelected = currentValue.includes(
  3032. props.value.toString()
  3033. );
  3034. if (!isCurrentlySelected) {
  3035. // 选中当前项
  3036. newModelValue = props.value;
  3037. } else {
  3038. // 取消选中当前项
  3039. // 如果不允许为空且当前只有这一项被选中,则阻止取消操作
  3040. if (!props.null && currentValue.length === 1) {
  3041. return; // 阻止取消唯一选中项
  3042. }
  3043. newModelValue = "";
  3044. }
  3045. }
  3046. emit("update:modelValue", newModelValue);
  3047. emit("change", newModelValue, props.value, props.label);
  3048. callGlobalOnchg(newModelValue);
  3049. nextTick(() => {
  3050. // 触发验证
  3051. if (window.ssVm) {
  3052. window.ssVm.validateField(props.name);
  3053. }
  3054. });
  3055. };
  3056. return { isChecked, toggleSelect };
  3057. },
  3058. render() {
  3059. const SsFormIcon = resolveComponent("ss-form-icon");
  3060. return h("div", { class: "radio-container2" }, [
  3061. // 隐藏的表单元素
  3062. this.multiple
  3063. ? h("input", {
  3064. type: "hidden",
  3065. name: `${this.name}`, // 多选模式下使用数组形式的 name
  3066. value: this.isChecked ? this.value : "",
  3067. })
  3068. : this.isChecked &&
  3069. h("input", {
  3070. // 只有当前按钮被选中时才创建 input
  3071. type: "hidden",
  3072. name: this.name,
  3073. value: this.value,
  3074. }),
  3075. // 按钮显示
  3076. h(
  3077. "div",
  3078. {
  3079. class: { checked: this.isChecked },
  3080. style: { width: this.width },
  3081. onClick: this.toggleSelect,
  3082. },
  3083. [
  3084. h("span", null, this.label),
  3085. h("div", { class: "mark" }, [
  3086. h(SsFormIcon, {
  3087. class: this.isChecked
  3088. ? "form-icon-onoff-checked"
  3089. : "form-icon-onoff-unchecked",
  3090. }),
  3091. ]),
  3092. ]
  3093. ),
  3094. ]);
  3095. },
  3096. };
  3097. // ss-textarea
  3098. // ss-textarea
  3099. const SsTextarea = {
  3100. name: "SsTextarea",
  3101. props: {
  3102. name: {
  3103. type: String,
  3104. required: true,
  3105. },
  3106. placeholder: {
  3107. type: String,
  3108. default: "请输入",
  3109. },
  3110. defaultValue: [String, Number],
  3111. modelValue: [String, Number],
  3112. },
  3113. emits: ["update:modelValue"],
  3114. setup(props, { emit }) {
  3115. const inputValue = ref(props.modelValue || props.defaultValue || "");
  3116. // 监听 modelValue 变化
  3117. watch(
  3118. () => props.modelValue,
  3119. (newVal) => {
  3120. inputValue.value = newVal;
  3121. }
  3122. );
  3123. // 输入事件处理
  3124. const onInput = (event) => {
  3125. const newValue = event.target.value;
  3126. inputValue.value = newValue;
  3127. emit("update:modelValue", newValue);
  3128. // 触发验证
  3129. if (window.ssVm) {
  3130. window.ssVm.validateField(props.name);
  3131. }
  3132. };
  3133. // 失焦时验证
  3134. const onBlur = () => {
  3135. if (window.ssVm) {
  3136. window.ssVm.validateField(props.name);
  3137. }
  3138. };
  3139. return { inputValue, onInput, onBlur };
  3140. },
  3141. render() {
  3142. return h("div", { class: "textarea-container" }, [
  3143. h("div", { class: "textarea" }, [
  3144. h("input", {
  3145. type: "hidden",
  3146. name: this.name,
  3147. value: this.inputValue || "",
  3148. }),
  3149. h("textarea", {
  3150. placeholder: this.placeholder,
  3151. value: this.inputValue,
  3152. onInput: this.onInput,
  3153. onBlur: this.onBlur,
  3154. }),
  3155. ]),
  3156. ]);
  3157. },
  3158. };
  3159. // ss-editor 富文本编辑器 基于Jodit
  3160. const SsEditor = {
  3161. name: "SsEditor",
  3162. props: {
  3163. modelValue: {
  3164. type: String,
  3165. default: "",
  3166. },
  3167. html: {
  3168. type: String,
  3169. default: "",
  3170. },
  3171. name: {
  3172. type: String,
  3173. default: "",
  3174. },
  3175. url: {
  3176. type: String,
  3177. default: "",
  3178. },
  3179. height: {
  3180. type: [Number, String],
  3181. default: 400,
  3182. },
  3183. placeholder: {
  3184. type: String,
  3185. default: "请输入内容",
  3186. },
  3187. readonly: {
  3188. type: Boolean,
  3189. default: false,
  3190. },
  3191. mode: {
  3192. type: String,
  3193. default: "edit", // 'edit' | 'view'
  3194. },
  3195. uploadUrl: {
  3196. type: String,
  3197. default: "/ulByHttp", //原值为“upload” Ben(20251205)
  3198. },
  3199. param: {
  3200. type: Object,
  3201. default: () => ({}),
  3202. },
  3203. customButtons: {
  3204. type: Array,
  3205. default: () => [],
  3206. },
  3207. },
  3208. emits: ["update:modelValue", "ready", "change"],
  3209. setup(props, { emit }) {
  3210. const editorRef = ref(null);
  3211. const editorContent = ref("");
  3212. const currentModelValue = ref(props.modelValue || "");
  3213. const uniqueId = "editor-" + Date.now();
  3214. const errMsg = Vue.ref("");
  3215. // 计算是否只读:mode='play' 表示只读 by xu 20250402
  3216. const isReadonly = computed(() => props.mode === "play");
  3217. // button 支持对象(旧格式,单个附件按钮)或数组(新格式,多个按钮)by xu 20250331
  3218. const buttonConfigRaw = props.param && props.param.button ? props.param.button : null;
  3219. const buttonArray = Array.isArray(buttonConfigRaw)
  3220. ? buttonConfigRaw
  3221. : buttonConfigRaw
  3222. ? [buttonConfigRaw]
  3223. : [];
  3224. // 找到附件按钮配置(有 cmsAddUrl 的)
  3225. const fjButton = buttonArray.find(btn => btn.cmsAddUrl && btn.cmsUpdUrl) || {};
  3226. const fjid = ref(fjButton.val || null);
  3227. const fjName = fjButton.desc || "附件";
  3228. // 筛选出自定义按钮(有 func 的)
  3229. const customButtonsFromParam = buttonArray.filter(btn => btn.func).map(btn => ({
  3230. name: btn.name,
  3231. text: btn.desc || btn.text,
  3232. tooltip: btn.desc || btn.tooltip,
  3233. icon: btn.icon || 'editor-icon-file',
  3234. onClick: btn.func // 函数名字符串
  3235. }));
  3236. const mode = props.param ? props.param.mode : null;
  3237. const normalizeHtml = (rawHtml) => {
  3238. if (rawHtml == null) {
  3239. return "";
  3240. }
  3241. const html = String(rawHtml).trim();
  3242. if (!html) {
  3243. return "";
  3244. }
  3245. if (
  3246. /<html[\s>]/i.test(html) ||
  3247. /<body[\s>]/i.test(html) ||
  3248. /<!doctype/i.test(html)
  3249. ) {
  3250. try {
  3251. const doc = new DOMParser().parseFromString(html, "text/html");
  3252. if (doc && doc.body) {
  3253. return doc.body.innerHTML || "";
  3254. }
  3255. } catch (e) {
  3256. console.warn("ss-editor 解析完整HTML失败,回退原始内容:", e);
  3257. }
  3258. }
  3259. return html;
  3260. };
  3261. const syncHiddenContentInput = (html) => {
  3262. const contentElements = document.getElementsByName(
  3263. props.name.replace(/wj$/, "") + "Edit"
  3264. );
  3265. if (contentElements.length > 0) {
  3266. contentElements[0].value = html;
  3267. }
  3268. };
  3269. const setEditorHtml = (html) => {
  3270. const normalizedHtml = normalizeHtml(html);
  3271. editorContent.value = normalizedHtml;
  3272. syncHiddenContentInput(normalizedHtml);
  3273. if (editorRef.value && editorRef.value.value !== normalizedHtml) {
  3274. editorRef.value.value = normalizedHtml;
  3275. }
  3276. };
  3277. const resolveWindowFunction = (handlerName) => {
  3278. if (!handlerName || typeof handlerName !== "string") {
  3279. return null;
  3280. }
  3281. return handlerName.split(".").reduce((current, key) => {
  3282. return current && current[key] != null ? current[key] : null;
  3283. }, window);
  3284. };
  3285. const getCustomButtonKey = (button, index) => {
  3286. const baseName =
  3287. (button &&
  3288. (button.key || button.name || button.text || button.tooltip)) ||
  3289. `button${index + 1}`;
  3290. return `ssCustomButton_${String(baseName).replace(
  3291. /[^a-zA-Z0-9_-]/g,
  3292. "_"
  3293. )}_${index}`;
  3294. };
  3295. const normalizeCustomButtons = (buttons = []) => {
  3296. return Array.isArray(buttons)
  3297. ? buttons.filter(Boolean).map((button, index) => ({
  3298. ...button,
  3299. _buttonKey: getCustomButtonKey(button, index),
  3300. }))
  3301. : [];
  3302. };
  3303. const renderButtonIcon = (icon) => {
  3304. if (!icon) {
  3305. return null;
  3306. }
  3307. if (typeof icon === "string" && icon.trim().startsWith("<")) {
  3308. return icon;
  3309. }
  3310. return `<span class="editor-icon ${icon}"></span>`;
  3311. };
  3312. const buildCustomButtonRegistry = (buttons = []) => {
  3313. const controls = {};
  3314. const buttonNames = [];
  3315. const iconMap = {};
  3316. normalizeCustomButtons(buttons).forEach((button) => {
  3317. const buttonKey = button._buttonKey;
  3318. const handler =
  3319. button.onClick ||
  3320. button.click ||
  3321. button.handler ||
  3322. button.exec ||
  3323. null;
  3324. const tooltip =
  3325. button.tooltip ||
  3326. button.text ||
  3327. button.label ||
  3328. button.name ||
  3329. "自定义按钮";
  3330. buttonNames.push(buttonKey);
  3331. if (button.icon) {
  3332. iconMap[buttonKey] = button.icon;
  3333. }
  3334. controls[buttonKey] = {
  3335. name: button.name || buttonKey,
  3336. tooltip,
  3337. exec: function (editor) {
  3338. const context = {
  3339. editor,
  3340. button,
  3341. props,
  3342. value:
  3343. editor && typeof editor.value !== "undefined"
  3344. ? editor.value
  3345. : "",
  3346. setValue: (value) => setEditorHtml(value),
  3347. getValue: () =>
  3348. editor && typeof editor.value !== "undefined"
  3349. ? editor.value
  3350. : "",
  3351. emit,
  3352. currentModelValue: currentModelValue.value,
  3353. fjid: fjid.value,
  3354. };
  3355. if (typeof handler === "function") {
  3356. return handler(context);
  3357. }
  3358. if (typeof handler === "string") {
  3359. const windowHandler = resolveWindowFunction(handler);
  3360. if (typeof windowHandler === "function") {
  3361. return windowHandler(context);
  3362. }
  3363. console.warn("ss-editor 自定义按钮未找到点击事件:", handler);
  3364. return undefined;
  3365. }
  3366. console.warn("ss-editor 自定义按钮缺少点击事件配置:", button);
  3367. return undefined;
  3368. },
  3369. };
  3370. });
  3371. return {
  3372. controls,
  3373. buttonNames,
  3374. iconMap,
  3375. };
  3376. };
  3377. const validate = () => {
  3378. if (window.ssVm) {
  3379. const result = window.ssVm.validateField(props.name);
  3380. console.log("validate", window.ssVm.validateField(props.name));
  3381. errMsg.value = result.valid ? "" : result.message;
  3382. }
  3383. };
  3384. onMounted(() => {
  3385. validate();
  3386. // 只读模式下不初始化 Jodit,直接设置内容 by xu 20250402
  3387. if (isReadonly) {
  3388. if (props.html) {
  3389. setEditorHtml(props.html);
  3390. } else if (props.url) {
  3391. const params = new URLSearchParams();
  3392. if (mode) params.append("mode", mode);
  3393. if (props.modelValue) params.append("path", props.modelValue);
  3394. axios
  3395. .post(props.url, params, {
  3396. headers: {
  3397. "Content-Type": "application/x-www-form-urlencoded",
  3398. },
  3399. })
  3400. .then((response) => {
  3401. if ("timeout" == response.data.statusText) {
  3402. alert("网络超时!");
  3403. return;
  3404. }
  3405. const content = response.data.content;
  3406. if (content != null) {
  3407. setEditorHtml(content);
  3408. }
  3409. const filePath = response.data.path;
  3410. if (filePath) {
  3411. currentModelValue.value = filePath;
  3412. emit("update:modelValue", filePath);
  3413. }
  3414. });
  3415. } else {
  3416. setEditorHtml(props.html);
  3417. }
  3418. return;
  3419. }
  3420. // 如果 prop 为空,尝试从各种来源读取按钮配置
  3421. let buttonsToUse = props.customButtons;
  3422. if (!buttonsToUse || buttonsToUse.length === 0) {
  3423. // 1. 优先从 param.button 数组中筛选(新格式)by xu 20250331
  3424. if (customButtonsFromParam && customButtonsFromParam.length > 0) {
  3425. buttonsToUse = customButtonsFromParam;
  3426. }
  3427. // 2. 尝试从 param.customButtons 读取(旧格式,兼容)
  3428. if (!buttonsToUse || buttonsToUse.length === 0) {
  3429. if (props.param && props.param.customButtons && props.param.customButtons.length > 0) {
  3430. buttonsToUse = props.param.customButtons;
  3431. }
  3432. }
  3433. // 3. 尝试通过桥接 API 读取
  3434. if (!buttonsToUse || buttonsToUse.length === 0) {
  3435. const vm = window.SS.dom.getVueApp({ scope: "chain" });
  3436. if (vm && vm.zwwjCustomButtons) {
  3437. buttonsToUse = vm.zwwjCustomButtons;
  3438. }
  3439. }
  3440. // 4. 从 formElemConfig 读取(兜底)
  3441. if (!buttonsToUse || buttonsToUse.length === 0) {
  3442. const zwwjConfig = window.SS.dom.formElemConfig?.zwwj;
  3443. if (zwwjConfig?.customButtons) {
  3444. buttonsToUse = zwwjConfig.customButtons;
  3445. } else {
  3446. buttonsToUse = window.SS.dom.formElemConfig?.zwwjCustomButtons;
  3447. }
  3448. }
  3449. }
  3450. const {
  3451. controls: customButtonControls,
  3452. buttonNames: customButtonNames,
  3453. iconMap: customButtonIconMap,
  3454. } = buildCustomButtonRegistry(buttonsToUse);
  3455. console.log(
  3456. "[SsEditor] 解析后的按钮:",
  3457. customButtonNames,
  3458. customButtonControls
  3459. );
  3460. const appendCustomButtons = (buttons = []) => {
  3461. if (!customButtonNames.length) {
  3462. return buttons;
  3463. }
  3464. const toolbarButtons = [...buttons];
  3465. const insertIndex = toolbarButtons.includes("dots")
  3466. ? toolbarButtons.indexOf("dots")
  3467. : toolbarButtons.includes("print")
  3468. ? toolbarButtons.indexOf("print")
  3469. : -1;
  3470. if (insertIndex >= 0) {
  3471. toolbarButtons.splice(insertIndex, 0, ...customButtonNames);
  3472. return toolbarButtons;
  3473. }
  3474. return [...toolbarButtons, ...customButtonNames];
  3475. };
  3476. const editor = Jodit.make(`#${uniqueId}`, {
  3477. height: props.height,
  3478. placeholder: props.placeholder,
  3479. readonly: isReadonly,
  3480. language: "zh_cn",
  3481. i18n: {
  3482. zh_cn: {
  3483. Link: "链接",
  3484. URL: "链接",
  3485. "No follow": "无跟踪",
  3486. "Class name": "类名",
  3487. Image: "图片",
  3488. File: "文件",
  3489. "Line height": "行高",
  3490. Alternative: "描述",
  3491. "Alternative text": "描述",
  3492. "Lower Alpha": "小写字母",
  3493. "Upper Alpha": "大写字母",
  3494. "Upper Roman": "大写罗马数字",
  3495. "Lower Roman": "小写罗马数字",
  3496. "Lower Greek": "小写希腊字母",
  3497. "Lower Letter": "小写字母",
  3498. "Upper Letter": "大写字母",
  3499. },
  3500. },
  3501. showXPathInStatusbar: false,
  3502. showCharsCounter: false,
  3503. showWordsCounter: false,
  3504. allowResizeY: false,
  3505. toolbarSticky: false,
  3506. statusbar: false,
  3507. uploader: {
  3508. url: props.uploadUrl,
  3509. format: "json",
  3510. method: "POST",
  3511. filesVariableName: function (i) {
  3512. return "imgs[" + i + "]";
  3513. },
  3514. headers: {
  3515. Accept: "application/json",
  3516. },
  3517. prepareData: function (formData) {
  3518. return formData;
  3519. },
  3520. isSuccess: function (resp) {
  3521. console.log("isSuccess resp:", resp);
  3522. return resp.code === 0;
  3523. },
  3524. getMessage: function (resp) {
  3525. console.log("getMessage resp:", resp);
  3526. return resp.msg || "上传失败";
  3527. },
  3528. process: function (resp) {
  3529. console.log("process resp:", resp);
  3530. return resp.data.url;
  3531. },
  3532. error: function (e) {
  3533. console.error("上传失败:", e.message);
  3534. },
  3535. defaultHandlerSuccess: function (resp) {
  3536. console.log("上传成功:", resp);
  3537. },
  3538. defaultHandlerError: function (err) {
  3539. console.error("上传错误:", err);
  3540. },
  3541. contentType: function () {
  3542. return false;
  3543. },
  3544. },
  3545. controls: {
  3546. font: {
  3547. list: {
  3548. Arial: "Arial",
  3549. SimSun: "宋体",
  3550. SimHei: "黑体",
  3551. "Microsoft YaHei": "微软雅黑",
  3552. KaiTi: "楷体",
  3553. FangSong: "仿宋",
  3554. "Times New Roman": "Times New Roman",
  3555. "Courier New": "Courier New",
  3556. },
  3557. },
  3558. customLinkButton: {
  3559. name: "link",
  3560. tooltip: "附件",
  3561. exec: function () {
  3562. if (!fjButton.cmsAddUrl || !fjButton.cmsUpdUrl) {
  3563. console.warn("ss-editor 未配置附件按钮地址,忽略附件操作");
  3564. return;
  3565. }
  3566. if (fjid.value == null || fjid.value === "") {
  3567. $.ajax({
  3568. type: "post",
  3569. url: fjButton.cmsAddUrl,
  3570. async: false,
  3571. data: {
  3572. name: "fjid",
  3573. ssNrObjName: "sh",
  3574. ssNrObjId: "",
  3575. },
  3576. success: function (_fjid) {
  3577. console.log("cmsAddUrl success", _fjid);
  3578. fjid.value = _fjid;
  3579. },
  3580. });
  3581. }
  3582. var str =
  3583. "&nrid=T-" +
  3584. fjid.value +
  3585. "&objectId=" +
  3586. fjid.value +
  3587. "&objectName=" +
  3588. fjName +
  3589. "&callback=" +
  3590. (window["fjidCallbackName"] || "");
  3591. console.log("str", str);
  3592. SS.openDialog({
  3593. src: buttonConfig.cmsUpdUrl + str,
  3594. headerTitle: "编辑",
  3595. width: 900,
  3596. high: 664,
  3597. zIndex: 51,
  3598. });
  3599. },
  3600. },
  3601. ...customButtonControls,
  3602. },
  3603. toolbarAdaptive: true,
  3604. // 调试:记录最终按钮配置
  3605. buttons: (() => {
  3606. const finalButtons = appendCustomButtons([
  3607. "fullsize",
  3608. "bold",
  3609. "italic",
  3610. "underline",
  3611. "strikethrough",
  3612. "eraser",
  3613. "|",
  3614. "font",
  3615. "fontsize",
  3616. "brush",
  3617. "paragraph",
  3618. "|",
  3619. "left",
  3620. "center",
  3621. "right",
  3622. "justify",
  3623. "|",
  3624. "ul",
  3625. "ol",
  3626. "indent",
  3627. "outdent",
  3628. "|",
  3629. "image",
  3630. "table",
  3631. "customLinkButton",
  3632. "print",
  3633. "|",
  3634. "undo",
  3635. "redo",
  3636. "find",
  3637. ]);
  3638. console.log("[SsEditor] 最终 buttons 配置:", finalButtons);
  3639. return finalButtons;
  3640. })(),
  3641. buttonsMD: appendCustomButtons([
  3642. "fullsize",
  3643. "bold",
  3644. "italic",
  3645. "underline",
  3646. "strikethrough",
  3647. "eraser",
  3648. "|",
  3649. "font",
  3650. "fontsize",
  3651. "brush",
  3652. "paragraph",
  3653. "|",
  3654. "font",
  3655. "fontsize",
  3656. "|",
  3657. "left",
  3658. "center",
  3659. "right",
  3660. "justify",
  3661. "|",
  3662. "image",
  3663. "customLinkButton",
  3664. "|",
  3665. "dots",
  3666. ]),
  3667. buttonsSM: appendCustomButtons([
  3668. "fullsize",
  3669. "bold",
  3670. "italic",
  3671. "|",
  3672. "image",
  3673. "|",
  3674. "dots",
  3675. ]),
  3676. buttonsXS: appendCustomButtons(["fullsize", "bold", "|", "dots"]),
  3677. sizeLG: 1024,
  3678. sizeMD: 768,
  3679. sizeSM: 576,
  3680. getIcon: function (name, clearName) {
  3681. const iconMap = {
  3682. bold: "editor-icon-bold",
  3683. italic: "editor-icon-italic",
  3684. underline: "editor-icon-underline",
  3685. strikethrough: "editor-icon-strikethrough",
  3686. eraser: "editor-icon-eraser",
  3687. copyformat: "editor-icon-copyformat",
  3688. font: "editor-icon-font",
  3689. fontsize: "editor-icon-fontsize",
  3690. brush: "editor-icon-brush",
  3691. paragraph: "editor-icon-paragraph",
  3692. left: "editor-icon-align-left",
  3693. center: "editor-icon-align-center",
  3694. right: "editor-icon-align-right",
  3695. justify: "editor-icon-align-justify",
  3696. ul: "editor-icon-ul",
  3697. ol: "editor-icon-ol",
  3698. indent: "editor-icon-indent",
  3699. outdent: "editor-icon-outdent",
  3700. image: "editor-icon-image",
  3701. file: "editor-icon-file",
  3702. video: "editor-icon-video",
  3703. table: "editor-icon-table",
  3704. link: "editor-icon-link",
  3705. source: "editor-icon-source",
  3706. eye: "editor-icon-preview",
  3707. fullsize: "editor-icon-fullsize",
  3708. shrink: "editor-icon-fullsize-exit",
  3709. print: "editor-icon-print",
  3710. undo: "editor-icon-undo",
  3711. redo: "editor-icon-redo",
  3712. search: "editor-icon-find",
  3713. selectall: "editor-icon-selectall",
  3714. };
  3715. const customIcon =
  3716. customButtonIconMap[clearName] || customButtonIconMap[name];
  3717. if (customIcon) {
  3718. return renderButtonIcon(customIcon);
  3719. }
  3720. const iconClass = iconMap[clearName] || iconMap[name];
  3721. if (iconClass) {
  3722. return renderButtonIcon(iconClass);
  3723. }
  3724. return null;
  3725. },
  3726. });
  3727. editorRef.value = editor;
  3728. editor.events.on("change", () => {
  3729. const html = editor.value || "";
  3730. editorContent.value = html;
  3731. syncHiddenContentInput(html);
  3732. emit("change", html);
  3733. setTimeout(() => {
  3734. validate();
  3735. }, 50);
  3736. });
  3737. emit("ready", editor);
  3738. if (props.html) {
  3739. setEditorHtml(props.html);
  3740. } else if (props.url) {
  3741. const params = new URLSearchParams();
  3742. if (mode) params.append("mode", mode);
  3743. if (props.modelValue) params.append("path", props.modelValue);
  3744. axios
  3745. .post(props.url, params, {
  3746. headers: {
  3747. "Content-Type": "application/x-www-form-urlencoded",
  3748. },
  3749. })
  3750. .then((response) => {
  3751. if ("timeout" == response.data.statusText) {
  3752. alert("网络超时!");
  3753. return;
  3754. }
  3755. const content = response.data.content;
  3756. if (content != null) {
  3757. setEditorHtml(content);
  3758. }
  3759. const filePath = response.data.path;
  3760. if (filePath) {
  3761. currentModelValue.value = filePath;
  3762. emit("update:modelValue", filePath);
  3763. }
  3764. });
  3765. } else {
  3766. setEditorHtml(props.html);
  3767. }
  3768. });
  3769. watch(
  3770. () => props.html,
  3771. (newValue) => {
  3772. setEditorHtml(newValue);
  3773. }
  3774. );
  3775. watch(
  3776. () => props.modelValue,
  3777. (newValue) => {
  3778. currentModelValue.value = newValue || "";
  3779. }
  3780. );
  3781. watch(
  3782. () => props.mode,
  3783. (newMode) => {
  3784. if (editorRef.value) {
  3785. editorRef.value.setReadOnly(newMode === "play");
  3786. }
  3787. }
  3788. );
  3789. // 监听 customButtons 变化,支持运行时动态更新 by xu 20250331
  3790. watch(
  3791. () => props.customButtons,
  3792. (newButtons) => {
  3793. if (!editorRef.value) return;
  3794. if (!newButtons || newButtons.length === 0) return;
  3795. console.log("[SsEditor] customButtons 变化:", newButtons);
  3796. const { controls, buttonNames } = buildCustomButtonRegistry(newButtons);
  3797. if (buttonNames.length === 0) return;
  3798. // 注册新控件到 Jodit
  3799. buttonNames.forEach((btnKey) => {
  3800. const control = controls[btnKey];
  3801. if (control && control.exec) {
  3802. // 使用 Jodit 的 register 方法注册新按钮
  3803. editorRef.value.controls.register(btnKey, control);
  3804. console.log("[SsEditor] 注册新按钮:", btnKey);
  3805. }
  3806. });
  3807. // 更新工具栏(需要重新构建)
  3808. const toolbar = editorRef.value.toolbar;
  3809. if (toolbar && toolbar.build) {
  3810. try {
  3811. // 获取当前配置并重新构建工具栏
  3812. const currentButtons = editorRef.value.options.buttons || [];
  3813. const newToolbarButtons = [...currentButtons, ...buttonNames];
  3814. editorRef.value.options.buttons = newToolbarButtons;
  3815. toolbar.build(newToolbarButtons, toolbar.container);
  3816. console.log("[SsEditor] 工具栏已更新,新按钮:", buttonNames);
  3817. } catch (e) {
  3818. console.warn("[SsEditor] 工具栏更新失败:", e);
  3819. }
  3820. }
  3821. },
  3822. { deep: true, immediate: false }
  3823. );
  3824. onBeforeUnmount(() => {
  3825. if (editorRef.value) {
  3826. editorRef.value.destruct();
  3827. }
  3828. });
  3829. // 只读模式:打开附件弹窗 by xu 20250402
  3830. const openAttachmentDialog = () => {
  3831. if (!fjButton.cmsAddUrl || !fjButton.cmsUpdUrl) {
  3832. console.warn("ss-editor 未配置附件按钮地址,忽略附件操作");
  3833. return;
  3834. }
  3835. if (fjid.value == null || fjid.value === "") {
  3836. $.ajax({
  3837. type: "post",
  3838. url: fjButton.cmsAddUrl,
  3839. async: false,
  3840. data: {
  3841. name: "fjid",
  3842. ssNrObjName: "sh",
  3843. ssNrObjId: "",
  3844. },
  3845. success: function (_fjid) {
  3846. console.log("cmsAddUrl success", _fjid);
  3847. fjid.value = _fjid;
  3848. },
  3849. });
  3850. }
  3851. var str =
  3852. "&nrid=T-" +
  3853. fjid.value +
  3854. "&objectId=" +
  3855. fjid.value +
  3856. "&objectName=" +
  3857. fjName +
  3858. "&callback=" +
  3859. (window["fjidCallbackName"] || "");
  3860. console.log("str", str);
  3861. SS.openDialog({
  3862. src: fjButton.cmsUpdUrl + str,
  3863. headerTitle: "编辑",
  3864. width: 900,
  3865. high: 664,
  3866. zIndex: 51,
  3867. });
  3868. };
  3869. return () => {
  3870. // 只读模式:不初始化 Jodit,直接渲染 HTML + 附件按钮 by xu 20250402
  3871. if (isReadonly) {
  3872. return h("div", { class: "ss-editor-container ss-editor-readonly" }, [
  3873. fjid.value &&
  3874. h("input", {
  3875. type: "hidden",
  3876. name: "fjid",
  3877. value: fjid.value,
  3878. }),
  3879. h("input", {
  3880. type: "hidden",
  3881. name: props.name.replace(/wj$/, "") + "Edit",
  3882. value: editorContent.value,
  3883. }),
  3884. h("input", {
  3885. type: "hidden",
  3886. name: props.name.replace(/wj$/, "") + "wj",
  3887. value: currentModelValue.value,
  3888. }),
  3889. h("input", {
  3890. type: "hidden",
  3891. name: "ueditorpath",
  3892. value: "mswj",
  3893. }),
  3894. // 附件按钮(只读模式下仍显示)
  3895. fjButton.cmsAddUrl && fjButton.cmsUpdUrl &&
  3896. h("div", {
  3897. class: "ss-editor-attach-btn",
  3898. onClick: openAttachmentDialog,
  3899. }, [
  3900. h("span", { class: "editor-icon editor-icon-file" }),
  3901. h("span", { class: "ss-editor-attach-text" }, "附件")
  3902. ]),
  3903. // HTML 内容展示
  3904. h("div", {
  3905. class: "ss-editor-readonly-content",
  3906. innerHTML: editorContent.value,
  3907. }),
  3908. ]);
  3909. }
  3910. // 正常编辑模式:渲染 textarea 供 Jodit 初始化
  3911. return h("div", { class: "ss-editor-container" }, [
  3912. fjid.value &&
  3913. h("input", {
  3914. type: "hidden",
  3915. name: "fjid",
  3916. value: fjid.value,
  3917. }),
  3918. h("input", {
  3919. type: "hidden",
  3920. name: props.name.replace(/wj$/, "") + "Edit",
  3921. value: editorContent.value,
  3922. }),
  3923. h("input", {
  3924. type: "hidden",
  3925. name: props.name.replace(/wj$/, "") + "wj",
  3926. value: currentModelValue.value,
  3927. }),
  3928. h("input", {
  3929. type: "hidden",
  3930. name: "ueditorpath",
  3931. value: "mswj",
  3932. }),
  3933. h("textarea", { id: uniqueId }),
  3934. ]);
  3935. };
  3936. },
  3937. };
  3938. // 弹窗右边图标
  3939. const SsFullStyleHeader = {
  3940. name: "SsFullStyleHeader",
  3941. props: {
  3942. title: {
  3943. type: String,
  3944. default: "标题",
  3945. },
  3946. },
  3947. emits: ["close"],
  3948. setup(props, { emit }) {
  3949. // console.log(props.title)
  3950. const onClose = () => {
  3951. emit("close");
  3952. };
  3953. const SsIcon = resolveComponent("ss-icon");
  3954. return () =>
  3955. h("div", { class: "header-container" }, [
  3956. h("div", { class: "title" }, props.title),
  3957. h("div", { class: "handle-bar" }, [
  3958. h("div", { class: "left-bar" }, [
  3959. h(SsDialogIcon, { class: "dialog-icon-download" }),
  3960. h(SsDialogIcon, { class: "dialog-icon-print" }),
  3961. h(SsDialogIcon, { class: "dialog-icon-setting" }),
  3962. h(SsDialogIcon, { class: "dialog-icon-collect" }),
  3963. h(SsDialogIcon, { class: "dialog-icon-help" }),
  3964. h(SsDialogIcon, { class: "dialog-icon-full-screen" }),
  3965. h(SsDialogIcon, { class: "dialog-icon-lock" }),
  3966. ]),
  3967. h("div", { class: "close-bar", onClick: onClose }, [
  3968. h(SsDialogIcon, { class: "dialog-icon-close" }),
  3969. ]),
  3970. ]),
  3971. ]);
  3972. },
  3973. };
  3974. // ss-dialog弹窗
  3975. const SsDialog = {
  3976. name: "SsDialog",
  3977. props: {
  3978. src: {
  3979. type: String,
  3980. },
  3981. headerTitle: {
  3982. type: String,
  3983. // required: true,
  3984. default: "弹窗",
  3985. },
  3986. width: {
  3987. type: String,
  3988. default: "1400",
  3989. },
  3990. height: {
  3991. type: String,
  3992. default: "600",
  3993. },
  3994. params: {
  3995. type: Object,
  3996. default: () => ({}),
  3997. },
  3998. zIndex: {
  3999. type: Number,
  4000. default: 1000,
  4001. },
  4002. },
  4003. emits: ["close"],
  4004. setup(props, { slots, emit }) {
  4005. // 关闭窗口方法
  4006. const onClose = () => {
  4007. emit("close");
  4008. };
  4009. const showHeader = ref(true);
  4010. const headerVisible = ref(false);
  4011. const popupHieght = ref(props.height);
  4012. // 状态:存储位置信息
  4013. const position = reactive({
  4014. // 页面居中
  4015. x: (window.innerWidth - props.width) / 2,
  4016. y: (window.innerHeight - popupHieght.value) / 2,
  4017. isDragging: false,
  4018. offsetX: 0,
  4019. offsetY: 0,
  4020. });
  4021. // 鼠标按下时设置起始坐标并开始拖拽
  4022. const startDrag = (event) => {
  4023. position.isDragging = true;
  4024. position.offsetX = event.clientX - position.x;
  4025. position.offsetY = event.clientY - position.y;
  4026. };
  4027. // 鼠标移动时更新位置
  4028. const onDrag = (event) => {
  4029. if (position.isDragging) {
  4030. position.x = event.clientX - position.offsetX;
  4031. position.y = event.clientY - position.offsetY;
  4032. }
  4033. };
  4034. // 鼠标放开时结束拖拽
  4035. const endDrag = () => {
  4036. position.isDragging = false;
  4037. };
  4038. // 监听来自 iframe 的消息
  4039. const handleMessage = (event) => {
  4040. // 顶天立地
  4041. if (event.data && typeof event.data.hasScrollBar !== "undefined") {
  4042. if (event.data.hasScrollBar) {
  4043. // console.log(event);
  4044. position.y = 10;
  4045. showHeader.value = false;
  4046. headerVisible.value = true;
  4047. popupHieght.value = window.innerHeight - 20;
  4048. // console.log(popupHieght.value);
  4049. document.querySelector(".body").style.height = "100%";
  4050. document.querySelector(".body").style.paddingTop = "30px";
  4051. document.querySelector(".header-container ").style.position =
  4052. "absolute";
  4053. document.querySelector(".header-container ").style.zIndex = "10";
  4054. }
  4055. }
  4056. };
  4057. // 鼠标移入关闭按钮区域时显示头部
  4058. const onMouseEnterCloseButton = () => {
  4059. headerVisible.value = false;
  4060. };
  4061. // 鼠标移出关闭按钮区域时隐藏头部
  4062. const onMouseLeaveCloseButton = () => {
  4063. headerVisible.value = true;
  4064. };
  4065. // 在组件挂载时添加全局事件监听器
  4066. Vue.onMounted(() => {
  4067. // 如果传过来的高度大于窗口高度,则设置为窗口高度减去20 否则保持传过来的高度
  4068. popupHieght.value =
  4069. popupHieght.value > window.innerHeight
  4070. ? window.innerHeight - 20
  4071. : popupHieght.value;
  4072. const container = document.querySelector(".header-container");
  4073. if (container) {
  4074. container.addEventListener("mousedown", startDrag);
  4075. }
  4076. document.addEventListener("mousemove", onDrag);
  4077. document.addEventListener("mouseup", endDrag);
  4078. window.addEventListener("message", handleMessage);
  4079. });
  4080. // 在组件卸载时移除全局事件监听器
  4081. Vue.onUnmounted(() => {
  4082. document.removeEventListener("mousemove", onDrag);
  4083. document.removeEventListener("mouseup", endDrag);
  4084. window.removeEventListener("message", handleMessage);
  4085. });
  4086. const SsMark = resolveComponent("ss-mark");
  4087. const SsFullStyleHeader = resolveComponent("ss-full-style-header");
  4088. // render函数定义组件结构
  4089. return () =>
  4090. h(
  4091. Teleport,
  4092. { to: "body" }, // 使用 Teleport 将弹窗内容挂载到 body
  4093. h(SsMark, {}, [
  4094. h(
  4095. "div",
  4096. {
  4097. class: "popup-container",
  4098. style: {
  4099. position: "absolute",
  4100. left: `${position.x}px`,
  4101. top: `${position.y}px`,
  4102. width: props.width + "px",
  4103. height: popupHieght.value + "px",
  4104. zIndex: props.zIndex, // 确保弹窗在最上层
  4105. },
  4106. },
  4107. [
  4108. h(SsFullStyleHeader, {
  4109. class: "header",
  4110. title: props.headerTitle,
  4111. onClose: onClose,
  4112. onMousedown: startDrag, // 绑定拖动事件
  4113. onMouseUp: endDrag,
  4114. ...(!showHeader.value && {
  4115. onMouseenter: onMouseEnterCloseButton,
  4116. onMouseleave: onMouseLeaveCloseButton,
  4117. }),
  4118. style: {
  4119. cursor: position.isDragging ? "grabbing" : "grab",
  4120. visibility: headerVisible.value ? "hidden" : "visible",
  4121. },
  4122. }),
  4123. h(
  4124. "div",
  4125. {
  4126. class: "body",
  4127. style: {},
  4128. },
  4129. [
  4130. h("iframe", {
  4131. src: props.src,
  4132. frameborder: 0,
  4133. style: { width: "100%", height: "100%" },
  4134. }),
  4135. ]
  4136. ),
  4137. headerVisible.value &&
  4138. h("div", {
  4139. class: "close-button",
  4140. onMouseenter: onMouseEnterCloseButton,
  4141. onMouseleave: onMouseLeaveCloseButton,
  4142. style: {
  4143. position: "absolute",
  4144. top: "0",
  4145. right: "0",
  4146. // background: 'black',
  4147. width: "60px",
  4148. height: "60px",
  4149. cursor: "pointer",
  4150. },
  4151. }),
  4152. ]
  4153. ),
  4154. ])
  4155. );
  4156. },
  4157. };
  4158. // ss-mark遮罩层
  4159. const SsMark = {
  4160. name: "SsMark",
  4161. setup(props, { slots, emit }) {
  4162. return () =>
  4163. h("div", { class: "dialog-container" }, [
  4164. h("div", { class: "mark-content" }, [
  4165. h("div", { class: "dialog-contianer" }, [
  4166. slots.default ? slots.default() : "",
  4167. ]),
  4168. ]),
  4169. ]);
  4170. },
  4171. };
  4172. // ss-bottom-button 底部按钮
  4173. // 修改支持更多按钮 by xu 20251211
  4174. const SsBottomButton = {
  4175. name: "SsBottomButton",
  4176. props: {
  4177. text: {
  4178. type: String,
  4179. required: false,
  4180. },
  4181. type: {
  4182. type: String,
  4183. default: "button",
  4184. },
  4185. iconClass: {
  4186. type: String,
  4187. },
  4188. class: {
  4189. type: String,
  4190. default: "",
  4191. },
  4192. onclick: {
  4193. type: [Function, String],
  4194. default: null,
  4195. },
  4196. // 修改支持更多按钮 by xu 20251211
  4197. more: {
  4198. type: [Boolean, String],
  4199. default: false,
  4200. },
  4201. },
  4202. setup(props, { emit }) {
  4203. const SsBottomDivIcon = Vue.resolveComponent("ss-bottom-div-icon");
  4204. const showDropdown = Vue.ref(false);
  4205. // 修改支持更多按钮 by xu 20251211
  4206. const moreKey = Vue.computed(() => {
  4207. const val = props.more;
  4208. if (val === false || val === null || typeof val === "undefined") {
  4209. return null;
  4210. }
  4211. if (val === true || val === "" || val === "true") {
  4212. return "moreChg";
  4213. }
  4214. return val;
  4215. });
  4216. // 从配置中读取按钮信息和下拉选项
  4217. const config = Vue.computed(() => {
  4218. if (
  4219. moreKey.value &&
  4220. window.ss &&
  4221. window.ss.dom &&
  4222. window.ss.dom.btnElemConfig
  4223. ) {
  4224. return window.ss.dom.btnElemConfig[moreKey.value] || {};
  4225. }
  4226. return {};
  4227. });
  4228. const buttonText = Vue.computed(() => {
  4229. return props.text || config.value.desc || "";
  4230. });
  4231. const dropOptions = Vue.computed(() => {
  4232. return config.value.dropOptions || [];
  4233. });
  4234. const hasDropdown = Vue.computed(() => {
  4235. return dropOptions.value.length > 0;
  4236. });
  4237. const handleMouseEnter = () => {
  4238. if (hasDropdown.value) {
  4239. showDropdown.value = true;
  4240. }
  4241. };
  4242. const handleMouseLeave = () => {
  4243. showDropdown.value = false;
  4244. };
  4245. const handleDropItemClick = (option) => {
  4246. if (option.callback && typeof option.callback === "function") {
  4247. option.callback();
  4248. }
  4249. showDropdown.value = false;
  4250. };
  4251. return () =>
  4252. h(
  4253. "div",
  4254. {
  4255. class: "ss-bottom-button-wrapper",
  4256. onMouseenter: handleMouseEnter,
  4257. onMouseleave: handleMouseLeave,
  4258. },
  4259. [
  4260. h(
  4261. "button",
  4262. {
  4263. class: props.class,
  4264. onClick: (e) => {
  4265. e.stopPropagation();
  4266. emit("click", e);
  4267. if (props.onclick) {
  4268. // 如果是函数直接调用
  4269. if (typeof props.onclick === "function") {
  4270. props.onclick(e);
  4271. } else if (typeof props.onclick === "string") {
  4272. // 如果是字符串,使用直接的方法执行
  4273. // 临时存储按钮元素到全局变量
  4274. window.__ss_current_button = e.currentTarget;
  4275. // 直接执行代码,使用eval以保留原始上下文
  4276. try {
  4277. eval(props.onclick);
  4278. } finally {
  4279. // 清理全局变量
  4280. delete window.__ss_current_button;
  4281. }
  4282. }
  4283. }
  4284. },
  4285. type: props.type,
  4286. },
  4287. [
  4288. h("span", null, [
  4289. h(SsBottomDivIcon, {
  4290. class: props.iconClass,
  4291. }),
  4292. ]),
  4293. h("span", null, buttonText.value),
  4294. ]
  4295. ),
  4296. // 渲染下拉菜单
  4297. hasDropdown.value && showDropdown.value
  4298. ? h(
  4299. "div",
  4300. {
  4301. class: "ss-bottom-button-dropdown",
  4302. },
  4303. dropOptions.value.map((option) =>
  4304. h(
  4305. "div",
  4306. {
  4307. class: "ss-bottom-button-dropdown-item",
  4308. onClick: (e) => {
  4309. e.stopPropagation();
  4310. handleDropItemClick(option);
  4311. },
  4312. },
  4313. option.desc
  4314. )
  4315. )
  4316. )
  4317. : null,
  4318. ]
  4319. );
  4320. },
  4321. };
  4322. // ss-search搜索框
  4323. const SsSearch = {
  4324. name: "SsSearch",
  4325. props: {
  4326. theme: {
  4327. type: String,
  4328. default: "light",
  4329. validator: function (value) {
  4330. return ["dark", "light"].includes(value);
  4331. },
  4332. },
  4333. placeholder: {
  4334. type: String,
  4335. default: "请输入搜索条件",
  4336. },
  4337. },
  4338. setup(props, { emit }) {
  4339. const onClick = () => {
  4340. console.log("Search clicked");
  4341. emit("click");
  4342. };
  4343. const SsIcon = Vue.resolveComponent("ss-icon");
  4344. return () =>
  4345. Vue.h(
  4346. "div",
  4347. {
  4348. class: ["search-container", props.theme],
  4349. onClick: onClick,
  4350. },
  4351. [
  4352. Vue.h("input", {
  4353. placeholder: props.placeholder,
  4354. disabled: true,
  4355. }),
  4356. Vue.h(SsIcon, {
  4357. name: "search-result",
  4358. size: "20px",
  4359. }),
  4360. ]
  4361. );
  4362. },
  4363. };
  4364. // ss-cart-item 菜单页面的卡片 左右结构
  4365. const SsCartItem = {
  4366. name: "SsCartItem",
  4367. props: {
  4368. active: Boolean,
  4369. item: {
  4370. type: Object,
  4371. default: () => ({
  4372. thumb: "images/example/project-img.png",
  4373. title: "广州(国际)科技成果转化天河基地专",
  4374. description: "佳能中国广州分公司",
  4375. all: 50,
  4376. finish: 5,
  4377. }),
  4378. },
  4379. },
  4380. setup(props, { emit }) {
  4381. const item = props.item;
  4382. const itemWidth = Vue.computed(() => {
  4383. const containerWidth =
  4384. document.body.clientWidth || document.body.scrollWidth - 520;
  4385. const halfWidth = containerWidth / 2;
  4386. if (halfWidth < 480) {
  4387. return Math.min(containerWidth, 702) + "px";
  4388. } else {
  4389. return Math.min(halfWidth, 702) + "px";
  4390. }
  4391. });
  4392. const onItemClick = (e) => {
  4393. emit("click", e);
  4394. };
  4395. return {
  4396. item,
  4397. itemWidth,
  4398. onItemClick,
  4399. };
  4400. },
  4401. render() {
  4402. const SsIcon = Vue.resolveComponent("ss-icon");
  4403. return Vue.h(
  4404. "div",
  4405. {
  4406. class: { "item-container": true, active: this.active },
  4407. onClick: this.onItemClick,
  4408. style: { width: this.itemWidth },
  4409. },
  4410. [
  4411. Vue.h("div", { class: "header" }, [
  4412. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  4413. ]),
  4414. Vue.h("div", { class: "body" }, [
  4415. Vue.h("div", { class: "left" }, [
  4416. Vue.h("img", {
  4417. src: this.item.thumb,
  4418. alt: "Thumbnail",
  4419. class: "imgUnHandle",
  4420. style: { "object-fit": "cover", width: "100%", height: "100%" },
  4421. }),
  4422. ]),
  4423. Vue.h("div", { class: "right" }, [
  4424. Vue.h("div", { class: "title" }, this.item.title),
  4425. Vue.h("div", { class: "desc" }, this.item.description),
  4426. Vue.h("div", { class: "progress" }, [
  4427. Vue.h(
  4428. "div",
  4429. {
  4430. style: {
  4431. width: `${(this.item.finish / this.item.all) * 100}%`,
  4432. },
  4433. },
  4434. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  4435. ),
  4436. ]),
  4437. ]),
  4438. ]),
  4439. ]
  4440. );
  4441. },
  4442. };
  4443. // ss-cart-item2 菜单页面的卡片 上下结构
  4444. const SsCartItem2 = {
  4445. name: "SsCartItem2",
  4446. props: {
  4447. active: Boolean,
  4448. item: {
  4449. type: Object,
  4450. default: () => ({
  4451. thumb: "images/example/project-img.png",
  4452. title: "广州(国际)科技成果转化天河基地专",
  4453. description: "佳能中国广州分公司",
  4454. all: 50,
  4455. finish: 5,
  4456. }),
  4457. },
  4458. },
  4459. setup(props, { emit }) {
  4460. const item = props.item;
  4461. const itemWidth = Vue.computed(() => {
  4462. const containerWidth =
  4463. document.body.clientWidth || document.body.scrollWidth - 520;
  4464. const halfWidth = containerWidth / 2;
  4465. if (halfWidth < 480) {
  4466. return Math.min(containerWidth, 702) + "px";
  4467. } else {
  4468. return Math.min(halfWidth, 702) + "px";
  4469. }
  4470. });
  4471. const onItemClick = (e) => {
  4472. emit("click", e);
  4473. };
  4474. return {
  4475. item,
  4476. itemWidth,
  4477. onItemClick,
  4478. };
  4479. },
  4480. render() {
  4481. const SsIcon = Vue.resolveComponent("ss-icon");
  4482. return Vue.h(
  4483. "div",
  4484. {
  4485. class: { "item-container2": true, active: this.active },
  4486. onClick: this.onItemClick,
  4487. style: { width: this.itemWidth },
  4488. },
  4489. [
  4490. Vue.h("div", { class: "action-bar" }, [
  4491. Vue.h(SsIcon, { name: "setting", size: "20px" }),
  4492. ]),
  4493. Vue.h("div", { class: "header" }, [
  4494. Vue.h("div", { class: "title" }, `${this.item.title}`),
  4495. ]),
  4496. Vue.h("div", { class: "body" }, [
  4497. Vue.h("div", { class: "left" }, [
  4498. Vue.h("img", {
  4499. src: this.item.thumb,
  4500. alt: "Thumbnail",
  4501. class: "imgUnHandle",
  4502. style: { "object-fit": "cover", width: "100%", height: "100%" },
  4503. }),
  4504. ]),
  4505. Vue.h("div", { class: "right" }, [
  4506. Vue.h("div", { class: "content" }, this.item.description),
  4507. Vue.h("div", { class: "tip" }, [
  4508. Vue.h("div", { class: "progress" }, [
  4509. Vue.h(
  4510. "div",
  4511. {
  4512. style: {
  4513. width: `${(this.item.finish / this.item.all) * 100}%`,
  4514. },
  4515. },
  4516. [Vue.h("div", `${this.item.finish}/${this.item.all}`)]
  4517. ),
  4518. ]),
  4519. ]),
  4520. ]),
  4521. ]),
  4522. ]
  4523. );
  4524. },
  4525. };
  4526. /**
  4527. * SsListCard - 列表卡片组件
  4528. *
  4529. * @description 用于显示列表项的卡片组件,支持缩略图、标签、状态、操作按钮和选择功能
  4530. *
  4531. * @prop {Object} item - 卡片数据对象
  4532. * @prop {String} item.title - 卡片标题
  4533. * @prop {String} [item.thumb] - 缩略图 URL(可选)
  4534. * @prop {String} [item.thumbType] - 缩略图类型:'thumbnail'(缩略图)或默认(证件照)
  4535. * @prop {String} [item.status] - 卡片状态:'available'(可用-绿色)、'unavailable'(不可用-黄色)、'disabled'(禁用-红色)
  4536. * @prop {Array} item.tags - 标签数组,格式:[{键: 值}, ...]
  4537. * @prop {Function} item.onclick - 点击卡片的回调函数
  4538. * @prop {Array} [item.buttons] - 操作按钮数组(可选),显示在右上角齿轮
  4539. * @prop {Array} [item.statusIcons] - 状态图标数组(可选),显示在右上角,格式:[{class: '图标类名', title: '提示文字'}, ...]
  4540. *
  4541. * @example
  4542. * // 基础用法
  4543. * const item = {
  4544. * title: "卡片标题",
  4545. * tags: [
  4546. * { 类型: '文档' },
  4547. * { 状态: '进行中' }
  4548. * ],
  4549. * onclick: () => console.log('点击了卡片')
  4550. * };
  4551. *
  4552. * @example
  4553. * // 带缩略图和状态
  4554. * const item = {
  4555. * title: "场地预定",
  4556. * thumbType: 'thumbnail',
  4557. * thumb: "https://example.com/image.jpg",
  4558. * status: "available", // 绿色背景
  4559. * tags: [{ 容量: '50人' }],
  4560. * onclick: () => {}
  4561. * };
  4562. *
  4563. * @example
  4564. * // 带操作按钮和状态图标
  4565. * const item = {
  4566. * title: "会议室A",
  4567. * tags: [{ 楼层: '3F' }],
  4568. * onclick: () => {},
  4569. * // 右上角操作按钮(齿轮)
  4570. * buttons: [{
  4571. * class: 'cart-list-setting',
  4572. * title: '编辑',
  4573. * onclick: () => console.log('编辑')
  4574. * }],
  4575. * // 右上角状态图标(在齿轮右边)
  4576. * statusIcons: [{
  4577. * class: 'icon-emoji',
  4578. * title: '清洁中'
  4579. * }]
  4580. * };
  4581. *
  4582. * @features
  4583. * - 卡片选择:鼠标悬停右下角显示选择角标,点击切换选中状态,选中后显示底部深灰色线条
  4584. * - 状态颜色:根据 status 字段显示不同背景色(可用/不可用/禁用)
  4585. * - 图片类型:支持证件照(73×100px)和缩略图(180×100px)两种尺寸
  4586. * - 操作按钮:右上角齿轮,hover 显示,支持多个按钮下拉菜单
  4587. * - 状态图标:右上角显示状态图标,齿轮会根据图标数量自动左移
  4588. *
  4589. * @author xu
  4590. * @date 20260105
  4591. */
  4592. // 组件文档补全(JSDoc) by xu 20260108
  4593. /**
  4594. * SsListCard(左侧对象卡片)
  4595. *
  4596. * 用途:
  4597. * - 渲染左侧卡片(标题 + tags)
  4598. * - 右下角“角标”用于选中/取消选中(不会触发卡片 click)
  4599. *
  4600. * 调用示例:
  4601. * ```html
  4602. * <ss-list-card :item="item" @toggle-select="handleToggleSelect" @click="openDetail"></ss-list-card>
  4603. * ```
  4604. *
  4605. * Props:
  4606. * - `item`:卡片数据对象(建议含 `id/title/tags[]`;内部会读写 `item._ssSelected` 作为选中态)
  4607. *
  4608. * Emits:
  4609. * - `toggle-select`:点击角标触发,参数 `{ item, selected }`
  4610. * - `click`:点击卡片主体触发(用于打开详情等)
  4611. */
  4612. const SsListCard = {
  4613. name: "SsListCard",
  4614. props: {
  4615. ssObjName: { type: String, default: "" }, // 功能:业务对象名(用于默认缩略图 icon) by xu 20260109
  4616. cardClickAction: { type: String, default: "view" }, // 功能:卡片主体点击动作(view=查看;single=单选互斥) by xu 20260109
  4617. item: {
  4618. type: Object,
  4619. required: true,
  4620. },
  4621. },
  4622. emits: ["click", "change", "toggle-select"],
  4623. setup(props, { emit }) {
  4624. const item = props.item;
  4625. // 移除 itemWidth 计算属性,不再需要 by xu 20260105
  4626. // 判断卡片类型 by xu 20260105
  4627. const cardType = Vue.computed(() => {
  4628. // 支持“无图但保留缩略图占位”(同一业务列表图片形态一致) by xu 20260109
  4629. if (!item.thumb && !item.thumbType) return ""; // 业务列表“无图”形态
  4630. // 根据 thumbType 字段判断,如果没有则默认为证件照
  4631. return item.thumbType === "thumbnail" ? "card-thumbnail" : "card-photo";
  4632. });
  4633. // 判断状态类型 - 场地预定状态 by xu 20260105
  4634. const statusClass = Vue.computed(() => {
  4635. if (!item.status) return ""; // 无状态,默认白色
  4636. // 映射状态值到 CSS 类名
  4637. const statusMap = {
  4638. available: "status-available",
  4639. unavailable: "status-unavailable",
  4640. disabled: "status-disabled",
  4641. };
  4642. return statusMap[item.status] || "";
  4643. });
  4644. const onItemClick = (e) => {
  4645. // 清除所有类型卡片的 active 状态(卡片主体点击仅做 active 高亮) by xu 20260109
  4646. const allListCards = document.querySelectorAll(
  4647. ".knowledge-item-container"
  4648. );
  4649. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  4650. allListCards.forEach((card) => card.classList.remove("active"));
  4651. allFolderCards.forEach((card) => card.classList.remove("active"));
  4652. // 设置当前项的 active 状态
  4653. e.currentTarget.classList.add("active");
  4654. // 卡片主体点击动作由页面级配置控制 by xu 20260109
  4655. if (props.cardClickAction === "view") {
  4656. props.item.onclick?.();
  4657. // 通知父级:卡片点击(查看) by xu 20260109
  4658. emit("click", props.item);
  4659. }
  4660. };
  4661. const onItemChange = (e, icon, index) => {
  4662. e.stopPropagation(); // 阻止事件冒泡到卡片
  4663. props.item.buttons[0].onclick();
  4664. // emit("change", { item: props.item, icon, index });
  4665. };
  4666. return {
  4667. item,
  4668. cardType,
  4669. statusClass,
  4670. onItemClick,
  4671. onItemChange,
  4672. };
  4673. },
  4674. data() {
  4675. return {
  4676. showButtons: false,
  4677. selected: false, // 选择状态 by xu 20260105
  4678. showTextPopover: false, // 功能:右侧文字区 hover 展示全量 by xu 20260108
  4679. textPopoverType: "", // second-summary / second-tags / third / third-full by xu 20260108
  4680. textPopoverBottom: 0, // 功能:popover 从当前省略行位置向上展开 by xu 20260108
  4681. hideTextPopoverTimer: null, // 功能:鼠标从省略行移到浮层的缓冲 by xu 20260108
  4682. textPopoverPayload: null, // { kind, text?, lines? } by xu 20260108
  4683. ellipsisVisible: {
  4684. // 功能:只在真实出现 ... 时才显示命中区/允许 goheight by xu 20260109
  4685. secondSummary: false,
  4686. secondTags: false,
  4687. third: false,
  4688. thirdFull: false,
  4689. },
  4690. };
  4691. },
  4692. methods: {
  4693. __allowSelect() {
  4694. // 功能说明:无 rbarObj 时禁用选中能力(隐藏右下角勾选并禁止 toggle) by xu 20260122
  4695. try {
  4696. if (this?.$root && this.$root.hasObjPanel === false) return false;
  4697. if (
  4698. typeof window !== "undefined" &&
  4699. window.__objListVm &&
  4700. window.__objListVm.hasObjPanel === false
  4701. )
  4702. return false;
  4703. } catch (_) {}
  4704. return true;
  4705. },
  4706. // 切换选择状态(对外 emit,支持方案A父级 state 中转) by xu 20260106
  4707. toggleSelect(e) {
  4708. e.stopPropagation();
  4709. if (!this.__allowSelect()) return; // 功能说明:无 rbarObj 时禁止选中 by xu 20260122
  4710. // 使用 item 上的状态,便于父级/右侧边栏反向同步 by xu 20260106
  4711. this.item._ssSelected = !this.item?._ssSelected;
  4712. this.$emit("toggle-select", {
  4713. item: this.item,
  4714. selected: !!this.item?._ssSelected,
  4715. });
  4716. },
  4717. // 卡片主体点击=单选互斥:只有“本次切到选中”才清理其他选中 by xu 20260109
  4718. toggleSelectExclusive(e) {
  4719. e?.stopPropagation?.();
  4720. if (!this.__allowSelect()) return; // 功能说明:无 rbarObj 时禁止选中 by xu 20260122
  4721. this.item._ssSelected = !this.item?._ssSelected;
  4722. const selected = !!this.item?._ssSelected;
  4723. this.$emit("toggle-select", {
  4724. item: this.item,
  4725. selected,
  4726. exclusive: true,
  4727. });
  4728. },
  4729. // 功能:无缩略图时,用业务对象 icon 做默认图(ss-icon + icon-obj-xx) by xu 20260109
  4730. getBizThumbIconClass() {
  4731. const name = String(
  4732. this.ssObjName ||
  4733. this.item?.ssObjName ||
  4734. this.$root?.ssObjName ||
  4735. window?.ss?.dom?.ssObjName ||
  4736. ""
  4737. ).trim();
  4738. if (!name) return "";
  4739. return `icon-obj-${name}`;
  4740. },
  4741. // 功能:构造右侧文字区 4 行(摘要/类目或标签/对象号) by xu 20260108
  4742. buildRightTextLines() {
  4743. const item = this.item || {};
  4744. const summary = String(item?.desc ?? "").trim(); // 后端字段后续映射 by xu 20260108
  4745. const objNum = String(item?.objNum ?? "").trim(); // 后端字段后续映射 by xu 20260108
  4746. const categoryArr = Array.isArray(item?.category) ? item.category : [];
  4747. const tagsArr = Array.isArray(item?.tags) ? item.tags : [];
  4748. const hasTags = tagsArr.length > 0;
  4749. const hasCategory = categoryArr.length > 0;
  4750. // 第二部分(L1-L3):摘要优先,其次物品参数 by xu 20260108
  4751. const secondKind = summary ? "summary" : hasTags ? "tags" : "";
  4752. const hasSecond = !!secondKind;
  4753. // 第三部分(L4):对象号优先,其次类目 by xu 20260108
  4754. const thirdKind = objNum ? "objNum" : hasCategory ? "category" : "";
  4755. const hasThird = !!thirdKind;
  4756. const thirdFull = !hasSecond && hasThird; // 第二部分为空则第三部分占满 4 行 by xu 20260108
  4757. const secondFull = hasSecond && !hasThird && secondKind === "tags"; // 仅标签时占满 4 行(不留空行) by xu 20260109
  4758. const toValueText = (obj) => {
  4759. // 功能说明:类目/物品参数回显展示 key: value(否则只显示值看不懂) by xu 20260114
  4760. const [k, v] = Object.entries(obj || {})[0] || ["", ""];
  4761. const key = k !== undefined && k !== null ? String(k).trim() : "";
  4762. const val = v !== undefined && v !== null ? String(v).trim() : "";
  4763. if (key && val) return `${key}:${val}`;
  4764. if (val) return val;
  4765. if (key) return key;
  4766. return "";
  4767. };
  4768. const toLineList = (arr) =>
  4769. (arr || [])
  4770. .map(toValueText)
  4771. .map((s) => String(s ?? "").trim())
  4772. .filter(Boolean);
  4773. const flat = (arr) => toLineList(arr).join(" ");
  4774. // 第二部分 tags:默认 3 行;仅标签时占满 4 行(避免底部空一行) by xu 20260109
  4775. const secondTagsMaxLines = secondFull ? 4 : 3;
  4776. const secondTagsLinesFull = toLineList(tagsArr);
  4777. const secondTagsHead = secondTagsLinesFull.slice(
  4778. 0,
  4779. Math.max(0, secondTagsMaxLines - 1)
  4780. );
  4781. const secondTagsTail = secondTagsLinesFull.slice(
  4782. Math.max(0, secondTagsMaxLines - 1)
  4783. );
  4784. const secondTagsLast =
  4785. secondTagsTail.length <= 1
  4786. ? secondTagsTail[0] || ""
  4787. : secondTagsTail.join(" "); // 功能:最后一行平铺剩余 by xu 20260108
  4788. // 第三部分类目:卡片上串成一行;goheight 展开时一条一行 by xu 20260109
  4789. const categoryLinesFull = toLineList(categoryArr);
  4790. const categoryLine = categoryLinesFull.join(" ");
  4791. const thirdText =
  4792. thirdKind === "objNum"
  4793. ? objNum
  4794. : thirdKind === "category"
  4795. ? categoryLine
  4796. : "";
  4797. return {
  4798. secondKind,
  4799. thirdKind,
  4800. hasSecond,
  4801. hasThird,
  4802. thirdFull,
  4803. secondFull,
  4804. summary,
  4805. secondTagsMaxLines,
  4806. secondTagsHead,
  4807. secondTagsLast,
  4808. secondTagsLinesFull,
  4809. objNum,
  4810. categoryLine,
  4811. categoryLinesFull,
  4812. thirdText,
  4813. };
  4814. },
  4815. measureTextOverflowByLines(text, maxLines, width) {
  4816. const w = Number(width) || 0;
  4817. if (!w || !text) return false;
  4818. const probe = document.createElement("div");
  4819. probe.style.position = "fixed";
  4820. probe.style.left = "-99999px";
  4821. probe.style.top = "0";
  4822. probe.style.width = w + "px";
  4823. probe.style.fontSize = "18px";
  4824. probe.style.lineHeight = "24px";
  4825. probe.style.whiteSpace = "normal";
  4826. probe.style.wordBreak = "break-word";
  4827. probe.style.visibility = "hidden";
  4828. probe.textContent = text;
  4829. document.body.appendChild(probe);
  4830. const h = probe.getBoundingClientRect().height || 0;
  4831. document.body.removeChild(probe);
  4832. return h > maxLines * 24 + 1;
  4833. },
  4834. measureSingleLineOverflow(text, width) {
  4835. const w = Number(width) || 0;
  4836. if (!w || !text) return false;
  4837. const probe = document.createElement("span");
  4838. probe.style.position = "fixed";
  4839. probe.style.left = "-99999px";
  4840. probe.style.top = "0";
  4841. probe.style.display = "inline-block";
  4842. probe.style.maxWidth = w + "px";
  4843. probe.style.fontSize = "18px";
  4844. probe.style.lineHeight = "24px";
  4845. probe.style.whiteSpace = "nowrap";
  4846. probe.style.visibility = "hidden";
  4847. probe.textContent = text;
  4848. document.body.appendChild(probe);
  4849. const overflow =
  4850. (probe.scrollWidth || 0) > (probe.clientWidth || w) + 1;
  4851. document.body.removeChild(probe);
  4852. return overflow;
  4853. },
  4854. // 功能:根据当前卡片宽度刷新「是否出现 ...」状态(用于控制命中区显示) by xu 20260109
  4855. refreshEllipsisVisible() {
  4856. try {
  4857. const right = this.$el?.querySelector?.(".right");
  4858. const rawWidth =
  4859. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  4860. const width = Math.max(0, Math.round(rawWidth)); // 修复:内容区不再使用 padding-right 预留,测量按真实宽度 by xu 20260109
  4861. const model = this.buildRightTextLines();
  4862. const next = {
  4863. secondSummary: false,
  4864. secondTags: false,
  4865. third: false,
  4866. thirdFull: false,
  4867. };
  4868. if (model.secondKind === "summary" && model.summary) {
  4869. next.secondSummary = this.measureTextOverflowByLines(
  4870. model.summary,
  4871. 3,
  4872. width
  4873. );
  4874. }
  4875. if (model.secondKind === "tags") {
  4876. // 功能说明:tags 采用「最后一行平铺剩余」策略,是否出现 ... 仅取决于最后一行是否溢出(数量多但平铺放得下不算溢出) by xu 20260114
  4877. next.secondTags = this.measureSingleLineOverflow(
  4878. model.secondTagsLast,
  4879. width
  4880. );
  4881. }
  4882. if (model.hasThird && !model.thirdFull) {
  4883. next.third = this.measureSingleLineOverflow(model.thirdText, width);
  4884. }
  4885. if (model.hasThird && model.thirdFull) {
  4886. next.thirdFull = this.measureTextOverflowByLines(
  4887. model.thirdText,
  4888. 4,
  4889. width
  4890. );
  4891. }
  4892. const prev = this.ellipsisVisible || {};
  4893. const changed =
  4894. prev.secondSummary !== next.secondSummary ||
  4895. prev.secondTags !== next.secondTags ||
  4896. prev.third !== next.third ||
  4897. prev.thirdFull !== next.thirdFull;
  4898. if (changed) this.ellipsisVisible = next;
  4899. } catch (e) {
  4900. // ignore by xu 20260109
  4901. }
  4902. },
  4903. showTextPopoverFor(el, kind) {
  4904. // 调试开关:window.__SS_LISTCARD_DEBUG__ = true 时打印 hover/溢出判断日志 by xu 20260108
  4905. const debug =
  4906. typeof window !== "undefined" && !!window.__SS_LISTCARD_DEBUG__;
  4907. if (debug) {
  4908. console.log("[SsListCard] ellipsis hover", {
  4909. kind,
  4910. el: el?.className,
  4911. });
  4912. }
  4913. const model = this.buildRightTextLines();
  4914. const lineEl = el?.closest?.(".ss-card-text__line") || el;
  4915. const right = lineEl?.closest?.(".right") || el?.closest?.(".right");
  4916. const rawWidth =
  4917. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  4918. const width = Math.max(0, Math.round(rawWidth)); // 修复:内容区不再预留 padding-right,测量按真实宽度 by xu 20260109
  4919. const textEl =
  4920. kind === "second-summary"
  4921. ? lineEl?.querySelector?.(".ss-card-text__secondSummary")
  4922. : kind === "second-tags"
  4923. ? lineEl?.querySelector?.(".ss-card-text__tagLineLast")
  4924. : kind === "third"
  4925. ? lineEl?.querySelector?.(".ss-card-text__thirdLine")
  4926. : lineEl?.querySelector?.(".ss-card-text__thirdFull");
  4927. let payload = null;
  4928. // 仅当真实会出现 ... 时才允许 goheight(避免“没超出也能出 goheight”) by xu 20260109
  4929. const overflowed =
  4930. kind === "second-summary"
  4931. ? this.measureTextOverflowByLines(model.summary, 3, width)
  4932. : kind === "second-tags"
  4933. ? this.measureSingleLineOverflow(model.secondTagsLast, width) // 功能说明:同 refreshEllipsisVisible,tags 仅看最后一行是否溢出 by xu 20260114
  4934. : kind === "third"
  4935. ? this.measureSingleLineOverflow(model.thirdText, width)
  4936. : this.measureTextOverflowByLines(model.thirdText, 4, width);
  4937. if (!overflowed) return;
  4938. if (kind === "second-summary") {
  4939. if (model.summary) payload = { kind, text: model.summary };
  4940. } else if (kind === "second-tags") {
  4941. if (
  4942. Array.isArray(model.secondTagsLinesFull) &&
  4943. model.secondTagsLinesFull.length
  4944. ) {
  4945. payload = { kind, lines: model.secondTagsLinesFull };
  4946. }
  4947. } else if (kind === "third") {
  4948. if (
  4949. model.thirdKind === "category" &&
  4950. Array.isArray(model.categoryLinesFull) &&
  4951. model.categoryLinesFull.length
  4952. ) {
  4953. payload = { kind, lines: model.categoryLinesFull }; // 功能:类目展开一条一行 by xu 20260109
  4954. } else if (model.thirdText) {
  4955. payload = { kind, text: model.thirdText };
  4956. }
  4957. } else if (kind === "third-full") {
  4958. if (
  4959. model.thirdKind === "category" &&
  4960. Array.isArray(model.categoryLinesFull) &&
  4961. model.categoryLinesFull.length
  4962. ) {
  4963. payload = { kind, lines: model.categoryLinesFull }; // 功能:类目占满模式展开一条一行 by xu 20260109
  4964. } else if (model.thirdText) {
  4965. payload = { kind, text: model.thirdText };
  4966. }
  4967. }
  4968. if (debug) {
  4969. console.log("[SsListCard] ellipsis decide", {
  4970. kind,
  4971. rawWidth: Math.round(rawWidth),
  4972. width,
  4973. hasPayload: !!payload,
  4974. textEl: textEl?.className,
  4975. textClient: textEl
  4976. ? {
  4977. cw: textEl.clientWidth,
  4978. ch: textEl.clientHeight,
  4979. sw: textEl.scrollWidth,
  4980. sh: textEl.scrollHeight,
  4981. }
  4982. : null,
  4983. });
  4984. }
  4985. if (!payload) return;
  4986. this.clearHideTextPopoverTimer();
  4987. const container = lineEl?.closest?.(".right");
  4988. const containerRect = container?.getBoundingClientRect?.();
  4989. const lineRect = lineEl?.getBoundingClientRect?.();
  4990. if (containerRect && lineRect) {
  4991. const bottom = Math.max(
  4992. 0,
  4993. Math.round(containerRect.bottom - lineRect.bottom)
  4994. );
  4995. this.textPopoverBottom = bottom;
  4996. } else {
  4997. this.textPopoverBottom = 0;
  4998. }
  4999. this.textPopoverPayload = payload;
  5000. this.textPopoverType = kind;
  5001. this.showTextPopover = true;
  5002. if (debug) console.log("[SsListCard] goheight show", payload);
  5003. },
  5004. isOverflowing(el) {
  5005. if (!el) return false;
  5006. // 单行/多行省略统一判断:scroll 尺寸大于 client 尺寸即认为有 ... by xu 20260108
  5007. return (
  5008. (el.scrollWidth &&
  5009. el.clientWidth &&
  5010. el.scrollWidth > el.clientWidth + 1) ||
  5011. (el.scrollHeight &&
  5012. el.clientHeight &&
  5013. el.scrollHeight > el.clientHeight + 1)
  5014. );
  5015. },
  5016. isSummaryOverflowing(el) {
  5017. if (!el) return false;
  5018. // -webkit-line-clamp 场景下 scrollHeight 不稳定,改用“无 clamp 的离屏测量”判断是否超过 2 行 by xu 20260108
  5019. const text = String(this.item?.desc ?? "").trim();
  5020. if (!text) return false;
  5021. const rect = el.getBoundingClientRect?.();
  5022. const width = rect?.width || el.clientWidth || 0;
  5023. if (!width) return false;
  5024. const probe = document.createElement("div");
  5025. probe.style.position = "fixed";
  5026. probe.style.left = "-99999px";
  5027. probe.style.top = "0";
  5028. probe.style.width = width + "px";
  5029. probe.style.fontSize = "18px";
  5030. probe.style.lineHeight = "24px";
  5031. probe.style.whiteSpace = "normal";
  5032. probe.style.wordBreak = "break-word";
  5033. probe.style.visibility = "hidden";
  5034. probe.textContent = text;
  5035. document.body.appendChild(probe);
  5036. const h = probe.getBoundingClientRect().height || 0;
  5037. document.body.removeChild(probe);
  5038. return h > 48 + 1;
  5039. },
  5040. clearHideTextPopoverTimer() {
  5041. if (this.hideTextPopoverTimer) {
  5042. clearTimeout(this.hideTextPopoverTimer);
  5043. this.hideTextPopoverTimer = null;
  5044. }
  5045. },
  5046. // 修复 goheight hover 无响应:移除重复方法覆盖,统一使用上面的 showTextPopoverFor(el, kind) by xu 20260109
  5047. hideTextPopoverLater() {
  5048. this.clearHideTextPopoverTimer();
  5049. this.hideTextPopoverTimer = setTimeout(() => {
  5050. this.showTextPopover = false;
  5051. this.textPopoverType = "";
  5052. this.textPopoverPayload = null;
  5053. }, 120);
  5054. },
  5055. hideTextPopover() {
  5056. this.clearHideTextPopoverTimer();
  5057. this.showTextPopover = false;
  5058. this.textPopoverType = "";
  5059. this.textPopoverPayload = null;
  5060. },
  5061. // 功能:新需求下不在 updated 内做测量,避免死循环 by xu 20260108
  5062. },
  5063. mounted() {
  5064. // 无需在 mounted/updated 里做 overflow 测量(避免死循环),只在 hover 触发时判断 by xu 20260108
  5065. // 仅用于控制“...命中区是否显示”,不会触发循环更新 by xu 20260109
  5066. this.$nextTick?.(() => {
  5067. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5068. });
  5069. this.__ssListCardResizeHandler = () => this.refreshEllipsisVisible?.(); // 功能:窗口变化时刷新 ... 显示 by xu 20260109
  5070. window.addEventListener?.("resize", this.__ssListCardResizeHandler);
  5071. },
  5072. updated() {
  5073. // 卡片数据更新后刷新一次 ... 显示状态(避免“宽度/内容变了但命中区不变”) by xu 20260109
  5074. this.$nextTick?.(() => {
  5075. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5076. });
  5077. },
  5078. beforeUnmount() {
  5079. // 清理 timer,避免残留导致异常 by xu 20260108
  5080. this.clearHideTextPopoverTimer?.();
  5081. if (this.__ssListCardResizeHandler) {
  5082. window.removeEventListener?.("resize", this.__ssListCardResizeHandler);
  5083. this.__ssListCardResizeHandler = null;
  5084. }
  5085. },
  5086. render() {
  5087. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  5088. const SsIcon = Vue.resolveComponent("ss-icon");
  5089. const hasThumbArea = !!(this.item?.thumb || this.item?.thumbType); // 功能:无图但有 thumbType 时仍保留占位 by xu 20260109
  5090. const thumbSrc = (() => {
  5091. // 功能说明:兼容 thumb 为 raw path 或 {val}/{value},组件内统一转为 dlByHttp URL by xu 20260122
  5092. const t = this.item?.thumb;
  5093. if (!t) return "";
  5094. if (typeof t === "string") {
  5095. const s = t.trim();
  5096. if (!s) return "";
  5097. // 已经是 URL/绝对路径则直接使用;否则按 path 构建 dlByHttp by xu 20260122
  5098. if (
  5099. /^https?:\/\//i.test(s) ||
  5100. s.startsWith("/service?") ||
  5101. s.startsWith("/")
  5102. )
  5103. return s;
  5104. return buildThumbUrl(s);
  5105. }
  5106. return buildThumbUrl(t);
  5107. })();
  5108. return Vue.h(
  5109. "div",
  5110. {
  5111. class: {
  5112. "knowledge-item-container": true,
  5113. active: this.item.active,
  5114. [this.cardType]: !!this.cardType, // 动态添加卡片类型类名 by xu 20260105
  5115. [this.statusClass]: !!this.statusClass,
  5116. },
  5117. onClick: (e) => {
  5118. this.onItemClick?.(e);
  5119. if (this.__allowSelect() && this.cardClickAction === "single") {
  5120. // 功能说明:无 rbarObj 时不允许单选互斥 by xu 20260122
  5121. this.toggleSelectExclusive?.(e);
  5122. }
  5123. }, // 功能:卡片主体点击动作(view/single) by xu 20260109
  5124. // 移除固定宽度,由 CSS min-width 控制 by xu 20260105
  5125. },
  5126. [
  5127. // 右上角状态图标区域 by xu 20260105
  5128. this.item?.statusIcons?.length > 0 &&
  5129. Vue.h(
  5130. "div",
  5131. { class: "card-status-icons" },
  5132. this.item.statusIcons.map((icon) =>
  5133. Vue.h(SsIcon, {
  5134. class: `status-icon ${icon.class}`,
  5135. title: icon.title,
  5136. })
  5137. )
  5138. ),
  5139. this.item?.buttons?.length > 0 &&
  5140. Vue.h(
  5141. "div",
  5142. {
  5143. class: "header",
  5144. style:
  5145. this.item?.statusIcons?.length > 0
  5146. ? {
  5147. right: `${this.item.statusIcons.length * 48}px`,
  5148. borderTopRightRadius: "0",
  5149. }
  5150. : {},
  5151. onMouseenter: () => (this.showButtons = true),
  5152. onMouseleave: () => (this.showButtons = false),
  5153. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  5154. },
  5155. [
  5156. // 只在有按钮时渲染设置图标
  5157. // this.item?.buttons?.length > 0 &&
  5158. Vue.h("div", {
  5159. class: "cart-list-setting cart-list-icon",
  5160. title: this.item?.buttons?.[0]?.title,
  5161. }),
  5162. // 鼠标移入时显示按钮列表,与图标同级
  5163. // this.item?.buttons?.length > 0 &&
  5164. this.showButtons &&
  5165. this.item?.buttons?.length > 1 &&
  5166. Vue.h(
  5167. "div",
  5168. {
  5169. class: "cart-list-button-popup",
  5170. },
  5171. this.item.buttons.map((btn) =>
  5172. Vue.h(
  5173. "div",
  5174. {
  5175. onClick: (e) => {
  5176. e.stopPropagation();
  5177. btn.onclick?.();
  5178. },
  5179. },
  5180. [
  5181. // 如果有 class,显示对应的图标
  5182. btn.class &&
  5183. Vue.h(SsCartListIcon, {
  5184. class: [btn.class],
  5185. }),
  5186. // 显示按钮文本
  5187. Vue.h("span", null, btn.title),
  5188. ]
  5189. )
  5190. )
  5191. ),
  5192. ]
  5193. ),
  5194. Vue.h("div", { class: "body" }, [
  5195. Vue.h("div", { class: "box-header" }, [
  5196. Vue.h("div", `${this.item.title}`),
  5197. ]),
  5198. Vue.h(
  5199. "div",
  5200. {
  5201. class: !hasThumbArea ? "no-thumb box-body" : "box-body",
  5202. },
  5203. [
  5204. hasThumbArea
  5205. ? thumbSrc
  5206. ? Vue.h("div", { class: "left" }, [
  5207. Vue.h("img", {
  5208. src: thumbSrc,
  5209. alt: "Thumbnail",
  5210. class: "imgUnHandle",
  5211. style: {
  5212. "object-fit": "cover",
  5213. width: "100%",
  5214. height: "100%",
  5215. },
  5216. }),
  5217. ])
  5218. : Vue.h(
  5219. // 功能:无图占位(ss-icon + biz icon,居中) by xu 20260109
  5220. "div",
  5221. { class: "left ss-objlist-thumbPlaceholder" },
  5222. [
  5223. Vue.h(SsIcon, {
  5224. class: `${this.getBizThumbIconClass()} ss-objlist-thumbIcon`,
  5225. }),
  5226. ]
  5227. )
  5228. : null,
  5229. Vue.h(
  5230. "div",
  5231. {
  5232. class: "right",
  5233. },
  5234. (() => {
  5235. const model = this.buildRightTextLines(); // 功能:右侧文字区新规则(第二部分/第三部分优先级) by xu 20260108
  5236. const hasAny = !!(model?.hasSecond || model?.hasThird);
  5237. if (!hasAny) return [];
  5238. const children = [];
  5239. // 第二部分:L1-L3(摘要优先,其次 tags;不足留空;超出 L3 ...) by xu 20260108
  5240. if (model.hasSecond) {
  5241. if (model.secondKind === "summary") {
  5242. children.push(
  5243. Vue.h(
  5244. "div",
  5245. {
  5246. class:
  5247. "ss-card-text__line ss-card-text__secondBlock",
  5248. },
  5249. [
  5250. Vue.h(
  5251. "div",
  5252. {
  5253. class: "ss-card-text__secondSummary",
  5254. title: model.summary,
  5255. },
  5256. model.summary
  5257. ),
  5258. Vue.h("span", {
  5259. class: [
  5260. "ss-card-text__ellipsisHit",
  5261. "ss-card-text__ellipsisHit--second",
  5262. this.ellipsisVisible?.secondSummary
  5263. ? "is-on"
  5264. : "",
  5265. ],
  5266. title: "查看完整摘要",
  5267. onMouseenter: (e) =>
  5268. this.showTextPopoverFor(
  5269. e?.currentTarget,
  5270. "second-summary"
  5271. ),
  5272. onClick: (e) => {
  5273. e?.stopPropagation?.();
  5274. this.showTextPopoverFor(
  5275. e?.currentTarget,
  5276. "second-summary"
  5277. );
  5278. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5279. onMouseleave: () => this.hideTextPopoverLater(),
  5280. }),
  5281. ]
  5282. )
  5283. );
  5284. } else if (model.secondKind === "tags") {
  5285. children.push(
  5286. Vue.h(
  5287. "div",
  5288. {
  5289. class: [
  5290. "ss-card-text__line",
  5291. model.secondFull
  5292. ? "ss-card-text__secondFullBlock"
  5293. : "ss-card-text__secondBlock",
  5294. ],
  5295. },
  5296. [
  5297. // 功能:仅标签时占满 4 行 by xu 20260109
  5298. Vue.h(
  5299. "div",
  5300. { class: "ss-card-text__secondTags" },
  5301. [
  5302. ...model.secondTagsHead.map((t) =>
  5303. Vue.h(
  5304. "div",
  5305. {
  5306. class: "ss-card-text__tagLine",
  5307. title: t,
  5308. },
  5309. t
  5310. )
  5311. ),
  5312. // 第三行:平铺剩余(可能为空) by xu 20260108
  5313. Vue.h(
  5314. "div",
  5315. {
  5316. class:
  5317. "ss-card-text__tagLine is-last ss-card-text__tagLineLast",
  5318. title: model.secondTagsLast,
  5319. },
  5320. model.secondTagsLast
  5321. ),
  5322. ].filter(Boolean)
  5323. ),
  5324. // 只在最后一行出现 ... 时才触发 goheight by xu 20260108
  5325. Vue.h("span", {
  5326. class: [
  5327. "ss-card-text__ellipsisHit",
  5328. "ss-card-text__ellipsisHit--second",
  5329. this.ellipsisVisible?.secondTags
  5330. ? "is-on"
  5331. : "",
  5332. ],
  5333. title: "查看完整物品参数",
  5334. onMouseenter: (e) =>
  5335. this.showTextPopoverFor(
  5336. e?.currentTarget,
  5337. "second-tags"
  5338. ),
  5339. onClick: (e) => {
  5340. e?.stopPropagation?.();
  5341. this.showTextPopoverFor(
  5342. e?.currentTarget,
  5343. "second-tags"
  5344. );
  5345. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5346. onMouseleave: () => this.hideTextPopoverLater(),
  5347. }),
  5348. ]
  5349. )
  5350. );
  5351. }
  5352. }
  5353. // 第三部分:默认 L4;第二部分为空则占满 L1-L4 by xu 20260108
  5354. if (model.hasThird) {
  5355. if (model.thirdFull) {
  5356. children.push(
  5357. Vue.h(
  5358. "div",
  5359. {
  5360. class:
  5361. "ss-card-text__line ss-card-text__thirdFullBlock",
  5362. },
  5363. [
  5364. Vue.h(
  5365. "div",
  5366. {
  5367. class: "ss-card-text__thirdFull",
  5368. title: model.thirdText,
  5369. },
  5370. model.thirdText
  5371. ),
  5372. Vue.h("span", {
  5373. class: [
  5374. "ss-card-text__ellipsisHit",
  5375. "ss-card-text__ellipsisHit--third",
  5376. this.ellipsisVisible?.thirdFull
  5377. ? "is-on"
  5378. : "",
  5379. ],
  5380. title: "查看完整信息",
  5381. onMouseenter: (e) =>
  5382. this.showTextPopoverFor(
  5383. e?.currentTarget,
  5384. "third-full"
  5385. ),
  5386. onClick: (e) => {
  5387. e?.stopPropagation?.();
  5388. this.showTextPopoverFor(
  5389. e?.currentTarget,
  5390. "third-full"
  5391. );
  5392. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5393. onMouseleave: () => this.hideTextPopoverLater(),
  5394. }),
  5395. ]
  5396. )
  5397. );
  5398. } else {
  5399. children.push(
  5400. Vue.h(
  5401. "div",
  5402. {
  5403. class:
  5404. "ss-card-text__line ss-card-text__thirdLineWrap",
  5405. },
  5406. [
  5407. Vue.h(
  5408. "div",
  5409. {
  5410. class: "ss-card-text__thirdLine",
  5411. title: model.thirdText,
  5412. },
  5413. model.thirdText
  5414. ),
  5415. Vue.h("span", {
  5416. class: [
  5417. "ss-card-text__ellipsisHit",
  5418. "ss-card-text__ellipsisHit--third",
  5419. this.ellipsisVisible?.third ? "is-on" : "",
  5420. ],
  5421. title: "查看完整信息",
  5422. onMouseenter: (e) =>
  5423. this.showTextPopoverFor(
  5424. e?.currentTarget,
  5425. "third"
  5426. ),
  5427. onClick: (e) => {
  5428. e?.stopPropagation?.();
  5429. this.showTextPopoverFor(
  5430. e?.currentTarget,
  5431. "third"
  5432. );
  5433. }, // 功能:点击 ... 也可展开(避免 hover 受遮挡) by xu 20260109
  5434. onMouseleave: () => this.hideTextPopoverLater(),
  5435. }),
  5436. ]
  5437. )
  5438. );
  5439. }
  5440. }
  5441. // hover 展开浮层:宽度=右侧文字区,底对齐向上展开,带阴影 by xu 20260108
  5442. // popover 作为 `.right` 的 sibling 渲染,避免被 `.ss-card-text{overflow:hidden}` 裁剪 by xu 20260108
  5443. const popover =
  5444. this.showTextPopover &&
  5445. Vue.h(
  5446. "div",
  5447. {
  5448. class: "ss-card-text-popover",
  5449. style: { bottom: this.textPopoverBottom + "px" },
  5450. onMouseenter: () => {
  5451. this.clearHideTextPopoverTimer();
  5452. this.showTextPopover = true;
  5453. },
  5454. onMouseleave: () => this.hideTextPopoverLater(),
  5455. },
  5456. (() => {
  5457. const p = this.textPopoverPayload || {};
  5458. if (p.kind === "second-summary" && p.text) {
  5459. return [
  5460. Vue.h(
  5461. "div",
  5462. { class: "ss-card-text-popover__summary" },
  5463. p.text
  5464. ),
  5465. ];
  5466. }
  5467. if (Array.isArray(p.lines)) {
  5468. return [
  5469. Vue.h(
  5470. "div",
  5471. { class: "ss-card-text-popover__kvlist" },
  5472. p.lines.map((t) =>
  5473. Vue.h(
  5474. "div",
  5475. { class: "ss-card-text-popover__kv" },
  5476. t
  5477. )
  5478. )
  5479. ),
  5480. ];
  5481. }
  5482. if (
  5483. (p.kind === "third" || p.kind === "third-full") &&
  5484. p.text
  5485. ) {
  5486. return [
  5487. Vue.h(
  5488. "div",
  5489. { class: "ss-card-text-popover__objno" },
  5490. p.text
  5491. ),
  5492. ];
  5493. }
  5494. return [];
  5495. })()
  5496. );
  5497. return [
  5498. Vue.h("div", { class: "ss-card-text" }, children),
  5499. popover,
  5500. ];
  5501. })()
  5502. ),
  5503. ]
  5504. ),
  5505. ]),
  5506. // 右下角卡片选择图标 by xu 20260105
  5507. this.__allowSelect()
  5508. ? Vue.h(SsIcon, {
  5509. class: this.item?._ssSelected
  5510. ? "card-icon icon-cardChk-on"
  5511. : "card-icon icon-cardChk",
  5512. onClick: this.toggleSelect,
  5513. })
  5514. : null,
  5515. // 选中后底部线条 by xu 20260105
  5516. this.__allowSelect() &&
  5517. this.item?._ssSelected &&
  5518. Vue.h("div", { class: "select-bottom-line" }),
  5519. ]
  5520. );
  5521. },
  5522. };
  5523. // 二级对象卡片:复用一级对象新卡片布局/省略浮层,但去掉勾选与 single 选中,仅支持点击查看 by xu 20260115
  5524. const SsCObjCardList = {
  5525. name: "SsCObjCardList",
  5526. props: {
  5527. ssObjName: { type: String, default: "" }, // 功能说明:业务对象名(用于默认缩略图 icon) by xu 20260115
  5528. item: {
  5529. type: Object,
  5530. required: true,
  5531. },
  5532. },
  5533. emits: ["click", "change"],
  5534. setup(props, { emit }) {
  5535. const item = props.item;
  5536. const cardType = Vue.computed(() => {
  5537. if (!item.thumb && !item.thumbType) return "";
  5538. return item.thumbType === "thumbnail" ? "card-thumbnail" : "card-photo";
  5539. });
  5540. const statusClass = Vue.computed(() => {
  5541. if (!item.status) return "";
  5542. const statusMap = {
  5543. available: "status-available",
  5544. unavailable: "status-unavailable",
  5545. disabled: "status-disabled",
  5546. };
  5547. return statusMap[item.status] || "";
  5548. });
  5549. const onItemClick = (e) => {
  5550. // 清除所有类型卡片的 active 状态(保持与一级对象一致) by xu 20260115
  5551. const allListCards = document.querySelectorAll(
  5552. ".knowledge-item-container"
  5553. );
  5554. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  5555. allListCards.forEach((card) => card.classList.remove("active"));
  5556. allFolderCards.forEach((card) => card.classList.remove("active"));
  5557. e.currentTarget.classList.add("active");
  5558. // 二级对象卡片:点击仅查看(调用 item.onclick) by xu 20260115
  5559. props.item.onclick?.();
  5560. emit("click", props.item);
  5561. };
  5562. const onItemChange = (e) => {
  5563. e.stopPropagation();
  5564. props.item.buttons?.[0]?.onclick?.();
  5565. };
  5566. return { item, cardType, statusClass, onItemClick, onItemChange };
  5567. },
  5568. data() {
  5569. return {
  5570. showButtons: false,
  5571. showTextPopover: false, // 功能:右侧文字区 hover 展示全量 by xu 20260115
  5572. textPopoverType: "", // second-summary / second-tags / third / third-full by xu 20260115
  5573. textPopoverBottom: 0, // 功能:popover 从当前省略行位置向上展开 by xu 20260115
  5574. hideTextPopoverTimer: null, // 功能:鼠标从省略行移到浮层的缓冲 by xu 20260115
  5575. textPopoverPayload: null, // { kind, text?, lines? } by xu 20260115
  5576. ellipsisVisible: {
  5577. secondSummary: false,
  5578. secondTags: false,
  5579. third: false,
  5580. thirdFull: false,
  5581. }, // 功能:只在真实出现 ... 时才显示命中区/允许 goheight by xu 20260115
  5582. };
  5583. },
  5584. methods: {
  5585. getBizThumbIconClass() {
  5586. // 功能:无缩略图时,用业务对象 icon 做默认图(ss-icon + icon-obj-xx) by xu 20260115
  5587. const name = String(
  5588. this.ssObjName ||
  5589. this.item?.ssObjName ||
  5590. this.$root?.ssObjName ||
  5591. window?.ss?.dom?.ssObjName ||
  5592. ""
  5593. ).trim();
  5594. if (!name) return "";
  5595. return "icon-obj-" + name;
  5596. },
  5597. buildRightTextLines() {
  5598. // 功能:沿用一级对象卡片右侧文字区规则 by xu 20260115
  5599. const item = this.item || {};
  5600. const summary = String(item?.desc ?? "").trim();
  5601. const objNum = String(item?.objNum ?? "").trim();
  5602. const categoryArr = Array.isArray(item?.category) ? item.category : [];
  5603. const tagsArr = Array.isArray(item?.tags) ? item.tags : [];
  5604. const hasTags = tagsArr.length > 0;
  5605. const hasCategory = categoryArr.length > 0;
  5606. const secondKind = summary ? "summary" : hasTags ? "tags" : "";
  5607. const hasSecond = !!secondKind;
  5608. const thirdKind = objNum ? "objNum" : hasCategory ? "category" : "";
  5609. const hasThird = !!thirdKind;
  5610. const thirdFull = !hasSecond && hasThird;
  5611. const secondFull = hasSecond && !hasThird && secondKind === "tags";
  5612. const toValueText = (obj) => {
  5613. // 功能说明:类目/物品参数回显展示 key: value(否则只显示值看不懂) by xu 20260115
  5614. const [k, v] = Object.entries(obj || {})[0] || ["", ""];
  5615. const key = k !== undefined && k !== null ? String(k).trim() : "";
  5616. const val = v !== undefined && v !== null ? String(v).trim() : "";
  5617. if (key && val) return key + ":" + val;
  5618. if (val) return val;
  5619. if (key) return key;
  5620. return "";
  5621. };
  5622. const toLineList = (arr) =>
  5623. (arr || [])
  5624. .map(toValueText)
  5625. .map((s) => String(s ?? "").trim())
  5626. .filter(Boolean);
  5627. const secondTagsMaxLines = secondFull ? 4 : 3;
  5628. const secondTagsLinesFull = toLineList(tagsArr);
  5629. const secondTagsHead = secondTagsLinesFull.slice(
  5630. 0,
  5631. Math.max(0, secondTagsMaxLines - 1)
  5632. );
  5633. const secondTagsTail = secondTagsLinesFull.slice(
  5634. Math.max(0, secondTagsMaxLines - 1)
  5635. );
  5636. const secondTagsLast =
  5637. secondTagsTail.length <= 1
  5638. ? secondTagsTail[0] || ""
  5639. : secondTagsTail.join(" ");
  5640. const categoryLinesFull = toLineList(categoryArr);
  5641. const categoryLine = categoryLinesFull.join(" ");
  5642. const thirdText =
  5643. thirdKind === "objNum"
  5644. ? objNum
  5645. : thirdKind === "category"
  5646. ? categoryLine
  5647. : "";
  5648. return {
  5649. secondKind,
  5650. thirdKind,
  5651. hasSecond,
  5652. hasThird,
  5653. thirdFull,
  5654. secondFull,
  5655. summary,
  5656. secondTagsMaxLines,
  5657. secondTagsHead,
  5658. secondTagsLast,
  5659. secondTagsLinesFull,
  5660. objNum,
  5661. categoryLine,
  5662. categoryLinesFull,
  5663. thirdText,
  5664. };
  5665. },
  5666. measureTextOverflowByLines(text, maxLines, width) {
  5667. const w = Number(width) || 0;
  5668. if (!w || !text) return false;
  5669. const probe = document.createElement("div");
  5670. probe.style.position = "fixed";
  5671. probe.style.left = "-99999px";
  5672. probe.style.top = "0";
  5673. probe.style.width = w + "px";
  5674. probe.style.fontSize = "18px";
  5675. probe.style.lineHeight = "24px";
  5676. probe.style.whiteSpace = "normal";
  5677. probe.style.wordBreak = "break-word";
  5678. probe.style.visibility = "hidden";
  5679. probe.textContent = text;
  5680. document.body.appendChild(probe);
  5681. const h = probe.getBoundingClientRect().height || 0;
  5682. document.body.removeChild(probe);
  5683. return h > maxLines * 24 + 1;
  5684. },
  5685. measureSingleLineOverflow(text, width) {
  5686. const w = Number(width) || 0;
  5687. if (!w || !text) return false;
  5688. const probe = document.createElement("span");
  5689. probe.style.position = "fixed";
  5690. probe.style.left = "-99999px";
  5691. probe.style.top = "0";
  5692. probe.style.display = "inline-block";
  5693. probe.style.maxWidth = w + "px";
  5694. probe.style.fontSize = "18px";
  5695. probe.style.lineHeight = "24px";
  5696. probe.style.whiteSpace = "nowrap";
  5697. probe.style.visibility = "hidden";
  5698. probe.textContent = text;
  5699. document.body.appendChild(probe);
  5700. const overflow =
  5701. (probe.scrollWidth || 0) > (probe.clientWidth || w) + 1;
  5702. document.body.removeChild(probe);
  5703. return overflow;
  5704. },
  5705. refreshEllipsisVisible() {
  5706. // 功能:刷新「是否出现 ...」状态(用于控制命中区显示) by xu 20260115
  5707. try {
  5708. const right = this.$el?.querySelector?.(".right");
  5709. const rawWidth =
  5710. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  5711. const width = Math.max(0, Math.round(rawWidth));
  5712. const model = this.buildRightTextLines();
  5713. const next = {
  5714. secondSummary: false,
  5715. secondTags: false,
  5716. third: false,
  5717. thirdFull: false,
  5718. };
  5719. if (model.secondKind === "summary" && model.summary) {
  5720. next.secondSummary = this.measureTextOverflowByLines(
  5721. model.summary,
  5722. 3,
  5723. width
  5724. );
  5725. }
  5726. if (model.secondKind === "tags") {
  5727. next.secondTags = this.measureSingleLineOverflow(
  5728. model.secondTagsLast,
  5729. width
  5730. ); // 功能说明:tags 仅看最后一行是否溢出 by xu 20260115
  5731. }
  5732. if (model.hasThird && !model.thirdFull) {
  5733. next.third = this.measureSingleLineOverflow(model.thirdText, width);
  5734. }
  5735. if (model.hasThird && model.thirdFull) {
  5736. next.thirdFull = this.measureTextOverflowByLines(
  5737. model.thirdText,
  5738. 4,
  5739. width
  5740. );
  5741. }
  5742. const prev = this.ellipsisVisible || {};
  5743. const changed =
  5744. prev.secondSummary !== next.secondSummary ||
  5745. prev.secondTags !== next.secondTags ||
  5746. prev.third !== next.third ||
  5747. prev.thirdFull !== next.thirdFull;
  5748. if (changed) this.ellipsisVisible = next;
  5749. } catch (e) {
  5750. // ignore by xu 20260115
  5751. }
  5752. },
  5753. clearHideTextPopoverTimer() {
  5754. if (this.hideTextPopoverTimer) {
  5755. clearTimeout(this.hideTextPopoverTimer);
  5756. this.hideTextPopoverTimer = null;
  5757. }
  5758. },
  5759. hideTextPopoverLater() {
  5760. this.clearHideTextPopoverTimer();
  5761. this.hideTextPopoverTimer = setTimeout(() => {
  5762. this.showTextPopover = false;
  5763. this.textPopoverType = "";
  5764. this.textPopoverPayload = null;
  5765. }, 120);
  5766. },
  5767. showTextPopoverFor(el, kind) {
  5768. const model = this.buildRightTextLines();
  5769. const lineEl = el?.closest?.(".ss-card-text__line") || el;
  5770. const right = lineEl?.closest?.(".right") || el?.closest?.(".right");
  5771. const rawWidth =
  5772. right?.getBoundingClientRect?.().width || right?.clientWidth || 0;
  5773. const width = Math.max(0, Math.round(rawWidth));
  5774. const overflowed =
  5775. kind === "second-summary"
  5776. ? this.measureTextOverflowByLines(model.summary, 3, width)
  5777. : kind === "second-tags"
  5778. ? this.measureSingleLineOverflow(model.secondTagsLast, width)
  5779. : kind === "third"
  5780. ? this.measureSingleLineOverflow(model.thirdText, width)
  5781. : this.measureTextOverflowByLines(model.thirdText, 4, width);
  5782. if (!overflowed) return;
  5783. let payload = null;
  5784. if (kind === "second-summary") {
  5785. if (model.summary) payload = { kind, text: model.summary };
  5786. } else if (kind === "second-tags") {
  5787. if (
  5788. Array.isArray(model.secondTagsLinesFull) &&
  5789. model.secondTagsLinesFull.length
  5790. ) {
  5791. payload = { kind, lines: model.secondTagsLinesFull };
  5792. }
  5793. } else if (kind === "third") {
  5794. if (
  5795. model.thirdKind === "category" &&
  5796. Array.isArray(model.categoryLinesFull) &&
  5797. model.categoryLinesFull.length
  5798. ) {
  5799. payload = { kind, lines: model.categoryLinesFull };
  5800. } else if (model.thirdText) {
  5801. payload = { kind, text: model.thirdText };
  5802. }
  5803. } else if (kind === "third-full") {
  5804. if (
  5805. model.thirdKind === "category" &&
  5806. Array.isArray(model.categoryLinesFull) &&
  5807. model.categoryLinesFull.length
  5808. ) {
  5809. payload = { kind, lines: model.categoryLinesFull };
  5810. } else if (model.thirdText) {
  5811. payload = { kind, text: model.thirdText };
  5812. }
  5813. }
  5814. if (!payload) return;
  5815. this.clearHideTextPopoverTimer();
  5816. const container = lineEl?.closest?.(".right");
  5817. const containerRect = container?.getBoundingClientRect?.();
  5818. const lineRect = lineEl?.getBoundingClientRect?.();
  5819. if (containerRect && lineRect) {
  5820. const bottom = Math.max(
  5821. 0,
  5822. Math.round(containerRect.bottom - lineRect.bottom)
  5823. );
  5824. this.textPopoverBottom = bottom;
  5825. } else {
  5826. this.textPopoverBottom = 0;
  5827. }
  5828. this.textPopoverPayload = payload;
  5829. this.textPopoverType = kind;
  5830. this.showTextPopover = true;
  5831. },
  5832. },
  5833. mounted() {
  5834. this.$nextTick?.(() => {
  5835. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5836. });
  5837. this.__ssCObjCardResizeHandler = () => this.refreshEllipsisVisible?.(); // 功能说明:窗口变化时刷新 ... 显示 by xu 20260115
  5838. window.addEventListener?.("resize", this.__ssCObjCardResizeHandler);
  5839. },
  5840. updated() {
  5841. this.$nextTick?.(() => {
  5842. requestAnimationFrame(() => this.refreshEllipsisVisible?.());
  5843. });
  5844. },
  5845. beforeUnmount() {
  5846. this.clearHideTextPopoverTimer?.();
  5847. if (this.__ssCObjCardResizeHandler) {
  5848. window.removeEventListener?.("resize", this.__ssCObjCardResizeHandler);
  5849. this.__ssCObjCardResizeHandler = null;
  5850. }
  5851. },
  5852. render() {
  5853. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  5854. const SsIcon = Vue.resolveComponent("ss-icon");
  5855. const hasThumbArea = !!(this.item?.thumb || this.item?.thumbType);
  5856. const thumbSrc = (() => {
  5857. // 功能说明:兼容 thumb 为 raw path 或 {val}/{value},组件内统一转为 dlByHttp URL by xu 20260122
  5858. const t = this.item?.thumb;
  5859. if (!t) return "";
  5860. if (typeof t === "string") {
  5861. const s = t.trim();
  5862. if (!s) return "";
  5863. if (
  5864. /^https?:\/\//i.test(s) ||
  5865. s.startsWith("/service?") ||
  5866. s.startsWith("/")
  5867. )
  5868. return s;
  5869. return buildThumbUrl(s);
  5870. }
  5871. return buildThumbUrl(t);
  5872. })();
  5873. return Vue.h(
  5874. "div",
  5875. {
  5876. class: {
  5877. "knowledge-item-container": true,
  5878. active: this.item.active,
  5879. [this.cardType]: !!this.cardType,
  5880. [this.statusClass]: !!this.statusClass,
  5881. },
  5882. onClick: (e) => this.onItemClick?.(e), // 功能说明:二级对象卡片点击仅查看 by xu 20260115
  5883. },
  5884. [
  5885. this.item?.statusIcons?.length > 0 &&
  5886. Vue.h(
  5887. "div",
  5888. { class: "card-status-icons" },
  5889. this.item.statusIcons.map((icon) =>
  5890. Vue.h(SsIcon, {
  5891. class: "status-icon " + icon.class,
  5892. title: icon.title,
  5893. })
  5894. )
  5895. ),
  5896. this.item?.buttons?.length > 0 &&
  5897. Vue.h(
  5898. "div",
  5899. {
  5900. class: "header",
  5901. style:
  5902. this.item?.statusIcons?.length > 0
  5903. ? {
  5904. right: String(this.item.statusIcons.length * 48) + "px",
  5905. borderTopRightRadius: "0",
  5906. }
  5907. : {},
  5908. onMouseenter: () => (this.showButtons = true),
  5909. onMouseleave: () => (this.showButtons = false),
  5910. onClick: (e) => this.onItemChange(e),
  5911. },
  5912. [
  5913. Vue.h("div", {
  5914. class: "cart-list-setting cart-list-icon",
  5915. title: this.item?.buttons?.[0]?.title,
  5916. }),
  5917. this.showButtons &&
  5918. this.item?.buttons?.length > 1 &&
  5919. Vue.h(
  5920. "div",
  5921. { class: "cart-list-button-popup" },
  5922. this.item.buttons.map((btn) =>
  5923. Vue.h(
  5924. "div",
  5925. {
  5926. onClick: (e) => {
  5927. e.stopPropagation();
  5928. btn.onclick?.();
  5929. },
  5930. },
  5931. [
  5932. btn.class &&
  5933. Vue.h(SsCartListIcon, { class: [btn.class] }),
  5934. Vue.h("span", null, btn.title),
  5935. ]
  5936. )
  5937. )
  5938. ),
  5939. ]
  5940. ),
  5941. Vue.h("div", { class: "body" }, [
  5942. Vue.h("div", { class: "box-header" }, [
  5943. Vue.h("div", String(this.item.title || "")),
  5944. ]),
  5945. Vue.h(
  5946. "div",
  5947. { class: !hasThumbArea ? "no-thumb box-body" : "box-body" },
  5948. [
  5949. hasThumbArea
  5950. ? thumbSrc
  5951. ? Vue.h("div", { class: "left" }, [
  5952. Vue.h("img", {
  5953. src: thumbSrc,
  5954. alt: "Thumbnail",
  5955. class: "imgUnHandle",
  5956. style: {
  5957. "object-fit": "cover",
  5958. width: "100%",
  5959. height: "100%",
  5960. },
  5961. }),
  5962. ])
  5963. : Vue.h(
  5964. "div",
  5965. { class: "left ss-objlist-thumbPlaceholder" },
  5966. [
  5967. Vue.h(SsIcon, {
  5968. class:
  5969. this.getBizThumbIconClass() +
  5970. " ss-objlist-thumbIcon",
  5971. }),
  5972. ]
  5973. )
  5974. : null,
  5975. Vue.h(
  5976. "div",
  5977. { class: "right" },
  5978. (() => {
  5979. const model = this.buildRightTextLines();
  5980. const hasAny = !!(model?.hasSecond || model?.hasThird);
  5981. if (!hasAny) return [];
  5982. const children = [];
  5983. if (model.hasSecond && model.secondKind === "summary") {
  5984. children.push(
  5985. Vue.h(
  5986. "div",
  5987. {
  5988. class:
  5989. "ss-card-text__line ss-card-text__secondBlock",
  5990. },
  5991. [
  5992. Vue.h(
  5993. "div",
  5994. {
  5995. class: "ss-card-text__secondSummary",
  5996. title: model.summary,
  5997. },
  5998. model.summary
  5999. ),
  6000. Vue.h("span", {
  6001. class: [
  6002. "ss-card-text__ellipsisHit",
  6003. "ss-card-text__ellipsisHit--second",
  6004. this.ellipsisVisible?.secondSummary
  6005. ? "is-on"
  6006. : "",
  6007. ],
  6008. title: "查看完整信息",
  6009. onMouseenter: (e) =>
  6010. this.showTextPopoverFor(
  6011. e?.currentTarget,
  6012. "second-summary"
  6013. ),
  6014. onClick: (e) => {
  6015. e?.stopPropagation?.();
  6016. this.showTextPopoverFor(
  6017. e?.currentTarget,
  6018. "second-summary"
  6019. );
  6020. },
  6021. onMouseleave: () => this.hideTextPopoverLater(),
  6022. }),
  6023. ]
  6024. )
  6025. );
  6026. }
  6027. if (model.hasSecond && model.secondKind === "tags") {
  6028. children.push(
  6029. Vue.h(
  6030. "div",
  6031. {
  6032. class: [
  6033. "ss-card-text__line",
  6034. model.secondFull
  6035. ? "ss-card-text__secondFullBlock"
  6036. : "ss-card-text__secondBlock",
  6037. ],
  6038. },
  6039. [
  6040. Vue.h(
  6041. "div",
  6042. { class: "ss-card-text__secondTags" },
  6043. [
  6044. ...model.secondTagsHead.map((t) =>
  6045. Vue.h(
  6046. "div",
  6047. {
  6048. class: "ss-card-text__tagLine",
  6049. title: t,
  6050. },
  6051. t
  6052. )
  6053. ),
  6054. Vue.h(
  6055. "div",
  6056. {
  6057. class:
  6058. "ss-card-text__tagLine is-last ss-card-text__tagLineLast",
  6059. title: model.secondTagsLast,
  6060. },
  6061. model.secondTagsLast
  6062. ),
  6063. ]
  6064. ),
  6065. Vue.h("span", {
  6066. class: [
  6067. "ss-card-text__ellipsisHit",
  6068. "ss-card-text__ellipsisHit--second",
  6069. this.ellipsisVisible?.secondTags ? "is-on" : "",
  6070. ],
  6071. title: "查看完整信息",
  6072. onMouseenter: (e) =>
  6073. this.showTextPopoverFor(
  6074. e?.currentTarget,
  6075. "second-tags"
  6076. ),
  6077. onClick: (e) => {
  6078. e?.stopPropagation?.();
  6079. this.showTextPopoverFor(
  6080. e?.currentTarget,
  6081. "second-tags"
  6082. );
  6083. },
  6084. onMouseleave: () => this.hideTextPopoverLater(),
  6085. }),
  6086. ]
  6087. )
  6088. );
  6089. }
  6090. if (model.hasThird) {
  6091. if (model.thirdFull) {
  6092. children.push(
  6093. Vue.h(
  6094. "div",
  6095. {
  6096. class:
  6097. "ss-card-text__line ss-card-text__thirdFullBlock",
  6098. },
  6099. [
  6100. Vue.h(
  6101. "div",
  6102. {
  6103. class: "ss-card-text__thirdFull",
  6104. title: model.thirdText,
  6105. },
  6106. model.thirdText
  6107. ),
  6108. Vue.h("span", {
  6109. class: [
  6110. "ss-card-text__ellipsisHit",
  6111. "ss-card-text__ellipsisHit--third",
  6112. this.ellipsisVisible?.thirdFull
  6113. ? "is-on"
  6114. : "",
  6115. ],
  6116. title: "查看完整信息",
  6117. onMouseenter: (e) =>
  6118. this.showTextPopoverFor(
  6119. e?.currentTarget,
  6120. "third-full"
  6121. ),
  6122. onClick: (e) => {
  6123. e?.stopPropagation?.();
  6124. this.showTextPopoverFor(
  6125. e?.currentTarget,
  6126. "third-full"
  6127. );
  6128. },
  6129. onMouseleave: () => this.hideTextPopoverLater(),
  6130. }),
  6131. ]
  6132. )
  6133. );
  6134. } else {
  6135. children.push(
  6136. Vue.h(
  6137. "div",
  6138. {
  6139. class:
  6140. "ss-card-text__line ss-card-text__thirdLineWrap",
  6141. },
  6142. [
  6143. Vue.h(
  6144. "div",
  6145. {
  6146. class: "ss-card-text__thirdLine",
  6147. title: model.thirdText,
  6148. },
  6149. model.thirdText
  6150. ),
  6151. Vue.h("span", {
  6152. class: [
  6153. "ss-card-text__ellipsisHit",
  6154. "ss-card-text__ellipsisHit--third",
  6155. this.ellipsisVisible?.third ? "is-on" : "",
  6156. ],
  6157. title: "查看完整信息",
  6158. onMouseenter: (e) =>
  6159. this.showTextPopoverFor(
  6160. e?.currentTarget,
  6161. "third"
  6162. ),
  6163. onClick: (e) => {
  6164. e?.stopPropagation?.();
  6165. this.showTextPopoverFor(
  6166. e?.currentTarget,
  6167. "third"
  6168. );
  6169. },
  6170. onMouseleave: () => this.hideTextPopoverLater(),
  6171. }),
  6172. ]
  6173. )
  6174. );
  6175. }
  6176. }
  6177. const popover =
  6178. this.showTextPopover &&
  6179. Vue.h(
  6180. "div",
  6181. {
  6182. class: "ss-card-text-popover",
  6183. style: { bottom: this.textPopoverBottom + "px" },
  6184. onMouseenter: () => {
  6185. this.clearHideTextPopoverTimer();
  6186. this.showTextPopover = true;
  6187. },
  6188. onMouseleave: () => this.hideTextPopoverLater(),
  6189. },
  6190. (() => {
  6191. const p = this.textPopoverPayload || {};
  6192. if (p.kind === "second-summary" && p.text) {
  6193. return [
  6194. Vue.h(
  6195. "div",
  6196. { class: "ss-card-text-popover__summary" },
  6197. p.text
  6198. ),
  6199. ];
  6200. }
  6201. if (Array.isArray(p.lines)) {
  6202. return [
  6203. Vue.h(
  6204. "div",
  6205. { class: "ss-card-text-popover__kvlist" },
  6206. p.lines.map((t) =>
  6207. Vue.h(
  6208. "div",
  6209. { class: "ss-card-text-popover__kv" },
  6210. t
  6211. )
  6212. )
  6213. ),
  6214. ];
  6215. }
  6216. if (
  6217. (p.kind === "third" || p.kind === "third-full") &&
  6218. p.text
  6219. ) {
  6220. return [
  6221. Vue.h(
  6222. "div",
  6223. { class: "ss-card-text-popover__objno" },
  6224. p.text
  6225. ),
  6226. ];
  6227. }
  6228. return [];
  6229. })()
  6230. );
  6231. return [
  6232. Vue.h("div", { class: "ss-card-text" }, children),
  6233. popover,
  6234. ];
  6235. })()
  6236. ),
  6237. ]
  6238. ),
  6239. ]),
  6240. ]
  6241. );
  6242. },
  6243. };
  6244. // ss-sidebar 右侧边栏(容器 + 子组件),用于 objList 右侧区域 by xu 20260106
  6245. // 组件文档补全(JSDoc) by xu 20260108
  6246. /**
  6247. * SsSidebarButtons(右侧边栏顶部按钮栏)
  6248. *
  6249. * 用途:
  6250. * - 渲染 objList 右侧顶部快捷操作(预定/入住/退房/清洁...)
  6251. * - 内部复用 `ss-search-button`(项目现有按钮样式/交互)
  6252. *
  6253. * 调用示例:
  6254. * ```html
  6255. * <ss-sidebar-buttons :items="sidebarButtons" />
  6256. * ```
  6257. *
  6258. * Props:
  6259. * - `items`: 按钮配置数组
  6260. * - `{ id, text, icon?, onClick? }`
  6261. *
  6262. * Emits:
  6263. * - `click`:点击按钮时触发,参数为按钮对象
  6264. */
  6265. const SsSidebarButtons = {
  6266. name: "SsSidebarButtons",
  6267. props: {
  6268. items: { type: Array, default: () => [] },
  6269. },
  6270. emits: ["click"],
  6271. render() {
  6272. const SsSearchButton = Vue.resolveComponent("ss-search-button");
  6273. const items = this.items || [];
  6274. if (!items.length) return null;
  6275. return Vue.h(
  6276. "div",
  6277. { class: "ss-sidebar-actions" },
  6278. items.map((btn) =>
  6279. // 顶部操作按钮复用 ss-search-button(先 mock 固定按钮) by xu 20260106
  6280. Vue.h(SsSearchButton, {
  6281. text: btn?.text ?? "",
  6282. iconClass: btn?.iconClass ?? "",
  6283. opt: btn?.opt ?? [],
  6284. checkId: btn?.checkId ?? "0",
  6285. width: btn?.width,
  6286. id: btn?.id,
  6287. onClick: (e) => {
  6288. e?.stopPropagation?.();
  6289. btn?.onClick?.(btn);
  6290. this.$emit("click", btn);
  6291. },
  6292. })
  6293. )
  6294. );
  6295. },
  6296. };
  6297. // 组件文档补全(JSDoc) by xu 20260108
  6298. /**
  6299. * SsSidebarChart(ECharts 容器渲染)
  6300. *
  6301. * 用途:
  6302. * - 仅负责 echarts init / setOption / resize / dispose
  6303. * - 被 `ss-sidebar-chart-hover` 与图表面板复用
  6304. *
  6305. * 调用示例:
  6306. * ```html
  6307. * <ss-sidebar-chart :options="option" height="220px" />
  6308. * ```
  6309. *
  6310. * Props:
  6311. * - `options`:ECharts option(Object)
  6312. * - `height`:容器高度(String)
  6313. */
  6314. const SsSidebarChart = {
  6315. name: "SsSidebarChart",
  6316. props: {
  6317. options: { type: Object, default: () => ({}) },
  6318. height: { type: String, default: "200px" },
  6319. },
  6320. setup(props) {
  6321. const elRef = Vue.ref(null);
  6322. let chart = null;
  6323. const renderChart = () => {
  6324. if (!elRef.value || !window.echarts) return;
  6325. if (!chart) {
  6326. chart = window.echarts.init(elRef.value);
  6327. }
  6328. chart.setOption(props.options || {}, true);
  6329. };
  6330. const resizeChart = () => {
  6331. chart?.resize?.();
  6332. };
  6333. Vue.onMounted(() => {
  6334. renderChart();
  6335. window.addEventListener("resize", resizeChart);
  6336. });
  6337. Vue.onBeforeUnmount(() => {
  6338. window.removeEventListener("resize", resizeChart);
  6339. chart?.dispose?.();
  6340. chart = null;
  6341. });
  6342. Vue.watch(
  6343. () => props.options,
  6344. () => {
  6345. renderChart();
  6346. },
  6347. { deep: true }
  6348. );
  6349. return { elRef };
  6350. },
  6351. render() {
  6352. return Vue.h("div", {
  6353. ref: "elRef",
  6354. style: {
  6355. width: "100%",
  6356. height: this.height,
  6357. // 图表容器不加 padding/border,由外层布局控制 by xu 20260106
  6358. background: "transparent",
  6359. border: "none",
  6360. "border-radius": "0",
  6361. },
  6362. });
  6363. },
  6364. };
  6365. // ss-sidebar-chart-hover:hover 弹出左侧大图(支持图钉/全屏) by xu 20260106
  6366. // 组件文档补全(JSDoc) by xu 20260108
  6367. /**
  6368. * SsSidebarChartHover(小图 + hover 左侧大图预览 + 图钉固定 + 全屏)
  6369. *
  6370. * 用途:
  6371. * - 右侧统计图小卡片:hover 时在左侧弹出大图预览
  6372. * - 预览头部:左侧图标+标题;右侧固定/全屏按钮(icon-base)
  6373. * - 全屏:方案A(浏览器 Fullscreen API)
  6374. *
  6375. * 调用示例(由 ss-sidebar chart panel 内部调用):
  6376. * ```html
  6377. * <ss-sidebar-chart-hover
  6378. * title="校舍建筑面积和总体分布"
  6379. * icon-class="menu-icon icon-obj-jzw"
  6380. * :options="option"
  6381. * height="220px"
  6382. * />
  6383. * ```
  6384. *
  6385. * Props:
  6386. * - `title/iconClass/icon`:用于预览/全屏 header 显示(与面板 header 一致)
  6387. * - `options`:ECharts option
  6388. * - `height`:小图高度
  6389. * - `previewWidth/previewHeight`:预览建议尺寸(会按视口自适应)
  6390. */
  6391. const SsSidebarChartHover = {
  6392. name: "SsSidebarChartHover",
  6393. props: {
  6394. // hover 大图标题/图标(与小图面板 header 一致) by xu 20260108
  6395. title: { type: String, default: "" },
  6396. iconClass: { type: String, default: "" },
  6397. icon: { type: String, default: "" },
  6398. options: { type: Object, default: () => ({}) },
  6399. height: { type: String, default: "220px" },
  6400. // hover 弹窗建议尺寸:默认 1000x650(比例由逻辑统一管控),实际渲染会按比例自适应视口 by xu 20260115
  6401. previewWidth: { type: Number, default: 1000 },
  6402. previewHeight: { type: Number, default: 650 },
  6403. },
  6404. setup(props) {
  6405. const triggerRef = Vue.ref(null);
  6406. const fullscreenRef = Vue.ref(null);
  6407. const open = Vue.ref(false);
  6408. const pinned = Vue.ref(false);
  6409. const fullscreen = Vue.ref(false);
  6410. const hoveringTrigger = Vue.ref(false);
  6411. const hoveringPreview = Vue.ref(false);
  6412. const previewStyle = Vue.ref({});
  6413. let closeTimer = null;
  6414. const updatePreviewPosition = () => {
  6415. const el = triggerRef.value;
  6416. if (!el) return;
  6417. const rect = el.getBoundingClientRect();
  6418. // 功能说明:优先使用 visualViewport(避免浏览器 UI/缩放导致可视区与 innerHeight 偏差,出现预览被遮挡约 70px) by xu 20260116
  6419. const docEl = document.documentElement;
  6420. const vv = window.visualViewport;
  6421. let viewportLeft = Number(vv?.offsetLeft ?? 0) || 0;
  6422. let viewportTop = Number(vv?.offsetTop ?? 0) || 0;
  6423. let vw =
  6424. Number(vv?.width ?? 0) ||
  6425. Number(docEl?.clientWidth || 0) ||
  6426. window.innerWidth;
  6427. let vh =
  6428. Number(vv?.height ?? 0) ||
  6429. Number(docEl?.clientHeight || 0) ||
  6430. window.innerHeight;
  6431. // 功能说明:若页面在 iframe 内,父页面可能裁切 iframe 可见区域(overflow/弹窗容器),需要用“iframe可见区域”做二次约束 by xu 20260116
  6432. try {
  6433. const inIframe = window.top && window.top !== window;
  6434. const frameEl = window.frameElement;
  6435. if (inIframe && frameEl && window.top?.document) {
  6436. const topVv = window.top.visualViewport;
  6437. const topDocEl = window.top.document.documentElement;
  6438. const topVw =
  6439. Number(topVv?.width ?? 0) ||
  6440. Number(topDocEl?.clientWidth || 0) ||
  6441. window.top.innerWidth;
  6442. const topVh =
  6443. Number(topVv?.height ?? 0) ||
  6444. Number(topDocEl?.clientHeight || 0) ||
  6445. window.top.innerHeight;
  6446. const fr = frameEl.getBoundingClientRect?.();
  6447. if (fr && fr.width > 0 && fr.height > 0) {
  6448. const visibleW = Math.max(
  6449. 0,
  6450. Math.min(fr.right, topVw) - Math.max(fr.left, 0)
  6451. );
  6452. const visibleH = Math.max(
  6453. 0,
  6454. Math.min(fr.bottom, topVh) - Math.max(fr.top, 0)
  6455. );
  6456. if (visibleW > 0) {
  6457. vw = Math.min(vw, visibleW);
  6458. viewportLeft = Math.max(0, -fr.left); // iframe内坐标系偏移(左侧被裁切时) by xu 20260116
  6459. }
  6460. if (visibleH > 0) {
  6461. vh = Math.min(vh, visibleH);
  6462. viewportTop = Math.max(0, -fr.top); // iframe内坐标系偏移(顶部被裁切时) by xu 20260116
  6463. }
  6464. }
  6465. }
  6466. } catch (_) {}
  6467. // 预览窗尺寸:优先保证“完整可见”,其次再尽量对齐右侧 header 顶部 by xu 20260116
  6468. const viewportPaddingX = 40;
  6469. const viewportPaddingTop = 20;
  6470. const viewportPaddingBottom = 10;
  6471. // 功能说明:hover 预览框不要覆盖右侧栏,优先放在 ss-sidebar 左侧;必要时动态缩小宽度 by xu 20260115
  6472. const sidebarEl = el.closest ? el.closest(".ss-sidebar") : null;
  6473. const sidebarRect = sidebarEl?.getBoundingClientRect?.();
  6474. const maxWidthByViewport = Math.max(240, vw - viewportPaddingX);
  6475. const maxWidthByLeftSpace = sidebarRect
  6476. ? Math.max(
  6477. 240,
  6478. sidebarRect.left - viewportPaddingX - 14 /* gapFromSidebar */
  6479. )
  6480. : maxWidthByViewport;
  6481. // 功能说明:预览框尺寸按比例(默认 5:3)缩放,并提供最大/最小值约束 by xu 20260115
  6482. const ratio = 3 / 5;
  6483. const minWidth = 320;
  6484. const minHeight = 240;
  6485. const maxHeightByViewport = Math.max(
  6486. minHeight,
  6487. vh - viewportPaddingTop - viewportPaddingBottom
  6488. );
  6489. const maxWidthByProp = Number(props.previewWidth) || 1000;
  6490. const maxHeightByProp = Number(props.previewHeight) || 650;
  6491. // 优先按高度撑满可视区(保证预览完整可见),再根据左侧可用宽度回退 by xu 20260116
  6492. const maxHeight = Math.min(maxHeightByProp, maxHeightByViewport);
  6493. let height = Math.max(minHeight, maxHeight);
  6494. let width = Math.round(height / ratio);
  6495. width = Math.min(
  6496. width,
  6497. maxWidthByProp,
  6498. maxWidthByViewport,
  6499. maxWidthByLeftSpace
  6500. );
  6501. width = Math.max(minWidth, width);
  6502. height = Math.round(width * ratio);
  6503. if (height > maxHeight) {
  6504. height = maxHeight;
  6505. width = Math.round(height / ratio);
  6506. }
  6507. // 默认贴着小图左侧弹出,右边缘与小图左边缘轻微重叠,避免 1px 缝隙导致 hover 闪断 by xu 20260108
  6508. const overlap = 2;
  6509. const gapFromSidebar = 14; // 功能说明:弹窗与右侧边栏留出距离(更不贴近) by xu 20260108
  6510. // 优先:贴在 sidebar 左侧(不压住右侧栏内容) by xu 20260115
  6511. let left = sidebarRect
  6512. ? sidebarRect.left - gapFromSidebar - width + overlap
  6513. : rect.left - width - gapFromSidebar + overlap;
  6514. // 如果左侧空间不足,则贴右侧(兜底,同样重叠) by xu 20260108
  6515. if (left < 0) left = rect.right + gapFromSidebar - overlap;
  6516. left = Math.max(
  6517. viewportLeft,
  6518. Math.min(left, viewportLeft + vw - width)
  6519. );
  6520. // top:优先保证完整可见,然后才贴近 header 顶部 by xu 20260116
  6521. let headerEl = el;
  6522. while (headerEl && !headerEl.classList?.contains("ss-sidebar-panel")) {
  6523. headerEl = headerEl.parentElement;
  6524. }
  6525. let headerRect = headerEl
  6526. ?.querySelector(".ss-sidebar-panel__header")
  6527. ?.getBoundingClientRect();
  6528. let top = headerRect?.top ?? rect.top;
  6529. top = Math.max(
  6530. viewportTop + viewportPaddingTop,
  6531. Math.min(top, viewportTop + vh - height - viewportPaddingBottom)
  6532. );
  6533. previewStyle.value = {
  6534. position: "fixed",
  6535. left: `${Math.round(left)}px`,
  6536. top: `${Math.round(top)}px`,
  6537. width: `${width}px`,
  6538. height: `${height}px`,
  6539. zIndex: 2147483647, // 功能说明:提高层级到接近浏览器上限,避免仍被页面固定栏/弹窗遮挡 by xu 20260116
  6540. };
  6541. };
  6542. const clearCloseTimer = () => {
  6543. if (closeTimer) {
  6544. clearTimeout(closeTimer);
  6545. closeTimer = null;
  6546. }
  6547. };
  6548. const scheduleClose = () => {
  6549. clearCloseTimer();
  6550. if (pinned.value || fullscreen.value) return;
  6551. if (hoveringTrigger.value || hoveringPreview.value) return; // 功能:鼠标在小图/大图之间移动不关闭 by xu 20260108
  6552. closeTimer = setTimeout(() => {
  6553. open.value = false;
  6554. }, 100);
  6555. };
  6556. const openPreview = () => {
  6557. clearCloseTimer();
  6558. updatePreviewPosition();
  6559. open.value = true;
  6560. };
  6561. const togglePin = () => {
  6562. pinned.value = !pinned.value;
  6563. if (pinned.value) {
  6564. open.value = true;
  6565. updatePreviewPosition();
  6566. }
  6567. };
  6568. const toggleFullscreen = () => {
  6569. // 全屏:采用浏览器 Fullscreen API(方案A),不使用遮罩弹窗 by xu 20260108
  6570. if (!fullscreen.value) {
  6571. open.value = false; // 避免同时渲染预览与全屏 by xu 20260108
  6572. fullscreen.value = true;
  6573. Vue.nextTick(() => {
  6574. const el = fullscreenRef.value;
  6575. if (el?.requestFullscreen) {
  6576. el.requestFullscreen().catch(() => {
  6577. // requestFullscreen 失败则回退为非全屏状态 by xu 20260108
  6578. fullscreen.value = false;
  6579. });
  6580. } else {
  6581. fullscreen.value = false;
  6582. }
  6583. });
  6584. } else {
  6585. if (document?.exitFullscreen) {
  6586. document.exitFullscreen().catch(() => {});
  6587. }
  6588. }
  6589. };
  6590. const handleFullscreenChange = () => {
  6591. const isFs = !!document.fullscreenElement;
  6592. fullscreen.value = isFs; // 功能说明:同步 ESC/系统退出全屏状态 by xu 20260108
  6593. if (isFs) {
  6594. open.value = false;
  6595. clearCloseTimer();
  6596. return;
  6597. }
  6598. // 退出全屏后:若固定或仍 hover,则恢复预览,否则关闭 by xu 20260108
  6599. if (pinned.value || hoveringTrigger.value || hoveringPreview.value) {
  6600. open.value = true;
  6601. updatePreviewPosition();
  6602. } else {
  6603. open.value = false;
  6604. }
  6605. };
  6606. Vue.onMounted(() => {
  6607. window.addEventListener("resize", updatePreviewPosition);
  6608. window.addEventListener("scroll", updatePreviewPosition, true);
  6609. document.addEventListener("fullscreenchange", handleFullscreenChange); // 功能说明:监听全屏状态变化 by xu 20260108
  6610. });
  6611. Vue.onBeforeUnmount(() => {
  6612. clearCloseTimer();
  6613. window.removeEventListener("resize", updatePreviewPosition);
  6614. window.removeEventListener("scroll", updatePreviewPosition, true);
  6615. document.removeEventListener(
  6616. "fullscreenchange",
  6617. handleFullscreenChange
  6618. );
  6619. });
  6620. return {
  6621. triggerRef,
  6622. fullscreenRef,
  6623. open,
  6624. pinned,
  6625. fullscreen,
  6626. hoveringTrigger,
  6627. hoveringPreview,
  6628. previewStyle,
  6629. openPreview,
  6630. scheduleClose,
  6631. clearCloseTimer,
  6632. togglePin,
  6633. toggleFullscreen,
  6634. };
  6635. },
  6636. render() {
  6637. const SsIcon = Vue.resolveComponent("ss-icon");
  6638. const Chart = Vue.resolveComponent("ss-sidebar-chart");
  6639. const hasHeader = !!(this.title || this.iconClass || this.icon); // 功能:hover 大图显示左侧图标+标题 by xu 20260108
  6640. const previewContent = Vue.h(
  6641. "div",
  6642. {
  6643. class: { "ss-sidebar-chart-preview": true, "is-pinned": this.pinned },
  6644. style: this.previewStyle,
  6645. onMouseenter: () => {
  6646. this.hoveringPreview = true;
  6647. this.clearCloseTimer();
  6648. },
  6649. onMouseleave: () => {
  6650. this.hoveringPreview = false;
  6651. this.scheduleClose();
  6652. },
  6653. },
  6654. [
  6655. hasHeader
  6656. ? Vue.h(
  6657. "div",
  6658. {
  6659. class:
  6660. "ss-sidebar-panel__header ss-sidebar-chart-preview__header",
  6661. },
  6662. [
  6663. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  6664. this.iconClass
  6665. ? Vue.h(SsIcon, {
  6666. class: this.iconClass + " ss-sidebar-panel__icon",
  6667. })
  6668. : this.icon
  6669. ? Vue.h(SsIcon, {
  6670. name: this.icon,
  6671. size: "16px",
  6672. class: "ss-sidebar-panel__icon",
  6673. })
  6674. : null,
  6675. Vue.h("span", null, this.title || "统计图"),
  6676. ]),
  6677. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6678. Vue.h(
  6679. "button",
  6680. {
  6681. type: "button",
  6682. class: {
  6683. "ss-sidebar-chart-tool": true,
  6684. "is-active": this.pinned,
  6685. },
  6686. title: this.pinned ? "取消固定" : "固定",
  6687. onClick: (e) => {
  6688. e.stopPropagation();
  6689. this.togglePin();
  6690. },
  6691. },
  6692. // 功能说明:右侧栏 hover 工具图标使用 ss-sidebar-base-icon(不复用左侧 menu-base-icon) by xu 20260123
  6693. [
  6694. Vue.h(SsIcon, {
  6695. class: this.pinned
  6696. ? "ss-sidebar-base-icon icon-fix-bold"
  6697. : "ss-sidebar-base-icon icon-fix",
  6698. }),
  6699. ]
  6700. ),
  6701. Vue.h(
  6702. "button",
  6703. {
  6704. type: "button",
  6705. class: "ss-sidebar-chart-tool",
  6706. title: "全屏",
  6707. onClick: (e) => {
  6708. e.stopPropagation();
  6709. this.toggleFullscreen();
  6710. },
  6711. },
  6712. [
  6713. Vue.h(SsIcon, {
  6714. class: this.fullscreen
  6715. ? "ss-sidebar-base-icon icon-fs-exit"
  6716. : "ss-sidebar-base-icon icon-fs",
  6717. }),
  6718. ]
  6719. ),
  6720. ]),
  6721. ]
  6722. )
  6723. : Vue.h(
  6724. "div",
  6725. {
  6726. class:
  6727. "ss-sidebar-chart-preview__header ss-sidebar-chart-preview__header--simple",
  6728. },
  6729. [
  6730. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6731. Vue.h(
  6732. "button",
  6733. {
  6734. type: "button",
  6735. class: {
  6736. "ss-sidebar-chart-tool": true,
  6737. "is-active": this.pinned,
  6738. },
  6739. title: this.pinned ? "取消固定" : "固定",
  6740. onClick: (e) => {
  6741. e.stopPropagation();
  6742. this.togglePin();
  6743. },
  6744. },
  6745. [
  6746. Vue.h(SsIcon, {
  6747. class: this.pinned
  6748. ? "ss-sidebar-base-icon icon-fix-bold"
  6749. : "ss-sidebar-base-icon icon-fix",
  6750. }),
  6751. ]
  6752. ),
  6753. Vue.h(
  6754. "button",
  6755. {
  6756. type: "button",
  6757. class: "ss-sidebar-chart-tool",
  6758. title: "全屏",
  6759. onClick: (e) => {
  6760. e.stopPropagation();
  6761. this.toggleFullscreen();
  6762. },
  6763. },
  6764. [
  6765. Vue.h(SsIcon, {
  6766. class: this.fullscreen
  6767. ? "ss-sidebar-base-icon icon-chk-on"
  6768. : "ss-sidebar-base-icon icon-chk",
  6769. }),
  6770. ]
  6771. ),
  6772. ]),
  6773. ]
  6774. ),
  6775. Vue.h("div", { class: "ss-sidebar-chart-preview__body" }, [
  6776. Vue.h(Chart, { options: this.options, height: "100%" }),
  6777. ]),
  6778. ]
  6779. );
  6780. const fullscreenContent =
  6781. this.fullscreen &&
  6782. Vue.h(
  6783. "div",
  6784. {
  6785. ref: "fullscreenRef",
  6786. class: "ss-sidebar-chart-fullscreen",
  6787. },
  6788. [
  6789. Vue.h(
  6790. "div",
  6791. {
  6792. class:
  6793. "ss-sidebar-panel__header ss-sidebar-chart-fullscreen__header",
  6794. },
  6795. [
  6796. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  6797. this.iconClass
  6798. ? Vue.h(SsIcon, {
  6799. class: this.iconClass + " ss-sidebar-panel__icon",
  6800. })
  6801. : this.icon
  6802. ? Vue.h(SsIcon, {
  6803. name: this.icon,
  6804. size: "16px",
  6805. class: "ss-sidebar-panel__icon",
  6806. })
  6807. : null,
  6808. Vue.h("span", null, this.title || "统计图"),
  6809. ]),
  6810. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  6811. Vue.h(
  6812. "button",
  6813. {
  6814. type: "button",
  6815. class: {
  6816. "ss-sidebar-chart-tool": true,
  6817. "is-active": this.pinned,
  6818. },
  6819. title: this.pinned ? "取消固定" : "固定",
  6820. onClick: (e) => {
  6821. e.stopPropagation();
  6822. this.togglePin();
  6823. },
  6824. },
  6825. [
  6826. Vue.h(SsIcon, {
  6827. class: this.pinned
  6828. ? "ss-sidebar-base-icon icon-fix-bold"
  6829. : "ss-sidebar-base-icon icon-fix",
  6830. }),
  6831. ]
  6832. ),
  6833. Vue.h(
  6834. "button",
  6835. {
  6836. type: "button",
  6837. class: "ss-sidebar-chart-tool",
  6838. title: "退出全屏",
  6839. onClick: (e) => {
  6840. e.stopPropagation();
  6841. this.toggleFullscreen();
  6842. },
  6843. },
  6844. [
  6845. Vue.h(SsIcon, {
  6846. class: "ss-sidebar-base-icon icon-fs-exit",
  6847. }),
  6848. ]
  6849. ),
  6850. ]),
  6851. ]
  6852. ),
  6853. Vue.h("div", { class: "ss-sidebar-chart-fullscreen__body" }, [
  6854. Vue.h(Chart, { options: this.options, height: "100%" }),
  6855. ]),
  6856. ]
  6857. );
  6858. return Vue.h("div", { class: "ss-sidebar-chart-hover" }, [
  6859. Vue.h(
  6860. "div",
  6861. {
  6862. ref: "triggerRef",
  6863. class: "ss-sidebar-chart-hover__trigger",
  6864. onMouseenter: () => {
  6865. this.hoveringTrigger = true;
  6866. this.openPreview();
  6867. },
  6868. onMouseleave: () => {
  6869. this.hoveringTrigger = false;
  6870. this.scheduleClose();
  6871. },
  6872. },
  6873. [Vue.h(Chart, { options: this.options, height: this.height })]
  6874. ),
  6875. (this.open || this.fullscreen) &&
  6876. Vue.h(Vue.Teleport, { to: "body" }, [
  6877. this.open ? previewContent : null,
  6878. fullscreenContent || null,
  6879. ]),
  6880. ]);
  6881. },
  6882. };
  6883. // 组件文档补全(JSDoc) by xu 20260108
  6884. /**
  6885. * SsSidebarList(右侧业务面板:人员/已选/服务/预定...)
  6886. *
  6887. * 用途:
  6888. * - 统一渲染面板 header(图标/标题/数量/右侧按钮)
  6889. * - 统一渲染 list(固定行高、hover、右侧移除按钮等)
  6890. *
  6891. * 调用示例(由 ss-sidebar 通过 panels 配置驱动):
  6892. * ```js
  6893. * { type:'list', title:'已选', iconClass:'menu-icon icon-obj-xcd', mode:'selected', items:selectedItems, closable:true }
  6894. * ```
  6895. *
  6896. * Props(核心):
  6897. * - `title`:header 标题
  6898. * - `iconClass/icon`:header 图标(优先 iconClass)
  6899. * - `count`:数量回显(图表面板可不传)
  6900. * - `closable`:是否显示“清空”按钮(触发 emit clear)
  6901. * - `headerFilters`:header 条件数组(组件名 + props),用于联调接口搜索
  6902. * - `headerSearchButton`:是否显示搜索按钮(触发 emit search)
  6903. * - `items`:列表数据
  6904. * - `mode`:`selected` 时右侧按钮语义为“移除”
  6905. * - `itemLayout`:`simple` / `person`(人员号槽位)
  6906. * - `itemAction`:是否显示 item 右侧操作按钮(hover 才出现)
  6907. *
  6908. * Emits:
  6909. * - `remove(item)`:点击 item 右侧移除
  6910. * - `clear()`:点击 header 清空
  6911. * - `search({keyword, filters})`:点击 header 搜索
  6912. */
  6913. const SsSidebarList = {
  6914. name: "SsSidebarList",
  6915. props: {
  6916. title: { type: String, default: "" },
  6917. // header 图标:优先使用 iconClass(走 ss-icon v3.0 class 分支) by xu 20260106
  6918. iconClass: { type: String, default: "" },
  6919. icon: { type: String, default: "" }, // 兼容旧写法(ss-icon name)
  6920. count: { type: [Number, String], default: "" },
  6921. // 选中类分区:右侧关闭按钮=清空分区数据 by xu 20260106
  6922. closable: { type: Boolean, default: false },
  6923. searchable: { type: Boolean, default: false },
  6924. // 搜索框是否放在 header 内(人员块需要该布局) by xu 20260106
  6925. searchInHeader: { type: Boolean, default: false },
  6926. // header 搜索:下拉条件 + 搜索按钮(适合“人员”块) by xu 20260106
  6927. headerFilters: { type: Array, default: () => [] },
  6928. headerSearchButton: { type: Boolean, default: false },
  6929. searchPlaceholder: { type: String, default: "搜索" },
  6930. // 列表项布局:simple(仅标题) / person(标题+人员号槽位) by xu 20260106
  6931. itemLayout: { type: String, default: "simple" },
  6932. itemAction: { type: Boolean, default: true },
  6933. collapsible: { type: Boolean, default: true }, // 功能说明:是否允许双击 header 折叠/展开 by xu 20260116
  6934. collapsed: { type: Boolean, default: false }, // 功能说明:折叠态仅展示 header by xu 20260116
  6935. items: { type: Array, default: () => [] },
  6936. mode: { type: String, default: "search" }, // search / selected
  6937. },
  6938. emits: ["select", "remove", "clear", "search", "toggle-collapse"],
  6939. data() {
  6940. return {
  6941. keyword: "",
  6942. filterValues: {},
  6943. }; // 功能说明:折叠状态完全由 props.collapsed 驱动,避免多面板复用导致状态不同步 by xu 20260116
  6944. },
  6945. created() {
  6946. // header 下拉条件默认值初始化 by xu 20260106
  6947. (this.headerFilters || []).forEach((f) => {
  6948. if (!f || !f.key) return;
  6949. if (this.filterValues[f.key] !== undefined) return;
  6950. const first = f?.options?.[0]?.value ?? "";
  6951. this.filterValues[f.key] = f.value !== undefined ? f.value : first;
  6952. });
  6953. },
  6954. methods: {
  6955. __shouldIgnoreHeaderToggle(e) {
  6956. // 功能说明:忽略工具区/输入区触发折叠,避免误触 by xu 20260116
  6957. const t = e?.target;
  6958. if (!t || !t.closest) return false;
  6959. if (t.closest(".ss-sidebar-panel__tools")) return true;
  6960. if (t.closest(".ss-sidebar-panel__filters")) return true;
  6961. if (t.closest("input,textarea,select,button")) return true;
  6962. return false;
  6963. },
  6964. __toggleCollapseInternal(e, source) {
  6965. if (!this.collapsible) return;
  6966. if (this.__shouldIgnoreHeaderToggle(e)) return;
  6967. const nextCollapsed = !this.collapsed;
  6968. console.log("[SsSidebarList] toggle emit", {
  6969. title: this.title,
  6970. source,
  6971. to: nextCollapsed,
  6972. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  6973. // 功能说明:由父组件(SsSidebar.toggleSectionCollapse)统一控制 section 高度与折叠数组 by xu 20260116
  6974. this.$emit("toggle-collapse");
  6975. },
  6976. },
  6977. render() {
  6978. const items = this.items || [];
  6979. const SsIcon = Vue.resolveComponent("ss-icon");
  6980. const isSelectedMode = this.mode === "selected";
  6981. const activeKeyword = this.filterValues?.keyword ?? this.keyword; // 功能:keyword 优先取 headerFilters.keyword by xu 20260106
  6982. const hasHeaderKeyword = (this.headerFilters || []).some(
  6983. (f) => f?.key === "keyword"
  6984. ); // 功能:header 内 keyword 过滤 by xu 20260106
  6985. const renderHeaderFilter = (f) => {
  6986. if (!f) return null;
  6987. const key = f.key;
  6988. const componentName = f.component;
  6989. if (!key || !componentName) return null;
  6990. const Comp = Vue.resolveComponent(componentName);
  6991. if (!Comp) return null;
  6992. const modelValue = this.filterValues[key];
  6993. const props = f.props || {};
  6994. return Vue.h(Comp, {
  6995. ...props,
  6996. modelValue,
  6997. "onUpdate:modelValue": (v) => {
  6998. this.filterValues[key] = v;
  6999. },
  7000. });
  7001. };
  7002. const filteredItems =
  7003. this.searchable && activeKeyword
  7004. ? items.filter((it) =>
  7005. String(it?.title ?? "")
  7006. .toLowerCase()
  7007. .includes(String(activeKeyword).toLowerCase())
  7008. )
  7009. : items;
  7010. if (!filteredItems.length && !this.title) return null;
  7011. if (this.collapsed) {
  7012. return Vue.h("div", { class: "ss-sidebar-panel" }, [
  7013. this.title
  7014. ? Vue.h(
  7015. "div",
  7016. {
  7017. class: "ss-sidebar-panel__header",
  7018. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  7019. onDblclick: (e) => {
  7020. e?.preventDefault?.();
  7021. e?.stopPropagation?.();
  7022. console.log("[SsSidebarList] header dblclick", {
  7023. title: this.title,
  7024. collapsed: true,
  7025. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7026. this.__toggleCollapseInternal(e, "dblclick");
  7027. },
  7028. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  7029. },
  7030. [
  7031. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7032. this.iconClass
  7033. ? Vue.h(SsIcon, {
  7034. class: this.iconClass + " ss-sidebar-panel__icon",
  7035. })
  7036. : this.icon
  7037. ? Vue.h(SsIcon, {
  7038. name: this.icon,
  7039. size: "16px",
  7040. class: "ss-sidebar-panel__icon",
  7041. })
  7042. : null,
  7043. Vue.h("span", null, this.title),
  7044. this.count !== ""
  7045. ? Vue.h(
  7046. "span",
  7047. { class: "ss-sidebar-panel__count" },
  7048. `(${this.count})`
  7049. )
  7050. : null,
  7051. ]),
  7052. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7053. this.closable
  7054. ? Vue.h(
  7055. "button",
  7056. {
  7057. type: "button",
  7058. class: "ss-sidebar-icon-btn ss-sidebar-header-btn",
  7059. title: "清空",
  7060. onClick: (e) => {
  7061. e.stopPropagation();
  7062. this.$emit("clear");
  7063. },
  7064. },
  7065. [
  7066. Vue.h(SsIcon, {
  7067. class: "ss-sidebar-base-icon icon-cl",
  7068. }),
  7069. ] // 功能说明:右侧栏“已选”清空按钮图标使用 ss-sidebar-base-icon by xu 20260123
  7070. )
  7071. : null,
  7072. ]),
  7073. ]
  7074. )
  7075. : null,
  7076. ]);
  7077. }
  7078. return Vue.h("div", { class: "ss-sidebar-panel" }, [
  7079. this.title
  7080. ? Vue.h(
  7081. "div",
  7082. {
  7083. class: "ss-sidebar-panel__header",
  7084. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  7085. onDblclick: (e) => {
  7086. e?.preventDefault?.();
  7087. e?.stopPropagation?.();
  7088. console.log("[SsSidebarList] header dblclick", {
  7089. title: this.title,
  7090. collapsed: false,
  7091. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7092. this.__toggleCollapseInternal(e, "dblclick");
  7093. },
  7094. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  7095. },
  7096. [
  7097. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7098. // 图标 + 标题(每个分区都有) by xu 20260106
  7099. this.iconClass
  7100. ? Vue.h(SsIcon, {
  7101. class: this.iconClass + " ss-sidebar-panel__icon",
  7102. })
  7103. : this.icon
  7104. ? Vue.h(SsIcon, {
  7105. name: this.icon,
  7106. size: "16px",
  7107. class: "ss-sidebar-panel__icon",
  7108. })
  7109. : null,
  7110. Vue.h("span", null, this.title),
  7111. // 数量回显:图表分区可不传 count by xu 20260106
  7112. this.count !== ""
  7113. ? Vue.h(
  7114. "span",
  7115. { class: "ss-sidebar-panel__count" },
  7116. `(${this.count})`
  7117. )
  7118. : null,
  7119. ]),
  7120. Vue.h("div", { class: "ss-sidebar-panel__tools" }, [
  7121. // header 条件(例如下拉框)+ 右侧搜索按钮 by xu 20260106
  7122. this.headerFilters?.length
  7123. ? Vue.h(
  7124. "div",
  7125. { class: "ss-sidebar-panel__filters" },
  7126. this.headerFilters
  7127. .map(renderHeaderFilter)
  7128. .filter(Boolean)
  7129. )
  7130. : null,
  7131. this.headerSearchButton
  7132. ? Vue.h(
  7133. "button",
  7134. {
  7135. type: "button",
  7136. class: "ss-sidebar-icon-btn",
  7137. title: "搜索",
  7138. onClick: (e) => {
  7139. e.stopPropagation();
  7140. this.$emit("search", {
  7141. // headerFilters 内也可能包含 keyword by xu 20260106
  7142. keyword: activeKeyword,
  7143. filters: { ...(this.filterValues || {}) },
  7144. });
  7145. },
  7146. },
  7147. [Vue.h(SsIcon, { name: "search", size: "14px" })]
  7148. )
  7149. : null,
  7150. // 人员块:搜索框在 header 内 by xu 20260106
  7151. this.searchable &&
  7152. this.searchInHeader &&
  7153. !this.headerSearchButton
  7154. ? Vue.h(
  7155. "div",
  7156. { class: "ss-sidebar-panel__searchInline" },
  7157. [
  7158. Vue.h(
  7159. "div",
  7160. { class: "ss-sidebar-search is-inline" },
  7161. [
  7162. Vue.h(SsIcon, {
  7163. name: "search",
  7164. size: "14px",
  7165. class: "ss-sidebar-search__prefix",
  7166. }),
  7167. Vue.h("input", {
  7168. class: "ss-sidebar-search__input",
  7169. value: this.keyword,
  7170. placeholder: this.searchPlaceholder,
  7171. onInput: (e) => {
  7172. this.keyword = e?.target?.value ?? "";
  7173. },
  7174. }),
  7175. ]
  7176. ),
  7177. ]
  7178. )
  7179. : null,
  7180. this.closable
  7181. ? Vue.h(
  7182. "button",
  7183. {
  7184. type: "button",
  7185. class: "ss-sidebar-icon-btn ss-sidebar-header-btn",
  7186. title: "清空",
  7187. onClick: (e) => {
  7188. e.stopPropagation();
  7189. this.$emit("clear");
  7190. },
  7191. },
  7192. // 清空按钮使用 icon-base 的 icon-cl by xu 20260106
  7193. [
  7194. Vue.h(SsIcon, {
  7195. class: "ss-sidebar-base-icon icon-cl",
  7196. }),
  7197. ] // 功能说明:右侧栏清空按钮图标使用 ss-sidebar-base-icon by xu 20260123
  7198. )
  7199. : null,
  7200. ]),
  7201. ]
  7202. )
  7203. : null,
  7204. // 非 header 内搜索:独立一行 by xu 20260106
  7205. // headerSearchButton/headerFilters 已覆盖搜索能力时,不再额外渲染独立搜索行 by xu 20260106
  7206. this.searchable &&
  7207. !this.searchInHeader &&
  7208. !this.headerSearchButton &&
  7209. !hasHeaderKeyword
  7210. ? Vue.h("div", { class: "ss-sidebar-panel__search" }, [
  7211. Vue.h("div", { class: "ss-sidebar-search" }, [
  7212. Vue.h(SsIcon, {
  7213. name: "search",
  7214. size: "14px",
  7215. class: "ss-sidebar-search__prefix",
  7216. }),
  7217. Vue.h("input", {
  7218. class: "ss-sidebar-search__input",
  7219. value: this.keyword,
  7220. placeholder: this.searchPlaceholder,
  7221. onInput: (e) => {
  7222. this.keyword = e?.target?.value ?? "";
  7223. },
  7224. }),
  7225. ]),
  7226. ])
  7227. : null,
  7228. Vue.h(
  7229. "div",
  7230. { class: "ss-sidebar-list" },
  7231. filteredItems.map((item, idx) => {
  7232. const title = item?.title ?? "";
  7233. const tags = item?.tags || [];
  7234. const isPersonLayout = this.itemLayout === "person";
  7235. const hasTags = !isPersonLayout && tags?.length > 0; // 列表项垂直对齐:有 tags 顶对齐 by xu 20260106
  7236. return Vue.h(
  7237. "div",
  7238. {
  7239. class: {
  7240. "ss-sidebar-list-item": true,
  7241. "is-first": idx === 0,
  7242. "is-person": isPersonLayout,
  7243. "has-tags": hasTags,
  7244. },
  7245. },
  7246. [
  7247. Vue.h("div", { class: "ss-sidebar-list-item__main" }, [
  7248. Vue.h(
  7249. "div",
  7250. { class: "ss-sidebar-list-item__title" },
  7251. Vue.h(
  7252. "span",
  7253. {
  7254. style: {
  7255. "white-space": "nowrap",
  7256. overflow: "hidden",
  7257. "text-overflow": "ellipsis",
  7258. },
  7259. },
  7260. title
  7261. )
  7262. ),
  7263. // 非人员布局才显示 tags by xu 20260106
  7264. !isPersonLayout && tags?.length
  7265. ? Vue.h(
  7266. "div",
  7267. { class: "ss-sidebar-list-item__tags" },
  7268. tags.map((tag) => {
  7269. const [k, v] = Object.entries(tag)[0] || ["", ""];
  7270. return Vue.h(
  7271. "span",
  7272. { class: "ss-sidebar-tag", title: `${k}: ${v}` },
  7273. `${k}: ${v}`
  7274. );
  7275. })
  7276. )
  7277. : null,
  7278. ]),
  7279. // 人员布局:中间保留“人员号”槽位 by xu 20260106
  7280. isPersonLayout
  7281. ? Vue.h(
  7282. "div",
  7283. {
  7284. class: "ss-sidebar-list-item__meta",
  7285. title: String(item?.meta ?? ""),
  7286. },
  7287. item?.meta ?? ""
  7288. )
  7289. : null,
  7290. this.itemAction
  7291. ? Vue.h(
  7292. "button",
  7293. {
  7294. type: "button",
  7295. class: {
  7296. // item 操作按钮:默认无背景/无边框,hover 才高亮 by xu 20260106
  7297. "ss-sidebar-item-btn": true,
  7298. },
  7299. title: isSelectedMode ? "移除" : "选择",
  7300. onClick: (e) => {
  7301. e.stopPropagation();
  7302. if (isSelectedMode) this.$emit("remove", item);
  7303. else this.$emit("select", item);
  7304. },
  7305. },
  7306. [
  7307. // item 移除图标使用 icon-base 的 icon-cl by xu 20260106
  7308. isSelectedMode
  7309. ? Vue.h(SsIcon, {
  7310. class: "ss-sidebar-base-icon icon-cl",
  7311. }) // 功能说明:右侧栏 item 移除图标使用 ss-sidebar-base-icon by xu 20260123
  7312. : Vue.h(SsIcon, { name: "check", size: "14px" }),
  7313. ]
  7314. )
  7315. : null,
  7316. ]
  7317. );
  7318. })
  7319. ),
  7320. ]);
  7321. },
  7322. };
  7323. // ss-sidebar-report-table:右侧“统计表/报表”面板(pstatList grtjlbm=51 聚拢渲染) by xu 20260115
  7324. const SsSidebarReportTable = {
  7325. name: "SsSidebarReportTable",
  7326. props: {
  7327. title: { type: String, default: "" },
  7328. iconClass: { type: String, default: "" },
  7329. icon: { type: String, default: "" },
  7330. items: { type: Array, default: () => [] }, // pstatList(grtjlbm=51) 数组
  7331. onOpen: { type: Function, default: null }, // (srv, ctx) => void
  7332. collapsible: { type: Boolean, default: true }, // 功能说明:是否允许双击 header 折叠/展开 by xu 20260116
  7333. collapsed: { type: Boolean, default: false }, // 功能说明:折叠态仅展示 header by xu 20260116
  7334. },
  7335. emits: ["open", "toggle-collapse"],
  7336. data() {
  7337. return {}; // 功能说明:折叠状态完全由 props.collapsed 驱动 by xu 20260116
  7338. },
  7339. methods: {
  7340. __toggleCollapseInternal(e, source) {
  7341. if (!this.collapsible) return;
  7342. const next = !this.collapsed;
  7343. console.log("[SsSidebarReportTable] toggle emit", {
  7344. title: this.title,
  7345. source,
  7346. to: next,
  7347. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7348. this.$emit("toggle-collapse");
  7349. },
  7350. },
  7351. render() {
  7352. const SsIcon = Vue.resolveComponent("ss-icon");
  7353. const list = this.items || [];
  7354. if (!this.title && !list.length) return null;
  7355. const header = this.title
  7356. ? Vue.h(
  7357. "div",
  7358. {
  7359. class: "ss-sidebar-panel__header",
  7360. // 功能说明:折叠触发绑定到整个 header(dblclick + click.detail==2 兜底) by xu 20260116
  7361. onDblclick: (e) => {
  7362. e?.preventDefault?.();
  7363. e?.stopPropagation?.();
  7364. console.log("[SsSidebarReportTable] header dblclick", {
  7365. title: this.title,
  7366. collapsed: this.collapsed,
  7367. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7368. this.__toggleCollapseInternal(e, "dblclick");
  7369. },
  7370. // 功能说明:移除 click.detail==2 兜底,避免双击同时触发 click+dblclick 导致“折叠又立刻展开” by xu 20260116
  7371. },
  7372. [
  7373. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  7374. this.iconClass
  7375. ? Vue.h(SsIcon, {
  7376. class: this.iconClass + " ss-sidebar-panel__icon",
  7377. })
  7378. : this.icon
  7379. ? Vue.h(SsIcon, {
  7380. name: this.icon,
  7381. size: "16px",
  7382. class: "ss-sidebar-panel__icon",
  7383. })
  7384. : null,
  7385. Vue.h("span", null, this.title),
  7386. ]),
  7387. Vue.h("div", { class: "ss-sidebar-panel__tools" }),
  7388. ]
  7389. )
  7390. : null;
  7391. const renderReport = (report) => {
  7392. const title = String(report?.mc ?? "");
  7393. const mx = Array.isArray(report?.grtjmxList) ? report.grtjmxList : [];
  7394. if (!title && !mx.length) return null;
  7395. // 功能说明:每个报表对象渲染为一个 table(有边框、无圆角、表间距10px;样式由 base.css 统一控制) by xu 20260115
  7396. const cols = Math.max(1, mx.length);
  7397. // 功能说明:table 外层包一层 wrap,子项过多时支持横向滚动 by xu 20260115
  7398. return Vue.h("div", { class: "ss-sidebar-report-table-wrap" }, [
  7399. Vue.h("table", { class: "ss-sidebar-report-table" }, [
  7400. Vue.h("thead", null, [
  7401. Vue.h("tr", null, [
  7402. Vue.h(
  7403. "th",
  7404. { class: "ss-sidebar-report-table__title", colspan: cols },
  7405. Vue.h(
  7406. "div",
  7407. { class: "ss-sidebar-report-table__title-content" },
  7408. [
  7409. Vue.h("span", { class: "ss-sidebar-report-table__dot" }),
  7410. Vue.h(
  7411. "span",
  7412. { class: "ss-sidebar-report-table__title-text", title },
  7413. title
  7414. ),
  7415. ]
  7416. )
  7417. ),
  7418. ]),
  7419. ]),
  7420. Vue.h("tbody", null, [
  7421. Vue.h(
  7422. "tr",
  7423. null,
  7424. mx.map((cell) => {
  7425. const text = String(cell?.mc ?? "");
  7426. const srv = {
  7427. servName: cell?.fwm ?? "",
  7428. dest: cell?.bjm ?? "",
  7429. title: text,
  7430. width: cell?.width,
  7431. height: cell?.height,
  7432. minHeight: cell?.height,
  7433. maxHeight: cell?.height,
  7434. showTitle: text,
  7435. };
  7436. return Vue.h(
  7437. "td",
  7438. {
  7439. class: "ss-sidebar-report-table__cell",
  7440. title: text,
  7441. onClick: (e) => {
  7442. e?.stopPropagation?.();
  7443. try {
  7444. this.onOpen?.(srv, { report, cell });
  7445. } catch (_) {}
  7446. this.$emit("open", { report, cell, srv });
  7447. },
  7448. },
  7449. text
  7450. );
  7451. })
  7452. ),
  7453. ]),
  7454. ]),
  7455. ]);
  7456. };
  7457. // 功能说明:报表面板增加独立 class,便于 base.css 统一控制 padding/间距 by xu 20260115
  7458. return Vue.h(
  7459. "div",
  7460. { class: "ss-sidebar-panel ss-sidebar-report-panel" },
  7461. [
  7462. header,
  7463. this.collapsed
  7464. ? null
  7465. : Vue.h(
  7466. "div",
  7467. // 功能说明:报表列表滚动/高度样式下沉到 base.css,避免写在 DOM 上 by xu 20260115
  7468. { class: "ss-sidebar-report__list" },
  7469. list.map(renderReport).filter(Boolean)
  7470. ),
  7471. ]
  7472. );
  7473. },
  7474. };
  7475. // 组件文档补全(JSDoc) by xu 20260108
  7476. /**
  7477. * SsSidebar(objList 右侧边栏容器)
  7478. *
  7479. * 用途:
  7480. * - 统一渲染顶部按钮栏(buttons)
  7481. * - 统一渲染中间业务面板(list panels,可拖拽调高度)
  7482. * - 统一渲染底部图表(chart panels,内部用 ss-sidebar-chart-hover)
  7483. *
  7484. * 调用示例:
  7485. * ```html
  7486. * <ss-sidebar :buttons="sidebarButtons" :panels="sidebarPanels" @remove="handleSidebarRemove" />
  7487. * ```
  7488. *
  7489. * Props:
  7490. * - `buttons`:顶部按钮配置数组
  7491. * - `panels`:分区配置数组(`type: 'list' | 'chart'`)
  7492. *
  7493. * Events(向外透传):
  7494. * - `remove(item)`:来自 list 面板移除
  7495. * - `select(item)`:来自 list 面板选择(如后续需要)
  7496. */
  7497. const SsSidebar = {
  7498. name: "SsSidebar",
  7499. props: {
  7500. buttons: { type: Array, default: () => [] },
  7501. charts: { type: Array, default: () => [] },
  7502. list: { type: Array, default: () => [] }, // legacy
  7503. listMode: { type: String, default: "search" }, // legacy
  7504. panels: { type: Array, default: () => [] },
  7505. },
  7506. emits: ["select", "remove"],
  7507. data() {
  7508. return {
  7509. // 业务面板高度(索引 -> px) by xu 20260106
  7510. sectionHeights: [],
  7511. sectionCollapsed: [], // 功能说明:面板折叠状态(sectionPanels 索引) by xu 20260116
  7512. sectionHeightsExpanded: [], // 功能说明:面板展开高度缓存(用于折叠后恢复) by xu 20260116
  7513. sectionLastItemCounts: [], // 功能说明:记录栏目数据量,供“无数据默认关闭/已选自动展开”规则复用 by xu 20260313
  7514. chartCollapsed: [], // 功能说明:图表面板折叠状态(chartPanels 索引) by xu 20260116
  7515. chartHeaderTitleDownAt: [], // 功能说明:双击检测绑定到 chart 标题区 by xu 20260116
  7516. reportCollapsed: [], // 功能说明:报表面板折叠状态(reportPanels 索引) by xu 20260116
  7517. resizeTimer: null,
  7518. resizing: false,
  7519. resizeIndex: -1,
  7520. resizeStartY: 0,
  7521. resizeStartPrev: 0,
  7522. resizeStartNext: 0,
  7523. __resizeMoveHandler: null, // 功能说明:显式绑定 this 的 pointermove handler,避免 addEventListener 场景 this 丢失导致拖拽无效 by xu 20260122
  7524. __resizeEndHandler: null, // 功能说明:显式绑定 this 的 pointerup handler,确保能正确结束拖拽 by xu 20260122
  7525. __resizeCancelHandler: null, // 功能说明:显式绑定 this 的 pointercancel handler,触控取消也能收尾 by xu 20260122
  7526. __resizePrevSectionEl: null, // 功能说明:拖拽时直接写 DOM 高度(修复响应式更新不生效) by xu 20260122
  7527. __resizeNextSectionEl: null, // 功能说明:拖拽时直接写 DOM 高度(修复响应式更新不生效) by xu 20260122
  7528. };
  7529. },
  7530. methods: {
  7531. // 初始化默认高度(只在第一次/面板数量变化时补齐) by xu 20260106
  7532. ensureSectionHeights(sectionCount) {
  7533. if (!Array.isArray(this.sectionHeights)) this.sectionHeights = [];
  7534. if (this.sectionHeights.length === sectionCount) return;
  7535. const next = [];
  7536. for (let i = 0; i < sectionCount; i++) {
  7537. next[i] = this.sectionHeights[i] ?? 190; // 默认高度 by xu 20260106
  7538. }
  7539. this.sectionHeights = next;
  7540. // 功能说明:面板数量变化时补齐折叠/缓存数组长度 by xu 20260116
  7541. this.sectionCollapsed = Array.from(
  7542. { length: sectionCount },
  7543. (_, i) => !!this.sectionCollapsed?.[i]
  7544. );
  7545. this.sectionHeightsExpanded = Array.from(
  7546. { length: sectionCount },
  7547. (_, i) => this.sectionHeightsExpanded?.[i] ?? null
  7548. );
  7549. this.sectionLastItemCounts = Array.from(
  7550. { length: sectionCount },
  7551. (_, i) => Number(this.sectionLastItemCounts?.[i] ?? 0) || 0
  7552. );
  7553. },
  7554. __getPanelsForSectionState(panelsInput) {
  7555. return (panelsInput || []).length
  7556. ? panelsInput
  7557. : this.list?.length
  7558. ? [
  7559. {
  7560. type: "list",
  7561. title: "已选",
  7562. icon: "",
  7563. mode: this.listMode,
  7564. items: this.list,
  7565. },
  7566. ]
  7567. : [];
  7568. },
  7569. __getSectionPanelsForState(panelsInput) {
  7570. return this.__getPanelsForSectionState(panelsInput)
  7571. .filter((p) => {
  7572. const k = String(p?._tabKey ?? "")
  7573. .trim()
  7574. .toLowerCase();
  7575. const t = String(p?.title ?? "").trim();
  7576. if (k === "rbarobj") return false;
  7577. if (t === "对象") return false;
  7578. return true;
  7579. })
  7580. .filter((p) => p?.type !== "chart" && p?.type !== "report-table");
  7581. },
  7582. __getSectionPanelCount(panel) {
  7583. const explicitCount = Number(panel?.count);
  7584. if (Number.isFinite(explicitCount)) return explicitCount;
  7585. return Array.isArray(panel?.items) ? panel.items.length : 0;
  7586. },
  7587. __setSectionCollapsedState(index, collapsed) {
  7588. const i = Number(index);
  7589. if (isNaN(i) || i < 0) return;
  7590. const nextCollapsed = !!collapsed;
  7591. const collapsedHeight = 37;
  7592. const cur = !!this.sectionCollapsed?.[i];
  7593. const currentHeight = Number(this.sectionHeights?.[i] ?? 190) || 190;
  7594. if (nextCollapsed === cur) {
  7595. if (nextCollapsed && currentHeight !== collapsedHeight) {
  7596. this.sectionHeights.splice(i, 1, collapsedHeight);
  7597. }
  7598. return;
  7599. }
  7600. if (nextCollapsed) {
  7601. this.sectionHeightsExpanded[i] =
  7602. currentHeight > collapsedHeight
  7603. ? currentHeight
  7604. : Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  7605. this.sectionHeights.splice(i, 1, collapsedHeight);
  7606. } else {
  7607. const restore =
  7608. Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  7609. this.sectionHeights.splice(i, 1, restore);
  7610. }
  7611. this.sectionCollapsed.splice(i, 1, nextCollapsed);
  7612. },
  7613. __syncSectionAutoCollapse(panelsInput) {
  7614. const sectionPanels = this.__getSectionPanelsForState(panelsInput);
  7615. const sectionCount = sectionPanels.length;
  7616. this.ensureSectionHeights(sectionCount);
  7617. const prevCounts = Array.isArray(this.sectionLastItemCounts)
  7618. ? this.sectionLastItemCounts.slice()
  7619. : [];
  7620. const nextCounts = Array.from({ length: sectionCount }, (_, i) =>
  7621. this.__getSectionPanelCount(sectionPanels[i])
  7622. );
  7623. this.sectionLastItemCounts = nextCounts;
  7624. sectionPanels.forEach((panel, index) => {
  7625. const count = Number(nextCounts[index] ?? 0) || 0;
  7626. const prevCount = Number(prevCounts[index] ?? 0) || 0;
  7627. const title = String(panel?.title ?? "").trim();
  7628. if (count <= 0) {
  7629. this.__setSectionCollapsedState(index, true);
  7630. return;
  7631. }
  7632. if (title === "已选" && count > prevCount) {
  7633. this.__setSectionCollapsedState(index, false);
  7634. }
  7635. });
  7636. },
  7637. toggleSectionCollapse(index) {
  7638. // 功能说明:双击 header 折叠/展开 section 面板(仅控制高度与内容渲染) by xu 20260116
  7639. const i = Number(index);
  7640. if (isNaN(i) || i < 0) return;
  7641. // 功能说明:加更细粒度日志,定位“多面板折叠无视觉效果”的根因(高度是否真的变、DOM 是否更新) by xu 20260116
  7642. const collapsedHeight = 37; // 功能说明:header(35) + panel 边框(2),避免 flex shrink 导致 header 变 25px by xu 20260116
  7643. const cur = !!this.sectionCollapsed?.[i];
  7644. console.log("[SsSidebar] toggleSectionCollapse", {
  7645. index: i,
  7646. to: !cur,
  7647. prevHeight: this.sectionHeights?.[i],
  7648. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7649. if (!cur) {
  7650. this.sectionHeightsExpanded[i] = this.sectionHeights[i] ?? 190;
  7651. this.sectionHeights.splice(i, 1, collapsedHeight);
  7652. } else {
  7653. const restore =
  7654. Number(this.sectionHeightsExpanded?.[i] ?? 190) || 190;
  7655. this.sectionHeights.splice(i, 1, restore);
  7656. }
  7657. this.sectionCollapsed.splice(i, 1, !cur);
  7658. console.log("[SsSidebar] section state(after)", {
  7659. index: i,
  7660. height: this.sectionHeights?.[i],
  7661. collapsed: this.sectionCollapsed?.[i],
  7662. allHeights: Array.from(this.sectionHeights || []),
  7663. allCollapsed: Array.from(this.sectionCollapsed || []),
  7664. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7665. Vue.nextTick(() => {
  7666. try {
  7667. const root = this.$el;
  7668. const sections = root?.querySelectorAll?.(".ss-sidebar-section");
  7669. const el = sections?.[i];
  7670. const rectH = el?.getBoundingClientRect?.().height;
  7671. console.log("[SsSidebar] section dom(beforeFix)", {
  7672. index: i,
  7673. styleHeight: el?.style?.height,
  7674. rectH,
  7675. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7676. // 功能说明:若渲染未把 height patch 到 DOM,则在 nextTick 强制同步一次(并打印) by xu 20260116
  7677. const targetH =
  7678. (Number(this.sectionHeights?.[i] ?? 190) || 190) + "px";
  7679. if (el && el.style && el.style.height !== targetH) {
  7680. el.style.height = targetH;
  7681. }
  7682. if (el?.classList) {
  7683. el.classList.toggle("is-collapsed", !!this.sectionCollapsed?.[i]);
  7684. }
  7685. const rectAfter = el?.getBoundingClientRect?.().height;
  7686. console.log("[SsSidebar] section dom(afterFix)", {
  7687. index: i,
  7688. styleHeight: el?.style?.height,
  7689. rectH: rectAfter,
  7690. targetH,
  7691. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7692. } catch (err) {
  7693. console.log("[SsSidebar] section dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7694. }
  7695. });
  7696. },
  7697. toggleChartCollapse(index) {
  7698. // 功能说明:双击 header 折叠/展开底部 chart 面板(隐藏/显示 chart-hover) by xu 20260116
  7699. const i = Number(index);
  7700. if (isNaN(i) || i < 0) return;
  7701. const cur = !!this.chartCollapsed?.[i];
  7702. console.log("[SsSidebar] toggleChartCollapse", { index: i, to: !cur }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7703. this.chartCollapsed.splice(i, 1, !cur);
  7704. console.log("[SsSidebar] chart state(after)", {
  7705. index: i,
  7706. collapsed: this.chartCollapsed?.[i],
  7707. allCollapsed: Array.from(this.chartCollapsed || []),
  7708. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7709. Vue.nextTick(() => {
  7710. try {
  7711. const root = this.$el;
  7712. const el = root?.querySelector?.(
  7713. `.ss-sidebar-chart-panel[data-chart-idx="${i}"]`
  7714. );
  7715. console.log("[SsSidebar] chart dom(beforeFix)", {
  7716. index: i,
  7717. found: !!el,
  7718. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7719. if (el?.classList)
  7720. el.classList.toggle("is-collapsed", !!this.chartCollapsed?.[i]);
  7721. console.log("[SsSidebar] chart dom(afterFix)", {
  7722. index: i,
  7723. collapsed: !!this.chartCollapsed?.[i],
  7724. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7725. } catch (err) {
  7726. console.log("[SsSidebar] chart dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7727. }
  7728. });
  7729. },
  7730. toggleReportCollapse(index) {
  7731. // 功能说明:双击 header 折叠/展开底部 report-table 面板(隐藏/显示表格) by xu 20260116
  7732. const i = Number(index);
  7733. if (isNaN(i) || i < 0) return;
  7734. const cur = !!this.reportCollapsed?.[i];
  7735. console.log("[SsSidebar] toggleReportCollapse", { index: i, to: !cur }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7736. this.reportCollapsed.splice(i, 1, !cur);
  7737. console.log("[SsSidebar] report state(after)", {
  7738. index: i,
  7739. collapsed: this.reportCollapsed?.[i],
  7740. allCollapsed: Array.from(this.reportCollapsed || []),
  7741. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7742. Vue.nextTick(() => {
  7743. try {
  7744. const root = this.$el;
  7745. const el = root?.querySelector?.(
  7746. `.ss-sidebar-report-panel[data-report-idx="${i}"]`
  7747. );
  7748. console.log("[SsSidebar] report dom(beforeFix)", {
  7749. index: i,
  7750. found: !!el,
  7751. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7752. if (el?.classList)
  7753. el.classList.toggle("is-collapsed", !!this.reportCollapsed?.[i]);
  7754. console.log("[SsSidebar] report dom(afterFix)", {
  7755. index: i,
  7756. collapsed: !!this.reportCollapsed?.[i],
  7757. }); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7758. } catch (err) {
  7759. console.log("[SsSidebar] report dom(afterTick) error", err); // 功能说明:直接打印用于排查多面板不生效 by xu 20260116
  7760. }
  7761. });
  7762. },
  7763. startResize(index, e) {
  7764. if (e?.preventDefault) e.preventDefault();
  7765. if (e?.stopPropagation) e.stopPropagation();
  7766. if (this.resizing) return;
  7767. // 长按 0.5s 后才进入拖拽调高度 by xu 20260106
  7768. clearTimeout(this.resizeTimer);
  7769. // 功能说明:修复“长按拖拽偶发失效/卡死”——pointerup 早于 500ms 时必须取消 timer,否则 timer 触发后进入 resizing=true 且再也收不到 pointerup,导致后续都无法拖拽 by xu 20260122
  7770. const pointerId = e?.pointerId;
  7771. const cancelPendingResize = (ev) => {
  7772. try {
  7773. if (
  7774. pointerId != null &&
  7775. ev?.pointerId != null &&
  7776. ev.pointerId !== pointerId
  7777. )
  7778. return;
  7779. } catch (_) {}
  7780. clearTimeout(this.resizeTimer);
  7781. this.resizeTimer = null;
  7782. document.removeEventListener("pointerup", cancelPendingResize, true);
  7783. document.removeEventListener(
  7784. "pointercancel",
  7785. cancelPendingResize,
  7786. true
  7787. );
  7788. };
  7789. // 功能说明:用 document+capture 监听,避免 window 监听在部分容器/iframe 场景丢事件导致拖拽无响应 by xu 20260122
  7790. document.addEventListener("pointerup", cancelPendingResize, {
  7791. passive: false,
  7792. once: true,
  7793. capture: true,
  7794. });
  7795. document.addEventListener("pointercancel", cancelPendingResize, {
  7796. passive: false,
  7797. once: true,
  7798. capture: true,
  7799. });
  7800. const startY = e?.clientY ?? 0;
  7801. const gapEl = e?.currentTarget;
  7802. // 功能说明:记录 gap 前后 section 节点,拖拽过程中直接写入 style.height,避免某些环境下 Vue render 不刷新导致“拖拽无视觉变化” by xu 20260122
  7803. this.__resizePrevSectionEl = gapEl?.previousElementSibling || null;
  7804. this.__resizeNextSectionEl = gapEl?.nextElementSibling || null;
  7805. this.resizeTimer = setTimeout(() => {
  7806. // 定时器触发后进入拖拽态,移除“取消等待”监听,避免误取消 by xu 20260122
  7807. document.removeEventListener("pointerup", cancelPendingResize, true);
  7808. document.removeEventListener(
  7809. "pointercancel",
  7810. cancelPendingResize,
  7811. true
  7812. );
  7813. this.resizing = true;
  7814. this.resizeIndex = index;
  7815. this.resizeStartY = startY;
  7816. this.resizeStartPrev = this.sectionHeights[index] ?? 190;
  7817. this.resizeStartNext = this.sectionHeights[index + 1] ?? 190;
  7818. gapEl?.classList?.add("is-active");
  7819. try {
  7820. if (gapEl?.setPointerCapture && pointerId != null)
  7821. gapEl.setPointerCapture(pointerId);
  7822. } catch (_) {} // 功能说明:捕获 pointer,避免拖拽过程中移出窗口导致 pointermove 丢失 by xu 20260122
  7823. // 功能说明:用 document+capture,确保拖拽时 pointermove/up 不会被中途 stopPropagation 影响 by xu 20260122
  7824. document.addEventListener(
  7825. "pointermove",
  7826. this.__resizeMoveHandler || this.onResizeMove,
  7827. { passive: false, capture: true }
  7828. );
  7829. document.addEventListener(
  7830. "pointerup",
  7831. this.__resizeEndHandler || this.endResize,
  7832. { passive: false, once: true, capture: true }
  7833. );
  7834. document.addEventListener(
  7835. "pointercancel",
  7836. this.__resizeCancelHandler || this.endResize,
  7837. { passive: false, once: true, capture: true }
  7838. ); // 功能说明:触控/手势取消时也要结束拖拽 by xu 20260122
  7839. }, 500);
  7840. },
  7841. onResizeMove(e) {
  7842. if (!this.resizing) return;
  7843. if (e?.preventDefault) e.preventDefault();
  7844. const dy = (e?.clientY ?? 0) - this.resizeStartY;
  7845. const minPanelHeight = 83; // header(35) + listMin(48) by xu 20260106
  7846. const prev = Math.max(minPanelHeight, this.resizeStartPrev + dy);
  7847. const next = Math.max(minPanelHeight, this.resizeStartNext - dy);
  7848. // 若其中一个达到最小值,则停止继续挤压 by xu 20260106
  7849. const adjustedDy = prev - this.resizeStartPrev;
  7850. const nextAdjusted = this.resizeStartNext - adjustedDy;
  7851. const appliedPrev = prev;
  7852. const appliedNext = Math.max(minPanelHeight, nextAdjusted);
  7853. this.sectionHeights.splice(this.resizeIndex, 1, appliedPrev);
  7854. this.sectionHeights.splice(this.resizeIndex + 1, 1, appliedNext);
  7855. // 功能说明:强制触发一次 sectionHeights 引用变化,避免某些运行时环境下 splice 未触发视图更新导致“拖拽没反应” by xu 20260122
  7856. this.sectionHeights = (this.sectionHeights || []).slice();
  7857. // 功能说明:兜底——直接写 DOM 的 height,确保视觉立即响应(用于排查/修复某些环境下 render 不更新) by xu 20260122
  7858. try {
  7859. if (this.__resizePrevSectionEl?.style)
  7860. this.__resizePrevSectionEl.style.height = appliedPrev + "px";
  7861. if (this.__resizeNextSectionEl?.style)
  7862. this.__resizeNextSectionEl.style.height = appliedNext + "px";
  7863. } catch (_) {}
  7864. },
  7865. endResize(e) {
  7866. clearTimeout(this.resizeTimer);
  7867. this.resizeTimer = null;
  7868. if (!this.resizing) return;
  7869. if (e?.preventDefault) e.preventDefault();
  7870. const activeGaps = document.querySelectorAll(
  7871. ".ss-sidebar-gap.is-active"
  7872. );
  7873. activeGaps.forEach((g) => g.classList.remove("is-active"));
  7874. this.resizing = false;
  7875. this.resizeIndex = -1;
  7876. this.__resizePrevSectionEl = null; // 功能说明:释放 DOM 引用,避免内存泄漏 by xu 20260122
  7877. this.__resizeNextSectionEl = null; // 功能说明:释放 DOM 引用,避免内存泄漏 by xu 20260122
  7878. document.removeEventListener(
  7879. "pointermove",
  7880. this.__resizeMoveHandler || this.onResizeMove,
  7881. true
  7882. );
  7883. document.removeEventListener(
  7884. "pointercancel",
  7885. this.__resizeCancelHandler || this.endResize,
  7886. true
  7887. ); // 功能说明:清理 cancel 监听,避免残留 by xu 20260122
  7888. },
  7889. },
  7890. watch: {
  7891. panels: {
  7892. handler(nextPanels) {
  7893. this.__syncSectionAutoCollapse(nextPanels);
  7894. },
  7895. deep: true,
  7896. immediate: true,
  7897. },
  7898. list: {
  7899. handler(nextList) {
  7900. if ((this.panels || []).length) return;
  7901. this.__syncSectionAutoCollapse(nextList);
  7902. },
  7903. deep: true,
  7904. immediate: true,
  7905. },
  7906. },
  7907. mounted() {
  7908. clearTimeout(this.resizeTimer);
  7909. this.resizeTimer = null;
  7910. // 功能说明:绑定拖拽事件 handler(用于 add/removeEventListener) by xu 20260122
  7911. if (!this.__resizeMoveHandler)
  7912. this.__resizeMoveHandler = (e) => this.onResizeMove?.(e);
  7913. if (!this.__resizeEndHandler)
  7914. this.__resizeEndHandler = (e) => this.endResize?.(e);
  7915. if (!this.__resizeCancelHandler)
  7916. this.__resizeCancelHandler = (e) => this.endResize?.(e);
  7917. // 功能说明:暂时回退为固定底部留白方案(CSS 控制),后续再定位遮挡根因 by xu 20260115
  7918. },
  7919. beforeUnmount() {
  7920. clearTimeout(this.resizeTimer);
  7921. this.resizeTimer = null;
  7922. document.removeEventListener(
  7923. "pointermove",
  7924. this.__resizeMoveHandler || this.onResizeMove,
  7925. true
  7926. );
  7927. document.removeEventListener(
  7928. "pointerup",
  7929. this.__resizeEndHandler || this.endResize,
  7930. true
  7931. );
  7932. document.removeEventListener(
  7933. "pointercancel",
  7934. this.__resizeCancelHandler || this.endResize,
  7935. true
  7936. );
  7937. },
  7938. render() {
  7939. const SsSidebarButtonsComp = Vue.resolveComponent("ss-sidebar-buttons");
  7940. const SsSidebarChartComp = Vue.resolveComponent("ss-sidebar-chart");
  7941. const SsSidebarListComp = Vue.resolveComponent("ss-sidebar-list");
  7942. const SsSidebarReportTableComp = Vue.resolveComponent(
  7943. "ss-sidebar-report-table"
  7944. );
  7945. const SsIcon = Vue.resolveComponent("ss-icon");
  7946. // 支持 panels(多分区),list/listMode 作为 legacy 兜底 by xu 20260106
  7947. const panels = (this.panels || []).length
  7948. ? this.panels
  7949. : this.list?.length
  7950. ? [
  7951. {
  7952. type: "list",
  7953. title: "已选",
  7954. icon: "",
  7955. mode: this.listMode,
  7956. items: this.list,
  7957. },
  7958. ]
  7959. : [];
  7960. // 功能说明:右侧栏强制移除“对象”tab(兼容后端返回 rbarObj/rbarobj 或直接返回中文“对象”标题) by xu 20260116
  7961. const panelsNoObj = (panels || []).filter((p) => {
  7962. const k = String(p?._tabKey ?? "")
  7963. .trim()
  7964. .toLowerCase();
  7965. const t = String(p?.title ?? "").trim();
  7966. if (k === "rbarobj") return false;
  7967. if (t === "对象") return false;
  7968. return true;
  7969. });
  7970. // 功能说明:report-table 作为底部报表区(放在统计图下面),不参与可拖拽 section 面板 by xu 20260115
  7971. const sectionPanels = panelsNoObj.filter(
  7972. (p) => p?.type !== "chart" && p?.type !== "report-table"
  7973. );
  7974. const chartPanels = panelsNoObj.filter((p) => p?.type === "chart");
  7975. const reportPanels = panelsNoObj.filter(
  7976. (p) => p?.type === "report-table"
  7977. );
  7978. this.ensureSectionHeights(sectionPanels.length);
  7979. // 功能说明:补齐 chart/report 折叠数组长度 by xu 20260116
  7980. this.chartCollapsed = Array.from(
  7981. { length: chartPanels.length },
  7982. (_, i) => !!this.chartCollapsed?.[i]
  7983. );
  7984. this.chartHeaderTitleDownAt = Array.from(
  7985. { length: chartPanels.length },
  7986. (_, i) => this.chartHeaderTitleDownAt?.[i] ?? 0
  7987. );
  7988. this.reportCollapsed = Array.from(
  7989. { length: reportPanels.length },
  7990. (_, i) => !!this.reportCollapsed?.[i]
  7991. );
  7992. return Vue.h("div", { class: "ss-sidebar" }, [
  7993. this.buttons?.length
  7994. ? Vue.h(SsSidebarButtonsComp, { items: this.buttons })
  7995. : null,
  7996. Vue.h(
  7997. "div",
  7998. { class: "ss-sidebar__inner" },
  7999. [
  8000. ...(this.charts || []).map((c) =>
  8001. Vue.h(SsSidebarChartComp, {
  8002. options: c?.options || {},
  8003. height: c?.height || "200px",
  8004. })
  8005. ),
  8006. // 可拖拽的业务面板容器 by xu 20260106
  8007. Vue.h(
  8008. "div",
  8009. { class: "ss-sidebar-sections", style: { flex: "0 0 auto" } },
  8010. sectionPanels.flatMap((p, idx) => {
  8011. const panelContent =
  8012. p?.type === "report-table"
  8013. ? Vue.h(SsSidebarReportTableComp, {
  8014. key: `ss-sidebar-report-in-section-${idx}-${
  8015. p?.title ?? ""
  8016. }`,
  8017. title: p?.title ?? "",
  8018. icon: p?.icon ?? "",
  8019. iconClass: p?.iconClass ?? "",
  8020. items: p?.items || [],
  8021. onOpen: (srv, ctx) => p?.onOpen?.(srv, ctx),
  8022. })
  8023. : Vue.h(SsSidebarListComp, {
  8024. key: `ss-sidebar-list-${idx}-${p?.title ?? ""}`,
  8025. title: p?.title ?? "",
  8026. icon: p?.icon ?? "",
  8027. count: p?.count ?? p?.items?.length ?? "",
  8028. closable: !!p?.closable,
  8029. searchable: !!p?.searchable,
  8030. searchInHeader: !!p?.searchInHeader,
  8031. headerFilters: p?.headerFilters || [],
  8032. headerSearchButton: !!p?.headerSearchButton,
  8033. searchPlaceholder: p?.searchPlaceholder ?? "搜索",
  8034. itemLayout: p?.itemLayout ?? "simple",
  8035. itemAction: p?.itemAction ?? true,
  8036. collapsible: true,
  8037. collapsed: !!this.sectionCollapsed?.[idx],
  8038. onToggleCollapse: () =>
  8039. this.toggleSectionCollapse?.(idx),
  8040. iconClass: p?.iconClass ?? "",
  8041. items: p?.items || [],
  8042. mode: p?.mode || "search",
  8043. onSelect: (item) => this.$emit("select", item),
  8044. onRemove: (item) => this.$emit("remove", item),
  8045. onClear: () => p?.onClear?.(),
  8046. onSearch: (payload) => p?.onSearch?.(payload),
  8047. });
  8048. const section = Vue.h(
  8049. "div",
  8050. {
  8051. class: {
  8052. "ss-sidebar-section": true,
  8053. "is-collapsed": !!this.sectionCollapsed?.[idx],
  8054. },
  8055. key: `ss-sidebar-section-${idx}-${p?.type ?? "list"}-${
  8056. p?.title ?? ""
  8057. }`,
  8058. style: {
  8059. height: (this.sectionHeights[idx] ?? 190) + "px",
  8060. flex: "0 0 auto",
  8061. },
  8062. },
  8063. [
  8064. Vue.h("div", { class: "ss-sidebar-section__content" }, [
  8065. panelContent,
  8066. ]),
  8067. ]
  8068. );
  8069. const gap =
  8070. idx < sectionPanels.length - 1
  8071. ? Vue.h("div", {
  8072. class: "ss-sidebar-gap",
  8073. onPointerdown: (e) => this.startResize(idx, e),
  8074. })
  8075. : null;
  8076. return gap ? [section, gap] : [section];
  8077. })
  8078. ),
  8079. // 图表区固定在底部(hover 弹出大图) by xu 20260106
  8080. ...chartPanels.map((p, chartIdx) =>
  8081. Vue.h(
  8082. "div",
  8083. {
  8084. class: {
  8085. "ss-sidebar-panel": true,
  8086. "ss-sidebar-chart-panel": true,
  8087. "is-collapsed": !!this.chartCollapsed?.[chartIdx],
  8088. },
  8089. style: { flex: "0 0 auto", minHeight: "37px" },
  8090. "data-chart-idx": chartIdx,
  8091. key: `ss-sidebar-chart-${chartIdx}-${p?.title ?? ""}`,
  8092. },
  8093. [
  8094. p?.title
  8095. ? Vue.h(
  8096. "div",
  8097. {
  8098. class: "ss-sidebar-panel__header",
  8099. onDblclick: (e) => {
  8100. e?.preventDefault?.();
  8101. e?.stopPropagation?.();
  8102. console.log("[SsSidebar] chart header dblclick", {
  8103. idx: chartIdx,
  8104. title: p?.title,
  8105. });
  8106. this.toggleChartCollapse?.(chartIdx);
  8107. },
  8108. },
  8109. [
  8110. Vue.h("div", { class: "ss-sidebar-panel__title" }, [
  8111. p?.iconClass
  8112. ? Vue.h(SsIcon, {
  8113. class:
  8114. p.iconClass + " ss-sidebar-panel__icon",
  8115. })
  8116. : p?.icon
  8117. ? Vue.h(SsIcon, {
  8118. name: p.icon,
  8119. size: "16px",
  8120. class: "ss-sidebar-panel__icon",
  8121. })
  8122. : null,
  8123. Vue.h("span", null, p.title),
  8124. ]),
  8125. Vue.h("div", { class: "ss-sidebar-panel__tools" }),
  8126. ]
  8127. )
  8128. : null,
  8129. this.chartCollapsed?.[chartIdx]
  8130. ? null
  8131. : Vue.h(Vue.resolveComponent("ss-sidebar-chart-hover"), {
  8132. title: p?.title ?? "",
  8133. iconClass: p?.iconClass ?? "",
  8134. icon: p?.icon ?? "",
  8135. options: p?.options || {},
  8136. height: p?.height || "240px",
  8137. }),
  8138. ]
  8139. )
  8140. ),
  8141. ...reportPanels.map((p, reportIdx) =>
  8142. Vue.h(
  8143. "div",
  8144. {
  8145. class: {
  8146. "ss-sidebar-report-panel-wrap": true,
  8147. "ss-sidebar-report-panel": true,
  8148. "is-collapsed": !!this.reportCollapsed?.[reportIdx],
  8149. },
  8150. style: { flex: "0 0 auto", minHeight: "37px" },
  8151. "data-report-idx": reportIdx,
  8152. key: `ss-sidebar-report-wrap-${reportIdx}-${p?.title ?? ""}`,
  8153. },
  8154. [
  8155. Vue.h(SsSidebarReportTableComp, {
  8156. key: `ss-sidebar-report-${reportIdx}-${p?.title ?? ""}`,
  8157. title: p?.title ?? "",
  8158. icon: p?.icon ?? "",
  8159. iconClass: p?.iconClass ?? "",
  8160. items: p?.items || [],
  8161. collapsible: true,
  8162. collapsed: !!this.reportCollapsed?.[reportIdx],
  8163. onToggleCollapse: () =>
  8164. this.toggleReportCollapse?.(reportIdx),
  8165. onOpen: (srv, ctx) => p?.onOpen?.(srv, ctx),
  8166. }),
  8167. ]
  8168. )
  8169. ),
  8170. ].filter(Boolean)
  8171. ),
  8172. ]);
  8173. },
  8174. };
  8175. // ss-folder-card 文件夹卡片
  8176. const SsFolderCard = {
  8177. name: "SsFolderCard",
  8178. props: {
  8179. item: {
  8180. type: Object,
  8181. required: true,
  8182. },
  8183. },
  8184. data() {
  8185. return {
  8186. showButtons: false,
  8187. };
  8188. },
  8189. emits: ["click", "change"],
  8190. setup(props, { emit }) {
  8191. const item = props.item;
  8192. const showChildren = ref(false);
  8193. const eventBus = window.parent.sharedEventBus;
  8194. const itemWidth = Vue.computed(() => {
  8195. // 功能说明:页面改为 grid 等分布局后,卡片宽度交给容器控制,这里固定 100% by xu 20260116
  8196. return "100%";
  8197. });
  8198. onMounted(() => {
  8199. eventBus.subscribe("folderPath", (path) => {
  8200. const currentPath = path || [];
  8201. // 如果当前文件夹不在路径中,则销毁视图
  8202. if (
  8203. !currentPath.some((item) => item.folder.title === props.item.title)
  8204. ) {
  8205. showChildren.value = false;
  8206. }
  8207. });
  8208. });
  8209. const onItemClick = (e) => {
  8210. if (e && e.stopPropagation) {
  8211. e.stopPropagation();
  8212. }
  8213. // 单击只处理 active 状态
  8214. if (e && e.currentTarget) {
  8215. const allListCards = document.querySelectorAll(
  8216. ".knowledge-item-container"
  8217. );
  8218. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8219. allListCards.forEach((card) => card.classList.remove("active"));
  8220. allFolderCards.forEach((card) => card.classList.remove("active"));
  8221. e.currentTarget.classList.add("active");
  8222. } else {
  8223. // 如果是数据对象,需要找到对应的 DOM 元素
  8224. const allListCards = document.querySelectorAll(
  8225. ".knowledge-item-container"
  8226. );
  8227. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8228. allListCards.forEach((card) => card.classList.remove("active"));
  8229. allFolderCards.forEach((card) => card.classList.remove("active"));
  8230. // 找到标题匹配的文件夹元素
  8231. const targetFolder = Array.from(allFolderCards).find((card) =>
  8232. card.textContent.includes(e.title)
  8233. );
  8234. if (targetFolder) {
  8235. targetFolder.classList.add("active");
  8236. }
  8237. }
  8238. emit("click", item);
  8239. };
  8240. // 修改双击处理函数
  8241. const handleFolderDblClick = (folder, e) => {
  8242. if (e) e.stopPropagation();
  8243. if (folder.children?.length) {
  8244. showChildren.value = true;
  8245. const pathInfo = {
  8246. title: folder.title,
  8247. folder: folder,
  8248. };
  8249. const currentPath = eventBus.getState("folderPath") || [];
  8250. if (!currentPath.some((item) => item.title === folder.title)) {
  8251. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  8252. }
  8253. }
  8254. };
  8255. const onItemChange = (e, icon, index) => {
  8256. e.stopPropagation();
  8257. props.item.buttons[0].onclick();
  8258. // emit("change", { item: props.item, icon, index });
  8259. };
  8260. return {
  8261. item,
  8262. itemWidth,
  8263. showChildren,
  8264. onItemClick,
  8265. onItemChange,
  8266. handleFolderDblClick,
  8267. };
  8268. },
  8269. render() {
  8270. const SsCartListIcon = Vue.resolveComponent("ss-cart-list-icon");
  8271. if (this.showChildren) {
  8272. return h(SsFolderCartView, {
  8273. folder: this.item,
  8274. });
  8275. }
  8276. return Vue.h(
  8277. "div",
  8278. {
  8279. class: { "ss-folder-list": true, active: this.item.active },
  8280. onClick: (e) => {
  8281. e.stopPropagation();
  8282. this.onItemClick(e);
  8283. },
  8284. onDblclick: (e) => this.handleFolderDblClick(this.item, e),
  8285. style: { width: this.itemWidth },
  8286. },
  8287. [
  8288. // 文件夹特有的装饰元素
  8289. Vue.h("div", { class: "ss-folder-list-trapezoid" }),
  8290. Vue.h("div", { class: "ss-folder-list-top-transparent" }),
  8291. Vue.h("div", { class: "ss-folder-list-top" }),
  8292. Vue.h("div", { class: "ss-folder-list-right" }),
  8293. // header 部分(按钮)
  8294. this.item?.buttons?.length > 0 &&
  8295. Vue.h(
  8296. "div",
  8297. {
  8298. class: "header",
  8299. onMouseenter: () => (this.showButtons = true),
  8300. onMouseleave: () => (this.showButtons = false),
  8301. onClick: (e) => this.onItemChange(e, this.item.buttons[0], 0),
  8302. },
  8303. [
  8304. // this.item?.buttons?.length > 0 &&
  8305. Vue.h("div", {
  8306. class: "cart-list-setting cart-list-icon",
  8307. title: this.item?.buttons?.[0]?.title,
  8308. }),
  8309. // this.item?.buttons?.length > 0 &&
  8310. this.showButtons &&
  8311. this.item?.buttons?.length > 1 &&
  8312. Vue.h(
  8313. "div",
  8314. {
  8315. class: "cart-list-button-popup",
  8316. },
  8317. this.item.buttons.map((btn) =>
  8318. Vue.h(
  8319. "div",
  8320. {
  8321. onClick: (e) => {
  8322. e.stopPropagation();
  8323. btn.onclick?.();
  8324. },
  8325. },
  8326. [
  8327. btn.class &&
  8328. Vue.h(SsCartListIcon, {
  8329. class: [btn.class],
  8330. }),
  8331. Vue.h("span", null, btn.title),
  8332. ]
  8333. )
  8334. )
  8335. ),
  8336. ]
  8337. ),
  8338. // body 部分
  8339. Vue.h("div", { class: "body" }, [
  8340. Vue.h("div", { class: "box-header" }, [
  8341. Vue.h("div", null, this.item.title),
  8342. ]),
  8343. Vue.h(
  8344. "div",
  8345. {
  8346. class: !this.item.thumb ? "no-thumb box-body" : "box-body",
  8347. },
  8348. [
  8349. this.item.thumb
  8350. ? Vue.h("div", { class: "left" }, [
  8351. Vue.h("img", {
  8352. src: this.item.thumb,
  8353. alt: "Thumbnail",
  8354. class: "imgUnHandle",
  8355. style: {
  8356. "object-fit": "cover",
  8357. width: "100%",
  8358. height: "100%",
  8359. },
  8360. }),
  8361. ])
  8362. : null,
  8363. Vue.h("div", { class: "right" }, [
  8364. ...this.item.tags.map((tag) => {
  8365. const [key, value] = Object.entries(tag)[0];
  8366. return Vue.h(
  8367. "div",
  8368. {
  8369. class: "title",
  8370. title: `${key}: ${value}`,
  8371. },
  8372. `${key}: ${value}`
  8373. );
  8374. }),
  8375. ]),
  8376. ]
  8377. ),
  8378. ]),
  8379. ]
  8380. );
  8381. },
  8382. };
  8383. // SsFolderCartView 组件 - 用于显示文件夹内容
  8384. const SsFolderCartView = {
  8385. name: "SsFolderCartView",
  8386. props: {
  8387. folder: {
  8388. type: Object,
  8389. required: true,
  8390. },
  8391. },
  8392. emits: ["click"],
  8393. setup(props, { emit }) {
  8394. const eventBus = window.parent.sharedEventBus;
  8395. const currentFolder = ref(props.folder);
  8396. const showChildren = ref(false);
  8397. const onItemClick = (e) => {
  8398. if (e && e.stopPropagation) {
  8399. e.stopPropagation();
  8400. }
  8401. // 单击只处理 active 状态
  8402. if (e && e.currentTarget) {
  8403. const allListCards = document.querySelectorAll(
  8404. ".knowledge-item-container"
  8405. );
  8406. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8407. allListCards.forEach((card) => card.classList.remove("active"));
  8408. allFolderCards.forEach((card) => card.classList.remove("active"));
  8409. e.currentTarget.classList.add("active");
  8410. } else {
  8411. // 如果是数据对象,需要找到对应的 DOM 元素
  8412. const allListCards = document.querySelectorAll(
  8413. ".knowledge-item-container"
  8414. );
  8415. const allFolderCards = document.querySelectorAll(".ss-folder-list");
  8416. allListCards.forEach((card) => card.classList.remove("active"));
  8417. allFolderCards.forEach((card) => card.classList.remove("active"));
  8418. // 找到标题匹配的文件夹元素
  8419. const targetFolder = Array.from(allFolderCards).find((card) =>
  8420. card.textContent.includes(e.title)
  8421. );
  8422. if (targetFolder) {
  8423. targetFolder.classList.add("active");
  8424. }
  8425. }
  8426. emit("click", props.folder);
  8427. };
  8428. const handleFolderDblClick = (folder, e) => {
  8429. if (e) e.stopPropagation();
  8430. if (folder.children?.length) {
  8431. showChildren.value = true;
  8432. const pathInfo = {
  8433. title: folder.title,
  8434. folder: folder,
  8435. };
  8436. const currentPath = eventBus.getState("folderPath") || [];
  8437. if (!currentPath.some((item) => item.title === folder.title)) {
  8438. eventBus.publish("folderPath", [...currentPath, pathInfo]);
  8439. currentFolder.value = folder;
  8440. }
  8441. }
  8442. };
  8443. const goBack = (targetFolder) => {
  8444. if (targetFolder === null) {
  8445. // 返回根目录
  8446. eventBus.publish("folderPath", []);
  8447. } else {
  8448. currentFolder.value = targetFolder;
  8449. }
  8450. };
  8451. return {
  8452. currentFolder,
  8453. showChildren,
  8454. onItemClick,
  8455. handleFolderDblClick,
  8456. goBack,
  8457. };
  8458. },
  8459. render() {
  8460. return h(
  8461. "div",
  8462. {
  8463. class: "page-container",
  8464. style: {
  8465. position: "fixed",
  8466. top: 0,
  8467. left: 0,
  8468. width: "100%",
  8469. height: "100%",
  8470. background: "var(--lightgray)",
  8471. padding: "20px 0",
  8472. zIndex: 1000,
  8473. },
  8474. },
  8475. [
  8476. // 搜索栏
  8477. h("div", { class: "search-bar" }, [
  8478. h("div", { class: "search-bar-contaienr" }, [
  8479. h(SsBreadcrumb, {
  8480. level: {
  8481. onBack: this.goBack,
  8482. },
  8483. }),
  8484. ]),
  8485. ]),
  8486. // 内容区域
  8487. h(
  8488. "div",
  8489. {
  8490. class: "content-area item-content-area",
  8491. style: { gap: "20px" },
  8492. },
  8493. [
  8494. ...(this.currentFolder.children || []).map((child, index) =>
  8495. h(child.children ? SsFolderCard : SsListCard, {
  8496. key: index,
  8497. item: child,
  8498. onClick: (e) => this.onItemClick(e),
  8499. onDblclick: (e) => this.handleFolderDblClick(child, e),
  8500. })
  8501. ),
  8502. ]
  8503. ),
  8504. ]
  8505. );
  8506. },
  8507. };
  8508. // ss-page分页
  8509. const SsPage = {
  8510. name: "SsPage",
  8511. props: {
  8512. total: {
  8513. type: Number,
  8514. required: true,
  8515. },
  8516. size: {
  8517. type: Number,
  8518. default: 10,
  8519. },
  8520. page: {
  8521. type: Number,
  8522. default: 1,
  8523. },
  8524. onChange: {
  8525. type: Function,
  8526. default: () => {},
  8527. },
  8528. },
  8529. setup(props) {
  8530. const totalItems = ref(props.total); // 总条目数
  8531. const totalPages = ref(Math.ceil(props.total / props.size));
  8532. const currentPage = ref(props.page); // 当前页码
  8533. // 计算显示的信息
  8534. const pageInfo = ref(
  8535. `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`
  8536. );
  8537. // 上一页的逻辑
  8538. const goToPreviousPage = (e) => {
  8539. e.preventDefault(); // 阻止默认行为
  8540. if (currentPage.value > 1) {
  8541. currentPage.value -= 1;
  8542. updatePageInfo();
  8543. props.onChange?.({
  8544. pageNo: currentPage.value, // 当前页码
  8545. rowNumPer: props.size, // 每页条数
  8546. rowNum: props.total, // 总记录数
  8547. });
  8548. }
  8549. };
  8550. // 下一页的逻辑
  8551. const goToNextPage = (e) => {
  8552. e.preventDefault(); // 阻止默认行为
  8553. if (currentPage.value < totalPages.value) {
  8554. currentPage.value += 1;
  8555. updatePageInfo();
  8556. props.onChange?.({
  8557. pageNo: currentPage.value, // 当前页码
  8558. rowNumPer: props.size, // 每页条数
  8559. rowNum: props.total, // 总记录数
  8560. });
  8561. }
  8562. };
  8563. // 更新页码信息的函数
  8564. const updatePageInfo = () => {
  8565. pageInfo.value = `共${totalItems.value}条,第 ${currentPage.value}/${totalPages.value} 页`;
  8566. };
  8567. return {
  8568. pageInfo,
  8569. totalPages,
  8570. goToPreviousPage,
  8571. goToNextPage,
  8572. };
  8573. },
  8574. render(props, { slots, emit }) {
  8575. return Vue.h("div", { class: "pager-container" }, [
  8576. Vue.h("input", { type: "hidden", name: "rowNum", value: props.total }),
  8577. Vue.h("input", {
  8578. type: "hidden",
  8579. name: "rowNumPer",
  8580. value: props.size,
  8581. }),
  8582. Vue.h("input", {
  8583. type: "hidden",
  8584. name: "pageCount",
  8585. value: this.totalPages,
  8586. }),
  8587. Vue.h("input", { type: "hidden", name: "pageNo", value: props.page }),
  8588. Vue.h("div", { class: "pager-content" }, [
  8589. Vue.h("div", { class: "info" }, this.pageInfo),
  8590. Vue.h(
  8591. "div",
  8592. { class: "btn" },
  8593. Vue.h(
  8594. "button",
  8595. { onClick: (e) => this.goToPreviousPage(e) },
  8596. "上一页"
  8597. )
  8598. ),
  8599. Vue.h(
  8600. "div",
  8601. { class: "btn" },
  8602. Vue.h("button", { onClick: (e) => this.goToNextPage(e) }, "下一页")
  8603. ),
  8604. ]),
  8605. ]);
  8606. },
  8607. };
  8608. // ss-right-info 一级页面右边栏
  8609. const SSRightInfo = {
  8610. name: "SSRightInfo",
  8611. setup() {
  8612. // 初始化响应式数据
  8613. const item = ref({
  8614. thumb: "images/example/project-img.png", // 更换为适合你项目的实际路径
  8615. title: "工业和信息化产业高质量发展资金",
  8616. });
  8617. return {
  8618. item,
  8619. };
  8620. },
  8621. render() {
  8622. return Vue.h("div", { class: "info-container" }, [
  8623. Vue.h("div", { class: "header" }, [
  8624. Vue.h("div", [
  8625. Vue.h("img", {
  8626. src: this.item.thumb,
  8627. class: "imgUnHandle",
  8628. style: { "object-fit": "cover", width: "100%", height: "100%" },
  8629. }), // 将 ImageViewer 替换为 img 标签
  8630. ]),
  8631. Vue.h("div", [Vue.h("div", this.item.title)]),
  8632. ]),
  8633. Vue.h("div", { class: "section-container" }, [
  8634. Vue.h("div", { class: "section" }, [
  8635. Vue.h("div", { class: "title" }, "合同"),
  8636. Vue.h("div", { class: "text" }, "合同总金额:42,399,320"),
  8637. Vue.h(
  8638. "div",
  8639. { class: "a" },
  8640. "《工业和信息化产业高质量发展资金补助合同》"
  8641. ),
  8642. ]),
  8643. Vue.h("div", { class: "section" }, [
  8644. Vue.h("div", { class: "title" }, "发票"),
  8645. Vue.h("div", { class: "text" }, "应开发票总额:42,399,320"),
  8646. Vue.h("div", { class: "text" }, "已开发票金额:17,235,345"),
  8647. Vue.h("div", { class: "text" }, "未开发票金额:25,163,975"),
  8648. ]),
  8649. Vue.h("div", { class: "section" }, [
  8650. Vue.h("div", { class: "title" }, "项目组成员"),
  8651. Vue.h("div", { class: "text" }, "我司:3人"),
  8652. Vue.h("div", { class: "text" }, "对方:2人"),
  8653. Vue.h("div", { class: "text" }, "项目负责人:张三"),
  8654. ]),
  8655. Vue.h("div", { class: "section" }, [
  8656. Vue.h("div", { class: "title" }, "采购"),
  8657. Vue.h("div", { class: "text" }, "总额:999,320"),
  8658. Vue.h("div", { class: "text" }, "已付金额:335,345"),
  8659. Vue.h("div", { class: "text" }, "未付金额:663,975"),
  8660. ]),
  8661. ]),
  8662. ]);
  8663. },
  8664. };
  8665. //
  8666. const SsSuccessPopup = {
  8667. name: "SsSuccessPopup",
  8668. props: {
  8669. right: {
  8670. type: String,
  8671. default: "20px",
  8672. },
  8673. bottom: {
  8674. type: String,
  8675. default: "calc(100% + 5px)",
  8676. },
  8677. },
  8678. setup(props, { expose }) {
  8679. // 响应式状态:是否可见
  8680. const visible = ref(false);
  8681. // 计算样式
  8682. const style = computed(() => {
  8683. return {
  8684. "--message-dialog-right": props.right,
  8685. "--message-dialog-bottom": props.bottom,
  8686. };
  8687. });
  8688. // 显示对话框的方法
  8689. const show = () => {
  8690. visible.value = true;
  8691. };
  8692. // 隐藏对话框的方法
  8693. const hide = () => {
  8694. visible.value = false;
  8695. };
  8696. // 将方法暴露给外部使用
  8697. expose({ show, hide });
  8698. // 返回渲染函数
  8699. return () => {
  8700. if (!visible.value) return null;
  8701. const SsIcon = resolveComponent("ss-icon");
  8702. return h(
  8703. "div",
  8704. {
  8705. class: "success-popup",
  8706. style: style.value,
  8707. onClick: (e) => e.stopPropagation(),
  8708. },
  8709. [
  8710. h("div", { class: "left" }, [
  8711. h("div", { class: "icon" }, [
  8712. h(SsIcon, { name: "check", size: "36px" }),
  8713. ]),
  8714. ]),
  8715. h("div", { class: "right" }, [
  8716. h("div", { class: "title" }, "提交成功"),
  8717. h("div", { class: "desc" }, "您的信息已成功提交。"),
  8718. ]),
  8719. ]
  8720. );
  8721. };
  8722. },
  8723. };
  8724. const SsErrorDialog = {
  8725. name: "SsErrorDialog",
  8726. setup(props, { emit }) {
  8727. const visible = ref(false);
  8728. const style = computed(() => {
  8729. return {};
  8730. });
  8731. const show = () => {
  8732. visible.value = true;
  8733. };
  8734. const hide = () => {
  8735. visible.value = false;
  8736. };
  8737. const onBack = () => {
  8738. emit("back");
  8739. hide();
  8740. };
  8741. return {
  8742. visible,
  8743. style,
  8744. show,
  8745. hide,
  8746. onBack,
  8747. };
  8748. },
  8749. render() {
  8750. const SsIcon = resolveComponent("ss-icon");
  8751. return this.visible
  8752. ? h(
  8753. "div",
  8754. {
  8755. class: "errorDialog",
  8756. style: this.style,
  8757. onClick: (event) => event.stopPropagation(),
  8758. },
  8759. [
  8760. h("div", { class: "body" }, [
  8761. h("div", { class: "left" }, [
  8762. h("div", { class: "icon" }, [
  8763. h(SsIcon, { name: "close", size: "36px" }),
  8764. ]),
  8765. ]),
  8766. h("div", { class: "right" }, [
  8767. h("div", { class: "title" }, "操作失败"),
  8768. h("div", { class: "desc" }, "请点击返回以继续。"),
  8769. ]),
  8770. ]),
  8771. h("div", { class: "footer" }, [
  8772. h("div", { class: "left" }),
  8773. h("div", { class: "right" }, [
  8774. h(
  8775. "div",
  8776. {
  8777. class: "btn",
  8778. onClick: this.onBack,
  8779. },
  8780. [h(SsIcon, { name: "arrow-left-line" }), h("div", "返回")]
  8781. ),
  8782. ]),
  8783. ]),
  8784. ]
  8785. )
  8786. : null;
  8787. },
  8788. };
  8789. /**
  8790. * 审核链条
  8791. * @name ss-verify
  8792. * @param { Array } verify-list 审核节点列表
  8793. * @property { Array } verify-list 审核节点列表
  8794. * @example <ss-verify :verify-list="verifyList"></ss-verify>
  8795. * verify-list [
  8796. * {
  8797. * groupName: "", // 群组名称
  8798. * open: true, // 默认是否展开
  8799. * children:[ //群组里的人员
  8800. * {
  8801. * thumb: "images/example/user-4.png", // 头像
  8802. * name: "李丽思 ", // 姓名
  8803. * role: "人事处处长", // 角色
  8804. * description: "同意。", // 审核意见
  8805. * time: "09:38 08/11", // 审核时间
  8806. * video: false, // false不显示/true显示 视频icon
  8807. * link: false, // false不显示/true显示 链接icon 后续应该是附件
  8808. * }
  8809. * ]
  8810. * }
  8811. * ]
  8812. */
  8813. const SsVerify = {
  8814. name: "SsVerify",
  8815. props: {
  8816. verifyList: {
  8817. type: Array,
  8818. required: true,
  8819. },
  8820. },
  8821. setup(props) {
  8822. const toggleOpen = (item) => {
  8823. item.open = !item.open;
  8824. };
  8825. onMounted(() => {
  8826. setTimeout(() => {
  8827. const lastOpenGroup = document.querySelector(".group-item-last-open");
  8828. console.log("lastOpenGroup", lastOpenGroup);
  8829. if (lastOpenGroup) {
  8830. const nodes = $(lastOpenGroup).find(".verify-node-container");
  8831. if (nodes.length) {
  8832. let totalHeight = 0;
  8833. const gudingHeight = 100;
  8834. if (nodes.length === 1) {
  8835. totalHeight = gudingHeight;
  8836. } else {
  8837. // 累加除最后一个节点外的所有节点高度
  8838. for (let i = 0; i < nodes.length - 1; i++) {
  8839. totalHeight += $(nodes[i]).outerHeight();
  8840. }
  8841. totalHeight += gudingHeight;
  8842. }
  8843. console.log("节点信息:", {
  8844. 节点总数: nodes.length,
  8845. 计算后的高度: totalHeight,
  8846. });
  8847. lastOpenGroup.style.setProperty(
  8848. "--group-line-height",
  8849. `${totalHeight}px`
  8850. );
  8851. }
  8852. }
  8853. }, 0);
  8854. });
  8855. return {
  8856. toggleOpen,
  8857. };
  8858. },
  8859. render() {
  8860. const SsIcon = resolveComponent("ss-icon");
  8861. const SsCommonIcon = resolveComponent("ss-common-icon");
  8862. const SsVerifyNode = resolveComponent("ss-verify-node");
  8863. return h(
  8864. "div",
  8865. { class: "verify-nodes" },
  8866. this.verifyList.map((item, i) =>
  8867. h(
  8868. "div",
  8869. {
  8870. key: i,
  8871. class: {
  8872. "group-item": true,
  8873. "group-item-last-open":
  8874. i === this.verifyList.length - 1 && item.open,
  8875. },
  8876. },
  8877. [
  8878. h(
  8879. "div",
  8880. {
  8881. class: "group-item-title",
  8882. onClick: () => this.toggleOpen(item),
  8883. },
  8884. [
  8885. h("div", { class: "icon" }, [
  8886. item.open
  8887. ? h(SsCommonIcon, { class: "common-icon-folder-open" })
  8888. : h(SsCommonIcon, { class: "common-icon-folder-close" }),
  8889. h(
  8890. "div",
  8891. {
  8892. class: "num",
  8893. style: { top: item.open ? "60%" : "55%" },
  8894. },
  8895. item.children?.length || 0
  8896. ),
  8897. ]),
  8898. h("div", { class: "name" }, item.groupName),
  8899. ]
  8900. ),
  8901. item.open && item.children?.length > 0
  8902. ? h(
  8903. "div",
  8904. { class: "group-item-children" },
  8905. item.children.map((citem, j) =>
  8906. h(SsVerifyNode, {
  8907. key: j,
  8908. item: citem,
  8909. // isGroup: i + 1 !== this.verifyList.length,
  8910. isGroup: true,
  8911. })
  8912. )
  8913. )
  8914. : null,
  8915. ]
  8916. )
  8917. )
  8918. );
  8919. },
  8920. };
  8921. /**
  8922. * 审核页面的审核节点
  8923. * @name ss-verify-node
  8924. * @param {Object} item 审核节点信息
  8925. * @param {Boolean} isGroup 是否为分组节点
  8926. */
  8927. const SsVerifyNode = {
  8928. name: "SsVerifyNode",
  8929. props: {
  8930. item: {
  8931. type: Object,
  8932. required: true,
  8933. },
  8934. isGroup: {
  8935. type: Boolean,
  8936. default: false,
  8937. },
  8938. },
  8939. render() {
  8940. const SsIcon = resolveComponent("ss-icon");
  8941. const SsCommonIcon = resolveComponent("ss-common-icon");
  8942. return Vue.h("div", { class: "verify-node-container" }, [
  8943. Vue.h("div", { class: "info" }, [
  8944. Vue.h("div", { class: "avatar" }, [
  8945. Vue.h("img", {
  8946. src: this.item.thumb,
  8947. style: {
  8948. width: "50px",
  8949. height: "50px",
  8950. borderRadius: "50%",
  8951. },
  8952. }),
  8953. ]),
  8954. Vue.h("div", { class: "desc" }, [
  8955. Vue.h("div", this.item.name),
  8956. Vue.h("div", this.item.role),
  8957. ]),
  8958. Vue.h("div", { class: "link" }, [
  8959. Vue.h("div", [
  8960. this.item.video
  8961. ? Vue.h(SsCommonIcon, { class: "common-icon-video" })
  8962. : null,
  8963. this.item.link
  8964. ? Vue.h(SsCommonIcon, {
  8965. class: "common-icon-paper-clip",
  8966. })
  8967. : null,
  8968. ]),
  8969. ]),
  8970. ]),
  8971. Vue.h(
  8972. "div",
  8973. {
  8974. class: {
  8975. description: true,
  8976. link: this.isGroup,
  8977. },
  8978. attrs: { "data-num": "3" },
  8979. },
  8980. [Vue.h("div", this.item.description)]
  8981. ),
  8982. Vue.h("div", { class: "time" }, this.item.time),
  8983. ]);
  8984. },
  8985. };
  8986. /**
  8987. * 智能识别图片的左侧图片播放 可以放大缩小旋转图片
  8988. * @name ss-orc-img-box
  8989. * @param { Object } image-obj 包含图片的url, 和图片的名称
  8990. *
  8991. */
  8992. const SsOrcImgBox = {
  8993. name: "SsOrcImgBox",
  8994. props: {
  8995. imageObj: {
  8996. type: Object,
  8997. required: true,
  8998. },
  8999. },
  9000. setup(props) {
  9001. const zoom = ref(1);
  9002. const rotation = ref(0);
  9003. const containerWidth = ref(0);
  9004. const containerHeight = ref(0);
  9005. const container = ref(null);
  9006. const imgPosition = ref({ x: 0, y: 0 });
  9007. const isDragging = ref(false);
  9008. const lastMousePosition = ref({ x: 0, y: 0 });
  9009. const imgStyle = computed(() => ({
  9010. width: `${zoom.value * 100}%`,
  9011. height: `${zoom.value * 100}%`,
  9012. transform: `rotate(${rotation.value}deg) translate(${imgPosition.value.x}px, ${imgPosition.value.y}px)`,
  9013. transformOrigin: "center center",
  9014. cursor: isDragging.value ? "grabbing" : "grab",
  9015. }));
  9016. const resetZoom = () => {
  9017. zoom.value = 1;
  9018. rotation.value = rotation.value + 90;
  9019. imgPosition.value = { x: 0, y: 0 };
  9020. };
  9021. const handleRangeChange = (event) => {
  9022. const value = event.target.value / 50; // 0 到 100 映射到 0 到 2 的缩放
  9023. zoom.value = Math.max(value, 0.1); // 设置最小缩放值为 0.1
  9024. };
  9025. const updateImgBoxDimensions = () => {
  9026. if (container.value) {
  9027. containerWidth.value = container.value.clientWidth;
  9028. containerHeight.value = container.value.clientHeight;
  9029. }
  9030. };
  9031. const onMouseDown = (event) => {
  9032. isDragging.value = true;
  9033. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  9034. };
  9035. const onMouseMove = (event) => {
  9036. if (isDragging.value) {
  9037. const dx = event.clientX - lastMousePosition.value.x;
  9038. const dy = event.clientY - lastMousePosition.value.y;
  9039. // 防止旋转后拖动的x,y反转
  9040. // 首先将当前旋转角度从度数转换为弧度,因为 JavaScript 的 Math 库使用弧度
  9041. const angle = rotation.value * (Math.PI / 180);
  9042. // 使用基本的二维旋转矩阵将原始位移 dx 和 dy 转换为旋转后的位移 rotatedDx 和 rotatedDy。
  9043. const rotatedDx = dx * Math.cos(angle) + dy * Math.sin(angle);
  9044. const rotatedDy = dy * Math.cos(angle) - dx * Math.sin(angle);
  9045. imgPosition.value = {
  9046. x: imgPosition.value.x + rotatedDx,
  9047. y: imgPosition.value.y + rotatedDy,
  9048. };
  9049. lastMousePosition.value = { x: event.clientX, y: event.clientY };
  9050. }
  9051. };
  9052. const onMouseUp = () => {
  9053. isDragging.value = false;
  9054. };
  9055. onMounted(() => {
  9056. nextTick(() => {
  9057. updateImgBoxDimensions();
  9058. window.addEventListener("resize", updateImgBoxDimensions);
  9059. window.addEventListener("mousemove", onMouseMove);
  9060. window.addEventListener("mouseup", onMouseUp);
  9061. });
  9062. });
  9063. return {
  9064. zoom,
  9065. rotation,
  9066. container,
  9067. imgStyle,
  9068. resetZoom,
  9069. handleRangeChange,
  9070. containerWidth,
  9071. containerHeight,
  9072. onMouseDown,
  9073. imgPosition,
  9074. };
  9075. },
  9076. render() {
  9077. const SsIcon = resolveComponent("ss-icon");
  9078. return h("div", { class: "ocr-img-box" }, [
  9079. h("div", { class: "img-bar" }, [
  9080. h("div", this.imageObj.name),
  9081. h("div", { class: "action-bar" }, [
  9082. h("div", { class: "ocr-img-range-box" }, [
  9083. h("input", {
  9084. type: "range",
  9085. min: 0,
  9086. max: 100,
  9087. value: this.zoom * 50, // 初始位置为50
  9088. onInput: this.handleRangeChange,
  9089. }),
  9090. h("span", { class: "line" }),
  9091. ]),
  9092. h(SsIcon, {
  9093. name: "reset",
  9094. size: "26px",
  9095. onClick: this.resetZoom,
  9096. }),
  9097. ]),
  9098. ]),
  9099. h("div", { class: "img-viewer", ref: "container" }, [
  9100. h(
  9101. "div",
  9102. {
  9103. class: "img-box",
  9104. style: {
  9105. width: `${this.containerWidth}px`,
  9106. height: `${this.containerHeight}px`,
  9107. overflow: "hidden",
  9108. position: "relative",
  9109. },
  9110. },
  9111. [
  9112. h("img", {
  9113. src: this.imageObj.thumb,
  9114. style: this.imgStyle,
  9115. class: "zoomable-img",
  9116. onMousedown: this.onMouseDown,
  9117. }),
  9118. ]
  9119. ),
  9120. ]),
  9121. ]);
  9122. },
  9123. };
  9124. // 搜索输入框组件
  9125. const SsSearchInput = {
  9126. name: "SsSearchInput",
  9127. props: {
  9128. name: String,
  9129. placeholder: String,
  9130. width: {
  9131. type: String,
  9132. default: "100px",
  9133. },
  9134. modelValue: String,
  9135. },
  9136. emits: ["update:modelValue", "search"],
  9137. setup(props, { emit }) {
  9138. const handleInput = (e) => {
  9139. emit("update:modelValue", e.target.value);
  9140. };
  9141. const handleKeyup = (e) => {
  9142. if (e.key === "Enter") {
  9143. emit("search");
  9144. }
  9145. };
  9146. return { handleInput, handleKeyup };
  9147. },
  9148. render() {
  9149. return h(
  9150. "div",
  9151. {
  9152. class: "input",
  9153. style: this.width ? { width: this.width } : undefined,
  9154. },
  9155. [
  9156. h("input", {
  9157. name: this.name,
  9158. placeholder: this.placeholder,
  9159. value: this.modelValue,
  9160. onInput: this.handleInput,
  9161. onKeyup: this.handleKeyup,
  9162. }),
  9163. ]
  9164. );
  9165. },
  9166. };
  9167. // ss-search-date-picker 日期时间选择器组件
  9168. const SsSearchDatePicker = {
  9169. name: "SsSearchDatePicker",
  9170. props: {
  9171. modelValue: {
  9172. type: [String, Number, Date],
  9173. default: "",
  9174. },
  9175. name: {
  9176. type: String,
  9177. required: true,
  9178. },
  9179. type: {
  9180. type: String,
  9181. default: "date",
  9182. validator: (value) => ["date", "datetime", "time"].includes(value),
  9183. },
  9184. fmt: {
  9185. type: String,
  9186. default: null,
  9187. },
  9188. placeholder: {
  9189. type: String,
  9190. default: "",
  9191. },
  9192. width: {
  9193. type: String,
  9194. default: "100%",
  9195. },
  9196. },
  9197. emits: ["update:modelValue"],
  9198. setup(props, { emit }) {
  9199. const errMsg = ref("");
  9200. const validate = () => {
  9201. if (window.ssVm) {
  9202. const result = window.ssVm.validateField(props.name);
  9203. console.log("validate", window.ssVm.validateField(props.name));
  9204. errMsg.value = result.valid ? "" : result.message;
  9205. }
  9206. };
  9207. // 根据type确定默认格式
  9208. const defaultFormat = computed(() => {
  9209. switch (props.type) {
  9210. case "datetime":
  9211. return "YYYY-MM-DD HH:mm:ss";
  9212. case "date":
  9213. return "YYYY-MM-DD";
  9214. case "time":
  9215. return "HH:mm:ss";
  9216. }
  9217. });
  9218. const convertJavaFormatToElement = (javaFormat) => {
  9219. if (!javaFormat) return null;
  9220. return javaFormat
  9221. .replace("yyyy", "YYYY")
  9222. .replace("MM", "MM")
  9223. .replace("dd", "DD")
  9224. .replace("HH", "HH")
  9225. .replace("mm", "mm")
  9226. .replace("ss", "ss");
  9227. };
  9228. const finalFormat = computed(() => {
  9229. if (props.fmt) {
  9230. return convertJavaFormatToElement(props.fmt);
  9231. }
  9232. return defaultFormat.value;
  9233. });
  9234. // 使用 resolveComponent 获取组件
  9235. const ElDatePicker = resolveComponent("ElDatePicker");
  9236. const ElTimePicker = resolveComponent("ElTimePicker");
  9237. const SsFormIcon = resolveComponent("SsFormIcon");
  9238. const ElIcon = resolveComponent("ElIcon");
  9239. let useTimePicker = true;
  9240. //"yyyy-MM-dd HH:mm:ss"; "日期字符串格式在java的写法",传到本组件fmt属性也是按这个格式
  9241. if (props.fmt) {
  9242. //有fmt属性,则以fmt属性优先判断类型
  9243. if (/[dMy]/.test(props.fmt)) {
  9244. //如果有传入日期格式,且含年月日
  9245. useTimePicker = false;
  9246. } else {
  9247. useTimePicker = true;
  9248. }
  9249. } else if (props.type !== "time") {
  9250. useTimePicker = false;
  9251. }
  9252. const dateType = computed(() => {
  9253. const fmt = props.fmt || "";
  9254. if (fmt.includes("HH:mm:ss")) {
  9255. return "datetime";
  9256. } else if (fmt.includes("HH:mm")) {
  9257. return "datetime";
  9258. } else if (fmt.includes("mm:ss")) {
  9259. return "time";
  9260. }
  9261. return "date";
  9262. });
  9263. const handleValueUpdate = (val) => {
  9264. emit("update:modelValue", val);
  9265. emit("change", val); // 同时触发 change 事件
  9266. setTimeout(() => {
  9267. validate();
  9268. }, 50);
  9269. };
  9270. return () =>
  9271. h(
  9272. "div",
  9273. { class: "ss-search-date-picker", style: { width: props.width } },
  9274. [
  9275. h("input", {
  9276. type: "hidden",
  9277. name: props.name,
  9278. value: props.modelValue,
  9279. }),
  9280. h(useTimePicker ? ElTimePicker : ElDatePicker, {
  9281. modelValue: props.modelValue,
  9282. "onUpdate:modelValue": handleValueUpdate,
  9283. type: dateType.value,
  9284. format: finalFormat.value,
  9285. "value-format": finalFormat.value,
  9286. clearable: true,
  9287. placeholder: props.placeholder,
  9288. class: "custom-date-picker", // 用于自定义样式
  9289. "time-arrow-control": props.type === "datetime", // 修改这里
  9290. size: "large", // 添加这一行,改为 large 尺寸
  9291. style: { width: "100%" },
  9292. "prefix-icon": h(SsFormIcon, { class: "form-icon-time" }),
  9293. }),
  9294. ]
  9295. );
  9296. },
  9297. };
  9298. // 搜索按钮组件(包含下拉按钮)
  9299. const SsSearchButton = {
  9300. name: "SsSearchButton",
  9301. props: {
  9302. text: {
  9303. type: String,
  9304. required: true,
  9305. },
  9306. iconClass: {
  9307. type: String,
  9308. required: false,
  9309. },
  9310. opt: {
  9311. type: Array,
  9312. default: () => [],
  9313. },
  9314. checkId: {
  9315. type: String,
  9316. default: "0",
  9317. },
  9318. width: {
  9319. //add by Ben(20251225)
  9320. type: String,
  9321. required: false,
  9322. },
  9323. id: {
  9324. //add by Ben(20251225)
  9325. type: String,
  9326. required: false,
  9327. },
  9328. },
  9329. emits: ["click"],
  9330. setup(props, { emit }) {
  9331. const currentId = ref(props.checkId || "0");
  9332. const showPopup = ref(false);
  9333. const handleMouseEnter = () => {
  9334. showPopup.value = true;
  9335. };
  9336. const handleMouseLeave = () => {
  9337. showPopup.value = false;
  9338. };
  9339. // 添加点击事件处理,阻止默认行为
  9340. const handleClick = (e) => {
  9341. e.preventDefault();
  9342. if (props.opt?.length > 0) {
  9343. const selectedOption =
  9344. currentId.value === "0"
  9345. ? props.opt[0]
  9346. : props.opt.find((opt) => opt.id === currentId.value);
  9347. if (selectedOption) {
  9348. selectedOption.callback?.();
  9349. }
  9350. } else {
  9351. emit("click", e);
  9352. }
  9353. };
  9354. // 获取显示文本
  9355. const getDisplayText = () => {
  9356. if (!props.opt?.length) return props.text;
  9357. const selectedOption =
  9358. currentId.value === "0"
  9359. ? props.opt[0]
  9360. : props.opt.find((opt) => opt.id === currentId.value);
  9361. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  9362. };
  9363. return () =>
  9364. h(
  9365. "button",
  9366. {
  9367. class:
  9368. props.opt?.length > 0
  9369. ? "ss-drop-button ss-drop-button-more"
  9370. : "ss-drop-button",
  9371. type: "button", // 明确指定按钮类型为 button
  9372. onMouseenter: handleMouseEnter,
  9373. onMouseleave: handleMouseLeave,
  9374. onClick: handleClick, // 添加点击事件处理
  9375. style: { width: props.width }, //add by Ben(20251225)
  9376. id: props.id, //add by Ben(20251225)
  9377. },
  9378. [
  9379. props.iconClass
  9380. ? h("span", {
  9381. class: props.iconClass,
  9382. style: { fontFamily: "iconfont", marginRight: "5px" },
  9383. })
  9384. : null,
  9385. h("span", getDisplayText()),
  9386. props.opt.length > 0 &&
  9387. showPopup.value &&
  9388. h(
  9389. "div",
  9390. {
  9391. class: "popup",
  9392. },
  9393. props.opt.map((item) =>
  9394. h(
  9395. "div",
  9396. {
  9397. onClick: (e) => {
  9398. e.preventDefault(); // 选项点击也阻止默认行为
  9399. e.stopPropagation(); // 阻止事件冒泡
  9400. currentId.value = item.id; // 更新当前选中的ID
  9401. item.callback();
  9402. showPopup.value = false; // 选择后关闭弹窗
  9403. },
  9404. },
  9405. item.desc
  9406. )
  9407. )
  9408. ),
  9409. ]
  9410. );
  9411. },
  9412. };
  9413. // 下拉按钮组件
  9414. const SsDropButton = {
  9415. name: "SsDropButton",
  9416. props: {
  9417. text: {
  9418. type: String,
  9419. required: true,
  9420. },
  9421. iconClass: {
  9422. type: String,
  9423. required: true,
  9424. },
  9425. opt: {
  9426. type: Array,
  9427. default: () => [],
  9428. },
  9429. checkId: {
  9430. type: String,
  9431. default: "0",
  9432. },
  9433. onclick: {
  9434. type: Function,
  9435. default: null,
  9436. },
  9437. },
  9438. setup(props) {
  9439. const currentId = ref(props.checkId || "0");
  9440. const showPopup = ref(false);
  9441. const handleMouseEnter = () => {
  9442. showPopup.value = true;
  9443. };
  9444. const handleMouseLeave = () => {
  9445. showPopup.value = false;
  9446. };
  9447. // 添加点击事件处理,阻止默认行为
  9448. const handleClick = (e) => {
  9449. e.preventDefault();
  9450. if (props.opt?.length > 0) {
  9451. const selectedOption =
  9452. currentId.value === "0"
  9453. ? props.opt[0]
  9454. : props.opt.find((opt) => opt.id === currentId.value);
  9455. if (selectedOption) {
  9456. selectedOption.callback?.();
  9457. }
  9458. } else if (props.onclick) {
  9459. props.onclick();
  9460. }
  9461. };
  9462. // 获取显示文本
  9463. const getDisplayText = () => {
  9464. if (!props.opt?.length) return props.text;
  9465. const selectedOption =
  9466. currentId.value === "0"
  9467. ? props.opt[0]
  9468. : props.opt.find((opt) => opt.id === currentId.value);
  9469. return selectedOption ? selectedOption.desc : props.opt[0].desc;
  9470. };
  9471. return () =>
  9472. h(
  9473. "button",
  9474. {
  9475. class:
  9476. props.opt?.length > 0
  9477. ? "ss-drop-button ss-drop-button-more"
  9478. : "ss-drop-button",
  9479. type: "button", // 明确指定按钮类型为 button
  9480. onMouseenter: handleMouseEnter,
  9481. onMouseleave: handleMouseLeave,
  9482. onClick: handleClick, // 添加点击事件处理
  9483. },
  9484. [
  9485. h("span", {
  9486. class: props.iconClass,
  9487. style: { fontFamily: "iconfont" },
  9488. }),
  9489. h("span", getDisplayText()),
  9490. props.opt.length > 0 &&
  9491. showPopup.value &&
  9492. h(
  9493. "div",
  9494. {
  9495. class: "popup",
  9496. },
  9497. props.opt.map((item) =>
  9498. h(
  9499. "div",
  9500. {
  9501. onClick: (e) => {
  9502. e.preventDefault(); // 选项点击也阻止默认行为
  9503. e.stopPropagation(); // 阻止事件冒泡
  9504. currentId.value = item.id; // 更新当前选中的ID
  9505. item.callback();
  9506. showPopup.value = false; // 选择后关闭弹窗
  9507. },
  9508. },
  9509. item.desc
  9510. )
  9511. )
  9512. ),
  9513. ]
  9514. );
  9515. },
  9516. };
  9517. /**
  9518. * 二级页面标签组件
  9519. * @name ss-sub-tab
  9520. * @description 用于展示二级页面的布局组件,包含左侧垂直标签导航(支持分组)和右侧iframe内容区
  9521. * @property {String} headerImage - 左侧顶部图片地址
  9522. * @property {Array} menuList - 菜单配置列表
  9523. * @property {Object} [activeMenu] - 当前选中的菜单项,不传则自动选择第一个可选菜单
  9524. * @property {Array} footerButtons - 底部按钮配置列表
  9525. */
  9526. /**
  9527. * SsSubTab 左侧菜单+iframe内容组件
  9528. * v3.0 改造:去掉顶部图片,改为图标+悬浮模式,iframe懒加载 by xu 20251216
  9529. */
  9530. const SsSubTab = {
  9531. name: "SsSubTab",
  9532. props: {
  9533. menuList: {
  9534. type: Array,
  9535. required: true,
  9536. },
  9537. activeMenu: {
  9538. type: String,
  9539. default: "",
  9540. },
  9541. footerButtons: {
  9542. type: Array,
  9543. default: () => [],
  9544. },
  9545. leftDisplay: {
  9546. type: Boolean,
  9547. default: true,
  9548. },
  9549. // v3.0 新增:菜单模式 collapse(悬浮展开) / fixed(始终收起) by xu 20251216
  9550. initialMode: {
  9551. type: String,
  9552. default: "collapse",
  9553. },
  9554. },
  9555. emits: ["menu-change", "footer-click"],
  9556. setup(props, { emit }) {
  9557. // v3.0 新增:默认图标映射,使用icon-biz图标 by xu 20251216
  9558. const defaultIcons = [
  9559. "icon-obj-ry", // 人员
  9560. "icon-obj-dw", // 单位
  9561. "icon-obj-gw", // 岗位
  9562. "icon-biz-rc", // 人才
  9563. "icon-biz-xc", // 巡查
  9564. "icon-biz-cl", // 材料
  9565. "icon-biz-men", // 门
  9566. "icon-obj-xy", // 协议
  9567. ];
  9568. //功能: SsSubTab 支持后端下发 iconName + pobj/cobj 两级菜单 by xu 20251222
  9569. const isTrue = (v) => v === true || v === "true" || v === 1 || v === "1"; //功能 by xu 20251222
  9570. const resolveIconClass = (iconNameOrClass, fallbackIndex) => {
  9571. //功能 by xu 20251222
  9572. const fallback = `menu-icon ${
  9573. defaultIcons[fallbackIndex % defaultIcons.length]
  9574. }`;
  9575. if (!iconNameOrClass) {
  9576. return fallback;
  9577. }
  9578. // 已经是完整 class(可能包含 menu-icon / menu-base-icon / 多个 class)
  9579. if (
  9580. typeof iconNameOrClass === "string" &&
  9581. iconNameOrClass.indexOf(" ") > -1
  9582. ) {
  9583. return iconNameOrClass;
  9584. }
  9585. const iconName = iconNameOrClass;
  9586. if (iconName === "menu-icon" || iconName === "menu-base-icon") {
  9587. return fallback;
  9588. }
  9589. // 业务图标库:icon-biz / icon-obj -> menu-icon
  9590. if (
  9591. typeof iconName === "string" &&
  9592. (iconName.indexOf("icon-obj-") === 0 ||
  9593. iconName.indexOf("icon-biz-") === 0)
  9594. ) {
  9595. return `menu-icon ${iconName}`;
  9596. }
  9597. // 默认认为是 icon-base 图标 -> menu-base-icon
  9598. return `menu-base-icon ${iconName}`;
  9599. };
  9600. const getMenuIcon = (item, index) => {
  9601. //功能 by xu 20251222
  9602. if (!item) {
  9603. return resolveIconClass(null, index);
  9604. }
  9605. //功能: 变动图标后端暂不正确,前端先写死为 icon-chg by xu 20251223
  9606. if (item.title === "变动" || item.name === "sys_bd") {
  9607. return resolveIconClass("icon-chg", index);
  9608. }
  9609. // 兼容旧字段 icon(优先使用)
  9610. if (item.icon) return resolveIconClass(item.icon, index);
  9611. // v3.0 使用后端下发 iconName
  9612. if (item.iconName) return resolveIconClass(item.iconName, index);
  9613. return resolveIconClass(null, index);
  9614. };
  9615. //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  9616. const getFooterIcon = (button) => {
  9617. //功能 by xu 20251224
  9618. if (!button) return "menu-base-icon icon-subm";
  9619. const iconNameOrClass =
  9620. button.iconClass || button.iconName || button.icon;
  9621. if (!iconNameOrClass) return "menu-base-icon icon-subm";
  9622. if (
  9623. typeof iconNameOrClass === "string" &&
  9624. iconNameOrClass.indexOf(" ") > -1
  9625. ) {
  9626. return iconNameOrClass;
  9627. }
  9628. return `menu-base-icon ${iconNameOrClass}`;
  9629. };
  9630. //功能: pobj/cobj 扁平结构转换为 children 树结构,兼容原 children 结构 by xu 20251222
  9631. const normalizeMenuList = (rawList) => {
  9632. if (!Array.isArray(rawList) || rawList.length === 0) {
  9633. return [];
  9634. }
  9635. const hasTree = rawList.some(
  9636. (it) => Array.isArray(it?.children) && it.children.length > 0
  9637. );
  9638. if (hasTree) {
  9639. return rawList.map((it) => ({
  9640. ...it,
  9641. __level: 1,
  9642. children: Array.isArray(it.children)
  9643. ? it.children.map((c) => ({ ...c, __level: 2 }))
  9644. : it.children,
  9645. }));
  9646. }
  9647. const hasMarker = rawList.some(
  9648. (it) => it && ("pobj" in it || "cobj" in it)
  9649. );
  9650. if (!hasMarker) {
  9651. return rawList.map((it) => ({ ...it, __level: 1 }));
  9652. }
  9653. const result = [];
  9654. let currentGroup = null;
  9655. for (const item of rawList) {
  9656. //功能: “变动”始终按一级处理(即使后端误传 pobj/cobj)by xu 20251223
  9657. const isChgItem =
  9658. item && (item.title === "变动" || item.name === "sys_bd");
  9659. if (isChgItem) {
  9660. result.push({ ...item, __level: 1 });
  9661. continue;
  9662. }
  9663. const isParent = isTrue(item?.pobj);
  9664. const isChild = isTrue(item?.cobj);
  9665. if (isParent) {
  9666. currentGroup = {
  9667. ...item,
  9668. __level: 1,
  9669. children: [],
  9670. };
  9671. result.push(currentGroup);
  9672. continue;
  9673. }
  9674. if (isChild && currentGroup) {
  9675. currentGroup.children.push({ ...item, __level: 2 });
  9676. continue;
  9677. }
  9678. //功能: 变动等无 pobj/cobj 的选项按一级展示(不挂到 children,也不打断当前分组)by xu 20251223
  9679. result.push({ ...item, __level: 1 });
  9680. }
  9681. return result;
  9682. };
  9683. const menuListComputed = computed(() =>
  9684. normalizeMenuList(props.menuList)
  9685. ); //功能 by xu 20251222
  9686. //功能: 分组展开状态(默认展开),避免 computed 生成对象导致 open 状态丢失 by xu 20251222
  9687. const groupOpenState = reactive({}); // { [key]: boolean }
  9688. const getGroupKey = (item) => item?.name || item?.title || ""; //功能 by xu 20251222
  9689. const isGroupOpen = (item) => {
  9690. //功能 by xu 20251222
  9691. const key = getGroupKey(item);
  9692. if (!key) return true;
  9693. return groupOpenState[key] !== false;
  9694. };
  9695. const toggleGroupOpen = (item) => {
  9696. //功能 by xu 20251222
  9697. const key = getGroupKey(item);
  9698. if (!key) return;
  9699. groupOpenState[key] = !isGroupOpen(item);
  9700. };
  9701. const getLevelClass = (item, fallbackLevel) => {
  9702. //功能 by xu 20251222
  9703. //功能: “变动”始终按一级样式处理 by xu 20251223
  9704. if (item && (item.title === "变动" || item.name === "sys_bd")) {
  9705. return "level-1";
  9706. }
  9707. const level = item?.__level || fallbackLevel || 1;
  9708. return level === 2 ? "level-2" : "level-1";
  9709. };
  9710. // v3.0 新增:菜单模式管理 by xu 20251216
  9711. const menuMode = ref(props.initialMode);
  9712. const isHovering = ref(false);
  9713. const toggleMenuMode = () => {
  9714. menuMode.value = menuMode.value === "collapse" ? "fixed" : "collapse";
  9715. };
  9716. //功能: 提供给旧UI弹窗顶部按钮调用的 API(替代点击 .menu-mode-toggle DOM)by xu 20251224
  9717. const registerSsSubTabApi = () => {
  9718. //功能 by xu 20251224
  9719. try {
  9720. window.SS = window.SS || {};
  9721. window.SS.dom = window.SS.dom || {};
  9722. //功能: 兼容小写 ss 命名空间(部分页面只引用 window.ss)by xu 20251224
  9723. window.ss = window.ss || window.SS;
  9724. window.ss.dom = window.ss.dom || window.SS.dom;
  9725. const api = {
  9726. toggleMenuMode,
  9727. getMenuMode: () => menuMode.value,
  9728. };
  9729. window.SS.dom.ssSubTabApi = api;
  9730. window.ss.dom.ssSubTabApi = api;
  9731. //功能: 多层弹窗(如 objPlay -> objInfo) 场景,将 API 注册到 topWindow 供按钮跨层调用 by xu 20251224
  9732. try {
  9733. const wdDialogId =
  9734. window.wd &&
  9735. wd.display &&
  9736. wd.display.getwdDialogId &&
  9737. wd.display.getwdDialogId();
  9738. if (wdDialogId && window.top) {
  9739. window.top.__ssSubTabApiMap = window.top.__ssSubTabApiMap || {};
  9740. window.top.__ssSubTabApiMap[wdDialogId] = api;
  9741. }
  9742. } catch (e) {}
  9743. try {
  9744. console.log(
  9745. "[SsSubTabApi] registered",
  9746. window.location && window.location.pathname
  9747. );
  9748. } catch (e) {}
  9749. } catch (e) {}
  9750. };
  9751. const unregisterSsSubTabApi = () => {
  9752. //功能 by xu 20251224
  9753. try {
  9754. //功能: 从 topWindow 解绑(避免弹窗关闭后残留)by xu 20251224
  9755. try {
  9756. const wdDialogId =
  9757. window.wd &&
  9758. wd.display &&
  9759. wd.display.getwdDialogId &&
  9760. wd.display.getwdDialogId();
  9761. if (
  9762. wdDialogId &&
  9763. window.top &&
  9764. window.top.__ssSubTabApiMap &&
  9765. window.top.__ssSubTabApiMap[wdDialogId]
  9766. ) {
  9767. delete window.top.__ssSubTabApiMap[wdDialogId];
  9768. }
  9769. } catch (e) {}
  9770. if (window.SS?.dom?.ssSubTabApi?.toggleMenuMode === toggleMenuMode) {
  9771. delete window.SS.dom.ssSubTabApi;
  9772. }
  9773. if (window.ss?.dom?.ssSubTabApi?.toggleMenuMode === toggleMenuMode) {
  9774. delete window.ss.dom.ssSubTabApi;
  9775. }
  9776. } catch (e) {}
  9777. };
  9778. //功能: 立即注册,避免 enable 早于 onMounted 导致“api not ready”by xu 20251224
  9779. registerSsSubTabApi(); //功能 by xu 20251224
  9780. onBeforeUnmount(unregisterSsSubTabApi); //功能 by xu 20251224
  9781. const onMouseEnter = () => {
  9782. if (menuMode.value === "collapse") {
  9783. isHovering.value = true;
  9784. }
  9785. };
  9786. const onMouseLeave = () => {
  9787. isHovering.value = false;
  9788. };
  9789. const isExpanded = computed(() => {
  9790. return menuMode.value === "collapse" && isHovering.value;
  9791. });
  9792. // v3.0 新增:iframe 懒加载,点击才加载 by xu 20251216
  9793. const loadedMenus = ref(new Set());
  9794. const isMenuLoaded = (menuName) => {
  9795. return loadedMenus.value.has(menuName);
  9796. };
  9797. // 根据标题找到对应的菜单项
  9798. const findMenuByTitle = (title) => {
  9799. for (const item of menuListComputed.value) {
  9800. //功能 by xu 20251222
  9801. if (item.children?.length > 0) {
  9802. const child = item.children.find((c) => c.title === title);
  9803. if (child) return child;
  9804. } else if (item.title === title) {
  9805. return item;
  9806. }
  9807. }
  9808. return null;
  9809. };
  9810. // 计算默认选中的菜单项
  9811. const defaultActiveMenu = computed(() => {
  9812. if (props.activeMenu) {
  9813. const menu = findMenuByTitle(props.activeMenu);
  9814. if (menu) return menu;
  9815. }
  9816. const firstItem = menuListComputed.value[0]; //功能 by xu 20251222
  9817. if (!firstItem) return null;
  9818. //功能: 默认选中第一个一级菜单(不默认跳到第一个二级)by xu 20251224
  9819. return firstItem;
  9820. });
  9821. const currentMenu = ref(defaultActiveMenu.value);
  9822. // 监听外部activeMenu变化
  9823. watch(
  9824. () => props.activeMenu,
  9825. (newTitle) => {
  9826. if (newTitle) {
  9827. const menu = findMenuByTitle(newTitle);
  9828. if (menu) {
  9829. currentMenu.value = menu;
  9830. }
  9831. }
  9832. }
  9833. );
  9834. // 初始化:默认选中项加入已加载集合
  9835. watch(
  9836. currentMenu,
  9837. (menu) => {
  9838. if (menu?.name) {
  9839. loadedMenus.value.add(menu.name);
  9840. }
  9841. },
  9842. { immediate: true }
  9843. );
  9844. // 选择菜单项时触发 menu-change 钩子
  9845. const selectItem = (item) => {
  9846. currentMenu.value = item;
  9847. // 标记为已加载
  9848. if (item.name) {
  9849. loadedMenus.value.add(item.name);
  9850. }
  9851. emit("menu-change", item);
  9852. };
  9853. // 处理底部按钮点击
  9854. const handleFooterClick = (button, index) => {
  9855. emit("footer-click", { button, index });
  9856. };
  9857. return {
  9858. menuListComputed, //功能 by xu 20251222
  9859. currentMenu,
  9860. selectItem,
  9861. handleFooterClick,
  9862. getFooterIcon, //功能: SsSubTab 底部按钮支持 icon+文字(icon-base)by xu 20251224
  9863. menuMode,
  9864. isHovering,
  9865. isExpanded,
  9866. toggleMenuMode,
  9867. onMouseEnter,
  9868. onMouseLeave,
  9869. isMenuLoaded,
  9870. getMenuIcon,
  9871. isGroupOpen, //功能 by xu 20251222
  9872. toggleGroupOpen, //功能 by xu 20251222
  9873. getLevelClass, //功能 by xu 20251222
  9874. };
  9875. },
  9876. template: `
  9877. <div class="project-edit-container">
  9878. <div class="left-side"
  9879. v-if="leftDisplay"
  9880. :data-mode="menuMode"
  9881. :class="{ 'is-expanded': isExpanded }"
  9882. @mouseenter="onMouseEnter"
  9883. @mouseleave="onMouseLeave">
  9884. <!-- 菜单内容 -->
  9885. <div class="menu-content">
  9886. <div class="scroll-view">
  9887. <template v-for="(menuItem, i) in menuListComputed" :key="i">
  9888. <!-- 分组菜单 -->
  9889. <div v-if="menuItem.children?.length > 0" class="group">
  9890. <!-- 功能: 一级(pobj)可点击进入,箭头仅控制展开/收起;二级点击不影响一级选中状态 by xu 20251223 -->
  9891. <div class="menu-item"
  9892. :class="[getLevelClass(menuItem, 1), { active: menuItem.name === currentMenu?.name }]"
  9893. @click="selectItem(menuItem)">
  9894. <ss-icon :class="getMenuIcon(menuItem, i)" />
  9895. <span class="menu-label">{{ menuItem.title }}</span>
  9896. <!-- 功能: 一级菜单有子项时显示 dot(参考全局左侧菜单)by xu 20251224 -->
  9897. <div class="has-children-dot"></div>
  9898. <div class="menu-tooltip">{{ menuItem.title }}</div>
  9899. </div>
  9900. <!-- 功能: 二级菜单始终展示,不做收缩展开 by xu 20251223 -->
  9901. <div class="group-detail">
  9902. <div v-for="(item, j) in menuItem.children"
  9903. :key="j"
  9904. class="menu-item"
  9905. :class="[getLevelClass(item, 2), { active: item.name === currentMenu?.name }]"
  9906. @click.stop="selectItem(item)">
  9907. <ss-icon :class="getMenuIcon(item, j)" />
  9908. <span class="menu-label">{{ item.title }}</span>
  9909. </div>
  9910. </div>
  9911. </div>
  9912. <!-- 普通菜单项 -->
  9913. <div v-else
  9914. class="menu-item"
  9915. :class="[getLevelClass(menuItem, 1), { active: menuItem.name === currentMenu?.name }]"
  9916. @click="selectItem(menuItem)">
  9917. <ss-icon :class="getMenuIcon(menuItem, i)" />
  9918. <span class="menu-label">{{ menuItem.title }}</span>
  9919. <div class="menu-tooltip">{{ menuItem.title }}</div>
  9920. </div>
  9921. </template>
  9922. </div>
  9923. </div>
  9924. <!-- 底部按钮 -->
  9925. <div v-if="footerButtons.length > 0"
  9926. class="sub-tab-menu-footer"
  9927. :class="{ 'has-text': !!footerButtons[0].text }"
  9928. @click="footerButtons[0].onclick">
  9929. <ss-icon :class="getFooterIcon(footerButtons[0])" />
  9930. <div class="footer-label" v-if="footerButtons[0].text">{{ footerButtons[0].text }}</div>
  9931. <ss-icon v-if="footerButtons.length > 1" class="footer-arrow" name="arrow-up" size="24px" />
  9932. <div v-if="footerButtons.length > 1" class="sub-tab-menu-popup">
  9933. <div v-for="(button, index) in footerButtons.slice(1)"
  9934. :key="index"
  9935. @click.stop="button.onclick">
  9936. {{ button.text }}
  9937. </div>
  9938. </div>
  9939. </div>
  9940. </div>
  9941. <!-- 右侧内容区域 - 懒加载 iframe -->
  9942. <div class="content-area fit-height-content" style="overflow: hidden;" :style="!leftDisplay ? { width: '100%' } : {}">
  9943. <template v-for="(menuItem, i) in menuList" :key="i">
  9944. <iframe
  9945. v-if="isMenuLoaded(menuItem.name)"
  9946. :src="menuItem.url"
  9947. style="height: 100%;width: 100%;"
  9948. frameborder="0"
  9949. class="sub-tab-iframe"
  9950. :id="i === 0 ? 'sub-tab-iframe' : ''"
  9951. v-show="currentMenu?.name === menuItem.name"
  9952. />
  9953. </template>
  9954. </div>
  9955. </div>
  9956. `,
  9957. };
  9958. // <iframe
  9959. // v-if="currentMenu?.url"
  9960. // :src="currentMenu.url"
  9961. // style="height: 100%;width: 100%;"
  9962. // frameborder="0"
  9963. // id="sub-tab-iframe"
  9964. // />
  9965. // ss-photo-upload 通用图片上传组件
  9966. const SsImgUpload = {
  9967. name: "SsImgUpload",
  9968. props: {
  9969. name: {
  9970. type: String,
  9971. required: true,
  9972. },
  9973. // 图片URL,用于回显
  9974. // url: {
  9975. // type: String,
  9976. // default: "",
  9977. // },
  9978. // 样式类名
  9979. class: {
  9980. type: String,
  9981. required: true,
  9982. },
  9983. // 裁剪配置
  9984. cropperOpt: {
  9985. type: Object,
  9986. default: () => ({
  9987. width: 360,
  9988. height: 360,
  9989. aspectRatio: 1,
  9990. }),
  9991. },
  9992. //上传图片url(未加图片名参数之前的部分)
  9993. ulUrl: {
  9994. type: String,
  9995. required: true,
  9996. },
  9997. //下载图片url(未加图片名参数之前的部分)
  9998. dlUrl: {
  9999. type: String,
  10000. required: true,
  10001. },
  10002. modelValue: [String, Number],
  10003. },
  10004. emits: ["update:modelValue"],
  10005. setup(props, { emit }) {
  10006. const inputId = Vue.computed(
  10007. () => `file_${Vue.getCurrentInstance().uid}`
  10008. );
  10009. //修改图片初始显示路径
  10010. let pathVal = ref(props.modelValue);
  10011. let picUrl = ref("");
  10012. if (props.modelValue) {
  10013. picUrl.value = props.dlUrl + "&path=" + props.modelValue;
  10014. }
  10015. Vue.onMounted(() => {
  10016. window.SS.cropper.init({
  10017. el: $(`#${inputId.value}`),
  10018. photoSize: {
  10019. width: props.cropperOpt.width,
  10020. height: props.cropperOpt.height,
  10021. },
  10022. aspectRatio: props.cropperOpt.aspectRatio,
  10023. uploadUrl: props.ulUrl,
  10024. success: (path) => {
  10025. pathVal.value = path;
  10026. picUrl.value = props.dlUrl + "&path=" + path;
  10027. emit("update:modelValue", path);
  10028. },
  10029. });
  10030. });
  10031. return () =>
  10032. h("div", { class: [props.class] }, [
  10033. h("input", {
  10034. type: "file",
  10035. accept: "image/*",
  10036. id: inputId.value,
  10037. style: { display: "none" },
  10038. }),
  10039. h("input", {
  10040. type: "hidden",
  10041. name: props.name,
  10042. value: pathVal.value,
  10043. }),
  10044. h(
  10045. "div",
  10046. {
  10047. style: {
  10048. width: "100%",
  10049. height: "100%",
  10050. },
  10051. onClick: () => $(`#${inputId.value}`).click(),
  10052. },
  10053. [
  10054. picUrl.value &&
  10055. h("img", {
  10056. src: picUrl.value,
  10057. style:
  10058. "width: 100%; height: 100%;object-fit: inherit;position: relative;z-index: 11;",
  10059. }),
  10060. ]
  10061. ),
  10062. ]);
  10063. },
  10064. };
  10065. // 初始化函数,负责创建和挂载 Vue 应用
  10066. // window.SS = { dom: {} };
  10067. /**
  10068. * 获取当前窗口的父窗口
  10069. * @returns {Window} 父窗口对象
  10070. */
  10071. window.SS.topWin = (function (p, c) {
  10072. while (p != c) {
  10073. c = p;
  10074. p = p.parent;
  10075. }
  10076. return c;
  10077. })(window.parent, window);
  10078. window.SS.createSsDialogInstance = createSsDialogInstance;
  10079. /**
  10080. * 创建弹窗
  10081. * @param {Object} setting
  10082. * @param {Function} callbackEvent
  10083. */
  10084. window.SS.openDialog = function (setting, callbackEvent) {
  10085. if (setting.params) {
  10086. const encodedParams = encodeURIComponent(JSON.stringify(setting.params));
  10087. setting.src +=
  10088. (setting.src.includes("?") ? "&" : "?") + "params=" + encodedParams;
  10089. }
  10090. if (window.parent && window.parent !== window) {
  10091. window.parent.SS.createSsDialogInstance(setting, callbackEvent);
  10092. } else {
  10093. createSsDialogInstance(setting, callbackEvent);
  10094. }
  10095. };
  10096. //关闭弹窗
  10097. window.SS.closeDialog = function () {
  10098. console.log("关闭弹窗");
  10099. if (topWindow.dialogInstances.length > 0) {
  10100. const instance = topWindow.dialogInstances.pop();
  10101. console.log("instance", instance);
  10102. console.log("instance.callbackEvent", instance.callbackEvent);
  10103. console.log(
  10104. "instance.callbackEvent.end",
  10105. typeof instance.callbackEvent === "function"
  10106. );
  10107. if (instance.callbackEvent) {
  10108. // 判断是否有end回调并执行
  10109. if (typeof instance.callbackEvent === "function") {
  10110. instance.callbackEvent();
  10111. }
  10112. if (typeof instance.callbackEvent.end === "function") {
  10113. instance.callbackEvent.end();
  10114. }
  10115. }
  10116. instance.app.unmount(); // 卸载最后一个实例
  10117. if (instance.container && instance.container.parentNode) {
  10118. instance.container.parentNode.removeChild(instance.container); // 移除容器
  10119. }
  10120. }
  10121. };
  10122. /**
  10123. * 裁剪插件
  10124. */
  10125. window.SS.cropper = {
  10126. init: function (setting) {
  10127. if (!window.top.SS) window.top.SS = {};
  10128. // 重要:确保 cropper 对象的完整初始化
  10129. if (!window.top.SS.cropper) {
  10130. window.top.SS.cropper = {
  10131. settings: new Map(),
  10132. _backupSettings: {},
  10133. getSetting: this.getSetting,
  10134. clearSetting: this.clearSetting,
  10135. debug: this.debug,
  10136. };
  10137. } else if (!window.top.SS.cropper.settings) {
  10138. // 如果 cropper 存在但 settings 不存在,重新初始化 settings
  10139. window.top.SS.cropper.settings = new Map();
  10140. window.top.SS.cropper._backupSettings = {};
  10141. }
  10142. const uploaderId = `uploader_${Date.now()}_${Math.random()
  10143. .toString(36)
  10144. .substr(2, 9)}`;
  10145. window.top.SS.cropper.settings.set(uploaderId, setting);
  10146. window.top.SS.cropper._backupSettings[uploaderId] = setting;
  10147. setting.box = setting.box || "1";
  10148. var winSetting = {
  10149. headerTitle: "图片裁剪",
  10150. src: "/js/cropper/cropper.jsp", //原来在"/newUI/page/cropper.jsp" Ben(20251205)
  10151. width: "900",
  10152. height: "500",
  10153. };
  10154. $(setting.el).change(function () {
  10155. if (!window.SS.cropper.verify(setting)) {
  10156. $(setting.el).val(""); // 清空文件选择
  10157. return false;
  10158. }
  10159. var files = this.files;
  10160. if (files && files.length) {
  10161. if (!window.SS.cropper.verifySize($(setting.el)[0], 5)) {
  10162. $(setting.el).val(""); // 清空文件选择
  10163. alert("文件大小不能超过5M,请重新选择");
  10164. return false;
  10165. }
  10166. var URL = window.URL || window.webkitURL;
  10167. var file = files[0];
  10168. setting.file = file;
  10169. if (
  10170. /^image\/\w+$/.test(file.type) &&
  10171. /\.(jpg|jpeg|png|)$/i.test(file.name)
  10172. ) {
  10173. var uploadedImageURL = URL.createObjectURL(file);
  10174. setting.data = uploadedImageURL;
  10175. setting.fileName = file.name;
  10176. // console.log()
  10177. winSetting.params = {
  10178. ...setting,
  10179. uploaderId,
  10180. };
  10181. console.log("ss-componets中change之后的winSetting", winSetting);
  10182. SS.openDialog(winSetting, {
  10183. success: function (win) {
  10184. console.log("裁剪插件成功");
  10185. // win.cropperSetting = setting;
  10186. },
  10187. end: function () {
  10188. console.log("裁剪插件结束");
  10189. $(setting.el).val(""); // 清空文件选择
  10190. },
  10191. });
  10192. } else {
  10193. alert("请选择图片文件,支持jpg、jpeg、png格式");
  10194. }
  10195. }
  10196. });
  10197. return uploaderId;
  10198. },
  10199. verify: function (setting) {
  10200. if (!setting) {
  10201. console.error(" cropper setting is not undefined! ");
  10202. return false;
  10203. }
  10204. if (!setting.el) {
  10205. console.error(" cropper setting.el is not undefined! ");
  10206. return false;
  10207. }
  10208. if (setting.photoSize) {
  10209. if (
  10210. (!setting.photoSize.width && setting.photoSize.height) ||
  10211. (!setting.photoSize.height && setting.photoSize.width)
  10212. ) {
  10213. console.error(
  10214. " cropper setting.photoSize { width, height } is not undefined! "
  10215. );
  10216. return false;
  10217. }
  10218. }
  10219. if (!setting.box) {
  10220. setting.box = "1";
  10221. }
  10222. if (!setting.aspectRatio) {
  10223. setting.aspectRatio = 1 / 1;
  10224. }
  10225. return true;
  10226. },
  10227. verifySize: function (fileEl, maxSize) {
  10228. // 判断是否为IE浏览器: /msie/i.test(navigator.userAgent) 为一个简单正则
  10229. var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  10230. var fileSize = 0;
  10231. if (isIE && !fileEl.files) {
  10232. // IE浏览器
  10233. var filePath = fileEl.value; // 获得上传文件的绝对路径
  10234. var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
  10235. var file = fileSystem.GetFile(filePath);
  10236. fileSize = file.Size; // 文件大小,单位:b
  10237. } else {
  10238. // 非IE浏览器
  10239. fileSize = fileEl.files[0].size;
  10240. }
  10241. var size = fileSize / 1024 / 1024;
  10242. return !(size > maxSize);
  10243. },
  10244. // 获取特定上传组件的setting
  10245. getSetting: function (uploaderId) {
  10246. if (!window.top.SS?.cropper) {
  10247. console.warn("顶层窗口中未找到 SS.cropper");
  10248. return null;
  10249. }
  10250. // 优先从 Map 中获取
  10251. let setting = window.top.SS.cropper.settings.get(uploaderId);
  10252. // 如果 Map 中没有,尝试从备份中获取
  10253. if (!setting && window.top.SS.cropper._backupSettings[uploaderId]) {
  10254. console.log("从备份中恢复 setting");
  10255. setting = window.top.SS.cropper._backupSettings[uploaderId];
  10256. // 恢复到 Map 中
  10257. window.top.SS.cropper.settings.set(uploaderId, setting);
  10258. }
  10259. return setting;
  10260. },
  10261. // 清理特定上传组件的setting
  10262. clearSetting: function (uploaderId) {
  10263. if (!window.top.SS?.cropper) return;
  10264. window.top.SS.cropper.settings.delete(uploaderId);
  10265. delete window.top.SS.cropper._backupSettings[uploaderId];
  10266. console.log(
  10267. "清理设置后的 Map size:",
  10268. window.top.SS.cropper.settings.size
  10269. );
  10270. },
  10271. };
  10272. /**
  10273. * 获取url中的参数
  10274. * @returns {Object}
  10275. */
  10276. window.SS.getQueryParams = function () {
  10277. const params = {};
  10278. const queryString = window.location.search.substring(1);
  10279. const pairs = queryString.split("&");
  10280. for (let i = 0; i < pairs.length; i++) {
  10281. const pair = pairs[i].split("=");
  10282. params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  10283. }
  10284. if (params.params) {
  10285. try {
  10286. params.params = JSON.parse(params.params);
  10287. } catch (e) {
  10288. console.error("Failed to parse params:", e);
  10289. }
  10290. }
  10291. return params;
  10292. };
  10293. /**
  10294. * 创建vue应用
  10295. * @param {Object} config 配置项
  10296. * @values {String} config.el 挂载的元素
  10297. * @values {Boolean} config.isDialogPage 是否是弹窗页面 决定了是否可以使用顶天立地
  10298. * @values {Object} config.vueOptions vue配置项
  10299. * @returns {Object} vue实例
  10300. */
  10301. window.ss = window.ss || window.SS;
  10302. window.ss.dom = window.ss.dom || window.SS.dom;
  10303. window.SS.dom._vueAppSeq =
  10304. window.SS.dom._vueAppSeq || window.ss.dom._vueAppSeq || 0;
  10305. window.SS.dom.vueApps = window.SS.dom.vueApps || window.ss.dom.vueApps || [];
  10306. window.ss.dom._vueAppSeq = window.SS.dom._vueAppSeq;
  10307. window.ss.dom.vueApps = window.SS.dom.vueApps;
  10308. window.SS.dom._registerVueApp = function ({ vm, el, appKey, scope, href }) {
  10309. if (!vm) return null;
  10310. const registry = window.SS.dom.vueApps || (window.SS.dom.vueApps = []);
  10311. const id = `vue-app-${++window.SS.dom._vueAppSeq}`;
  10312. const record = {
  10313. id,
  10314. el: el || "",
  10315. appKey: appKey || "",
  10316. scope: scope || "current",
  10317. href: href || window.location.href,
  10318. createdAt: Date.now(),
  10319. vm,
  10320. win: window,
  10321. };
  10322. registry.push(record);
  10323. window.SS.dom.currentApp = vm;
  10324. window.SS.dom.currentAppRecord = record;
  10325. if (window.ss && window.ss.dom) {
  10326. window.ss.dom.vueApps = registry;
  10327. window.ss.dom._vueAppSeq = window.SS.dom._vueAppSeq;
  10328. window.ss.dom.currentApp = vm;
  10329. window.ss.dom.currentAppRecord = record;
  10330. }
  10331. return record;
  10332. };
  10333. window.SS.dom._getVmData = function (vm) {
  10334. if (!vm) return null;
  10335. return vm.$data || vm;
  10336. };
  10337. window.SS.dom._hasVmKey = function (vm, key) {
  10338. if (!vm || !key) return false;
  10339. const data = window.SS.dom._getVmData(vm);
  10340. return key in vm || (!!data && key in data);
  10341. };
  10342. window.SS.dom._hasVmMethod = function (vm, methodName) {
  10343. return !!(vm && methodName && typeof vm[methodName] === "function");
  10344. };
  10345. window.SS.dom._normalizeBridgeOptions = function (
  10346. options = {},
  10347. defaults = {}
  10348. ) {
  10349. return {
  10350. scope: "chain",
  10351. ...defaults,
  10352. ...options,
  10353. };
  10354. };
  10355. window.SS.dom._matchVueRecord = function (record, options = {}) {
  10356. if (!record || !record.vm) return false;
  10357. if (options.appKey && record.appKey !== options.appKey) return false;
  10358. if (options.el && record.el !== options.el) return false;
  10359. if (options.id && record.id !== options.id) return false;
  10360. if (
  10361. options.dataKey &&
  10362. !window.SS.dom._hasVmKey(record.vm, options.dataKey)
  10363. ) {
  10364. return false;
  10365. }
  10366. if (
  10367. options.methodName &&
  10368. !window.SS.dom._hasVmMethod(record.vm, options.methodName)
  10369. ) {
  10370. return false;
  10371. }
  10372. if (typeof options.predicate === "function") {
  10373. try {
  10374. if (!options.predicate(record.vm, record)) {
  10375. return false;
  10376. }
  10377. } catch (e) {
  10378. return false;
  10379. }
  10380. }
  10381. return true;
  10382. };
  10383. window.SS.dom._getWindowVueRecord = function (targetWindow, options = {}) {
  10384. if (!targetWindow || !targetWindow.SS || !targetWindow.SS.dom) return null;
  10385. const registry = targetWindow.SS.dom.vueApps || [];
  10386. for (let i = registry.length - 1; i >= 0; i--) {
  10387. if (targetWindow.SS.dom._matchVueRecord(registry[i], options)) {
  10388. return registry[i];
  10389. }
  10390. }
  10391. const currentRecord = targetWindow.SS.dom.currentAppRecord;
  10392. if (targetWindow.SS.dom._matchVueRecord(currentRecord, options)) {
  10393. return currentRecord;
  10394. }
  10395. const currentVm = targetWindow.SS.dom.currentApp;
  10396. const fallbackRecord = currentVm
  10397. ? {
  10398. vm: currentVm,
  10399. win: targetWindow,
  10400. el: "",
  10401. appKey: "",
  10402. id: "",
  10403. }
  10404. : null;
  10405. if (targetWindow.SS.dom._matchVueRecord(fallbackRecord, options)) {
  10406. return fallbackRecord;
  10407. }
  10408. return null;
  10409. };
  10410. window.SS.dom.getVueAppRecord = function (options = {}) {
  10411. const scope = options.scope || "current";
  10412. if (scope === "current") {
  10413. return window.SS.dom._getWindowVueRecord(window, options);
  10414. }
  10415. if (scope === "top") {
  10416. try {
  10417. return window.SS.dom._getWindowVueRecord(window.top, options);
  10418. } catch (e) {
  10419. return null;
  10420. }
  10421. }
  10422. if (scope === "parent") {
  10423. try {
  10424. if (window.parent && window.parent !== window) {
  10425. return window.SS.dom._getWindowVueRecord(window.parent, options);
  10426. }
  10427. } catch (e) {
  10428. return null;
  10429. }
  10430. return null;
  10431. }
  10432. if (scope === "chain") {
  10433. let currentWindow = window;
  10434. while (currentWindow) {
  10435. try {
  10436. const record = window.SS.dom._getWindowVueRecord(
  10437. currentWindow,
  10438. options
  10439. );
  10440. if (record) {
  10441. return record;
  10442. }
  10443. } catch (e) {
  10444. return null;
  10445. }
  10446. if (currentWindow === currentWindow.parent) {
  10447. break;
  10448. }
  10449. currentWindow = currentWindow.parent;
  10450. }
  10451. return null;
  10452. }
  10453. return window.SS.dom._getWindowVueRecord(window, options);
  10454. };
  10455. window.SS.dom.getVueApp = function (options = {}) {
  10456. const record = window.SS.dom.getVueAppRecord(options);
  10457. return record ? record.vm : null;
  10458. };
  10459. window.SS.dom.getVmValue = function (key, options = {}) {
  10460. const vm = window.SS.dom.getVueApp(
  10461. window.SS.dom._normalizeBridgeOptions(options, { dataKey: key })
  10462. );
  10463. if (!vm) return undefined;
  10464. return vm[key];
  10465. };
  10466. window.SS.dom.setVmValue = function (key, value, options = {}) {
  10467. const vm = window.SS.dom.getVueApp(
  10468. window.SS.dom._normalizeBridgeOptions(options, { dataKey: key })
  10469. );
  10470. if (!vm) return false;
  10471. vm[key] = value;
  10472. return true;
  10473. };
  10474. window.SS.dom.callVmMethod = function (methodName, args = [], options = {}) {
  10475. const vm = window.SS.dom.getVueApp(
  10476. window.SS.dom._normalizeBridgeOptions(options, { methodName })
  10477. );
  10478. if (!vm || typeof vm[methodName] !== "function") {
  10479. return undefined;
  10480. }
  10481. return vm[methodName].apply(vm, args);
  10482. };
  10483. window.SS.dom.get = function (key, options = {}) {
  10484. return window.SS.dom.getVmValue(key, options);
  10485. };
  10486. window.SS.dom.set = function (key, value, options = {}) {
  10487. return window.SS.dom.setVmValue(key, value, options);
  10488. };
  10489. window.SS.dom.call = function (methodName, args = [], options = {}) {
  10490. return window.SS.dom.callVmMethod(methodName, args, options);
  10491. };
  10492. [
  10493. "_registerVueApp",
  10494. "_getVmData",
  10495. "_hasVmKey",
  10496. "_hasVmMethod",
  10497. "_normalizeBridgeOptions",
  10498. "_matchVueRecord",
  10499. "_getWindowVueRecord",
  10500. "getVueAppRecord",
  10501. "getVueApp",
  10502. "getVmValue",
  10503. "setVmValue",
  10504. "callVmMethod",
  10505. "get",
  10506. "set",
  10507. "call",
  10508. ].forEach((name) => {
  10509. window.ss.dom[name] = window.SS.dom[name];
  10510. });
  10511. window.SS.dom.initializeFormApp = function (config) {
  10512. const {
  10513. el,
  10514. isDialogPage = false,
  10515. appKey = "",
  10516. scope = "current",
  10517. ...vueOptions
  10518. } = config;
  10519. const app = createApp({
  10520. ...vueOptions,
  10521. });
  10522. if (isDialogPage) {
  10523. function checkScroll() {
  10524. const elements = document.querySelectorAll(".fit-height-content");
  10525. let hasScrollBar = false;
  10526. elements.forEach((el) => {
  10527. if (el.scrollHeight > el.clientHeight) {
  10528. hasScrollBar = true;
  10529. }
  10530. });
  10531. window.parent.postMessage({ hasScrollBar }, "*");
  10532. }
  10533. function addScrollListeners() {
  10534. const elements = document.querySelectorAll("div");
  10535. elements.forEach((el) => {
  10536. el.addEventListener("scroll", checkScroll);
  10537. });
  10538. }
  10539. const observer = new MutationObserver(() => {
  10540. addScrollListeners();
  10541. checkScroll();
  10542. });
  10543. observer.observe(document.body, {
  10544. childList: true,
  10545. subtree: true,
  10546. });
  10547. window.addEventListener("resize", checkScroll);
  10548. }
  10549. app.component("SsLoginIcon", SsLoginIcon);
  10550. app.component("SsMark", SsMark);
  10551. app.component("SsFullStyleHeader", SsFullStyleHeader);
  10552. app.component("SsDialog", SsDialog);
  10553. app.component("SsInp", SsInput);
  10554. app.component("SsObjp", SsObjp);
  10555. app.component("SsHidden", SsHidden);
  10556. app.component("SsCcp", SsCcp);
  10557. app.component("SsDatePicker", SsDatePicker);
  10558. app.component("SsIcon", SsIcon);
  10559. app.component("SsCommonIcon", SsCommonIcon);
  10560. app.component("SsBreadcrumb", SsBreadcrumb);
  10561. app.component("SsEditor", SsEditor);
  10562. app.component("SsDialogIcon", SsDialogIcon);
  10563. app.component("SsBottomButton", SsBottomButton);
  10564. app.component("SsNavIcon", SsNavIcon);
  10565. app.component("SsHeaderIcon", SsHeaderIcon);
  10566. app.component("SsGolbalMenuIcon", SsGolbalMenuIcon);
  10567. app.component("SsCartListIcon", SsCartListIcon);
  10568. app.component("SsQuickIcon", SsQuickIcon);
  10569. app.component("SsFormIcon", SsFormIcon);
  10570. app.component("SsBottomDivIcon", SsBottomDivIcon);
  10571. app.component("SsEditorIcon", SsEditorIcon);
  10572. app.component("SsValidate", SsValidate);
  10573. app.component("SsOnoff", Ssonoff);
  10574. app.component("SsonoffArray", SsonoffArray);
  10575. app.component("SsTextarea", SsTextarea);
  10576. app.component("SsLoginInput", SsLoginInput);
  10577. app.component("SsLoginButton", SsLoginButton);
  10578. app.component("SsSearch", SsSearch);
  10579. app.component("SsCartItem", SsCartItem);
  10580. app.component("SsCartItem2", SsCartItem2);
  10581. app.component("SsListCard", SsListCard);
  10582. app.component("ss-cobj-card-list", SsCObjCardList);
  10583. app.component("SsFolderCard", SsFolderCard);
  10584. app.component("ss-sidebar", SsSidebar);
  10585. app.component("ss-sidebar-buttons", SsSidebarButtons);
  10586. app.component("ss-sidebar-chart", SsSidebarChart);
  10587. app.component("ss-sidebar-chart-hover", SsSidebarChartHover);
  10588. app.component("ss-sidebar-list", SsSidebarList);
  10589. app.component("ss-sidebar-report-table", SsSidebarReportTable);
  10590. app.component("SsFolderCartView", SsFolderCartView);
  10591. app.component("SsPage", SsPage);
  10592. app.component("SsRightInfo", SSRightInfo);
  10593. app.component("SsSuccessPopup", SsSuccessPopup);
  10594. app.component("SsErrorDialog", SsErrorDialog);
  10595. app.component("SsVerify", SsVerify);
  10596. app.component("SsVerifyNode", SsVerifyNode);
  10597. app.component("SsOrcImgBox", SsOrcImgBox);
  10598. app.component("ss-search-input", SsSearchInput);
  10599. app.component("ss-search-date-picker", SsSearchDatePicker);
  10600. app.component("ss-search-button", SsSearchButton);
  10601. app.component("ss-drop-button", SsDropButton);
  10602. app.component("ss-sub-tab", SsSubTab);
  10603. app.component("ss-img", SsImgUpload);
  10604. app.use(ElementPlus, {
  10605. locale: ElementPlusLocaleZhCn,
  10606. });
  10607. for (const componentName in IndexComponents) {
  10608. app.component(componentName, IndexComponents[componentName]);
  10609. }
  10610. for (const componentName in EchartComponents) {
  10611. app.component(componentName, EchartComponents[componentName]);
  10612. }
  10613. let vm;
  10614. try {
  10615. vm = app.mount(el);
  10616. vm.data = vueOptions.data();
  10617. window.SS.dom._registerVueApp({
  10618. vm,
  10619. el,
  10620. appKey,
  10621. scope,
  10622. href: window.location.href,
  10623. });
  10624. console.log("vm:", vm);
  10625. console.log("vueOptions:", vueOptions);
  10626. } catch (error) {
  10627. console.log("Mount failed:" + error);
  10628. }
  10629. return vm;
  10630. };
  10631. })();