index.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import { css, cx } from "@linaria/core";
  2. import { Button, Tooltip } from "ant-design-vue";
  3. import { computed, reactive } from "vue";
  4. import {
  5. IconAi,
  6. IconApplication,
  7. IconCloud,
  8. IconImage,
  9. IconText,
  10. IconTpl,
  11. IconVideo,
  12. } from "@/assets/icons";
  13. import { IconCube, IconLayers } from "@queenjs/icons";
  14. import { defineUI } from "queenjs";
  15. import { CompTree } from "../SliderRight/CompTree";
  16. import AiText from "./AiText";
  17. import Application from "./Application";
  18. import CustomComps from "./CustomComps";
  19. import { Sources } from "./Sources";
  20. import Templates from "./Templates";
  21. import Text from "./Text";
  22. const tabs = [
  23. {
  24. title: "模板",
  25. icon: IconTpl,
  26. component: Templates,
  27. },
  28. {
  29. title: "组合",
  30. icon: IconCube,
  31. content: [
  32. {
  33. title: "平台",
  34. component: CustomComps,
  35. props: { compType: "senior" },
  36. },
  37. {
  38. title: "我的",
  39. component: CustomComps,
  40. props: { compType: "user" },
  41. },
  42. ],
  43. },
  44. {
  45. title: "文字",
  46. icon: IconText,
  47. component: Text,
  48. },
  49. {
  50. title: "图片",
  51. icon: IconImage,
  52. component: Sources,
  53. props: { sourceType: "Image", sourceFrom: "system" },
  54. },
  55. // {
  56. // title: "形状",
  57. // icon: IconShape,
  58. // component: Shapes,
  59. // },
  60. {
  61. title: "视频",
  62. icon: IconVideo,
  63. component: Sources,
  64. props: { sourceType: "Video", sourceFrom: "system" },
  65. },
  66. {
  67. title: "组件",
  68. icon: IconApplication,
  69. component: Application,
  70. },
  71. {
  72. title: "已上传",
  73. icon: IconCloud,
  74. content: [
  75. {
  76. title: "图片",
  77. component: Sources,
  78. props: { sourceType: "Image", sourceFrom: "user" },
  79. },
  80. {
  81. title: "视频",
  82. component: Sources,
  83. props: { sourceType: "Video", sourceFrom: "user" },
  84. },
  85. ],
  86. },
  87. {
  88. title: "AI",
  89. icon: IconAi,
  90. component: AiText,
  91. },
  92. {
  93. title: "图层",
  94. icon: () => <IconLayers class="text-24px transform scale-170" />,
  95. component: CompTree,
  96. },
  97. ];
  98. export default defineUI({
  99. setup() {
  100. // @ts-ignore
  101. const state = reactive({
  102. tabIndex: 0,
  103. compIndexs: [0, 0, 0, 0, 0, 0, 0],
  104. currentTab: computed(() => {
  105. return tabs[state.tabIndex];
  106. }),
  107. currCompIndex: computed(() => {
  108. return state.compIndexs[state.tabIndex];
  109. }),
  110. });
  111. return () => {
  112. const { tabIndex, currentTab, currCompIndex } = state;
  113. const currComp = currentTab.component
  114. ? currentTab
  115. : currentTab.content?.[state.currCompIndex];
  116. return (
  117. <div class="h-full flex">
  118. <div class="flex flex-col w-70px py-16px border-right !border-2px">
  119. {tabs.map((record, index) => {
  120. return (
  121. <>
  122. {index === tabs.length - 2 && <div class="flex-1"></div>}
  123. <div
  124. key={index}
  125. class={cx(
  126. tabItem,
  127. "relative mt-10px py-8px text-center cursor-pointer text-light-50 transition",
  128. state.tabIndex == index && "active"
  129. )}
  130. onClick={() => (state.tabIndex = index)}
  131. >
  132. <Tooltip title={record.title} placement="right">
  133. <record.icon class="text-28px p-10px" />
  134. </Tooltip>
  135. </div>
  136. </>
  137. );
  138. })}
  139. </div>
  140. <div class="flex-1 h-1/1 overflow-hidden flex flex-col">
  141. {currentTab.content && (
  142. <div class="mt-5px ml-10px space-x-10px">
  143. {currentTab.content?.map((item: any, index: number) => (
  144. <Button
  145. key={index}
  146. type="text"
  147. class={cx(
  148. "transition",
  149. currCompIndex == index && "font-bold"
  150. )}
  151. onClick={() => (state.compIndexs[tabIndex] = index)}
  152. >
  153. {item?.title}
  154. </Button>
  155. ))}
  156. </div>
  157. )}
  158. <currComp.component
  159. class="flex-1 h-1/1 px-16px !my-10px overflow-y-auto"
  160. {...currComp.props}
  161. />
  162. </div>
  163. </div>
  164. );
  165. };
  166. },
  167. });
  168. const tabItem = css`
  169. &:hover {
  170. color: @inf-primary-color;
  171. }
  172. &.active {
  173. color: @inf-primary-color;
  174. &:before {
  175. content: "";
  176. position: absolute;
  177. left: 0;
  178. top: 0;
  179. height: 100%;
  180. width: 3px;
  181. background-color: @inf-primary-color;
  182. }
  183. }
  184. `;