ProTabs.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import { useRef, useState } from "react";
  2. import { Switch } from "antd";
  3. import { Radio, Space } from "antd";
  4. import { SettingOutlined, ShoppingCartOutlined } from "@ant-design/icons";
  5. import SettingArticle from "../auth/setting/SettingArticle";
  6. import DictComponent from "../dict/DictComponent";
  7. import { DictIcon, TermIcon } from "../../assets/icon";
  8. import TermShell from "./TermShell";
  9. const setting = (
  10. <>
  11. <Space>
  12. {"保存到用户设置"}
  13. <Switch
  14. defaultChecked
  15. onChange={(checked) => {
  16. console.log(checked);
  17. }}
  18. />
  19. </Space>
  20. <SettingArticle />
  21. </>
  22. );
  23. const ProTabsWidget = () => {
  24. const [value2, setValue2] = useState("close");
  25. const divSetting = useRef<HTMLDivElement>(null);
  26. const divDict = useRef<HTMLDivElement>(null);
  27. const divTerm = useRef<HTMLDivElement>(null);
  28. const divCart = useRef<HTMLDivElement>(null);
  29. const divPanel = useRef<HTMLDivElement>(null);
  30. const rightBarWidth = "48px";
  31. const closeAll = () => {
  32. if (divPanel.current) {
  33. divPanel.current.style.display = "none";
  34. }
  35. };
  36. const openPanel = () => {
  37. if (divPanel.current) {
  38. divPanel.current.style.display = "block";
  39. }
  40. };
  41. const headHeight = 64;
  42. const stylePanel: React.CSSProperties = {
  43. height: `calc(100vh - ${headHeight})`,
  44. overflowY: "scroll",
  45. };
  46. return (
  47. <div style={{ display: "flex" }}>
  48. <div ref={divPanel} style={{ width: 350, display: "none" }}>
  49. <div ref={divSetting} style={stylePanel}>
  50. {setting}
  51. </div>
  52. <div ref={divDict} style={stylePanel}>
  53. <DictComponent />
  54. </div>
  55. <div ref={divTerm} style={stylePanel}>
  56. <TermShell />
  57. </div>
  58. <div ref={divCart} style={stylePanel}></div>
  59. </div>
  60. <div
  61. style={{
  62. width: `${rightBarWidth}`,
  63. display: "flex",
  64. flexDirection: "column",
  65. }}
  66. >
  67. <Radio.Group
  68. value={value2}
  69. optionType="button"
  70. buttonStyle="solid"
  71. onChange={(e) => {
  72. console.log("radio change", e.target.value);
  73. if (divSetting.current) {
  74. divSetting.current.style.display = "none";
  75. }
  76. if (divDict.current) {
  77. divDict.current.style.display = "none";
  78. }
  79. if (divTerm.current) {
  80. divTerm.current.style.display = "none";
  81. }
  82. if (divCart.current) {
  83. divCart.current.style.display = "none";
  84. }
  85. switch (e.target.value) {
  86. case "setting":
  87. if (divSetting.current) {
  88. divSetting.current.style.display = "block";
  89. }
  90. openPanel();
  91. break;
  92. case "dict":
  93. if (divDict.current) {
  94. divDict.current.style.display = "block";
  95. }
  96. openPanel();
  97. break;
  98. case "term":
  99. if (divTerm.current) {
  100. divTerm.current.style.display = "block";
  101. }
  102. openPanel();
  103. break;
  104. case "cart":
  105. if (divCart.current) {
  106. divCart.current.style.display = "block";
  107. }
  108. openPanel();
  109. break;
  110. default:
  111. break;
  112. }
  113. setValue2(e.target.value);
  114. }}
  115. >
  116. <Space orientation="vertical">
  117. <Radio
  118. value="setting"
  119. onClick={() => {
  120. if (value2 === "setting") {
  121. setValue2("close");
  122. closeAll();
  123. }
  124. }}
  125. >
  126. <SettingOutlined />
  127. </Radio>
  128. <Radio
  129. value="dict"
  130. onClick={() => {
  131. if (value2 === "dict") {
  132. setValue2("close");
  133. closeAll();
  134. }
  135. }}
  136. >
  137. <DictIcon />
  138. </Radio>
  139. <Radio
  140. value="term"
  141. onClick={() => {
  142. if (value2 === "term") {
  143. setValue2("close");
  144. closeAll();
  145. }
  146. }}
  147. >
  148. <TermIcon />
  149. </Radio>
  150. <Radio
  151. value="cart"
  152. onClick={() => {
  153. if (value2 === "cart") {
  154. setValue2("close");
  155. closeAll();
  156. }
  157. }}
  158. >
  159. <ShoppingCartOutlined />
  160. </Radio>
  161. <Radio value="close" style={{ display: "none" }}></Radio>
  162. </Space>
  163. </Radio.Group>
  164. </div>
  165. </div>
  166. );
  167. };
  168. export default ProTabsWidget;