newActivity.vue 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  1. <template>
  2. <!-- 运营活动管理 - 新增/编辑页面 -->
  3. <div class="table-box" style="width: 100%; min-height: 100%; background-color: white">
  4. <div class="header">
  5. <el-button @click="goBack"> 返回 </el-button>
  6. <h2 class="title">{{ type == "add" ? "新建" : "编辑" }}活动</h2>
  7. </div>
  8. <div class="form-wrapper">
  9. <div class="form-wrapper-main">
  10. <el-form ref="ruleFormRef" :model="activityModel" :rules="rules" class="formBox" label-width="140px">
  11. <div class="form-content">
  12. <!-- 活动类型 -->
  13. <el-form-item label="活动类型" prop="activityType">
  14. <el-select v-model="activityModel.activityType" class="form-input" clearable placeholder="请选择">
  15. <el-option label="营销活动" :value="1" />
  16. <el-option label="评论有礼" :value="2" />
  17. </el-select>
  18. </el-form-item>
  19. <!-- 活动名称 -->
  20. <el-form-item label="活动名称" prop="activityName">
  21. <el-input v-model="activityModel.activityName" class="form-input" clearable maxlength="50" placeholder="请输入" />
  22. </el-form-item>
  23. <!-- 活动时间 -->
  24. <el-form-item class="activity-time-item" label="活动时间" prop="activityTimeRange">
  25. <el-date-picker
  26. v-model="activityModel.activityTimeRange"
  27. :disabled-date="disabledDate"
  28. class="form-input"
  29. end-placeholder="结束日期"
  30. format="YYYY/MM/DD"
  31. range-separator="-"
  32. start-placeholder="开始日期"
  33. type="daterange"
  34. value-format="YYYY-MM-DD"
  35. />
  36. </el-form-item>
  37. <!-- 评论有礼相关字段 -->
  38. <template v-if="activityModel.activityType === 1">
  39. <!-- 用户可参与次数 -->
  40. <el-form-item label="用户可参与次数" prop="participationLimit">
  41. <el-input v-model="activityModel.participationLimit" placeholder="请输入" maxlength="4" />
  42. </el-form-item>
  43. <!-- 活动规则 -->
  44. <el-form-item label="活动规则" prop="activityRule">
  45. <el-cascader
  46. v-model="activityModel.activityRule"
  47. :options="ruleCascaderOptions"
  48. :props="cascaderProps"
  49. class="form-input"
  50. clearable
  51. placeholder="请选择"
  52. style="width: 100%"
  53. />
  54. </el-form-item>
  55. <!-- 优惠券 -->
  56. <el-form-item label="优惠券" prop="couponId">
  57. <el-select v-model="activityModel.couponId" class="form-input" clearable filterable placeholder="请选择">
  58. <el-option v-for="item in couponList" :key="item.id" :label="item.name" :value="item.id" />
  59. </el-select>
  60. </el-form-item>
  61. <!-- 优惠券发放数量 -->
  62. <el-form-item label="优惠券发放数量" prop="couponQuantity">
  63. <el-input v-model="activityModel.couponQuantity" placeholder="请输入" maxlength="5" />
  64. </el-form-item>
  65. </template>
  66. <!-- 营销活动相关字段 -->
  67. <template v-if="activityModel.activityType === 2">
  68. <!-- 报名时间 -->
  69. <el-form-item class="activity-time-item" label="报名时间" prop="signupTimeRange">
  70. <el-date-picker
  71. v-model="activityModel.signupTimeRange"
  72. :disabled-date="disabledDate"
  73. class="form-input"
  74. end-placeholder="结束日期"
  75. format="YYYY/MM/DD"
  76. range-separator="-"
  77. start-placeholder="开始日期"
  78. type="daterange"
  79. value-format="YYYY-MM-DD"
  80. />
  81. </el-form-item>
  82. <!-- 活动限制人数 -->
  83. <el-form-item label="活动限制人数" prop="activityLimitPeople">
  84. <el-input v-model="activityModel.activityLimitPeople" placeholder="请输入" maxlength="6" />
  85. </el-form-item>
  86. <!-- 活动详情 -->
  87. <el-form-item label="活动详情" prop="activityDetails">
  88. <el-input
  89. v-model="activityModel.activityDetails"
  90. type="textarea"
  91. :rows="6"
  92. placeholder="请输入活动详情"
  93. maxlength="1000"
  94. show-word-limit
  95. />
  96. </el-form-item>
  97. </template>
  98. <!-- 上传图片方式 -->
  99. <el-form-item label="活动图片类型" prop="uploadImgType">
  100. <el-radio-group v-model="activityModel.uploadImgType">
  101. <el-radio :label="1"> 本地上传 </el-radio>
  102. <el-radio :label="2"> AI生成 </el-radio>
  103. </el-radio-group>
  104. </el-form-item>
  105. <!-- 图片描述(当选择使用描述时显示) -->
  106. <el-form-item v-if="activityModel.uploadImgType === 2" label="图片描述" prop="imgDescribe">
  107. <el-input
  108. v-model="activityModel.imgDescribe"
  109. type="textarea"
  110. :rows="4"
  111. placeholder="请输入图片描述"
  112. maxlength="500"
  113. show-word-limit
  114. />
  115. </el-form-item>
  116. <!-- 活动标题图 -->
  117. <el-form-item v-if="activityModel.uploadImgType === 1" label="活动标题图" prop="activityTitleImage">
  118. <div class="upload-item-wrapper">
  119. <div class="upload-area upload-area-horizontal-21-9" :class="{ 'upload-full': titleFileList.length >= 1 }">
  120. <el-upload
  121. v-model:file-list="titleFileList"
  122. :accept="'.jpg,.jpeg,.png'"
  123. :auto-upload="false"
  124. :before-remove="handleBeforeRemove"
  125. :disabled="hasUnuploadedImages"
  126. :limit="1"
  127. :on-change="handleTitleUploadChange"
  128. :on-exceed="handleUploadExceed"
  129. :on-preview="handlePictureCardPreview"
  130. :on-remove="handleTitleRemove"
  131. :show-file-list="true"
  132. list-type="picture-card"
  133. >
  134. <template #trigger>
  135. <div v-if="titleFileList.length < 1" class="upload-trigger-card el-upload--picture-card">
  136. <el-icon>
  137. <Plus />
  138. </el-icon>
  139. </div>
  140. </template>
  141. </el-upload>
  142. </div>
  143. <div class="upload-hint">请上传21:9尺寸图片效果更佳,支持jpg、jpeg、png格式,上传图片不得超过20M</div>
  144. </div>
  145. </el-form-item>
  146. <!-- 活动详情图 -->
  147. <el-form-item v-if="activityModel.uploadImgType === 1" label="活动详情图" prop="activityDetailImage">
  148. <div class="upload-item-wrapper">
  149. <div class="upload-area upload-area-vertical" :class="{ 'upload-full': detailFileList.length >= 1 }">
  150. <el-upload
  151. v-model:file-list="detailFileList"
  152. :accept="'.jpg,.jpeg,.png'"
  153. :auto-upload="false"
  154. :before-remove="handleBeforeRemove"
  155. :disabled="hasUnuploadedImages"
  156. :limit="1"
  157. :on-change="handleDetailUploadChange"
  158. :on-exceed="handleUploadExceed"
  159. :on-preview="handlePictureCardPreview"
  160. :on-remove="handleDetailRemove"
  161. :show-file-list="true"
  162. list-type="picture-card"
  163. >
  164. <template #trigger>
  165. <div v-if="detailFileList.length < 1" class="upload-trigger-card el-upload--picture-card">
  166. <el-icon>
  167. <Plus />
  168. </el-icon>
  169. </div>
  170. </template>
  171. </el-upload>
  172. </div>
  173. <div class="upload-hint">请上传竖版图片,支持jpg、jpeg、png格式,上传图片不得超过20M</div>
  174. </div>
  175. </el-form-item>
  176. </div>
  177. </el-form>
  178. </div>
  179. <!-- 底部按钮区域 -->
  180. <div class="button-container">
  181. <el-button @click="goBack"> 取消 </el-button>
  182. <el-button type="primary" @click="handleSubmit()"> 提交审核 </el-button>
  183. </div>
  184. </div>
  185. <!-- 图片预览 -->
  186. <el-image-viewer
  187. v-if="imageViewerVisible"
  188. :initial-index="imageViewerInitialIndex"
  189. :url-list="imageViewerUrlList"
  190. @close="imageViewerVisible = false"
  191. />
  192. </div>
  193. </template>
  194. <script lang="tsx" name="newActivity" setup>
  195. /**
  196. * 运营活动管理 - 新增/编辑页面
  197. * 功能:支持运营活动的新增和编辑操作
  198. */
  199. import { computed, nextTick, onMounted, reactive, ref, watch } from "vue";
  200. import type { FormInstance, UploadFile, UploadProps } from "element-plus";
  201. import { ElMessage, ElMessageBox } from "element-plus";
  202. import { Plus } from "@element-plus/icons-vue";
  203. import { useRoute, useRouter } from "vue-router";
  204. import {
  205. addActivity,
  206. getActivityDetail,
  207. getActivityRuleOptions,
  208. getCouponList,
  209. updateActivity
  210. } from "@/api/modules/operationManagement";
  211. import { uploadContractImage } from "@/api/modules/licenseManagement";
  212. import { localGet } from "@/utils";
  213. // ==================== 响应式数据定义 ====================
  214. // 路由相关
  215. const router = useRouter();
  216. const route = useRoute();
  217. // 页面状态
  218. const type = ref<string>(""); // 页面类型:add-新增, edit-编辑
  219. const id = ref<string>(""); // 页面ID参数
  220. // 表单引用
  221. const ruleFormRef = ref<FormInstance>();
  222. // 优惠券列表
  223. const couponList = ref<any[]>([]);
  224. // 文件上传相关
  225. const titleFileList = ref<UploadFile[]>([]);
  226. const detailFileList = ref<UploadFile[]>([]);
  227. const titleImageUrl = ref<string>("");
  228. const detailImageUrl = ref<string>("");
  229. const pendingUploadFiles = ref<UploadFile[]>([]);
  230. const uploading = ref(false);
  231. const imageViewerVisible = ref(false);
  232. const imageViewerUrlList = ref<string[]>([]);
  233. const imageViewerInitialIndex = ref(0);
  234. // 活动规则级联选择器选项
  235. const ruleCascaderOptions = ref<any[]>([]);
  236. // 级联选择器配置
  237. const cascaderProps = {
  238. expandTrigger: "hover" as const,
  239. emitPath: true,
  240. disabled: (data: any) => {
  241. // 除了 "当用户 > 核销并评论 > 优惠券" 这个路径,其余选项不可选择
  242. if (data.disabled !== undefined) {
  243. return data.disabled;
  244. }
  245. return false;
  246. }
  247. };
  248. // 是否有未上传的图片
  249. const hasUnuploadedImages = computed(() => {
  250. return (
  251. titleFileList.value.some(file => file.status === "ready" || file.status === "uploading") ||
  252. detailFileList.value.some(file => file.status === "ready" || file.status === "uploading")
  253. );
  254. });
  255. // ==================== 表单验证规则 ====================
  256. const rules = reactive({
  257. activityType: [{ required: true, message: "请选择活动类型", trigger: "change" }],
  258. activityName: [{ required: true, message: "请输入活动名称", trigger: "blur" }],
  259. activityTimeRange: [
  260. { required: true, message: "请选择活动时间", trigger: "change" },
  261. {
  262. validator: (rule: any, value: any, callback: any) => {
  263. if (!value || !Array.isArray(value) || value.length !== 2) {
  264. callback(new Error("请选择活动时间"));
  265. return;
  266. }
  267. const [startTime, endTime] = value;
  268. if (!startTime || !endTime) {
  269. callback(new Error("请选择完整的活动时间"));
  270. return;
  271. }
  272. const start = new Date(startTime);
  273. const end = new Date(endTime);
  274. const today = new Date();
  275. today.setHours(0, 0, 0, 0);
  276. if (start < today) {
  277. callback(new Error("活动开始时间不能早于当前时间"));
  278. return;
  279. }
  280. if (start >= end) {
  281. callback(new Error("活动开始时间必须早于活动结束时间"));
  282. return;
  283. }
  284. callback();
  285. },
  286. trigger: "change"
  287. }
  288. ],
  289. participationLimit: [
  290. { required: true, message: "请输入用户可参与次数", trigger: "blur" },
  291. {
  292. validator: (rule: any, value: any, callback: any) => {
  293. if (activityModel.value.activityType === 1) {
  294. if (!value) {
  295. callback(new Error("请输入用户可参与次数"));
  296. return;
  297. }
  298. const numValue = Number(value);
  299. if (isNaN(numValue) || !Number.isInteger(numValue) || numValue <= 0) {
  300. callback(new Error("用户可参与次数必须为正整数"));
  301. return;
  302. }
  303. if (numValue > 9999) {
  304. callback(new Error("用户可参与次数必须小于9999"));
  305. return;
  306. }
  307. }
  308. callback();
  309. },
  310. trigger: "blur"
  311. }
  312. ],
  313. activityRule: [
  314. { required: true, message: "请选择活动规则", trigger: "change" },
  315. {
  316. validator: (rule: any, value: any, callback: any) => {
  317. if (activityModel.value.activityType === 1) {
  318. if (!value || !Array.isArray(value) || value.length < 2) {
  319. callback(new Error("请选择完整的活动规则(至少选择角色和行为)"));
  320. return;
  321. }
  322. }
  323. callback();
  324. },
  325. trigger: "change"
  326. }
  327. ],
  328. couponId: [
  329. { required: true, message: "请选择优惠券", trigger: "change" },
  330. {
  331. validator: (rule: any, value: any, callback: any) => {
  332. if (activityModel.value.activityType === 1) {
  333. if (!value) {
  334. callback(new Error("请选择优惠券"));
  335. return;
  336. }
  337. }
  338. callback();
  339. },
  340. trigger: "change"
  341. }
  342. ],
  343. couponQuantity: [
  344. { required: true, message: "请输入优惠券发放数量", trigger: "blur" },
  345. {
  346. validator: (rule: any, value: any, callback: any) => {
  347. if (activityModel.value.activityType === 1) {
  348. if (!value) {
  349. callback(new Error("请输入优惠券发放数量"));
  350. return;
  351. }
  352. const numValue = Number(value);
  353. if (isNaN(numValue) || !Number.isInteger(numValue) || numValue <= 0) {
  354. callback(new Error("优惠券发放数量必须为正整数"));
  355. return;
  356. }
  357. if (numValue > 99999) {
  358. callback(new Error("优惠券发放数量必须小于99999"));
  359. return;
  360. }
  361. }
  362. callback();
  363. },
  364. trigger: "blur"
  365. }
  366. ],
  367. signupTimeRange: [
  368. { required: true, message: "请选择报名时间", trigger: "change" },
  369. {
  370. validator: (rule: any, value: any, callback: any) => {
  371. if (activityModel.value.activityType === 2) {
  372. if (!value || !Array.isArray(value) || value.length !== 2) {
  373. callback(new Error("请选择报名时间"));
  374. return;
  375. }
  376. const [startTime, endTime] = value;
  377. if (!startTime || !endTime) {
  378. callback(new Error("请选择完整的报名时间"));
  379. return;
  380. }
  381. const start = new Date(startTime);
  382. const end = new Date(endTime);
  383. if (start >= end) {
  384. callback(new Error("报名开始时间必须早于报名结束时间"));
  385. return;
  386. }
  387. }
  388. callback();
  389. },
  390. trigger: "change"
  391. }
  392. ],
  393. activityLimitPeople: [
  394. { required: true, message: "请输入活动限制人数", trigger: "blur" },
  395. {
  396. validator: (rule: any, value: any, callback: any) => {
  397. if (activityModel.value.activityType === 2) {
  398. if (!value) {
  399. callback(new Error("请输入活动限制人数"));
  400. return;
  401. }
  402. const numValue = Number(value);
  403. if (isNaN(numValue) || !Number.isInteger(numValue) || numValue <= 0) {
  404. callback(new Error("活动限制人数必须为正整数"));
  405. return;
  406. }
  407. if (numValue > 999999) {
  408. callback(new Error("活动限制人数必须小于999999"));
  409. return;
  410. }
  411. }
  412. callback();
  413. },
  414. trigger: "blur"
  415. }
  416. ],
  417. activityDetails: [
  418. { required: true, message: "请输入活动详情", trigger: ["blur", "change"] },
  419. {
  420. validator: (rule: any, value: any, callback: any) => {
  421. if (activityModel.value.activityType === 2) {
  422. if (!value || value.trim() === "") {
  423. callback(new Error("请输入活动详情"));
  424. return;
  425. }
  426. }
  427. callback();
  428. },
  429. trigger: ["blur", "change"]
  430. }
  431. ],
  432. uploadImgType: [{ required: true, message: "请选择上传图片方式", trigger: "change" }],
  433. imgDescribe: [
  434. {
  435. required: true,
  436. validator: (rule: any, value: any, callback: any) => {
  437. if (activityModel.value.uploadImgType === 2) {
  438. if (!value || value.trim() === "") {
  439. callback(new Error("请输入图片描述"));
  440. return;
  441. }
  442. }
  443. callback();
  444. },
  445. trigger: ["blur", "change"]
  446. }
  447. ],
  448. activityTitleImage: [
  449. {
  450. required: true,
  451. validator: (rule: any, value: any, callback: any) => {
  452. if (activityModel.value.uploadImgType === 1) {
  453. if (!titleImageUrl.value) {
  454. callback(new Error("请上传活动标题图"));
  455. return;
  456. }
  457. }
  458. callback();
  459. },
  460. trigger: ["change", "blur"]
  461. }
  462. ],
  463. activityDetailImage: [
  464. {
  465. required: true,
  466. validator: (rule: any, value: any, callback: any) => {
  467. if (activityModel.value.uploadImgType === 1) {
  468. if (!detailImageUrl.value) {
  469. callback(new Error("请上传活动详情图"));
  470. return;
  471. }
  472. }
  473. callback();
  474. },
  475. trigger: ["change", "blur"]
  476. }
  477. ]
  478. });
  479. // ==================== 活动信息数据模型 ====================
  480. const activityModel = ref<any>({
  481. // 活动类型:1-评论有礼,2-营销活动
  482. activityType: 2,
  483. // 活动宣传图(包含标题和详情)
  484. promotionImages: null,
  485. // 活动标题图片
  486. activityTitleImg: null,
  487. // 活动详情图片
  488. activityDetailImg: null,
  489. // 活动标题图(用于表单验证)
  490. activityTitleImage: null,
  491. // 活动详情图(用于表单验证)
  492. activityDetailImage: null,
  493. // 活动名称
  494. activityName: "",
  495. // 活动时间范围
  496. activityTimeRange: [],
  497. // 用户可参与次数(评论有礼)
  498. participationLimit: "",
  499. // 活动规则(级联选择器的值数组)(评论有礼)
  500. activityRule: [],
  501. // 优惠券ID(评论有礼)
  502. couponId: "",
  503. // 优惠券发放数量(评论有礼)
  504. couponQuantity: "",
  505. // 报名时间范围(营销活动)
  506. signupTimeRange: [],
  507. // 活动限制人数(营销活动)
  508. activityLimitPeople: "",
  509. // 活动详情(营销活动)
  510. activityDetails: "",
  511. // 上传图片方式:1-正常用户,2-使用描述
  512. uploadImgType: 1,
  513. // 图片描述(当uploadImgType为2时使用)
  514. imgDescribe: ""
  515. });
  516. // ==================== 日期选择器禁用规则 ====================
  517. // 禁用日期(不能早于今天)
  518. const disabledDate = (time: Date) => {
  519. const today = new Date();
  520. today.setHours(0, 0, 0, 0);
  521. return time.getTime() < today.getTime();
  522. };
  523. // ==================== 图片参数转换函数 ====================
  524. /**
  525. * 图片URL转换为upload组件的参数
  526. * @param imageUrl 图片URL
  527. * @returns UploadFile对象
  528. */
  529. const handleImageParam = (imageUrl: string): UploadFile => {
  530. // 使用split方法以'/'为分隔符将URL拆分成数组
  531. const parts = imageUrl.split("/");
  532. // 取数组的最后一项,即图片名称
  533. const imageName = parts[parts.length - 1];
  534. return {
  535. uid: Date.now() + Math.random(),
  536. name: imageName,
  537. status: "success",
  538. percentage: 100,
  539. url: imageUrl
  540. } as unknown as UploadFile;
  541. };
  542. // ==================== 文件上传相关函数 ====================
  543. /**
  544. * 检查文件是否在排队中(未上传)
  545. */
  546. const isFilePending = (file: any): boolean => {
  547. if (file.status === "ready") {
  548. return true;
  549. }
  550. if (pendingUploadFiles.value.some(item => item.uid === file.uid)) {
  551. return true;
  552. }
  553. return false;
  554. };
  555. /**
  556. * 图片上传 - 删除前确认
  557. */
  558. const handleBeforeRemove = async (uploadFile: any, uploadFiles: any[]): Promise<boolean> => {
  559. if (isFilePending(uploadFile)) {
  560. ElMessage.warning("图片尚未上传,请等待上传完成后再删除");
  561. return false;
  562. }
  563. try {
  564. await ElMessageBox.confirm("确定要删除这张图片吗?", "提示", {
  565. confirmButtonText: "确定",
  566. cancelButtonText: "取消",
  567. type: "warning"
  568. });
  569. return true;
  570. } catch {
  571. return false;
  572. }
  573. };
  574. /**
  575. * 活动标题图片上传 - 移除图片回调
  576. */
  577. const handleTitleRemove: UploadProps["onRemove"] = (uploadFile, uploadFiles) => {
  578. const file = uploadFile as any;
  579. const imageUrl = file.url;
  580. if (imageUrl) {
  581. titleImageUrl.value = "";
  582. activityModel.value.activityTitleImg = null;
  583. activityModel.value.activityTitleImage = null;
  584. // 触发表单验证
  585. nextTick(() => {
  586. ruleFormRef.value?.validateField("activityTitleImage");
  587. });
  588. }
  589. if (file.url && file.url.startsWith("blob:")) {
  590. URL.revokeObjectURL(file.url);
  591. }
  592. titleFileList.value = [...uploadFiles];
  593. ElMessage.success("图片已删除");
  594. };
  595. /**
  596. * 活动详情图片上传 - 移除图片回调
  597. */
  598. const handleDetailRemove: UploadProps["onRemove"] = (uploadFile, uploadFiles) => {
  599. const file = uploadFile as any;
  600. const imageUrl = file.url;
  601. if (imageUrl) {
  602. detailImageUrl.value = "";
  603. activityModel.value.activityDetailImg = null;
  604. activityModel.value.activityDetailImage = null;
  605. // 触发表单验证
  606. nextTick(() => {
  607. ruleFormRef.value?.validateField("activityDetailImage");
  608. });
  609. }
  610. if (file.url && file.url.startsWith("blob:")) {
  611. URL.revokeObjectURL(file.url);
  612. }
  613. detailFileList.value = [...uploadFiles];
  614. ElMessage.success("图片已删除");
  615. };
  616. /**
  617. * 上传文件超出限制提示
  618. */
  619. const handleUploadExceed: UploadProps["onExceed"] = () => {
  620. ElMessage.warning("最多只能上传1张图片");
  621. };
  622. /**
  623. * 活动标题图片上传 - 文件变更
  624. */
  625. const handleTitleUploadChange: UploadProps["onChange"] = async (uploadFile, uploadFiles) => {
  626. if (uploadFile.raw) {
  627. const fileType = uploadFile.raw.type.toLowerCase();
  628. const fileName = uploadFile.name.toLowerCase();
  629. const validTypes = ["image/jpeg", "image/jpg", "image/png"];
  630. const validExtensions = [".jpg", ".jpeg", ".png"];
  631. const isValidType = validTypes.includes(fileType) || validExtensions.some(ext => fileName.endsWith(ext));
  632. if (!isValidType) {
  633. // 从文件列表中移除不符合类型的文件
  634. const index = titleFileList.value.findIndex((f: any) => f.uid === uploadFile.uid);
  635. if (index > -1) {
  636. titleFileList.value.splice(index, 1);
  637. }
  638. // 从 uploadFiles 中移除
  639. const uploadIndex = uploadFiles.findIndex((f: any) => f.uid === uploadFile.uid);
  640. if (uploadIndex > -1) {
  641. uploadFiles.splice(uploadIndex, 1);
  642. }
  643. // 如果文件有 blob URL,释放它
  644. if (uploadFile.url && uploadFile.url.startsWith("blob:")) {
  645. URL.revokeObjectURL(uploadFile.url);
  646. }
  647. ElMessage.warning("只支持上传 JPG、JPEG 和 PNG 格式的图片");
  648. return;
  649. }
  650. // 检查文件大小,不得超过20M
  651. const maxSize = 20 * 1024 * 1024; // 20MB
  652. if (uploadFile.raw.size > maxSize) {
  653. // 从文件列表中移除超过大小的文件
  654. const index = titleFileList.value.findIndex((f: any) => f.uid === uploadFile.uid);
  655. if (index > -1) {
  656. titleFileList.value.splice(index, 1);
  657. }
  658. // 从 uploadFiles 中移除
  659. const uploadIndex = uploadFiles.findIndex((f: any) => f.uid === uploadFile.uid);
  660. if (uploadIndex > -1) {
  661. uploadFiles.splice(uploadIndex, 1);
  662. }
  663. // 如果文件有 blob URL,释放它
  664. if (uploadFile.url && uploadFile.url.startsWith("blob:")) {
  665. URL.revokeObjectURL(uploadFile.url);
  666. }
  667. ElMessage.warning("上传图片不得超过20M");
  668. return;
  669. }
  670. }
  671. const existingIndex = titleFileList.value.findIndex((f: any) => f.uid === uploadFile.uid);
  672. if (existingIndex === -1) {
  673. titleFileList.value.push(uploadFile);
  674. }
  675. const readyFiles = titleFileList.value.filter(file => file.status === "ready");
  676. if (readyFiles.length) {
  677. readyFiles.forEach(file => {
  678. if (!pendingUploadFiles.value.some(item => item.uid === file.uid)) {
  679. pendingUploadFiles.value.push(file);
  680. }
  681. });
  682. }
  683. processUploadQueue("title");
  684. };
  685. /**
  686. * 活动详情图片上传 - 文件变更
  687. */
  688. const handleDetailUploadChange: UploadProps["onChange"] = async (uploadFile, uploadFiles) => {
  689. if (uploadFile.raw) {
  690. const fileType = uploadFile.raw.type.toLowerCase();
  691. const fileName = uploadFile.name.toLowerCase();
  692. const validTypes = ["image/jpeg", "image/jpg", "image/png"];
  693. const validExtensions = [".jpg", ".jpeg", ".png"];
  694. const isValidType = validTypes.includes(fileType) || validExtensions.some(ext => fileName.endsWith(ext));
  695. if (!isValidType) {
  696. // 从文件列表中移除不符合类型的文件
  697. const index = detailFileList.value.findIndex((f: any) => f.uid === uploadFile.uid);
  698. if (index > -1) {
  699. detailFileList.value.splice(index, 1);
  700. }
  701. // 从 uploadFiles 中移除
  702. const uploadIndex = uploadFiles.findIndex((f: any) => f.uid === uploadFile.uid);
  703. if (uploadIndex > -1) {
  704. uploadFiles.splice(uploadIndex, 1);
  705. }
  706. // 如果文件有 blob URL,释放它
  707. if (uploadFile.url && uploadFile.url.startsWith("blob:")) {
  708. URL.revokeObjectURL(uploadFile.url);
  709. }
  710. ElMessage.warning("只支持上传 JPG、JPEG 和 PNG 格式的图片");
  711. return;
  712. }
  713. // 检查文件大小,不得超过20M
  714. const maxSize = 20 * 1024 * 1024; // 20MB
  715. if (uploadFile.raw.size > maxSize) {
  716. // 从文件列表中移除超过大小的文件
  717. const index = detailFileList.value.findIndex((f: any) => f.uid === uploadFile.uid);
  718. if (index > -1) {
  719. detailFileList.value.splice(index, 1);
  720. }
  721. // 从 uploadFiles 中移除
  722. const uploadIndex = uploadFiles.findIndex((f: any) => f.uid === uploadFile.uid);
  723. if (uploadIndex > -1) {
  724. uploadFiles.splice(uploadIndex, 1);
  725. }
  726. // 如果文件有 blob URL,释放它
  727. if (uploadFile.url && uploadFile.url.startsWith("blob:")) {
  728. URL.revokeObjectURL(uploadFile.url);
  729. }
  730. ElMessage.warning("上传图片不得超过20M");
  731. return;
  732. }
  733. }
  734. const existingIndex = detailFileList.value.findIndex((f: any) => f.uid === uploadFile.uid);
  735. if (existingIndex === -1) {
  736. detailFileList.value.push(uploadFile);
  737. }
  738. const readyFiles = detailFileList.value.filter(file => file.status === "ready");
  739. if (readyFiles.length) {
  740. readyFiles.forEach(file => {
  741. if (!pendingUploadFiles.value.some(item => item.uid === file.uid)) {
  742. pendingUploadFiles.value.push(file);
  743. }
  744. });
  745. }
  746. processUploadQueue("detail");
  747. };
  748. /**
  749. * 处理上传队列 - 逐个上传文件
  750. */
  751. const processUploadQueue = async (type: string) => {
  752. if (uploading.value || pendingUploadFiles.value.length === 0) {
  753. return;
  754. }
  755. const file = pendingUploadFiles.value.shift();
  756. if (file) {
  757. await uploadSingleFile(file, type);
  758. processUploadQueue(type);
  759. }
  760. };
  761. /**
  762. * 单文件上传图片
  763. */
  764. const uploadSingleFile = async (file: UploadFile, uploadType: string) => {
  765. if (!file.raw) {
  766. return;
  767. }
  768. const rawFile = file.raw as File;
  769. const formData = new FormData();
  770. formData.append("file", rawFile);
  771. formData.append("user", "text");
  772. file.status = "uploading";
  773. file.percentage = 0;
  774. uploading.value = true;
  775. try {
  776. const result: any = await uploadContractImage(formData);
  777. if (result?.code === 200 && result.data) {
  778. let imageUrl = result.data[0];
  779. if (!imageUrl) {
  780. throw new Error("上传成功但未获取到图片URL");
  781. }
  782. file.status = "success";
  783. file.percentage = 100;
  784. file.url = imageUrl;
  785. file.response = { url: imageUrl };
  786. if (uploadType === "title") {
  787. titleImageUrl.value = imageUrl;
  788. activityModel.value.activityTitleImg = { url: imageUrl };
  789. activityModel.value.activityTitleImage = imageUrl;
  790. // 触发表单验证
  791. nextTick(() => {
  792. ruleFormRef.value?.validateField("activityTitleImage");
  793. });
  794. } else if (uploadType === "detail") {
  795. detailImageUrl.value = imageUrl;
  796. activityModel.value.activityDetailImg = { url: imageUrl };
  797. activityModel.value.activityDetailImage = imageUrl;
  798. // 触发表单验证
  799. nextTick(() => {
  800. ruleFormRef.value?.validateField("activityDetailImage");
  801. });
  802. }
  803. } else {
  804. throw new Error(result?.msg || "图片上传失败");
  805. }
  806. } catch (error: any) {
  807. // 上传失败时保持进度条为 0
  808. file.percentage = 0;
  809. // 不要设置 file.status = "fail",直接移除文件,避免显示错误占位图
  810. if (file.url && file.url.startsWith("blob:")) {
  811. URL.revokeObjectURL(file.url);
  812. }
  813. // 从文件列表中移除失败的文件
  814. const index =
  815. uploadType === "title"
  816. ? titleFileList.value.findIndex((f: any) => f.uid === file.uid)
  817. : detailFileList.value.findIndex((f: any) => f.uid === file.uid);
  818. if (index > -1) {
  819. if (uploadType === "title") {
  820. titleFileList.value.splice(index, 1);
  821. } else {
  822. detailFileList.value.splice(index, 1);
  823. }
  824. }
  825. // Error message handled by global upload method, except for specific business logic errors
  826. if (error?.message && error.message.includes("未获取到图片URL")) {
  827. ElMessage.error(error.message);
  828. }
  829. } finally {
  830. uploading.value = false;
  831. // 触发视图更新
  832. if (uploadType === "title") {
  833. titleFileList.value = [...titleFileList.value];
  834. } else {
  835. detailFileList.value = [...detailFileList.value];
  836. }
  837. }
  838. };
  839. /**
  840. * 图片预览
  841. */
  842. const handlePictureCardPreview = (file: any) => {
  843. if (isFilePending(file)) {
  844. ElMessage.warning("图片尚未上传,请等待上传完成后再预览");
  845. return;
  846. }
  847. if (file.status === "uploading" && file.url) {
  848. imageViewerUrlList.value = [file.url];
  849. imageViewerInitialIndex.value = 0;
  850. imageViewerVisible.value = true;
  851. return;
  852. }
  853. const allFiles = [...titleFileList.value, ...detailFileList.value];
  854. const urlList = allFiles
  855. .filter((item: any) => item.status === "success" && (item.url || item.response?.data))
  856. .map((item: any) => item.url || item.response?.data);
  857. const currentIndex = urlList.findIndex((url: string) => url === (file.url || file.response?.data));
  858. if (currentIndex < 0) {
  859. ElMessage.warning("图片尚未上传完成,无法预览");
  860. return;
  861. }
  862. imageViewerUrlList.value = urlList;
  863. imageViewerInitialIndex.value = currentIndex;
  864. imageViewerVisible.value = true;
  865. };
  866. // ==================== 监听器 ====================
  867. /**
  868. * 监听活动类型变化,切换时清除相关数据并重新验证
  869. */
  870. watch(
  871. () => activityModel.value.activityType,
  872. (newVal, oldVal) => {
  873. // 如果 oldVal 为空或 undefined,说明是初始化,不处理
  874. if (oldVal === undefined || oldVal === null || oldVal === "") return;
  875. // 如果新旧值相同,不处理
  876. if (newVal === oldVal) return;
  877. nextTick(() => {
  878. if (newVal === 1) {
  879. // 切换到评论有礼:清除营销活动相关字段
  880. activityModel.value.signupTimeRange = [];
  881. activityModel.value.activityLimitPeople = "";
  882. activityModel.value.activityDetails = "";
  883. // 清除营销活动字段的验证状态
  884. ruleFormRef.value?.clearValidate(["signupTimeRange", "activityLimitPeople", "activityDetails"]);
  885. } else if (newVal === 2) {
  886. // 切换到营销活动:清除评论有礼相关字段
  887. activityModel.value.participationLimit = "";
  888. activityModel.value.activityRule = [];
  889. activityModel.value.couponId = "";
  890. activityModel.value.couponQuantity = "";
  891. // 清除评论有礼字段的验证状态
  892. ruleFormRef.value?.clearValidate(["participationLimit", "activityRule", "couponId", "couponQuantity"]);
  893. }
  894. });
  895. },
  896. { immediate: false }
  897. );
  898. /**
  899. * 监听上传图片方式变化,切换时清除相关数据并重新验证
  900. */
  901. watch(
  902. () => activityModel.value.uploadImgType,
  903. (newVal, oldVal) => {
  904. if (oldVal === undefined) return; // 初始化时不处理
  905. nextTick(() => {
  906. if (newVal === 2) {
  907. // 切换到使用描述:清除图片数据
  908. titleFileList.value = [];
  909. detailFileList.value = [];
  910. titleImageUrl.value = "";
  911. detailImageUrl.value = "";
  912. activityModel.value.activityTitleImg = null;
  913. activityModel.value.activityDetailImg = null;
  914. activityModel.value.activityTitleImage = null;
  915. activityModel.value.activityDetailImage = null;
  916. // 清除图片字段的验证
  917. ruleFormRef.value?.clearValidate(["activityTitleImage", "activityDetailImage"]);
  918. // 验证描述字段
  919. ruleFormRef.value?.validateField("imgDescribe");
  920. } else if (newVal === 1) {
  921. // 切换到正常用户:清除描述数据
  922. activityModel.value.imgDescribe = "";
  923. // 清除描述字段的验证
  924. ruleFormRef.value?.clearValidate("imgDescribe");
  925. // 验证图片字段
  926. ruleFormRef.value?.validateField(["activityTitleImage", "activityDetailImage"]);
  927. }
  928. });
  929. }
  930. );
  931. // ==================== 生命周期钩子 ====================
  932. /**
  933. * 组件挂载时初始化
  934. */
  935. onMounted(async () => {
  936. id.value = (route.query.id as string) || "";
  937. type.value = (route.query.type as string) || "";
  938. // 加载优惠券列表
  939. try {
  940. const params = {
  941. storeId: localGet("createdId"),
  942. groupType: localGet("businessSection"),
  943. couponType: "2",
  944. couponStatus: "1",
  945. couponsFromType: 1,
  946. pageNum: 1,
  947. pageSize: 99999
  948. };
  949. const res: any = await getCouponList(params);
  950. if (res && res.code == 200) {
  951. couponList.value = res.data?.discountList?.records || [];
  952. }
  953. } catch (error) {
  954. console.error("加载优惠券列表失败:", error);
  955. }
  956. // 加载活动规则级联选择器选项
  957. try {
  958. const res: any = await getActivityRuleOptions();
  959. console.log("ruleCascaderOptions:", res.data);
  960. if (res && res.code == 200) {
  961. ruleCascaderOptions.value = res.data || [];
  962. }
  963. } catch (error) {
  964. console.error("加载活动规则选项失败:", error);
  965. }
  966. // 编辑模式下加载数据
  967. if (type.value != "add" && id.value) {
  968. try {
  969. const res: any = await getActivityDetail({ id: id.value });
  970. if (res && res.code == 200) {
  971. activityModel.value = { ...activityModel.value, ...res.data };
  972. // 处理活动时间范围
  973. if (res.data.startTime && res.data.endTime) {
  974. activityModel.value.activityTimeRange = [res.data.startTime, res.data.endTime];
  975. }
  976. // 加载活动规则(评论有礼)
  977. if (res.data.activityRule) {
  978. activityModel.value.activityRule = res.data.activityRule.split(",");
  979. } else {
  980. activityModel.value.activityRule = [];
  981. }
  982. // 加载报名开始时间(营销活动)
  983. if (res.data.signupStartTime) {
  984. activityModel.value.signupStartTime = res.data.signupStartTime;
  985. }
  986. // 加载报名结束时间(营销活动)
  987. if (res.data.signupEndTime) {
  988. activityModel.value.signupEndTime = res.data.signupEndTime;
  989. }
  990. // 加载活动限制人数(营销活动)
  991. if (res.data.activityLimitPeople !== undefined) {
  992. activityModel.value.activityLimitPeople = res.data.activityLimitPeople;
  993. }
  994. // 加载活动详情(营销活动)
  995. if (res.data.activityDetails) {
  996. activityModel.value.activityDetails = res.data.activityDetails;
  997. }
  998. // 加载上传图片方式
  999. if (res.data.uploadImgType !== undefined) {
  1000. activityModel.value.uploadImgType = res.data.uploadImgType;
  1001. } else {
  1002. activityModel.value.uploadImgType = 1; // 默认为正常用户
  1003. }
  1004. // 加载图片描述
  1005. if (res.data.imgDescribe) {
  1006. activityModel.value.imgDescribe = res.data.imgDescribe;
  1007. } else {
  1008. activityModel.value.imgDescribe = "";
  1009. }
  1010. // 根据上传图片方式决定是否加载图片数据
  1011. if (activityModel.value.uploadImgType === 1) {
  1012. // 如果有标题图片,添加到文件列表
  1013. if (res.data.activityTitleImgUrl) {
  1014. const titleImgUrl = res.data.activityTitleImgUrl;
  1015. if (titleImgUrl) {
  1016. titleImageUrl.value = titleImgUrl;
  1017. activityModel.value.activityTitleImg = res.data.activityTitleImgUrl;
  1018. activityModel.value.activityTitleImage = titleImgUrl;
  1019. const titleFile = handleImageParam(titleImgUrl);
  1020. titleFileList.value = [titleFile];
  1021. }
  1022. }
  1023. // 如果有详情图片,添加到文件列表
  1024. if (res.data.activityDetailImgUrl) {
  1025. const detailImgUrl = res.data.activityDetailImgUrl;
  1026. if (detailImgUrl) {
  1027. detailImageUrl.value = detailImgUrl;
  1028. activityModel.value.activityDetailImg = res.data.activityDetailImgUrl;
  1029. activityModel.value.activityDetailImage = detailImgUrl;
  1030. const detailFile = handleImageParam(detailImgUrl);
  1031. detailFileList.value = [detailFile];
  1032. }
  1033. }
  1034. }
  1035. }
  1036. } catch (error) {
  1037. console.error("加载活动详情失败:", error);
  1038. ElMessage.error("加载活动详情失败");
  1039. }
  1040. }
  1041. await nextTick();
  1042. ruleFormRef.value?.clearValidate();
  1043. });
  1044. // ==================== 事件处理函数 ====================
  1045. /**
  1046. * 返回上一页
  1047. */
  1048. const goBack = () => {
  1049. router.go(-1);
  1050. };
  1051. /**
  1052. * 提交表单
  1053. */
  1054. const handleSubmit = async () => {
  1055. if (!ruleFormRef.value) return;
  1056. // 如果选择正常用户方式且有未上传的图片,阻止提交
  1057. if (activityModel.value.uploadImgType === 1 && hasUnuploadedImages.value) {
  1058. ElMessage.warning("请等待图片上传完成后再提交");
  1059. return;
  1060. }
  1061. await ruleFormRef.value.validate(async valid => {
  1062. if (valid) {
  1063. const [startTime, endTime] = activityModel.value.activityTimeRange || [];
  1064. const auditParam = {
  1065. text: `${activityModel.value.activityName}, ${activityModel.value.imgDescribe || ""}`,
  1066. image_urls: [titleImageUrl.value, detailImageUrl.value]
  1067. };
  1068. const params: any = {
  1069. activityType: activityModel.value.activityType,
  1070. activityName: activityModel.value.activityName,
  1071. startTime: startTime,
  1072. endTime: endTime,
  1073. uploadImgType: activityModel.value.uploadImgType,
  1074. storeId: localGet("createdId"),
  1075. groupType: localGet("businessSection"),
  1076. status: 1, // 1-待审核
  1077. auditParam: JSON.stringify(auditParam)
  1078. };
  1079. // 根据活动类型添加不同的字段,确保只提交对应类型的字段
  1080. if (activityModel.value.activityType === 1) {
  1081. // 评论有礼:只添加评论有礼相关字段
  1082. params.participationLimit = activityModel.value.participationLimit;
  1083. params.activityRule = activityModel.value.activityRule.join(",");
  1084. params.couponId = activityModel.value.couponId;
  1085. params.couponQuantity = activityModel.value.couponQuantity;
  1086. // 确保不包含营销活动的字段
  1087. delete params.signupStartTime;
  1088. delete params.signupEndTime;
  1089. delete params.activityLimitPeople;
  1090. delete params.activityDetails;
  1091. } else if (activityModel.value.activityType === 2) {
  1092. // 营销活动:只添加营销活动相关字段
  1093. const [signupStartTime, signupEndTime] = activityModel.value.signupTimeRange || [];
  1094. params.signupStartTime = signupStartTime;
  1095. params.signupEndTime = signupEndTime;
  1096. params.activityLimitPeople = activityModel.value.activityLimitPeople;
  1097. params.activityDetails = activityModel.value.activityDetails;
  1098. // 确保不包含评论有礼的字段
  1099. delete params.participationLimit;
  1100. delete params.activityRule;
  1101. delete params.couponId;
  1102. delete params.couponQuantity;
  1103. }
  1104. // 根据上传图片方式设置不同的参数
  1105. if (activityModel.value.uploadImgType === 1) {
  1106. // 正常用户:上传图片
  1107. params.activityTitleImg = {
  1108. imgUrl: titleImageUrl.value,
  1109. imgSort: 0,
  1110. storeId: localGet("createdId")
  1111. };
  1112. params.activityDetailImg = {
  1113. imgUrl: detailImageUrl.value,
  1114. imgSort: 0,
  1115. storeId: localGet("createdId")
  1116. };
  1117. } else if (activityModel.value.uploadImgType === 2) {
  1118. // 使用描述:提交描述文本,但依然保留图片字段,imgUrl为空
  1119. params.imgDescribe = activityModel.value.imgDescribe;
  1120. params.activityTitleImg = {
  1121. imgUrl: "",
  1122. imgSort: 0,
  1123. storeId: localGet("createdId")
  1124. };
  1125. params.activityDetailImg = {
  1126. imgUrl: "",
  1127. imgSort: 0,
  1128. storeId: localGet("createdId")
  1129. };
  1130. }
  1131. try {
  1132. let res: any;
  1133. if (type.value == "add") {
  1134. res = await addActivity(params);
  1135. } else {
  1136. params.id = id.value;
  1137. res = await updateActivity(params);
  1138. }
  1139. if (res && res.code == 200) {
  1140. ElMessage.success(type.value == "add" ? "新增成功" : "编辑成功");
  1141. goBack();
  1142. } else {
  1143. ElMessage.error(res?.msg || "操作失败");
  1144. }
  1145. } catch (error) {
  1146. console.error("提交失败:", error);
  1147. ElMessage.error("操作失败");
  1148. }
  1149. }
  1150. });
  1151. };
  1152. </script>
  1153. <style lang="scss" scoped>
  1154. /* 页面容器 */
  1155. .table-box {
  1156. display: flex;
  1157. flex-direction: column;
  1158. height: auto !important;
  1159. min-height: 100%;
  1160. }
  1161. /* 头部区域 */
  1162. .header {
  1163. display: flex;
  1164. align-items: center;
  1165. justify-content: center;
  1166. padding: 20px 24px;
  1167. background-color: #ffffff;
  1168. border-bottom: 1px solid #e4e7ed;
  1169. box-shadow: 0 2px 4px rgb(0 0 0 / 2%);
  1170. }
  1171. .title {
  1172. flex: 1;
  1173. margin: 0;
  1174. font-size: 18px;
  1175. font-weight: 600;
  1176. color: #303133;
  1177. text-align: center;
  1178. }
  1179. /* 表单内容区域 */
  1180. .form-content {
  1181. padding: 24px;
  1182. background-color: #ffffff;
  1183. }
  1184. /* 表单包装器 */
  1185. .form-wrapper {
  1186. display: flex;
  1187. flex-direction: column;
  1188. align-items: center;
  1189. background-color: #ffffff;
  1190. .form-wrapper-main {
  1191. width: 100%;
  1192. max-width: 800px;
  1193. }
  1194. }
  1195. /* 上传项容器 */
  1196. .upload-item-wrapper {
  1197. display: flex;
  1198. flex-direction: column;
  1199. gap: 12px;
  1200. align-items: flex-start;
  1201. width: 100%;
  1202. }
  1203. .upload-hint {
  1204. margin-top: 4px;
  1205. font-size: 12px;
  1206. line-height: 1.5;
  1207. color: #909399;
  1208. }
  1209. /* 规则表格容器 */
  1210. .rule-table-container {
  1211. margin-top: 20px;
  1212. }
  1213. /* 底部按钮区域 */
  1214. .button-container {
  1215. display: flex;
  1216. gap: 20px;
  1217. justify-content: center;
  1218. padding-bottom: 15px;
  1219. background-color: #ffffff;
  1220. }
  1221. .upload-area {
  1222. width: 100%;
  1223. :deep(.el-upload--picture-card) {
  1224. width: 100%;
  1225. height: 180px;
  1226. }
  1227. :deep(.el-upload-list--picture-card) {
  1228. width: 100%;
  1229. .el-upload-list__item {
  1230. width: 100%;
  1231. height: 180px;
  1232. margin: 0;
  1233. }
  1234. }
  1235. :deep(.el-upload-list--picture-card .el-upload-list__item:hover .el-upload-list__item-status-label) {
  1236. display: inline-flex !important;
  1237. opacity: 1 !important;
  1238. }
  1239. :deep(.el-upload-list__item.is-success:focus .el-upload-list__item-status-label) {
  1240. display: inline-flex !important;
  1241. opacity: 1 !important;
  1242. }
  1243. :deep(.el-upload-list--picture-card .el-icon--close-tip) {
  1244. display: none !important;
  1245. }
  1246. &.upload-full {
  1247. :deep(.el-upload--picture-card) {
  1248. display: none !important;
  1249. }
  1250. }
  1251. // 21:9横向图片样式
  1252. &.upload-area-horizontal-21-9 {
  1253. :deep(.el-upload--picture-card) {
  1254. width: 100%;
  1255. height: auto;
  1256. aspect-ratio: 21 / 9;
  1257. }
  1258. :deep(.el-upload-list--picture-card) {
  1259. width: 100%;
  1260. .el-upload-list__item {
  1261. width: 100%;
  1262. height: auto;
  1263. aspect-ratio: 21 / 9;
  1264. margin: 0;
  1265. }
  1266. }
  1267. }
  1268. // 竖版图片样式
  1269. &.upload-area-vertical {
  1270. max-width: 300px;
  1271. :deep(.el-upload--picture-card) {
  1272. width: 100%;
  1273. height: 400px;
  1274. aspect-ratio: 3 / 4;
  1275. }
  1276. :deep(.el-upload-list--picture-card) {
  1277. width: 100%;
  1278. .el-upload-list__item {
  1279. width: 100%;
  1280. height: 400px;
  1281. aspect-ratio: 3 / 4;
  1282. margin: 0;
  1283. }
  1284. }
  1285. }
  1286. }
  1287. .upload-trigger-card {
  1288. display: flex;
  1289. flex-direction: column;
  1290. align-items: center;
  1291. justify-content: center;
  1292. width: 100%;
  1293. height: 100%;
  1294. font-size: 28px;
  1295. color: #8c939d;
  1296. }
  1297. /* el-upload 图片预览铺满容器 */
  1298. :deep(.el-upload-list--picture-card) {
  1299. .el-upload-list__item {
  1300. margin: 0;
  1301. overflow: hidden;
  1302. .el-upload-list__item-thumbnail {
  1303. width: 100%;
  1304. height: 100%;
  1305. //object-fit: fill;
  1306. }
  1307. }
  1308. .el-upload-list__item[data-status="ready"],
  1309. .el-upload-list__item.is-ready {
  1310. position: relative;
  1311. pointer-events: none;
  1312. cursor: not-allowed;
  1313. opacity: 0.6;
  1314. &::after {
  1315. position: absolute;
  1316. inset: 0;
  1317. z-index: 1;
  1318. content: "";
  1319. background-color: rgb(0 0 0 / 30%);
  1320. }
  1321. .el-upload-list__item-actions {
  1322. pointer-events: none;
  1323. opacity: 0.5;
  1324. }
  1325. }
  1326. .el-upload-list__item:hover .el-upload-list__item-status-label {
  1327. display: inline-flex !important;
  1328. opacity: 1 !important;
  1329. }
  1330. .el-upload-list__item.is-success:focus .el-upload-list__item-status-label {
  1331. display: inline-flex !important;
  1332. opacity: 1 !important;
  1333. }
  1334. .el-icon--close-tip {
  1335. display: none !important;
  1336. }
  1337. }
  1338. </style>