diff --git a/package.json b/package.json index bc2b6c8..1848ab3 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "devDependencies": { "decimal.js": "^10.4.3", "react-router-dom": "^6.28.0", - "tailwindcss": "^3.4.15" + "tailwindcss": "^3.4.15", + "universal-cookie": "^7.2.2" }, "browserslist": { "production": [ diff --git a/src/Credit.ts b/src/Credit.ts new file mode 100644 index 0000000..0c54619 --- /dev/null +++ b/src/Credit.ts @@ -0,0 +1,3 @@ +class Credit { + +} \ No newline at end of file diff --git a/src/FoodOrderer.tsx b/src/FoodOrderer.tsx index 9886b76..e605a5d 100644 --- a/src/FoodOrderer.tsx +++ b/src/FoodOrderer.tsx @@ -106,7 +106,7 @@ function FoodList({ list, setList }: { {list.map((item) =>
@@ -114,7 +114,7 @@ function FoodList({ list, setList }: {

{item.provider.name}

{item.provider.price} 元/个

库存: {item.provider.storage}

- +
@@ -138,7 +138,7 @@ function FoodList({ list, setList }: { } }} className="text-center w-16 h-8 bg-gray-50 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-blue-400 text-base appearance-none pl-1.5" - /> + />
- )} ) } +const processOrder = ( + items: ShopItem[], + setItems: React.Dispatch> +) => { + let needPrice = 0 + items.forEach((it)=>{ + needPrice += getNeedPrice(it) + }) + if (needPrice == 0){ // 没花钱 + return + } + setItems(items.map((it) => ({ + ...it, + need: 0, + provider: { + ...it.provider, + storage: it.provider.storage - it.need + } + }))) + alert(`花掉了 ${needPrice} 元`) +} const FoodOrderer = () => { const [items, setItems] = useState(shopItems) return ( -
+

点些什么

+
+ +
) diff --git a/yarn.lock b/yarn.lock index cc5c3dc..753b869 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1878,6 +1878,11 @@ dependencies: "@types/node" "*" +"@types/cookie@^0.6.0": + version "0.6.0" + resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.6.0.tgz#eac397f28bf1d6ae0ae081363eca2f425bedf0d5" + integrity sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA== + "@types/eslint-scope@^3.7.7": version "3.7.7" resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.7.tgz#3108bd5f18b0cdb277c867b3dd449c9ed7079ac5" @@ -3306,6 +3311,11 @@ cookie@0.7.1: resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.7.1.tgz#2f73c42142d5d5cf71310a74fc4ae61670e5dbc9" integrity sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w== +cookie@^0.7.2: + version "0.7.2" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.7.2.tgz#556369c472a2ba910f2979891b526b3436237ed7" + integrity sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w== + core-js-compat@^3.38.0, core-js-compat@^3.38.1: version "3.39.0" resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.39.0.tgz#b12dccb495f2601dc860bdbe7b4e3ffa8ba63f61" @@ -9096,6 +9106,14 @@ unique-string@^2.0.0: dependencies: crypto-random-string "^2.0.0" +universal-cookie@^7.2.2: + version "7.2.2" + resolved "https://registry.yarnpkg.com/universal-cookie/-/universal-cookie-7.2.2.tgz#93ae9ec55baab89b24300473543170bb8112773c" + integrity sha512-fMiOcS3TmzP2x5QV26pIH3mvhexLIT0HmPa3V7Q7knRfT9HG6kTwq02HZGLPw0sAOXrAmotElGRvTLCMbJsvxQ== + dependencies: + "@types/cookie" "^0.6.0" + cookie "^0.7.2" + universalify@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.2.0.tgz#6451760566fa857534745ab1dde952d1b1761be0"