import { useMemo, useState, memo } from "react";
import { View, Image,Text } from "@tarojs/components";
import Taro from '@tarojs/taro'
import PageCustom from "@/components/page-custom/index";
import NavBarNormal from "@/components/NavBarNormal/index";
import WemetaInput from "@/components/wemeta-input/index";
import Popup from "@/components/popup/popup";
import style from './index.module.less'
import editorStyle from "../editor.module.less";
import BottomBar from "@/components/BottomBar";
import { useComponentStore } from "@/store/componentStore";
import { uploadImage } from "@/utils/http";
import { EComponentType } from "@/consts/enum";
export default function Index() {
let currentComponent = useComponentStore((state)=> state.currentComponent);
if(!currentComponent){
return <>>
}
const { saveComponent } = useComponentStore();
const loading = useComponentStore((state)=> state.loading);
const data = currentComponent.data;
const [linkValue, setLinkValue] = useState<{
name: string;
shortLink: string;
poster: string;
}>(data.value);
const [show, setShow] = useState(false);
const setValueByKey = (key: string, v: string) => {
setLinkValue((prev)=> {
prev[key] = v;
return {...prev};
});
};
const handleSubmit = async () => {
if(!data?.id){
return
}
if(loading){
return;
}
const c = {
data: {
value: linkValue,
layout: 'full',
id: data.id,
index: data.index,
},
enabled: currentComponent?.enabled ?? true,
type: EComponentType.miniProgram,
};
const result = await saveComponent(c)
if(result){
Taro.navigateBack()
}
};
const RenderPoster = memo(({src}:{src: string})=> {
if(src){
console.log('render image')
return (
)
}
return (
<>
建议上传1:1标准尺寸图
>
)
})
// useMemo 麻烦...
const RenderPosterCached = useMemo(()=> {
return
}, [linkValue.poster])
const handleAddPoster = () => {
Taro.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
async success (chooseImageRes) {
const tempFilePaths = chooseImageRes.tempFilePaths
Taro.cropImage({
src: tempFilePaths[0],
cropScale: "1:1",
success: async (cropRes) => {
const path = cropRes.tempFilePath;
const res = await uploadImage(path);
if (res?.publicUrl) {
setValueByKey('poster', res.publicUrl)
}
},
});
}
})
};
const renderTips = () => {
return (
<>
🌟 小蓝本提示:
打开小程序主页 - 顶部更多操作/评分入口 - 复制链接
>
);
};
return (
小程序链接
小程序名称
setValueByKey("name", value)}
placeholder="请输入小程序名字..."
maxlength={50}
/>
小程序链接
setShow(true)}>
如何获取?
setValueByKey("shortLink", value)}
placeholder="长按粘贴小程序链接..."
/>
封面图 (选填)
{RenderPosterCached}
保存
{renderTips()}
);
}