index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <template>
  2. <div class="collapsible-toolbar" :class="{ collapsed: isCollapsed }">
  3. <div class="toolbar-content" v-show="!isCollapsed">
  4. <div class="sidebar-content">
  5. <div class="sidebar-item" :class="{ active: activeSubmenu === 'interactive' }" @click="toggleSubmenu('interactive')">
  6. <svg class="item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  7. <circle cx="12" cy="12" r="3"/>
  8. <path d="M12 1v6m0 6v6M5.64 5.64l4.24 4.24m4. 4.24l4.24 4.24M1 12h6m6 0h6M5.64 18.36l4.24-4.24m4.24-4.24l4kt-4.24"/>
  9. </svg>
  10. <span class="item-label">{{ lang.ssInteract }}</span>
  11. </div>
  12. <div class="sidebar-item" @click="handleToolClick('h5page')">
  13. <svg class="item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  14. <circle cx="12" cy="12" r="10"/>
  15. <path d="M2 12h20"/>
  16. <path d="M12 2a15.3 15.3 0 014 10 15.3 15.3 0 01-4 10 15.3 15.3 0 01-4-10 15.3 15.3 0 014-10z"/>
  17. </svg>
  18. <span class="item-label">{{ lang.ssHPage }}</span>
  19. </div>
  20. <div class="sidebar-item" @click="handleToolClick('aiapp')">
  21. <svg class="item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  22. <rect x="3" y="3" width="7" height="7"/>
  23. <rect x="14" y="3" width="7" height="7"/>
  24. <rect x="14" y="14" width="7" height="7"/>
  25. <rect x="3" y="14" width="7" height="7"/>
  26. </svg>
  27. <span class="item-label">{{ lang.ssAiApp }}</span>
  28. </div>
  29. <div class="sidebar-item" @click="handleToolClick('video')">
  30. <svg class="item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  31. <rect x="3" y="4" width="18" height="16" rx="2" ry="2"/>
  32. <polygon points="10 9 16 12 10 15 10 9"/>
  33. </svg>
  34. <span class="item-label">{{ lang.ssVideo }}</span>
  35. </div>
  36. <div class="sidebar-item" @click="handleToolClick('creative')">
  37. <svg class="item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  38. <circle cx="12" cy="12" r="10"/>
  39. <line x1="12" y1="8" x2="12" y2="16"/>
  40. <line x1="8" y1="12" x2="16" y2="12"/>
  41. </svg>
  42. <span class="item-label">{{ lang.ssCreative }}</span>
  43. </div>
  44. <div class="sidebar-item" :class="{ active: activeSubmenu === 'contentlist' }" @click="toggleSubmenu('contentlist')" v-show="false">
  45. <svg class="item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  46. <path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/>
  47. <path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/>
  48. </svg>
  49. <span class="item-label">{{ lang.ssContentList }}</span>
  50. </div>
  51. </div>
  52. </div>
  53. <div class="submenu" :class="{ visible: activeSubmenu === 'interactive' }">
  54. <div class="submenu-item" @click="handleToolClick('choice')">
  55. <svg class="submenu-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  56. <circle cx="12" cy="12" r="10"/>
  57. <path d="M12 16v-4m0-4h.01"/>
  58. </svg>
  59. <span class="submenu-label">{{ lang.ssChoiceQ }}</span>
  60. </div>
  61. <div class="submenu-item" @click="handleToolClick('qa')">
  62. <svg class="submenu-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  63. <path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/>
  64. </svg>
  65. <span class="submenu-label">{{ lang.ssQandA }}</span>
  66. </div>
  67. </div>
  68. <div class="content-list-submenu" :class="{ visible: activeSubmenu === 'contentlist' }">
  69. <div v-if="contentList.length === 0" class="empty-state">
  70. <div class="empty-icon">📚</div>
  71. <div class="empty-title">{{ lang.ssNoLearn }}</div>
  72. <div class="empty-title">{{ lang.ssNeedUpload }}</div>
  73. </div>
  74. <div v-else class="content-list">
  75. <div
  76. v-for="(item, index) in contentList"
  77. :key="index"
  78. class="content-item"
  79. >
  80. <div class="content-main" @click="insertContent(item)">
  81. <svg class="content-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  82. <path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/>
  83. <path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/>
  84. </svg>
  85. <span class="content-label">{{ item.title }}</span>
  86. <span class="type-tag" :class="getTypeClass(item.tool)">{{ getTypeLabel(item.tool) }}</span>
  87. </div>
  88. <div class="content-actions">
  89. <template v-if="item.tool === 74 || item.tool === 75">
  90. <div class="action-btn" @click.stop="previewVideo(item)" :title="lang.ssPreview">
  91. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  92. <polygon points="5 3 19 12 5 21 5 3"/>
  93. </svg>
  94. </div>
  95. </template>
  96. <template v-if="item.tool !== 74 && item.tool !== 75 && item.tool !== 76">
  97. <div class="action-btn" @click.stop="editContent(item)" :title="lang.ssEdit">
  98. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  99. <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
  100. <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
  101. </svg>
  102. </div>
  103. </template>
  104. <template v-if="item.tool !== 76">
  105. <div class="action-btn" @click.stop="copyContent(item)" :title="lang.ssCopy">
  106. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  107. <rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
  108. <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
  109. </svg>
  110. </div>
  111. </template>
  112. <div class="action-btn delete" @click.stop="deleteContent(item)" :title="lang.ssDelete">
  113. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  114. <polyline points="3 6 5 6 21 6"/>
  115. <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>
  116. </svg>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. </template>
  124. <script lang="ts" setup>
  125. import { ref } from 'vue'
  126. import { storeToRefs } from 'pinia'
  127. import useCreateElement from '@/hooks/useCreateElement'
  128. import useSlideHandler from '@/hooks/useSlideHandler'
  129. import { useSlidesStore } from '@/store'
  130. import { lang } from '@/main'
  131. interface ContentItem {
  132. tool?: number
  133. title?: string
  134. url?: string
  135. id?: string
  136. }
  137. const props = withDefaults(defineProps<{
  138. defaultCollapsed?: boolean
  139. }>(), {
  140. defaultCollapsed: false
  141. })
  142. const emit = defineEmits<{
  143. (e: 'toggle', collapsed: boolean): void
  144. }>()
  145. const isCollapsed = ref(props.defaultCollapsed)
  146. const activeSubmenu = ref<string | null>(null)
  147. const contentList = ref<ContentItem[]>([])
  148. const slidesStore = useSlidesStore()
  149. const { currentSlide } = storeToRefs(slidesStore)
  150. const { createFrameElement } = useCreateElement()
  151. const { createSlide } = useSlideHandler()
  152. const toggleCollapse = () => {
  153. isCollapsed.value = !isCollapsed.value
  154. emit('toggle', isCollapsed.value)
  155. }
  156. const toggleSubmenu = (menu: string) => {
  157. if (activeSubmenu.value === menu) {
  158. activeSubmenu.value = null
  159. }
  160. else {
  161. activeSubmenu.value = menu
  162. if (menu === 'contentlist') {
  163. loadContentList()
  164. }
  165. }
  166. }
  167. const handleToolClick = (tool: string) => {
  168. interface ParentWindowWithToolList extends Window {
  169. addTool?: (id: number) => void;
  170. openVideoUploadDialog?: () => void;
  171. openApplicationCenter?: () => void;
  172. }
  173. const parentWindow = window.parent as ParentWindowWithToolList
  174. console.log('点击工具:', tool)
  175. if (tool === 'h5page') {
  176. parentWindow?.addTool?.(73)
  177. }
  178. else if (tool === 'aiapp') {
  179. parentWindow?.addTool?.(72)
  180. }
  181. else if (tool === 'video') {
  182. parentWindow?.openVideoUploadDialog?.()
  183. }
  184. else if (tool === 'creative') {
  185. parentWindow?.openApplicationCenter?.()
  186. }
  187. else if (tool === 'choice') {
  188. parentWindow?.addTool?.(45)
  189. }
  190. else if (tool === 'qa') {
  191. parentWindow?.addTool?.(15)
  192. }
  193. }
  194. const loadContentList = () => {
  195. try {
  196. interface ParentWindowWithToolList extends Window {
  197. pptToolList?: ContentItem[]
  198. }
  199. const parentWindow = window.parent as ParentWindowWithToolList
  200. contentList.value = parentWindow?.pptToolList || []
  201. }
  202. catch (error) {
  203. console.error('加载内容列表失败:', error)
  204. contentList.value = []
  205. }
  206. }
  207. const insertContent = (item: ContentItem) => {
  208. if (!item.tool || !item.url) return
  209. createFrameElement(item.url, item.tool)
  210. }
  211. const addContent = (data: ContentItem, type: number) => {
  212. // contentList.value.push(data)
  213. if (type === 2) {
  214. const elements = currentSlide.value?.elements || []
  215. const frameElement = elements.find((el: any) => el.type === 'frame' && (el.toolType === 45 || el.toolType === 15))
  216. if (frameElement) {
  217. slidesStore.updateElement({
  218. id: frameElement.id,
  219. props: { url: data.url }
  220. })
  221. }
  222. }
  223. else {
  224. createSlide()
  225. insertContent(data)
  226. }
  227. }
  228. Object.assign(window, { addContent, loadContentList })
  229. // window.loadContentList = loadContentList
  230. // window.addContent = addContent
  231. const previewVideo = (item: ContentItem) => {
  232. interface ParentWindowWithToolList extends Window {
  233. previewVideo?: (item: ContentItem) => void;
  234. }
  235. const parentWindow = window.parent as ParentWindowWithToolList
  236. parentWindow?.previewVideo?.(item)
  237. }
  238. const editContent = (item: ContentItem) => {
  239. interface ParentWindowWithToolList extends Window {
  240. toolBtn?: (action: number, id: string) => void;
  241. }
  242. const parentWindow = window.parent as ParentWindowWithToolList
  243. parentWindow?.toolBtn?.(0, item.id || '')
  244. }
  245. const copyContent = (item: ContentItem) => {
  246. interface ParentWindowWithToolList extends Window {
  247. toolBtn?: (action: number, id: string) => void;
  248. }
  249. const parentWindow = window.parent as ParentWindowWithToolList
  250. parentWindow?.toolBtn?.(1, item.id || '')
  251. }
  252. const deleteContent = (item: ContentItem) => {
  253. interface ParentWindowWithToolList extends Window {
  254. toolBtn?: (action: number, id: string) => void;
  255. }
  256. const parentWindow = window.parent as ParentWindowWithToolList
  257. parentWindow?.toolBtn?.(2, item.id || '')
  258. }
  259. const getTypeLabel = (type?: number) => {
  260. const typeMap: Record<number, string> = {
  261. 45: lang.ssChoiceQ,
  262. 15: lang.ssQATest,
  263. 72: lang.ssAiApp,
  264. 73: lang.ssHPage,
  265. 81: lang.ssHPage,
  266. 74: lang.ssVideo,
  267. 75: lang.lang == 'cn' ? lang.ssBiliVideo : lang.ssYouTube,
  268. 76: lang.ssCreative,
  269. 77: lang.ssEnglishSpeakingTool,
  270. 78: lang.ssVote,
  271. 79: lang.ssPhoto,
  272. }
  273. return typeMap[type || 0] || lang.ssUnknown
  274. }
  275. const getTypeClass = (type?: number) => {
  276. const classMap: Record<number, string> = {
  277. 45: 'type-choice',
  278. 15: 'type-question',
  279. 72: 'type-ai',
  280. 73: 'type-h5',
  281. 74: 'type-video',
  282. 75: 'type-bilibili',
  283. 76: 'type-app-center'
  284. }
  285. return classMap[type || 0] || 'type-default'
  286. }
  287. </script>
  288. <style lang="scss" scoped>
  289. .collapsible-toolbar {
  290. width: 100%;
  291. height: 100%;
  292. display: flex;
  293. background: #fff;
  294. border-right: 1px solid #e5e7eb;
  295. transition: width 0.3s ease;
  296. }
  297. .toolbar-content {
  298. flex: 1;
  299. overflow: hidden;
  300. padding: 16px 8px;
  301. }
  302. .sidebar-content {
  303. display: flex;
  304. flex-direction: column;
  305. gap: 6px;
  306. width: 84px;
  307. position: relative;
  308. }
  309. .sidebar-item {
  310. width: 84px;
  311. padding: 12px 8px;
  312. border-radius: 12px;
  313. display: flex;
  314. flex-direction: column;
  315. align-items: center;
  316. justify-content: center;
  317. gap: 6px;
  318. cursor: pointer;
  319. transition: all 0.2s;
  320. position: relative;
  321. &:hover {
  322. background: #f3f4f6;
  323. }
  324. &:active {
  325. background: #e5e7eb;
  326. }
  327. &.active {
  328. background: #eef3ff;
  329. box-shadow: 0 2px 8px rgba(40, 92, 245, 0.15);
  330. }
  331. &.active::after {
  332. content: '';
  333. position: absolute;
  334. left: -8px;
  335. top: 50%;
  336. transform: translateY(-50%);
  337. width: 4px;
  338. height: 32px;
  339. background: #285cf5;
  340. border-radius: 0 2px 2px 0;
  341. }
  342. }
  343. .item-icon {
  344. width: 22px;
  345. height: 22px;
  346. flex-shrink: 0;
  347. color: #6b7280;
  348. }
  349. .sidebar-item:hover .item-icon,
  350. .sidebar-item.active .item-icon {
  351. color: #285cf5;
  352. }
  353. .item-label {
  354. font-size: 11px;
  355. font-weight: 500;
  356. color: #6b7280;
  357. text-align: center;
  358. }
  359. .sidebar-item:hover .item-label,
  360. .sidebar-item.active .item-label {
  361. color: #285cf5;
  362. font-weight: 600;
  363. }
  364. .submenu {
  365. width: 0;
  366. min-width: 0;
  367. overflow: hidden;
  368. transition: all 0.3s ease;
  369. background: #fff;
  370. border-radius: 12px;
  371. z-index: 100;
  372. &.visible {
  373. width: 160px;
  374. min-width: 160px;
  375. padding: 8px 0;
  376. }
  377. }
  378. .submenu-item {
  379. display: flex;
  380. align-items: center;
  381. gap: 12px;
  382. padding: 10px 16px;
  383. cursor: pointer;
  384. transition: all 0.2s ease;
  385. font-size: 13px;
  386. color: #6b7280;
  387. border-radius: 8px;
  388. margin: 4px 8px;
  389. &:hover {
  390. background-color: #f3f4f6;
  391. color: #285cf5;
  392. }
  393. &:active {
  394. background-color: #e5e7eb;
  395. }
  396. }
  397. .submenu-icon {
  398. width: 18px;
  399. height: 18px;
  400. flex-shrink: 0;
  401. color: #9ca3af;
  402. }
  403. .submenu-item:hover .submenu-icon {
  404. color: #285cf5;
  405. }
  406. .submenu-label {
  407. font-size: 13px;
  408. color: #6b7280;
  409. }
  410. .submenu-item:hover .submenu-label {
  411. color: #285cf5;
  412. }
  413. .content-list-submenu {
  414. width: 0;
  415. min-width: 0;
  416. overflow: hidden;
  417. transition: all 0.3s ease;
  418. background: #fff;
  419. border-radius: 12px;
  420. z-index: 100;
  421. &.visible {
  422. width: 380px;
  423. min-width: 380px;
  424. padding: 8px 0;
  425. }
  426. }
  427. .empty-state {
  428. text-align: center;
  429. padding: 20px 10px;
  430. color: #666;
  431. }
  432. .empty-icon {
  433. font-size: 32px;
  434. margin-bottom: 8px;
  435. }
  436. .empty-title {
  437. font-size: 12px;
  438. color: #999;
  439. }
  440. .content-list {
  441. max-height: 400px;
  442. overflow-y: auto;
  443. padding: 4px 0;
  444. &::-webkit-scrollbar {
  445. width: 4px;
  446. }
  447. &::-webkit-scrollbar-track {
  448. background: #f1f1f1;
  449. border-radius: 2px;
  450. }
  451. &::-webkit-scrollbar-thumb {
  452. background: #c1c1c1;
  453. border-radius: 2px;
  454. &:hover {
  455. background: #a8a8a8;
  456. }
  457. }
  458. }
  459. .content-item {
  460. display: flex;
  461. align-items: center;
  462. justify-content: space-between;
  463. padding: 8px 12px;
  464. border-radius: 8px;
  465. margin: 2px 8px;
  466. position: relative;
  467. transition: all 0.2s ease;
  468. &:hover {
  469. background-color: #f8f9fa;
  470. }
  471. }
  472. .content-main {
  473. display: flex;
  474. align-items: center;
  475. gap: 8px;
  476. flex: 1;
  477. min-width: 0;
  478. cursor: pointer;
  479. padding: 4px;
  480. border-radius: 6px;
  481. transition: all 0.2s ease;
  482. &:hover {
  483. background-color: #f3f4f6;
  484. }
  485. }
  486. .content-icon {
  487. width: 16px;
  488. height: 16px;
  489. flex-shrink: 0;
  490. color: #9ca3af;
  491. }
  492. .content-main:hover .content-icon {
  493. color: #285cf5;
  494. }
  495. .content-label {
  496. flex: 1;
  497. font-size: 13px;
  498. color: #6b7280;
  499. white-space: nowrap;
  500. overflow: hidden;
  501. text-overflow: ellipsis;
  502. }
  503. .content-main:hover .content-label {
  504. color: #285cf5;
  505. }
  506. .content-actions {
  507. display: flex;
  508. align-items: center;
  509. gap: 4px;
  510. }
  511. .action-btn {
  512. width: 28px;
  513. height: 28px;
  514. display: flex;
  515. align-items: center;
  516. justify-content: center;
  517. border-radius: 4px;
  518. cursor: pointer;
  519. transition: all 0.2s ease;
  520. color: #9ca3af;
  521. svg {
  522. width: 14px;
  523. height: 14px;
  524. }
  525. &:hover {
  526. background-color: #f3f4f6;
  527. color: #285cf5;
  528. }
  529. &.delete {
  530. &:hover {
  531. background-color: #fee2e2;
  532. color: #ef4444;
  533. }
  534. }
  535. }
  536. .type-tag {
  537. padding: 2px 6px;
  538. border-radius: 4px;
  539. font-size: 10px;
  540. font-weight: 500;
  541. color: #fff;
  542. white-space: nowrap;
  543. flex-shrink: 0;
  544. &.type-choice {
  545. background-color: #4caf50;
  546. }
  547. &.type-question {
  548. background-color: #ff9800;
  549. }
  550. &.type-ai {
  551. background-color: #2196f3;
  552. }
  553. &.type-h5 {
  554. background-color: #9c27b0;
  555. }
  556. &.type-video {
  557. background-color: #f44336;
  558. }
  559. &.type-bilibili {
  560. background-color: #fb7299;
  561. }
  562. &.type-default {
  563. background-color: #757575;
  564. }
  565. &.type-app-center {
  566. background-color: #673ab7;
  567. }
  568. }
  569. </style>