@bytenew/bn-applet-ui 1.1.78 → 1.1.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -28743,6 +28743,7 @@ var es_array_sort = __webpack_require__(6910);
|
|
|
28743
28743
|
|
|
28744
28744
|
|
|
28745
28745
|
|
|
28746
|
+
|
|
28746
28747
|
|
|
28747
28748
|
|
|
28748
28749
|
var defaultData = []; //不包括省市级code的数据
|
|
@@ -29997,68 +29998,112 @@ function shouldFallbackToAIWhenEmpty(parse, originalAddress) {
|
|
|
29997
29998
|
}
|
|
29998
29999
|
|
|
29999
30000
|
/**
|
|
30000
|
-
*
|
|
30001
|
-
*
|
|
30002
|
-
*
|
|
30003
|
-
|
|
30004
|
-
|
|
30005
|
-
|
|
30001
|
+
* 解析大模型识别接口的响应体
|
|
30002
|
+
* @param {object} res 接口响应体
|
|
30003
|
+
* @returns {{aiResult?: object, failMsg?: string}}
|
|
30004
|
+
*/
|
|
30005
|
+
function parseChatResponse(res) {
|
|
30006
|
+
// 兼容调用方 post 直接返回 axios 完整响应对象({status, data})的情况
|
|
30007
|
+
if (res && typeof res.status === 'number' && res.data && _typeof(res.data) === 'object') {
|
|
30008
|
+
res = res.data;
|
|
30009
|
+
}
|
|
30010
|
+
if (res && !res.code && res.data && res.data.content) {
|
|
30011
|
+
try {
|
|
30012
|
+
return {
|
|
30013
|
+
aiResult: JSON.parse(res.data.content)
|
|
30014
|
+
};
|
|
30015
|
+
} catch (e) {
|
|
30016
|
+
console.error('大模型识别结果解析失败:', res.data.content);
|
|
30017
|
+
return {
|
|
30018
|
+
failMsg: '识别结果解析失败'
|
|
30019
|
+
};
|
|
30020
|
+
}
|
|
30021
|
+
}
|
|
30022
|
+
// 接口失败(如未开通 address_aIautorecognition 功能):返回接口 msg
|
|
30023
|
+
return {
|
|
30024
|
+
failMsg: res ? res.msg : '请求失败'
|
|
30025
|
+
};
|
|
30026
|
+
}
|
|
30027
|
+
|
|
30028
|
+
/**
|
|
30029
|
+
* 接口异常统一处理
|
|
30030
|
+
* @param {Error} error 异常对象
|
|
30031
|
+
* @returns {{failMsg: string}}
|
|
30032
|
+
*/
|
|
30033
|
+
function handleChatError(error) {
|
|
30034
|
+
console.error('大模型地址识别接口调用失败:', error);
|
|
30035
|
+
return {
|
|
30036
|
+
failMsg: error && error.message ? error.message : '请求异常'
|
|
30037
|
+
};
|
|
30038
|
+
}
|
|
30039
|
+
|
|
30040
|
+
/**
|
|
30041
|
+
* 开发环境(localhost/127.0.0.1 等)返回 devServer 代理前缀 /proxyWay,线上同域部署返回空串
|
|
30042
|
+
* @returns {string}
|
|
30043
|
+
*/
|
|
30044
|
+
function getDevProxyPrefix() {
|
|
30045
|
+
if (typeof window === 'undefined' || !window.location) {
|
|
30046
|
+
return '';
|
|
30047
|
+
}
|
|
30048
|
+
var hostname = window.location.hostname;
|
|
30049
|
+
var isLocal = hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '0.0.0.0' || hostname === '[::1]';
|
|
30050
|
+
return isLocal ? '/proxyWay' : '';
|
|
30051
|
+
}
|
|
30052
|
+
|
|
30053
|
+
/**
|
|
30054
|
+
* 原生 fetch 请求地址识别接口(调用方未注入 post 时的兜底)
|
|
30055
|
+
* @param {string} url 完整请求地址
|
|
30056
|
+
* @param {object} fetchOptions fetch 参数
|
|
30006
30057
|
* @returns {Promise<{aiResult?: object, failMsg?: string}|null>}
|
|
30007
|
-
* 成功返回 {aiResult}(content 解析后的对象);失败返回 {failMsg}(接口 msg);不支持 fetch 返回 null
|
|
30008
30058
|
*/
|
|
30009
|
-
function
|
|
30010
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
30059
|
+
function requestChat(url, fetchOptions) {
|
|
30011
30060
|
// 小程序等不支持 fetch 的环境直接跳过,保留本地识别结果
|
|
30012
30061
|
if (typeof fetch !== 'function') {
|
|
30013
30062
|
console.warn('当前环境不支持 fetch,无法调用大模型地址识别接口');
|
|
30014
30063
|
return Promise.resolve(null);
|
|
30015
30064
|
}
|
|
30016
|
-
// 本地开发环境(localhost/127.0.0.1 等)请求前加代理前缀 /proxyWay,走前端 devServer 代理转发;
|
|
30017
|
-
// 非本地环境(线上同域部署)不加前缀
|
|
30018
|
-
var baseUrl = '';
|
|
30019
|
-
if (typeof window !== 'undefined' && window.location) {
|
|
30020
|
-
var hostname = window.location.hostname;
|
|
30021
|
-
var isLocal = hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '0.0.0.0' || hostname === '[::1]';
|
|
30022
|
-
baseUrl = isLocal ? '/proxyWay' : '';
|
|
30023
|
-
}
|
|
30024
|
-
// 插件端走单独接口:POST /project/column/addressBychat;其他端走 v2 的 GET 接口
|
|
30025
|
-
var isPlugin = options.platform === 'plugin';
|
|
30026
|
-
var url = baseUrl + (isPlugin ? '/gateway/project/column/addressBychat' : '/v2/project/column/addressBychat?contents=' + encodeURIComponent(address));
|
|
30027
|
-
var fetchOptions = isPlugin ? {
|
|
30028
|
-
method: 'POST',
|
|
30029
|
-
headers: {
|
|
30030
|
-
'Content-Type': 'application/json'
|
|
30031
|
-
},
|
|
30032
|
-
body: JSON.stringify({
|
|
30033
|
-
content: address
|
|
30034
|
-
})
|
|
30035
|
-
} : {
|
|
30036
|
-
method: 'GET'
|
|
30037
|
-
};
|
|
30038
30065
|
return fetch(url, fetchOptions).then(function (r) {
|
|
30039
30066
|
return r.json();
|
|
30040
|
-
}).then(
|
|
30041
|
-
|
|
30042
|
-
|
|
30043
|
-
|
|
30044
|
-
|
|
30045
|
-
|
|
30046
|
-
|
|
30047
|
-
|
|
30048
|
-
|
|
30049
|
-
|
|
30050
|
-
|
|
30051
|
-
|
|
30067
|
+
}).then(parseChatResponse)["catch"](handleChatError);
|
|
30068
|
+
}
|
|
30069
|
+
|
|
30070
|
+
/**
|
|
30071
|
+
* 本地识别错误时,调用大模型接口重新识别
|
|
30072
|
+
* 插件端(options.platform === 'plugin'):POST /project/column/addressBychat,请求体 {content: 待识别文本};
|
|
30073
|
+
* 传了 options.post 时由宿主 axios 拼前缀、带鉴权头,未传时直连 /gateway 兜底
|
|
30074
|
+
* 其他端:GET /v2/project/column/addressBychat?contents={待识别文本}
|
|
30075
|
+
* 接口返回 data.content 为大模型识别结果的 JSON 字符串(name/mobile/tel/province/city/area/street/addr)
|
|
30076
|
+
* @param {string} address 原始地址字符串
|
|
30077
|
+
* @param {object} [options] 可选配置,platform === 'plugin' 表示插件端;
|
|
30078
|
+
* post 为调用方传入的 post 方法 (path, data) => Promise<响应体>,接口前缀与 plugin-token 等鉴权头由宿主项目的 axios 统一处理
|
|
30079
|
+
* @returns {Promise<{aiResult?: object, failMsg?: string}|null>}
|
|
30080
|
+
*/
|
|
30081
|
+
function parseAddressByChat(address) {
|
|
30082
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
30083
|
+
// 插件端走单独接口:POST /project/column/addressBychat
|
|
30084
|
+
if (options.platform === 'plugin') {
|
|
30085
|
+
// 优先使用调用方传入的 post(一般是项目 axios 封装),避免组件库内直接 fetch 拼错前缀、缺少鉴权头导致 404
|
|
30086
|
+
if (typeof options.post === 'function') {
|
|
30087
|
+
return Promise.resolve().then(function () {
|
|
30088
|
+
return options.post('/project/column/addressBychat', {
|
|
30089
|
+
content: address
|
|
30090
|
+
});
|
|
30091
|
+
}).then(parseChatResponse)["catch"](handleChatError);
|
|
30052
30092
|
}
|
|
30053
|
-
//
|
|
30054
|
-
return {
|
|
30055
|
-
|
|
30056
|
-
|
|
30057
|
-
|
|
30058
|
-
|
|
30059
|
-
|
|
30060
|
-
|
|
30061
|
-
|
|
30093
|
+
// 兜底:直连插件网关
|
|
30094
|
+
return requestChat(getDevProxyPrefix() + '/gateway/project/column/addressBychat', {
|
|
30095
|
+
method: 'POST',
|
|
30096
|
+
headers: {
|
|
30097
|
+
'Content-Type': 'application/json'
|
|
30098
|
+
},
|
|
30099
|
+
body: JSON.stringify({
|
|
30100
|
+
content: address
|
|
30101
|
+
})
|
|
30102
|
+
});
|
|
30103
|
+
}
|
|
30104
|
+
// 其他端:v2 的 GET 接口
|
|
30105
|
+
return requestChat(getDevProxyPrefix() + '/v2/project/column/addressBychat?contents=' + encodeURIComponent(address), {
|
|
30106
|
+
method: 'GET'
|
|
30062
30107
|
});
|
|
30063
30108
|
}
|
|
30064
30109
|
|