index.vue 13 KB

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