index.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { useState } from "react";
  2. import { View } from "@tarojs/components";
  3. import PageCustom from "@/components/page-custom/index";
  4. import NavBarNormal from "@/components/NavBarNormal/index";
  5. import BottomBar from "@/components/BottomBar";
  6. import editorStyle from "../editor.module.less";
  7. import { useComponentStore } from "@/store/componentStore";
  8. import Taro, { useUnload } from "@tarojs/taro";
  9. import WemetaTextarea from "@/components/wemeta-textarea/index";
  10. import { EComponentType } from "@/consts/enum";
  11. export default function Index() {
  12. let currentComponent = useComponentStore((state)=> state.currentComponent);
  13. const { saveComponent } = useComponentStore();
  14. const loading = useComponentStore((state)=> state.loading);
  15. const [value, setValue] = useState<string>(currentComponent?.data?.text ?? '');
  16. const handleSubmit = async () => {
  17. if(loading){
  18. return;
  19. }
  20. if(!currentComponent?.data.id){
  21. return
  22. }
  23. const c = {
  24. data: {
  25. text: value,
  26. layout: currentComponent?.data?.layout ?? 'center',
  27. id: currentComponent?.data.id,
  28. index: currentComponent?.data?.index,
  29. },
  30. enabled: currentComponent?.enabled ?? true,
  31. type: EComponentType.text,
  32. };
  33. await saveComponent(c)
  34. Taro.navigateBack()
  35. };
  36. const onChange = (e: any) => {
  37. setValue(e);
  38. };
  39. return (
  40. <PageCustom bgColor="global-light-green-bg">
  41. <NavBarNormal>文本内容</NavBarNormal>
  42. <View className="flex flex-col items-center w-full">
  43. <View className="w-full p-16">
  44. <WemetaTextarea
  45. value={value}
  46. onInput={(value: any) => onChange(value)}
  47. placeholder="文本内容"
  48. cursorSpacing={100}
  49. maxlength={2000}
  50. />
  51. </View>
  52. <BottomBar>
  53. <View className="button-rounded button-primary flex-1" onClick={handleSubmit}>保存</View>
  54. </BottomBar>
  55. </View>
  56. </PageCustom>
  57. );
  58. }