mirror of
https://gitee.com/BDWare/contract-java-example.git
synced 2026-02-14 16:49:30 +00:00
update front development guide
This commit is contained in:
114
front/html/axios-fetch.iife.js
Normal file
114
front/html/axios-fetch.iife.js
Normal file
@@ -0,0 +1,114 @@
|
||||
var axiosFetch = (function (exports) {
|
||||
'use strict';
|
||||
|
||||
var src = {};
|
||||
|
||||
var typeUtils = {};
|
||||
|
||||
Object.defineProperty(typeUtils, "__esModule", { value: true });
|
||||
typeUtils.getUrl = typeUtils.createAxiosHeaders = typeUtils.createFetchHeaders = void 0;
|
||||
function createFetchHeaders(axiosHeaders = {}) {
|
||||
const headers = [];
|
||||
Object.entries(axiosHeaders).forEach(([name, value]) => {
|
||||
headers.push([name, value]);
|
||||
});
|
||||
return headers;
|
||||
}
|
||||
typeUtils.createFetchHeaders = createFetchHeaders;
|
||||
const isHeaders = (headers) => { var _a; return ((_a = headers.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'Headers'; };
|
||||
function createAxiosHeaders(headers = {}) {
|
||||
const rawHeaders = {};
|
||||
if (isHeaders(headers)) {
|
||||
headers.forEach((value, name) => {
|
||||
rawHeaders[name] = value;
|
||||
});
|
||||
}
|
||||
else if (Array.isArray(headers)) {
|
||||
headers.forEach(([name, value]) => {
|
||||
if (value) {
|
||||
rawHeaders[name] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
Object.entries(headers).forEach(([name, value]) => {
|
||||
if (value) {
|
||||
rawHeaders[name] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
return rawHeaders;
|
||||
}
|
||||
typeUtils.createAxiosHeaders = createAxiosHeaders;
|
||||
function getUrl(input) {
|
||||
let url;
|
||||
if (typeof input === 'string') {
|
||||
url = input;
|
||||
}
|
||||
else if (input === null || input === void 0 ? void 0 : input.href) {
|
||||
url = input.href;
|
||||
}
|
||||
else if (input === null || input === void 0 ? void 0 : input.url) {
|
||||
url = input.url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
typeUtils.getUrl = getUrl;
|
||||
|
||||
Object.defineProperty(src, "__esModule", { value: true });
|
||||
exports.buildAxiosFetch = src.buildAxiosFetch = void 0;
|
||||
const typeUtils_1 = typeUtils;
|
||||
/**
|
||||
* A Fetch WebAPI implementation based on the Axios client
|
||||
*/
|
||||
const axiosFetch = (axios,
|
||||
// Convert the `fetch` style arguments into a Axios style config
|
||||
transformer = (config) => config) => async (input, init) => {
|
||||
const rawHeaders = (0, typeUtils_1.createAxiosHeaders)(init === null || init === void 0 ? void 0 : init.headers);
|
||||
const lowerCasedHeaders = {};
|
||||
Object.entries(rawHeaders).forEach(([name, value]) => {
|
||||
lowerCasedHeaders[name.toLowerCase()] = value;
|
||||
});
|
||||
if (!('content-type' in lowerCasedHeaders)) {
|
||||
lowerCasedHeaders['content-type'] = 'text/plain;charset=UTF-8';
|
||||
}
|
||||
const rawConfig = {
|
||||
url: (0, typeUtils_1.getUrl)(input),
|
||||
method: (init === null || init === void 0 ? void 0 : init.method) || 'GET',
|
||||
data: init === null || init === void 0 ? void 0 : init.body,
|
||||
headers: lowerCasedHeaders,
|
||||
// Force the response to an arraybuffer type. Without this, the Response
|
||||
// object will try to guess the content type and add headers that weren't in
|
||||
// the response.
|
||||
// NOTE: Don't use 'stream' because it's not supported in the browser
|
||||
responseType: 'arraybuffer'
|
||||
};
|
||||
const config = transformer(rawConfig, input, init);
|
||||
let result;
|
||||
try {
|
||||
result = await axios.request(config);
|
||||
}
|
||||
catch (err) {
|
||||
if (err.response) {
|
||||
result = err.response;
|
||||
}
|
||||
else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
return new Response(result.data, {
|
||||
status: result.status,
|
||||
statusText: result.statusText,
|
||||
headers: (0, typeUtils_1.createFetchHeaders)(result.headers)
|
||||
});
|
||||
};
|
||||
const buildAxiosFetch = (axios, transformer) => axiosFetch(axios, transformer);
|
||||
exports.buildAxiosFetch = src.buildAxiosFetch = buildAxiosFetch;
|
||||
|
||||
exports["default"] = src;
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
return exports;
|
||||
|
||||
})({});
|
||||
2
front/html/axios.min.js
vendored
Normal file
2
front/html/axios.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
front/html/bdcontract-sdk.iife.js
Normal file
2
front/html/bdcontract-sdk.iife.js
Normal file
File diff suppressed because one or more lines are too long
2
front/html/cryptico.iife.js
Normal file
2
front/html/cryptico.iife.js
Normal file
File diff suppressed because one or more lines are too long
28
front/html/index.html
Normal file
28
front/html/index.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<script src="./cryptico.iife.js"></script>
|
||||
<script src="./sm2.js"></script>
|
||||
<script src="./axios-fetch.iife.js"></script>
|
||||
<script src="./axios.min.js"></script>
|
||||
<script src="./bdcontract-sdk.iife.js"></script>
|
||||
|
||||
<script>
|
||||
async function run(){
|
||||
const url = 'http://127.0.0.1:21030/SCIDE';
|
||||
var sm2Key = {"publicKey": "04180354fdb6507f8ab98ccfbe165ce11da74ba733f81af86ad6d32216b32cf4f797c559d50ceeefbf4c760c3483840471c67471b90acdffb388cd7d496d9a1610",
|
||||
"privateKey": "1d4196947f59532db6f8f4055e58474a48db8f30b476ae3edc66406464521b3b"};
|
||||
const client = new bdcontract.HttpClient(url, sm2Key);
|
||||
const data = await client.executeContract(
|
||||
'ContractExample',
|
||||
'callHello',
|
||||
'abc');
|
||||
alert(data.data);
|
||||
};
|
||||
run();
|
||||
</script>
|
||||
<title>Example</title>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
2102
front/html/sm2.js
Normal file
2102
front/html/sm2.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user