index.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { useState } from "react";
  2. import { View, Text, Image } from "@tarojs/components";
  3. import Taro, { useRouter } from "@tarojs/taro";
  4. import PageCustom from "@/components/page-custom/index";
  5. import NavBarNormal from "@/components/nav-bar-normal/index";
  6. import Popup from "@/components/popup/popup";
  7. import editorStyle from "../editor.module.less";
  8. import { useCharacterStore } from "@/store/characterStore";
  9. import { useComponentStore } from "@/store/componentStore";
  10. import WemetaInput from "@/components/wemeta-input/index";
  11. export default function Index() {
  12. const router = useRouter();
  13. const { id } = router.params;
  14. const deltaNum = id ? 1 : 2;
  15. let currentComponent = useComponentStore((state) => state.currentComponent);
  16. const character = useCharacterStore((state) => state.character);
  17. const { saveComponent } = useComponentStore();
  18. const loading = useComponentStore((state) => state.loading);
  19. const { value } = currentComponent?.data ?? {};
  20. const [storeProductValue, setStoreProductValue] = useState<{
  21. appid: string;
  22. }>(value ?? {});
  23. const [show, setShow] = useState(false);
  24. const handleSave = async () => {
  25. if (loading) {
  26. return;
  27. }
  28. if (!storeProductValue.appid) {
  29. return;
  30. }
  31. const c = {
  32. data: {
  33. value: storeProductValue,
  34. layout: 'mini',
  35. },
  36. enabled: currentComponent?.enabled ?? true,
  37. id: currentComponent?.id,
  38. name: currentComponent?.name ?? "微信小店",
  39. characterProfileId:
  40. currentComponent?.characterProfileId ?? character?.profileId,
  41. type: "storeHome",
  42. };
  43. console.log(c);
  44. await saveComponent(c);
  45. };
  46. const handleNavBack = async () => {
  47. await handleSave();
  48. };
  49. const setValueByKey = (key: string, v: string) => {
  50. setStoreProductValue((prev)=> {
  51. return {
  52. ...prev,
  53. [key]: v
  54. }
  55. });
  56. };
  57. const showTips = () => () => {
  58. setShow(true);
  59. };
  60. return (
  61. <PageCustom>
  62. <NavBarNormal
  63. backText="保存"
  64. navDelta={deltaNum}
  65. onNavBack={handleNavBack}
  66. >
  67. 填写小店商品信息
  68. </NavBarNormal>
  69. <View className="flex flex-col items-center w-full pt-20">
  70. <View className={editorStyle.container}>
  71. <View className={editorStyle.formContainer}>
  72. <View className={editorStyle.formItem}>
  73. <View className={editorStyle.formItemLabel}>
  74. <View className="flex-1">小店ID</View>
  75. <View className="text-green" onClick={showTips()}>
  76. 如何获取?
  77. </View>
  78. </View>
  79. <WemetaInput
  80. value={storeProductValue.appid}
  81. onInput={(value: string) => setValueByKey("appid", value)}
  82. placeholder="长按粘贴小店ID..."
  83. />
  84. </View>
  85. </View>
  86. </View>
  87. </View>
  88. <Popup
  89. title="获取小店ID"
  90. show={show}
  91. setShow={setShow}
  92. >
  93. <View className="flex flex-col gap-16 mb-44">
  94. <View
  95. className={`flex flex-col p-12 gap-10 text-14 rounded-20 leading-22 text-gray-65 bg-gray-f8 overflow-hidden`}
  96. >
  97. <View>
  98. 🌟 <Text className="font-medium">小绿提示:</Text>
  99. <Text>通过微信小店后台 - 商品管理 - 商品列表 - 规格/编码获取。</Text>
  100. </View>
  101. <Image
  102. className="w-full"
  103. mode="widthFix"
  104. src="https://cdn.wehome.cn/cmn/png/214/META-H8UKXHWU-PIWQ5G6H7F9LO74FT7QR2-9SOBIJ4M-KC.png"
  105. ></Image>
  106. </View>
  107. <View className='button-rounded-big mt-20' onClick={() => setShow(false)}>知道了</View>
  108. </View>
  109. </Popup>
  110. </PageCustom>
  111. );
  112. }