iconEdit.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <template>
  2. <div class="icon-edit-page">
  3. <!-- Header -->
  4. <div class="header">
  5. <div class="logo">
  6. <img src="@/assets/images/home/logo@2x.png" alt="STORLEAD" />
  7. </div>
  8. <div class="user-info">
  9. <img src="@/assets/images/home/Group@2x.png" alt="User" class="user-avatar" />
  10. <span class="username">祝小清</span>
  11. </div>
  12. </div>
  13. <!-- Main Content -->
  14. <div class="main-content">
  15. <div class="section" v-for="app in appList" :key="app.appId">
  16. <h2 class="section-title">{{ app.appName }}</h2>
  17. <div class="icon-grid">
  18. <div
  19. class="icon-item"
  20. v-for="page in app.appPages"
  21. :key="page.pageId"
  22. @click="handleIconClick(page)"
  23. >
  24. <div class="icon-wrapper">
  25. <img
  26. :src="getIconPath(page.iconName || getDefaultIcon(page.appName))"
  27. :alt="page.appName"
  28. />
  29. <div class="edit-overlay">
  30. <el-icon><Edit /></el-icon>
  31. <span>编辑</span>
  32. </div>
  33. </div>
  34. <span class="icon-label">{{ page.appName }}</span>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. <!-- Icon Select Dialog -->
  40. <HomeIconSelect
  41. v-model="iconSelectVisible"
  42. :current-icon="currentIconName"
  43. @confirm="handleIconConfirm"
  44. />
  45. </div>
  46. </template>
  47. <script setup name="IconEdit" lang="ts">
  48. import { ref, onMounted } from 'vue';
  49. import { Edit } from '@element-plus/icons-vue';
  50. import { ElMessage } from 'element-plus';
  51. import { getHomeApp, updateIcon } from '@/api/app';
  52. import HomeIconSelect from '@/components/HomeIconSelect/index.vue';
  53. import { getIconPath as getIconPathUtil } from '@/assets/homeIcon/iconUtils';
  54. interface AppPage {
  55. pageId: number;
  56. appName: string;
  57. iconName?: string;
  58. }
  59. interface AppInfo {
  60. appId: number;
  61. appName: string;
  62. appPages: AppPage[];
  63. }
  64. const appList = ref<AppInfo[]>([]);
  65. const iconSelectVisible = ref(false);
  66. const currentEditingPage = ref<AppPage | null>(null);
  67. const currentIconName = ref<string>('');
  68. // 默认图标映射(中文名称到英文图标名称)
  69. const defaultIconMap: Record<string, string> = {
  70. '我的目标': 'my_goals',
  71. '我的任务': 'my_tasks',
  72. '@我的任务': 'at_my_tasks',
  73. '我的简报': 'my_briefing',
  74. '简报草稿': 'briefing_draft',
  75. '个人绩效': 'personal_performance',
  76. '我的线索': 'my_leads',
  77. '公共线索': 'public_leads',
  78. '全部客户': 'all_customers',
  79. '公海客户': 'public_sea_customers',
  80. '重点客户': 'key_customers',
  81. '跟进记录': 'follow_up_records',
  82. '联系人': 'contacts',
  83. '我的商机': 'my_opportunities',
  84. '我的订单': 'my_orders',
  85. '全部任务': 'all_tasks',
  86. '工资条': 'payslip',
  87. '月考勤报表': 'monthly_attendance_report',
  88. '假期余额': 'leave_balance',
  89. '社保缴纳记录': 'social_security_payment_records',
  90. '公积金缴纳记录': 'provident_fund_payment_records',
  91. '指挥中心': 'command_center',
  92. '数据中心': 'data_center',
  93. '任务': 'tasks',
  94. '测试': 'test',
  95. '我的项目': 'my_projects',
  96. '采购管理': 'procurement_management'
  97. };
  98. // 获取默认图标名称
  99. const getDefaultIcon = (appName: string): string => {
  100. return defaultIconMap[appName] || 'my_goals';
  101. };
  102. // 获取图标路径
  103. const getIconPath = (iconName: string): string => {
  104. return getIconPathUtil(iconName);
  105. };
  106. // 点击图标
  107. const handleIconClick = (page: AppPage) => {
  108. currentEditingPage.value = page;
  109. currentIconName.value = page.iconName || getDefaultIcon(page.appName);
  110. iconSelectVisible.value = true;
  111. };
  112. // 确认选择图标
  113. const handleIconConfirm = async (iconName: string) => {
  114. if (!currentEditingPage.value) return;
  115. try {
  116. await updateIcon({
  117. id: currentEditingPage.value.pageId,
  118. iconName: iconName
  119. });
  120. // 更新本地数据
  121. if (currentEditingPage.value) {
  122. currentEditingPage.value.iconName = iconName;
  123. }
  124. ElMessage.success('图标更新成功');
  125. iconSelectVisible.value = false;
  126. currentEditingPage.value = null;
  127. } catch (error) {
  128. console.error('更新图标失败:', error);
  129. ElMessage.error('图标更新失败');
  130. }
  131. };
  132. // 初始化数据
  133. const initData = async () => {
  134. try {
  135. const res = await getHomeApp();
  136. if (res.result) {
  137. appList.value = res.result;
  138. }
  139. } catch (error) {
  140. console.error('Failed to get home app list:', error);
  141. }
  142. };
  143. onMounted(() => {
  144. initData();
  145. });
  146. </script>
  147. <style scoped lang="scss">
  148. .icon-edit-page {
  149. min-height: 100vh;
  150. background: linear-gradient(180deg, #F5F7FA 0%, #FFFFFF 100%);
  151. overflow-y: scroll;
  152. }
  153. .header {
  154. position: fixed;
  155. top: 0;
  156. left: 0;
  157. right: 0;
  158. z-index: 100;
  159. display: flex;
  160. justify-content: space-between;
  161. align-items: center;
  162. padding: 20px 40px;
  163. background: linear-gradient(90deg, #1E88E5 0%, #42A5F5 100%);
  164. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  165. .logo {
  166. img {
  167. height: 32px;
  168. }
  169. }
  170. .user-info {
  171. display: flex;
  172. align-items: center;
  173. gap: 12px;
  174. color: white;
  175. cursor: pointer;
  176. .user-avatar {
  177. width: 32px;
  178. height: 32px;
  179. border-radius: 50%;
  180. border: 2px solid rgba(255, 255, 255, 0.3);
  181. }
  182. .username {
  183. font-size: 14px;
  184. font-weight: 500;
  185. }
  186. }
  187. }
  188. .main-content {
  189. max-width: 1400px;
  190. margin: 0 auto;
  191. padding: 92px 20px 40px 20px;
  192. }
  193. .section {
  194. margin-bottom: 48px;
  195. .section-title {
  196. font-size: 18px;
  197. font-weight: 600;
  198. color: #333;
  199. margin-bottom: 24px;
  200. padding-left: 12px;
  201. border-left: 4px solid #1E88E5;
  202. }
  203. .icon-grid {
  204. display: grid;
  205. grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  206. gap: 32px 24px;
  207. background: white;
  208. padding: 32px;
  209. border-radius: 12px;
  210. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  211. @media (max-width: 768px) {
  212. grid-template-columns: repeat(4, 1fr);
  213. gap: 24px 16px;
  214. padding: 24px;
  215. }
  216. @media (max-width: 480px) {
  217. grid-template-columns: repeat(3, 1fr);
  218. gap: 20px 12px;
  219. padding: 20px;
  220. }
  221. }
  222. .icon-item {
  223. display: flex;
  224. flex-direction: column;
  225. align-items: center;
  226. gap: 12px;
  227. cursor: pointer;
  228. transition: transform 0.2s ease;
  229. &:hover {
  230. transform: translateY(-4px);
  231. .icon-wrapper {
  232. .edit-overlay {
  233. opacity: 1;
  234. }
  235. }
  236. }
  237. .icon-wrapper {
  238. width: 64px;
  239. height: 64px;
  240. border-radius: 16px;
  241. display: flex;
  242. align-items: center;
  243. justify-content: center;
  244. transition: all 0.3s ease;
  245. position: relative;
  246. overflow: hidden;
  247. img {
  248. width: 64px;
  249. height: 64px;
  250. object-fit: contain;
  251. }
  252. .edit-overlay {
  253. position: absolute;
  254. top: 0;
  255. left: 0;
  256. right: 0;
  257. bottom: 0;
  258. background: rgba(0, 0, 0, 0.6);
  259. display: flex;
  260. flex-direction: column;
  261. align-items: center;
  262. justify-content: center;
  263. color: white;
  264. opacity: 0;
  265. transition: opacity 0.3s ease;
  266. border-radius: 16px;
  267. .el-icon {
  268. font-size: 20px;
  269. margin-bottom: 4px;
  270. }
  271. span {
  272. font-size: 12px;
  273. }
  274. }
  275. }
  276. .icon-label {
  277. font-size: 14px;
  278. color: #666;
  279. text-align: center;
  280. font-weight: 500;
  281. white-space: nowrap;
  282. }
  283. }
  284. }
  285. </style>