mp-ss-components.js 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481
  1. // H5版本的小程序组件库
  2. // 参考 alf/ss-components.js 的组件形式
  3. (function () {
  4. const {
  5. ref,
  6. createApp,
  7. watch,
  8. inject,
  9. onMounted,
  10. onBeforeUnmount,
  11. computed,
  12. nextTick,
  13. } = Vue;
  14. async function ensureOptionalAssets(name) {
  15. if (window.SS && typeof window.SS.ensureOptionalAssets === "function") {
  16. return window.SS.ensureOptionalAssets(name);
  17. }
  18. throw new Error(`可选资源加载器未就绪: ${name}`);
  19. }
  20. // ===== 公共上传函数 =====
  21. /**
  22. * 统一文件上传函数
  23. * @param {File|Blob} file - 文件或Blob对象
  24. * @param {String} type - 'image' | 'file'
  25. * @param {String} fileName - 文件名(可选)
  26. * @returns {Promise<String>} 服务器路径
  27. */
  28. async function uploadFile(file, type = "image", fileName) {
  29. try {
  30. window.showToast?.("上传中...", "loading");
  31. const formData = new FormData();
  32. const name = fileName || (file instanceof Blob ? "file" : file.name);
  33. formData.append("fileEdit", file, name);
  34. formData.append("application", "");
  35. // 根据类型选择接口参数
  36. const apiType = type === "image" ? "img" : "file";
  37. const result = await window.request.post(
  38. `/service?ssServ=ulByHttp&type=${apiType}`,
  39. formData,
  40. { loading: false }
  41. );
  42. if (result?.data?.fileList?.[0]?.path) {
  43. const serverPath = result.data.fileList[0].path;
  44. window.showToast?.("上传成功", "success");
  45. return serverPath;
  46. } else {
  47. throw new Error("上传返回数据格式错误");
  48. }
  49. } catch (error) {
  50. console.error("上传失败:", error);
  51. window.showToast?.("上传失败,请重试", "error");
  52. throw error;
  53. }
  54. }
  55. const SsCommonIcon = {
  56. name: "SsCommonIcon",
  57. props: {
  58. class: {
  59. type: String,
  60. required: true,
  61. },
  62. },
  63. setup(props) {
  64. const { h } = Vue;
  65. return () =>
  66. h("i", {
  67. class: props.class + " common-icon",
  68. });
  69. },
  70. };
  71. // ss-input 智能输入组件
  72. const SsInput = {
  73. name: "SsInput",
  74. inheritAttrs: false, // 不直接继承属性到组件根元素
  75. props: {
  76. // v-model 绑定的值
  77. modelValue: {
  78. type: [String, Number],
  79. default: "",
  80. },
  81. // 字段名称
  82. name: {
  83. type: String,
  84. default: "",
  85. },
  86. // 占位符
  87. placeholder: {
  88. type: String,
  89. default: "请输入",
  90. },
  91. // 错误提示
  92. errTip: {
  93. type: String,
  94. default: "",
  95. },
  96. },
  97. emits: ["update:modelValue", "input", "blur", "change", "focus"],
  98. setup(props, { emit }) {
  99. const inputValue = ref(props.modelValue || "");
  100. const validationState = ref({
  101. hasError: false,
  102. errorMessage: "",
  103. isRequired: false,
  104. isEmpty: true,
  105. hasInteracted: false, // 是否已经交互过
  106. isSubmitMode: false, // 是否处于提交模式
  107. });
  108. // 从ValidatedTd注入事件处理函数(兼容小程序方式)
  109. const onInputInject = inject("onInput", null);
  110. const onBlurInject = inject("onBlur", null);
  111. // 检查是否为必填字段
  112. const checkRequired = () => {
  113. if (window.ssVm && props.name) {
  114. validationState.value.isRequired = window.ssVm.isRequired(props.name);
  115. }
  116. };
  117. // 更新父级td的class
  118. const updateTdClass = () => {
  119. // 找到父级td元素
  120. const inputElement = document.querySelector(
  121. `input[name="${props.name}"]`
  122. );
  123. if (inputElement) {
  124. const tdElement = inputElement.closest("td");
  125. if (tdElement) {
  126. // 移除所有校验相关的class
  127. tdElement.classList.remove("td-required", "td-error");
  128. // 逻辑分离:
  129. // 1. 初始状态:必填且为空 → 只有左侧红线 (td-required)
  130. // 2. 实时校验失败 → 左侧红线 + 底部红线 + 错误文字 (td-error)
  131. if (
  132. validationState.value.hasError &&
  133. validationState.value.hasInteracted
  134. ) {
  135. // 用户交互后校验失败:左侧红线 + 底部红线 + 错误文字
  136. tdElement.classList.add("td-error");
  137. } else if (
  138. validationState.value.isRequired &&
  139. validationState.value.isEmpty
  140. ) {
  141. // 必填且为空:只有左侧红线
  142. tdElement.classList.add("td-required");
  143. }
  144. }
  145. }
  146. };
  147. // 校验字段
  148. const validateField = (value) => {
  149. if (window.ssVm && props.name) {
  150. const result = window.ssVm.validateField(props.name);
  151. validationState.value.hasError = !result.valid;
  152. validationState.value.errorMessage = result.message || "";
  153. validationState.value.isEmpty = !value || value.trim() === "";
  154. // 更新td的class
  155. setTimeout(updateTdClass, 0);
  156. return result;
  157. }
  158. return { valid: true, message: "" };
  159. };
  160. // 监听props变化
  161. watch(
  162. () => props.modelValue,
  163. (newVal) => {
  164. inputValue.value = newVal;
  165. validateField(newVal);
  166. }
  167. );
  168. // 挂载时初始化
  169. onMounted(() => {
  170. checkRequired();
  171. validateField(inputValue.value);
  172. // 监听ssVm规则更新事件
  173. const inputElement = document.querySelector(
  174. `input[name="${props.name}"]`
  175. );
  176. if (inputElement) {
  177. inputElement.addEventListener("ssvm-rules-updated", () => {
  178. console.log(`收到规则更新通知: ${props.name}`);
  179. checkRequired();
  180. validateField(inputValue.value);
  181. updateTdClass();
  182. });
  183. }
  184. // 确保初始状态正确显示,延迟更长时间确保DOM完全渲染
  185. setTimeout(() => {
  186. updateTdClass();
  187. }, 200);
  188. });
  189. // 事件处理函数
  190. const handleInput = (event) => {
  191. const value = event.target.value;
  192. inputValue.value = value;
  193. // 标记已交互
  194. validationState.value.hasInteracted = true;
  195. // 1. 支持v-model
  196. emit("update:modelValue", value);
  197. emit("input", event);
  198. // 2. 内部校验(实时校验)
  199. validateField(value);
  200. // 3. 兼容小程序inject方式
  201. if (onInputInject) {
  202. onInputInject(event);
  203. }
  204. };
  205. const handleBlur = (event) => {
  206. // 标记已交互
  207. validationState.value.hasInteracted = true;
  208. emit("blur", event);
  209. // 失焦时再次校验
  210. validateField(inputValue.value);
  211. // 兼容小程序inject方式
  212. if (onBlurInject) {
  213. onBlurInject(event);
  214. }
  215. };
  216. const handleFocus = (event) => {
  217. emit("focus", event);
  218. };
  219. return {
  220. inputValue,
  221. validationState,
  222. handleInput,
  223. handleBlur,
  224. handleFocus,
  225. };
  226. },
  227. template: `
  228. <!-- 移动端简化的错误提示 - 显示在输入框右下角 -->
  229. <div v-if="validationState.hasError && validationState.hasInteracted" class="ss-input__error">
  230. {{ validationState.errorMessage }}
  231. </div>
  232. <div class="ss-input">
  233. <input
  234. class="ss-input__field"
  235. :name="name"
  236. type="text"
  237. :value="inputValue"
  238. :placeholder="placeholder"
  239. @input="handleInput"
  240. @blur="handleBlur"
  241. @focus="handleFocus"
  242. autocomplete="off"
  243. v-bind="$attrs"
  244. />
  245. </div>
  246. `,
  247. };
  248. // icon 图标组件 - 从小程序转换
  249. const Icon = {
  250. name: "Icon",
  251. props: {
  252. // 图标名称,对应iconfont中的类名,如'icon-home'
  253. name: {
  254. type: String,
  255. required: true,
  256. },
  257. // 图标颜色
  258. color: {
  259. type: String,
  260. default: "#000",
  261. },
  262. // 图标大小,单位rpx (H5中转换为px)
  263. size: {
  264. type: [Number, String],
  265. default: 32,
  266. },
  267. },
  268. emits: ["click"],
  269. setup(props, { emit }) {
  270. // 计算完整的图标类名
  271. const iconClass = computed(() => {
  272. return props.name;
  273. });
  274. // 计算样式
  275. const iconStyle = computed(() => ({
  276. color: props.color,
  277. fontSize: parseInt(props.size) / 2 + "px", // rpx转px,除以2
  278. verticalAlign: "middle",
  279. }));
  280. // 点击事件处理
  281. const handleClick = (event) => {
  282. emit("click", event);
  283. };
  284. return {
  285. iconClass,
  286. iconStyle,
  287. handleClick,
  288. };
  289. },
  290. template: `
  291. <span
  292. :class="['iconfont', iconClass]"
  293. :style="iconStyle"
  294. @click="handleClick"
  295. ></span>
  296. `,
  297. };
  298. // ss-card 卡片组件 - 从小程序转换
  299. const SsCard = {
  300. name: "SsCard",
  301. props: {
  302. item: {
  303. type: Object,
  304. default: () => ({}),
  305. },
  306. },
  307. emits: ["click", "buttonClick"],
  308. setup(props, { emit }) {
  309. // 状态
  310. const showButtonMenu = ref(false);
  311. const swipeOffset = ref(0);
  312. const touchStartX = ref(0);
  313. const touchStartY = ref(0);
  314. const swipeOpening = ref(false);
  315. const isSwiping = ref(false);
  316. const swipeActions = computed(() => {
  317. return Array.isArray(props.item?.swipeActions)
  318. ? props.item.swipeActions.filter(Boolean)
  319. : [];
  320. });
  321. const hasSwipeActions = computed(() => swipeActions.value.length > 0);
  322. const swipeActionPalette = [
  323. { backgroundColor: "#357cdf", color: "#fff" },
  324. { backgroundColor: "#94bfff", color: "#000000" },
  325. { backgroundColor: "#e0edff", color: "#000000" },
  326. ];
  327. const actionPaneWidth = computed(() => {
  328. if (!hasSwipeActions.value) return 0;
  329. return 66 * swipeActions.value.length;
  330. });
  331. // 计算属性
  332. const hasButtons = computed(() => {
  333. return (
  334. props.item?.buttons &&
  335. Array.isArray(props.item.buttons) &&
  336. props.item.buttons.length > 0
  337. );
  338. });
  339. const isMultipleButtons = computed(() => {
  340. return props.item?.buttons && props.item.buttons.length > 1;
  341. });
  342. const isSingleButton = computed(() => {
  343. return props.item?.buttons && props.item.buttons.length === 1;
  344. });
  345. const cardContentStyle = computed(() => ({
  346. transform: `translateX(-${swipeOffset.value}px)`,
  347. }));
  348. const actionPaneStyle = computed(() => ({
  349. width: `${actionPaneWidth.value}px`,
  350. }));
  351. const swipeIndicatorStyle = computed(() => {
  352. const palette = getSwipeActionStyle(0) || {};
  353. return {
  354. backgroundColor: palette.backgroundColor || "#357cdf",
  355. opacity: swipeOffset.value > 0 ? 0 : 1,
  356. };
  357. });
  358. const getSwipeActionStyle = (index) => {
  359. const paletteIndex = Math.min(
  360. Number(index || 0),
  361. swipeActionPalette.length - 1
  362. );
  363. return swipeActionPalette[paletteIndex] || swipeActionPalette[0];
  364. };
  365. const closeSwipe = () => {
  366. swipeOffset.value = 0;
  367. swipeOpening.value = false;
  368. };
  369. const openSwipe = () => {
  370. if (!hasSwipeActions.value) return;
  371. swipeOffset.value = actionPaneWidth.value;
  372. swipeOpening.value = true;
  373. };
  374. // 处理卡片点击
  375. const handleCardClick = () => {
  376. if (isSwiping.value) {
  377. isSwiping.value = false;
  378. return;
  379. }
  380. if (swipeOpening.value) {
  381. closeSwipe();
  382. return;
  383. }
  384. // 如果菜单打开,先关闭菜单
  385. if (showButtonMenu.value) {
  386. showButtonMenu.value = false;
  387. return;
  388. }
  389. emit("click");
  390. };
  391. // 处理设置按钮点击
  392. const handleSettingClick = () => {
  393. if (isSingleButton.value) {
  394. // 只有一个按钮,直接执行
  395. handleButtonClick(props.item.buttons[0], 0);
  396. } else if (isMultipleButtons.value) {
  397. // 先记录当前状态
  398. const wasOpen = showButtonMenu.value;
  399. // 关闭其他卡片的菜单
  400. document.dispatchEvent(new CustomEvent("closeAllCardMenus"));
  401. // 切换当前菜单状态
  402. showButtonMenu.value = !wasOpen;
  403. }
  404. };
  405. // 关闭菜单
  406. const closeMenu = () => {
  407. showButtonMenu.value = false;
  408. };
  409. const handleTouchStart = (event) => {
  410. if (!hasSwipeActions.value) return;
  411. const touch = event.touches && event.touches[0];
  412. if (!touch) return;
  413. touchStartX.value = touch.clientX;
  414. touchStartY.value = touch.clientY;
  415. isSwiping.value = false;
  416. document.dispatchEvent(new CustomEvent("closeAllCardSwipes"));
  417. };
  418. const handleTouchMove = (event) => {
  419. if (!hasSwipeActions.value) return;
  420. const touch = event.touches && event.touches[0];
  421. if (!touch) return;
  422. const deltaX = touch.clientX - touchStartX.value;
  423. const deltaY = touch.clientY - touchStartY.value;
  424. if (Math.abs(deltaY) > Math.abs(deltaX) || Math.abs(deltaX) < 8) {
  425. return;
  426. }
  427. isSwiping.value = true;
  428. const nextOffset = swipeOpening.value
  429. ? actionPaneWidth.value - deltaX
  430. : -deltaX;
  431. swipeOffset.value = Math.max(
  432. 0,
  433. Math.min(actionPaneWidth.value, nextOffset)
  434. );
  435. };
  436. const handleTouchEnd = () => {
  437. if (!hasSwipeActions.value) return;
  438. if (swipeOffset.value > actionPaneWidth.value / 2) {
  439. openSwipe();
  440. } else {
  441. closeSwipe();
  442. }
  443. setTimeout(() => {
  444. isSwiping.value = false;
  445. }, 0);
  446. };
  447. const handleCloseAllSwipes = () => {
  448. closeSwipe();
  449. };
  450. // 处理按钮点击
  451. const handleButtonClick = (btn, index) => {
  452. showButtonMenu.value = false;
  453. closeSwipe();
  454. // 执行按钮的回调
  455. if (btn.onclick && typeof btn.onclick === "function") {
  456. btn.onclick();
  457. }
  458. // 触发组件事件
  459. emit("buttonClick", { button: btn, index, item: props.item });
  460. };
  461. // 监听全局关闭事件
  462. onMounted(() => {
  463. document.addEventListener("closeAllCardMenus", closeMenu);
  464. document.addEventListener("closeAllCardSwipes", handleCloseAllSwipes);
  465. });
  466. onBeforeUnmount(() => {
  467. document.removeEventListener("closeAllCardMenus", closeMenu);
  468. document.removeEventListener(
  469. "closeAllCardSwipes",
  470. handleCloseAllSwipes
  471. );
  472. });
  473. // H5环境下的清理逻辑
  474. // 注意:Vue 3的beforeUnmount在某些H5环境下可能不可用
  475. // 这里暂时省略,依赖页面刷新时的自动清理
  476. return {
  477. showButtonMenu,
  478. swipeActions,
  479. hasSwipeActions,
  480. hasButtons,
  481. isMultipleButtons,
  482. isSingleButton,
  483. cardContentStyle,
  484. actionPaneStyle,
  485. swipeIndicatorStyle,
  486. getSwipeActionStyle,
  487. handleCardClick,
  488. handleSettingClick,
  489. handleTouchStart,
  490. handleTouchMove,
  491. handleTouchEnd,
  492. handleButtonClick,
  493. };
  494. },
  495. template: `
  496. <div class="ss-card" :class="{ 'ss-card--swipeable': hasSwipeActions }">
  497. <div
  498. v-if="hasSwipeActions"
  499. class="ss-card-swipe__indicator"
  500. :style="swipeIndicatorStyle"
  501. ></div>
  502. <div v-if="hasSwipeActions" class="ss-card-swipe__actions" :style="actionPaneStyle">
  503. <!-- 功能说明:卡片左滑露出记录操作按钮(如“变动”),替代齿轮菜单入口 by xu 2026-03-06 -->
  504. <button
  505. v-for="(btn, index) in swipeActions"
  506. :key="index"
  507. class="ss-card-swipe__action"
  508. :style="getSwipeActionStyle(index)"
  509. @click.stop="handleButtonClick(btn, index)"
  510. >
  511. {{ btn.title || btn.text || btn.desc }}
  512. </button>
  513. </div>
  514. <div
  515. class="ss-card-swipe__content"
  516. :style="cardContentStyle"
  517. @touchstart="handleTouchStart"
  518. @touchmove="handleTouchMove"
  519. @touchend="handleTouchEnd"
  520. >
  521. <div class="ss-card-main" @click="handleCardClick">
  522. <!-- 右上角设置按钮 - 只有buttons且长度>0时显示 -->
  523. <div
  524. v-if="hasButtons && !hasSwipeActions"
  525. class="card-setting-header"
  526. @click.stop="handleSettingClick"
  527. >
  528. <div class="setting-icon">
  529. <Icon name="icon-chilun" size="32" color="#999"/>
  530. </div>
  531. <!-- 按钮弹窗菜单 - 只有多个按钮时显示 -->
  532. <div
  533. v-if="showButtonMenu && isMultipleButtons"
  534. class="button-menu"
  535. @click.stop
  536. >
  537. <div
  538. v-for="(btn, index) in item.buttons"
  539. :key="index"
  540. class="menu-item"
  541. @click="handleButtonClick(btn, index)"
  542. >
  543. <Icon v-if="btn.icon" :name="btn.icon" size="28" color="inherit"/>
  544. <span class="menu-text">{{ btn.title }}</span>
  545. </div>
  546. </div>
  547. </div>
  548. <!-- 卡片内容 -->
  549. <slot></slot>
  550. </div>
  551. </div>
  552. </div>
  553. `,
  554. };
  555. // ss-search-button 搜索按钮组件 - 从小程序转换
  556. const SsSearchButton = {
  557. name: "SsSearchButton",
  558. props: {
  559. // 按钮文本
  560. text: {
  561. type: String,
  562. default: "增加",
  563. },
  564. // 是否禁用
  565. disabled: {
  566. type: Boolean,
  567. default: false,
  568. },
  569. // 按钮高度
  570. height: {
  571. type: [String, Number],
  572. default: "36px",
  573. },
  574. // 前置图标名称
  575. preIcon: {
  576. type: String,
  577. default: "",
  578. },
  579. // 后置图标名称
  580. suffixIcon: {
  581. type: String,
  582. default: "",
  583. },
  584. // 图标大小
  585. iconSize: {
  586. type: [String, Number],
  587. default: "32",
  588. },
  589. // 图标颜色
  590. iconColor: {
  591. type: String,
  592. default: "#585d6e",
  593. },
  594. // 自定义按钮样式
  595. customStyle: {
  596. type: Object,
  597. default: () => ({}),
  598. },
  599. // 跳转链接(兼容原JSP用法)
  600. href: {
  601. type: String,
  602. default: "",
  603. },
  604. // 选项列表
  605. options: {
  606. type: Array,
  607. default: () => [],
  608. },
  609. },
  610. emits: ["click", "optionClick"],
  611. setup(props, { emit }) {
  612. // 状态
  613. const showOptionsMenu = ref(false);
  614. // 计算属性
  615. const hasOptions = computed(() => {
  616. return (
  617. props.options &&
  618. Array.isArray(props.options) &&
  619. props.options.length > 0
  620. );
  621. });
  622. const hasMultipleOptions = computed(() => {
  623. return props.options && props.options.length > 1;
  624. });
  625. const isSingleOption = computed(() => {
  626. return props.options && props.options.length === 1;
  627. });
  628. // 按钮样式
  629. const buttonStyle = computed(() => ({
  630. height:
  631. typeof props.height === "number" ? `${props.height}px` : props.height,
  632. ...props.customStyle,
  633. }));
  634. // 处理按钮点击
  635. const handleClick = () => {
  636. if (!hasOptions.value) {
  637. // 没有选项,直接触发点击事件
  638. emit("click");
  639. } else if (isSingleOption.value) {
  640. // 单个选项,直接执行
  641. handleOptionClick(props.options[0], 0);
  642. } else if (hasMultipleOptions.value) {
  643. // 先记录当前状态
  644. const wasOpen = showOptionsMenu.value;
  645. // 关闭其他按钮的菜单
  646. document.dispatchEvent(new CustomEvent("closeAllButtonMenus"));
  647. // 切换当前菜单状态
  648. showOptionsMenu.value = !wasOpen;
  649. }
  650. };
  651. // 处理选项点击
  652. const handleOptionClick = (option, index) => {
  653. showOptionsMenu.value = false;
  654. // 执行选项的回调
  655. if (option.onclick && typeof option.onclick === "function") {
  656. option.onclick();
  657. }
  658. // 触发组件事件
  659. emit("optionClick", { option, index });
  660. };
  661. // 关闭菜单
  662. const closeMenu = () => {
  663. showOptionsMenu.value = false;
  664. };
  665. // 监听全局关闭事件
  666. onMounted(() => {
  667. document.addEventListener("closeAllButtonMenus", closeMenu);
  668. });
  669. return {
  670. showOptionsMenu,
  671. hasOptions,
  672. hasMultipleOptions,
  673. isSingleOption,
  674. buttonStyle,
  675. handleClick,
  676. handleOptionClick,
  677. };
  678. },
  679. template: `
  680. <div class="ss-search-button-container" :class="{ open: showOptionsMenu }">
  681. <button
  682. class="ss-search-button"
  683. :style="buttonStyle"
  684. @click="handleClick"
  685. :disabled="disabled"
  686. >
  687. <!-- 前置图标插槽 -->
  688. <div v-if="preIcon" class="ss-search-button__pre-icon">
  689. <Icon :name="preIcon" :size="iconSize" :color="iconColor"/>
  690. </div>
  691. <!-- 按钮文本 -->
  692. <span class="ss-search-button__text">{{ text }}</span>
  693. <!-- 后置图标插槽 -->
  694. <div v-if="suffixIcon" class="ss-search-button__suffix-icon">
  695. <Icon :name="suffixIcon" :size="iconSize" :color="iconColor"/>
  696. </div>
  697. </button>
  698. <!-- 选项弹窗菜单 -->
  699. <div
  700. v-if="showOptionsMenu && hasMultipleOptions"
  701. class="options-menu"
  702. @click.stop
  703. >
  704. <div
  705. v-for="(option, index) in options"
  706. :key="index"
  707. class="option-item"
  708. @click="handleOptionClick(option, index)"
  709. >
  710. <Icon v-if="option.icon" :name="option.icon" size="28" color="inherit"/>
  711. <span class="option-text">{{ option.text }}</span>
  712. </div>
  713. </div>
  714. </div>
  715. `,
  716. };
  717. let activeSsSelectCloser = null;
  718. // ss-select 下拉选择组件 - 从小程序转换
  719. const SsSelect = {
  720. name: "SsSelect",
  721. props: {
  722. // 选项数组
  723. options: {
  724. type: Array,
  725. default: () => [],
  726. },
  727. // 字段映射
  728. mapping: {
  729. type: Object,
  730. default: () => ({ text: "n", value: "v" }),
  731. },
  732. // 默认值
  733. modelValue: {
  734. type: [String, Number],
  735. default: "",
  736. },
  737. // 占位符
  738. placeholder: {
  739. type: String,
  740. default: "请选择",
  741. },
  742. // 校验配置
  743. validation: {
  744. type: Object,
  745. default: () => ({ enable: false, message: "" }),
  746. },
  747. // 是否禁用
  748. disabled: {
  749. type: Boolean,
  750. default: false,
  751. },
  752. // 是否支持搜索
  753. searchable: {
  754. type: Boolean,
  755. default: false,
  756. },
  757. // 是否支持清空
  758. clearable: {
  759. type: Boolean,
  760. default: false,
  761. },
  762. // 加载状态
  763. loading: {
  764. type: Boolean,
  765. default: false,
  766. },
  767. // 宽度设置
  768. width: {
  769. type: String,
  770. default: "100%",
  771. },
  772. minWidth: {
  773. type: String,
  774. default: "unset",
  775. },
  776. // 功能说明:对齐PC端 ss-objp,用 codebook 在组件内部拉取下拉选项 by xu 2026-02-28
  777. cb: {
  778. type: String,
  779. default: "",
  780. },
  781. url: {
  782. type: String,
  783. default: "/service?ssServ=loadObjpOpt&objectpickerdropdown1=1",
  784. },
  785. inp: {
  786. type: [Boolean, String],
  787. default: false,
  788. },
  789. filter: {
  790. type: [Object, String],
  791. default: null,
  792. },
  793. autoSelectFirst: {
  794. type: Boolean,
  795. default: false,
  796. },
  797. },
  798. emits: ["update:modelValue", "change", "search", "clear", "loaded"],
  799. setup(props, { emit }) {
  800. const isOpen = ref(false);
  801. const containerRef = ref(null);
  802. const optionsRef = ref(null);
  803. const optionsStyle = ref({});
  804. const inputRef = ref(null);
  805. const selectedValue = ref(props.modelValue);
  806. const searchKeyword = ref("");
  807. const filterKeyword = ref("");
  808. const remoteOptions = ref([]);
  809. const remoteLoading = ref(false);
  810. const autoMinWidth = ref("");
  811. const forceShowAll = ref(false);
  812. const canInput = computed(() => {
  813. return props.inp === true || props.inp === "true";
  814. });
  815. // 功能说明:ss-select 未显式传宽度时,按 placeholder/选项文本计算稳定最小宽度,避免回显和下拉宽度随选中项抖动 by xu 2026-03-06
  816. const normalizeCssSize = (value) => {
  817. if (value === undefined || value === null) return "";
  818. if (typeof value === "number") return `${value}px`;
  819. const text = String(value).trim();
  820. return text;
  821. };
  822. const hasExplicitWidth = computed(() => {
  823. const widthText = normalizeCssSize(props.width);
  824. if (!widthText) return false;
  825. return widthText !== "100%" && widthText !== "auto";
  826. });
  827. const parseFilterObj = () => {
  828. if (!props.filter) return {};
  829. if (typeof props.filter === "object") return props.filter;
  830. if (typeof props.filter === "string") {
  831. try {
  832. const obj = JSON.parse(props.filter);
  833. return obj && typeof obj === "object" ? obj : {};
  834. } catch (_) {
  835. return {};
  836. }
  837. }
  838. return {};
  839. };
  840. const normalizeResultToOptions = (respData) => {
  841. const raw = respData || {};
  842. if (Array.isArray(raw.resultList)) {
  843. return raw.resultList.map((it) => {
  844. if (it && typeof it === "object") return it;
  845. return { n: String(it || ""), v: String(it || "") };
  846. });
  847. }
  848. if (Array.isArray(raw.result)) {
  849. return raw.result
  850. .map((it) => {
  851. if (!it || typeof it !== "object") return null;
  852. const entry = Object.entries(it)[0];
  853. if (!entry) return null;
  854. return { n: entry[1], v: entry[0] };
  855. })
  856. .filter(Boolean);
  857. }
  858. if (raw.result && typeof raw.result === "object") {
  859. return Object.keys(raw.result).map((k) => ({
  860. n: raw.result[k],
  861. v: k,
  862. }));
  863. }
  864. if (Array.isArray(raw.objectList)) {
  865. return raw.objectList.map((it) => {
  866. if (it && typeof it === "object") return it;
  867. return { n: String(it || ""), v: String(it || "") };
  868. });
  869. }
  870. return [];
  871. };
  872. const needRemoteData = computed(() => !!String(props.cb || "").trim());
  873. const optionsList = computed(() => {
  874. if (Array.isArray(props.options) && props.options.length > 0) {
  875. return props.options;
  876. }
  877. if (needRemoteData.value) {
  878. return remoteOptions.value;
  879. }
  880. return [];
  881. });
  882. const getOptionText = (option) => {
  883. if (!option || typeof option !== "object") return "";
  884. const text = option[props.mapping.text];
  885. return text === undefined || text === null ? "" : String(text);
  886. };
  887. const findSelectedOption = () => {
  888. return optionsList.value.find(
  889. (option) => option?.[props.mapping.value] === selectedValue.value
  890. );
  891. };
  892. const syncInputFromSelection = () => {
  893. if (!canInput.value) return;
  894. const selectedOption = findSelectedOption();
  895. searchKeyword.value = selectedOption
  896. ? getOptionText(selectedOption)
  897. : "";
  898. filterKeyword.value = "";
  899. forceShowAll.value = false;
  900. };
  901. const filteredOptions = computed(() => {
  902. const list = Array.isArray(optionsList.value) ? optionsList.value : [];
  903. if (!canInput.value || forceShowAll.value) {
  904. return list;
  905. }
  906. const keyword = String(filterKeyword.value || "")
  907. .trim()
  908. .toLowerCase();
  909. if (!keyword) {
  910. return list;
  911. }
  912. return list.filter((option) =>
  913. getOptionText(option).toLowerCase().includes(keyword)
  914. );
  915. });
  916. const measureStableMinWidth = () => {
  917. if (hasExplicitWidth.value) {
  918. autoMinWidth.value = "";
  919. return;
  920. }
  921. const texts = [props.placeholder]
  922. .concat(
  923. (Array.isArray(optionsList.value) ? optionsList.value : []).map(
  924. (option) => option?.[props.mapping.text]
  925. )
  926. )
  927. .map((item) =>
  928. item === undefined || item === null ? "" : String(item).trim()
  929. )
  930. .filter(Boolean);
  931. if (!texts.length || typeof document === "undefined") {
  932. autoMinWidth.value = "";
  933. return;
  934. }
  935. const measureNode =
  936. containerRef.value?.querySelector?.(".select-text") ||
  937. containerRef.value;
  938. const computedStyle = measureNode
  939. ? window.getComputedStyle(measureNode)
  940. : null;
  941. const fontSize = computedStyle?.fontSize || "16px";
  942. const fontWeight = computedStyle?.fontWeight || "400";
  943. const fontFamily = computedStyle?.fontFamily || "sans-serif";
  944. const canvas = document.createElement("canvas");
  945. const context = canvas.getContext("2d");
  946. if (!context) return;
  947. context.font = `${fontWeight} ${fontSize} ${fontFamily}`;
  948. const widestText = texts.reduce((maxWidth, text) => {
  949. return Math.max(maxWidth, context.measureText(text).width);
  950. }, 0);
  951. const reservedWidth = 52;
  952. autoMinWidth.value = `${Math.max(
  953. 88,
  954. Math.ceil(widestText + reservedWidth)
  955. )}px`;
  956. };
  957. const maybeAutoSelectFirst = (opts) => {
  958. if (!props.autoSelectFirst) return;
  959. if (!Array.isArray(opts) || opts.length === 0) return;
  960. if (
  961. selectedValue.value !== undefined &&
  962. selectedValue.value !== null &&
  963. selectedValue.value !== ""
  964. ) {
  965. return;
  966. }
  967. const first = opts[0];
  968. if (!first || typeof first !== "object") return;
  969. const value = first[props.mapping.value];
  970. if (value === undefined || value === null || value === "") return;
  971. selectedValue.value = value;
  972. emit("update:modelValue", value);
  973. emit("change", value);
  974. syncInputFromSelection();
  975. };
  976. const loadRemoteOptions = async () => {
  977. if (!needRemoteData.value) return;
  978. if (!window.request || typeof window.request.post !== "function")
  979. return;
  980. remoteLoading.value = true;
  981. try {
  982. const filterObj = parseFilterObj();
  983. const objpParam = {
  984. input: String(canInput.value),
  985. codebook: String(props.cb || ""),
  986. ...filterObj,
  987. };
  988. const postData = {
  989. objectpickerparam: JSON.stringify(objpParam),
  990. objectpickertype: 1,
  991. objectpickersearchAll: 1,
  992. };
  993. // 功能说明:xyByBj 人员码本按班级级联时,补充固定 cascadingLevel 和上级班级值 by xu 2026-03-18
  994. if (String(props.cb || "") === "xyByBj" && filterObj.bjid) {
  995. objpParam.cascadingLevel = "bjid,ryid";
  996. postData.objectpickerparam = JSON.stringify(objpParam);
  997. postData.upperValue = filterObj.bjid;
  998. }
  999. const resp = await window.request.post(
  1000. props.url || "/service?ssServ=loadObjpOpt&objectpickerdropdown1=1",
  1001. postData,
  1002. { loading: false, formData: true }
  1003. );
  1004. const opts = normalizeResultToOptions(
  1005. resp && resp.data ? resp.data : null
  1006. );
  1007. remoteOptions.value = opts;
  1008. emit("loaded", opts);
  1009. maybeAutoSelectFirst(opts);
  1010. if (!isOpen.value) {
  1011. syncInputFromSelection();
  1012. }
  1013. } catch (e) {
  1014. remoteOptions.value = [];
  1015. emit("loaded", []);
  1016. console.error("[ss-select] loadRemoteOptions failed", props.cb, e);
  1017. } finally {
  1018. remoteLoading.value = false;
  1019. }
  1020. };
  1021. const finalLoading = computed(() => {
  1022. return !!props.loading || remoteLoading.value;
  1023. });
  1024. const selectContainerStyle = computed(() => {
  1025. const style = {};
  1026. const widthText = normalizeCssSize(props.width);
  1027. const minWidthText = normalizeCssSize(props.minWidth);
  1028. // 功能说明:ss-select 在 td 等窄容器中限制最大宽度,避免自动 minWidth 把父布局撑开 by xu 2026-03-07
  1029. style.maxWidth = "100%";
  1030. if (hasExplicitWidth.value) {
  1031. style.width = widthText;
  1032. }
  1033. if (minWidthText && minWidthText !== "unset") {
  1034. style.minWidth = `min(${minWidthText}, 100%)`;
  1035. } else if (autoMinWidth.value) {
  1036. style.minWidth = `min(${autoMinWidth.value}, 100%)`;
  1037. }
  1038. return style;
  1039. });
  1040. const displayText = computed(() => {
  1041. if (!selectedValue.value) return props.placeholder;
  1042. const selectedOption = findSelectedOption();
  1043. return selectedOption
  1044. ? getOptionText(selectedOption)
  1045. : props.placeholder;
  1046. });
  1047. const enterInputFilterMode = () => {
  1048. if (!canInput.value) return;
  1049. const selectedOption = findSelectedOption();
  1050. const selectedText = selectedOption
  1051. ? getOptionText(selectedOption)
  1052. : "";
  1053. if (!filterKeyword.value && searchKeyword.value === selectedText) {
  1054. searchKeyword.value = "";
  1055. }
  1056. filterKeyword.value = searchKeyword.value;
  1057. forceShowAll.value = false;
  1058. };
  1059. // 将选项浮层挂到 body,并按可视区域动态定位,避免被页面滚动容器裁切。
  1060. const updateOptionsPosition = async () => {
  1061. await nextTick();
  1062. const container = containerRef.value;
  1063. const menu = optionsRef.value;
  1064. if (!container || !menu) return;
  1065. const rect = container.getBoundingClientRect();
  1066. const viewportWidth =
  1067. document.documentElement.clientWidth || window.innerWidth;
  1068. const viewportHeight =
  1069. document.documentElement.clientHeight || window.innerHeight;
  1070. const margin = 12;
  1071. const gap = 6;
  1072. const naturalHeight = Math.min(menu.scrollHeight || 300, 320);
  1073. const spaceBelow = viewportHeight - rect.bottom - margin - gap;
  1074. const spaceAbove = rect.top - margin - gap;
  1075. const openUp =
  1076. spaceBelow < Math.min(naturalHeight, 220) &&
  1077. spaceAbove > spaceBelow;
  1078. const available = Math.max(openUp ? spaceAbove : spaceBelow, 80);
  1079. const maxHeight = Math.min(320, available);
  1080. const top = openUp
  1081. ? Math.max(margin, rect.top - maxHeight - gap)
  1082. : Math.min(
  1083. viewportHeight - margin - maxHeight,
  1084. rect.bottom + gap
  1085. );
  1086. const menuWidth = Math.min(
  1087. viewportWidth - margin * 2,
  1088. Math.max(rect.width, 260)
  1089. );
  1090. const left = Math.max(
  1091. margin,
  1092. Math.min(rect.left, viewportWidth - margin - menuWidth)
  1093. );
  1094. optionsStyle.value = {
  1095. display: "block",
  1096. position: "fixed",
  1097. fontSize: "14px",
  1098. lineHeight: "20px",
  1099. top: `${top}px`,
  1100. left: `${left}px`,
  1101. minWidth: `${Math.min(rect.width, viewportWidth - margin * 2)}px`,
  1102. maxWidth: `${viewportWidth - margin * 2}px`,
  1103. maxHeight: `${Math.max(80, maxHeight)}px`,
  1104. width: `${menuWidth}px`,
  1105. overflowY: "auto",
  1106. overflowX: "hidden",
  1107. WebkitOverflowScrolling: "touch",
  1108. overscrollBehavior: "contain",
  1109. zIndex: 10000,
  1110. };
  1111. await nextTick();
  1112. const menuRect = menu.getBoundingClientRect();
  1113. if (menuRect.right > viewportWidth - margin) {
  1114. optionsStyle.value = {
  1115. ...optionsStyle.value,
  1116. left: `${Math.max(
  1117. margin,
  1118. viewportWidth - margin - menuRect.width
  1119. )}px`,
  1120. };
  1121. }
  1122. };
  1123. const openDropdown = (showAll = false) => {
  1124. if (props.disabled) return;
  1125. if (activeSsSelectCloser && activeSsSelectCloser !== closeDropdown) {
  1126. activeSsSelectCloser({ restoreInput: true });
  1127. }
  1128. forceShowAll.value = showAll;
  1129. isOpen.value = true;
  1130. activeSsSelectCloser = closeDropdown;
  1131. updateOptionsPosition();
  1132. };
  1133. const closeDropdown = ({ restoreInput = true } = {}) => {
  1134. isOpen.value = false;
  1135. forceShowAll.value = false;
  1136. if (activeSsSelectCloser === closeDropdown) {
  1137. activeSsSelectCloser = null;
  1138. }
  1139. if (restoreInput) {
  1140. syncInputFromSelection();
  1141. }
  1142. };
  1143. const toggleDropdown = () => {
  1144. if (props.disabled) return;
  1145. if (isOpen.value) {
  1146. closeDropdown();
  1147. } else {
  1148. openDropdown(false);
  1149. }
  1150. };
  1151. const handleContainerClick = () => {
  1152. if (props.disabled || canInput.value) return;
  1153. toggleDropdown();
  1154. };
  1155. const handleTextClick = () => {
  1156. if (props.disabled) return;
  1157. if (!canInput.value) {
  1158. toggleDropdown();
  1159. return;
  1160. }
  1161. enterInputFilterMode();
  1162. openDropdown(false);
  1163. if (inputRef.value) {
  1164. inputRef.value.focus();
  1165. }
  1166. };
  1167. const handleInputFocus = () => {
  1168. if (props.disabled || !canInput.value) return;
  1169. enterInputFilterMode();
  1170. openDropdown(false);
  1171. };
  1172. const handleInput = (event) => {
  1173. const value = event?.target?.value || "";
  1174. searchKeyword.value = value;
  1175. filterKeyword.value = value;
  1176. forceShowAll.value = false;
  1177. isOpen.value = true;
  1178. updateOptionsPosition();
  1179. emit("search", value);
  1180. };
  1181. const handleArrowClick = () => {
  1182. if (props.disabled) return;
  1183. if (!canInput.value) {
  1184. toggleDropdown();
  1185. return;
  1186. }
  1187. filterKeyword.value = "";
  1188. forceShowAll.value = true;
  1189. isOpen.value = true;
  1190. updateOptionsPosition();
  1191. };
  1192. const selectOption = (option) => {
  1193. const value = option[props.mapping.value];
  1194. selectedValue.value = value;
  1195. searchKeyword.value = getOptionText(option);
  1196. filterKeyword.value = "";
  1197. forceShowAll.value = false;
  1198. isOpen.value = false;
  1199. emit("update:modelValue", value);
  1200. emit("change", value);
  1201. };
  1202. const handleClickOutside = (event) => {
  1203. if (
  1204. !containerRef.value?.contains(event.target) &&
  1205. !optionsRef.value?.contains(event.target)
  1206. ) {
  1207. closeDropdown();
  1208. }
  1209. };
  1210. const handleViewportChange = () => {
  1211. if (isOpen.value) updateOptionsPosition();
  1212. };
  1213. watch(
  1214. () => props.modelValue,
  1215. (newValue) => {
  1216. selectedValue.value = newValue;
  1217. if (!isOpen.value) {
  1218. syncInputFromSelection();
  1219. }
  1220. },
  1221. { immediate: true }
  1222. );
  1223. watch(
  1224. () => props.options,
  1225. (newVal) => {
  1226. if (needRemoteData.value) return;
  1227. emit("loaded", Array.isArray(newVal) ? newVal : []);
  1228. if (!isOpen.value) {
  1229. syncInputFromSelection();
  1230. }
  1231. }
  1232. );
  1233. watch(
  1234. () => [props.cb, props.url, props.filter],
  1235. () => {
  1236. if (!needRemoteData.value) return;
  1237. loadRemoteOptions();
  1238. }
  1239. );
  1240. watch(
  1241. () => [
  1242. props.placeholder,
  1243. props.width,
  1244. props.minWidth,
  1245. optionsList.value
  1246. .map((option) => option?.[props.mapping.text])
  1247. .join("||"),
  1248. ],
  1249. () => {
  1250. measureStableMinWidth();
  1251. },
  1252. { immediate: true }
  1253. );
  1254. watch(
  1255. () => optionsList.value,
  1256. () => {
  1257. if (!isOpen.value) {
  1258. syncInputFromSelection();
  1259. }
  1260. },
  1261. { deep: true }
  1262. );
  1263. onMounted(() => {
  1264. document.addEventListener("click", handleClickOutside);
  1265. window.addEventListener("resize", handleViewportChange);
  1266. window.addEventListener("scroll", handleViewportChange, true);
  1267. loadRemoteOptions();
  1268. if (!needRemoteData.value && Array.isArray(props.options)) {
  1269. emit("loaded", props.options);
  1270. }
  1271. syncInputFromSelection();
  1272. measureStableMinWidth();
  1273. });
  1274. onBeforeUnmount(() => {
  1275. if (activeSsSelectCloser === closeDropdown) {
  1276. activeSsSelectCloser = null;
  1277. }
  1278. document.removeEventListener("click", handleClickOutside);
  1279. window.removeEventListener("resize", handleViewportChange);
  1280. window.removeEventListener("scroll", handleViewportChange, true);
  1281. });
  1282. return {
  1283. containerRef,
  1284. optionsRef,
  1285. optionsStyle,
  1286. inputRef,
  1287. isOpen,
  1288. selectedValue,
  1289. searchKeyword,
  1290. canInput,
  1291. filteredOptions,
  1292. finalLoading,
  1293. displayText,
  1294. selectContainerStyle,
  1295. handleContainerClick,
  1296. handleTextClick,
  1297. handleInputFocus,
  1298. handleInput,
  1299. handleArrowClick,
  1300. selectOption,
  1301. };
  1302. },
  1303. template: `
  1304. <div
  1305. ref="containerRef"
  1306. class="ss-select-container"
  1307. :class="{ open: isOpen }"
  1308. :style="selectContainerStyle"
  1309. @click.stop="handleContainerClick"
  1310. >
  1311. <div class="ss-select" :class="{ disabled: disabled }">
  1312. <div class="select-text" @click.stop="handleTextClick">
  1313. <input
  1314. v-if="canInput"
  1315. ref="inputRef"
  1316. :type="'text'"
  1317. :value="searchKeyword"
  1318. :placeholder="placeholder"
  1319. :disabled="disabled"
  1320. @focus.stop="handleInputFocus"
  1321. @click.stop="handleTextClick"
  1322. @input="handleInput"
  1323. style="width: 100%; border: none; outline: none; background: transparent; color: inherit; font-size: inherit; padding: 0; margin: 0;"
  1324. />
  1325. <span v-else :class="{ placeholder: !selectedValue }">{{ displayText }}</span>
  1326. </div>
  1327. <div class="select-arrow" :class="{ rotate: isOpen }" @click.stop="handleArrowClick">
  1328. <Icon name="icon-xiangxiajiantou" size="32" :color="disabled ? '#ccc' : '#999'"/>
  1329. </div>
  1330. </div>
  1331. <teleport to="body">
  1332. <div
  1333. ref="optionsRef"
  1334. class="ss-options"
  1335. :style="optionsStyle"
  1336. v-if="isOpen"
  1337. @click.stop
  1338. >
  1339. <div
  1340. v-if="finalLoading"
  1341. class="option-item loading-item"
  1342. >
  1343. <span class="loading-text">加载中...</span>
  1344. </div>
  1345. <div
  1346. v-else-if="filteredOptions.length === 0"
  1347. class="option-item no-options"
  1348. >
  1349. 无选项
  1350. </div>
  1351. <div
  1352. v-else
  1353. v-for="(option, index) in filteredOptions"
  1354. :key="index"
  1355. class="option-item"
  1356. :class="{ selected: option[mapping.value] === selectedValue }"
  1357. @click.stop="selectOption(option)"
  1358. >
  1359. {{ option[mapping.text] }}
  1360. </div>
  1361. </div>
  1362. </teleport>
  1363. </div>
  1364. `,
  1365. };
  1366. // ss-bottom 底部按钮组件
  1367. const SsBottom = {
  1368. name: "SsBottom",
  1369. props: {
  1370. // 是否显示审核意见
  1371. showShyj: {
  1372. type: Boolean,
  1373. default: false,
  1374. },
  1375. // 审核意见标题
  1376. shyjTitle: {
  1377. type: String,
  1378. default: "审核意见",
  1379. },
  1380. // 审核意见占位符
  1381. shyjPlaceholder: {
  1382. type: String,
  1383. default: "请输入审核意见",
  1384. },
  1385. divider: {
  1386. type: Boolean,
  1387. default: true,
  1388. },
  1389. // 按钮配置
  1390. buttons: {
  1391. type: Array,
  1392. default: () => [
  1393. { text: "取消", action: "cancel" },
  1394. { text: "保存并提交", action: "submit" },
  1395. ],
  1396. },
  1397. },
  1398. emits: ["button-click", "update:shyjValue"],
  1399. setup(props, { emit }) {
  1400. const reason = ref("");
  1401. const activeButtonIndex = ref(-1);
  1402. // 处理按钮点击
  1403. const handleButtonClick = (button, index) => {
  1404. emit("button-click", {
  1405. action: button.action,
  1406. button: button,
  1407. index: index,
  1408. shyjValue: reason.value, // 传递审核意见
  1409. });
  1410. };
  1411. // 监听审核意见变化
  1412. const handleShyjInput = (event) => {
  1413. const value = event.target.value;
  1414. reason.value = value;
  1415. emit("update:shyjValue", value);
  1416. };
  1417. // 处理按钮按下
  1418. const handleButtonMouseDown = (index) => {
  1419. activeButtonIndex.value = index;
  1420. };
  1421. // 处理按钮释放
  1422. const handleButtonMouseUp = () => {
  1423. activeButtonIndex.value = -1;
  1424. };
  1425. // 处理鼠标离开
  1426. const handleMouseLeave = () => {
  1427. activeButtonIndex.value = -1;
  1428. };
  1429. // 计算按钮样式
  1430. const getButtonStyle = (button) => {
  1431. const styles = {};
  1432. // 如果有背景颜色配置
  1433. if (button.backgroundColor) {
  1434. styles.backgroundColor = button.backgroundColor;
  1435. }
  1436. // 如果有字体颜色配置
  1437. if (button.color) {
  1438. styles.color = button.color;
  1439. }
  1440. return styles;
  1441. };
  1442. // 计算按钮点击样式
  1443. const getButtonActiveStyle = (button) => {
  1444. const styles = {};
  1445. // 如果有点击背景色配置,使用点击背景色
  1446. if (button.clickBgColor) {
  1447. styles.backgroundColor = button.clickBgColor;
  1448. } else if (button.backgroundColor) {
  1449. // 如果没有点击背景色,但有背景色,点击时使用背景色
  1450. styles.backgroundColor = button.backgroundColor;
  1451. }
  1452. // 如果有点击字体色配置,使用点击字体色
  1453. if (button.clickColor) {
  1454. styles.color = button.clickColor;
  1455. } else if (button.color) {
  1456. // 如果没有点击字体色,但有字体色,点击时使用字体色
  1457. styles.color = button.color;
  1458. }
  1459. return styles;
  1460. };
  1461. return {
  1462. reason,
  1463. activeButtonIndex,
  1464. handleButtonClick,
  1465. handleShyjInput,
  1466. handleButtonMouseDown,
  1467. handleButtonMouseUp,
  1468. handleMouseLeave,
  1469. getButtonStyle,
  1470. getButtonActiveStyle,
  1471. };
  1472. },
  1473. template: `
  1474. <div class="ss-bottom">
  1475. <!-- 审核意见区域 -->
  1476. <div v-if="showShyj" class="ss-bottom__opinion">
  1477. <table class="ss-bottom__opinion-table">
  1478. <tr>
  1479. <th class="ss-bottom__opinion-label">{{ shyjTitle }}</th>
  1480. <td class="ss-bottom__opinion-input">
  1481. <ss-input
  1482. :placeholder="shyjPlaceholder"
  1483. v-model="reason"
  1484. @input="handleShyjInput"
  1485. />
  1486. </td>
  1487. </tr>
  1488. </table>
  1489. </div>
  1490. <!-- 按钮区域 -->
  1491. <div class="ss-bottom__buttons" :class="{ 'ss-bottom__buttons--with-border': !showShyj }">
  1492. <template v-for="(button, index) in buttons" :key="index">
  1493. <div
  1494. class="ss-bottom__button"
  1495. :class="{
  1496. 'ss-bottom__button--custom': button.backgroundColor || button.color || button.clickBgColor || button.clickColor,
  1497. 'ss-bottom__button--active': activeButtonIndex === index
  1498. }"
  1499. :style="activeButtonIndex === index ? getButtonActiveStyle(button) : getButtonStyle(button)"
  1500. @click="handleButtonClick(button, index)"
  1501. @mousedown="handleButtonMouseDown(index)"
  1502. @mouseup="handleButtonMouseUp"
  1503. @mouseleave="handleMouseLeave"
  1504. @touchstart="handleButtonMouseDown(index)"
  1505. @touchend="handleButtonMouseUp"
  1506. >
  1507. {{ button.text }}
  1508. </div>
  1509. <!-- 分割线,最后一个按钮不显示 -->
  1510. <div v-if="index < buttons.length - 1 && divider" class="ss-bottom__divider"></div>
  1511. </template>
  1512. </div>
  1513. </div>
  1514. `,
  1515. };
  1516. // ===== SsVerify 审核节点链组件 =====
  1517. const SsVerify = {
  1518. name: "SsVerify",
  1519. props: {
  1520. verifyList: {
  1521. type: Array,
  1522. required: true,
  1523. },
  1524. },
  1525. setup(props) {
  1526. const toggleOpen = (item) => {
  1527. item.open = !item.open;
  1528. // 切换后重新计算连线高度
  1529. setTimeout(() => {
  1530. calculateLineHeight();
  1531. }, 50);
  1532. };
  1533. // 计算连线高度的函数
  1534. const calculateLineHeight = () => {
  1535. const lastOpenGroup = document.querySelector(".group-item-last-open");
  1536. console.log("lastOpenGroup", lastOpenGroup);
  1537. if (lastOpenGroup) {
  1538. // 使用原生JavaScript代替jQuery
  1539. const nodes = lastOpenGroup.querySelectorAll(
  1540. ".verify-node-container"
  1541. );
  1542. if (nodes.length) {
  1543. let totalHeight = 0;
  1544. if (nodes.length === 1) {
  1545. // 只有一个节点时,连线伸到节点的中间位置
  1546. const nodeHeight = nodes[0].offsetHeight;
  1547. const nodeTop = nodes[0].offsetTop;
  1548. totalHeight = nodeTop + nodeHeight / 2 - 15; // 减去圆点半径5px
  1549. } else {
  1550. // 多个节点时,连线延伸到最后一个节点的中间位置
  1551. const lastNode = nodes[nodes.length - 1];
  1552. const lastNodeTop = lastNode.offsetTop;
  1553. const lastNodeHeight = lastNode.offsetHeight;
  1554. totalHeight = lastNodeTop + lastNodeHeight / 2 - 15; // 减去圆点半径5px
  1555. }
  1556. console.log("节点信息:", {
  1557. 节点总数: nodes.length,
  1558. 计算后的高度: totalHeight,
  1559. 最后节点top: nodes[nodes.length - 1]?.offsetTop,
  1560. 最后节点高度: nodes[nodes.length - 1]?.offsetHeight,
  1561. });
  1562. lastOpenGroup.style.setProperty(
  1563. "--group-line-height",
  1564. `${totalHeight}px`
  1565. );
  1566. }
  1567. }
  1568. };
  1569. onMounted(() => {
  1570. setTimeout(() => {
  1571. calculateLineHeight();
  1572. }, 100);
  1573. });
  1574. return {
  1575. toggleOpen,
  1576. };
  1577. },
  1578. render() {
  1579. const { h } = Vue;
  1580. return h(
  1581. "div",
  1582. { class: "verify-nodes" },
  1583. this.verifyList.map((item, i) =>
  1584. h(
  1585. "div",
  1586. {
  1587. key: i,
  1588. class: {
  1589. "group-item": true,
  1590. "group-item-last-open":
  1591. i === this.verifyList.length - 1 && item.open,
  1592. },
  1593. },
  1594. [
  1595. h(
  1596. "div",
  1597. {
  1598. class: "group-item-title",
  1599. onClick: () => this.toggleOpen(item),
  1600. },
  1601. [
  1602. h("div", { class: "icon" }, [
  1603. h("i", {
  1604. class: item.open
  1605. ? "common-icon-folder-open common-icon"
  1606. : "common-icon-folder-close common-icon",
  1607. }),
  1608. h(
  1609. "div",
  1610. {
  1611. class: "num",
  1612. style: { top: item.open ? "60%" : "55%" },
  1613. },
  1614. item.children?.length || 0
  1615. ),
  1616. ]),
  1617. h("div", { class: "name" }, item.groupName),
  1618. ]
  1619. ),
  1620. item.open && item.children?.length > 0
  1621. ? h(
  1622. "div",
  1623. { class: "group-item-children" },
  1624. item.children.map((citem, j) =>
  1625. h(SsVerifyNode, {
  1626. key: j,
  1627. item: citem,
  1628. // isGroup: i + 1 !== this.verifyList.length,
  1629. isGroup: true,
  1630. })
  1631. )
  1632. )
  1633. : null,
  1634. ]
  1635. )
  1636. )
  1637. );
  1638. },
  1639. };
  1640. // ===== SsVerifyNode 审核节点组件 =====
  1641. const SsVerifyNode = {
  1642. name: "SsVerifyNode",
  1643. props: {
  1644. item: {
  1645. type: Object,
  1646. required: true,
  1647. },
  1648. isGroup: {
  1649. type: Boolean,
  1650. default: false,
  1651. },
  1652. },
  1653. render() {
  1654. const { h } = Vue;
  1655. return h("div", { class: "verify-node-container" }, [
  1656. h("div", { class: "info" }, [
  1657. h("div", { class: "avatar" }, [
  1658. h("img", {
  1659. src: this.item.thumb,
  1660. style: {
  1661. width: "50px",
  1662. height: "50px",
  1663. borderRadius: "50%",
  1664. },
  1665. }),
  1666. ]),
  1667. h("div", { class: "desc" }, [
  1668. h("div", this.item.name),
  1669. h("div", this.item.role),
  1670. ]),
  1671. h("div", { class: "link" }, [
  1672. h("div", [
  1673. this.item.video
  1674. ? h("i", { class: "common-icon-video common-icon" })
  1675. : null,
  1676. this.item.link
  1677. ? h("i", { class: "common-icon-paper-clip common-icon" })
  1678. : null,
  1679. ]),
  1680. ]),
  1681. ]),
  1682. h(
  1683. "div",
  1684. {
  1685. class: {
  1686. description: true,
  1687. link: this.isGroup,
  1688. },
  1689. attrs: { "data-num": "3" },
  1690. },
  1691. [h("div", this.item.description)]
  1692. ),
  1693. h("div", { class: "time" }, this.item.time),
  1694. ]);
  1695. },
  1696. };
  1697. // ===== SsOnoffButton 开关按钮 =====
  1698. const SsOnoffButton = {
  1699. name: "SsOnoffButton",
  1700. props: {
  1701. // 字段名称,用于表单校验
  1702. name: { type: String, required: true },
  1703. // 显示标签
  1704. label: { type: String, required: true },
  1705. // 按钮的值
  1706. value: { type: [String, Number], required: true },
  1707. // 宽度设置
  1708. width: { type: String, default: "" },
  1709. // v-model 绑定的值
  1710. modelValue: { type: [String, Number, Array], default: "" },
  1711. // 是否多选模式
  1712. multiple: { type: Boolean, default: false },
  1713. // 是否禁用
  1714. disabled: { type: Boolean, default: false },
  1715. },
  1716. emits: ["update:modelValue", "change"],
  1717. setup(props, { emit }) {
  1718. // 解析 modelValue,支持逗号分隔的字符串和数组
  1719. const parseModelValue = (val) => {
  1720. if (!val) return [];
  1721. // 如果是数组,直接返回字符串数组
  1722. if (Array.isArray(val)) {
  1723. return val.map((v) => v.toString());
  1724. }
  1725. // 如果是字符串,按逗号分割
  1726. const cleanValue = val.toString().replace(/^,+/, ""); // 去掉开头的逗号
  1727. if (cleanValue.includes("|")) {
  1728. return cleanValue.split("|");
  1729. }
  1730. if (cleanValue.includes(",")) {
  1731. return cleanValue.split(",");
  1732. }
  1733. return cleanValue ? [cleanValue] : [];
  1734. };
  1735. // 判断当前按钮是否选中
  1736. const isChecked = computed(() => {
  1737. if (props.multiple) {
  1738. const currentValue = parseModelValue(props.modelValue);
  1739. return currentValue.includes(props.value.toString());
  1740. }
  1741. return props.modelValue === props.value;
  1742. });
  1743. // 切换选中状态
  1744. const toggleSelect = () => {
  1745. // 如果禁用,不执行任何操作
  1746. if (props.disabled) return;
  1747. if (props.multiple) {
  1748. // 多选模式
  1749. const currentValue = parseModelValue(props.modelValue);
  1750. const index = currentValue.indexOf(props.value.toString());
  1751. let newValue;
  1752. if (index === -1) {
  1753. // 添加选项
  1754. newValue = [...currentValue, props.value.toString()];
  1755. } else {
  1756. // 移除选项
  1757. newValue = currentValue.filter((v) => v !== props.value.toString());
  1758. }
  1759. // 发送更新事件,使用逗号分隔的字符串格式
  1760. const emitValue = newValue.join(",");
  1761. emit("update:modelValue", emitValue);
  1762. emit("change", emitValue, newValue);
  1763. } else {
  1764. // 单选模式
  1765. emit("update:modelValue", props.value);
  1766. emit("change", props.value);
  1767. }
  1768. };
  1769. return { isChecked, toggleSelect };
  1770. },
  1771. template: `
  1772. <div class="ss-onoff-button" :class="{ checked: isChecked, disabled: disabled }" @click="toggleSelect">
  1773. <span class="button-label">{{ label }}</span>
  1774. <div class="button-mark">
  1775. <span class="form-icon" :class="isChecked ? 'form-icon-onoffbutton-checked' : 'form-icon-onoffbutton-unchecked'"></span>
  1776. </div>
  1777. </div>
  1778. `,
  1779. };
  1780. // ===== SsDatetimePicker 日期时间选择(使用 Vant 4) =====
  1781. const SsDatetimePicker = {
  1782. name: "SsDatetimePicker",
  1783. props: {
  1784. mode: { type: String, default: "date" }, // date | time | datetime
  1785. placeholder: { type: String, default: "请选择日期" },
  1786. modelValue: { type: String, default: "" },
  1787. minDate: { type: String, default: "" },
  1788. maxDate: { type: String, default: "" },
  1789. // 字段名称 - 用于ssVm校验
  1790. name: { type: String, default: "" },
  1791. // 是否禁用
  1792. disabled: { type: Boolean, default: false },
  1793. },
  1794. emits: [
  1795. "update:modelValue",
  1796. "change",
  1797. "confirm",
  1798. "cancel",
  1799. "open",
  1800. "close",
  1801. ],
  1802. setup(props, { emit }) {
  1803. const showPicker = ref(false);
  1804. const showTimePicker = ref(false);
  1805. const currentStep = ref("date"); // 'date' | 'time'
  1806. // 功能说明:统一在组件层处理 iframe 场景底部按钮显隐,避免每个页面重复绑定 by xu 2026-02-28
  1807. const notifyParentBottomVisible = (visible) => {
  1808. try {
  1809. const fn = window.parent && window.parent.__mpObjInpSetBottomVisible;
  1810. if (typeof fn === "function") fn(visible !== false);
  1811. } catch (_) {}
  1812. };
  1813. // 功能说明:监听弹层显隐,点遮罩/取消关闭时也恢复父层底部按钮 by xu 2026-03-01
  1814. watch(
  1815. [showPicker, showTimePicker],
  1816. ([dateOpen, timeOpen], [prevDateOpen, prevTimeOpen]) => {
  1817. const hasOpen = !!(dateOpen || timeOpen);
  1818. const hadOpen = !!(prevDateOpen || prevTimeOpen);
  1819. if (!hadOpen && hasOpen) {
  1820. emit("open");
  1821. notifyParentBottomVisible(false);
  1822. return;
  1823. }
  1824. if (hadOpen && !hasOpen) {
  1825. emit("close");
  1826. notifyParentBottomVisible(true);
  1827. }
  1828. }
  1829. );
  1830. // Vant DatePicker 需要数组格式 [year, month, day]
  1831. const currentDateArray = ref([]);
  1832. const currentTimeArray = ref(["12", "00"]); // [hour, minute]
  1833. const tempDateStr = ref(""); // 临时存储选择的日期
  1834. // 格式化显示文本
  1835. const displayText = computed(() => {
  1836. if (!props.modelValue) return props.placeholder;
  1837. try {
  1838. const d = new Date(props.modelValue);
  1839. if (isNaN(d.getTime())) return props.modelValue;
  1840. const year = d.getFullYear();
  1841. const month = String(d.getMonth() + 1).padStart(2, "0");
  1842. const day = String(d.getDate()).padStart(2, "0");
  1843. const hours = String(d.getHours()).padStart(2, "0");
  1844. const minutes = String(d.getMinutes()).padStart(2, "0");
  1845. if (props.mode === "time") {
  1846. return `${hours}:${minutes}`;
  1847. } else if (props.mode === "datetime") {
  1848. return `${year}-${month}-${day} ${hours}:${minutes}`;
  1849. }
  1850. return `${year}-${month}-${day}`;
  1851. } catch (e) {
  1852. return props.modelValue;
  1853. }
  1854. });
  1855. // 监听 modelValue 变化,转换为数组格式
  1856. watch(
  1857. () => props.modelValue,
  1858. (newVal) => {
  1859. console.log("📅 modelValue 变化:", newVal);
  1860. if (newVal) {
  1861. try {
  1862. const d = new Date(newVal);
  1863. if (!isNaN(d.getTime())) {
  1864. currentDateArray.value = [
  1865. d.getFullYear(),
  1866. d.getMonth() + 1,
  1867. d.getDate(),
  1868. ];
  1869. console.log("📅 转换为数组:", currentDateArray.value);
  1870. }
  1871. } catch (e) {
  1872. console.warn("Invalid date:", newVal);
  1873. }
  1874. } else {
  1875. const today = new Date();
  1876. currentDateArray.value = [
  1877. today.getFullYear(),
  1878. today.getMonth() + 1,
  1879. today.getDate(),
  1880. ];
  1881. }
  1882. },
  1883. { immediate: true }
  1884. );
  1885. // 确认选择 - 根据模式处理不同的数据
  1886. const onConfirm = (value) => {
  1887. console.log(
  1888. "📅 Vant Picker confirm 原始值:",
  1889. value,
  1890. "mode:",
  1891. props.mode
  1892. );
  1893. try {
  1894. // Vant 返回的是对象,包含 selectedValues 数组
  1895. const selectedValues = value.selectedValues || value;
  1896. console.log("📅 selectedValues:", selectedValues);
  1897. if (props.mode === "time") {
  1898. // 时间模式:处理时分
  1899. if (Array.isArray(selectedValues) && selectedValues.length >= 2) {
  1900. const [hour, minute] = selectedValues;
  1901. const timeStr = `${hour.padStart(2, "0")}:${minute.padStart(
  1902. 2,
  1903. "0"
  1904. )}`;
  1905. console.log("🕐 转换后的时间字符串:", timeStr);
  1906. emit("update:modelValue", timeStr);
  1907. emit("change", timeStr);
  1908. emit("confirm", timeStr);
  1909. emit("close");
  1910. notifyParentBottomVisible(true);
  1911. showPicker.value = false;
  1912. }
  1913. } else if (
  1914. Array.isArray(selectedValues) &&
  1915. selectedValues.length >= 3
  1916. ) {
  1917. // 日期模式:处理年月日
  1918. const [year, month, day] = selectedValues;
  1919. const dateStr = `${year}-${month.padStart(2, "0")}-${day.padStart(
  1920. 2,
  1921. "0"
  1922. )}`;
  1923. if (props.mode === "datetime") {
  1924. // datetime 模式:先存储日期,然后打开时间选择器
  1925. tempDateStr.value = dateStr;
  1926. showPicker.value = false;
  1927. showTimePicker.value = true;
  1928. currentStep.value = "time";
  1929. } else {
  1930. // date 模式:直接完成
  1931. emit("update:modelValue", dateStr);
  1932. emit("change", dateStr);
  1933. emit("confirm", dateStr);
  1934. emit("close");
  1935. notifyParentBottomVisible(true);
  1936. showPicker.value = false;
  1937. }
  1938. }
  1939. } catch (e) {
  1940. console.error("Picker conversion error:", e);
  1941. }
  1942. };
  1943. // 时间选择确认
  1944. const onTimeConfirm = (value) => {
  1945. try {
  1946. const selectedValues = value.selectedValues || value;
  1947. if (Array.isArray(selectedValues) && selectedValues.length >= 2) {
  1948. const [hour, minute] = selectedValues;
  1949. const datetimeStr = `${tempDateStr.value} ${hour.padStart(
  1950. 2,
  1951. "0"
  1952. )}:${minute.padStart(2, "0")}`;
  1953. emit("update:modelValue", datetimeStr);
  1954. emit("change", datetimeStr);
  1955. emit("confirm", datetimeStr);
  1956. emit("close");
  1957. notifyParentBottomVisible(true);
  1958. }
  1959. } catch (e) {
  1960. console.error("Time conversion error:", e);
  1961. }
  1962. showTimePicker.value = false;
  1963. currentStep.value = "date";
  1964. };
  1965. // 取消选择
  1966. const onCancel = () => {
  1967. emit("cancel");
  1968. showPicker.value = false;
  1969. };
  1970. const onTimeCancel = () => {
  1971. emit("cancel");
  1972. showTimePicker.value = false;
  1973. };
  1974. // 打开选择器
  1975. const openPicker = () => {
  1976. // 如果禁用,不打开选择器
  1977. if (props.disabled) return;
  1978. showPicker.value = true;
  1979. };
  1980. // 计算最小最大日期
  1981. const minDateObj = computed(() => {
  1982. return props.minDate ? new Date(props.minDate) : undefined;
  1983. });
  1984. const maxDateObj = computed(() => {
  1985. return props.maxDate ? new Date(props.maxDate) : undefined;
  1986. });
  1987. return {
  1988. showPicker,
  1989. showTimePicker,
  1990. currentDateArray,
  1991. currentTimeArray,
  1992. displayText,
  1993. openPicker,
  1994. onConfirm,
  1995. onTimeConfirm,
  1996. onTimeCancel,
  1997. onCancel,
  1998. minDateObj,
  1999. maxDateObj,
  2000. };
  2001. },
  2002. template: `
  2003. <div class="ss-datetime-picker ss-mobile-component" :class="{ disabled: disabled }">
  2004. <!-- 隐藏的input用于ssVm校验 -->
  2005. <input type="hidden" :name="name" :value="modelValue" />
  2006. <div class="datetime-picker-display" @click="openPicker">
  2007. <span class="datetime-picker-value" :class="{ placeholder: !modelValue }">{{ displayText }}</span>
  2008. </div>
  2009. <!-- 日期选择器 -->
  2010. <van-popup v-model:show="showPicker" position="bottom" :style="{ zIndex: 10000 }">
  2011. <van-date-picker
  2012. v-if="mode === 'date' || mode === 'datetime'"
  2013. v-model="currentDateArray"
  2014. :min-date="minDateObj"
  2015. :max-date="maxDateObj"
  2016. @confirm="onConfirm"
  2017. @cancel="onCancel"
  2018. title="选择日期"
  2019. />
  2020. <van-time-picker
  2021. v-if="mode === 'time'"
  2022. v-model="currentTimeArray"
  2023. @confirm="onConfirm"
  2024. @cancel="onCancel"
  2025. title="选择时间"
  2026. />
  2027. </van-popup>
  2028. <!-- 时间选择器(datetime 模式的第二步) -->
  2029. <van-popup v-model:show="showTimePicker" position="bottom" :style="{ zIndex: 10000 }">
  2030. <van-time-picker
  2031. v-model="currentTimeArray"
  2032. @confirm="onTimeConfirm"
  2033. @cancel="onTimeCancel"
  2034. title="选择时间"
  2035. />
  2036. </van-popup>
  2037. </div>
  2038. `,
  2039. };
  2040. const SsConfirm = {
  2041. name: "SsConfirm",
  2042. props: {
  2043. modelValue: { type: Boolean, default: false },
  2044. title: { type: String, default: "确认" },
  2045. content: { type: String, default: "" },
  2046. maskClosable: { type: Boolean, default: true },
  2047. },
  2048. emits: ["update:modelValue", "confirm", "cancel", "close"],
  2049. setup(props, { emit }) {
  2050. // 监听弹窗显示状态,控制 body 滚动
  2051. watch(
  2052. () => props.modelValue,
  2053. (newVal) => {
  2054. console.log("🔔 SsConfirm modelValue 变化:", newVal);
  2055. if (newVal) {
  2056. document.body.classList.add("modal-open");
  2057. } else {
  2058. document.body.classList.remove("modal-open");
  2059. }
  2060. },
  2061. { immediate: true }
  2062. ); // 添加 immediate 选项
  2063. const close = () => {
  2064. console.log("🚪 关闭确认弹窗");
  2065. emit("update:modelValue", false);
  2066. emit("close");
  2067. };
  2068. const onMask = () => {
  2069. console.log("👆 点击了遮罩层");
  2070. if (props.maskClosable) close();
  2071. };
  2072. const onCancel = () => {
  2073. console.log("❌ 点击了取消按钮");
  2074. emit("cancel");
  2075. close();
  2076. };
  2077. const onConfirm = () => {
  2078. console.log("✅ 点击了确认按钮,触发 confirm 事件");
  2079. emit("confirm");
  2080. close();
  2081. };
  2082. return { onMask, onCancel, onConfirm };
  2083. },
  2084. template: `
  2085. <div v-if="modelValue" class="ss-confirm">
  2086. <div class="confirm-mask" @click="onMask"></div>
  2087. <div class="confirm-content">
  2088. <div class="confirm-header" v-if="title">
  2089. <div class="header-title">{{ title }}</div>
  2090. </div>
  2091. <div class="header-line" v-if="title"></div>
  2092. <div class="confirm-body">
  2093. <div v-if="content" class="confirm-content-text" v-html="content"></div>
  2094. <div class="confirm-slot-content"><slot /></div>
  2095. </div>
  2096. <div class="confirm-bottom">
  2097. <button class="confirm-btn confirm-btn-cancel" @click.stop="onCancel">取消</button>
  2098. <button class="confirm-btn confirm-btn-confirm" @click.stop="onConfirm">确认</button>
  2099. </div>
  2100. </div>
  2101. </div>
  2102. `,
  2103. };
  2104. // ===== SsImageCropper 纯裁剪组件 =====
  2105. const SsImageCropper = {
  2106. name: "SsImageCropper",
  2107. props: {
  2108. // 是否显示裁剪器
  2109. show: { type: Boolean, default: false },
  2110. // 图片源(base64 或 URL)
  2111. src: { type: String, required: true },
  2112. // 图片形状:circle圆形 | square方形
  2113. shape: { type: String, required: true },
  2114. // 裁剪比例(宽/高)
  2115. aspectRatio: { type: Number, default: 1 },
  2116. // 输出图片宽度
  2117. outputWidth: { type: Number, default: 300 },
  2118. // 输出图片高度
  2119. outputHeight: { type: Number, default: 300 },
  2120. },
  2121. emits: ["update:show", "confirm", "cancel"],
  2122. setup(props, { emit }) {
  2123. const cropperInstance = ref(null);
  2124. // 监听 show 变化,初始化或销毁 Cropper
  2125. watch(
  2126. () => props.show,
  2127. (newVal) => {
  2128. if (newVal) {
  2129. // 等待 DOM 更新后初始化
  2130. Vue.nextTick(() => {
  2131. initCropper().catch((error) => {
  2132. console.error("图片裁剪组件初始化失败:", error);
  2133. });
  2134. });
  2135. } else {
  2136. destroyCropper();
  2137. }
  2138. }
  2139. );
  2140. // 监听 src 变化,重新初始化 Cropper
  2141. watch(
  2142. () => props.src,
  2143. () => {
  2144. if (props.show) {
  2145. Vue.nextTick(() => {
  2146. initCropper().catch((error) => {
  2147. console.error("图片裁剪组件重新初始化失败:", error);
  2148. });
  2149. });
  2150. }
  2151. }
  2152. );
  2153. // 初始化 Cropper
  2154. const initCropper = async () => {
  2155. if (!window.Cropper) {
  2156. await ensureOptionalAssets("cropper");
  2157. }
  2158. const imageElement = document.getElementById("ss-image-cropper-img");
  2159. if (!imageElement || !window.Cropper) return;
  2160. // 销毁旧实例
  2161. destroyCropper();
  2162. // 根据 shape 属性添加类名
  2163. const container = document.querySelector(".ss-image-cropper-container");
  2164. if (container) {
  2165. if (props.shape === "circle") {
  2166. container.classList.add("crop-shape-circle");
  2167. container.classList.remove("crop-shape-square");
  2168. } else {
  2169. container.classList.add("crop-shape-square");
  2170. container.classList.remove("crop-shape-circle");
  2171. }
  2172. }
  2173. cropperInstance.value = new window.Cropper(imageElement, {
  2174. aspectRatio: props.aspectRatio,
  2175. viewMode: 1,
  2176. dragMode: "move",
  2177. autoCropArea: 0.8,
  2178. restore: false,
  2179. guides: false, // 关闭辅助线
  2180. center: false, // 关闭中心指示器
  2181. highlight: false,
  2182. cropBoxMovable: true,
  2183. cropBoxResizable: true,
  2184. toggleDragModeOnDblclick: false,
  2185. minContainerWidth: window.innerWidth,
  2186. minContainerHeight: window.innerHeight - 50,
  2187. });
  2188. };
  2189. // 销毁 Cropper
  2190. const destroyCropper = () => {
  2191. if (cropperInstance.value) {
  2192. cropperInstance.value.destroy();
  2193. cropperInstance.value = null;
  2194. }
  2195. };
  2196. // 取消裁剪
  2197. const handleCancel = () => {
  2198. emit("update:show", false);
  2199. emit("cancel");
  2200. };
  2201. // 确认裁剪
  2202. const handleConfirm = () => {
  2203. if (!cropperInstance.value) return;
  2204. const canvas = cropperInstance.value.getCroppedCanvas({
  2205. width: props.outputWidth,
  2206. height: props.outputHeight,
  2207. imageSmoothingEnabled: true,
  2208. imageSmoothingQuality: "high",
  2209. fillColor: "#fff",
  2210. });
  2211. canvas.toBlob(
  2212. (blob) => {
  2213. emit("update:show", false);
  2214. emit("confirm", blob);
  2215. },
  2216. "image/jpeg",
  2217. 0.9
  2218. );
  2219. };
  2220. // 处理底部按钮事件
  2221. const handleCropAction = (data) => {
  2222. if (data.action === "cancel") {
  2223. handleCancel();
  2224. } else if (data.action === "confirm") {
  2225. handleConfirm();
  2226. }
  2227. };
  2228. return {
  2229. handleCropAction,
  2230. };
  2231. },
  2232. template: `
  2233. <div v-if="show" class="ss-image-cropper-container">
  2234. <!-- 左上角尺寸显示 -->
  2235. <div class="crop-size-display">
  2236. 长: {{ outputWidth }}px<br>宽: {{ outputHeight }}px
  2237. </div>
  2238. <div class="ss-crop-image-container">
  2239. <img id="ss-image-cropper-img" :src="src" />
  2240. </div>
  2241. <!-- 使用 ss-bottom 组件 -->
  2242. <ss-bottom
  2243. :show-shyj="false"
  2244. :buttons="[
  2245. { text: '取消', action: 'cancel' },
  2246. { text: '保存并提交', action: 'confirm' }
  2247. ]"
  2248. @button-click="handleCropAction"
  2249. />
  2250. </div>
  2251. `,
  2252. };
  2253. // ===== SsUploadImage 图片上传裁剪组件(支持单图/多图) =====
  2254. const SsUploadImage = {
  2255. name: "SsUploadImage",
  2256. props: {
  2257. // v-model 绑定的值(单图:String,多图:Array)
  2258. modelValue: { type: [String, Array], default: "" },
  2259. // 最大上传数量(默认1张,多图时设置大于1)
  2260. max: { type: Number, default: 1 },
  2261. // 是否禁用
  2262. disabled: { type: Boolean, default: false },
  2263. // 图片宽度(像素) - 必填
  2264. width: { type: [Number, String], required: true },
  2265. // 图片高度(像素) - 必填
  2266. height: { type: [Number, String], required: true },
  2267. // 图片形状:circle圆形 | square方形 - 必填
  2268. shape: { type: String, required: true },
  2269. // 裁剪比例(宽/高)
  2270. aspectRatio: { type: Number, default: undefined },
  2271. // 输出图片宽度
  2272. outputWidth: { type: Number, default: 300 },
  2273. // 输出图片高度
  2274. outputHeight: { type: Number, default: 300 },
  2275. },
  2276. emits: ["update:modelValue", "updated"],
  2277. setup(props, { emit }) {
  2278. const showCropper = ref(false);
  2279. const tempImageSrc = ref("");
  2280. // 图片列表(统一用数组管理)
  2281. const imageList = ref([]);
  2282. // 监听 modelValue 变化,同步到 imageList
  2283. watch(
  2284. () => props.modelValue,
  2285. (newVal) => {
  2286. if (props.max === 1) {
  2287. // 单图模式
  2288. imageList.value = newVal ? [newVal] : [];
  2289. } else {
  2290. // 多图模式
  2291. imageList.value = Array.isArray(newVal)
  2292. ? [...newVal]
  2293. : newVal
  2294. ? [newVal]
  2295. : [];
  2296. }
  2297. },
  2298. { immediate: true }
  2299. );
  2300. // 是否可以继续添加图片
  2301. const canAddMore = computed(() => {
  2302. return imageList.value.length < props.max;
  2303. });
  2304. // 容器样式
  2305. const itemStyle = computed(() => ({
  2306. width:
  2307. typeof props.width === "number" ? `${props.width}px` : props.width,
  2308. height:
  2309. typeof props.height === "number" ? `${props.height}px` : props.height,
  2310. borderRadius: props.shape === "circle" ? "50%" : "8px",
  2311. }));
  2312. // 获取图片 URL(用于显示)
  2313. const getImageUrl = (path) => {
  2314. if (!path) return "/static/images/yishuzhao_nv.svg";
  2315. if (path.startsWith("http") || path.startsWith("blob:")) {
  2316. return path;
  2317. }
  2318. return window.SS.utils?.getImageUrl?.(path) || path;
  2319. };
  2320. // 选择图片
  2321. const selectImage = () => {
  2322. if (props.disabled || !canAddMore.value) return;
  2323. const input = document.createElement("input");
  2324. input.type = "file";
  2325. input.accept = "image/*";
  2326. input.onchange = (e) => {
  2327. const file = e.target.files[0];
  2328. if (file) {
  2329. const reader = new FileReader();
  2330. reader.onload = (event) => {
  2331. tempImageSrc.value = event.target.result;
  2332. showCropper.value = true;
  2333. };
  2334. reader.readAsDataURL(file);
  2335. }
  2336. };
  2337. input.click();
  2338. };
  2339. // 删除图片
  2340. const deleteImage = (index) => {
  2341. const newList = imageList.value.filter((_, i) => i !== index);
  2342. updateModelValue(newList);
  2343. };
  2344. // 确认裁剪
  2345. const handleCropConfirm = async (blob) => {
  2346. try {
  2347. const serverPath = await uploadFile(blob, "image", "image.jpg");
  2348. const newList = [...imageList.value, serverPath];
  2349. updateModelValue(newList);
  2350. emit("updated", serverPath);
  2351. } catch (error) {
  2352. console.error("上传失败:", error);
  2353. }
  2354. };
  2355. // 取消裁剪
  2356. const handleCropCancel = () => {
  2357. tempImageSrc.value = "";
  2358. };
  2359. // 更新 modelValue
  2360. const updateModelValue = (list) => {
  2361. if (props.max === 1) {
  2362. // 单图模式:返回 String
  2363. emit("update:modelValue", list[0] || "");
  2364. } else {
  2365. // 多图模式:返回 Array
  2366. emit("update:modelValue", list);
  2367. }
  2368. };
  2369. return {
  2370. imageList,
  2371. canAddMore,
  2372. itemStyle,
  2373. showCropper,
  2374. tempImageSrc,
  2375. getImageUrl,
  2376. selectImage,
  2377. deleteImage,
  2378. handleCropConfirm,
  2379. handleCropCancel,
  2380. };
  2381. },
  2382. template: `
  2383. <div class="ss-upload-image-multi">
  2384. <!-- 图片列表 -->
  2385. <div class="image-list">
  2386. <!-- 已上传的图片 -->
  2387. <div
  2388. v-for="(img, index) in imageList"
  2389. :key="index"
  2390. class="image-item"
  2391. :style="itemStyle"
  2392. >
  2393. <img :src="getImageUrl(img)" class="image-display" />
  2394. <!-- 删除按钮 -->
  2395. <div v-if="!disabled" class="image-delete" @click.stop="deleteImage(index)">
  2396. <Icon name="icon-guanbi" size="32" color="#fff" />
  2397. </div>
  2398. </div>
  2399. <!-- 添加按钮 -->
  2400. <div
  2401. v-if="canAddMore && !disabled"
  2402. class="image-item image-add"
  2403. :style="itemStyle"
  2404. @click="selectImage"
  2405. >
  2406. <Icon name="icon-xiangji" size="48" color="#ccc" />
  2407. <div class="add-text">{{ imageList.length }}/{{ max }}</div>
  2408. </div>
  2409. </div>
  2410. <!-- 裁剪组件 -->
  2411. <ss-image-cropper
  2412. v-model:show="showCropper"
  2413. :src="tempImageSrc"
  2414. :shape="shape"
  2415. :aspect-ratio="aspectRatio"
  2416. :output-width="outputWidth"
  2417. :output-height="outputHeight"
  2418. @confirm="handleCropConfirm"
  2419. @cancel="handleCropCancel"
  2420. />
  2421. </div>
  2422. `,
  2423. };
  2424. // ===== SsCarCard 车辆卡片组件 =====
  2425. const SsCarCard = {
  2426. name: "SsCarCard",
  2427. props: {
  2428. // 车辆数据
  2429. carData: {
  2430. type: Object,
  2431. default: () => ({}),
  2432. },
  2433. // 车辆状态:'available' | 'reserved' | 'disabled'
  2434. status: {
  2435. type: String,
  2436. default: "available",
  2437. validator: (value) =>
  2438. ["available", "reserved", "disabled"].includes(value),
  2439. },
  2440. },
  2441. emits: ["click", "select"],
  2442. setup(props, { emit }) {
  2443. // 计算状态样式类
  2444. const statusClass = computed(() => {
  2445. return `status-${props.status}`;
  2446. });
  2447. // 获取图片URL
  2448. const getImageUrl = (path) => {
  2449. if (!path) return "/static/images/default-car.png";
  2450. if (path.startsWith("http") || path.startsWith("blob:")) {
  2451. return path;
  2452. }
  2453. return window.SS.utils?.getImageUrl?.(path) || path;
  2454. };
  2455. // 处理卡片点击
  2456. const handleCardClick = () => {
  2457. if (props.status === "disabled") {
  2458. return; // 禁用状态不响应点击
  2459. }
  2460. emit("click", props.carData);
  2461. emit("select", props.carData);
  2462. };
  2463. return {
  2464. statusClass,
  2465. getImageUrl,
  2466. handleCardClick,
  2467. };
  2468. },
  2469. template: `
  2470. <div class="car-card" :class="statusClass" @click="handleCardClick">
  2471. <!-- 第一行:车辆名称 -->
  2472. <div class="car-title">
  2473. {{ carData.name || '别克GL8' }}
  2474. </div>
  2475. <!-- 第二行:左右结构 -->
  2476. <div class="car-info">
  2477. <!-- 左边:车辆图片 -->
  2478. <div class="car-image-container">
  2479. <img class="car-image" :src="getImageUrl(carData.image)" />
  2480. </div>
  2481. <!-- 右边:车辆信息 -->
  2482. <div class="car-details">
  2483. <div class="detail-item car-name" v-if="carData.wph">
  2484. {{ carData.wph }}
  2485. </div>
  2486. <div class="detail-item seats" v-for="(wp, index) in carData.wpcsList" :key="index">
  2487. {{ wp.mc }} : {{ wp.sz || wp.zf }}
  2488. </div>
  2489. <div class="detail-item car-type">
  2490. {{ carData.type || '商务车' }}
  2491. </div>
  2492. </div>
  2493. </div>
  2494. </div>
  2495. `,
  2496. };
  2497. // ===== SsSubTab 移动端Tab组件 =====
  2498. const SsSubTab = {
  2499. name: "SsSubTab",
  2500. props: {
  2501. // Tab列表数据
  2502. tabList: {
  2503. type: Array,
  2504. required: true,
  2505. },
  2506. // 当前激活的Tab索引
  2507. activeIndex: {
  2508. type: Number,
  2509. default: 0,
  2510. },
  2511. // 基础URL参数(会传递给每个iframe)
  2512. baseParams: {
  2513. type: Object,
  2514. default: () => ({}),
  2515. },
  2516. },
  2517. emits: ["tab-change"],
  2518. setup(props, { emit }) {
  2519. const currentTab = ref(props.activeIndex);
  2520. const currentTabUrl = ref("");
  2521. // 加载Tab对应的URL
  2522. const loadTabUrl = (index) => {
  2523. const tab = props.tabList[index];
  2524. if (!tab || !tab.dest) return;
  2525. // 构建iframe URL:mp_ + dest + .html
  2526. const fileName = `mp_${tab.dest}.html`;
  2527. // 构建完整URL,包含所有参数
  2528. const tabService =
  2529. tab.service ||
  2530. tab.servName ||
  2531. props.baseParams.service ||
  2532. props.baseParams.ssServ ||
  2533. "";
  2534. const tabDest =
  2535. tab.dest || props.baseParams.dest || props.baseParams.ssDest || "";
  2536. const tabParam =
  2537. tab.param ||
  2538. tab.parm ||
  2539. props.baseParams.param ||
  2540. props.baseParams.parm ||
  2541. "";
  2542. const params = new URLSearchParams({
  2543. ...props.baseParams,
  2544. service: tabService,
  2545. dest: tabDest,
  2546. ssServ: tabService,
  2547. ssDest: tabDest,
  2548. param: tabParam,
  2549. parm: tabParam,
  2550. });
  2551. currentTabUrl.value = `/page/${fileName}?${params.toString()}`;
  2552. console.log(
  2553. "🔄 切换到Tab:",
  2554. tab.desc || tab.title,
  2555. "加载页面:",
  2556. currentTabUrl.value
  2557. );
  2558. };
  2559. // 监听 activeIndex 变化
  2560. watch(
  2561. () => props.activeIndex,
  2562. (newIndex) => {
  2563. currentTab.value = newIndex;
  2564. loadTabUrl(newIndex);
  2565. },
  2566. { immediate: true }
  2567. );
  2568. // 监听 tabList 变化
  2569. watch(
  2570. () => props.tabList,
  2571. () => {
  2572. if (props.tabList.length > 0 && currentTab.value === 0) {
  2573. loadTabUrl(0);
  2574. }
  2575. },
  2576. { immediate: true }
  2577. );
  2578. // 切换Tab
  2579. const handleTabClick = (index) => {
  2580. if (currentTab.value === index) return;
  2581. currentTab.value = index;
  2582. loadTabUrl(index);
  2583. emit("tab-change", { index, tab: props.tabList[index] });
  2584. };
  2585. return {
  2586. currentTab,
  2587. currentTabUrl,
  2588. handleTabClick,
  2589. };
  2590. },
  2591. template: `
  2592. <div class="ss-sub-tab">
  2593. <!-- Tab 栏 -->
  2594. <div class="ss-sub-tab__bar" v-if="tabList.length > 0">
  2595. <div
  2596. v-for="(tab, index) in tabList"
  2597. :key="index"
  2598. class="ss-sub-tab__item"
  2599. :class="{ 'ss-sub-tab__item--active': currentTab === index }"
  2600. @click="handleTabClick(index)"
  2601. >
  2602. {{ tab.desc || tab.title }}
  2603. </div>
  2604. </div>
  2605. <!-- 内容区域 -->
  2606. <div class="ss-sub-tab__content" v-if="currentTabUrl">
  2607. <iframe :src="currentTabUrl" frameborder="0"></iframe>
  2608. </div>
  2609. </div>
  2610. `,
  2611. };
  2612. // ===== SsUploadFile 文件上传组件(支持单文件/多文件) =====
  2613. const SsUploadFile = {
  2614. name: "SsUploadFile",
  2615. props: {
  2616. // v-model 绑定的值(单文件:String,多文件:Array)
  2617. modelValue: { type: [String, Array], default: "" },
  2618. // 最大上传数量(默认1个)
  2619. max: { type: Number, default: 1 },
  2620. // 是否禁用
  2621. disabled: { type: Boolean, default: false },
  2622. // 允许的文件类型(默认常见文件类型)
  2623. accept: {
  2624. type: String,
  2625. default: ".pdf,.doc,.docx,.xls,.xlsx,.txt,.zip,.rar",
  2626. },
  2627. // 最大文件大小(MB,默认5MB)
  2628. maxSize: { type: Number, default: 5 },
  2629. },
  2630. emits: ["update:modelValue", "uploaded"],
  2631. setup(props, { emit }) {
  2632. // 文件列表(统一用数组管理)
  2633. const fileList = ref([]);
  2634. // 监听 modelValue 变化,同步到 fileList
  2635. watch(
  2636. () => props.modelValue,
  2637. (newVal) => {
  2638. if (props.max === 1) {
  2639. // 单文件模式
  2640. fileList.value = newVal
  2641. ? [{ path: newVal, name: getFileName(newVal) }]
  2642. : [];
  2643. } else {
  2644. // 多文件模式
  2645. if (Array.isArray(newVal)) {
  2646. fileList.value = newVal.map((path) => ({
  2647. path,
  2648. name: getFileName(path),
  2649. }));
  2650. } else {
  2651. fileList.value = newVal
  2652. ? [{ path: newVal, name: getFileName(newVal) }]
  2653. : [];
  2654. }
  2655. }
  2656. },
  2657. { immediate: true }
  2658. );
  2659. // 是否可以继续添加文件
  2660. const canAddMore = computed(() => {
  2661. return fileList.value.length < props.max;
  2662. });
  2663. // 从路径中提取文件名
  2664. const getFileName = (path) => {
  2665. if (!path) return "";
  2666. const parts = path.split("/");
  2667. return parts[parts.length - 1];
  2668. };
  2669. // 获取文件图标
  2670. const getFileIcon = (fileName) => {
  2671. const ext = fileName.split(".").pop().toLowerCase();
  2672. const iconMap = {
  2673. pdf: "icon-pdf",
  2674. doc: "icon-word",
  2675. docx: "icon-word",
  2676. xls: "icon-excel",
  2677. xlsx: "icon-excel",
  2678. txt: "icon-txt",
  2679. zip: "icon-zip",
  2680. rar: "icon-zip",
  2681. };
  2682. return iconMap[ext] || "icon-wenjian";
  2683. };
  2684. // 选择文件
  2685. const selectFile = () => {
  2686. if (props.disabled || !canAddMore.value) return;
  2687. const input = document.createElement("input");
  2688. input.type = "file";
  2689. input.accept = props.accept;
  2690. input.onchange = async (e) => {
  2691. const file = e.target.files[0];
  2692. if (!file) return;
  2693. // 检查文件大小
  2694. const fileSizeMB = file.size / 1024 / 1024;
  2695. if (fileSizeMB > props.maxSize) {
  2696. window.showToast?.(`文件大小不能超过${props.maxSize}MB`, "error");
  2697. return;
  2698. }
  2699. // 上传文件
  2700. try {
  2701. const serverPath = await uploadFile(file, "file", file.name);
  2702. const newList = [
  2703. ...fileList.value,
  2704. { path: serverPath, name: file.name },
  2705. ];
  2706. updateModelValue(newList);
  2707. emit("uploaded", serverPath);
  2708. } catch (error) {
  2709. console.error("文件上传失败:", error);
  2710. }
  2711. };
  2712. input.click();
  2713. };
  2714. // 删除文件
  2715. const deleteFile = (index) => {
  2716. const newList = fileList.value.filter((_, i) => i !== index);
  2717. updateModelValue(newList);
  2718. };
  2719. // 下载文件
  2720. const downloadFile = (file) => {
  2721. const url =
  2722. window.SS.utils?.getFileUrl?.(file.path) ||
  2723. window.getFileUrl?.(file.path) ||
  2724. file.path;
  2725. window.open(url, "_blank");
  2726. };
  2727. // 更新 modelValue
  2728. const updateModelValue = (list) => {
  2729. const paths = list.map((f) => f.path);
  2730. if (props.max === 1) {
  2731. // 单文件模式:返回 String
  2732. emit("update:modelValue", paths[0] || "");
  2733. } else {
  2734. // 多文件模式:返回 Array
  2735. emit("update:modelValue", paths);
  2736. }
  2737. };
  2738. return {
  2739. fileList,
  2740. canAddMore,
  2741. getFileIcon,
  2742. selectFile,
  2743. deleteFile,
  2744. downloadFile,
  2745. };
  2746. },
  2747. template: `
  2748. <div class="ss-upload-file">
  2749. <!-- 文件列表 -->
  2750. <div v-if="fileList.length > 0" class="file-list">
  2751. <!-- 已上传的文件 -->
  2752. <div
  2753. v-for="(file, index) in fileList"
  2754. :key="index"
  2755. class="file-item"
  2756. >
  2757. <div class="file-icon">
  2758. <Icon :name="getFileIcon(file.name)" size="40" color="#40ac6d" />
  2759. </div>
  2760. <div class="file-info" @click="downloadFile(file)">
  2761. <span class="file-name">{{ file.name }}</span>
  2762. </div>
  2763. <!-- 文件操作按钮 -->
  2764. <div class="file-actions">
  2765. <div class="file-download" @click="downloadFile(file)">
  2766. <Icon name="icon-xiazai" size="32" color="#40ac6d" />
  2767. </div>
  2768. <div v-if="!disabled" class="file-delete" @click.stop="deleteFile(index)">
  2769. <Icon name="icon-guanbi" size="32" color="#ff3b30" />
  2770. </div>
  2771. </div>
  2772. </div>
  2773. </div>
  2774. <!-- 添加按钮 -->
  2775. <div
  2776. v-if="canAddMore && !disabled"
  2777. class="file-add-button"
  2778. @click="selectFile"
  2779. >
  2780. <div class="add-icon">
  2781. <Icon name="icon-tianjia" size="64" color="#999" />
  2782. </div>
  2783. <span class="add-text">上传文件 ({{ fileList.length }}/{{ max }})</span>
  2784. <span class="file-tip">支持格式: {{ accept }},最大{{ maxSize }}MB</span>
  2785. </div>
  2786. </div>
  2787. `,
  2788. };
  2789. /**
  2790. * 功能说明:H5移动端富文本组件(对齐PC字段协议 mswj/fjid/path 回显) by xu 2026-03-01
  2791. *
  2792. * 约定:
  2793. * - v-model 绑定文件路径字段(如 mswj)
  2794. * - 组件内部维护编辑内容,并输出隐藏字段:xxEdit / xxwj / ueditorpath / fjid
  2795. * - 回显通过 url + path 拉取 HTML 内容,不直接依赖 modelValue 的 HTML 字符串
  2796. *
  2797. * @component SsEditor
  2798. * @prop {String} modelValue 文件路径(如 mswj)
  2799. * @prop {String} name 字段名(默认 mswj)
  2800. * @prop {String} url 回显读取接口地址
  2801. * @prop {Number|String} height 编辑器高度
  2802. * @prop {String} placeholder 占位文案
  2803. * @prop {Boolean} readonly 是否只读
  2804. * @prop {String} uploadUrl 上传接口地址
  2805. * @prop {Object} param 附件参数(button.cmsAddUrl / button.cmsUpdUrl / mode)
  2806. * @emits update:modelValue 更新文件路径
  2807. * @emits ready 编辑器就绪
  2808. * @emits change 内容变化
  2809. */
  2810. const SsEditor = {
  2811. name: "SsEditor",
  2812. props: {
  2813. modelValue: { type: String, default: "" },
  2814. name: { type: String, default: "mswj" },
  2815. url: { type: String, default: "" },
  2816. height: { type: [Number, String], default: 280 },
  2817. placeholder: { type: String, default: "请输入内容" },
  2818. readonly: { type: Boolean, default: false },
  2819. uploadUrl: { type: String, default: "/service?ssServ=ulByHttp" },
  2820. param: { type: Object, default: () => ({}) },
  2821. },
  2822. emits: ["update:modelValue", "ready", "change"],
  2823. setup(props, { emit }) {
  2824. const editorElementId = `ss-editor-${Date.now()}-${Math.floor(
  2825. Math.random() * 10000
  2826. )}`;
  2827. const editorContent = ref("");
  2828. const editorInstance = ref(null);
  2829. const fjid = ref(props.param?.button?.val || "");
  2830. const fjName = props.param?.button?.desc || "附件";
  2831. const mode = props.param?.mode;
  2832. /**
  2833. * 功能说明:确保附件 fjid 存在,不存在时先通过 cmsAddUrl 创建 by xu 2026-03-01
  2834. * @returns {Promise<string>} fjid
  2835. */
  2836. const ensureFjid = async () => {
  2837. if (fjid.value) return fjid.value;
  2838. if (!props.param?.button?.cmsAddUrl) return "";
  2839. return new Promise((resolve) => {
  2840. $.ajax({
  2841. type: "post",
  2842. url: props.param.button.cmsAddUrl,
  2843. async: false,
  2844. data: {
  2845. name: "fjid",
  2846. ssNrObjName: "sh",
  2847. ssNrObjId: "",
  2848. },
  2849. success: (_fjid) => {
  2850. fjid.value = _fjid || "";
  2851. resolve(fjid.value);
  2852. },
  2853. error: () => resolve(""),
  2854. });
  2855. });
  2856. };
  2857. /**
  2858. * 功能说明:打开附件管理弹窗(与PC端行为一致) by xu 2026-03-01
  2859. * @returns {Promise<void>}
  2860. */
  2861. const openAttachmentDialog = async () => {
  2862. if (!props.param?.button?.cmsUpdUrl) {
  2863. console.warn("未配置附件编辑地址 cmsUpdUrl");
  2864. return;
  2865. }
  2866. const currentFjid = await ensureFjid();
  2867. if (!currentFjid) return;
  2868. const query =
  2869. `&nrid=T-${currentFjid}` +
  2870. `&objectId=${currentFjid}` +
  2871. `&objectName=${encodeURIComponent(fjName)}` +
  2872. `&callback=${window["fjidCallbackName"] || ""}`;
  2873. if (window.SS && typeof window.SS.openDialog === "function") {
  2874. window.SS.openDialog({
  2875. src: props.param.button.cmsUpdUrl + query,
  2876. headerTitle: "编辑",
  2877. width: 900,
  2878. high: 664,
  2879. zIndex: 51,
  2880. });
  2881. }
  2882. };
  2883. /**
  2884. * 功能说明:初始化 Jodit 编辑器并绑定工具栏/上传/change 事件 by xu 2026-03-01
  2885. * @returns {void}
  2886. */
  2887. const buildEditor = async () => {
  2888. if (!window.Jodit || !window.Jodit.make) {
  2889. await ensureOptionalAssets("jodit");
  2890. }
  2891. if (!window.Jodit || !window.Jodit.make) {
  2892. console.error("Jodit 未加载,无法初始化 ss-editor");
  2893. return;
  2894. }
  2895. const editorUploadUrl = props.uploadUrl.includes("?")
  2896. ? `${props.uploadUrl}&type=img`
  2897. : `${props.uploadUrl}?type=img`;
  2898. const instance = window.Jodit.make(`#${editorElementId}`, {
  2899. height: props.height,
  2900. placeholder: props.placeholder,
  2901. readonly: props.readonly,
  2902. language: "zh_cn",
  2903. showXPathInStatusbar: false,
  2904. showCharsCounter: false,
  2905. showWordsCounter: false,
  2906. allowResizeY: false,
  2907. toolbarSticky: false,
  2908. statusbar: false,
  2909. uploader: {
  2910. url: editorUploadUrl,
  2911. format: "json",
  2912. method: "POST",
  2913. filesVariableName: (i) => `imgs[${i}]`,
  2914. isSuccess: (resp) => resp?.code === 0 || !!resp?.data,
  2915. getMessage: (resp) => resp?.msg || "上传失败",
  2916. process: (resp) => resp?.data?.url || resp?.data?.path || "",
  2917. contentType: () => false,
  2918. },
  2919. controls: {
  2920. customLinkButton: {
  2921. name: "link",
  2922. tooltip: "附件",
  2923. exec: () => {
  2924. openAttachmentDialog();
  2925. },
  2926. },
  2927. },
  2928. buttons: [
  2929. "fullsize",
  2930. "bold",
  2931. "italic",
  2932. "underline",
  2933. "|",
  2934. "font",
  2935. "fontsize",
  2936. "|",
  2937. "left",
  2938. "center",
  2939. "right",
  2940. "|",
  2941. "ul",
  2942. "ol",
  2943. "|",
  2944. "image",
  2945. "table",
  2946. "customLinkButton",
  2947. "|",
  2948. "undo",
  2949. "redo",
  2950. ],
  2951. buttonsMD: [
  2952. "bold",
  2953. "italic",
  2954. "underline",
  2955. "|",
  2956. "image",
  2957. "customLinkButton",
  2958. "|",
  2959. "dots",
  2960. ],
  2961. buttonsSM: [
  2962. "bold",
  2963. "italic",
  2964. "|",
  2965. "image",
  2966. "customLinkButton",
  2967. "|",
  2968. "dots",
  2969. ],
  2970. buttonsXS: ["bold", "|", "dots"],
  2971. });
  2972. instance.value = editorContent.value || "";
  2973. instance.events.on("change", () => {
  2974. editorContent.value = instance.value || "";
  2975. emit("change", editorContent.value);
  2976. });
  2977. editorInstance.value = instance;
  2978. emit("ready", instance);
  2979. };
  2980. /**
  2981. * 功能说明:按路径加载富文本HTML内容并回填编辑器 by xu 2026-03-01
  2982. * @returns {Promise<void>}
  2983. */
  2984. const loadContentByPath = async () => {
  2985. if (!props.url || !props.modelValue) return;
  2986. try {
  2987. const params = new URLSearchParams();
  2988. if (mode) params.append("mode", mode);
  2989. params.append("path", props.modelValue);
  2990. const response = await window.axios.post(props.url, params, {
  2991. headers: { "Content-Type": "application/x-www-form-urlencoded" },
  2992. });
  2993. const content = response?.data?.content || "";
  2994. if (content) {
  2995. editorContent.value = content;
  2996. if (editorInstance.value) {
  2997. editorInstance.value.value = content;
  2998. }
  2999. }
  3000. const filePath = response?.data?.path;
  3001. if (filePath) {
  3002. emit("update:modelValue", filePath);
  3003. }
  3004. } catch (error) {
  3005. console.error("ss-editor 回显内容加载失败:", error);
  3006. }
  3007. };
  3008. onMounted(async () => {
  3009. try {
  3010. await buildEditor();
  3011. } catch (error) {
  3012. console.error("ss-editor 初始化失败:", error);
  3013. }
  3014. await loadContentByPath();
  3015. });
  3016. watch(
  3017. () => props.readonly,
  3018. (newVal) => {
  3019. if (
  3020. editorInstance.value &&
  3021. typeof editorInstance.value.setReadOnly === "function"
  3022. ) {
  3023. editorInstance.value.setReadOnly(newVal);
  3024. }
  3025. }
  3026. );
  3027. onBeforeUnmount(() => {
  3028. if (
  3029. editorInstance.value &&
  3030. typeof editorInstance.value.destruct === "function"
  3031. ) {
  3032. editorInstance.value.destruct();
  3033. }
  3034. });
  3035. return {
  3036. editorElementId,
  3037. editorContent,
  3038. fjid,
  3039. };
  3040. },
  3041. template: `
  3042. <div class="ss-editor-container">
  3043. <input v-if="fjid" type="hidden" name="fjid" :value="fjid" />
  3044. <input type="hidden" :name="name.replace(/wj$/, '') + 'Edit'" :value="editorContent" />
  3045. <input type="hidden" :name="name.replace(/wj$/, '') + 'wj'" :value="modelValue" />
  3046. <input type="hidden" name="ueditorpath" value="mswj" />
  3047. <textarea :id="editorElementId"></textarea>
  3048. </div>
  3049. `,
  3050. };
  3051. window.SS.dom.initializeFormApp = function (config) {
  3052. const { el, ...vueOptions } = config;
  3053. const app = createApp({
  3054. ...vueOptions,
  3055. });
  3056. // 注册组件
  3057. // app.component("SsLoginIcon", SsLoginIcon);
  3058. // app.component("SsMark", SsMark);
  3059. // app.component("SsFullStyleHeader", SsFullStyleHeader);
  3060. // app.component("SsDialog", SsDialog);
  3061. app.component("SsInput", SsInput);
  3062. app.component("SsBottom", SsBottom);
  3063. app.component("SsCard", SsCard);
  3064. app.component("SsSearchButton", SsSearchButton);
  3065. app.component("SsSelect", SsSelect);
  3066. app.component("Icon", Icon);
  3067. // 注册 Vant 组件
  3068. const vantLib = window.vant || window.Vant;
  3069. console.log("🔍 检查 Vant:", {
  3070. hasVant: !!window.vant,
  3071. hasVantCap: !!window.Vant,
  3072. vantLib: !!vantLib,
  3073. vantKeys: vantLib ? Object.keys(vantLib).slice(0, 20) : [],
  3074. hasPopup: vantLib?.Popup,
  3075. hasDatetimePicker: vantLib?.DatetimePicker,
  3076. hasDatePicker: vantLib?.DatePicker,
  3077. hasTimePicker: vantLib?.TimePicker,
  3078. allKeys: vantLib ? Object.keys(vantLib) : [],
  3079. });
  3080. if (vantLib) {
  3081. try {
  3082. // 使用 Vant 的 use 方法注册所有组件
  3083. app.use(vantLib);
  3084. console.log("✅ Vant 全部组件注册成功");
  3085. } catch (error) {
  3086. console.error("❌ Vant 组件注册失败:", error);
  3087. // 降级方案:手动注册具体组件
  3088. try {
  3089. app.component("van-popup", vantLib.Popup);
  3090. app.component("van-datetime-picker", vantLib.DatetimePicker);
  3091. console.log("✅ Vant 手动注册成功");
  3092. } catch (e) {
  3093. console.error("❌ Vant 手动注册也失败:", e);
  3094. }
  3095. }
  3096. } else {
  3097. console.warn("⚠️ Vant 未加载");
  3098. }
  3099. // 注册组件 - 统一使用 kebab-case
  3100. app.component("ss-verify", SsVerify);
  3101. app.component("ss-verify-node", SsVerifyNode);
  3102. app.component("ss-common-icon", SsCommonIcon);
  3103. app.component("ss-onoff-button", SsOnoffButton);
  3104. app.component("ss-datetime-picker", SsDatetimePicker);
  3105. app.component("ss-confirm", SsConfirm);
  3106. app.component("ss-image-cropper", SsImageCropper);
  3107. app.component("ss-upload-image", SsUploadImage);
  3108. app.component("ss-upload-file", SsUploadFile);
  3109. app.component("ss-car-card", SsCarCard);
  3110. app.component("ss-sub-tab", SsSubTab);
  3111. app.component("ss-editor", SsEditor);
  3112. app.component("SsEditor", SsEditor);
  3113. // app.component("SsObjp", SsObjp);
  3114. // app.component("SsHidden", SsHidden);
  3115. // app.component("SsCcp", SsCcp);
  3116. // app.component("SsDatePicker", SsDatePicker);
  3117. // app.component("SsIcon", SsIcon);
  3118. // app.component("SsCommonIcon", SsCommonIcon);
  3119. // app.component("SsBreadcrumb", SsBreadcrumb);
  3120. // app.component("SsEditor", SsEditor);
  3121. // app.component("SsDialogIcon", SsDialogIcon);
  3122. // app.component("SsBottomButton", SsBottomButton);
  3123. // app.component("SsNavIcon", SsNavIcon);
  3124. // app.component("SsHeaderIcon", SsHeaderIcon);
  3125. // app.component("SsGolbalMenuIcon", SsGolbalMenuIcon);
  3126. // app.component("SsCartListIcon", SsCartListIcon);
  3127. // app.component("SsQuickIcon", SsQuickIcon);
  3128. // app.component("SsFormIcon", SsFormIcon);
  3129. // app.component("SsBottomDivIcon", SsBottomDivIcon);
  3130. // app.component("SsEditorIcon", SsEditorIcon);
  3131. // app.component("SsValidate", SsValidate);
  3132. // app.component("SsOnoffbutton", SsOnoffbutton);
  3133. // app.component("SsOnoffbuttonArray", SsOnoffbuttonArray);
  3134. // app.component("SsTextarea", SsTextarea);
  3135. // app.component("SsLoginInput", SsLoginInput);
  3136. // app.component("SsLoginButton", SsLoginButton);
  3137. // app.component("SsSearch", SsSearch);
  3138. // app.component("SsCartItem", SsCartItem);
  3139. // app.component("SsCartItem2", SsCartItem2);
  3140. // app.component("SsListCard", SsListCard);
  3141. // app.component("SsFolderCard", SsFolderCard);
  3142. // app.component("SsFolderCartView", SsFolderCartView);
  3143. // app.component("SsPage", SsPage);
  3144. // app.component("SsRightInfo", SSRightInfo);
  3145. // app.component("SsSuccessPopup", SsSuccessPopup);
  3146. // app.component("SsErrorDialog", SsErrorDialog);
  3147. // app.component("SsVerify", SsVerify);
  3148. // app.component("SsVerifyNode", SsVerifyNode);
  3149. // app.component("SsOrcImgBox", SsOrcImgBox);
  3150. // app.component("ss-search-input", SsSearchInput);
  3151. // app.component("ss-search-date-picker", SsSearchDatePicker);
  3152. // app.component("ss-search-button", SsSearchButton);
  3153. // app.component("ss-drop-button", SsDropButton);
  3154. // app.component("ss-sub-tab", SsSubTab);
  3155. // app.component("ss-img", SsImgUpload);
  3156. // 设置为中文
  3157. // app.use(ElementPlus, {
  3158. // locale: ElementPlusLocaleZhCn,
  3159. // });
  3160. // console.log(ElementPlus);
  3161. // 确保 ElementPlusIconsVue
  3162. // if (window.ElementPlusIconsVue) {
  3163. // // 注册 Element Plus 图标组件
  3164. // for (const [key, component] of Object.entries(
  3165. // window.ElementPlusIconsVue
  3166. // )) {
  3167. // console.log(key, component);
  3168. // app.component(key, component);
  3169. // }
  3170. // }
  3171. // 挂载首页的组件
  3172. // for (const componentName in IndexComponents) {
  3173. // app.component(componentName, IndexComponents[componentName]);
  3174. // }
  3175. // 挂载echarts的组件
  3176. // for (const componentName in EchartComponents) {
  3177. // app.component(componentName, EchartComponents[componentName]);
  3178. // }
  3179. // 挂载 Vue 应用
  3180. const vm = app.mount(el);
  3181. vm.data = vueOptions.data();
  3182. return vm;
  3183. };
  3184. })();