Commit 97f0e0da authored by hanfeng zhang's avatar hanfeng zhang

1

parent 00c7745d
This diff is collapsed.
......@@ -9,12 +9,17 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"ahooks-vue": "^0.12.0",
"ant-design-vue": "^1.7.5",
"axios": "^0.21.1",
"base64-js": "^1.5.1",
"bitcoinjs-lib": "^5.2.0",
"clipboard": "^2.0.8",
"core-js": "^3.6.5",
"enc-utils": "^3.0.0",
"mockjs": "^1.1.0",
"register-service-worker": "^1.7.1",
"secp256k1": "^4.0.2",
"validator": "^13.6.0",
"vant": "^2.12.22",
"vue": "^2.6.11",
......@@ -24,6 +29,7 @@
},
"devDependencies": {
"@types/mockjs": "^1.0.4",
"@types/secp256k1": "^4.0.3",
"@types/validator": "^13.6.3",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
......
......@@ -5,26 +5,45 @@ import router from '@/router'
import { Toast } from 'vant'
interface RouterConfig{
path: string
method?: string
crediential?: boolean
dataType?: string
headers?:string[][]
}
export default class BaseService {
public service: AxiosInstance;
private service: AxiosInstance;
constructor() {
this.service = axios.create({
baseURL:'/proxyApi',
timeout: 15000,
})
const get = this.service.get
const post = this.service.post
const resolveData = async (ret: any) => {
if (ret.code === 200){
if(ret.data){
return ret.data;
}
return ret
this.service.interceptors.request.use(
(res)=>{
return res
},
(err)=>{
throw new Error(err)
}
)
}
public async useService(routerConfig: RouterConfig,payload?:any){
let token;
let headerItems:{[key:string]:string|number} ={}
if(!routerConfig.method) routerConfig.method = 'post'
if(routerConfig.crediential) token = 'MOCK'
switch(routerConfig.method){
case 'post':
routerConfig.crediential&&Object.assign(headerItems,{'FZM-SIGNATURE':token})
routerConfig.headers&&routerConfig.headers.map(i=>{
headerItems[i[0]] = i[1]
})
const res = await this.service.post(routerConfig.path,payload,{
headers:headerItems
})
return res
}
this.service.interceptors.request.use()
}
}
\ No newline at end of file
export interface AcceptJoinDTO{
"expiration": number,
"inviterId": string,
"name": string,
"oaServer": string,
"depId": string,
"entId": string,
"hash": string,
"joinTime": number,
"phone": string,
"position": string
}
\ No newline at end of file
import BaseService from '../base'
import { AcceptJoinDTO } from './Enterprise.dto'
export default class Enterprise extends BaseService {
router= {
accept:{ path:'/v1/enterprise/accept-join',headers:[['df','1'],['sdfsdfl','dsfsd']]},
create:{ path:'/v1/enterprise/create'},
delete:{ path:'/v1/enterprise/delete'},
info:{ path:'/v1/enterprise/info'},
update:{ path:'/v1/enterprise/update'},
leader:{ path:'/v1/enterprise/update-leader'}
}
constructor(){
super()
}
async acceptJoin(data:AcceptJoinDTO){
return await this.useService(this.router.accept,data)
}
}
import secp256k1 from 'secp256k1'
import { crypto } from 'bitcoinjs-lib'
import { utf8ToBuffer } from 'enc-utils'
import base64 from 'base64-js'
let latestSig = ''
let forAccount = ''
let updateTime = 0
/**
* 对消息进行签名
* 结果必须为 65 字节长度,不然后端验证不成功;
* 最后一个字节的数据为 `recover id`
*/
export function sign(message: string, privateKey: Uint8Array): Uint8Array {
const hashedMessage = crypto.sha256(utf8ToBuffer(message))
/** 签名本身为 64 字节长 */
const { signature, recid } = secp256k1.ecdsaSign(hashedMessage, privateKey)
const outputSignature = new Uint8Array(65)
outputSignature.set(signature)
outputSignature.set([recid], 64)
return outputSignature
}
export interface Account {
mnemonic?: string
address: string
privateKey: Uint8Array
privateKeyHex: string
publicKey: Uint8Array
publicKeyHex: string
}
export function generateToken(account: Account): string {
const timeDiff = Date.now() - updateTime
if (timeDiff < 60 * 1000 && latestSig && forAccount == account.address) return latestSig
const message = String(Date.now()) + '*'
const signature = sign(message, account.privateKey)
const base64Signature = base64.fromByteArray(signature)
updateTime = Date.now()
forAccount = account.address
latestSig = `${base64Signature}#${message}#${account.publicKeyHex}`
return latestSig
}
......@@ -93,7 +93,7 @@ export default Vue.extend({
this.time = hh+ ':'+ mf+ ':'+ ss
},
currentTime(){
this.timer = setInterval(this.getTime,1000)
// this.timer = setInterval(this.getTime,1000)
},
check(){
let isShow = true
......@@ -114,7 +114,7 @@ export default Vue.extend({
},
mounted(){
this.getTime()
this.currentTime()
// this.currentTime()
},
beforeDestroy(){
if(this.timer){
......
......@@ -146,9 +146,9 @@ export default Vue.extend({
if (timer !== null) {
clearTimeout(timer)
}
timer = setTimeout(() => {
fn()
}, delay)
// timer = setTimeout(() => {
// fn()
// }, delay)
}
},
scrollHandler() {
......
......@@ -18,10 +18,17 @@ module.exports = {
}
},
devServer: {
proxy: 'http://localhost:8080', // 请求的ip或者域名:端口号
public: '127.0.0.1:8080', // 本地的ip:端口号
port: '8080'
}
// proxy: { // 设置代理
// '/proxyApi': {
// target:process.env.VUE_APP_URL,
// // target: 'http://' + "124.71.183.184:8093",
// changeOrigin: true,
// pathRewrite: {
// '^/proxyApi': ''
// }
// }
// }
},
// pwa: {
// name: 'My App',
// themeColor: '#4DBA87',
......
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