适配小程序代码结构
This commit is contained in:
169
unpackage/dist/dev/mp-weixin/common/appInit.js
vendored
Normal file
169
unpackage/dist/dev/mp-weixin/common/appInit.js
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
"use strict";
|
||||
const common_vendor = require("./vendor.js");
|
||||
const uniStarter_config = require("../uni-starter.config.js");
|
||||
const db = common_vendor.tr.database();
|
||||
function redirectToLogin() {
|
||||
const loginPage = "/uni_modules/uni-id-pages/pages/login/login-withpwd";
|
||||
const pages = getCurrentPages();
|
||||
if (pages.length > 0) {
|
||||
const currentPage = pages[pages.length - 1];
|
||||
if (currentPage.route && currentPage.route.includes("login")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
common_vendor.index.reLaunch({
|
||||
url: loginPage,
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:32", "跳转登录页失败:", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
function isLoginApi(url) {
|
||||
if (!url)
|
||||
return false;
|
||||
return url.includes("/api/sys/auth/login");
|
||||
}
|
||||
function setupRequestInterceptor() {
|
||||
const originalRequest = common_vendor.index.request;
|
||||
common_vendor.index.request = function(options = {}) {
|
||||
const { url, header = {}, method = "GET", ...restOptions } = options;
|
||||
let tenantId = "";
|
||||
try {
|
||||
tenantId = common_vendor.index.getStorageSync("backend-tenant-id") || "";
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:63", "获取 tenantId 失败:", e);
|
||||
}
|
||||
if (!isLoginApi(url) && !tenantId) {
|
||||
common_vendor.index.__f__("warn", "at common/appInit.js:68", "[Request Interceptor] 租户ID为空,跳转到登录页面");
|
||||
redirectToLogin();
|
||||
return Promise.reject(new Error("未登录,请先登录"));
|
||||
}
|
||||
const newHeader = {
|
||||
"Content-Type": "application/json",
|
||||
...header
|
||||
};
|
||||
if (tenantId) {
|
||||
newHeader["X-Tenant-Id"] = tenantId;
|
||||
}
|
||||
if (!isLoginApi(url)) {
|
||||
try {
|
||||
const token = common_vendor.index.getStorageSync("backend-token") || "";
|
||||
if (token) {
|
||||
newHeader["Authorization"] = `Bearer ${token}`;
|
||||
} else {
|
||||
delete newHeader["Authorization"];
|
||||
}
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:98", "获取 token 失败:", e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
const roleName = common_vendor.index.getStorageSync("backend-role-name") || "";
|
||||
if (roleName) {
|
||||
newHeader["X-Role-Name"] = roleName;
|
||||
}
|
||||
const scenario = common_vendor.index.getStorageSync("backend-scenario") || "";
|
||||
if (scenario) {
|
||||
newHeader["X-Scenario"] = scenario;
|
||||
}
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:113", "获取 roleName 或 scenario 失败:", e);
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
originalRequest.call(common_vendor.index, {
|
||||
...restOptions,
|
||||
url,
|
||||
method,
|
||||
header: newHeader,
|
||||
success: (res) => {
|
||||
if (options.success) {
|
||||
options.success(res);
|
||||
}
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:133", "[Request Interceptor] 请求失败:", {
|
||||
url,
|
||||
method: method.toUpperCase(),
|
||||
error: err
|
||||
});
|
||||
if (options.fail) {
|
||||
options.fail(err);
|
||||
}
|
||||
reject(err);
|
||||
},
|
||||
complete: (res) => {
|
||||
if (options.complete) {
|
||||
options.complete(res);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
async function initApp() {
|
||||
uniStarter_config.config.debug;
|
||||
setupRequestInterceptor();
|
||||
setTimeout(() => {
|
||||
getApp({
|
||||
allowDefault: true
|
||||
}).globalData.config = uniStarter_config.config;
|
||||
}, 1);
|
||||
function onDBError({
|
||||
code,
|
||||
// 错误码详见https://uniapp.dcloud.net.cn/uniCloud/clientdb?id=returnvalue
|
||||
message
|
||||
}) {
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:180", "onDBError", {
|
||||
code,
|
||||
message
|
||||
});
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:185", code, message);
|
||||
}
|
||||
db.on("error", onDBError);
|
||||
common_vendor.tr.interceptObject({
|
||||
async invoke({
|
||||
objectName,
|
||||
// 云对象名称
|
||||
methodName,
|
||||
// 云对象的方法名称
|
||||
params
|
||||
// 参数列表
|
||||
}) {
|
||||
if (objectName == "uni-id-co" && (methodName.includes("loginBy") || ["login", "registerUser"].includes(methodName))) {
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:204", "执行登录相关云对象");
|
||||
params[0].inviteCode = await new Promise((callBack) => {
|
||||
common_vendor.index.getClipboardData({
|
||||
success: function(res) {
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:208", "剪切板内容:" + res.data);
|
||||
if (res.data.slice(0, 18) == "uniInvitationCode:") {
|
||||
let uniInvitationCode = res.data.slice(18, 38);
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:211", "当前用户是其他用户推荐下载的,推荐者的code是:" + uniInvitationCode);
|
||||
callBack(uniInvitationCode);
|
||||
} else {
|
||||
callBack();
|
||||
}
|
||||
},
|
||||
fail() {
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:223", "error--");
|
||||
callBack();
|
||||
},
|
||||
complete() {
|
||||
common_vendor.index.hideToast();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
success(e) {
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:238", e);
|
||||
},
|
||||
complete() {
|
||||
},
|
||||
fail(e) {
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:244", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.initApp = initApp;
|
||||
//# sourceMappingURL=../../.sourcemap/mp-weixin/common/appInit.js.map
|
||||
10
unpackage/dist/dev/mp-weixin/common/assets.js
vendored
Normal file
10
unpackage/dist/dev/mp-weixin/common/assets.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
const _imports_0$3 = "/static/uni-center/headers.png";
|
||||
const _imports_0$2 = "/assets/face-verify-icon.da277dd7.svg";
|
||||
const _imports_0$1 = "/static/uni-load-state/disconnection.png";
|
||||
const _imports_0 = "/uni_modules/uni-sign-in/static/background.png";
|
||||
exports._imports_0 = _imports_0$3;
|
||||
exports._imports_0$1 = _imports_0$2;
|
||||
exports._imports_0$2 = _imports_0$1;
|
||||
exports._imports_0$3 = _imports_0;
|
||||
//# sourceMappingURL=../../.sourcemap/mp-weixin/common/assets.js.map
|
||||
446
unpackage/dist/dev/mp-weixin/common/bluetooth.js
vendored
Normal file
446
unpackage/dist/dev/mp-weixin/common/bluetooth.js
vendored
Normal file
@@ -0,0 +1,446 @@
|
||||
"use strict";
|
||||
const common_vendor = require("./vendor.js");
|
||||
class BluetoothRecorder {
|
||||
constructor() {
|
||||
this.adapterState = false;
|
||||
this.isScanning = false;
|
||||
this.connectedDeviceId = null;
|
||||
this.deviceList = [];
|
||||
this.services = [];
|
||||
this.characteristics = [];
|
||||
this.notifyCharacteristicId = null;
|
||||
this.writeCharacteristicId = null;
|
||||
this.audioBuffer = [];
|
||||
this.isReceiving = false;
|
||||
this.onDeviceFound = null;
|
||||
this.onDeviceConnected = null;
|
||||
this.onDeviceDisconnected = null;
|
||||
this.onAudioDataReceived = null;
|
||||
this.onError = null;
|
||||
}
|
||||
/**
|
||||
* 初始化蓝牙适配器
|
||||
*/
|
||||
async initBluetoothAdapter() {
|
||||
return new Promise((resolve, reject) => {
|
||||
common_vendor.index.openBluetoothAdapter({
|
||||
success: (res) => {
|
||||
common_vendor.index.__f__("log", "at common/bluetooth.js:36", "蓝牙适配器初始化成功", res);
|
||||
this.adapterState = true;
|
||||
this._listenAdapterState();
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/bluetooth.js:42", "蓝牙适配器初始化失败", err);
|
||||
this.adapterState = false;
|
||||
this._handleError("蓝牙适配器初始化失败", err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 监听蓝牙适配器状态变化
|
||||
*/
|
||||
_listenAdapterState() {
|
||||
common_vendor.index.onBluetoothAdapterStateChange((res) => {
|
||||
common_vendor.index.__f__("log", "at common/bluetooth.js:56", "蓝牙适配器状态变化", res);
|
||||
this.adapterState = res.available;
|
||||
if (!res.available) {
|
||||
this.connectedDeviceId = null;
|
||||
this._handleError("蓝牙适配器不可用", res);
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 开始搜索蓝牙设备
|
||||
* @param {Object} options - 搜索选项
|
||||
* @param {Array} options.services - 服务UUID列表(可选)
|
||||
* @param {number} options.interval - 上报间隔(毫秒)
|
||||
* @param {boolean} options.allowDuplicatesKey - 是否允许重复上报
|
||||
*/
|
||||
async startScan(options = {}) {
|
||||
if (this.isScanning) {
|
||||
common_vendor.index.__f__("warn", "at common/bluetooth.js:74", "已经在扫描中");
|
||||
return;
|
||||
}
|
||||
if (!this.adapterState) {
|
||||
await this.initBluetoothAdapter();
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
common_vendor.index.onBluetoothDeviceFound((res) => {
|
||||
const devices = res.devices || [];
|
||||
devices.forEach((device) => {
|
||||
const exists = this.deviceList.find((d) => d.deviceId === device.deviceId);
|
||||
if (!exists) {
|
||||
this.deviceList.push({
|
||||
deviceId: device.deviceId,
|
||||
name: device.name || "未知设备",
|
||||
RSSI: device.RSSI,
|
||||
advertisData: device.advertisData,
|
||||
advertisServiceUUIDs: device.advertisServiceUUIDs,
|
||||
localName: device.localName
|
||||
});
|
||||
if (this.onDeviceFound) {
|
||||
this.onDeviceFound(device);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
common_vendor.index.startBluetoothDevicesDiscovery({
|
||||
services: options.services || [],
|
||||
allowDuplicatesKey: options.allowDuplicatesKey || false,
|
||||
interval: options.interval || 0,
|
||||
success: (res) => {
|
||||
common_vendor.index.__f__("log", "at common/bluetooth.js:113", "开始搜索蓝牙设备", res);
|
||||
this.isScanning = true;
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/bluetooth.js:118", "搜索蓝牙设备失败", err);
|
||||
this.isScanning = false;
|
||||
this._handleError("搜索蓝牙设备失败", err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 停止搜索蓝牙设备
|
||||
*/
|
||||
async stopScan() {
|
||||
if (!this.isScanning) {
|
||||
return;
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
common_vendor.index.stopBluetoothDevicesDiscovery({
|
||||
success: (res) => {
|
||||
common_vendor.index.__f__("log", "at common/bluetooth.js:138", "停止搜索蓝牙设备", res);
|
||||
this.isScanning = false;
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/bluetooth.js:143", "停止搜索失败", err);
|
||||
this._handleError("停止搜索失败", err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 连接蓝牙设备
|
||||
* @param {string} deviceId - 设备ID
|
||||
*/
|
||||
async connectDevice(deviceId) {
|
||||
if (this.connectedDeviceId === deviceId) {
|
||||
common_vendor.index.__f__("warn", "at common/bluetooth.js:157", "设备已连接");
|
||||
return;
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
common_vendor.index.createBLEConnection({
|
||||
deviceId,
|
||||
success: async (res) => {
|
||||
common_vendor.index.__f__("log", "at common/bluetooth.js:165", "蓝牙设备连接成功", res);
|
||||
this.connectedDeviceId = deviceId;
|
||||
this._listenConnectionState(deviceId);
|
||||
try {
|
||||
await this.getServices(deviceId);
|
||||
if (this.onDeviceConnected) {
|
||||
this.onDeviceConnected(deviceId);
|
||||
}
|
||||
resolve(res);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/bluetooth.js:186", "蓝牙设备连接失败", err);
|
||||
this._handleError("蓝牙设备连接失败", err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 监听连接状态
|
||||
*/
|
||||
_listenConnectionState(deviceId) {
|
||||
common_vendor.index.onBLEConnectionStateChange((res) => {
|
||||
common_vendor.index.__f__("log", "at common/bluetooth.js:199", "蓝牙连接状态变化", res);
|
||||
if (res.deviceId === deviceId) {
|
||||
if (!res.connected) {
|
||||
this.connectedDeviceId = null;
|
||||
this.isReceiving = false;
|
||||
if (this.onDeviceDisconnected) {
|
||||
this.onDeviceDisconnected(deviceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 断开蓝牙设备连接
|
||||
*/
|
||||
async disconnectDevice() {
|
||||
if (!this.connectedDeviceId) {
|
||||
return;
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
common_vendor.index.closeBLEConnection({
|
||||
deviceId: this.connectedDeviceId,
|
||||
success: (res) => {
|
||||
common_vendor.index.__f__("log", "at common/bluetooth.js:225", "蓝牙设备断开成功", res);
|
||||
this.connectedDeviceId = null;
|
||||
this.isReceiving = false;
|
||||
this.audioBuffer = [];
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/bluetooth.js:232", "蓝牙设备断开失败", err);
|
||||
this._handleError("蓝牙设备断开失败", err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 获取蓝牙设备服务列表
|
||||
* @param {string} deviceId - 设备ID
|
||||
*/
|
||||
async getServices(deviceId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
common_vendor.index.getBLEDeviceServices({
|
||||
deviceId,
|
||||
success: async (res) => {
|
||||
common_vendor.index.__f__("log", "at common/bluetooth.js:249", "获取服务列表成功", res);
|
||||
this.services = res.services || [];
|
||||
for (const service of this.services) {
|
||||
try {
|
||||
await this.getCharacteristics(deviceId, service.uuid);
|
||||
} catch (err) {
|
||||
common_vendor.index.__f__("warn", "at common/bluetooth.js:257", "获取特征值失败", service.uuid, err);
|
||||
}
|
||||
}
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/bluetooth.js:264", "获取服务列表失败", err);
|
||||
this._handleError("获取服务列表失败", err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 获取特征值列表
|
||||
* @param {string} deviceId - 设备ID
|
||||
* @param {string} serviceId - 服务UUID
|
||||
*/
|
||||
async getCharacteristics(deviceId, serviceId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
common_vendor.index.getBLEDeviceCharacteristics({
|
||||
deviceId,
|
||||
serviceId,
|
||||
success: (res) => {
|
||||
common_vendor.index.__f__("log", "at common/bluetooth.js:283", "获取特征值成功", serviceId, res);
|
||||
const chars = res.characteristics || [];
|
||||
this.characteristics.push(...chars);
|
||||
chars.forEach((char) => {
|
||||
if (char.properties.notify || char.properties.indicate) {
|
||||
if (!this.notifyCharacteristicId) {
|
||||
this.notifyCharacteristicId = {
|
||||
deviceId,
|
||||
serviceId,
|
||||
characteristicId: char.uuid
|
||||
};
|
||||
this.enableNotify(deviceId, serviceId, char.uuid);
|
||||
}
|
||||
}
|
||||
if (char.properties.write || char.properties.writeNoResponse) {
|
||||
if (!this.writeCharacteristicId) {
|
||||
this.writeCharacteristicId = {
|
||||
deviceId,
|
||||
serviceId,
|
||||
characteristicId: char.uuid
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/bluetooth.js:317", "获取特征值失败", err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 启用特征值通知(用于接收音频数据)
|
||||
* @param {string} deviceId - 设备ID
|
||||
* @param {string} serviceId - 服务UUID
|
||||
* @param {string} characteristicId - 特征值UUID
|
||||
*/
|
||||
async enableNotify(deviceId, serviceId, characteristicId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
common_vendor.index.notifyBLECharacteristicValueChange({
|
||||
deviceId,
|
||||
serviceId,
|
||||
characteristicId,
|
||||
state: true,
|
||||
// 启用通知
|
||||
success: (res) => {
|
||||
common_vendor.index.__f__("log", "at common/bluetooth.js:338", "启用通知成功", res);
|
||||
common_vendor.index.onBLECharacteristicValueChange((res2) => {
|
||||
this._handleAudioData(res2.value);
|
||||
});
|
||||
this.isReceiving = true;
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/bluetooth.js:349", "启用通知失败", err);
|
||||
this._handleError("启用通知失败", err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 处理接收到的音频数据
|
||||
* @param {ArrayBuffer} data - 音频数据
|
||||
*/
|
||||
_handleAudioData(data) {
|
||||
const base64 = common_vendor.index.arrayBufferToBase64(data);
|
||||
this.audioBuffer.push({
|
||||
data: base64,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
if (this.onAudioDataReceived) {
|
||||
this.onAudioDataReceived({
|
||||
data: base64,
|
||||
arrayBuffer: data,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 读取特征值
|
||||
* @param {string} deviceId - 设备ID
|
||||
* @param {string} serviceId - 服务UUID
|
||||
* @param {string} characteristicId - 特征值UUID
|
||||
*/
|
||||
async readCharacteristic(deviceId, serviceId, characteristicId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
common_vendor.index.readBLECharacteristicValue({
|
||||
deviceId,
|
||||
serviceId,
|
||||
characteristicId,
|
||||
success: (res) => {
|
||||
common_vendor.index.__f__("log", "at common/bluetooth.js:394", "读取特征值成功", res);
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/bluetooth.js:398", "读取特征值失败", err);
|
||||
this._handleError("读取特征值失败", err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 写入特征值(发送命令到设备)
|
||||
* @param {ArrayBuffer} value - 要写入的数据
|
||||
*/
|
||||
async writeCharacteristic(value) {
|
||||
if (!this.writeCharacteristicId) {
|
||||
throw new Error("未找到可写入的特征值");
|
||||
}
|
||||
const { deviceId, serviceId, characteristicId } = this.writeCharacteristicId;
|
||||
return new Promise((resolve, reject) => {
|
||||
common_vendor.index.writeBLECharacteristicValue({
|
||||
deviceId,
|
||||
serviceId,
|
||||
characteristicId,
|
||||
value,
|
||||
success: (res) => {
|
||||
common_vendor.index.__f__("log", "at common/bluetooth.js:424", "写入特征值成功", res);
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/bluetooth.js:428", "写入特征值失败", err);
|
||||
this._handleError("写入特征值失败", err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 获取已缓存的音频数据
|
||||
*/
|
||||
getAudioBuffer() {
|
||||
return this.audioBuffer;
|
||||
}
|
||||
/**
|
||||
* 清空音频缓冲区
|
||||
*/
|
||||
clearAudioBuffer() {
|
||||
this.audioBuffer = [];
|
||||
}
|
||||
/**
|
||||
* 合并音频数据为完整文件(Base64格式)
|
||||
*/
|
||||
mergeAudioData() {
|
||||
return this.audioBuffer.map((item) => item.data).join("");
|
||||
}
|
||||
/**
|
||||
* 处理错误
|
||||
*/
|
||||
_handleError(message, error) {
|
||||
common_vendor.index.__f__("error", "at common/bluetooth.js:461", `[BluetoothRecorder] ${message}`, error);
|
||||
if (this.onError) {
|
||||
this.onError({
|
||||
message,
|
||||
error
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 关闭蓝牙适配器
|
||||
*/
|
||||
async closeBluetoothAdapter() {
|
||||
if (this.connectedDeviceId) {
|
||||
await this.disconnectDevice();
|
||||
}
|
||||
if (this.isScanning) {
|
||||
await this.stopScan();
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
common_vendor.index.closeBluetoothAdapter({
|
||||
success: (res) => {
|
||||
common_vendor.index.__f__("log", "at common/bluetooth.js:487", "关闭蓝牙适配器成功", res);
|
||||
this.adapterState = false;
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/bluetooth.js:492", "关闭蓝牙适配器失败", err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 获取设备列表
|
||||
*/
|
||||
getDeviceList() {
|
||||
return this.deviceList;
|
||||
}
|
||||
/**
|
||||
* 清空设备列表
|
||||
*/
|
||||
clearDeviceList() {
|
||||
this.deviceList = [];
|
||||
}
|
||||
}
|
||||
const bluetoothRecorder = new BluetoothRecorder();
|
||||
exports.bluetoothRecorder = bluetoothRecorder;
|
||||
//# sourceMappingURL=../../.sourcemap/mp-weixin/common/bluetooth.js.map
|
||||
49
unpackage/dist/dev/mp-weixin/common/config.js
vendored
Normal file
49
unpackage/dist/dev/mp-weixin/common/config.js
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
const common_vendor = require("./vendor.js");
|
||||
const common_env = require("./env.js");
|
||||
const API_TARGETS = {
|
||||
local: "http://localhost:8090/",
|
||||
prod: "https://api.huayang-star.com/"
|
||||
};
|
||||
const ENV_ALIAS = {
|
||||
development: "local",
|
||||
production: "prod",
|
||||
local: "local",
|
||||
prod: "prod"
|
||||
};
|
||||
function normalizeBaseUrl(url) {
|
||||
return url.endsWith("/") ? url : `${url}/`;
|
||||
}
|
||||
function resolveApiEnv() {
|
||||
var _a;
|
||||
const fileEnv = (_a = common_env.envConfig) == null ? void 0 : _a.apiEnv;
|
||||
{
|
||||
const mapped = ENV_ALIAS[fileEnv.toLowerCase()];
|
||||
if (mapped) {
|
||||
common_vendor.index.__f__("log", "at common/config.js:30", "[API Config] 使用 env.js 配置:", fileEnv, "=>", mapped);
|
||||
return mapped;
|
||||
}
|
||||
}
|
||||
const runtimeEnv = typeof process !== "undefined" && (process == null ? void 0 : process.env) ? process.env.UNI_APP_API_ENV || "development" : "";
|
||||
const aliasKey = runtimeEnv ? runtimeEnv.toLowerCase() : "";
|
||||
const env = ENV_ALIAS[aliasKey] || "prod";
|
||||
common_vendor.index.__f__("log", "at common/config.js:42", "[API Config] 使用环境变量:", runtimeEnv, "=>", env);
|
||||
return env;
|
||||
}
|
||||
const API_ENV = resolveApiEnv();
|
||||
const API_BASE_URL = normalizeBaseUrl(API_TARGETS[API_ENV] || API_TARGETS.prod);
|
||||
common_vendor.index.__f__("log", "at common/config.js:52", "[API Config] 当前环境:", API_ENV);
|
||||
common_vendor.index.__f__("log", "at common/config.js:53", "[API Config] API_BASE_URL:", API_BASE_URL);
|
||||
function getApiEnv() {
|
||||
return API_ENV;
|
||||
}
|
||||
function getApiUrl(path = "") {
|
||||
const apiPath = path.startsWith("/") ? path : `/${path}`;
|
||||
const fullPath = apiPath.startsWith("/") ? apiPath.slice(1) : apiPath;
|
||||
const fullUrl = `${API_BASE_URL}${fullPath}`;
|
||||
common_vendor.index.__f__("log", "at common/config.js:76", "[API Config] 非H5环境使用完整URL:", fullUrl);
|
||||
return fullUrl;
|
||||
}
|
||||
exports.getApiEnv = getApiEnv;
|
||||
exports.getApiUrl = getApiUrl;
|
||||
//# sourceMappingURL=../../.sourcemap/mp-weixin/common/config.js.map
|
||||
6
unpackage/dist/dev/mp-weixin/common/env.js
vendored
Normal file
6
unpackage/dist/dev/mp-weixin/common/env.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
const envConfig = {
|
||||
apiEnv: "local"
|
||||
};
|
||||
exports.envConfig = envConfig;
|
||||
//# sourceMappingURL=../../.sourcemap/mp-weixin/common/env.js.map
|
||||
4
unpackage/dist/dev/mp-weixin/common/openApp.js
vendored
Normal file
4
unpackage/dist/dev/mp-weixin/common/openApp.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
const uniStarter_config = require("../uni-starter.config.js");
|
||||
uniStarter_config.config.h5.openApp || {};
|
||||
//# sourceMappingURL=../../.sourcemap/mp-weixin/common/openApp.js.map
|
||||
152
unpackage/dist/dev/mp-weixin/common/request.js
vendored
Normal file
152
unpackage/dist/dev/mp-weixin/common/request.js
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
"use strict";
|
||||
const common_vendor = require("./vendor.js");
|
||||
const common_config = require("./config.js");
|
||||
function getTenantId() {
|
||||
try {
|
||||
return common_vendor.index.getStorageSync("backend-tenant-id") || "";
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("error", "at common/request.js:15", "获取 tenantId 失败:", e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
function redirectToLogin() {
|
||||
const loginPage = "/uni_modules/uni-id-pages/pages/login/login-withpwd";
|
||||
const pages = getCurrentPages();
|
||||
if (pages.length > 0) {
|
||||
const currentPage = pages[pages.length - 1];
|
||||
if (currentPage.route && currentPage.route.includes("login")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
common_vendor.index.reLaunch({
|
||||
url: loginPage,
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/request.js:38", "跳转登录页失败:", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
function isLoginApi(url) {
|
||||
if (!url)
|
||||
return false;
|
||||
return url.includes("/api/sys/auth/login");
|
||||
}
|
||||
function getToken() {
|
||||
try {
|
||||
return common_vendor.index.getStorageSync("backend-token") || "";
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("error", "at common/request.js:59", "获取 token 失败:", e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
function getRoleName() {
|
||||
try {
|
||||
return common_vendor.index.getStorageSync("backend-role-name") || "";
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("error", "at common/request.js:71", "获取 roleName 失败:", e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
function getScenario() {
|
||||
try {
|
||||
return common_vendor.index.getStorageSync("backend-scenario") || "";
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("error", "at common/request.js:83", "获取 scenario 失败:", e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
function request(options = {}) {
|
||||
const {
|
||||
url,
|
||||
method = "GET",
|
||||
data = {},
|
||||
header = {},
|
||||
timeout = 1e4,
|
||||
needTenantId = true,
|
||||
needToken = true,
|
||||
...restOptions
|
||||
} = options;
|
||||
const fullUrl = url.startsWith("http") ? url : common_config.getApiUrl(url);
|
||||
const apiEnv = typeof common_config.getApiEnv === "function" ? common_config.getApiEnv() : "";
|
||||
common_vendor.index.__f__("log", "at common/request.js:118", `H5环境(${apiEnv})直接使用完整URL: ${fullUrl}`);
|
||||
const requestHeader = {
|
||||
"Content-Type": "application/json",
|
||||
...header
|
||||
};
|
||||
if (needToken && !isLoginApi(fullUrl)) {
|
||||
const token = getToken();
|
||||
if (token) {
|
||||
requestHeader["Authorization"] = `Bearer ${token}`;
|
||||
} else {
|
||||
delete requestHeader["Authorization"];
|
||||
}
|
||||
}
|
||||
const roleName = getRoleName();
|
||||
if (roleName) {
|
||||
requestHeader["X-Role-Name"] = roleName;
|
||||
}
|
||||
const scenario = getScenario();
|
||||
if (scenario) {
|
||||
requestHeader["X-Scenario"] = scenario;
|
||||
}
|
||||
let requestData = { ...data };
|
||||
if (needTenantId) {
|
||||
const tenantId = getTenantId();
|
||||
if (!isLoginApi(fullUrl) && !tenantId) {
|
||||
common_vendor.index.__f__("warn", "at common/request.js:159", "[Request] 租户ID为空,跳转到登录页面");
|
||||
redirectToLogin();
|
||||
return Promise.reject(new Error("未登录,请先登录"));
|
||||
}
|
||||
if (tenantId) {
|
||||
requestHeader["X-Tenant-Id"] = tenantId;
|
||||
}
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
common_vendor.index.request({
|
||||
url: fullUrl,
|
||||
method: method.toUpperCase(),
|
||||
data: requestData,
|
||||
header: requestHeader,
|
||||
timeout,
|
||||
...restOptions,
|
||||
success: (res) => {
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/request.js:184", "[Request] 请求失败:", {
|
||||
url: fullUrl,
|
||||
method: method.toUpperCase(),
|
||||
error: err
|
||||
});
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
function get(url, data = {}, options = {}) {
|
||||
return request({
|
||||
url,
|
||||
method: "GET",
|
||||
data,
|
||||
...options
|
||||
});
|
||||
}
|
||||
function post(url, data = {}, options = {}) {
|
||||
return request({
|
||||
url,
|
||||
method: "POST",
|
||||
data,
|
||||
...options
|
||||
});
|
||||
}
|
||||
function put(url, data = {}, options = {}) {
|
||||
return request({
|
||||
url,
|
||||
method: "PUT",
|
||||
data,
|
||||
...options
|
||||
});
|
||||
}
|
||||
exports.get = get;
|
||||
exports.post = post;
|
||||
exports.put = put;
|
||||
//# sourceMappingURL=../../.sourcemap/mp-weixin/common/request.js.map
|
||||
15046
unpackage/dist/dev/mp-weixin/common/vendor.js
vendored
Normal file
15046
unpackage/dist/dev/mp-weixin/common/vendor.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user