提交 a7215867 作者: 李程佳

同步代码

上级 7745098b
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -4,93 +4,63 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<title id="title">Document</title>
<link rel="stylesheet" href="element-ui.min.css">
<link rel="stylesheet" href="./VFormRender.css">
<link rel="stylesheet" href="VFormRender.css">
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body, html {
width: 100%;
height: 100%;
margin:0;
font-family:"微软雅黑";
overflow-x: hidden;
background-color: #FFFFFF;
}
</style>
</head>
<body>
<div id="app" v-loading="loading" style="padding: 10px;width: 100vw;height: 100vh;">
<div id="app" v-loading="loading" style="width: 93vw;height: 100vh;">
<v-form-render :preview-state="true" identi-fication='XCX' :form-json="formJson" :form-data="formData"
:option-data="optionData" ref="vFormRef">
</v-form-render>
<!-- <el-button type="primary">Button</el-button> -->
<!-- <div>{{msg}}</div>
<button @click="btnClick">我是按钮</button> -->
</div>
<!-- <div id="testStr">
</div> -->
<!-- <script type="text/javascript">
var userAgent = navigator.userAgent;
if (userAgent.indexOf('AlipayClient') > -1) {
// 支付宝小程序的 JS-SDK 防止 404 需要动态加载,如果不需要兼容支付宝小程序,则无需引用此 JS 文件。
document.writeln('<script src="https://appx/web-view.min.js"' + '>' + '<' + '/' + 'script>');
} else if (/QQ/i.test(userAgent) && /miniProgram/i.test(userAgent)) {
// QQ 小程序
document.write(
'<script type="text/javascript" src="https://qqq.gtimg.cn/miniprogram/webview_jssdk/qqjssdk-1.0.0.js"><\/script>'
);
} else if (/miniProgram/i.test(userAgent) && /micromessenger/i.test(userAgent)) {
// 微信小程序 JS-SDK 如果不需要兼容微信小程序,则无需引用此 JS 文件。
document.write('<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"><\/script>');
} else if (/toutiaomicroapp/i.test(userAgent)) {
// 头条小程序 JS-SDK 如果不需要兼容头条小程序,则无需引用此 JS 文件。
document.write(
'<script type="text/javascript" src="https://s3.pstatp.com/toutiao/tmajssdk/jssdk-1.0.1.js"><\/script>');
} else if (/swan/i.test(userAgent)) {
// 百度小程序 JS-SDK 如果不需要兼容百度小程序,则无需引用此 JS 文件。
document.write(
'<script type="text/javascript" src="https://b.bdstatic.com/searchbox/icms/searchbox/js/swan-2.0.18.js"><\/script>'
);
} else if (/quickapp/i.test(userAgent)) {
// quickapp
document.write('<script type="text/javascript" src="https://quickapp/jssdk.webview.min.js"><\/script>');
}
</script> -->
<script src="jsbn.js"></script>
<script src="sm2.js"></script>
<script src="vuex.min.js"></script>
<script src="vue.min.js"></script>
<script src="vuex.min.js"></script>
<script src="mitt.js"></script>
<script src="element-ui.min.js"></script>
<script src="VFormRender.umd.js"></script>
<script src="VFormRender.umd.min.js"></script>
<script src="axios.min.js"></script>
<script src="common.js"></script>
<script src="uni-webview.js"></script>
<script src="jweixin.js"></script>
<script type="text/javascript" src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=3YILlt9BGfidJTSR3VOIi0QhTyWngyEX"></script>
<script>
// alert("加载页面")
console.log("开始获取浏览器参数==>")
let keypair = sm2.generateKeyPairHex()
let publicKey = keypair.publicKey
let privateKey = keypair.privateKey
console.log('生成公钥',publicKey)
console.log('生成私钥',privateKey)
var vm
// let params = getUrlPatams()
// let urlParams = JSON.parse(params)
let params = getUrlPatams()
let urlParams = JSON.parse(params)
console.log('-----------urlParams--', urlParams)
document.getElementById('title').innerHTML = urlParams.title
if(urlParams.sessionData){
setSessionStorage(urlParams.sessionData)
}
// 存放参数
// setLocalData(urlParams)
setLocalData(urlParams)
// 初始化请求头
let headers = initRequestHead()
console.log("请求头", headers);
// 初始化请求类
// let request = initRequest(headers, urlParams.modeEvn)
let request = initRequest(headers)
let request = initRequest(headers, urlParams.modeEvn,urlParams.SERVER_PUBLIC_KEY,urlParams.PRIVATE_KEY)
// let request = initRequest(headers)
var __glob_easyform_html_obj = {
async customMethods(requestConfig) {
console.log('requestConfig', requestConfig);
let { requestMethod, url, headers, data, params } = requestConfig
return await request({
url,
......@@ -105,6 +75,7 @@
})
}
}
window.onload = async function () {
console.log("HTML加载完毕==>")
vm = new Vue({
......@@ -118,28 +89,49 @@
async created() {
this.loading = true
// 获取字典
// await this.getDic()
await this.getDic()
// alert("获取字典完毕")
// 获取funcNo
// let res = await this.getFuncNo()
// if (res.code === '000000') {
// // 获取json串
// let res1 = await this.getJsonCode(res.retObj.funcNo)
// if (res1.code === '000000') {
// this.$refs.vFormRef.setFormJson(res1.retObj.code)
// }
// }
let res = await this.getFuncNo()
if (res.code === '000000') {
sessionStorage.setItem('tempNo', res.retObj.tempNo)
// 这里是模拟数据
let json = await MockJson()
// let json = await MockJson()
// 设置json串
this.$refs.vFormRef.setFormJson(json)
// this.$refs.vFormRef.setFormJson(json)
// 获取json串
let res1 = await this.getJsonCode(res.retObj.funcNo)
if (res1.code === '000000') {
this.$refs.vFormRef.setFormJson(res1.retObj.code)
}
}
// 这里是模拟数据
// let json = await MockJson()
// // 设置json串
// this.$refs.vFormRef.setFormJson(json)
this.loading = false
// await this.getLoanJsonCode()
// await this.getLocation()
},
methods: {
// 获取字典
async getDic() {
// 缓存版本号
const versionNoStorage = localStorage.getItem('versionNo')
// 最新获取的版本号
const versionNo = urlParams.versionNo
if(!versionNoStorage){
if (urlParams.isForceUpdate === '1') {
localStorage.removeItem('LOCALSTORAGE_GLOBLE_DIC_KEY_FROM_AVUE')
}
}else{
if (versionNoStorage !== versionNo) {
if (urlParams.isForceUpdate === '1') {
localStorage.removeItem('LOCALSTORAGE_GLOBLE_DIC_KEY_FROM_AVUE')
}
}
}
localStorage.setItem('versionNo',versionNo)
// 先获取字典
if (!localStorage.getItem('LOCALSTORAGE_GLOBLE_DIC_KEY_FROM_AVUE')) {
let { code, retObj } = await request({
......@@ -157,12 +149,14 @@
},
//获取funcNo
async getFuncNo() {
const tempBigClass = urlParams.tempBigClass
const tempSmallClass = urlParams.tempSmallClass
let res = await request({
url: '/XCX_CDB02031101',
method: 'post',
data: {
tempBigClass: 'smes',
tempSmallClass: 'smes02',
tempBigClass: tempBigClass,
tempSmallClass: tempSmallClass,
},
headers: {
SERVICE_ID: 'cmdb',
......@@ -207,8 +201,20 @@
}
}
})
// 监听 Hash 变化
window.addEventListener('hashchange', () => {
const currentHash = window.location.hash; // 获取当前 Hash(如 "#/about?id=1")
const path = currentHash.split('?')[0]; // 提取路径部分(如 "#/about")
const params = new URLSearchParams(currentHash.split('?')[1] || ''); // 解析参数
const data = JSON.parse(Object.fromEntries(params).id)
if (data !== 'upload') {
for (const key in data) {
vm.$refs.vFormRef.getWidgetRef(key).setValue(data[key])
}
}
history.go(-1)
});
}
</script>
</body>
......
......@@ -641,7 +641,7 @@ function verifyPublicKey(publicKey) {
return y.square().equals(x.multiply(x.square()).add(x.multiply(curve.a)).add(curve.b))
}
var _ = {
var aa = {
getGlobalCurve,
generateEcparam,
generateKeyPairHex,
......@@ -881,17 +881,17 @@ function sm3 (array) {
// SM2.js
const {G,curve,n} = _.generateEcparam()
const {G,curve,n} = aa.generateEcparam()
const C1C2C3 = 0
/**
* 加密
*/
function doEncrypt(msg, publicKey, cipherMode = 1) {
msg = typeof msg === 'string' ? _.hexToArray(_.utf8ToHex(msg)) : Array.prototype.slice.call(msg)
publicKey = _.getGlobalCurve().decodePointHex(publicKey) // 先将公钥转成点
msg = typeof msg === 'string' ? aa.hexToArray(aa.utf8ToHex(msg)) : Array.prototype.slice.call(msg)
publicKey = aa.getGlobalCurve().decodePointHex(publicKey) // 先将公钥转成点
const keypair = _.generateKeyPairHex()
const keypair = aa.generateKeyPairHex()
const k = new BigInteger(keypair.privateKey, 16) // 随机数 k
// c1 = k * G
......@@ -900,11 +900,11 @@ function doEncrypt(msg, publicKey, cipherMode = 1) {
// (x2, y2) = k * publicKey
const p = publicKey.multiply(k)
const x2 = _.hexToArray(_.leftPad(p.getX().toBigInteger().toRadix(16), 64))
const y2 = _.hexToArray(_.leftPad(p.getY().toBigInteger().toRadix(16), 64))
const x2 = aa.hexToArray(aa.leftPad(p.getX().toBigInteger().toRadix(16), 64))
const y2 = aa.hexToArray(aa.leftPad(p.getY().toBigInteger().toRadix(16), 64))
// c3 = hash(x2 || msg || y2)
const c3 = _.arrayToHex(sm3([].concat(x2, msg, y2)))
const c3 = aa.arrayToHex(sm3([].concat(x2, msg, y2)))
let ct = 1
let offset = 0
......@@ -926,7 +926,7 @@ function doEncrypt(msg, publicKey, cipherMode = 1) {
// c2 = msg ^ t
msg[i] ^= t[offset++] & 0xff
}
const c2 = _.arrayToHex(msg)
const c2 = aa.arrayToHex(msg)
return cipherMode === C1C2C3 ? c1 + c2 + c3 : c1 + c3 + c2
}
......@@ -947,12 +947,12 @@ function doDecrypt(encryptData, privateKey, cipherMode = 1, {
c2 = encryptData.substr(128, encryptData.length - 128 - 64)
}
const msg = _.hexToArray(c2)
const c1 = _.getGlobalCurve().decodePointHex('04' + encryptData.substr(0, 128))
const msg = aa.hexToArray(c2)
const c1 = aa.getGlobalCurve().decodePointHex('04' + encryptData.substr(0, 128))
const p = c1.multiply(privateKey)
const x2 = _.hexToArray(_.leftPad(p.getX().toBigInteger().toRadix(16), 64))
const y2 = _.hexToArray(_.leftPad(p.getY().toBigInteger().toRadix(16), 64))
const x2 = aa.hexToArray(aa.leftPad(p.getX().toBigInteger().toRadix(16), 64))
const y2 = aa.hexToArray(aa.leftPad(p.getY().toBigInteger().toRadix(16), 64))
let ct = 1
let offset = 0
......@@ -976,10 +976,10 @@ function doDecrypt(encryptData, privateKey, cipherMode = 1, {
}
// c3 = hash(x2 || msg || y2)
const checkC3 = _.arrayToHex(sm3([].concat(x2, msg, y2)))
const checkC3 = aa.arrayToHex(sm3([].concat(x2, msg, y2)))
if (checkC3 === c3) {
return output === 'array' ? msg : _.arrayToUtf8(msg)
return output === 'array' ? msg : aa.arrayToUtf8(msg)
} else {
return output === 'array' ? [] : ''
}
......@@ -995,7 +995,7 @@ function doSignature(msg, privateKey, {
publicKey,
userId
} = {}) {
let hashHex = typeof msg === 'string' ? _.utf8ToHex(msg) : _.arrayToHex(msg)
let hashHex = typeof msg === 'string' ? aa.utf8ToHex(msg) : aa.arrayToHex(msg)
if (hash) {
// sm3杂凑
......@@ -1031,7 +1031,7 @@ function doSignature(msg, privateKey, {
if (der) return encodeDer(r, s) // asn.1 der 编码
return _.leftPad(r.toString(16), 64) + _.leftPad(s.toString(16), 64)
return aa.leftPad(r.toString(16), 64) + aa.leftPad(s.toString(16), 64)
}
/**
......@@ -1042,7 +1042,7 @@ function doVerifySignature(msg, signHex, publicKey, {
hash,
userId
} = {}) {
let hashHex = typeof msg === 'string' ? _.utf8ToHex(msg) : _.arrayToHex(msg)
let hashHex = typeof msg === 'string' ? aa.utf8ToHex(msg) : aa.arrayToHex(msg)
if (hash) {
// sm3杂凑
......@@ -1083,15 +1083,15 @@ function doVerifySignature(msg, signHex, publicKey, {
*/
function getHash(hashHex, publicKey, userId = '1234567812345678') {
// z = hash(entl || userId || a || b || gx || gy || px || py)
userId = _.utf8ToHex(userId)
const a = _.leftPad(G.curve.a.toBigInteger().toRadix(16), 64)
const b = _.leftPad(G.curve.b.toBigInteger().toRadix(16), 64)
const gx = _.leftPad(G.getX().toBigInteger().toRadix(16), 64)
const gy = _.leftPad(G.getY().toBigInteger().toRadix(16), 64)
userId = aa.utf8ToHex(userId)
const a = aa.leftPad(G.curve.a.toBigInteger().toRadix(16), 64)
const b = aa.leftPad(G.curve.b.toBigInteger().toRadix(16), 64)
const gx = aa.leftPad(G.getX().toBigInteger().toRadix(16), 64)
const gy = aa.leftPad(G.getY().toBigInteger().toRadix(16), 64)
if (publicKey.length > 128) publicKey = publicKey.substr(2, 128) // 干掉 '04'
const px = publicKey.substr(0, 64)
const py = publicKey.substr(64, 64)
const data = _.hexToArray(userId + a + b + gx + gy + px + py)
const data = aa.hexToArray(userId + a + b + gx + gy + px + py)
const entl = userId.length * 4
data.unshift(entl & 0x00ff)
......@@ -1100,7 +1100,7 @@ function getHash(hashHex, publicKey, userId = '1234567812345678') {
const z = sm3(data)
// e = hash(z || msg)
return _.arrayToHex(sm3(z.concat(_.hexToArray(hashHex))))
return aa.arrayToHex(sm3(z.concat(aa.hexToArray(hashHex))))
}
/**
......@@ -1108,8 +1108,8 @@ function getHash(hashHex, publicKey, userId = '1234567812345678') {
*/
function getPublicKeyFromPrivateKey(privateKey) {
const PA = G.multiply(new BigInteger(privateKey, 16))
const x = _.leftPad(PA.getX().toBigInteger().toString(16), 64)
const y = _.leftPad(PA.getY().toBigInteger().toString(16), 64)
const x = aa.leftPad(PA.getX().toBigInteger().toString(16), 64)
const y = aa.leftPad(PA.getY().toBigInteger().toString(16), 64)
return '04' + x + y
}
......@@ -1117,7 +1117,7 @@ function getPublicKeyFromPrivateKey(privateKey) {
* 获取椭圆曲线点
*/
function getPoint() {
const keypair = _.generateKeyPairHex()
const keypair = aa.generateKeyPairHex()
const PA = curve.decodePointHex(keypair.publicKey)
keypair.k = new BigInteger(keypair.privateKey, 16)
......@@ -1152,8 +1152,8 @@ var sm2 = {
// 加密
const serverEncrypt = (text) => {
const publicKey = uni.getStorageSync('SERVER_PUBLIC_KEY')
const serverEncrypt = (text,publicKey,cipherMode) => {
// const publicKey = uni.getStorageSync('SERVER_PUBLIC_KEY')
if (publicKey) {
const encryptTxt = sm2.doEncrypt(text, publicKey, cipherMode)
return encryptTxt
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论