index.tsx 4.3 KB

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