index.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { useMemo, useState, memo } from "react";
  2. import { View, Image,Text } from "@tarojs/components";
  3. import Taro from '@tarojs/taro'
  4. import PageCustom from "@/components/page-custom/index";
  5. import NavBarNormal from "@/components/NavBarNormal/index";
  6. import WemetaInput from "@/components/wemeta-input/index";
  7. import Popup from "@/components/popup/popup";
  8. import style from './index.module.less'
  9. import BottomBar from "@/components/BottomBar";
  10. import { useComponentStore } from "@/store/componentStore";
  11. import FormitemSingleImage from '@/components/Form/FormItemSingleImage';
  12. import { EComponentType } from "@/consts/enum";
  13. import WemetaButton from "@/components/buttons/WemetaButton";
  14. export default function Index() {
  15. let currentComponent = useComponentStore((state)=> state.currentComponent);
  16. if(!currentComponent){
  17. return <></>
  18. }
  19. const { saveComponent } = useComponentStore();
  20. const loading = useComponentStore((state)=> state.loading);
  21. const data = currentComponent.data;
  22. const [linkValue, setLinkValue] = useState<{
  23. name: string;
  24. shortLink: string;
  25. poster: string;
  26. }>(data.value);
  27. const [show, setShow] = useState(false);
  28. const setValueByKey = (key: string, v: string) => {
  29. setLinkValue((prev)=> {
  30. prev[key] = v;
  31. return {...prev};
  32. });
  33. };
  34. const handleSubmit = async () => {
  35. if(!data?.id){
  36. return
  37. }
  38. if(loading){
  39. return;
  40. }
  41. const c = {
  42. data: {
  43. value: linkValue,
  44. layout: 'full',
  45. id: data.id,
  46. index: data.index,
  47. },
  48. enabled: currentComponent?.enabled ?? true,
  49. type: EComponentType.miniProgram,
  50. };
  51. const result = await saveComponent(c)
  52. if(result){
  53. Taro.navigateBack()
  54. }
  55. };
  56. const setLinkPoster = (value: string)=> {
  57. setValueByKey('poster', value)
  58. }
  59. const renderTips = () => {
  60. return (
  61. <>
  62. <View>
  63. 🌟 <Text className="font-medium">小蓝本提示:</Text>
  64. <Text>打开小程序主页 - 顶部更多操作/评分入口 - 复制链接</Text>
  65. </View>
  66. <Image
  67. className="w-full"
  68. mode="widthFix"
  69. src="https://cdn.wehome.cn/cmn/png/102/META-H8UKWHWU-KIWQFXN9CWIKI7PA148U3-N5Z1UG4M-H7.png"
  70. ></Image>
  71. </>
  72. );
  73. };
  74. return (
  75. <PageCustom>
  76. <NavBarNormal>小程序链接</NavBarNormal>
  77. <View className="flex flex-col items-center w-full">
  78. <View className="px-16 pt-12 pb-120 w-full">
  79. <View className="flex flex-col gap-32">
  80. <View className="flex flex-col gap-6">
  81. <View className="flex w-full items-center">
  82. <View className="flex-1 text-14 leading-28 font-medium">小程序名称</View>
  83. </View>
  84. <WemetaInput
  85. value={linkValue.name}
  86. onInput={(value: string) => setValueByKey("name", value)}
  87. placeholder="请输入小程序名字..."
  88. maxlength={50}
  89. />
  90. </View>
  91. <View className="flex flex-col gap-6">
  92. <View className="flex w-full items-center">
  93. <View className="flex-1 text-14 leading-28 font-medium">小程序链接<Text className="text-red">*</Text></View>
  94. <View className="text-primary" onClick={()=> setShow(true)}>
  95. 如何获取?
  96. </View>
  97. </View>
  98. <WemetaInput
  99. value={linkValue.shortLink}
  100. onInput={(value: string) => setValueByKey("shortLink", value)}
  101. placeholder="长按粘贴小程序链接..."
  102. />
  103. </View>
  104. <FormitemSingleImage url={linkValue.poster} setUrl={setLinkPoster} ></FormitemSingleImage>
  105. </View>
  106. </View>
  107. </View>
  108. <BottomBar>
  109. <WemetaButton className="flex-1" disabled={!linkValue.shortLink.length} onClick={handleSubmit}>保存</WemetaButton>
  110. </BottomBar>
  111. <Popup
  112. title='获取小程序链接'
  113. show={show}
  114. setShow={setShow}
  115. >
  116. <View className="flex flex-col gap-16 mb-88">
  117. <View
  118. className={`flex flex-col p-12 gap-10 text-14 rounded-20 leading-22 text-gray-5 bg-gray-f8 overflow-hidden`}
  119. >
  120. {renderTips()}
  121. </View>
  122. </View>
  123. </Popup>
  124. </PageCustom>
  125. );
  126. }