Commit 5ad2708a authored by brent's avatar brent

add bus

parent efd7f4d6
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"name": "AONET", "name": "AONET",
"version": "0.0.0", "version": "0.0.0",
"dependencies": { "dependencies": {
"aonweb": "^1.0.0", "aonweb": "^1.0.1",
"aos": "^2.3.4", "aos": "^2.3.4",
"axios": "^1.6.8", "axios": "^1.6.8",
"element-plus": "^2.7.5", "element-plus": "^2.7.5",
...@@ -1853,9 +1853,9 @@ ...@@ -1853,9 +1853,9 @@
} }
}, },
"node_modules/aonweb": { "node_modules/aonweb": {
"version": "1.0.0", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/aonweb/-/aonweb-1.0.0.tgz", "resolved": "https://registry.npmjs.org/aonweb/-/aonweb-1.0.1.tgz",
"integrity": "sha512-5BEDJb15A1cRu3/uAm4YIbGhmXiuyM9mrO3X0TvQIGcFkb3zeO30G0vNHLGAgwS9DAKNWFkFol0POuVp4dawXA==", "integrity": "sha512-oh5cjsy4T1yWykh31ATbCQCmXQXVekpKXGS34O22DrC0mME6ci6S6qHZuEpEfkbLpeWCZw5G8BXMg+qeyFrL4w==",
"dependencies": { "dependencies": {
"@fingerprintjs/fingerprintjs": "^4.4.0", "@fingerprintjs/fingerprintjs": "^4.4.0",
"bignumber.js": "^9.1.2", "bignumber.js": "^9.1.2",
...@@ -5621,9 +5621,9 @@ ...@@ -5621,9 +5621,9 @@
} }
}, },
"aonweb": { "aonweb": {
"version": "1.0.0", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/aonweb/-/aonweb-1.0.0.tgz", "resolved": "https://registry.npmjs.org/aonweb/-/aonweb-1.0.1.tgz",
"integrity": "sha512-5BEDJb15A1cRu3/uAm4YIbGhmXiuyM9mrO3X0TvQIGcFkb3zeO30G0vNHLGAgwS9DAKNWFkFol0POuVp4dawXA==", "integrity": "sha512-oh5cjsy4T1yWykh31ATbCQCmXQXVekpKXGS34O22DrC0mME6ci6S6qHZuEpEfkbLpeWCZw5G8BXMg+qeyFrL4w==",
"requires": { "requires": {
"@fingerprintjs/fingerprintjs": "^4.4.0", "@fingerprintjs/fingerprintjs": "^4.4.0",
"bignumber.js": "^9.1.2", "bignumber.js": "^9.1.2",
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
"type-check": "vue-tsc --build --force" "type-check": "vue-tsc --build --force"
}, },
"dependencies": { "dependencies": {
"aonweb": "^1.0.0", "aonweb": "^1.0.1",
"aos": "^2.3.4", "aos": "^2.3.4",
"axios": "^1.6.8", "axios": "^1.6.8",
"element-plus": "^2.7.5", "element-plus": "^2.7.5",
......
...@@ -21,9 +21,9 @@ import { ...@@ -21,9 +21,9 @@ import {
computed computed
} from 'vue'; } from 'vue';
import { useRouter,useRoute } from 'vue-router' import { useRouter,useRoute } from 'vue-router'
// import { User } from 'aonweb' import { User } from 'aonweb'
// import eventBus from '../eventBus.js'; import bus from '../eventBus.js';
const router = useRouter() const router = useRouter()
const route = useRoute() const route = useRoute()
...@@ -53,20 +53,28 @@ const goUser = () => { ...@@ -53,20 +53,28 @@ const goUser = () => {
}; };
// const balance = async () => { const balance = async () => {
// let user = new User() console.log("balance in")
// let result = await user.balance() let user = new User()
// if (result && result._balances && result._balances.length) { let result = await user.balance()
// balanceValue = result._balances[0] console.log("Header balance ",result)
// balanceValue = balanceValue / 1000000000000000000n if (result && result._balances && result._balances.length) {
// } let temp = result._balances[0]
// }; balanceValue.value = temp / 1000000000000000000n
}
console.log("Header balanceValue.value ",balanceValue.value)
};
// const handleBalance = (message) => { // const handleBalance = (message) => {
// console.log("handleBalance",message) // console.log("handleBalance",message)
// balance() // balance()
// } // }
bus.on('get_balance', (data) => {
console.log("get_balance",data)
balance()
});
const checkIfUserPage = () => { const checkIfUserPage = () => {
isUserPage.value = route.path === '/user' isUserPage.value = route.path === '/user'
}; };
......
import { createApp } from 'vue'; import mitt from 'mitt';
const eventBus = createApp({}); const bus = mitt();
export default eventBus; export default bus;
\ No newline at end of file \ No newline at end of file
...@@ -75,12 +75,13 @@ import { ref, onMounted } from 'vue'; ...@@ -75,12 +75,13 @@ import { ref, onMounted } from 'vue';
import { showToast } from 'vant'; import { showToast } from 'vant';
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { AI,AIOptions} from 'aonweb' import { AI,AIOptions,User} from 'aonweb'
import { getTemplate } from '../lib/getTemplate' import { getTemplate } from '../lib/getTemplate'
import 'vant/lib/index.css'; import 'vant/lib/index.css';
import Header from '../components/Header.vue'; import Header from '../components/Header.vue';
import Loading from '../components/Loading.vue'; import Loading from '../components/Loading.vue';
import bus from '../eventBus.js';
const router = useRouter() const router = useRouter()
...@@ -191,6 +192,7 @@ const formSubmit = async () => { ...@@ -191,6 +192,7 @@ const formSubmit = async () => {
let price = 10 let price = 10
let response = await aonet.prediction("/predictions/ai/pulid", data,price) let response = await aonet.prediction("/predictions/ai/pulid", data,price)
console.log("test", response) console.log("test", response)
bus.emit('get_balance',"prediction");
if (response && response.code == 200 && response.data) { if (response && response.code == 200 && response.data) {
response = response.data response = response.data
} }
...@@ -232,8 +234,27 @@ function selectTemplate(id, imageUrl, prompt_) { ...@@ -232,8 +234,27 @@ function selectTemplate(id, imageUrl, prompt_) {
prompt.value = prompt_ prompt.value = prompt_
} }
async function login() {
console.log('index login')
let user = new User()
let temp = await user.islogin()
if (!temp) {
console.log('index islogin')
await user.login((acc,userId,error) => {
console.log("getWeb3 account",acc)
console.log("getWeb3 userId",userId)
console.log("getWeb3 error",error)
bus.emit('get_balance',"login");
// eventBus.config.globalProperties.$emit('balance');
})
}
bus.emit('get_balance',"login");
console.log('index islogin sssss',temp)
}
onMounted(() => { onMounted(() => {
getTemplateList() getTemplateList()
login()
}) })
</script> </script>
......
...@@ -43,7 +43,7 @@ import { Options, User } from 'aonweb' ...@@ -43,7 +43,7 @@ import { Options, User } from 'aonweb'
import { showToast } from 'vant'; import { showToast } from 'vant';
import Header from '../components/Header.vue'; import Header from '../components/Header.vue';
// import eventBus from '../eventBus.js'; import bus from '../eventBus.js';
...@@ -78,13 +78,23 @@ async function getAccount() { ...@@ -78,13 +78,23 @@ async function getAccount() {
//User 的使用方法 //User 的使用方法
let user = new User() let user = new User()
await user.login((acc,userId,error) => { if (!await user.islogin()) {
console.log("getWeb3 account",account) await user.login((acc,userId,error) => {
console.log("getWeb3 userId",userId) console.log("getWeb3 account",acc)
console.log("getWeb3 error",error) console.log("getWeb3 userId",userId)
account.value = acc console.log("getWeb3 error",error)
// eventBus.config.globalProperties.$emit('balance'); account.value = acc
}) bus.emit('get_balance',"login");
// eventBus.config.globalProperties.$emit('balance');
})
} else {
let ethereum = await detectEthereumProvider()
let get_account = await ethereum.request({ method: 'eth_requestAccounts' })
get_account = get_account[0]
account.value = get_account
bus.emit('get_balance',"login");
}
// console.log("getWeb3 account", addr) // console.log("getWeb3 account", addr)
// account.value = addr[0] // account.value = addr[0]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment