diff --git a/config/index.ts b/config/index.ts index 7dd472e..50f41f2 100644 --- a/config/index.ts +++ b/config/index.ts @@ -48,6 +48,7 @@ const config = { }, webpackChain(chain, webpack) { chain.merge({ + performance: { maxEntrypointSize: 100000000, maxAssetSize: 300000000 }, plugin: { install: { plugin: UnifiedWebpackPluginV5, diff --git a/project.config.json b/project.config.json index f253c4f..6fba146 100644 --- a/project.config.json +++ b/project.config.json @@ -5,8 +5,8 @@ "appid": "wx2062eafa5dfc8ffb", "setting": { "urlCheck": true, - "es6": true, - "enhance": true, + "es6": false, + "enhance": false, "compileHotReLoad": false, "postcss": false, "preloadBackgroundData": false, diff --git a/project.private.config.json b/project.private.config.json index 24e2d5f..fc0fdd8 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -3,6 +3,6 @@ "projectname": "crab-wxapp", "setting": { "compileHotReLoad": true, - "urlCheck": true + "urlCheck": false } } \ No newline at end of file diff --git a/src/api/index.ts b/src/api/index.ts index d1aadd4..f7173fc 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -28,7 +28,6 @@ export const request = ({ } if (isToken) header['Authorization'] = 'Bearer ' + Taro.getStorageSync('token') Taro.showLoading({ title: '加载中...' }) - console.log("发起请求中"); wx.request({ url: baseUrl + url + (requestParams ? ('?' + requestParams) : ''), diff --git a/src/api/me.ts b/src/api/me.ts index 5c19a2e..1d9ecf3 100644 --- a/src/api/me.ts +++ b/src/api/me.ts @@ -30,4 +30,12 @@ export const addressDelete = (params) => { method: 'DELETE', params }) +} + +export const updateAddress = (data) => { + return request({ + url: 'wechat/v1/adoption-order/updateaddress', + method: 'PUT', + data + }) } \ No newline at end of file diff --git a/src/api/order.ts b/src/api/order.ts index d62c5f0..e3f35cd 100644 --- a/src/api/order.ts +++ b/src/api/order.ts @@ -25,10 +25,20 @@ export const tickPage = (params) => { }) } +// 根据ID获取订单信息 export const getOrderInfoById = (params) => { return request({ - url: 'wechat/v1/ticket/page', + url: 'wechat/v1/adoption-order/get', method: 'GET', params }) +} + +// 赠送好友 +export const adoptionGiveOther = (data) => { + return request({ + url: 'wechat/v1/adoption-order/giveOther', + method: 'PUT', + data + }) } \ No newline at end of file diff --git a/src/components/LoginForm/index.tsx b/src/components/LoginForm/index.tsx index 3935739..67ae73d 100644 --- a/src/components/LoginForm/index.tsx +++ b/src/components/LoginForm/index.tsx @@ -1,7 +1,7 @@ -import { Image, View, PageContainer, Input } from "@tarojs/components"; +import { Image, View, PageContainer, Input, Button } from "@tarojs/components"; import Taro from "@tarojs/taro"; import { useState } from "react"; -import { APPID, IMG_BASE_URL, SECRET } from "../../config"; +import { IMG_BASE_URL } from "../../config"; const larvea = IMG_BASE_URL + 'pagesHome/larvea.png' @@ -9,7 +9,7 @@ export default function LoginForm(props) { const { show, setShow, onConfirm } = props const [userNickName, setUserNickName] = useState('') const [userSignature, setUserSignature] = useState('') - const [avatar, setAvatar] = useState('') + const [avatar, setAvatar] = useState(larvea) return ( 设置你的头像和昵称 - { - Taro.chooseImage({ - success: (e) => { - console.log("e", e); - console.log("e", e); - const { tempFilePaths } = e; - if (Array.isArray(tempFilePaths) && tempFilePaths.length === 0) return - let res = '' - try { - const base64 = Taro.getFileSystemManager().readFileSync(tempFilePaths[0], "base64"); - if (base64) { - res = "data:image/jpg;base64," + base64; - } - } catch (error) { - console.warn("=> utilssearch.ts error imgToBase64", error); - throw error; - } finally { - setAvatar(res) - } - } - }) - }}> - - + + - { - setUserNickName((e.target as any).value) - }} /> - { - Taro.getUserProfile({ - desc: '用于完善会员资料', - success: async (res) => { - const { userInfo, signature } = res; - const { nickName, avatarUrl } = userInfo; - if (nickName) setUserNickName(nickName) - if (avatarUrl) setAvatar(avatarUrl) - Taro.login({ - success: (_res) => { - console.log("RES LOGIN", _res); - const { code } = _res - if (signature) setUserSignature(code) // 先用code顶替 - } - }) - }, - fail: (error) => { - console.warn("error", error); - } - }) - }}>使用微信昵称 + { + console.log("nickName =>", e); + setUserNickName((e.target as any).value) + }} + /> { const { code } = _res_ if (code) setUserSignature(code) + if (onConfirm) onConfirm({ + openId: code, + nickName: userNickName, + buyerImg: avatar + }) }, fail: () => { Taro.showToast({ diff --git a/src/pageMe/inviteFriends/index.tsx b/src/pageMe/inviteFriends/index.tsx index 114f08b..4407306 100644 --- a/src/pageMe/inviteFriends/index.tsx +++ b/src/pageMe/inviteFriends/index.tsx @@ -1,11 +1,12 @@ -import { View, ScrollView, Image, Text } from "@tarojs/components"; +import { View, ScrollView, Image, Text, Button } from "@tarojs/components"; import { APP_FULL_HEIGHT, formatMoney, IMG_BASE_URL } from "../../config"; import HeaderNation from "../../components/HeaderNation"; import OuterFrame from "../../components/OuterFrame"; import StatusBar from "../../components/StatusBar"; -import Taro, { getCurrentInstance } from "@tarojs/taro" +import Taro, { getCurrentInstance, useShareAppMessage } from "@tarojs/taro" import { useEffect, useState } from "react"; import { adoptionOrderPage } from "../../api/user"; +import { adoptionGiveOther } from '../../api/order' import dayjs from "dayjs"; const poster1 = IMG_BASE_URL + 'pageMe/poster1.png' @@ -31,11 +32,42 @@ export default function InviteFriends() { console.log("订单", list); if (Array.isArray(list)) { - const _item = list.filter(item => item.id === id) + const _item = list.filter(item => item.orderNumber === id) + console.log("选中订单", _item); + if (_item.length > 0) setCurOrderItem(_item[0]) } } useEffect(() => { getOrderInfo() }, []) + + useShareAppMessage(async (res) => { + const userOpenId = Taro.getStorageSync("USER_OPEN_ID") + const { data } = await adoptionGiveOther({ + originalOrderNumber: id, + openId: userOpenId + }) + console.log("赠送接口返回", data); + if (!data) { + Taro.showToast({ + title: '赠送失败!', + icon: 'error', + duration: 1400 + }) + return {} + } + console.log("useShareAppMessage", res) + if (res.from === 'button') { + // 来自页面内分享按钮 + } else { + // 右上角分享好友 + } + + return { + title: '大闸蟹认养小程序', // 分享卡片的title + path: 'pages/login/index?shareId=' + curOrderItem.orderNumber, // 分享卡片的小程序路径 + imageUrl: poster1 // 分享卡片的图片链接 + }; + }) return ( @@ -100,7 +132,7 @@ export default function InviteFriends() { 让我们一起来云养蟹吧! - 赠送好友 + ) diff --git a/src/pageMe/myCertificate/index.tsx b/src/pageMe/myCertificate/index.tsx index e88ac6a..5341ff7 100644 --- a/src/pageMe/myCertificate/index.tsx +++ b/src/pageMe/myCertificate/index.tsx @@ -1,4 +1,4 @@ -import { View, ScrollView, Image, Text } from "@tarojs/components"; +import { View, ScrollView, Image, Text, Button } from "@tarojs/components"; import { APP_FULL_HEIGHT, IMG_BASE_URL } from "../../config"; import HeaderNation from "../../components/HeaderNation"; import OuterFrame from "../../components/OuterFrame"; @@ -47,19 +47,21 @@ export default function MyCertificate() { - - 赠送好友 - { + + + ) diff --git a/src/pageMe/myOrder/index.tsx b/src/pageMe/myOrder/index.tsx index f516b74..275bd94 100644 --- a/src/pageMe/myOrder/index.tsx +++ b/src/pageMe/myOrder/index.tsx @@ -57,7 +57,7 @@ export default function MyOrder() { {item.planName} {dayjs(item.createTime).format('YYYY-MM-DD HH:mm:ss')} - { - if (item.status === '0') Taro.navigateTo({ url: '/userInfo/confirmOrder/index?id=' + item.id }) // 未付款 - if (item.status === '1') Taro.navigateTo({ url: '/pageMe/inviteFriends/index?id=' + item.id }) // 送好友 - }} - >{ - OperationMap[item.status] - } + { + if (item.status === '0') Taro.navigateTo({ url: '/userInfo/confirmOrder/index?id=' + item.id }) // 未付款 + if (item.status === '1') Taro.navigateTo({ url: '/pageMe/inviteFriends/index?id=' + item.orderNumber }) // 送好友 + }} + >{ + OperationMap[item.status] + } ) } + + useShareAppMessage(() => { + return { + title: '大闸蟹认养小程序', // 分享卡片的title + path: 'pages/login/index', // 分享卡片的小程序路径 + imageUrl: imgBg // 分享卡片的图片链接 + }; + }) return ( @@ -78,7 +87,7 @@ export default function AdoptionCircle() { 邀请好友认养,提升好人缘! - 分享 + { + const { router } = getCurrentInstance() + // 通过分享链接打开此页面, shareId 其实是 orderNumber + const shareId = router && router.params && router.params.shareId + console.log("通过分享链接打开,shareId=", shareId); + // Taro.navigateTo({ url: '/pageMe/myCertificate/index' }) const setUserAvatar = useStore((store:any) => store.setUserAvatar) const setUserName = useStore((store:any) => store.setUserName) diff --git a/src/pagesHome/adoption.tsx b/src/pagesHome/adoption.tsx index 62e771b..4766e4f 100644 --- a/src/pagesHome/adoption.tsx +++ b/src/pagesHome/adoption.tsx @@ -84,6 +84,7 @@ export default function Adoption() { if (Array.isArray(data)) setRuleList(data.map(item => ({ ...item, value: 0 }))) } const applyCount = (id, value) => { + if (value < 0) return setRuleList(ruleList.map(item => { if (item.id === id) return { ...item, value } return item @@ -219,16 +220,13 @@ export default function Adoption() { {item.specs}(¥{formatMoney(item.singlePrice)}/份) - { - applyCount(item.id, item.value-- ) + { + applyCount(item.id, item.value - 1 ) }}>- - { - console.log("rule Input", e.target); + { applyCount(item.id, +(e.target as any).value) }}/> - { - console.log("+1", item.value + 1); - + { applyCount(item.id, item.value + 1 ) }}>+ @@ -244,13 +242,15 @@ export default function Adoption() { (¥5/只) - { - setAmountCount((parseInt(amountCount) - 1).toString()) + { + const _val = parseInt(amountCount) - 1 + if (_val < 0) return + setAmountCount(_val.toString()) }}>- - { + { setAmountCount((e.target as any).value) }}/> - { + { setAmountCount((parseInt(amountCount) + 1).toString()) }}>+ diff --git a/src/pagesHome/monitor.tsx b/src/pagesHome/monitor.tsx index a5bb55e..21ab789 100644 --- a/src/pagesHome/monitor.tsx +++ b/src/pagesHome/monitor.tsx @@ -1,6 +1,6 @@ -import { View,Image,Text, ScrollView } from "@tarojs/components"; +import { View,Image,Text, ScrollView, Button } from "@tarojs/components"; import './index.scss' -import Taro from "@tarojs/taro"; +import Taro, { useShareAppMessage } from "@tarojs/taro"; import { IMG_BASE_URL } from "../config"; import useStore from "../storage"; import { useEffect, useState } from "react"; @@ -25,7 +25,7 @@ const CropGrowth = ({ belongPlot, type, updatePeriod }) => { const { list } = data; console.log("getDataList", list); if (Array.isArray(list)) { - setDataList(list) + setDataList(list.map(item => ({ ...item, imgId: item.imgId.replace("http://117.73.12.97:9000", "https://www.zhuangbeizz.cn/minio")}))) if (list.length > 0) { updatePeriod(list[0]) } @@ -191,6 +191,14 @@ export default function Monitor() { } } useEffect(() => { getMyOrder() }, []) + + useShareAppMessage(() => { + return { + title: '大闸蟹认养小程序', // 分享卡片的title + path: 'pages/login/index', // 分享卡片的小程序路径 + imageUrl: headerBg // 分享卡片的图片链接 + }; + }) return ( @@ -219,10 +227,10 @@ export default function Monitor() { 大闸蟹当前状态 - + {year}.{month} diff --git a/src/userInfo/address/index.tsx b/src/userInfo/address/index.tsx index 5b46d1b..8a850de 100644 --- a/src/userInfo/address/index.tsx +++ b/src/userInfo/address/index.tsx @@ -5,13 +5,15 @@ import { View, ScrollView, Image } from "@tarojs/components"; import { APP_FULL_HEIGHT, IMG_BASE_URL } from "../../config"; import noData from './assets/noData.png' import { useEffect, useState } from "react"; -import Taro, { useDidShow } from "@tarojs/taro"; -import { addressCreate, addressPage } from "../../api/me"; +import Taro, { getCurrentInstance, useDidShow } from "@tarojs/taro"; +import { addressCreate, addressPage, updateAddress } from "../../api/me"; const arrow = IMG_BASE_URL + 'arrow.png' export default function Address() { const bottomNavBarHeight = 80 + const { router } = getCurrentInstance() + const orderId = router?.params?.orderId const NoData = () => { return ( @@ -25,7 +27,17 @@ export default function Address() { return ( Taro.navigateTo({ url: '/userInfo/addAddress/index?edit=true&id=' + item.id }) + async () => { + if (!orderId) Taro.navigateTo({ url: '/userInfo/addAddress/index?edit=true&id=' + item.id }) + else { + const data = await updateAddress({ + id: orderId, addressNumber: item.addressNumber + }) + console.log("更新地址", data); + + Taro.navigateBack() + } + } }> @@ -52,6 +64,8 @@ export default function Address() { const openId = Taro.getStorageSync("USER_OPEN_ID") const { data } = await addressPage({ openId }) const { list } = data + console.log("Address List", list); + if (Array.isArray(list)) setAddressList(list) } useDidShow(() => { @@ -60,7 +74,7 @@ export default function Address() { return ( - + - { - Taro.chooseAddress({ - success: async (e) => { - console.log("E", e); - const userOpenId = Taro.getStorageSync("USER_OPEN_ID") - const { data, code } = await addressCreate({ - openId: userOpenId, - contact: e.userName, - phoneNumber: e.telNumber, - areaInfo: e.provinceName + '/' + e.cityName + '/' + e.countyName, - fullAddress: e.detailInfo, - zipCode: e.postalCode, - isDefault: '1', - remark: "", - userId: "", - deptId: "", - tenant: "158" + { + orderId ? <> + { + Taro.chooseAddress({ + success: async (e) => { + console.log("E", e); + const userOpenId = Taro.getStorageSync("USER_OPEN_ID") + const { data, code } = await addressCreate({ + openId: userOpenId, + contact: e.userName, + phoneNumber: e.telNumber, + areaInfo: e.provinceName + '/' + e.cityName + '/' + e.countyName, + fullAddress: e.detailInfo, + zipCode: e.postalCode, + isDefault: '1', + remark: "", + userId: "", + deptId: "", + tenant: "158" + }) + if (code === 0) getAddressList() + else Taro.showToast({ + title: '保存失败!', + icon: 'error', + duration: 1400 + }) + } }) - if (code === 0) getAddressList() - else Taro.showToast({ - title: '保存失败!', - icon: 'error', - duration: 1400 - }) - } - }) - }}>导入微信地址 - { - Taro.navigateTo({ url: '/userInfo/addAddress/index' }) - }}>新增收货地址 + }}>导入微信地址 + { + Taro.navigateTo({ url: '/userInfo/addAddress/index' }) + }}>新增收货地址 + : <> + + } ) diff --git a/src/userInfo/confirmOrder/index.tsx b/src/userInfo/confirmOrder/index.tsx index a899266..1bfb647 100644 --- a/src/userInfo/confirmOrder/index.tsx +++ b/src/userInfo/confirmOrder/index.tsx @@ -44,63 +44,45 @@ const CalcLeftTime = ({ time }) => { export default function ConfirmOrder() { const userAvatar = useStore((store:any) => store.userAvatar) const bottomNavBarHeight = 130 - // 倒计时 - const [leftTime, setLeftTime] = useState(100) const Divider = () => { return ( ) } + const [orderInfo, setOrderInfo] = useState({}) const { router } = getCurrentInstance() - console.log("ID" , router && router.params && router.params.id); const OrderId = router && router.params && router.params.id + + // 获取订单信息 const getOrderInfo = async () => { if (!OrderId) return - const userOpenId = Taro.getStorageSync("USER_OPEN_ID") - const { data } = await getOrderInfoById({ - id: OrderId, - serialNumber: 'JHLS202407012565376', - openId: userOpenId - }) - const { list } = data; - if (!Array.isArray(list)) return - const _orderItem = list.filter(item => { - if (item.id === OrderId) return true; - return false - }) - console.log("_orderItem", _orderItem[0]); - - if (_orderItem && _orderItem.length > 0) setOrderInfo(_orderItem[0]) + const { data } = await getOrderInfoById({ orderId: OrderId }) + if (data.orderId === OrderId) setOrderInfo(data) else { Taro.navigateBack() - Taro.showToast({ - title: '获取订单失败!', - icon: 'error', - duration: 1400 - }) + Taro.showToast({ title: '获取订单失败!', icon: 'error', duration: 1400 }) } } - useEffect(() => { - getOrderInfo() - }, []) + useDidShow(() => { getOrderInfo() }) - const [defaultAdd, setDefaultAdd] = useState({ - id: '' - }) - const getAddress = async () => { - const userOpenId = Taro.getStorageSync("USER_OPEN_ID") - const { data } = await addressPage({ - openId: userOpenId - }) - const { list } = data; - console.log("List", list); - if (!Array.isArray(list)) return - const _defaultAdd = list.filter(item => (item.isDefault === '1'))[0] - if (_defaultAdd) setDefaultAdd(_defaultAdd) + const formatSpecs = (orderDetailList) => { + if (Array.isArray(orderDetailList)) { + const arr = orderDetailList.map(item => (item.specs.specs)) + return arr.join(';\n') + } else { + return '' + } + } + + // 订单超时 返回true + const diabledPay = () => { + if (!orderInfo?.orderCreateTime) return false + const now = new Date().valueOf() + const limitTime = orderInfo.orderCreateTime + 1000 * 60 * 15 + if (limitTime - now < 0) return true + return false } - useDidShow(() => { getAddress() }) - return ( @@ -115,52 +97,61 @@ export default function ConfirmOrder() { className="pb-1 box-border overflow-hidden box-border" > - - - - {defaultAdd.contact} - {defaultAdd.phoneNumber} - - {defaultAdd.fullAddress} - - { - Taro.navigateTo({ url: '/userInfo/address/index' }) - }} /> - - { - Taro.navigateTo({ url: '/userInfo/address/index' }) - }} - > - - 请新增收货物地址 - - - - - - {orderInfo.plotName} - {orderInfo?.detail?.specs?.map(item => (item.specs)).join(';')} - - - - 预计收获日期: - - {dayjs(orderInfo.expectStart).format("YYYY-MM-DD")} - - - {dayjs(orderInfo.expectEnd).format("YYYY-MM-DD")} - - - - - - 合计 - ¥{formatMoney(orderInfo.orderAmount || 0)} - - - + { + orderInfo?.orderId ? ( + <> + { + orderInfo?.addressInfo?.id ? + + + {orderInfo.addressInfo.contact} + {orderInfo.addressInfo.phoneNumber} + + + {orderInfo.addressInfo.areaInfo} + {orderInfo.addressInfo.fullAddress} + + + { + Taro.navigateTo({ url: '/userInfo/address/index?orderId=' + OrderId }) + }} /> + : { + Taro.navigateTo({ url: '/userInfo/address/index?orderId=' + OrderId }) + }} + > + + 请新增收货物地址 + + } + + + + + {orderInfo.plotName} + {formatSpecs(orderInfo.orderDetailList)} + + + + 预计收获日期: + + {dayjs(orderInfo.orderExpectStart).format("YYYY-MM-DD")} + --- + {dayjs(orderInfo.orderExpectEnd).format("YYYY-MM-DD")} + + + + + + 合计 + ¥{formatMoney(orderInfo.orderAmount || 0)} + + + + + ) : null + } 倒计时: - + - { + { + if (diabledPay()) { + Taro.showToast({ + title: '订单超时!', + icon: 'error', + duration: 1400 + }) + return + } const id = router && router.params && router.params.id if (!id) return - if (!defaultAdd.id) { + if (!orderInfo?.addressInfo?.id) { Taro.showToast({ title: '请选择地址', icon: 'error',