From 26bc81aa56f83a808aea28a2e074a36e1d84cf75 Mon Sep 17 00:00:00 2001 From: snsd0805 Date: Sun, 11 Jun 2023 17:18:11 +0800 Subject: [PATCH] feat: shop's nav block --- backend/main.py | 12 +++++ src/components/ClientNav.vue | 12 ++--- src/components/PageNavbar.vue | 10 ++++ src/components/ShopNav.vue | 62 ++++++++++++++++++++++++ src/router/index.js | 6 +++ src/views/ClientCreditView.vue | 7 ++- src/views/ClientInfoView.vue | 12 +++-- src/views/ClientMainView.vue | 29 ++++++++++- src/views/ClientPayView.vue | 7 ++- src/views/ShopPayView.vue | 88 ++++++++++++++++++++++++++++++++++ 10 files changed, 232 insertions(+), 13 deletions(-) create mode 100644 src/components/ShopNav.vue create mode 100644 src/views/ShopPayView.vue diff --git a/backend/main.py b/backend/main.py index 4cbaba6..7b42836 100644 --- a/backend/main.py +++ b/backend/main.py @@ -94,6 +94,18 @@ def get_order(id): return jsonify(ans) +@app.route('/shop/check', methods=['POST']) +def shop_check(): + address = request.get_json()['address'] + db = sqlite3.connect(DATABASE) + cursor = db.cursor() + cursor.execute("SELECT COUNT(*) FROM `shops` WHERE `address`=?", (address, )) + result = cursor.fetchone()[0] + print(result, type(result)) + if result != 0: + return jsonify({'status': True}) + else: + return jsonify({'status': False}) if __name__ == '__main__': initDB() diff --git a/src/components/ClientNav.vue b/src/components/ClientNav.vue index 88c3e59..791f759 100644 --- a/src/components/ClientNav.vue +++ b/src/components/ClientNav.vue @@ -2,14 +2,14 @@ export default { name: 'ClientNav', props: ['path'], - mounted () { - console.log(this.path) - this.navCSS[this.path] += ' is-active' - console.log(this.navCSS) + mounted() { + if (this.path in this.navCSS) { + this.navCSS[this.path] += ' is-active' + } }, - data () { + data() { return { - navCSS: { + navCSS: { main: 'panel-block', pay: 'panel-block', credit: 'panel-block', diff --git a/src/components/PageNavbar.vue b/src/components/PageNavbar.vue index 50212f6..8444b54 100644 --- a/src/components/PageNavbar.vue +++ b/src/components/PageNavbar.vue @@ -44,6 +44,15 @@ export default { this.web3.eth.defaultAccount = clientAddr var returnNumber = await token.methods.getSBTNumber(clientAddr).call({from: clientAddr}) if (returnNumber != 0){ + var result = await fetch(import.meta.env.VITE_BACKEND_PREFIX+"/shop/check", { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({'address': clientAddr}) + }) + var result = await result.json() + this.$cookies.set('isShop', result.status) this.$cookies.set('address', clientAddr) this.$cookies.set('linked', true) this.$cookies.set('SBTNumber', returnNumber) @@ -71,6 +80,7 @@ export default { this.$cookies.remove('linked') this.$cookies.remove('address') this.$cookies.remove('SBTNumber') + this.$cookies.remove('shop') this.$router.push('/') } } diff --git a/src/components/ShopNav.vue b/src/components/ShopNav.vue new file mode 100644 index 0000000..2fb132e --- /dev/null +++ b/src/components/ShopNav.vue @@ -0,0 +1,62 @@ + + + diff --git a/src/router/index.js b/src/router/index.js index c553cb9..cb7925a 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -8,6 +8,7 @@ import ClientInfoView from '../views/ClientInfoView.vue' import ClientCreditView from '../views/ClientCreditView.vue' import ClientPayView from '../views/ClientPayView.vue' import PaymentView from '../views/PaymentView.vue' +import ShopPayView from '../views/ShopPayView.vue' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), @@ -57,6 +58,11 @@ const router = createRouter({ name: 'clientpayment', component: PaymentView }, + { + path: '/shop/pay', + name: 'shoppay', + component: ShopPayView + }, ] }) diff --git a/src/views/ClientCreditView.vue b/src/views/ClientCreditView.vue index 03d9e64..356c27b 100644 --- a/src/views/ClientCreditView.vue +++ b/src/views/ClientCreditView.vue @@ -7,6 +7,7 @@ import WarningModal from '../components/WarningModal.vue' import SuccessModal from '../components/SuccessModal.vue' import { useClientStore } from '../stores/Client.js' import ClientNav from '../components/ClientNav.vue' +import ShopNav from '../components/ShopNav.vue' // To use Html5QrcodeScanner (more info below) import { Html5QrcodeScanner } from "html5-qrcode"; @@ -17,7 +18,7 @@ import { Html5Qrcode } from "html5-qrcode"; export default { - components: { PageTitle, WarningModal, SuccessModal, ClientNav }, + components: { PageTitle, WarningModal, SuccessModal, ClientNav, ShopNav }, data() { return { SBTAddress: import.meta.env.VITE_SBT_ADDR, @@ -94,6 +95,10 @@ export default {
+ +
diff --git a/src/views/ClientInfoView.vue b/src/views/ClientInfoView.vue index f8a6edf..9fe98d0 100644 --- a/src/views/ClientInfoView.vue +++ b/src/views/ClientInfoView.vue @@ -8,6 +8,7 @@ import WarningModal from '../components/WarningModal.vue' import SuccessModal from '../components/SuccessModal.vue' import { useClientStore } from '../stores/Client.js' import ClientNav from '../components/ClientNav.vue' +import ShopNav from '../components/ShopNav.vue' // To use Html5QrcodeScanner (more info below) import { Html5QrcodeScanner } from "html5-qrcode"; @@ -17,7 +18,7 @@ import { Html5Qrcode } from "html5-qrcode"; export default { - components: { PageTitle, WarningModal, SuccessModal, ClientNav }, + components: { PageTitle, WarningModal, SuccessModal, ClientNav, ShopNav }, data() { return { SBTAddress: import.meta.env.VITE_SBT_ADDR, @@ -82,6 +83,10 @@ export default {
+ +
@@ -98,7 +103,7 @@ export default { 目前信用額度: - {{ this.credit }} ETH (尚可使用 {{ this.credit-this.arrear }} ETH) + {{ this.credit }} ETH (尚可使用 {{ this.credit - this.arrear }} ETH) @@ -116,7 +121,8 @@ export default { Soulbound Token NFT 證書: - {{ picName }}
+ {{ picName }}
+ diff --git a/src/views/ClientMainView.vue b/src/views/ClientMainView.vue index 0bcc868..7022e6c 100644 --- a/src/views/ClientMainView.vue +++ b/src/views/ClientMainView.vue @@ -30,7 +30,8 @@ export default { token: null, isWaiting: false, log: [], - scanner: null + scanner: null, + isShop: false } }, async mounted() { @@ -40,6 +41,7 @@ export default { this.web3 = new Web3(window.ethereum) this.clientAddr = this.$cookies.get('address') this.web3.eth.defaultAccount = this.clientAddr + this.isShop = (this.$cookies.get('isShop') == 'true') }, methods: { onScanSuccess(decodedText, decodedResult) { @@ -47,7 +49,7 @@ export default { console.log(`Code matched = ${decodedText}`, decodedResult); this.scanner.clear() }, - scan () { + scan() { this.scanner = new Html5QrcodeScanner( "reader", { fps: 10, qrbox: { width: 250, height: 250 } }, @@ -96,6 +98,29 @@ export default { + + + +
diff --git a/src/views/ClientPayView.vue b/src/views/ClientPayView.vue index b431631..fe7dc48 100644 --- a/src/views/ClientPayView.vue +++ b/src/views/ClientPayView.vue @@ -6,13 +6,14 @@ import PageTitle from '../components/PageTitle.vue' import WarningModal from '../components/WarningModal.vue' import SuccessModal from '../components/SuccessModal.vue' import ClientNav from '../components/ClientNav.vue' +import ShopNav from '../components/ShopNav.vue' // To use Html5QrcodeScanner (more info below) import { Html5QrcodeScanner } from "html5-qrcode"; export default { - components: { PageTitle, WarningModal, SuccessModal, ClientNav }, + components: { PageTitle, WarningModal, SuccessModal, ClientNav, ShopNav }, data() { return { SBTAddress: import.meta.env.VITE_SBT_ADDR, @@ -71,6 +72,10 @@ export default {
+ +
diff --git a/src/views/ShopPayView.vue b/src/views/ShopPayView.vue new file mode 100644 index 0000000..ae8f038 --- /dev/null +++ b/src/views/ShopPayView.vue @@ -0,0 +1,88 @@ + + +