mp-ss-components.js 98 KB

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