index.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import { useState } from "react";
  2. import { View, Text, Image } from "@tarojs/components";
  3. import Taro, { useRouter, useUnload } from "@tarojs/taro";
  4. import PageCustom from "@/components/page-custom/index";
  5. import NavBarNormal from "@/components/NavBarNormal/index";
  6. import WemetaTextarea from "@/components/wemeta-textarea/index";
  7. import WemetaInput from "@/components/wemeta-input/index";
  8. import { useComponentStore } from "@/store/componentStore";
  9. import { SocialMediaType } from "@/consts/socialMedia";
  10. import BottomBar from "@/components/BottomBar";
  11. import { EComponentType } from "@/consts/enum";
  12. import Popup from "@/components/popup/popup";
  13. import ButtonMain from "@/components/buttons/ButtonMain";
  14. export default function Index() {
  15. const router = useRouter();
  16. // 社交媒体类型
  17. const { mediaType } = router.params;
  18. let mt = mediaType ?? "link";
  19. let defaultLabel = `${SocialMediaType[mt]?.label} 链接`;
  20. if (mediaType === "shiping") {
  21. defaultLabel = "视频号";
  22. }
  23. let currentComponent = useComponentStore((state) => state.currentComponent);
  24. if (!currentComponent) {
  25. return <></>;
  26. }
  27. const { saveComponent } = useComponentStore();
  28. const loading = useComponentStore((state) => state.loading);
  29. const data = currentComponent?.data ?? {};
  30. const { value, text, layout } = data;
  31. const [show, setShow] = useState(false);
  32. const [linkValue, setLinkValue] = useState(value ?? "");
  33. const [linkText, setLinkText] = useState(text ?? "");
  34. // 是否为视频号, 视频号需要特殊提示
  35. // 如果后期还有更特殊需求,抽取单独页面
  36. const isShiping = SocialMediaType[mt]?.value === "shiping";
  37. const handleSubmit = async () => {
  38. if (!data?.id) {
  39. return;
  40. }
  41. if (loading) {
  42. return;
  43. }
  44. const c = {
  45. data: {
  46. value: linkValue,
  47. text: linkText,
  48. layout: layout ?? "",
  49. id: data.id,
  50. index: data.index,
  51. },
  52. enabled: currentComponent?.enabled ?? true,
  53. type: mediaType as EComponentType,
  54. };
  55. console.log(c);
  56. await saveComponent(c);
  57. Taro.navigateBack();
  58. };
  59. return (
  60. <PageCustom bgColor="global-light-green-bg">
  61. <NavBarNormal>{defaultLabel}</NavBarNormal>
  62. <View className="flex flex-col items-center gap-16 w-full px-16 pb-120">
  63. <View className="flex flex-col gap-6 w-full">
  64. <View className="flex w-full items-center ">
  65. <View className="flex text-14 leading-28 font-medium flex-1">{isShiping ? '视频号ID': '链接'}<Text className="text-red">*</Text></View>
  66. {isShiping && (
  67. <View className="text-primary" onClick={() => setShow(true)}>
  68. 如何获取?
  69. </View>
  70. )}
  71. </View>
  72. <WemetaTextarea
  73. value={linkValue}
  74. onInput={(value: string) => setLinkValue(value)}
  75. placeholder="填写视频号ID"
  76. maxlength={50}
  77. ></WemetaTextarea>
  78. </View>
  79. <View className={`flex flex-col gap-6 w-full`}>
  80. <View className="flex w-full items-center">
  81. <View className="flex flex-1 text-14 leading-28 font-medium">链接描述</View>
  82. </View>
  83. <WemetaInput
  84. value={linkText}
  85. onInput={(value: string) => setLinkText(value)}
  86. placeholder="请输入..."
  87. maxlength={50}
  88. />
  89. </View>
  90. </View>
  91. <BottomBar>
  92. <ButtonMain className="flex-1" disabled={!linkValue.length} onClick={handleSubmit}>保存</ButtonMain>
  93. </BottomBar>
  94. <Popup title={"获取视频号ID"} show={show} setShow={setShow}>
  95. <View className="flex flex-col gap-10 rounded-20 p-12 bg-white">
  96. <View className="text-gray-65">
  97. 🌟 <Text className="font-medium">小蓝本提示:</Text>
  98. <Text>
  99. 获取视频号ID的需要登录视频号助手,在首页可以查看自己的视频号ID
  100. </Text>
  101. </View>
  102. <Image
  103. className="w-full"
  104. mode="widthFix"
  105. src="https://cdn.wehome.cn/cmn/png/196/META-H8UK0IWU-9NNPJOLLD1MU95DE0NMA3-8W1EZW2M-2B1.png"
  106. ></Image>
  107. </View>
  108. </Popup>
  109. </PageCustom>
  110. );
  111. }