-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e53c20
commit 4574f17
Showing
11 changed files
with
2,353 additions
and
74 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { reactive } from 'vue' | ||
|
||
/** | ||
* like this: | ||
* { "uid": "1b017638-1b1c-4e75-8a16-389f72dfa98e", "token": { "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxYjAxNzYzOC0xYjFjLTRlNzUtOGExNi0zODlmNzJkZmE5OGUiLCJleHAiOjE2OTI1MjQ0MTcsImlhdCI6MTY5MjQzODAxN30.QZcxjqcRADI5eRuKTgE4LhPrk0nbMuy9G66Iz8KcK0A", "token_type": "Bearer" } } | ||
*/ | ||
export const tokenStore = reactive({ | ||
token: {}, | ||
setToken(jwt) { | ||
console.log("setToken"); | ||
this.token = jwt; | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<script setup> | ||
import { reactive, onMounted, ref } from 'vue' | ||
import { useRouter, useRoute } from 'vue-router' | ||
import { tokenStore } from '../store.js' | ||
const router = useRouter() | ||
const route = useRoute() | ||
const goodDetail = ref({}); | ||
const addOrderStatus = ref(''); | ||
const addOrderResult = ref({}); | ||
async function postData(url = '', data = {}) { | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': tokenStore.token.token.token_type + ' ' + tokenStore.token.token.access_token, | ||
}, | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
async function fetch_goods_detail() { | ||
const data = await fetch( | ||
'http://127.0.0.1:3004/goods_detail?goods_id=' + route.params.id, | ||
{ | ||
method: "post", | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
} | ||
).then(rsp => rsp.json()) | ||
// alert.call("") | ||
// window.alert("get goods_list over."); | ||
goodDetail.value = data; | ||
} | ||
async function add_order() { | ||
addOrderStatus.value = 'check sign status....'; | ||
if (JSON.stringify(tokenStore.token) === '{}') { | ||
window.alert("please sign in first."); | ||
return | ||
} | ||
addOrderStatus.value = 'request token....'; | ||
const addOrderTokenResp = await postData( | ||
'http://127.0.0.1:3002/request_order_token', | ||
{} | ||
) | ||
// .then(rsp => rsp.json()) | ||
const addOrderToken = addOrderTokenResp.token; | ||
addOrderStatus.value = 'request token success.' + addOrderToken; | ||
const addOrderResp = await postData( | ||
'http://127.0.0.1:3002/add_order', | ||
{ | ||
'items_id': Number(route.params.id), | ||
'price': goodDetail.value.unit_price, | ||
'count': 1, | ||
'currency': "CNY", | ||
'description': '', | ||
'token': addOrderToken, | ||
} | ||
) | ||
// .then(rsp => rsp.json()) | ||
addOrderStatus.value = 'add order success.'; | ||
// alert.call("") | ||
// window.alert("get goods_list over."); | ||
addOrderResult.value = addOrderResp; | ||
// goodDetail.value = data; | ||
} | ||
onMounted((async () => { | ||
fetch_goods_detail() | ||
})) | ||
</script> | ||
|
||
<template> | ||
<main> | ||
<div> | ||
Goods Detail: | ||
</div> | ||
<div> | ||
<p>name:</p> | ||
<p>{{ goodDetail.goods_name }}</p> | ||
<p>des:</p> | ||
<p>{{ goodDetail.goods_des }}</p> | ||
|
||
<div> | ||
<button @click="add_order">buy now!</button> | ||
</div> | ||
|
||
<br> | ||
<p>{{ addOrderStatus }}</p> | ||
<p>{{ JSON.stringify(addOrderResult) }}</p> | ||
</div> | ||
</main> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<script setup> | ||
import { reactive, onMounted, ref } from 'vue' | ||
const page = ref(0); | ||
const page_size = ref(10); | ||
const goods = ref([]); | ||
async function fetch_goods_list() { | ||
const data = await fetch( | ||
'http://127.0.0.1:3004/goods_list?page_size=' + page_size.value + '&page=' + page.value, | ||
{ | ||
method: "post", | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
} | ||
).then(rsp => rsp.json()) | ||
// alert.call("") | ||
// window.alert("get goods_list over."); | ||
goods.value = data; | ||
} | ||
onMounted((async () => { | ||
fetch_goods_list() | ||
})) | ||
</script> | ||
|
||
<template> | ||
<main> | ||
<div> | ||
Goods List: | ||
</div> | ||
<div> | ||
<ul> | ||
<li v-for="item of goods" :key="item.objectID"> | ||
<a :href="'/goods_detail/' + item.id">{{ item.goods_name }}</a> | ||
</li> | ||
</ul> | ||
</div> | ||
</main> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.