index.tsx 3.9 KB

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