index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <div class="floor-ad-page">
  3. <div class="floor-ad-container">
  4. <div class="ad-card">
  5. <!-- 标签页切换 -->
  6. <el-tabs v-model="activeTab" @tab-change="handleTabChange">
  7. <el-tab-pane label="首页三联广告" name="triple" />
  8. <el-tab-pane label="首页图标广告" name="icon" />
  9. <el-tab-pane label="首页logo" name="logo" />
  10. <el-tab-pane label="首页联系电话" name="contact" />
  11. </el-tabs>
  12. <!-- 三联广告展示区 -->
  13. <div v-if="activeTab === 'triple'" class="ad-preview triple-preview">
  14. <div class="triple-grid">
  15. <div
  16. v-for="(item, index) in adList"
  17. :key="item.id"
  18. class="triple-item"
  19. :class="{ active: selectedIndex === index }"
  20. @click="selectAd(index)"
  21. >
  22. <el-image :src="item.imageUrl" fit="contain" class="triple-image">
  23. <template #error>
  24. <div class="image-slot">
  25. <el-icon><Picture /></el-icon>
  26. </div>
  27. </template>
  28. </el-image>
  29. </div>
  30. </div>
  31. </div>
  32. <!-- 图标广告展示区 -->
  33. <div v-if="activeTab === 'icon'" class="ad-preview icon-preview">
  34. <div class="icon-grid">
  35. <div
  36. v-for="(item, index) in adList"
  37. :key="item.id"
  38. class="icon-item"
  39. :class="{ active: selectedIndex === index }"
  40. @click="selectAd(index)"
  41. >
  42. <div class="icon-img">
  43. <el-image :src="item.imageUrl" fit="contain" class="icon-image">
  44. <template #error
  45. ><el-icon size="32"><Picture /></el-icon
  46. ></template>
  47. </el-image>
  48. </div>
  49. <span class="icon-text">{{ item.title }}</span>
  50. </div>
  51. </div>
  52. </div>
  53. <!-- Logo展示区 -->
  54. <div v-if="activeTab === 'logo'" class="ad-preview logo-preview">
  55. <div class="logo-item" @click="selectAd(0)" :class="{ active: selectedIndex === 0 }">
  56. <el-image v-if="adList.length > 0" :src="adList[0]?.imageUrl" fit="contain" class="logo-image">
  57. <template #error>
  58. <div class="image-slot">
  59. <el-icon><Picture /></el-icon>
  60. </div>
  61. </template>
  62. </el-image>
  63. </div>
  64. </div>
  65. <!-- 联系电话展示区 -->
  66. <div v-if="activeTab === 'contact'" class="ad-preview contact-preview">
  67. <el-button type="default" @click="handleAddContact">新增首页图标广告</el-button>
  68. <div class="contact-list">
  69. <div
  70. v-for="(item, index) in adList"
  71. :key="item.id"
  72. class="contact-item"
  73. :class="{ active: selectedContactIndex === index }"
  74. @click="selectContact(index)"
  75. >
  76. <div class="contact-info">
  77. <span class="contact-label">{{ item.title }}</span>
  78. <span class="contact-value">{{ item.remark }}</span>
  79. </div>
  80. </div>
  81. </div>
  82. </div>
  83. <div class="ad-divider"></div>
  84. <!-- 联系电话编辑表单 -->
  85. <div v-if="activeTab === 'contact' && selectedContactIndex !== null && adList.length > 0" class="ad-form">
  86. <el-form :model="contactForm" label-width="50px">
  87. <el-form-item label="文字:">
  88. <el-input v-model="contactForm.title" placeholder="请输入文字" style="max-width: 500px" />
  89. </el-form-item>
  90. <el-form-item label="排序:">
  91. <el-input-number v-model="contactForm.sort" :min="0" :max="999" controls-position="right" />
  92. </el-form-item>
  93. <el-form-item label="电话:">
  94. <el-input v-model="contactForm.remark" placeholder="请输入电话" style="max-width: 500px" />
  95. </el-form-item>
  96. <el-form-item label=" ">
  97. <el-button type="primary" @click="handleSubmitContactEdit">提 交</el-button>
  98. </el-form-item>
  99. </el-form>
  100. </div>
  101. <!-- 编辑表单 -->
  102. <div v-if="selectedIndex !== null && adList.length > 0 && activeTab !== 'contact'" class="ad-form">
  103. <el-form ref="formRef" :model="form" label-width="50px">
  104. <el-row :gutter="20">
  105. <el-col :span="12">
  106. <el-form-item label="文字:">
  107. <el-input v-model="form.title" placeholder="请输入文字" />
  108. </el-form-item>
  109. </el-col>
  110. <el-col :span="12">
  111. <el-form-item label="链接:">
  112. <el-input v-model="form.link" placeholder="请输入链接地址" />
  113. </el-form-item>
  114. </el-col>
  115. </el-row>
  116. <el-form-item label="图片:">
  117. <upload-image v-model="form.imageUrl" :limit="1" />
  118. <div class="upload-tip">
  119. 请上传大小不超过 <span class="tip-highlight">5MB</span> 格式为 <span class="tip-highlight">png/jpg/jpeg</span> 的文件
  120. </div>
  121. </el-form-item>
  122. <el-form-item label="描述:">
  123. <el-input v-model="form.remark" type="textarea" :rows="3" placeholder="请输入描述" style="max-width: 500px" />
  124. </el-form-item>
  125. <el-form-item label=" ">
  126. <el-button type="primary" @click="handleSubmit">提 交</el-button>
  127. </el-form-item>
  128. </el-form>
  129. </div>
  130. <!-- 联系电话编辑对话框 -->
  131. <el-dialog v-model="contactDialog.visible" title="编辑联系电话" width="500px" append-to-body>
  132. <el-form :model="contactForm" label-width="80px">
  133. <el-form-item label="标题:">
  134. <el-input v-model="contactForm.title" placeholder="如:售后" />
  135. </el-form-item>
  136. <el-form-item label="电话:">
  137. <el-input v-model="contactForm.remark" placeholder="如:400-111-0027" />
  138. </el-form-item>
  139. </el-form>
  140. <template #footer>
  141. <el-button @click="contactDialog.visible = false">取消</el-button>
  142. <el-button type="primary" @click="handleSubmitContact">确定</el-button>
  143. </template>
  144. </el-dialog>
  145. </div>
  146. </div>
  147. </div>
  148. </template>
  149. <script setup name="IndustrialFloorAd" lang="ts">
  150. import { ref, reactive, onMounted } from 'vue';
  151. import { ElMessage } from 'element-plus';
  152. import { Picture } from '@element-plus/icons-vue';
  153. import { listAdContent, updateAdContent, addAdContent } from '@/api/ad/content';
  154. import dayjs from 'dayjs';
  155. const activeTab = ref('triple');
  156. const selectedIndex = ref<number | null>(null);
  157. // 广告类型映射(工业装修专用,避免和平台装修冲突)
  158. const adTypeMap: Record<string, string> = {
  159. triple: 'industrial_ad_triple',
  160. icon: 'industrial_ad_icon',
  161. logo: 'industrial_ad_logo',
  162. contact: 'industrial_ad_contact'
  163. };
  164. const adList = ref<any[]>([]);
  165. const loading = ref(false);
  166. const form = ref({
  167. id: undefined as number | undefined,
  168. adType: '',
  169. title: '',
  170. remark: '',
  171. link: '',
  172. imageUrl: '',
  173. sort: 0,
  174. status: 1,
  175. startTime: '',
  176. endTime: ''
  177. });
  178. // 联系电话对话框
  179. const contactDialog = reactive({ visible: false });
  180. const contactForm = ref({ id: undefined as number | undefined, title: '', remark: '', sort: 0 });
  181. const selectedContactIndex = ref<number | null>(null);
  182. const loadAdList = async () => {
  183. loading.value = true;
  184. try {
  185. const adType = adTypeMap[activeTab.value];
  186. const res = await listAdContent({ adType, pageSize: 100 });
  187. adList.value = res.rows || [];
  188. selectedIndex.value = null;
  189. selectedContactIndex.value = null;
  190. } catch (error) {
  191. console.error('加载广告列表失败', error);
  192. adList.value = [];
  193. } finally {
  194. loading.value = false;
  195. }
  196. };
  197. const handleTabChange = () => {
  198. selectedIndex.value = null;
  199. loadAdList();
  200. };
  201. const selectAd = (index: number) => {
  202. selectedIndex.value = index;
  203. loadFormData();
  204. };
  205. const loadFormData = () => {
  206. if (selectedIndex.value === null || !adList.value[selectedIndex.value]) return;
  207. const item = adList.value[selectedIndex.value];
  208. form.value = {
  209. id: item.id,
  210. adType: adTypeMap[activeTab.value],
  211. title: item.title || '',
  212. remark: item.remark || '',
  213. link: item.link || '',
  214. imageUrl: item.imageUrl || '',
  215. sort: item.sort || 0,
  216. status: item.status ?? 1,
  217. startTime: item.startTime ? dayjs(item.startTime).format('YYYY-MM-DD') : '',
  218. endTime: item.endTime ? dayjs(item.endTime).format('YYYY-MM-DD') : ''
  219. };
  220. };
  221. const handleSubmit = async () => {
  222. try {
  223. if (!form.value.startTime) form.value.startTime = dayjs().format('YYYY-MM-DD');
  224. if (!form.value.endTime) form.value.endTime = dayjs().add(365, 'day').format('YYYY-MM-DD');
  225. await updateAdContent(form.value);
  226. ElMessage.success('提交成功');
  227. await loadAdList();
  228. } catch (error) {
  229. ElMessage.error('保存失败');
  230. }
  231. };
  232. const handleAddContact = () => {
  233. contactForm.value = { id: undefined, title: '', remark: '', sort: 0 };
  234. contactDialog.visible = true;
  235. };
  236. // 选择联系电话
  237. const selectContact = (index: number) => {
  238. selectedContactIndex.value = index;
  239. const item = adList.value[index];
  240. contactForm.value = {
  241. id: item.id,
  242. title: item.title || '',
  243. remark: item.remark || '',
  244. sort: item.sort || 0
  245. };
  246. };
  247. // 提交联系电话编辑
  248. const handleSubmitContactEdit = async () => {
  249. try {
  250. await updateAdContent({
  251. id: contactForm.value.id,
  252. adType: adTypeMap.contact,
  253. title: contactForm.value.title,
  254. remark: contactForm.value.remark,
  255. sort: contactForm.value.sort,
  256. startTime: dayjs().format('YYYY-MM-DD'),
  257. endTime: dayjs().add(365, 'day').format('YYYY-MM-DD'),
  258. status: 1
  259. });
  260. ElMessage.success('提交成功');
  261. await loadAdList();
  262. } catch (error) {
  263. ElMessage.error('保存失败');
  264. }
  265. };
  266. const handleSubmitContact = async () => {
  267. try {
  268. const data = {
  269. adType: adTypeMap.contact,
  270. title: contactForm.value.title,
  271. remark: contactForm.value.remark,
  272. startTime: dayjs().format('YYYY-MM-DD'),
  273. endTime: dayjs().add(365, 'day').format('YYYY-MM-DD'),
  274. status: 1
  275. };
  276. if (contactForm.value.id) {
  277. await updateAdContent({ ...data, id: contactForm.value.id });
  278. } else {
  279. await addAdContent(data);
  280. }
  281. ElMessage.success('保存成功');
  282. contactDialog.visible = false;
  283. await loadAdList();
  284. } catch (error) {
  285. ElMessage.error('保存失败');
  286. }
  287. };
  288. onMounted(() => {
  289. loadAdList();
  290. });
  291. </script>
  292. <style scoped lang="scss">
  293. .floor-ad-page {
  294. min-height: 100vh;
  295. background: #f5f5f5;
  296. padding: 20px;
  297. }
  298. .floor-ad-container {
  299. max-width: 1200px;
  300. margin: 0 auto;
  301. }
  302. .ad-card {
  303. background: #fff;
  304. border-radius: 4px;
  305. padding: 20px;
  306. :deep(.el-tabs__nav-wrap::after) {
  307. height: 1px;
  308. background-color: #e4e7ed;
  309. }
  310. :deep(.el-tabs__item) {
  311. font-size: 14px;
  312. color: #666;
  313. padding: 0 20px;
  314. &.is-active {
  315. color: #409eff;
  316. }
  317. }
  318. :deep(.el-tabs__active-bar) {
  319. height: 2px;
  320. }
  321. }
  322. .ad-preview {
  323. margin: 20px 0;
  324. padding-bottom: 20px;
  325. }
  326. .ad-divider {
  327. border-bottom: 1px solid #e4e7ed;
  328. margin-bottom: 20px;
  329. }
  330. .triple-preview {
  331. .triple-grid {
  332. display: flex;
  333. justify-content: flex-start;
  334. gap: 15px;
  335. }
  336. .triple-item {
  337. width: 200px;
  338. height: 80px;
  339. flex-shrink: 0;
  340. cursor: pointer;
  341. border: 2px solid transparent;
  342. &:hover {
  343. opacity: 0.9;
  344. }
  345. &.active {
  346. border-color: #409eff;
  347. }
  348. .triple-image {
  349. width: 100%;
  350. height: 100%;
  351. }
  352. }
  353. }
  354. .icon-preview {
  355. .icon-grid {
  356. display: flex;
  357. justify-content: flex-start;
  358. gap: 10px;
  359. }
  360. .icon-item {
  361. display: flex;
  362. flex-direction: column;
  363. align-items: center;
  364. padding: 10px;
  365. cursor: pointer;
  366. border-radius: 4px;
  367. border: 2px solid transparent;
  368. &:hover {
  369. background: #f5f5f5;
  370. }
  371. &.active {
  372. border-color: #409eff;
  373. background: #ecf5ff;
  374. }
  375. .icon-img {
  376. width: 50px;
  377. height: 50px;
  378. display: flex;
  379. align-items: center;
  380. justify-content: center;
  381. margin-bottom: 6px;
  382. .icon-image {
  383. width: 100%;
  384. height: 100%;
  385. }
  386. }
  387. .icon-text {
  388. font-size: 12px;
  389. color: #333;
  390. }
  391. }
  392. }
  393. .logo-preview {
  394. .logo-item {
  395. width: 400px;
  396. height: 80px;
  397. cursor: pointer;
  398. border: 2px solid transparent;
  399. &.active {
  400. border-color: #409eff;
  401. }
  402. .logo-image {
  403. width: 100%;
  404. height: 100%;
  405. }
  406. }
  407. }
  408. .contact-preview {
  409. .contact-list {
  410. display: flex;
  411. gap: 30px;
  412. margin-top: 15px;
  413. }
  414. .contact-item {
  415. cursor: pointer;
  416. padding: 8px 12px;
  417. border-radius: 4px;
  418. border: 2px solid transparent;
  419. &:hover {
  420. background: #f5f5f5;
  421. }
  422. &.active {
  423. border-color: #409eff;
  424. background: #ecf5ff;
  425. }
  426. .contact-info {
  427. display: flex;
  428. flex-direction: column;
  429. .contact-label {
  430. font-size: 12px;
  431. color: #999;
  432. margin-bottom: 4px;
  433. }
  434. .contact-value {
  435. font-size: 14px;
  436. color: #333;
  437. }
  438. }
  439. }
  440. }
  441. .image-slot {
  442. display: flex;
  443. justify-content: center;
  444. align-items: center;
  445. width: 100%;
  446. height: 100%;
  447. background: #f5f7fa;
  448. color: #909399;
  449. font-size: 24px;
  450. }
  451. .ad-form {
  452. padding-top: 20px;
  453. .upload-tip {
  454. font-size: 12px;
  455. color: #999;
  456. margin-top: 8px;
  457. .tip-highlight {
  458. color: #f56c6c;
  459. }
  460. }
  461. }
  462. </style>