This commit is contained in:
huangjinming 2023-03-10 09:55:18 +08:00
parent c4f31dd08e
commit 823c5727df
8 changed files with 76 additions and 44 deletions

View File

@ -7,7 +7,7 @@ module.exports = {
propList: ['*'], // 能转化为vw的属性列表
viewportUnit: 'vw', // 希望使用的视口单位
fontViewportUnit: 'vw', // 字体使用的视口单位
selectorBlackList: [], // 需要忽略的CSS选择器不会转为视口单位使用原有的px等单位。
selectorBlackList: ['.bg-middle'], // 需要忽略的CSS选择器不会转为视口单位使用原有的px等单位。
minPixelValue: 1, // 设置最小的转换数值如果为1的话只有大于1的值会被转换
mediaQuery: false, // 媒体查询里的单位是否需要转换单位
replace: true, // 是否直接更换属性值,而不添加备用属性

View File

@ -43,6 +43,7 @@ export const logout = () =>
// })
export const getNonce = (params) =>
request({
url: '/webapp/index.php?c=Market&a=getNonce',
method: 'get',

View File

@ -62,6 +62,7 @@ export default class ChainManager {
}
public async login() {
if (!AppModule.step) {
try {
await this.bc.connect(true)
@ -75,6 +76,7 @@ export default class ChainManager {
public async checkNance() {
try {
let nonce = AppModule.nonce
if (!nonce) {
const preRequest: any = await getNonce({
@ -101,6 +103,7 @@ export default class ChainManager {
public async getNance() {
console.log('need get nance')
try {
const preRequest: any = await getNonce({
account: AppModule.accountId,
net_id: AppModule.chainId

View File

@ -100,6 +100,7 @@ export class Blockchain {
this.subscribeToEvents()
const accounts = await this.web3.eth.getAccounts()
if (accounts && accounts.length > 0) {
AppModule.updateAccount(accounts[0])
}
if (!this.currentChain) this.currentChain = chainId

View File

@ -66,17 +66,21 @@ function click(event) {
}
const formatAddress = computed(() => {
if (AppModule.accountId.length >= 10) {
console.log(AppModule.accountId.value,'AppModule.accountId');
if(!AppModule.accountId.value){
return '-'
}
if (AppModule.accountId.value.length >= 10) {
return (
AppModule.accountId.substring(0, 6) +
AppModule.accountId.value.substring(0, 6) +
"......" +
AppModule.accountId.substring(AppModule.accountId.length - 4)
AppModule.accountId.value.substring(AppModule.accountId.value.length - 4)
);
} else if (
AppModule.accountId.length > 0 &&
AppModule.accountId.length < 10
AppModule.accountId.value.length > 0 &&
AppModule.accountId.value.length < 10
) {
return AppModule.accountId;
return AppModule.accountId.value
} else {
return "-";
}

View File

@ -27,6 +27,7 @@ export const useAppStore = defineStore('app', () => {
}
function updateAccount(_accountId) {
accountId.value = _accountId;
}
function updateChainID(_chainId) {

View File

@ -1,76 +1,93 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
import { getToken, setToken, removeToken } from '@/utils/cookies';
import glodata from './user_global';
import { defineStore } from "pinia";
import { ref } from "vue";
import {
getToken,
setToken,
removeToken,
getAccountId,
setAccountId,
removeAccountId
} from "@/utils/cookies";
import glodata from "./user_global";
import pinia from '@/store'
import { useAppStore } from '@/store/app'
import pinia from "@/store";
import { useAppStore } from "@/store/app";
const AppModule = useAppStore(pinia);
glodata.token = getToken();
glodata.accountId = AppModule.accountId;
glodata.chainId = AppModule.chainId;
import { login } from '@/api/User';
export const useUserStore = defineStore('user', () => {
glodata.accountId = AppModule.accountId.value;
glodata.chainId = AppModule.chainId.value;
import { login } from "@/api/User";
export const useUserStore = defineStore("user", () => {
const EIP721_DOMAIN_DATA = [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' }
{ name: "name", type: "string" },
{ name: "version", type: "string" },
];
const token = ref(getToken());
const accountId = ref(getAccountId());
AppModule.updateAccount(accountId);
if(token.value && accountId.value){
AppModule.updateStep(1);
}
async function Login({bcInstance, account, chainId, nonce}) {
nonce += ''
const tips = 'This signature is only used for verify your account'
async function Login({ bcInstance, account, chainId, nonce }) {
nonce += "";
const tips = "This signature is only used for verify your account";
const signMsg = {
tips,
nonce
}
nonce,
};
const signObj = {
types: {
EIP712Domain: EIP721_DOMAIN_DATA,
set: [
{ name: 'tips', type: 'string' },
{ name: 'nonce', type: 'string' }
]
{ name: "tips", type: "string" },
{ name: "nonce", type: "string" },
],
},
primaryType: 'set',
primaryType: "set",
domain: {
name: 'Auth',
version: '1'
name: "Auth",
version: "1",
},
message: signMsg
}
const signature = await bcInstance.signData(signObj, account)
message: signMsg,
};
const signature = await bcInstance.signData(signObj, account);
const authData = {
account,
nonce,
signature,
tips,
net_id: chainId
}
console.log('login data: ', authData)
const res = await login(authData)
net_id: chainId,
};
console.log("login data: ", authData);
const res = await login(authData);
if (!res.errcode && res.token) {
setToken(res.token)
setToken(res.token);
console.log(res, "resres");
setAccountId(account);
AppModule.updateToken(res.token);
token.value = res.token;
}
}
function Logout() {
if (token==='') {
if (token === "") {
return;
}
removeAccountId()
removeToken();
token.value = '';
token.value = "";
accountId.value=''
AppModule.updateAccount('')
}
return {
return {
token,
Login,
Logout,
}
})
};
});

View File

@ -14,6 +14,11 @@ export const setMini = (mini: string) => Cookies.set(miniKey, mini)
// User
const tokenKey = 'vue_typescript_access_token'
const accountIdKey = 'vue_typescript_access_accountId'
export const getToken = () => localStorage.getItem(tokenKey)
export const setToken = (token: string) => localStorage.setItem(tokenKey, token)
export const removeToken = () => localStorage.removeItem(tokenKey)
export const getAccountId = () => localStorage.getItem(accountIdKey)
export const setAccountId = (accountId: string) => localStorage.setItem(accountIdKey, accountId)
export const removeAccountId = () => localStorage.removeItem(accountIdKey)