Initial Commit

This commit is contained in:
EZ4Jam1n 2024-05-22 10:14:19 +08:00
commit 5c3a5caeb8
96 changed files with 14000 additions and 0 deletions

14
.gitignore vendored Normal file
View File

@ -0,0 +1,14 @@
# Windows
[Dd]esktop.ini
Thumbs.db
$RECYCLE.BIN/
# macOS
.DS_Store
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
# Node.js
node_modules/

61
api/index.js Normal file
View File

@ -0,0 +1,61 @@
"use strict";
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
var utils_request = require("../utils/request.js");
var config_index = require("../config/index.js");
const login = (data) => utils_request.request({ url: "/api/users/wx/login", method: "POST", data });
const getAllRoles = () => utils_request.request({ url: "/api/roles/all", method: "GET" });
const getChatExist = (data) => utils_request.request({ url: "/api/chat_records/exists", method: "GET", data });
const createChat = (data) => utils_request.request({ baseUrl: config_index.base_url_other, url: "/chats", method: "POST", data });
const getAllRolesMessageRecord = (data) => utils_request.request({ url: "/api/chat_records/all", method: "GET", data });
const saveMessage = (data) => utils_request.request({ url: "/api/chat_records/", method: "POST", loading: false, data });
const getHistoryMessage = (data) => utils_request.request({ url: "/api/chat_records/", method: "GET", data });
const getListOfCommunity = (data) => utils_request.request({ url: "/api/post/", method: "GET", loading: false, data });
const uploadImage = (file) => utils_request.requestFormData({ url: "/api/files/", method: "POST", file });
const releaseContent = (data) => utils_request.request({ url: "/api/post/", method: "POST", data });
const saveDraft = (data) => utils_request.request({ url: "/api/drafts/", method: "POST", data });
const getDraftData = (data) => utils_request.request({ url: "/api/drafts/", method: "GET", data });
const getCommunityDetail = (id) => utils_request.request({ url: `/api/post/${id}`, method: "GET" });
const getCommentData = (id) => utils_request.request({ url: `/api/post/${id}/comments/`, method: "GET", loading: false });
const submitLike = (id) => utils_request.request({ url: `/api/post/${id}/like`, method: "POST", loading: false });
const cancelLike = (id) => utils_request.request({ url: `/api/post/${id}/like`, method: "DELETE", loading: false });
const submitComment = (_a) => {
var _b = _a, { id } = _b, data = __objRest(_b, ["id"]);
return utils_request.request({ url: `/api/post/${id}/comments/`, method: "POST", loading: false, data });
};
const deleteComment = ({ id, commentId }) => utils_request.request({ url: `/api/post/${id}/comments/${commentId}`, method: "DELETE", loading: false });
const saveAvatar = (data) => utils_request.request({ url: "/api/users/avatar_id", method: "PUT", data });
const saveUserName = (data) => utils_request.request({ url: "/api/users/username", method: "PUT", data });
exports.cancelLike = cancelLike;
exports.createChat = createChat;
exports.deleteComment = deleteComment;
exports.getAllRoles = getAllRoles;
exports.getAllRolesMessageRecord = getAllRolesMessageRecord;
exports.getChatExist = getChatExist;
exports.getCommentData = getCommentData;
exports.getCommunityDetail = getCommunityDetail;
exports.getDraftData = getDraftData;
exports.getHistoryMessage = getHistoryMessage;
exports.getListOfCommunity = getListOfCommunity;
exports.login = login;
exports.releaseContent = releaseContent;
exports.saveAvatar = saveAvatar;
exports.saveDraft = saveDraft;
exports.saveMessage = saveMessage;
exports.saveUserName = saveUserName;
exports.submitComment = submitComment;
exports.submitLike = submitLike;
exports.uploadImage = uploadImage;

46
app.js Normal file
View File

@ -0,0 +1,46 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports[Symbol.toStringTag] = "Module";
var common_vendor = require("./common/vendor.js");
if (!Math) {
"./pages/cover/index.js";
"./pages/login/index.js";
"./pages/index/index.js";
"./pages/chat/index.js";
"./pages/chatOnline/index.js";
"./pages/community/index.js";
"./pages/community/release.js";
"./pages/community/detail.js";
"./pages/mine/index.js";
"./pages/mine/aboutus.js";
"./pages/mine/contactus.js";
"./pages/call/index.js";
"./pages/bluetooth/index.js";
"./pages/bluetooth/device.js";
"./pages/bluetooth/connect.js";
}
const _sfc_main = {
onLaunch: function() {
console.log("App Launch");
},
onShow: function() {
console.log("App Show");
},
onHide: function() {
console.log("App Hide");
},
provide() {
return {
chatList: []
};
}
};
var App = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/App.vue"]]);
function createApp() {
const app = common_vendor.createSSRApp(App);
return {
app
};
}
createApp().app.mount("#app");
exports.createApp = createApp;

61
app.json Normal file
View File

@ -0,0 +1,61 @@
{
"pages": [
"pages/cover/index",
"pages/login/index",
"pages/index/index",
"pages/chat/index",
"pages/chatOnline/index",
"pages/community/index",
"pages/community/release",
"pages/community/detail",
"pages/mine/index",
"pages/mine/aboutus",
"pages/mine/contactus",
"pages/call/index",
"pages/bluetooth/index",
"pages/bluetooth/device",
"pages/bluetooth/connect"
],
"window": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8",
"homeButton": false
},
"tabBar": {
"color": "#999999",
"selectedColor": "#000000",
"backgroundColor": "#ffffff",
"borderStyle": "black",
"position": "bottom",
"list": [
{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "static/icon/ufo.png",
"selectedIconPath": "static/icon/ufo_active.png"
},
{
"pagePath": "pages/chat/index",
"text": "聊天",
"iconPath": "static/icon/chat.png",
"selectedIconPath": "static/icon/chat_active.png"
},
{
"pagePath": "pages/community/index",
"text": "社区",
"iconPath": "static/icon/community.png",
"selectedIconPath": "static/icon/community_active.png"
},
{
"pagePath": "pages/mine/index",
"text": "我的",
"iconPath": "static/icon/mine.png",
"selectedIconPath": "static/icon/mine_active.png"
}
]
},
"permission": {},
"usingComponents": {}
}

91
app.wxss Normal file

File diff suppressed because one or more lines are too long

9436
common/vendor.js Normal file

File diff suppressed because it is too large Load Diff

13
config/index.js Normal file
View File

@ -0,0 +1,13 @@
"use strict";
const base_url = "https://takway-ai.top:8002";
const base_url_other = "https://takway-ai.top:8001";
const filePrefix = "https://takway-ai.top:8002/api/files/";
const defaultAvatar = "e3672124045f11ef817ba036bc278b4c";
const wsUrl = "wss://takway-ai.top:8001/chat/streaming/lasting";
const wsVoiceCallUrl = "wss://takway-ai.top:8001/chat/voice_call";
exports.base_url = base_url;
exports.base_url_other = base_url_other;
exports.defaultAvatar = defaultAvatar;
exports.filePrefix = filePrefix;
exports.wsUrl = wsUrl;
exports.wsVoiceCallUrl = wsVoiceCallUrl;

3
kongshuju.js Normal file
View File

@ -0,0 +1,3 @@
"use strict";
var _imports_1 = "/static/image/kongshuju.png";
exports._imports_1 = _imports_1;

140
pages/bluetooth/connect.js Normal file
View File

@ -0,0 +1,140 @@
"use strict";
var common_vendor = require("../../common/vendor.js");
var utils_bluetooth = require("../../utils/bluetooth.js");
const _sfc_main = {
setup(__props) {
const deviceId = common_vendor.ref("");
common_vendor.onLoad((option) => {
deviceId.value = option.deviceId;
});
const ssid = common_vendor.ref("");
const rememberWifi = common_vendor.ref(false);
const password = common_vendor.ref("");
const onCheckboxChange = (event) => {
rememberWifi.value = !rememberWifi.value;
};
common_vendor.ref("");
const serviceUUIDSamll = common_vendor.ref("");
const notifyCharacteristicId = common_vendor.ref("");
const writeCharacteristicId = common_vendor.ref("");
const stringToBytes = (str) => {
var array = new Uint8Array(str.length);
for (var i = 0, l = str.length; i < l; i++) {
array[i] = str.charCodeAt(i);
}
console.log(array);
return array.buffer;
};
const connect = async () => {
ssid.value = ssid.value.trim();
password.value = password.value.trim();
if (ssid.value === "") {
wx.showToast({
title: "WiFi\u4FE1\u606F\u83B7\u53D6\u5931\u8D25",
icon: "none",
duration: 2e3
});
return;
}
if (password.value === "") {
wx.showToast({
title: "\u8BF7\u8F93\u5165\u5BC6\u7801",
icon: "none",
duration: 2e3
});
return;
}
if (rememberWifi.value) {
common_vendor.index.setStorage({
key: ssid.value,
data: password.value
});
} else {
common_vendor.index.removeStorage({
key: ssid.value
});
}
res = await utils_bluetooth.getBLEDeviceServices(that.data.deviceId);
for (let i2 = 0; i2 < res.services.length; i2++) {
if (res.services[i2].uuid.toUpperCase().indexOf(serviceUUIDSamll.value) != -1) {
console.log("\u670D\u52A1\u5DF2\u627E\u5230");
serviceId.value = res.services[i2].uuid;
break;
}
}
console.log("\u5DF2\u83B7\u53D6\u8FDE\u63A5\u8BBE\u5907\u7684service\u670D\u52A1");
res = await utils_bluetooth.getBLEDeviceCharacteristics(deviceId.value, serviceId.value);
for (var i = 0; i < res.characteristics.length; i++) {
console.log("\u83B7\u53D6\u5230\u7684\u7279\u5F81\u503Cid:" + res.characteristics[i].uuid);
if (res.characteristics[i].properties.notify) {
console.log("\u5F00\u542Fnotify\u7684characteristicId:" + res.characteristics[i].uuid);
notifyCharacteristicId.value = res.characteristics[i].uuid;
}
if (res.characteristics[i].properties.write) {
console.log("\u5F00\u542Fwrite\u7684characteristicId:" + res.characteristics[i].uuid);
writeCharacteristicId.value = res.characteristics[i].uuid;
}
}
console.log("\u5DF2\u83B7\u53D6\u8FDE\u63A5\u8BBE\u5907\u5177\u6709\u8BFB\u5199\u529F\u80FD\u670D\u52A1\u7684\u6240\u6709\u7279\u5F81\u503C");
res = await utils_bluetooth.notifyBLECharacteristicValueChange(deviceId.value, serviceId.value, notifyCharacteristicId.value);
console.log("\u5DF2\u542F\u52A8\u84DD\u7259\u7279\u5F81\u503C\u53D8\u5316");
const data = {
type: 0,
data: {
ssid: ssid.value,
passwd: password.value
}
};
let buffer = stringToBytes(JSON.stringify(data));
res = await utils_bluetooth.writeBLECharacteristicValue(deviceId.value, serviceId.value, writeCharacteristicId.value, buffer);
console.log("\u5DF2\u53D1\u9001\u6570\u636E");
res = await utils_bluetooth.closeBluetoothAdapter();
};
common_vendor.onMounted(() => {
wx.startWifi({
success(res2) {
wx.getConnectedWifi({
partialInfo: true,
success(res3) {
ssid.value = res3.wifi.SSID;
common_vendor.index.getStorage({
key: ssid.value,
success: function(res4) {
password.value = res4.data;
}
});
},
fail(res3) {
wx.showToast({
title: "WiFi\u4FE1\u606F\u83B7\u53D6\u5931\u8D25",
icon: "none",
duration: 2e3
});
return;
}
});
},
fail() {
wx.showToast({
title: "WiFi\u6A21\u5757\u521D\u59CB\u5316\u5931\u8D25",
icon: "none",
duration: 2e3
});
return;
}
});
});
return (_ctx, _cache) => {
return {
a: common_vendor.t(ssid.value),
b: password.value,
c: common_vendor.o(($event) => password.value = $event.detail.value),
d: common_vendor.o(onCheckboxChange),
e: common_vendor.n(rememberWifi.value ? "radio iconfont icon-gou" : "radio"),
f: common_vendor.o(connect)
};
};
}
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1665ba40"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/bluetooth/connect.vue"]]);
wx.createPage(MiniProgramPage);

View File

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "",
"usingComponents": {}
}

View File

@ -0,0 +1 @@
<view class="container data-v-1665ba40"><text class="title data-v-1665ba40">给萌主连网</text><view class="group-ssid data-v-1665ba40"><text class="icon iconfont icon-wifi data-v-1665ba40"></text><text class="text data-v-1665ba40">{{a}}</text></view><view class="group-password data-v-1665ba40"><text class="icon iconfont icon-lock data-v-1665ba40"></text><input class="text data-v-1665ba40" type="password" placeholder="请输入密码" value="{{b}}" bindinput="{{c}}"/></view><view class="group data-v-1665ba40"><view bindtap="{{d}}" class="{{['data-v-1665ba40', e]}}"></view><text class="remember-wifi-label data-v-1665ba40">记住WiFi密码</text></view><text class="button data-v-1665ba40" bindtap="{{f}}">连接</text></view>

View File

@ -0,0 +1,117 @@
.container.data-v-1665ba40 {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.title.data-v-1665ba40 {
top: 15%;
width: 142.63px;
height: 22.32px;
opacity: 1;
color: rgba(0, 0, 0, 1);
text-align: center;
font-weight: 500;
font-size: 20px;
position: absolute;
}
.uni-picker.data-v-1665ba40 {
margin-bottom: 20px;
padding: 10px;
border: none;
border-radius: 10px;
}
.group-ssid.data-v-1665ba40 {
display: flex;
align-items: center;
justify-content: flex-start;
height: 34px;
width: 200px;
top: 25%;
position: absolute;
}
.group.data-v-1665ba40 {
display: flex;
align-items: center;
justify-content: flex-start;
height: 34px;
width: 150px;
top: 35%;
position: absolute;
}
.group-password.data-v-1665ba40 {
display: flex;
align-items: center;
justify-content: flex-start;
background: rgba(245, 245, 247, 1);
border-radius: 18.5px;
height: 34px;
width: 200px;
top: 30%;
position: absolute;
}
.icon.data-v-1665ba40 {
margin-left: 15px;
margin-right: 15px;
}
.text.data-v-1665ba40 {
margin-right: 5px;
}
.button.data-v-1665ba40 {
width: 70%;
height: 47px;
opacity: 1;
border-radius: 23.5px;
border: 0px;
line-height: 47px;
text-align: center;
position: absolute;
top: 50%;
color: rgba(255, 255, 255, 1);
background: linear-gradient(90deg, rgba(255, 153, 71, 1) 0%, rgba(242, 52, 255, 1) 25.19%, rgba(34, 8, 228, 1) 79.99%, rgba(51, 204, 255, 1) 100%);
}
.checkbox.data-v-1665ba40 {
width: 12px;
/* 设置复选框的宽度 */
height: 12px;
/* 设置复选框的高度 */
border: 1px solid rgba(128, 128, 128, 1);
/* 设置复选框的边框 */
border-radius: 50%;
/* 设置复选框为圆形 */
display: flex;
justify-content: center;
align-items: center;
font-size: 10px;
/* 根据需要调整勾号大小 */
margin-left: 10px;
margin-right: 10px;
}
.checkmark.data-v-1665ba40 {
color: rgba(128, 128, 128, 1);
/* 设置勾号的颜色 */
}
.remember-wifi-label.data-v-1665ba40 {
font-size: 10px;
color: rgba(128, 128, 128, 1);
/* 设置勾号的颜色 */
}
.group .radio.data-v-1665ba40 {
position: relative;
margin-right: 4px;
display: inline-block;
width: 12px;
height: 12px;
box-sizing: border-box;
border: 1px solid rgba(128, 128, 128, 1);
border-radius: 50%;
font-size: 12px;
text-align: center;
line-height: 12px;
color: rgba(128, 128, 128, 1);
font-size: 10px;
/* 根据需要调整勾号大小 */
margin-left: 10px;
margin-right: 10px;
}

43
pages/bluetooth/device.js Normal file
View File

@ -0,0 +1,43 @@
"use strict";
var common_vendor = require("../../common/vendor.js");
const _sfc_main = {
setup(__props) {
common_vendor.onLoad((option) => {
console.log(option);
deviceId.value = option.deviceId;
deviceName.value = option.name;
});
const deviceId = common_vendor.ref("");
const deviceName = common_vendor.ref("");
const ignoreTheDevice = () => {
wx.closeBLEConnection({
deviceId: deviceId.value
});
common_vendor.index.navigateBack({
delta: 1
});
};
const startConnect = () => {
common_vendor.index.navigateTo({
url: "/pages/bluetooth/connect?deviceId=" + deviceId
});
if (deviceId.value)
;
};
const goSelectBluetooth = () => {
common_vendor.index.navigateBack({
delta: 1
});
};
return (_ctx, _cache) => {
return {
a: common_vendor.t(deviceName.value != "" ? deviceName.value : deviceId.value),
b: common_vendor.o(goSelectBluetooth),
c: common_vendor.o(startConnect),
d: common_vendor.o(ignoreTheDevice)
};
};
}
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2ad235d0"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/bluetooth/device.vue"]]);
wx.createPage(MiniProgramPage);

View File

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "",
"usingComponents": {}
}

View File

@ -0,0 +1 @@
<view class="container data-v-2ad235d0"><text class="title data-v-2ad235d0">发现以下设备</text><image class="image data-v-2ad235d0" src="/static/image/toy.png" mode="aspectFit"></image><view class="description data-v-2ad235d0" bindtap="{{b}}"><text class="text data-v-2ad235d0">{{a}}</text><text class="icon iconfont icon-goToSelect data-v-2ad235d0"></text></view><text class="button color1 data-v-2ad235d0" bindtap="{{c}}">开始连网</text><text class="button color2 data-v-2ad235d0" bindtap="{{d}}">忽略该设备</text></view>

View File

@ -0,0 +1,67 @@
.container.data-v-2ad235d0 {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.title.data-v-2ad235d0 {
top: 15%;
width: 142.63px;
height: 22.32px;
opacity: 1;
color: rgba(0, 0, 0, 1);
text-align: center;
font-weight: 500;
font-size: 20px;
position: absolute;
}
.image.data-v-2ad235d0 {
top: 15%;
opacity: 1;
width: 29%;
position: absolute;
}
.description.data-v-2ad235d0 {
display: flex;
justify-content: space-between;
align-items: center;
top: 42%;
height: 12.98px;
opacity: 1;
color: rgba(0, 0, 0, 1);
font-weight: 600;
position: absolute;
}
.text.data-v-2ad235d0 {
line-height: 10px;
height: 11.27px;
margin-right: 10px;
}
.icon.data-v-2ad235d0 {
font-size: 12px;
color: rgba(0, 0, 0, 1);
}
.button.data-v-2ad235d0 {
width: 70%;
height: 47px;
opacity: 1;
border-radius: 23.5px;
border: 0px;
line-height: 47px;
text-align: center;
position: absolute;
}
.color1.data-v-2ad235d0 {
position: absolute;
top: 50%;
color: rgba(255, 255, 255, 1);
background: linear-gradient(270deg, rgba(255, 153, 71, 1) 0%, rgba(242, 52, 255, 1) 57.29%, rgba(243, 64, 125, 1) 83.14%, rgba(243, 67, 98, 1) 100%);
}
.color2.data-v-2ad235d0 {
position: absolute;
top:58%;
color: rgba(52, 152, 255, 1);
background: rgba(204, 230, 255, 1);
font-size: 12px;
}

112
pages/bluetooth/index.js Normal file
View File

@ -0,0 +1,112 @@
"use strict";
var common_vendor = require("../../common/vendor.js");
const _sfc_main = {
setup(__props) {
common_vendor.onMounted(() => {
openBluetoothAdapter();
});
common_vendor.onUnmounted(() => {
if (discoveryStarted.value) {
stopBluetoothDevicesDiscovery();
}
});
const bluetoothDevices = common_vendor.reactive([]);
const ignoreDevices = common_vendor.reactive([]);
let discoveryStarted = common_vendor.ref(false);
let showLoading = common_vendor.ref(true);
const openBluetoothAdapter = () => {
wx.openBluetoothAdapter({
success: (res) => {
console.log("openBluetoothAdapter success", res);
startBluetoothDevicesDiscovery();
},
fail: (res) => {
console.log(res);
if (res.errCode === 10001) {
wx.onBluetoothAdapterStateChange(function(res2) {
console.log("onBluetoothAdapterStateChange", res2);
if (res2.available) {
startBluetoothDevicesDiscovery();
}
});
}
}
});
};
const startBluetoothDevicesDiscovery = () => {
if (discoveryStarted.value) {
return;
}
discoveryStarted.value = true;
wx.startBluetoothDevicesDiscovery({
success: (res) => {
console.log("startBluetoothDevicesDiscovery success", res);
onBluetoothDeviceFound();
},
fail: (err) => {
discoveryStarted.value = false;
wx.showToast({
title: "\u5F00\u542F\u641C\u7D22\u5931\u8D25",
icon: "none",
duration: 2e3
});
console.error("\u5F00\u542F\u84DD\u7259\u8BBE\u5907\u641C\u7D22\u5931\u8D25", err);
}
});
};
const onBluetoothDeviceFound = () => {
wx.onBluetoothDeviceFound((res) => {
showLoading.value = false;
res.devices.forEach((device) => {
console.log(device);
if (device.RSSI > -80 && !bluetoothDevices.some((d) => d.deviceId === device.deviceId) && !ignoreDevices.includes(device.deviceId)) {
bluetoothDevices.push(device);
}
});
});
};
const createBLEConnection = (device) => {
stopBluetoothDevicesDiscovery();
wx.showLoading({
title: "\u8FDE\u63A5\u4E2D..."
});
wx.createBLEConnection({
deviceId: device.deviceId,
success(res) {
wx.hideLoading();
common_vendor.index.navigateTo({
url: "/pages/bluetooth/device?deviceId=" + device.deviceId + "&name=" + device.name
});
},
fail() {
wx.hideLoading();
wx.showToast({
title: "\u84DD\u7259\u8FDE\u63A5\u5931\u8D25",
icon: "none",
duration: 2e3
});
return;
}
});
};
const stopBluetoothDevicesDiscovery = () => {
wx.stopBluetoothDevicesDiscovery();
};
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.unref(showLoading)
}, common_vendor.unref(showLoading) ? {} : {
b: common_vendor.o(startBluetoothDevicesDiscovery),
c: common_vendor.f(common_vendor.unref(bluetoothDevices), (device, index, i0) => {
return {
a: common_vendor.t(device.name || device.deviceId),
b: index,
c: common_vendor.o(($event) => createBLEConnection(device))
};
})
});
};
}
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-0e0dc370"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/bluetooth/index.vue"]]);
wx.createPage(MiniProgramPage);

View File

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "",
"usingComponents": {}
}

View File

@ -0,0 +1 @@
<view wx:if="{{a}}" class="loading-model data-v-0e0dc370"><view class="lm-box data-v-0e0dc370"><view class="loading data-v-0e0dc370"/><text class="loading-title data-v-0e0dc370">正在寻找萌主</text></view></view><view wx:else class="container data-v-0e0dc370"><view class="header data-v-0e0dc370" bindtap="{{b}}"><text class="header-text data-v-0e0dc370">选择附近的蓝牙设备</text></view><view class="device-list data-v-0e0dc370"><scroll-view class="scroll-view data-v-0e0dc370" scroll-y="true"><view wx:for="{{c}}" wx:for-item="device" wx:key="b" class="device-item data-v-0e0dc370" bindtap="{{device.c}}"><image class="device-icon data-v-0e0dc370" src="https://img.js.design/assets/img/657baf484725d8554ce1d747.png#78637e66fd84394d1a4cd2538bfee022"></image><text class="device-text data-v-0e0dc370">{{device.a}}</text></view></scroll-view></view></view>

109
pages/bluetooth/index.wxss Normal file

File diff suppressed because one or more lines are too long

248
pages/call/index.js Normal file
View File

@ -0,0 +1,248 @@
"use strict";
var common_vendor = require("../../common/vendor.js");
var config_index = require("../../config/index.js");
var utils_wsRequest = require("../../utils/wsRequest.js");
var utils_audioUtil = require("../../utils/audioUtil.js");
var api_index = require("../../api/index.js");
require("../../utils/request.js");
const _sfc_main = {
setup(__props) {
const innerAudioContext = wx.createInnerAudioContext({
useWebAudioImplement: false
});
common_vendor.reactive([]);
innerAudioContext.playbackRate = 1.3;
const recorderManager = wx.getRecorderManager();
const ws = common_vendor.ref(null);
const params = {
audio: "",
meta_info: {
session_id: "",
encoding: "raw"
},
is_close: false
};
const options = {
duration: 6e5,
sampleRate: 16e3,
numberOfChannels: 1,
encodeBitRate: 96e3,
format: "PCM",
frameSize: 12
};
innerAudioContext.onEnded(() => {
playNext();
});
const startRecord = () => {
isRecording.value = true;
console.log("\u5F00\u59CB\u5F55\u97F3");
recorderManager.start(options);
};
const stopRecord = () => {
if (!isRecording.value) {
console.log("\u6CA1\u6709\u5728\u5F55\u97F3...");
return;
}
recorderManager.stop();
isRecording.value = false;
console.log("\u505C\u6B62\u5F55\u97F3");
};
const playNext = () => {
if (aiVoices.length > 0) {
isPlaying.value = true;
let first = aiVoices.shift(0);
if (first) {
recorderManager.pause();
innerAudioContext.src = first;
innerAudioContext.play();
}
} else {
isPlaying.value = false;
recorderManager.resume();
}
};
let aiVoices = common_vendor.reactive([]);
let roleName = common_vendor.ref("");
let currentRoleId = common_vendor.ref("");
let status = common_vendor.ref("\u7B49\u5F85\u5BF9\u65B9\u63A5\u6536\u9080\u8BF7...");
let isRecording = common_vendor.ref(false);
let isPlaying = common_vendor.ref(false);
let isLoudSpeaker = common_vendor.ref(true);
let aiAvatarId = common_vendor.ref("");
let backGroundList = common_vendor.reactive([]);
const currentBackGroundImage = common_vendor.computed$1(() => {
return backGroundList[0];
});
common_vendor.onShow(() => {
common_vendor.index.getStorage({
key: "chatInfo",
success: ({
data
}) => {
const {
session_id,
background_ids = "",
role_name,
avatar_id,
role_id
} = data;
roleName.value = role_name;
currentRoleId.value = role_id;
params.meta_info.session_id = session_id;
aiAvatarId.value = avatar_id;
backGroundList.push(...background_ids.split(","));
}
});
const pcmToArrayBuffer = (pcmData, sampleRate, channels, sampleBits) => {
var _a;
const chunkSize = 36 + pcmData.byteLength;
const byteRate = sampleRate * channels * (sampleBits / 8);
const blockAlign = channels * (sampleBits / 8);
const wavHeader = new ArrayBuffer(44);
const view = new DataView(wavHeader);
view.setUint32(0, 1380533830, false);
view.setUint32(4, chunkSize, true);
view.setUint32(8, 1463899717, false);
view.setUint32(12, 1718449184, false);
view.setUint32(16, 16, true);
view.setUint16(20, 1, true);
view.setUint16(22, channels, true);
view.setUint32(24, sampleRate, true);
view.setUint32(28, byteRate, true);
view.setUint16(32, blockAlign, true);
view.setUint16(34, sampleBits, true);
view.setUint32(36, 1684108385, false);
view.setUint32(40, pcmData.byteLength, true);
const wavArrayBuffer = new Uint8Array(wavHeader);
const pcmArrayBuffer = new Uint8Array(pcmData);
const combinedArrayBuffer = new Uint8Array(wavArrayBuffer.length + pcmArrayBuffer.length);
combinedArrayBuffer.set(wavArrayBuffer, 0);
combinedArrayBuffer.set(pcmArrayBuffer, wavArrayBuffer.length);
const base64 = wx.arrayBufferToBase64(combinedArrayBuffer);
const data = Object.assign({}, params);
data.audio = base64;
(_a = ws.value) == null ? void 0 : _a.sendMsg(data);
console.log(data);
};
recorderManager.onFrameRecorded((res) => {
const {
frameBuffer,
isLastFrame
} = res;
pcmToArrayBuffer(frameBuffer, 16e3, 1, 16);
});
});
const usermessageIsEnd = common_vendor.ref(false);
const llmmessageIsEnd = common_vendor.ref(false);
const usermsg = common_vendor.reactive([]);
const llmmsg = common_vendor.reactive([]);
common_vendor.onMounted(() => {
var _a;
try {
wx.setKeepScreenOn({
keepScreenOn: true
});
ws.value = new utils_wsRequest.webSocketClass(config_index.wsVoiceCallUrl, 60);
(_a = ws.value) == null ? void 0 : _a.initSocket().then((res) => {
status.value = "\u5DF2\u63A5\u901A";
setTimeout(() => {
status.value = "";
}, 2e3);
common_vendor.index.$on("message", ({
type,
data
}) => {
status.value = "";
console.log("\u6536\u5230\u56DE\u590D", data);
if (data instanceof ArrayBuffer) {
utils_audioUtil.savePCMBuffer(data, aiVoices);
setTimeout(() => {
if (!isPlaying.value) {
playNext();
}
}, 400);
} else {
const message = JSON.parse(data);
if (message.type === "user_text") {
usermsg.push(message.msg);
} else if (message.type === "llm_text") {
llmmsg.push(message.msg);
} else if (message.type === "end") {
usermessageIsEnd.value = true;
llmmessageIsEnd.value = true;
api_index.saveMessage({
role_id: currentRoleId.value,
direction: 0,
message: usermsg.join("")
}).then(({ status: status2 }) => {
usermsg.length = 0;
api_index.saveMessage({
role_id: currentRoleId.value,
direction: 1,
message: llmmsg.join("")
}).then(({ status: status3 }) => {
llmmsg.length = 0;
});
});
}
}
});
startRecord();
});
} catch (e) {
}
});
const finlizer = () => {
var _a, _b;
wx.setKeepScreenOn({
keepScreenOn: false
});
innerAudioContext.destroy();
stopRecord();
const data = Object.assign({}, params);
data.audio = "";
data.is_close = true;
(_a = ws.value) == null ? void 0 : _a.sendMsg(data);
(_b = ws.value) == null ? void 0 : _b.closeSocket();
};
const endCall = () => {
common_vendor.index.navigateBack({
delta: 1
});
};
const goToChat = () => {
common_vendor.index.redirectTo({
url: "/pages/chatOnline/index"
});
};
common_vendor.onUnmounted(() => {
finlizer();
});
const changeLoudSpeaker = () => {
innerAudioContext.pause();
wx.setInnerAudioOption({
speakerOn: !isLoudSpeaker.value
});
innerAudioContext.play();
isLoudSpeaker.value = !isLoudSpeaker.value;
};
return (_ctx, _cache) => {
return {
a: `${common_vendor.unref(config_index.filePrefix)}${common_vendor.unref(currentBackGroundImage)}`,
b: `${common_vendor.unref(config_index.filePrefix)}${common_vendor.unref(aiAvatarId)}`,
c: common_vendor.t(common_vendor.unref(roleName)),
d: common_vendor.t(common_vendor.unref(status)),
e: common_vendor.unref(isRecording),
f: common_vendor.o(($event) => goToChat()),
g: common_vendor.o(($event) => endCall()),
h: common_vendor.o(($event) => changeLoudSpeaker()),
i: common_vendor.o(($event) => goToChat()),
j: common_vendor.o(($event) => endCall()),
k: common_vendor.t(common_vendor.unref(isLoudSpeaker) ? "\u626C\u58F0\u5668\u5DF2\u5F00" : "\u626C\u58F0\u5668\u5DF2\u5173"),
l: common_vendor.o(($event) => changeLoudSpeaker())
};
};
}
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-07f20a9a"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/call/index.vue"]]);
wx.createPage(MiniProgramPage);

5
pages/call/index.json Normal file
View File

@ -0,0 +1,5 @@
{
"navigationBarTitleText": "实时语音",
"navigationStyle": "custom",
"usingComponents": {}
}

1
pages/call/index.wxml Normal file
View File

@ -0,0 +1 @@
<view class="container data-v-07f20a9a"><image src="{{a}}" mode="aspectFill" class="background_image data-v-07f20a9a"></image><view class="profile-image-container data-v-07f20a9a"><image class="profile-image data-v-07f20a9a" src="{{b}}" mode="aspectFill"/><text class="name data-v-07f20a9a">{{c}}</text><text class="status data-v-07f20a9a">{{d}}</text></view><view class="voicepopu data-v-07f20a9a" hidden="{{!e}}"><image class="voicegif data-v-07f20a9a" src="https://img.js.design/assets/img/6641b9e994c3758bc330f840.gif#f8c7347898f3aa106cb5fc759f1c8c26" mode="aspectFill"></image></view><view class="controls data-v-07f20a9a"><view class="control-item data-v-07f20a9a" bindtap="{{f}}"><text class="control-icon iconfont icon-zhuanliaotian white data-v-07f20a9a"></text></view><view class="control-item data-v-07f20a9a" bindtap="{{g}}"><image src="/static/icon/guadianhua.png" class="control-icon data-v-07f20a9a"></image></view><view class="control-item data-v-07f20a9a" bindtap="{{h}}"><image src="/static/icon/yangshengqi.png" class="control-icon data-v-07f20a9a"></image></view></view><view class="controls-label data-v-07f20a9a"><view class="control-item data-v-07f20a9a" bindtap="{{i}}"><text class="icon-label data-v-07f20a9a">转聊天</text></view><view class="control-item data-v-07f20a9a" bindtap="{{j}}"><text class="icon-label data-v-07f20a9a">取消</text></view><view class="control-item data-v-07f20a9a" bindtap="{{l}}"><text class="icon-label data-v-07f20a9a">{{k}}</text></view></view></view>

102
pages/call/index.wxss Normal file
View File

@ -0,0 +1,102 @@
.container.data-v-07f20a9a {
display: flex;
flex-direction: column;
height: 100vh;
/* // 根据你的实际需求调整高度 */
}
.container .background_image.data-v-07f20a9a {
content: '';
display: block;
position: absolute;
top: 0;
left: 0;
z-index: -9;
width: 100%;
height: 100vh;
filter: blur(4px);
background-size: cover;
}
.profile-image-container.data-v-07f20a9a {
flex: 1;
/* // 占据上方大部分空间 */
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.profile-image.data-v-07f20a9a {
width: 120px;
/* // 根据你的实际需求调整尺寸 */
height: 120px;
border-radius: 25px;
/* // 圆形头像 */
}
.name.data-v-07f20a9a {
font-size: 18px;
font-weight: bold;
margin-bottom: 5px;
}
.status.data-v-07f20a9a {
font-size: 14px;
}
.controls.data-v-07f20a9a {
flex: 0 0 70px;
display: flex;
justify-content: space-between;
align-items: center;
}
.controls-label.data-v-07f20a9a {
flex: 0 0 20px;
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 70px;
}
.control-item.data-v-07f20a9a {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
}
.control-icon.data-v-07f20a9a {
width: 70px;
/* // 根据你的实际需求调整尺寸 */
height: 70px;
border-radius: 35px;
text-align: center;
line-height: 70px;
transition: transform 0.3s;
/* 平滑变换效果 */
}
.icon-label.data-v-07f20a9a {
font-size: 12px;
}
.control-icon.active.data-v-07f20a9a {
transform: scale(1.1);
/* 放大效果 */
opacity: 0.7;
/* 透明度变化效果 */
}
.white.data-v-07f20a9a {
background-color: white;
font-size: 25px;
/* // 挂电话按钮的背景色,根据你的设计调整颜色 */
}
.voicepopu.data-v-07f20a9a {
position: fixed;
right: 0;
top: 70%;
transform: translateY(-50%);
width: 130rpx;
height: 90rpx;
background-color: white;
border-radius: 75rpx 0 0 75rpx;
overflow: hidden;
z-index: 999;
text-align: center;
}
.voicegif.data-v-07f20a9a {
width: 80rpx;
height: 80rpx;
}

154
pages/chat/index.js Normal file
View File

@ -0,0 +1,154 @@
"use strict";
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var common_vendor = require("../../common/vendor.js");
var kongshuju = require("../../kongshuju.js");
var api_index = require("../../api/index.js");
var config_index = require("../../config/index.js");
require("../../utils/request.js");
const _sfc_main = {
setup(__props) {
const state = common_vendor.reactive({
initChatList: [],
chatList: [],
finished: false
});
const { chatList, finished } = common_vendor.toRefs(state);
const getMessageRecord = () => {
api_index.getAllRolesMessageRecord({
start_time: common_vendor.hooks().subtract(7, "days").startOf().format("YYYY-MM-DD HH:mm:ss"),
stop_time: common_vendor.hooks().endOf().format("YYYY-MM-DD HH:mm:ss")
}).then(({ status, data }) => {
if (Number(status) === 200 && Array.isArray(data.role_list)) {
const list = data.role_list.map((item) => {
var _a;
const [lastMessage] = (_a = item.list) == null ? void 0 : _a.slice(-1);
return __spreadProps(__spreadValues({}, item), {
lastMessage
});
});
state.initChatList = list;
state.chatList = list;
}
}).finally(() => {
state.finished = true;
});
};
common_vendor.onShow(getMessageRecord);
const onChatOnLine = async ({ role_info }) => {
try {
const { user_info } = common_vendor.index.getStorageSync("userData");
const { user_id } = user_info || {};
if (user_id) {
const { status, data } = await api_index.createChat({
user_id,
character_id: role_info.role_id
});
if (status === "success") {
common_vendor.index.setStorage({
key: "chatInfo",
data: __spreadValues({
userId: user_id,
session_id: data.session_id
}, role_info),
success: () => {
common_vendor.index.navigateTo({
url: "/pages/chatOnline/index"
});
}
});
} else {
common_vendor.index.showToast({
title: "\u521B\u5EFA\u804A\u5929\u5931\u8D25"
});
}
} else {
common_vendor.index.showToast({
title: "\u5F53\u524D\u767B\u5F55\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",
icon: "none"
});
common_vendor.index.clearStorage();
common_vendor.index.navigateTo({
url: "/pages/login/index"
});
}
} catch (e) {
throw new Error(e);
}
};
const timer = common_vendor.ref(null);
const onInputKeyWords = (e) => {
const keyWord = e.detail.value;
if (timer.value) {
clearTimeout(timer.value);
}
timer.value = setTimeout(() => {
if (keyWord) {
const clonedChatList = JSON.parse(JSON.stringify(state.initChatList));
const list = clonedChatList.filter((item) => {
const { role_info, list: list2 } = item;
if (role_info.role_name.includes(keyWord)) {
return true;
}
const filterMessageList = list2.filter(({ message }) => message.includes(keyWord));
if (filterMessageList.length > 0) {
item.lastMessage = filterMessageList[0];
return true;
}
return false;
});
state.chatList = list;
} else {
state.chatList = state.initChatList;
}
}, 500);
};
const sliceMessage = (str) => {
const message = str.replace(/\r\n|\r|\n/g, " ");
if (message.length > 20) {
return `${message.substring(0, 20)}...`;
}
return message;
};
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.o(onInputKeyWords),
b: common_vendor.unref(finished) && common_vendor.unref(chatList).length === 0
}, common_vendor.unref(finished) && common_vendor.unref(chatList).length === 0 ? {
c: kongshuju._imports_1
} : common_vendor.unref(finished) && common_vendor.unref(chatList).length > 0 ? {
e: common_vendor.f(common_vendor.unref(chatList), (item, index, i0) => {
return {
a: `${common_vendor.unref(config_index.filePrefix)}${item.role_info.avatar_id}`,
b: common_vendor.t(item.role_info.role_name),
c: common_vendor.t(sliceMessage(item.lastMessage.message)),
d: common_vendor.t(item.lastMessage.create_at),
e: index,
f: common_vendor.o(($event) => onChatOnLine(item))
};
})
} : {}, {
d: common_vendor.unref(finished) && common_vendor.unref(chatList).length > 0
});
};
}
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-3fea99d8"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/chat/index.vue"]]);
wx.createPage(MiniProgramPage);

4
pages/chat/index.json Normal file
View File

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "聊天",
"usingComponents": {}
}

1
pages/chat/index.wxml Normal file
View File

@ -0,0 +1 @@
<view class="content data-v-3fea99d8"><view class="search_box data-v-3fea99d8"><text class="iconfont icon-search data-v-3fea99d8"></text><input class="data-v-3fea99d8" bindinput="{{a}}" type="text" placeholder="请输入内容"/></view><view wx:if="{{b}}" class="no-data data-v-3fea99d8"><image class="data-v-3fea99d8" src="{{c}}" mode="aspectFill"></image><text class="data-v-3fea99d8">暂无聊天</text></view><view wx:elif="{{d}}" class="chat_list data-v-3fea99d8"><view wx:for="{{e}}" wx:for-item="item" wx:key="e" bindtap="{{item.f}}" class="chat_item data-v-3fea99d8"><view class="avatar_box data-v-3fea99d8"><image src="{{item.a}}" class="avatar data-v-3fea99d8" mode="aspectFill"></image><view class="state_dot online data-v-3fea99d8"></view></view><view class="center_info data-v-3fea99d8"><text class="name data-v-3fea99d8">{{item.b}}</text><text class="text data-v-3fea99d8">{{item.c}}</text></view><view class="right_info data-v-3fea99d8"><text class="time data-v-3fea99d8">{{item.d}}</text></view></view></view></view>

123
pages/chat/index.wxss Normal file
View File

@ -0,0 +1,123 @@
.search_box.data-v-3fea99d8 {
position: relative;
margin-top: 12px;
height: 28px;
padding: 0 16px;
box-sizing: border-box;
}
.search_box .iconfont.data-v-3fea99d8 {
position: absolute;
top: 50%;
left: 24px;
transform: translateY(-50%);
}
.search_box input.data-v-3fea99d8 {
border-bottom: 1px solid rgba(229, 229, 229, 1);
font-size: 12px;
color: rgba(153, 153, 153, 1);
padding: 0 36px;
box-sizing: border-box;
height: 28px;
}
.no-data.data-v-3fea99d8 {
padding-top: 26vh;
}
.no-data image.data-v-3fea99d8 {
display: block;
margin: 0 auto;
width: 70px;
height: 70px;
}
.no-data text.data-v-3fea99d8 {
margin-top: 12px;
display: block;
font-size: 18px;
color: #999999;
text-align: center;
}
.chat_list.data-v-3fea99d8 {
margin-top: 20px;
padding: 0 16px;
box-sizing: border-box;
}
.chat_item.data-v-3fea99d8 {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
height: 78px;
border: 1px solid rgba(213, 241, 242, 0.5);
border-radius: 24px;
padding: 16px;
box-sizing: border-box;
}
.chat_item .avatar_box.data-v-3fea99d8 {
position: relative;
margin-right: 12px;
}
.chat_item .avatar.data-v-3fea99d8 {
display: block;
width: 40px;
height: 40px;
border-radius: 50%;
object-fit: cover;
}
.chat_item .state_dot.data-v-3fea99d8 {
position: absolute;
right: 0;
bottom: 0;
width: 12px;
height: 12px;
border-radius: 50%;
background: #fff;
}
.chat_item .state_dot.data-v-3fea99d8::before {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 10px;
height: 10px;
border-radius: 50%;
content: '';
}
.chat_item .online.data-v-3fea99d8 {
background: rgba(93, 214, 77, 1);
}
.chat_item .offline.data-v-3fea99d8 {
background: rgba(255, 109, 51, 1);
}
.chat_item .center_info.data-v-3fea99d8 {
flex-grow: 1;
}
.chat_item .name.data-v-3fea99d8 {
display: block;
font-size: 16px;
font-weight: 500;
color: rgba(11, 41, 89, 1);
line-height: 24px;
}
.chat_item .text.data-v-3fea99d8 {
width: 300px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
margin-top: 4px;
display: block;
font-size: 12px;
color: rgba(43, 67, 105, 1);
line-height: 18px;
}
.chat_item .right_info.data-v-3fea99d8 {
position: absolute;
top: 12px;
right: 16px;
}
.chat_item .time.data-v-3fea99d8 {
font-size: 12px;
color: rgba(43, 67, 105, 1);
line-height: 22px;
}

207
pages/chatOnline/index.js Normal file
View File

@ -0,0 +1,207 @@
"use strict";
var common_vendor = require("../../common/vendor.js");
var config_index = require("../../config/index.js");
var api_index = require("../../api/index.js");
var utils_wsRequest = require("../../utils/wsRequest.js");
require("../../utils/request.js");
const _sfc_main = {
setup(__props) {
const currentDate = common_vendor.hooks().format("YYYY-MM-DD");
const currentMessage = common_vendor.ref("");
const messageList = common_vendor.reactive([]);
const initalMessageLength = common_vendor.ref(0);
const backGroundList = common_vendor.reactive([]);
const currentBackGroundImage = common_vendor.computed$1(() => {
const pageNum = Math.floor((messageList.length - initalMessageLength.value) / 10);
const currentIndex = pageNum % backGroundList.length;
return backGroundList[currentIndex] || "";
});
const sessionId = common_vendor.ref("");
const aiAvatarId = common_vendor.ref("");
const currentRoleId = common_vendor.ref("");
const userAvatar = common_vendor.ref("");
common_vendor.onLoad(() => {
console.log("onLoad");
const { user_info } = common_vendor.index.getStorageSync("userData");
userAvatar.value = (user_info == null ? void 0 : user_info.avatar_id) || config_index.defaultAvatar;
common_vendor.index.getStorage({
key: "chatInfo",
success: ({ data }) => {
const { session_id, avatar_id, role_id, background_ids = "", role_name } = data;
common_vendor.index.setNavigationBarTitle({
title: role_name || ""
});
if (sessionId) {
sessionId.value = session_id;
aiAvatarId.value = avatar_id;
currentRoleId.value = role_id;
backGroundList.push(...background_ids.split(","));
getHistoryMsg();
}
}
});
});
const getHistoryMsg = () => {
api_index.getHistoryMessage({
role_id: currentRoleId.value,
start_time: common_vendor.hooks().subtract(7, "days").startOf().format("YYYY-MM-DD HH:mm:ss"),
stop_time: common_vendor.hooks().endOf().format("YYYY-MM-DD HH:mm:ss")
}).then(({ status, data }) => {
if (Number(status) === 200 && Array.isArray(data == null ? void 0 : data.list)) {
const msgList = data.list.map(({ create_at, direction, message }) => ({
from: Number(direction) === 0 ? "me" : "ai",
avatar: Number(direction) === 0 ? userAvatar.value : aiAvatarId.value,
message,
date: create_at.split(" ")[0],
time: create_at.split(" ")[1]
}));
messageList.push(...msgList);
scrollToLastItem();
}
}).catch((err) => {
}).finally(initChat);
};
const ws = common_vendor.ref(null);
const messageIsEnd = common_vendor.ref(false);
const initChat = async () => {
var _a;
try {
ws.value = new utils_wsRequest.webSocketClass(config_index.wsUrl, 60);
(_a = ws.value) == null ? void 0 : _a.initSocket().then((res) => {
common_vendor.index.$on("message", ({ data }) => {
if (typeof data === "string") {
const { type, code, msg } = JSON.parse(data);
if (Number(code) === 200 && msg) {
if (messageIsEnd.value) {
messageList.push({
isSaved: false,
from: "ai",
avatar: aiAvatarId.value,
message: msg,
date: common_vendor.hooks().format("YYYY-MM-DD"),
time: common_vendor.hooks().format("HH:mm:ss")
});
} else {
const [lastMessageItem] = messageList.slice(-1);
lastMessageItem.message += msg;
}
scrollToLastItem();
}
if (type === "end") {
onSaveMessage();
}
messageIsEnd.value = type === "end";
}
});
});
} catch (e) {
throw new Error(e);
}
};
const toCall = () => {
var _a;
(_a = ws.value) == null ? void 0 : _a.closeSocket();
common_vendor.index.navigateTo({
url: "/pages/call/index?avatar_id=" + aiAvatarId.value
});
};
const sendMessage = () => {
var _a;
if (currentMessage.value) {
const data = {
text: currentMessage.value,
audio: "",
is_close: false,
meta_info: {
stream: false,
voice_synthesize: false,
is_end: false,
encoding: "",
session_id: sessionId.value
}
};
(_a = ws.value) == null ? void 0 : _a.sendMsg(data).then((res) => {
if (res) {
messageList.push({
isSaved: false,
from: "me",
avatar: userAvatar.value,
message: currentMessage.value,
date: common_vendor.hooks().format("YYYY-MM-DD"),
time: common_vendor.hooks().format("HH:mm:ss")
});
currentMessage.value = "";
messageIsEnd.value = true;
onSaveMessage();
}
}).catch(() => {
common_vendor.index.showToast({
title: "\u53D1\u9001\u6D88\u606F\u5931\u8D25",
icon: "none"
});
}).finally(scrollToLastItem);
} else {
common_vendor.index.showToast({
title: "\u8BF7\u8F93\u5165\u5185\u5BB9",
duration: 2e3
});
}
};
const onSaveMessage = () => {
const [item] = messageList.slice(-1);
if (item.isSaved) {
return;
}
api_index.saveMessage({
role_id: currentRoleId.value,
direction: item.from === "me" ? 0 : 1,
message: item.message
}).then(({ status }) => {
item.isSaved = true;
});
};
const lastItemId = common_vendor.ref("");
const scrollToItem = common_vendor.ref("");
const scrollToLastItem = () => {
const id = (Math.random() * 1e10).toFixed(0);
lastItemId.value = id;
common_vendor.nextTick(() => {
scrollToItem.value = `item_${id}`;
});
};
common_vendor.onUnmounted(() => {
var _a;
console.log("onUnmounted");
(_a = ws.value) == null ? void 0 : _a.closeSocket();
common_vendor.index.$off("message");
});
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.unref(currentBackGroundImage)
}, common_vendor.unref(currentBackGroundImage) ? {
b: `${common_vendor.unref(config_index.filePrefix)}${common_vendor.unref(currentBackGroundImage)}`
} : {}, {
c: common_vendor.f(common_vendor.unref(messageList), (item, index, i0) => {
return {
a: common_vendor.t(item.date === common_vendor.unref(currentDate) ? "\u4ECA\u5929" : item.date),
b: common_vendor.t(item.time),
c: `${common_vendor.unref(config_index.filePrefix)}${item.avatar}`,
d: common_vendor.t(item.message),
e: item.message,
f: `item_${index}`,
g: common_vendor.n(item.from === "me" ? "chat_item right" : "chat_item left")
};
}),
d: `item_${lastItemId.value}`,
e: scrollToItem.value,
f: common_vendor.o(toCall),
g: common_vendor.o(sendMessage),
h: currentMessage.value,
i: common_vendor.o(($event) => currentMessage.value = $event.detail.value),
j: common_vendor.o(sendMessage)
});
};
}
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-725f8307"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/chatOnline/index.vue"]]);
wx.createPage(MiniProgramPage);

View File

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "在线聊天",
"usingComponents": {}
}

View File

@ -0,0 +1 @@
<view class="content data-v-725f8307"><image wx:if="{{a}}" src="{{b}}" mode="aspectFill" class="background_image data-v-725f8307"></image><scroll-view scroll-into-view="{{e}}" scroll-y="true" class="scroll_wrapper data-v-725f8307"><view class="chat_list data-v-725f8307"><view wx:for="{{c}}" wx:for-item="item" wx:key="e" id="{{item.f}}" class="{{['data-v-725f8307', item.g]}}"><view class="chat_time data-v-725f8307">{{item.a}} {{item.b}}</view><view class="chat_content data-v-725f8307"><image src="{{item.c}}" class="avatar data-v-725f8307" mode="aspectFill"></image><view class="message data-v-725f8307">{{item.d}}</view></view></view><view id="{{d}}" class="last_chat_item data-v-725f8307"></view></view></scroll-view><view class="bottom_bar data-v-725f8307"><view class="icon_wrapper data-v-725f8307"><text bindtap="{{f}}" class="iconfont icon-weibiaoti-- data-v-725f8307"></text></view><input class="data-v-725f8307" confirm-type="send" confirm-hold="{{true}}" hold-keyboard="{{true}}" bindconfirm="{{g}}" type="text" placeholder="说点什么吧..." value="{{h}}" bindinput="{{i}}"/><view class="icon_wrapper data-v-725f8307"><text bindtap="{{j}}" class="iconfont icon-paperPlane data-v-725f8307"></text></view></view></view>

110
pages/chatOnline/index.wxss Normal file
View File

@ -0,0 +1,110 @@
.content.data-v-725f8307 {
width: 100%;
height: 100vh;
position: relative;
}
.content .background_image.data-v-725f8307 {
content: '';
display: block;
position: absolute;
top: 0;
left: 0;
z-index: -9;
width: 100%;
height: 100vh;
filter: blur(4px);
background-size: cover;
}
.scroll_wrapper.data-v-725f8307 {
height: calc(100vh - 80px);
}
.chat_list.data-v-725f8307 {
overflow: hidden;
padding-bottom: 80px;
width: 100%;
padding: 0 10px;
box-sizing: border-box;
}
.chat_item .chat_time.data-v-725f8307 {
margin: 16px 0;
text-align: center;
font-size: 14px;
color: rgba(83, 88, 110, 1);
}
.last_chat_item.data-v-725f8307 {
width: 100%;
margin-top: 20px;
}
.chat_content.data-v-725f8307 {
display: flex;
align-items: flex-start;
}
.left .chat_content.data-v-725f8307 {
flex-direction: row;
}
.right .chat_content.data-v-725f8307 {
flex-direction: row-reverse;
}
.avatar.data-v-725f8307 {
flex-shrink: 0;
display: block;
width: 46px;
height: 46px;
border-radius: 50%;
}
.left .avatar.data-v-725f8307 {
margin-right: 12px;
}
.right .avatar.data-v-725f8307 {
margin-left: 12px;
}
.chat_content .message.data-v-725f8307 {
max-width: calc(100% - 130px);
padding: 8px 12px;
box-sizing: border-box;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
font-size: 16px;
color: rgba(63, 72, 112, 1);
background: rgba(204, 230, 255, 1);
}
.right .chat_content .message.data-v-725f8307 {
background: rgba(242, 52, 255, 1);
color: #ffffff;
}
.bottom_bar.data-v-725f8307 {
padding: 0 12px;
box-sizing: border-box;
width: 100%;
height: 80px;
background: #ffffff;
display: flex;
justify-content: space-between;
align-items: center;
}
.icon_wrapper.data-v-725f8307 {
flex-shrink: 0;
width: 48px;
height: 48px;
background: rgb(245, 245, 247);
border-radius: 10px;
text-align: center;
}
.icon_wrapper .iconfont.data-v-725f8307 {
font-size: 26px;
line-height: 48px !important;
text-align: center;
}
.bottom_bar input.data-v-725f8307 {
flex-grow: 1;
margin: 0 10px;
padding: 0 10px;
box-sizing: border-box;
height: 48px;
border-radius: 10px;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1);
font-size: 14px;
color: rgba(35, 42, 53, 1);
text-align: left;
}

159
pages/community/detail.js Normal file
View File

@ -0,0 +1,159 @@
"use strict";
var common_vendor = require("../../common/vendor.js");
var api_index = require("../../api/index.js");
var config_index = require("../../config/index.js");
require("../../utils/request.js");
const _sfc_main = {
setup(__props) {
const userInfo = common_vendor.ref({});
const detail = common_vendor.reactive({
id: "",
userId: "",
images: [],
title: "",
text: "",
time: "",
isLike: false,
likeCount: void 0
});
const commentList = common_vendor.ref([]);
common_vendor.onLoad((e) => {
const { user_info } = common_vendor.index.getStorageSync("userData");
userInfo.value = user_info;
getCommunity(e.id);
getComment(e.id);
});
const getCommunity = (id) => {
api_index.getCommunityDetail(id).then(({ status, data }) => {
if (Number(status) === 200) {
const { post_id, user_id, title, is_like, like_count, content, created_at } = data.post_info;
const detailInfo = typeof content === "string" ? JSON.parse(content) : {};
detail.title = title || "";
detail.id = post_id;
detail.userId = user_id;
detail.images = detailInfo.images || [];
detail.text = detailInfo.text || "";
detail.time = created_at;
detail.isLike = is_like;
detail.likeCount = like_count;
}
});
};
const getComment = (id) => {
api_index.getCommentData(id).then(({ status, data }) => {
if (Number(status) === 200 && Array.isArray(data.comment_list)) {
commentList.value = data.comment_list;
}
});
};
const commentText = common_vendor.ref("");
const onSubmitComment = () => {
if (commentText.value) {
api_index.submitComment({
id: detail.id,
content: commentText.value
}).then(({ status }) => {
if (Number(status) === 200) {
commentText.value = "";
getComment(detail.id);
}
});
} else
[
common_vendor.index.showToast({
title: "\u8BF7\u8F93\u5165\u8BC4\u8BBA\u5185\u5BB9",
icon: "none"
})
];
};
const onDeleteComment = (item) => {
api_index.deleteComment({
id: detail.id,
commentId: item.comment_id
}).then(() => {
getComment(detail.id);
});
};
const onSubmitLike = async (type) => {
if (type === "like") {
api_index.submitLike(detail.id).then(({ status }) => {
if (Number(status) === 200) {
detail.isLike = true;
detail.likeCount += 1;
}
});
} else {
api_index.cancelLike(detail.id).then(({ status }) => {
if (Number(status) === 200) {
detail.isLike = false;
detail.likeCount -= 1;
}
});
}
};
const commentTxt = common_vendor.ref("");
const onInputBlur = () => {
if (commentTxt.value) {
api_index.submitComment({
id: detail.id,
content: commentTxt.value
}).then(({ status }) => {
if (Number(status) === 200) {
commentTxt.value = "";
getComment(detail.id);
}
});
}
};
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.unref(detail).images.length > 0
}, common_vendor.unref(detail).images.length > 0 ? {
b: common_vendor.f(common_vendor.unref(detail).images, (img, k0, i0) => {
return {
a: `${common_vendor.unref(config_index.filePrefix)}${img}`,
b: img
};
})
} : {}, {
c: common_vendor.t(common_vendor.unref(detail).title),
d: common_vendor.t(common_vendor.unref(detail).text),
e: common_vendor.t(common_vendor.unref(detail).time),
f: common_vendor.t(commentList.value.length),
g: `${common_vendor.unref(config_index.filePrefix)}${userInfo.value.avatar_id}`,
h: common_vendor.o(onInputBlur),
i: commentTxt.value,
j: common_vendor.o(($event) => commentTxt.value = $event.detail.value),
k: common_vendor.f(commentList.value, (item, k0, i0) => {
return common_vendor.e({
a: `${common_vendor.unref(config_index.filePrefix)}${item.avatar_id}`,
b: common_vendor.t(item.username),
c: item.user_id === common_vendor.unref(detail).userId
}, item.user_id === common_vendor.unref(detail).userId ? {} : {}, {
d: item.user_id === userInfo.value.user_id
}, item.user_id === userInfo.value.user_id ? {
e: common_vendor.o(($event) => onDeleteComment(item))
} : {}, {
f: common_vendor.t(item.content),
g: common_vendor.t(item.time),
h: item.comment_id
});
}),
l: commentText.value,
m: common_vendor.o(($event) => commentText.value = $event.detail.value),
n: common_vendor.unref(detail).isLike
}, common_vendor.unref(detail).isLike ? {
o: common_vendor.o(($event) => onSubmitLike("cancel"))
} : {
p: common_vendor.o(($event) => onSubmitLike("like"))
}, {
q: common_vendor.t(common_vendor.unref(detail).likeCount),
r: commentText.value
}, commentText.value ? {
s: common_vendor.o(onSubmitComment)
} : {});
};
}
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2f2e4a30"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/community/detail.vue"]]);
wx.createPage(MiniProgramPage);

View File

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "详情",
"usingComponents": {}
}

View File

@ -0,0 +1 @@
<view class="content data-v-2f2e4a30"><swiper wx:if="{{a}}" class="data-v-2f2e4a30" indicator-dots="{{true}}"><swiper-item wx:for="{{b}}" wx:for-item="img" wx:key="b" class="banner_item data-v-2f2e4a30"><image src="{{img.a}}" class="banner data-v-2f2e4a30" mode="aspectFill"></image></swiper-item></swiper><view class="title data-v-2f2e4a30">{{c}}</view><view class="text data-v-2f2e4a30">{{d}}</view><view class="time data-v-2f2e4a30">编辑于{{e}}</view><view class="comment_total data-v-2f2e4a30">共{{f}}条评论</view><view class="comment_input_wrapper data-v-2f2e4a30"><image src="{{g}}" class="avatar data-v-2f2e4a30" mode="aspectFill"></image><input bindblur="{{h}}" class="comment_input data-v-2f2e4a30" type="text" placeholder="有话要说,快来评论" value="{{i}}" bindinput="{{j}}"/></view><view class="comment_list data-v-2f2e4a30"><view wx:for="{{k}}" wx:for-item="item" wx:key="h" class="comment_item data-v-2f2e4a30"><image src="{{item.a}}" mode="aspectFill" class="avatar data-v-2f2e4a30"></image><view class="detail data-v-2f2e4a30"><view class="user data-v-2f2e4a30">{{item.b}} <view wx:if="{{item.c}}" class="tag data-v-2f2e4a30"> 作者 </view><text wx:if="{{item.d}}" bindtap="{{item.e}}" class="delete data-v-2f2e4a30">删除</text></view><view class="content data-v-2f2e4a30">{{item.f}}</view><view class="com_time data-v-2f2e4a30">{{item.g}}</view></view></view></view><view class="bottom_box data-v-2f2e4a30"><input type="text" placeholder="说点什么..." class="input data-v-2f2e4a30" value="{{l}}" bindinput="{{m}}"/><view class="btn_box data-v-2f2e4a30"><view class="btn data-v-2f2e4a30"><text wx:if="{{n}}" bindtap="{{o}}" class="iconfont icon-like data-v-2f2e4a30"></text><text wx:else bindtap="{{p}}" class="iconfont icon-aixin data-v-2f2e4a30"></text><text class="count data-v-2f2e4a30">{{q}}</text></view><button wx:if="{{r}}" bindtap="{{s}}" class="send_btn data-v-2f2e4a30">完成</button></view></view></view>

184
pages/community/detail.wxss Normal file
View File

@ -0,0 +1,184 @@
.content.data-v-2f2e4a30 {
padding-bottom: 80px;
}
swiper.data-v-2f2e4a30 {
height: 500px !important;
}
.banner_item.data-v-2f2e4a30 {
height: 500px;
}
.banner.data-v-2f2e4a30 {
display: block;
width: 100%;
height: 500px;
}
.title.data-v-2f2e4a30 {
margin: 20px 0;
padding: 0 16px;
box-sizing: border-box;
font-size: 18px;
font-weight: 500;
color: #000000;
}
.text.data-v-2f2e4a30 {
padding: 0 16px;
box-sizing: border-box;
font-size: 14px;
color: #000000;
}
.time.data-v-2f2e4a30 {
position: relative;
font-size: 12px;
color: rgba(140, 143, 150, 1);
padding: 10px 16px;
box-sizing: border-box;
}
.time.data-v-2f2e4a30::after {
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
content: '';
width: calc(100% - 32px);
height: 1px;
background: rgba(229, 229, 229, 1);
}
.comment_total.data-v-2f2e4a30 {
padding: 10px 16px;
box-sizing: border-box;
font-size: 12px;
color: rgba(128, 128, 128, 1);
}
.bottom_box.data-v-2f2e4a30 {
position: fixed;
left: 0;
right: 0;
bottom: 0;
padding: 10px 16px;
box-sizing: border-box;
width: 100%;
border-top: 1px solid rgba(229, 229, 229, 1);
display: flex;
justify-content: space-between;
align-items: center;
background-color: #fff;
}
.bottom_box .input.data-v-2f2e4a30 {
padding: 0 10px;
box-sizing: border-box;
flex-grow: 1;
height: 30px;
background-color: rgba(245, 245, 245, 1);
border-radius: 15px;
font-size: 14px;
line-height: 30px;
}
.bottom_box .btn_box.data-v-2f2e4a30 {
flex-shrink: 0;
display: flex;
align-items: center;
font-size: 16px;
}
.bottom_box .btn.data-v-2f2e4a30 {
margin-left: 12px;
display: flex;
align-items: center;
}
.btn .iconfont.data-v-2f2e4a30 {
font-size: 18px;
}
.btn .icon-like.data-v-2f2e4a30 {
color: rgba(243, 67, 98, 1);
}
.btn .count.data-v-2f2e4a30 {
font-size: 16px;
}
.send_btn.data-v-2f2e4a30 {
margin-left: 12px;
height: 30px;
line-height: 30px;
font-size: 14px;
color: #fff;
background: linear-gradient(270deg, rgba(255, 153, 71, 1) 0%, rgba(242, 52, 255, 1) 57.29%, rgba(243, 64, 125, 1) 83.14%, rgba(243, 67, 98, 1) 100%);
}
.comment_input_wrapper.data-v-2f2e4a30 {
padding: 15px 10px 20px;
box-sizing: border-box;
display: flex;
justify-content: space-between;
align-items: center;
}
.comment_input_wrapper .avatar.data-v-2f2e4a30 {
flex-shrink: 0;
margin-right: 16px;
display: block;
width: 34px;
height: 34px;
border-radius: 50%;
}
.comment_input_wrapper .comment_input.data-v-2f2e4a30 {
flex-grow: 1;
font-size: 12px;
padding: 0 14px;
box-sizing: border-box;
height: 28px;
border-radius: 14px;
background: rgba(245, 245, 247, 1);
}
.comment_list.data-v-2f2e4a30 {
padding: 0 10px;
box-sizing: border-box;
}
.comment_item.data-v-2f2e4a30 {
margin-bottom: 20px;
display: flex;
align-items: flex-start;
}
.comment_item .avatar.data-v-2f2e4a30 {
flex-shrink: 0;
margin-right: 16px;
display: block;
width: 34px;
height: 34px;
border-radius: 50%;
}
.comment_item .detail.data-v-2f2e4a30 {
flex-grow: 1;
}
.detail .user.data-v-2f2e4a30 {
position: relative;
display: flex;
align-items: center;
font-size: 12px;
color: rgba(166, 166, 166, 1);
}
.user .tag.data-v-2f2e4a30 {
margin-left: 4px;
width: 20px;
height: 12px;
border-radius: 8px;
background-color: #ddd;
color: #000000;
font-size: 8px;
line-height: 12px;
text-align: center;
}
.user .delete.data-v-2f2e4a30 {
position: absolute;
right: 10px;
top: 0;
font-size: 10px;
}
.detail .content.data-v-2f2e4a30 {
margin: 2px 0;
padding: 0;
font-size: 12px;
line-height: 20px;
}
.detail .com_time.data-v-2f2e4a30 {
padding: 0;
font-size: 10px;
border: none;
color: rgba(140, 143, 150, 1);
}

135
pages/community/index.js Normal file
View File

@ -0,0 +1,135 @@
"use strict";
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var common_vendor = require("../../common/vendor.js");
var tianjia = require("../../tianjia.js");
var kongshuju = require("../../kongshuju.js");
var config_index = require("../../config/index.js");
var api_index = require("../../api/index.js");
require("../../utils/request.js");
const _sfc_main = {
setup(__props) {
const openMenu = common_vendor.ref(false);
const finished = common_vendor.ref(false);
const rolesList = common_vendor.ref([]);
const getRoleList = () => {
api_index.getAllRoles().then(({ status, data }) => {
if (Number(status) === 200 && Array.isArray(data)) {
rolesList.value = data;
}
}).finally(getList);
};
const list = common_vendor.ref([]);
const getList = () => {
api_index.getListOfCommunity({
start_time: common_vendor.hooks().subtract(7, "days").startOf().format("YYYY-MM-DD HH:mm:ss"),
stop_time: common_vendor.hooks().endOf().format("YYYY-MM-DD HH:mm:ss"),
role_id: curRoleId.value
}).then(({ status, data }) => {
if (Number(status) === 200 && Array.isArray(data.post_list)) {
const array = data.post_list.map((item) => {
var _a;
const content = JSON.parse(item.content);
const cover = (_a = content == null ? void 0 : content.images) == null ? void 0 : _a[0];
return __spreadProps(__spreadValues({}, item), {
cover
});
});
list.value = array;
}
}).finally(() => {
finished.value = true;
});
};
const curRoleId = common_vendor.ref("");
const curRoleName = common_vendor.computed$1(() => {
const roleItem = rolesList.value.find((item) => item.role_id === curRoleId.value);
if (roleItem) {
return roleItem.role_name;
}
return "\u840C\u4E3B\u4EEC";
});
const onRoleChange = (item) => {
if (item) {
curRoleId.value = item.role_id;
} else {
curRoleId.value = "";
}
openMenu.value = false;
getList();
};
const toSubmitCommunity = () => {
common_vendor.index.navigateTo({
url: "/pages/community/release"
});
};
const toDetail = (item) => {
common_vendor.index.navigateTo({
url: `/pages/community/detail?id=${item.post_id}`
});
};
common_vendor.onShow(getRoleList);
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.t(common_vendor.unref(curRoleName)),
b: common_vendor.n(openMenu.value ? "open" : ""),
c: common_vendor.o(($event) => openMenu.value = !openMenu.value),
d: common_vendor.n(curRoleId.value === "" ? "active" : ""),
e: common_vendor.o(($event) => onRoleChange(null)),
f: common_vendor.f(rolesList.value, (item, k0, i0) => {
return {
a: `${common_vendor.unref(config_index.filePrefix)}${item.avatar_id}`,
b: common_vendor.t(item.role_name),
c: item.role_id,
d: common_vendor.n(curRoleId.value === item.role_id ? "active" : ""),
e: common_vendor.o(($event) => onRoleChange(item), item.role_id)
};
}),
g: common_vendor.n(openMenu.value ? "open" : ""),
h: tianjia._imports_0,
i: common_vendor.o(toSubmitCommunity),
j: finished.value && list.value.length === 0
}, finished.value && list.value.length === 0 ? {
k: kongshuju._imports_1
} : finished.value && list.value.length > 0 ? {
m: common_vendor.f(list.value, (item, index, i0) => {
return common_vendor.e({
a: `${common_vendor.unref(config_index.filePrefix)}${item.cover}`,
b: common_vendor.t(item.title),
c: item.user_avatar_id
}, item.user_avatar_id ? {
d: `${common_vendor.unref(config_index.filePrefix)}${item.user_avatar_id}`
} : {}, {
e: common_vendor.t(item.username),
f: item.is_like
}, item.is_like ? {} : {}, {
g: common_vendor.t(item.like_count),
h: index,
i: common_vendor.o(($event) => toDetail(item))
});
})
} : {}, {
l: finished.value && list.value.length > 0
});
};
}
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-5fb47dc3"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/community/index.vue"]]);
wx.createPage(MiniProgramPage);

View File

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "社区",
"usingComponents": {}
}

View File

@ -0,0 +1 @@
<view class="content data-v-5fb47dc3"><view class="ai_picker data-v-5fb47dc3"><view class="role_menu data-v-5fb47dc3"><view class="{{['cur_role_item', 'data-v-5fb47dc3', b]}}" bindtap="{{c}}"><text class="select_name data-v-5fb47dc3">{{a}}</text><text class="iconfont icon-xia data-v-5fb47dc3"></text></view><view class="{{['role_menu_list', 'data-v-5fb47dc3', g]}}"><view class="{{['role_menu_item', 'data-v-5fb47dc3', d]}}" bindtap="{{e}}"><view class="avatar avatar_empty data-v-5fb47dc3"></view><text class="data-v-5fb47dc3">萌主们</text></view><view wx:for="{{f}}" wx:for-item="item" wx:key="c" class="{{[item.d, 'role_menu_item', 'data-v-5fb47dc3']}}" bindtap="{{item.e}}"><image src="{{item.a}}" mode="aspectFill" class="avatar data-v-5fb47dc3"></image><text class="data-v-5fb47dc3">{{item.b}}</text></view></view></view><image src="{{h}}" mode="aspectFill" class="add_icon data-v-5fb47dc3" bindtap="{{i}}"></image></view><view wx:if="{{j}}" class="no-data data-v-5fb47dc3"><image class="data-v-5fb47dc3" src="{{k}}" mode="aspectFill"></image><text class="data-v-5fb47dc3">暂无帖子</text></view><scroll-view wx:elif="{{l}}" scroll-y="true" class="scroll_wrapper data-v-5fb47dc3"><view class="list data-v-5fb47dc3"><view wx:for="{{m}}" wx:for-item="item" wx:key="h" bindtap="{{item.i}}" class="item data-v-5fb47dc3"><image src="{{item.a}}" mode="aspectFill" class="cover data-v-5fb47dc3"></image><view class="content data-v-5fb47dc3">{{item.b}}</view><view class="info data-v-5fb47dc3"><view class="user data-v-5fb47dc3"><image wx:if="{{item.c}}" src="{{item.d}}" mode="aspectFill" class="avatar data-v-5fb47dc3"></image><text class="name data-v-5fb47dc3">{{item.e}}</text></view><view class="count data-v-5fb47dc3"><text wx:if="{{item.f}}" class="iconfont icon-like data-v-5fb47dc3"></text><text wx:else class="iconfont icon-aixin data-v-5fb47dc3"></text><text class="data-v-5fb47dc3">{{item.g}}</text></view></view></view></view></scroll-view></view>

184
pages/community/index.wxss Normal file
View File

@ -0,0 +1,184 @@
.ai_picker.data-v-5fb47dc3 {
position: relative;
width: 100%;
height: 48px;
padding: 0 16px;
box-sizing: border-box;
font-size: 16px;
line-height: 48px;
box-shadow: 0px 2px 6px 2px rgba(166, 166, 166, 0.25);
}
.cur_role_item.data-v-5fb47dc3 {
padding: 0 8px;
width: 88px;
height: 32px;
border-radius: 16px;
background-color: #fff;
border: 0.5px solid rgba(151, 151, 151, 0.2);
display: flex;
justify-content: space-between;
align-items: center;
font-size: 16px;
color: #000000;
}
.cur_role_item .select_name.data-v-5fb47dc3 {
font-size: 14px;
line-height: 32px;
}
.cur_role_item .iconfont.data-v-5fb47dc3 {
font-size: 6px;
transition: 300ms;
}
.cur_role_item.open .iconfont.data-v-5fb47dc3 {
transform: rotate(180deg);
}
.role_menu.data-v-5fb47dc3 {
position: absolute;
z-index: 999;
left: 16px;
top: 8px;
}
.role_menu_list.data-v-5fb47dc3 {
max-height: 0;
overflow: hidden;
padding: 0 8px;
margin-top: 4px;
box-sizing: border-box;
border-radius: 8px;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25);
background: rgba(255, 255, 255, 0.93);
transition: max-height 300ms;
}
.role_menu_list.open.data-v-5fb47dc3 {
max-height: 400px;
}
.role_menu_item.data-v-5fb47dc3 {
margin-bottom: 8px;
display: flex;
justify-content: flex-start;
align-items: center;
font-size: 10px;
color: rgba(166, 166, 166, 1);
}
.role_menu_item.data-v-5fb47dc3:first-child {
margin-top: 8px;
}
.role_menu_item .avatar.data-v-5fb47dc3 {
display: block;
margin-right: 8px;
width: 36px;
height: 36px;
border-radius: 50%;
}
.avatar_empty.data-v-5fb47dc3 {
background-color: #ddd;
}
.role_menu_item text.data-v-5fb47dc3 {
height: 36px;
line-height: 36px;
}
.role_menu_item.active.data-v-5fb47dc3 {
color: #000000;
}
.ai_picker .add_icon.data-v-5fb47dc3 {
width: 20px;
height: 20px;
position: absolute;
right: 16px;
top: 50%;
transform: translateY(-50%);
}
.no-data.data-v-5fb47dc3 {
padding-top: 26vh;
}
.no-data image.data-v-5fb47dc3 {
display: block;
margin: 0 auto;
width: 70px;
height: 70px;
}
.no-data text.data-v-5fb47dc3 {
margin-top: 12px;
display: block;
font-size: 18px;
color: #999999;
text-align: center;
}
.scroll_wrapper.data-v-5fb47dc3 {
height: calc(100vh - 48px);
}
.list.data-v-5fb47dc3 {
display: flex;
flex-wrap: wrap;
padding: 8px;
box-sizing: border-box;
}
.list .item.data-v-5fb47dc3 {
overflow: hidden;
margin: 0 4px 6px;
padding-bottom: 10px;
width: calc(50% - 4px);
border-radius: 4px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.list .item.data-v-5fb47dc3:nth-child(odd) {
margin-left: 0;
}
.list .item.data-v-5fb47dc3:nth-child(even) {
margin-right: 0;
}
.list .item .cover.data-v-5fb47dc3 {
width: 100%;
height: 224px;
}
.list .item .content.data-v-5fb47dc3 {
margin-bottom: 10px;
display: flex;
align-items: center;
height: 34px;
padding: 0 6px;
box-sizing: border-box;
font-size: 12px;
}
.list .item .info.data-v-5fb47dc3 {
padding: 0 6px;
box-sizing: border-box;
display: flex;
justify-content: space-between;
align-items: center;
}
.info .user.data-v-5fb47dc3 {
flex-grow: 1;
display: flex;
align-items: center;
}
.info .user .avatar.data-v-5fb47dc3 {
display: block;
margin-right: 8px;
width: 20px;
height: 20px;
border-radius: 50%;
}
.info .user .name.data-v-5fb47dc3 {
display: inline-block;
max-width: 100px;
font-size: 12px;
color: #808080;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.info .count.data-v-5fb47dc3 {
flex-shrink: 0;
display: flex;
align-items: center;
font-size: 12px;
color: #808080;
}
.info .count .iconfont.data-v-5fb47dc3 {
margin-right: 4px;
}
.info .count .icon-like.data-v-5fb47dc3 {
color: rgba(243, 67, 98, 1);
}

139
pages/community/release.js Normal file
View File

@ -0,0 +1,139 @@
"use strict";
var common_vendor = require("../../common/vendor.js");
var tianjia = require("../../tianjia.js");
var config_index = require("../../config/index.js");
var api_index = require("../../api/index.js");
require("../../utils/request.js");
const _sfc_main = {
setup(__props) {
const rolesList = common_vendor.reactive([]);
const getRoleList = () => {
api_index.getAllRoles().then(({ status, data }) => {
if (Number(status) === 200 && Array.isArray(data)) {
rolesList.push(...data);
}
}).finally(getDraft);
};
const getDraft = () => {
api_index.getDraftData().then(({ status, data }) => {
if (Number(status) === 200) {
const { title: tit, content, role_ids } = (data == null ? void 0 : data.draft_info) || {};
const detail = typeof content === "string" ? JSON.parse(content) : {};
imageList.push(...detail.images);
title.value = tit;
text.value = detail.text;
const roles = rolesList.filter((role) => role_ids.includes(role.role_id));
relateRole.push(...roles);
}
});
};
common_vendor.onMounted(getRoleList);
const imageList = common_vendor.reactive([]);
const onUploadFile = () => {
common_vendor.index.chooseImage({
count: 1,
sizeType: ["original", "compressed"],
sourceType: ["album"],
success: ({ tempFilePaths, tempFiles }) => {
const [file] = tempFiles;
const size = file.size / 1024 / 1024;
if (size <= 1) {
api_index.uploadImage(file).then(({ status, data }) => {
if (Number(status) === 200 && data.file_id) {
imageList.push(data.file_id);
}
});
} else {
common_vendor.index.showToast({
title: "\u56FE\u7247\u5927\u5C0F\u4E0D\u80FD\u8D85\u8FC71MB",
icon: "none"
});
}
}
});
};
const title = common_vendor.ref("");
const text = common_vendor.ref("");
const relateRole = common_vendor.reactive([]);
const onChangeRole = (e) => {
const curIndex = e.detail.value;
const curSelectedRole = rolesList[curIndex];
const existenceRole = relateRole.find((item) => item.role_id === curSelectedRole.role_id);
if (!existenceRole) {
relateRole.push(curSelectedRole);
}
};
const onDeleteRole = (role) => {
const filterRoles = relateRole.filter((item) => item.role_id !== role.role_id);
relateRole.splice(0, relateRole.length);
relateRole.push(...filterRoles);
};
const onSubmit = async (type) => {
let errMessage = "";
if (imageList.length === 0) {
errMessage = "\u6700\u5C11\u4E0A\u4F20\u4E00\u5F20\u56FE\u7247";
} else if (title.value === "") {
errMessage = "\u8BF7\u586B\u5199\u6807\u9898";
} else if (text.value === "") {
errMessage = "\u8BF7\u586B\u5199\u5185\u5BB9";
} else if (relateRole.length === 0) {
errMessage = "\u8BF7\u9009\u62E9\u76F8\u5173\u89D2\u8272";
}
if (errMessage) {
common_vendor.index.showToast({
title: errMessage,
icon: "none"
});
} else {
const params = {
title: title.value,
role_ids: relateRole.map((role) => role.role_id),
content: JSON.stringify({
images: imageList,
text: text.value
})
};
const { status } = type === "release" ? await api_index.releaseContent(params) : await api_index.saveDraft(params);
if (Number(status) === 200) {
common_vendor.index.showToast({
title: "\u4FDD\u5B58\u6210\u529F",
icon: "none"
});
common_vendor.index.navigateBack();
}
}
};
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.f(common_vendor.unref(imageList), (item, k0, i0) => {
return {
a: `${common_vendor.unref(config_index.filePrefix)}${item}`,
b: item
};
}),
b: common_vendor.unref(imageList).length < 5
}, common_vendor.unref(imageList).length < 5 ? {
c: common_vendor.o(onUploadFile)
} : {}, {
d: title.value,
e: common_vendor.o(($event) => title.value = $event.detail.value),
f: text.value,
g: common_vendor.o(($event) => text.value = $event.detail.value),
h: common_vendor.f(common_vendor.unref(relateRole), (role, k0, i0) => {
return {
a: common_vendor.t(role.role_name),
b: common_vendor.o(($event) => onDeleteRole(role)),
c: role.role_id
};
}),
i: tianjia._imports_0,
j: common_vendor.unref(rolesList),
k: common_vendor.o(onChangeRole),
l: common_vendor.o(($event) => onSubmit("draft")),
m: common_vendor.o(($event) => onSubmit("release"))
});
};
}
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-40246838"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/community/release.vue"]]);
wx.createPage(MiniProgramPage);

View File

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "发布",
"usingComponents": {}
}

View File

@ -0,0 +1 @@
<view class="content data-v-40246838"><view class="picture_upload_list data-v-40246838"><view wx:for="{{a}}" wx:for-item="item" wx:key="b" class="image_wrapper data-v-40246838"><image src="{{item.a}}" mode="aspectFill" class="image data-v-40246838"></image></view><view wx:if="{{b}}" class="uploader data-v-40246838" bindtap="{{c}}"><text class="iconfont icon-shangchuantupian data-v-40246838"></text></view></view><view class="text_form data-v-40246838"><input class="title_input data-v-40246838" type="text" maxlength="20" placeholder="请输入标题..." value="{{d}}" bindinput="{{e}}"/><block wx:if="{{r0}}"><textarea class="content_input data-v-40246838" type="text" maxlength="200" placeholder="说些什么吧..." value="{{f}}" bindinput="{{g}}"/></block></view><view class="role_title data-v-40246838">相关角色</view><scroll-view scroll-x="true" class="role_wrapper data-v-40246838"><view class="role_list data-v-40246838"><view wx:for="{{h}}" wx:for-item="role" wx:key="c" class="role_item data-v-40246838">{{role.a}} <text class="iconfont icon-shanchu data-v-40246838" bindtap="{{role.b}}"></text></view><picker class="data-v-40246838" range="{{j}}" range-key="role_name" bindchange="{{k}}"><image src="{{i}}" class="add_icon data-v-40246838" mode=""></image></picker></view></scroll-view><view class="btn_wrapper data-v-40246838"><view class="left_btn data-v-40246838" bindtap="{{l}}"><text class="iconfont icon-caogaoxiang data-v-40246838"></text><text class="txt data-v-40246838">存草稿</text></view><button class="btn data-v-40246838" bindtap="{{m}}"><text class="iconfont icon-paperPlane data-v-40246838"></text><text class="data-v-40246838">发布帖子</text></button></view></view>

View File

@ -0,0 +1,154 @@
.content.data-v-40246838 {
padding: 16px;
box-sizing: border-box;
}
.picture_upload_list.data-v-40246838 {
display: flex;
flex-wrap: wrap;
margin: 0 -4px;
}
.image_wrapper.data-v-40246838 {
overflow: hidden;
margin: 4px;
width: calc(33.33% - 8px);
aspect-ratio: 1;
border-radius: 10px;
}
.image_wrapper .image.data-v-40246838 {
display: block;
width: 100%;
height: 100%;
}
.uploader.data-v-40246838 {
margin: 4px;
width: calc(33.33% - 8px);
aspect-ratio: 1;
background-color: rgba(245, 245, 247, 1);
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
}
.uploader .iconfont.data-v-40246838 {
font-size: 50px;
color: #a8a8a8;
}
.text_form.data-v-40246838 {
margin-top: 6px;
}
.title_input.data-v-40246838 {
padding: 12px 0;
border-bottom: 1px solid rgba(229, 229, 229, 1);
font-size: 18px;
color: #000000;
}
.title_input.data-v-40246838::-webkit-input-placeholder {
color: rgba(166, 166, 166, 1);
}
.title_input.data-v-40246838::placeholder {
color: rgba(166, 166, 166, 1);
}
.content_input.data-v-40246838 {
width: 100%;
height: 210px;
padding: 12px 0;
box-sizing: border-box;
font-size: 16px;
color: #000000;
border-bottom: 1px solid rgba(229, 229, 229, 1);
}
.content_input.data-v-40246838::-webkit-input-placeholder {
color: rgba(166, 166, 166, 1);
}
.content_input.data-v-40246838::placeholder {
color: rgba(166, 166, 166, 1);
}
.role_title.data-v-40246838 {
width: 100%;
height: 46px;
line-height: 46px;
font-size: 16px;
color: #000000;
border-bottom: 1px solid rgba(229, 229, 229, 1);
}
.role_wrapper.data-v-40246838 {
border-bottom: 1px solid rgba(229, 229, 229, 1);
}
.role_list.data-v-40246838 {
display: flex;
align-items: center;
flex-wrap: nowrap;
width: 100%;
height: 60px;
}
.role_item.data-v-40246838 {
flex-shrink: 0;
display: inline-block;
margin-right: 12px;
height: 30px;
padding: 0 20px;
border: 1px solid rgba(128, 128, 128, 1);
border-radius: 15px;
line-height: 30px;
text-align: center;
font-size: 16px;
color: rgba(128, 128, 128, 1);
}
.add_icon.data-v-40246838 {
display: block;
width: 24px;
height: 24px;
}
.btn_wrapper.data-v-40246838 {
position: fixed;
left: 0;
right: 0;
bottom: 0;
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
padding: 24px 20px;
box-sizing: border-box;
}
.left_btn.data-v-40246838 {
margin-right: 22px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.left_btn .iconfont.data-v-40246838 {
display: inline-block;
width: 24px;
height: 24px;
border-radius: 50%;
background-color: rgba(245, 245, 247, 1);
font-size: 14px;
text-align: center;
line-height: 24px;
color: #a8a8a8;
}
.left_btn .txt.data-v-40246838 {
margin-top: 4px;
font-size: 12px;
color: rgba(166, 166, 166, 1);
line-height: 12px;
}
.btn_wrapper .btn.data-v-40246838 {
position: relative;
flex-grow: 1;
height: 40px;
border-radius: 20px;
background: linear-gradient(270deg, rgba(255, 153, 71, 1) 0%, rgba(242, 52, 255, 1) 57.29%, rgba(243, 64, 125, 1) 83.14%, rgba(243, 67, 98, 1) 100%);
font-size: 16px;
line-height: 40px;
color: #fff;
}
.btn_wrapper .btn .iconfont.data-v-40246838 {
position: absolute;
left: 16px;
top: 50%;
transform: translateY(-50%);
}

32
pages/cover/index.js Normal file
View File

@ -0,0 +1,32 @@
"use strict";
var common_vendor = require("../../common/vendor.js");
const _sfc_main = {
setup(__props) {
setTimeout(() => {
common_vendor.index.getStorage({
key: "userData",
success: ({ data }) => {
if (data) {
common_vendor.index.switchTab({
url: "/pages/index/index"
});
} else {
common_vendor.index.redirectTo({
url: "/pages/login/index"
});
}
},
fail: () => {
common_vendor.index.redirectTo({
url: "/pages/login/index"
});
}
});
}, 800);
return (_ctx, _cache) => {
return {};
};
}
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-3a00e0de"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/cover/index.vue"]]);
wx.createPage(MiniProgramPage);

4
pages/cover/index.json Normal file
View File

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "",
"usingComponents": {}
}

1
pages/cover/index.wxml Normal file
View File

@ -0,0 +1 @@
<view class="content data-v-3a00e0de"><image src="https://img.js.design/assets/img/6617b26b68c6f7fe0271164f.png#a6220b7db04e8e12f68147b13848031e" mode="aspectFill" class="cover_image data-v-3a00e0de"></image></view>

11
pages/cover/index.wxss Normal file
View File

@ -0,0 +1,11 @@
.cover_image.data-v-3a00e0de {
position: absolute;
top: 160px;
left: 50%;
transform: translateX(-50%);
display: block;
width: 300px;
height: 300px;
}

185
pages/index/index.js Normal file
View File

@ -0,0 +1,185 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var common_vendor = require("../../common/vendor.js");
var kongshuju = require("../../kongshuju.js");
var api_index = require("../../api/index.js");
var config_index = require("../../config/index.js");
require("../../utils/request.js");
const _sfc_main = {
setup(__props) {
const finished = common_vendor.ref(false);
const list = common_vendor.reactive([]);
const bannerList = common_vendor.computed$1(() => list.slice(0, 3));
const getRoleList = () => {
api_index.getAllRoles().then(({ status, data }) => {
if (Number(status) === 200 && Array.isArray(data)) {
list.push(...data);
}
}).finally(() => {
finished.value = true;
});
};
common_vendor.onMounted(getRoleList);
const showDialog = common_vendor.ref(false);
const currentItem = common_vendor.ref({});
const onOpenRoleDialog = (item) => {
currentItem.value = item;
showDialog.value = true;
};
const isExistChat = (item) => {
api_index.getChatExist({
role_id: item.role_id
}).then(({ status, data }) => {
if (Number(status) === 200) {
if (data.exists) {
toChat(item);
} else {
onOpenRoleDialog(item);
}
} else {
onOpenRoleDialog(item);
}
}).catch(() => {
onOpenRoleDialog(item);
});
};
const toCall = async (item) => {
try {
const { user_info } = common_vendor.index.getStorageSync("userData");
const { user_id } = user_info || {};
if (user_id) {
const { status, data } = await api_index.createChat({
user_id,
character_id: item.role_id
});
if (status === "success") {
common_vendor.index.setStorage({
key: "chatInfo",
data: __spreadValues({
userId: user_id,
session_id: data.session_id
}, item),
success: () => {
common_vendor.index.navigateTo({
url: "/pages/call/index"
});
}
});
} else {
common_vendor.index.showToast({
title: "\u521B\u5EFA\u804A\u5929\u5931\u8D25"
});
}
} else {
common_vendor.index.showToast({
title: "\u5F53\u524D\u767B\u5F55\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",
icon: "none"
});
common_vendor.index.clearStorage();
common_vendor.index.navigateTo({
url: "/pages/login/index"
});
}
} catch (e) {
throw new Error(e);
}
};
const toChat = async (item) => {
try {
const { user_info } = common_vendor.index.getStorageSync("userData");
const { user_id } = user_info || {};
if (user_id) {
const { status, data } = await api_index.createChat({
user_id,
character_id: item.role_id
});
if (status === "success") {
common_vendor.index.setStorage({
key: "chatInfo",
data: __spreadValues({
userId: user_id,
session_id: data.session_id
}, item),
success: () => {
common_vendor.index.navigateTo({
url: "/pages/chatOnline/index"
});
}
});
} else {
common_vendor.index.showToast({
title: "\u521B\u5EFA\u804A\u5929\u5931\u8D25"
});
}
} else {
common_vendor.index.showToast({
title: "\u5F53\u524D\u767B\u5F55\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",
icon: "none"
});
common_vendor.index.clearStorage();
common_vendor.index.navigateTo({
url: "/pages/login/index"
});
}
} catch (e) {
throw new Error(e);
}
};
return (_ctx, _cache) => {
return common_vendor.e({
a: finished.value && common_vendor.unref(list).length === 0
}, finished.value && common_vendor.unref(list).length === 0 ? {
b: kongshuju._imports_1
} : {}, {
c: finished.value && common_vendor.unref(bannerList).length > 0
}, finished.value && common_vendor.unref(bannerList).length > 0 ? {
d: common_vendor.f(common_vendor.unref(bannerList), (item, index, i0) => {
return {
a: common_vendor.o(($event) => onOpenRoleDialog(item)),
b: `${common_vendor.unref(config_index.filePrefix)}${item.avatar_id}`,
c: index
};
})
} : {}, {
e: finished.value && common_vendor.unref(list).length > 0
}, finished.value && common_vendor.unref(list).length > 0 ? {} : {}, {
f: common_vendor.f(common_vendor.unref(list), (item, index, i0) => {
return {
a: `${common_vendor.unref(config_index.filePrefix)}${item.avatar_id}`,
b: common_vendor.t(item.role_name),
c: common_vendor.t(item.world_scenario),
d: index,
e: common_vendor.o(($event) => isExistChat(item))
};
}),
g: showDialog.value
}, showDialog.value ? {
h: `${common_vendor.unref(config_index.filePrefix)}${currentItem.value.avatar_id}`,
i: common_vendor.t(currentItem.value.role_name),
j: common_vendor.t(currentItem.value.description),
k: common_vendor.o(($event) => toCall(currentItem.value)),
l: common_vendor.o(($event) => toChat(currentItem.value)),
m: common_vendor.o(() => {
}),
n: common_vendor.o(($event) => showDialog.value = false)
} : {});
};
}
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-57280228"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/index/index.vue"]]);
wx.createPage(MiniProgramPage);

4
pages/index/index.json Normal file
View File

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "首页",
"usingComponents": {}
}

1
pages/index/index.wxml Normal file
View File

@ -0,0 +1 @@
<view class="content data-v-57280228"><view wx:if="{{a}}" class="no-data data-v-57280228"><image class="data-v-57280228" src="{{b}}" mode="aspectFill"></image><text class="data-v-57280228">暂无数据</text></view><swiper wx:if="{{c}}" class="data-v-57280228" indicator-dots="{{false}}" autoplay="{{true}}" interval="{{5000}}" duration="{{1000}}"><swiper-item wx:for="{{d}}" wx:for-item="item" wx:key="c" class="data-v-57280228"><view class="banner_wrapper data-v-57280228"><view class="pointer data-v-57280228"><text class="iconfont icon-dianji data-v-57280228"></text><text class="data-v-57280228" bindtap="{{item.a}}">点击进入</text></view><image src="{{item.b}}" class="banner_item data-v-57280228" mode="aspectFill"></image></view></swiper-item></swiper><text wx:if="{{e}}" class="title data-v-57280228">我的萌主</text><view class="list data-v-57280228"><view wx:for="{{f}}" wx:for-item="item" wx:key="d" bindtap="{{item.e}}" class="item data-v-57280228"><image src="{{item.a}}" mode="aspectFill" class="cover data-v-57280228"></image><text class="item_title data-v-57280228">{{item.b}}</text><text class="item_desc data-v-57280228">类型:{{item.c}}</text></view></view><view wx:if="{{g}}" bindtap="{{n}}" class="mask data-v-57280228"><view class="dialog data-v-57280228" catchtap="{{m}}"><image src="{{h}}" mode="aspectFill" class="cover data-v-57280228" type="image"></image><view class="title data-v-57280228">{{i}}</view><view class="desc data-v-57280228"><text class="desc_text data-v-57280228">{{j}}</text></view><button class="btn tel data-v-57280228" bindtap="{{k}}"><text class="iconfont icon-weibiaoti-- data-v-57280228"></text> 与萌主打电话 </button><button class="btn msg data-v-57280228" bindtap="{{l}}"><text class="iconfont icon-zhuanliaotian data-v-57280228"></text> 与萌主聊聊 </button></view></view></view>

175
pages/index/index.wxss Normal file
View File

@ -0,0 +1,175 @@
swiper.data-v-57280228 {
height: 300px !important;
}
.no-data.data-v-57280228 {
padding-top: 26vh;
}
.no-data image.data-v-57280228 {
display: block;
margin: 0 auto;
width: 70px;
height: 70px;
}
.no-data text.data-v-57280228 {
margin-top: 12px;
display: block;
font-size: 18px;
color: #999999;
text-align: center;
}
.banner_wrapper.data-v-57280228 {
position: relative;
}
.pointer.data-v-57280228 {
position: absolute;
left: 12px;
bottom: 18px;
display: flex;
align-items: center;
padding: 0 16px;
box-sizing: border-box;
width: 200px;
height: 34px;
border-radius: 17px;
background: linear-gradient(90deg, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%);
}
.pointer text.data-v-57280228 {
font-size: 12px;
font-weight: bold;
fill: transparent;
background-image: linear-gradient(90deg, rgba(242, 52, 255, 1), rgba(34, 8, 228, 1), rgba(51, 204, 255, 1));
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
}
.pointer .iconfont.data-v-57280228 {
margin-right: 8px;
font-size: 24px;
transform: rotate(90deg);
}
.banner_item.data-v-57280228 {
display: block;
width: 100%;
height: 300px;
}
.title.data-v-57280228 {
padding: 0 26px;
font-size: 24px;
color: #000000;
font-weight: 700;
line-height: 66px;
}
.list.data-v-57280228 {
padding: 0 8px;
box-sizing: border-box;
display: flex;
flex-wrap: wrap;
}
.item.data-v-57280228 {
overflow: hidden;
width: calc(50% - 16px);
margin: 0 8px 16px;
height: 240px;
flex-shrink: 0;
border-radius: 20px;
box-sizing: border-box;
background: rgba(229, 229, 229, 0.25);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.item .cover.data-v-57280228 {
width: 100%;
height: 190px;
}
.item .item_title.data-v-57280228 {
display: block;
padding: 0 12px;
font-size: 12px;
color: rgba(56, 56, 56, 1);
line-height: 18px;
font-weight: 700;
}
.item .item_desc.data-v-57280228 {
padding: 0 12px;
font-size: 10px;
color: rgba(166, 166, 166, 1);
line-height: 16px;
}
.mask.data-v-57280228 {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
height: 100vh;
background: rgba(0, 0, 0, 0.5);
}
.mask .dialog.data-v-57280228 {
margin: 100px auto 0;
width: calc(100% - 40px);
min-height: calc(100vh - 200px);
background: #fff;
border-radius: 36px;
padding: 18px 20px;
box-sizing: border-box;
}
.dialog .cover.data-v-57280228 {
width: 100%;
height: 230px;
border-radius: 25px;
}
.dialog .title.data-v-57280228 {
text-align: center;
line-height: 56px;
font-size: 24px;
color: #000000;
font-weight: bold;
}
.dialog .desc.data-v-57280228 {
height: 80px;
margin-bottom: 30px;
display: -webkit-box;
font-size: 12px;
padding: 14px 20px;
box-sizing: border-box;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25);
border-radius: 30px;
overflow: hidden;
text-overflow: ellipsis;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
.desc_text.data-v-57280228 {
text-align: justify;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
text-overflow: ellipsis;
}
.dialog .btn.data-v-57280228 {
position: relative;
margin-bottom: 12px;
height: 40px;
border-radius: 20px;
font-size: 16px;
border: none;
outline: none;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25);
}
.dialog .btn .iconfont.data-v-57280228 {
position: absolute;
left: 18px;
top: 50%;
transform: translateY(-50%);
font-size: 20px;
}
.dialog .tel.data-v-57280228 {
background: linear-gradient(270deg, rgba(255, 153, 71, 1) 0%, rgba(242, 52, 255, 1) 57.29%, rgba(243, 64, 125, 1) 83.14%, rgba(243, 67, 98, 1) 100%);
color: #fff;
}
.dialog .msg.data-v-57280228 {
background: rgba(204, 230, 255, 1);
color: rgba(52, 152, 255, 1);
}

54
pages/login/index.js Normal file
View File

@ -0,0 +1,54 @@
"use strict";
var common_vendor = require("../../common/vendor.js");
var api_index = require("../../api/index.js");
require("../../utils/request.js");
require("../../config/index.js");
const _sfc_main = {
setup(__props) {
common_vendor.index.hideHomeButton();
const agree = common_vendor.ref(false);
const showDialog = common_vendor.ref(false);
const loginByWechat = () => {
if (!agree.value) {
common_vendor.index.showToast({
title: "\u8BF7\u5148\u9605\u8BFB\u5E76\u540C\u610F\u534F\u8BAE",
icon: "none"
});
return;
}
wx.login({
success: async ({ code }) => {
try {
const { status, data } = await api_index.login({ code });
if (Number(status) === 200) {
common_vendor.index.setStorage({
key: "userData",
data,
success: () => {
common_vendor.index.switchTab({
url: "/pages/index/index"
});
}
});
}
} catch (e) {
}
}
});
};
return (_ctx, _cache) => {
return {
a: common_vendor.o(loginByWechat),
b: common_vendor.n(agree.value ? "radio iconfont icon-gou" : "radio"),
c: common_vendor.o(($event) => showDialog.value = true),
d: common_vendor.o(($event) => agree.value = !agree.value),
e: common_vendor.o(() => {
}),
f: showDialog.value,
g: common_vendor.o(($event) => showDialog.value = false)
};
};
}
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4586967a"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/login/index.vue"]]);
wx.createPage(MiniProgramPage);

4
pages/login/index.json Normal file
View File

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "登录",
"usingComponents": {}
}

1
pages/login/index.wxml Normal file
View File

@ -0,0 +1 @@
<view class="content data-v-4586967a"><image src="https://img.js.design/assets/img/6617b26b68c6f7fe0271164f.png#a6220b7db04e8e12f68147b13848031e" class="cover_image data-v-4586967a" mode=""></image><view class="login_box data-v-4586967a"><button class="wechat data-v-4586967a" bindtap="{{a}}">微信快捷登录</button></view><view class="bottom_tip data-v-4586967a" bindtap="{{d}}"><view class="{{['data-v-4586967a', b]}}"></view> 我已阅读并同意<text class="data-v-4586967a" catchtap="{{c}}">《用户服务协议及隐私政策》</text></view><view hidden="{{!f}}" bindtap="{{g}}" class="mask data-v-4586967a"><view catchtap="{{e}}" class="dialog data-v-4586967a"><text class="dialog_title data-v-4586967a">隐私协议</text><view class="content_scroll_wrapper data-v-4586967a"></view></view></view></view>

154
pages/login/index.wxss Normal file
View File

@ -0,0 +1,154 @@
.cover_image.data-v-4586967a {
margin: 12px auto;
display: block;
width: 274px;
height: 274px;
}
.login_box.data-v-4586967a {
padding: 0 56px;
box-sizing: border-box;
}
.login_box button.data-v-4586967a {
margin-bottom: 24px;
display: block;
height: 48px;
border: none !important;
outline: none;
border-radius: 24px;
font-size: 14px;
line-height: 48px;
}
.login_box .wechat.data-v-4586967a {
background: linear-gradient(270deg, rgba(255, 153, 71, 1) 0%, rgba(242, 52, 255, 1) 57.29%, rgba(243, 64, 125, 1) 83.14%, rgba(243, 67, 98, 1) 100%);
color: #fff;
}
.login_box .phone.data-v-4586967a {
background: rgba(204, 230, 255, 1);
color: rgba(52, 152, 255, 1);
}
.bottom_tip.data-v-4586967a {
display: flex;
justify-content: center;
align-items: center;
position: fixed;
bottom: 70px;
width: 100%;
text-align: center;
font-size: 10px;
color: rgba(153, 153, 153, 1);
}
.bottom_tip text.data-v-4586967a {
color: rgba(52, 152, 255, 1);
}
.bottom_tip .radio.data-v-4586967a {
position: relative;
margin-right: 4px;
display: inline-block;
width: 16px;
height: 16px;
box-sizing: border-box;
border: 1px solid #3498FF;
border-radius: 50%;
font-size: 16px;
text-align: center;
line-height: 16px;
color: #3498FF;
}
.login_form.data-v-4586967a {
padding: 0 40px;
box-sizing: border-box;
}
.login_form .title.data-v-4586967a {
margin-top: 20px;
margin-bottom: 40px;
font-size: 32px;
line-height: 46px;
font-weight: 500;
color: #000;
}
.login_form input.data-v-4586967a {
height: 34px;
flex-grow: 1;
}
.login_form .form_item.data-v-4586967a {
margin-bottom: 40px;
display: flex;
justify-content: space-between;
align-items: center;
position: relative;
border-bottom: 1px solid #999999;
}
.login_form .form_item text.data-v-4586967a {
margin-right: 10px;
}
.login_form .form_item .send_code.data-v-4586967a {
height: 34px;
padding: 0;
line-height: 34px;
border: none;
outline: none;
background-color: #fff;
font-size: 14px;
color: #000;
}
.login_form .submit_item.data-v-4586967a {
margin-top: 128px;
padding: 0 18px;
box-sizing: border-box;
}
.login_form .submit_item button.data-v-4586967a {
font-size: 14px;
color: #fff;
height: 48px;
line-height: 48px;
border-radius: 24px;
background: linear-gradient(90deg, rgba(255, 153, 71, 1) 0%, rgba(242, 52, 255, 1) 25.19%, rgba(34, 8, 228, 1) 79.99%, rgba(51, 204, 255, 1) 100%);
}
.wechat_login_btn.data-v-4586967a {
position: relative;
margin: 180px auto 0;
width: 55px;
height: 55px;
border-radius: 50%;
background: #CCE6FF;
}
.wechat_login_btn text.data-v-4586967a {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 34px;
text-align: center;
line-height: 55px !important;
color: #3498FF;
}
.mask.data-v-4586967a {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
height: 100vh;
background: rgba(0, 0, 0, 0.5);
}
.mask .dialog.data-v-4586967a {
margin: 100px auto 0;
width: calc(100% - 40px);
min-height: calc(100vh - 200px);
background: #fff;
border-radius: 36px;
padding: 0 20px 18px;
box-sizing: border-box;
}
.dialog_title.data-v-4586967a {
display: block;
height: 60px;
line-height: 60px;
text-align: center;
}
.content_scroll_wrapper.data-v-4586967a {
height: calc(100% - 78px);
overflow-y: scroll;
}

8
pages/mine/aboutus.js Normal file
View File

@ -0,0 +1,8 @@
"use strict";
var common_vendor = require("../../common/vendor.js");
const _sfc_main = {};
function _sfc_render(_ctx, _cache) {
return {};
}
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-17ffc6a8"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/mine/aboutus.vue"]]);
wx.createPage(MiniProgramPage);

4
pages/mine/aboutus.json Normal file
View File

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "关于我们",
"usingComponents": {}
}

1
pages/mine/aboutus.wxml Normal file
View File

@ -0,0 +1 @@
<view class="about_us_content data-v-17ffc6a8"><view class="title data-v-17ffc6a8"><image src="https://img.js.design/assets/img/6617b26b68c6f7fe0271164f.png#a6220b7db04e8e12f68147b13848031e" mode="aspectFill" class="logo data-v-17ffc6a8"></image><text class="data-v-17ffc6a8">关于我们</text></view><text class="sub_title data-v-17ffc6a8">你好呀,话话糖在此!</text><text class="text_content data-v-17ffc6a8">我们是一个年轻的AI初创团队主要成员来自中科大、北大、上交、复旦、央美。我们希望用前沿的科技和有品质的内容给你更“破壁”的多维情感交互体验。</text><text class="text_content data-v-17ffc6a8">就像你已经体验到的一样我们基于AI的记忆、理解与共情能力为玩具实体和IP/原创角色注入数字生命,致力于实现有温度、有思考、有成长的交互,我们相信这是有趣且有意义的。</text><text class="end_text data-v-17ffc6a8">希望话话糖能让你有话可聊,有糖可嚼!</text></view>

35
pages/mine/aboutus.wxss Normal file
View File

@ -0,0 +1,35 @@
.about_us_content.data-v-17ffc6a8 {
padding: 40px 36px;
box-sizing: border-box;
}
.title.data-v-17ffc6a8 {
margin-bottom: 46px;
display: flex;
align-items: center;
}
.title image.data-v-17ffc6a8 {
margin-right: 16px;
display: block;
width: 40px;
height: 40px;
border-radius: 50%;
}
.title text.data-v-17ffc6a8 {
font-size: 18px;
color: #000000;
font-weight: 700;
}
.sub_title.data-v-17ffc6a8 {
margin-bottom: 30px;
display: block;
font-size: 16px;
color: #000000;
font-weight: 700;
}
.text_content.data-v-17ffc6a8 {
line-height: 24px;
text-align: justify;
display: block;
margin-bottom: 30px;
}

8
pages/mine/contactus.js Normal file
View File

@ -0,0 +1,8 @@
"use strict";
var common_vendor = require("../../common/vendor.js");
const _sfc_main = {};
function _sfc_render(_ctx, _cache) {
return {};
}
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2de0b7bb"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/mine/contactus.vue"]]);
wx.createPage(MiniProgramPage);

View File

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "联系我们",
"usingComponents": {}
}

View File

@ -0,0 +1 @@
<view class="content data-v-2de0b7bb"><image class="data-v-2de0b7bb" src="https://img.js.design/assets/img/662f19d044e67bd737a9d9f1.jpg#1d1b8ef2aac1be7b87bd7aa8a08b886f" mode="aspectFill"></image><button class="contact_btn data-v-2de0b7bb"><text class="iconfont icon-email-s data-v-2de0b7bb"></text> contactus@takway.ai </button></view>

25
pages/mine/contactus.wxss Normal file
View File

@ -0,0 +1,25 @@
.content image.data-v-2de0b7bb {
display: block;
margin: 0 auto;
height: 600px;
}
.contact_btn.data-v-2de0b7bb {
position: relative;
margin: 0 auto 0;
width: 274px;
height: 48px;
line-height: 48px;
font-size: 16px;
color: #fff;
border-radius: 24px;
background: linear-gradient(90deg, rgba(255, 153, 71, 1) 0%, rgba(242, 52, 255, 1) 25.19%, rgba(34, 8, 228, 1) 79.99%, rgba(51, 204, 255, 1) 100%);
}
.contact_btn .iconfont.data-v-2de0b7bb {
position: absolute;
left: 18px;
top: 50%;
transform: translateY(-50%);
font-size: 24px;
color: #fff;
}

141
pages/mine/index.js Normal file
View File

@ -0,0 +1,141 @@
"use strict";
var common_vendor = require("../../common/vendor.js");
var config_index = require("../../config/index.js");
var api_index = require("../../api/index.js");
require("../../utils/request.js");
const _sfc_main = {
setup(__props) {
const userInfo = common_vendor.reactive({
avatar: "",
userName: ""
});
const showDialog = common_vendor.ref(false);
const getUserInfo = () => {
common_vendor.index.getStorage({
key: "userData",
success: ({ data }) => {
const { avatar_id, username } = data.user_info || {};
userInfo.avatar = avatar_id || config_index.defaultAvatar;
userInfo.userName = username || "\u5FAE\u4FE1\u7528\u6237";
}
});
};
common_vendor.onShow(getUserInfo);
const updateUserInfo = (user_info) => {
const { token } = common_vendor.index.getStorageSync("userData");
common_vendor.index.setStorage({
key: "userData",
data: {
token,
user_info
},
success: getUserInfo
});
};
const onChangeAvatar = () => {
common_vendor.index.chooseImage({
count: 1,
sizeType: ["original", "compressed"],
sourceType: ["album"],
success: ({ tempFilePaths, tempFiles }) => {
const [file] = tempFiles;
const size = file.size / 1024 / 1024;
if (size <= 1) {
api_index.uploadImage(file).then(async ({ data }) => {
var _a;
try {
if (data.file_id) {
const res = await api_index.saveAvatar({ avatar_id: data.file_id });
if (Number(res.status) === 200) {
const user_info = ((_a = res.data) == null ? void 0 : _a.user_info) || {};
updateUserInfo(user_info);
}
}
} catch (e) {
throw new Error(e);
}
}).catch(() => {
common_vendor.index.showToast({
title: "\u4E0A\u4F20\u56FE\u7247\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",
icon: "none"
});
});
} else {
common_vendor.index.showToast({
title: "\u56FE\u7247\u5927\u5C0F\u4E0D\u80FD\u8D85\u8FC71MB",
icon: "none"
});
}
}
});
};
const showEditNameDialog = common_vendor.ref(false);
const userName = common_vendor.ref("");
const onSaveUserName = () => {
if (userName.value) {
api_index.saveUserName({ username: userName.value }).then(({ status, data }) => {
if (Number(status) === 200) {
const user_info = data.user_info || {};
updateUserInfo(user_info);
}
}).catch(() => {
common_vendor.index.showToast({
title: "\u4FEE\u6539\u6635\u79F0\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",
icon: "none"
});
}).finally(() => {
showEditNameDialog.value = false;
userName.value = "";
});
} else {
common_vendor.index.showToast({
title: "\u8BF7\u8F93\u5165\u6635\u79F0",
icon: "none"
});
}
};
const toyNetwork = () => {
common_vendor.index.navigateTo({
url: "/pages/bluetooth/index"
});
};
const onSubMenu = (type) => {
if (type === "protocol") {
showDialog.value = true;
} else if (type === "aboutus") {
common_vendor.index.navigateTo({
url: "/pages/mine/aboutus"
});
} else {
common_vendor.index.navigateTo({
url: "/pages/mine/contactus"
});
}
};
return (_ctx, _cache) => {
return {
a: `${common_vendor.unref(config_index.filePrefix)}${common_vendor.unref(userInfo).avatar}`,
b: common_vendor.o(onChangeAvatar),
c: common_vendor.t(common_vendor.unref(userInfo).userName),
d: common_vendor.o(($event) => showEditNameDialog.value = true),
e: common_vendor.o(($event) => onSubMenu("aboutus")),
f: common_vendor.o(toyNetwork),
g: common_vendor.o(($event) => onSubMenu("contactus")),
h: common_vendor.o(($event) => onSubMenu("protocol")),
i: common_vendor.o(() => {
}),
j: showDialog.value,
k: common_vendor.o(($event) => showDialog.value = false),
l: userName.value,
m: common_vendor.o(($event) => userName.value = $event.detail.value),
n: common_vendor.o(onSaveUserName),
o: common_vendor.o(() => {
}),
p: showEditNameDialog.value,
q: common_vendor.o(($event) => showEditNameDialog.value = false)
};
};
}
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4bd6864f"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/mine/index.vue"]]);
wx.createPage(MiniProgramPage);

4
pages/mine/index.json Normal file
View File

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "我的",
"usingComponents": {}
}

1
pages/mine/index.wxml Normal file
View File

@ -0,0 +1 @@
<view class="content data-v-4bd6864f"><view class="user_top_wrapper data-v-4bd6864f"><image src="/static/image/mine_bg.png" alt="" class="bg data-v-4bd6864f"/><view class="user_avatar_wrapper data-v-4bd6864f"><image src="{{a}}" bindtap="{{b}}" class="avatar data-v-4bd6864f" mode="aspectFill"></image></view></view><view bindtap="{{d}}" class="user_name data-v-4bd6864f">{{c}}</view><view class="user_menu data-v-4bd6864f"><view class="menu_item data-v-4bd6864f" bindtap="{{e}}"><view class="icon_wrapper data-v-4bd6864f"><text class="iconfont icon-yonghu1 data-v-4bd6864f"></text></view> 关于我们 </view><view class="menu_item data-v-4bd6864f" bindtap="{{f}}"><view class="icon_wrapper data-v-4bd6864f"><text class="iconfont icon-wifi data-v-4bd6864f"></text></view> 玩具配网 </view><view class="menu_item data-v-4bd6864f" bindtap="{{g}}"><view class="icon_wrapper data-v-4bd6864f"><text class="iconfont icon-qun data-v-4bd6864f"></text></view> 加入用户群/反馈bug </view><view class="menu_item data-v-4bd6864f" bindtap="{{h}}"><view class="icon_wrapper data-v-4bd6864f"><text class="iconfont icon-yijianfankui data-v-4bd6864f"></text></view> 隐私协议 </view></view><view hidden="{{!j}}" bindtap="{{k}}" class="mask data-v-4bd6864f"><view catchtap="{{i}}" class="dialog data-v-4bd6864f"><text class="dialog_title data-v-4bd6864f">隐私协议</text><view class="content_scroll_wrapper data-v-4bd6864f"></view></view></view><view hidden="{{!p}}" bindtap="{{q}}" class="mask data-v-4bd6864f"><view catchtap="{{o}}" class="dialog edit_dialog data-v-4bd6864f"><text class="dialog_title data-v-4bd6864f">修改昵称</text><view class="username_input data-v-4bd6864f"><input class="data-v-4bd6864f" type="text" maxlength="10" value="{{l}}" bindinput="{{m}}"/></view><view class="btn_wrapper data-v-4bd6864f"><button bindtap="{{n}}" class="submit_btn data-v-4bd6864f">确定</button></view></view></view></view>

129
pages/mine/index.wxss Normal file
View File

@ -0,0 +1,129 @@
.user_top_wrapper.data-v-4bd6864f {
margin-bottom: 54px;
padding: 0 10px;
position: relative;
box-sizing: border-box;
}
.bg.data-v-4bd6864f {
display: block;
width: 100%;
height: 200px;
border-radius: 40px;
}
.user_avatar_wrapper.data-v-4bd6864f {
position: absolute;
left: 50%;
transform: translateX(-50%);
bottom: -38px;
width: 140px;
height: 140px;
border-radius: 50%;
background-color: #fff;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}
.user_avatar_wrapper .avatar.data-v-4bd6864f {
display: block;
width: 140px;
height: 140px;
border-radius: 50%;
}
.user_name.data-v-4bd6864f {
width: 100%;
font-size: 16px;
line-height: 36px;
text-align: center;
color: rgba(166, 166, 166, 1);
}
.user_menu.data-v-4bd6864f {
margin-top: 20px;
padding: 0 24px;
box-sizing: border-box;
}
.menu_item.data-v-4bd6864f {
position: relative;
margin-bottom: 20px;
width: 100%;
height: 60px;
border-radius: 24px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
font-size: 16px;
font-weight: 600;
color: #000000;
text-align: center;
line-height: 60px;
}
.icon_wrapper.data-v-4bd6864f {
position: absolute;
width: 50px;
height: 50px;
border-radius: 50%;
background-color: rgba(245, 245, 247, 1);
left: 8px;
top: 50%;
transform: translateY(-50%);
}
.icon_wrapper .iconfont.data-v-4bd6864f {
font-size: 24px !important;
text-align: center;
line-height: 50px;
}
.mask.data-v-4bd6864f {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
height: 100vh;
background: rgba(0, 0, 0, 0.5);
}
.mask .dialog.data-v-4bd6864f {
margin: 100px auto 0;
width: calc(100% - 40px);
min-height: calc(100vh - 200px);
background: #fff;
border-radius: 36px;
padding: 0 20px 18px;
box-sizing: border-box;
}
.dialog_title.data-v-4bd6864f {
display: block;
height: 60px;
line-height: 60px;
text-align: center;
}
.content_scroll_wrapper.data-v-4bd6864f {
height: calc(100% - 78px);
overflow-y: scroll;
}
.mask .edit_dialog.data-v-4bd6864f {
margin: 220px auto 0;
height: 220px;
min-height: auto;
}
.username_input.data-v-4bd6864f {
padding: 20px;
box-sizing: border-box;
}
.username_input input.data-v-4bd6864f {
padding: 0 12px;
box-sizing: border-box;
font-size: 16px;
border-radius: 5px;
width: 100%;
height: 48px;
background: rgba(235, 235, 235, 0.53);
}
.btn_wrapper.data-v-4bd6864f {
padding: 0 40px;
box-sizing: border-box;
}
.btn_wrapper .submit_btn.data-v-4bd6864f {
width: 100%;
height: 48px;
border-radius: 24px;
color: #fff;
background: linear-gradient(270deg, rgba(255, 153, 71, 1) 0%, rgba(242, 52, 255, 1) 57.29%, rgba(243, 64, 125, 1) 83.14%, rgba(243, 67, 98, 1) 100%);
}

29
project.config.json Normal file
View File

@ -0,0 +1,29 @@
{
"appid": "wxae661fd0f9edd7da",
"compileType": "miniprogram",
"libVersion": "3.4.4",
"packOptions": {
"ignore": [],
"include": []
},
"setting": {
"coverView": true,
"es6": true,
"postcss": true,
"minified": true,
"enhance": true,
"showShadowRootInWxmlPanel": true,
"packNpmRelationList": [],
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
}
},
"condition": {},
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
},
"projectname": "1716042249597"
}

View File

@ -0,0 +1,4 @@
{
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"libVersion": "3.4.3"
}

BIN
static/icon/chat.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
static/icon/chat_active.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
static/icon/community.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
static/icon/guadianhua.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
static/icon/mine.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
static/icon/mine_active.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
static/icon/tianjia.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
static/icon/ufo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
static/icon/ufo_active.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
static/icon/yangshengqi.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

@ -0,0 +1,115 @@
@font-face {
font-family: "iconfont"; /* Project id 4506234 */
src: url('iconfont.woff2?t=1714395057846') format('woff2'),
url('iconfont.woff?t=1714395057846') format('woff'),
url('iconfont.ttf?t=1714395057846') format('truetype');
}
.iconfont {
font-family: "iconfont" !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-email-s:before {
content: "\e65e";
}
.icon-xia:before {
content: "\e651";
}
.icon-jia:before {
content: "\e623";
}
.icon-loading:before {
content: "\e60c";
}
.icon-goToSelect:before {
content: "\e60b";
}
.icon-wifi1:before {
content: "\e609";
}
.icon-lock:before {
content: "\e60a";
}
.icon-like:before {
content: "\e85c";
}
.icon-aixin:before {
content: "\e83f";
}
.icon-shanchu:before {
content: "\e66d";
}
.icon-caogaoxiang:before {
content: "\e650";
}
.icon-shangchuantupian:before {
content: "\e615";
}
.icon-zhuanliaotian:before {
content: "\e606";
}
.icon-yangshengqi:before {
content: "\e608";
}
.icon-guadianhua:before {
content: "\e605";
}
.icon-dianji:before {
content: "\e87c";
}
.icon-weibiaoti--:before {
content: "\e611";
}
.icon-paperPlane:before {
content: "\e6c1";
}
.icon-search:before {
content: "\e6c8";
}
.icon-weixin:before {
content: "\e614";
}
.icon-gou:before {
content: "\e610";
}
.icon-yonghu1:before {
content: "\e607";
}
.icon-yijianfankui:before {
content: "\e662";
}
.icon-wifi:before {
content: "\e7e0";
}
.icon-qun:before {
content: "\e64f";
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,184 @@
{
"id": "4506234",
"name": "chat",
"font_family": "iconfont",
"css_prefix_text": "icon-",
"description": "",
"glyphs": [
{
"icon_id": "6267698",
"name": "邮件-实色",
"font_class": "email-s",
"unicode": "e65e",
"unicode_decimal": 58974
},
{
"icon_id": "1168117",
"name": "下",
"font_class": "xia",
"unicode": "e651",
"unicode_decimal": 58961
},
{
"icon_id": "446687",
"name": "加",
"font_class": "jia",
"unicode": "e623",
"unicode_decimal": 58915
},
{
"icon_id": "40149403",
"name": "loading",
"font_class": "loading",
"unicode": "e60c",
"unicode_decimal": 58892
},
{
"icon_id": "40144108",
"name": "goToSelect",
"font_class": "goToSelect",
"unicode": "e60b",
"unicode_decimal": 58891
},
{
"icon_id": "40136504",
"name": "wifi",
"font_class": "wifi1",
"unicode": "e609",
"unicode_decimal": 58889
},
{
"icon_id": "40136505",
"name": "lock",
"font_class": "lock",
"unicode": "e60a",
"unicode_decimal": 58890
},
{
"icon_id": "8288959",
"name": "爱心",
"font_class": "like",
"unicode": "e85c",
"unicode_decimal": 59484
},
{
"icon_id": "8288820",
"name": "爱心",
"font_class": "aixin",
"unicode": "e83f",
"unicode_decimal": 59455
},
{
"icon_id": "4431967",
"name": "删除",
"font_class": "shanchu",
"unicode": "e66d",
"unicode_decimal": 58989
},
{
"icon_id": "4784078",
"name": "草稿箱",
"font_class": "caogaoxiang",
"unicode": "e650",
"unicode_decimal": 58960
},
{
"icon_id": "19494233",
"name": "上传图片",
"font_class": "shangchuantupian",
"unicode": "e615",
"unicode_decimal": 58901
},
{
"icon_id": "40074449",
"name": "zhuanliaotian",
"font_class": "zhuanliaotian",
"unicode": "e606",
"unicode_decimal": 58886
},
{
"icon_id": "40074448",
"name": "yangshengqi",
"font_class": "yangshengqi",
"unicode": "e608",
"unicode_decimal": 58888
},
{
"icon_id": "40074450",
"name": "guadianhua",
"font_class": "guadianhua",
"unicode": "e605",
"unicode_decimal": 58885
},
{
"icon_id": "9646451",
"name": "点击2",
"font_class": "dianji",
"unicode": "e87c",
"unicode_decimal": 59516
},
{
"icon_id": "6399658",
"name": "电话呼叫",
"font_class": "weibiaoti--",
"unicode": "e611",
"unicode_decimal": 58897
},
{
"icon_id": "30044909",
"name": "纸飞机",
"font_class": "paperPlane",
"unicode": "e6c1",
"unicode_decimal": 59073
},
{
"icon_id": "887935",
"name": "search",
"font_class": "search",
"unicode": "e6c8",
"unicode_decimal": 59080
},
{
"icon_id": "6366912",
"name": "微信",
"font_class": "weixin",
"unicode": "e614",
"unicode_decimal": 58900
},
{
"icon_id": "11078843",
"name": "勾",
"font_class": "gou",
"unicode": "e610",
"unicode_decimal": 58896
},
{
"icon_id": "7738015",
"name": "about_us",
"font_class": "yonghu1",
"unicode": "e607",
"unicode_decimal": 58887
},
{
"icon_id": "630127",
"name": "feedback",
"font_class": "yijianfankui",
"unicode": "e662",
"unicode_decimal": 58978
},
{
"icon_id": "4766957",
"name": "wifi",
"font_class": "wifi",
"unicode": "e7e0",
"unicode_decimal": 59360
},
{
"icon_id": "8655878",
"name": "group",
"font_class": "qun",
"unicode": "e64f",
"unicode_decimal": 58959
}
]
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
static/image/kongshuju.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

18
static/image/loading.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 37 KiB

BIN
static/image/mine_bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
static/image/toy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

3
tianjia.js Normal file
View File

@ -0,0 +1,3 @@
"use strict";
var _imports_0 = "/static/icon/tianjia.png";
exports._imports_0 = _imports_0;

57
utils/audioUtil.js Normal file
View File

@ -0,0 +1,57 @@
"use strict";
const savePCMBuffer = async (pcmArrayBuffer, voiceList) => {
const sampleRate = 16e3;
const channels = 1;
const bitDepth = 16;
const wavArrayBuffer = pcmToWav(pcmArrayBuffer, sampleRate, channels, bitDepth);
const FileSystemManager = wx.getFileSystemManager();
const dateNow = Date.now();
const savePath = `${wx.env.USER_DATA_PATH}/${dateNow}.wav`;
try {
await new Promise((resolve, reject) => {
FileSystemManager.writeFile({
data: wavArrayBuffer,
filePath: savePath,
success: resolve,
fail: reject
});
});
if (voiceList) {
voiceList.push(savePath);
}
} catch (error) {
console.error("Failed to save WAV file:", error);
}
};
const pcmToWav = (pcmArrayBuffer, sampleRate, channels, bitDepth) => {
const chunkSize = 36 + pcmArrayBuffer.byteLength;
const subChunk1Size = 16;
const audioFormat = 1;
const byteRate = sampleRate * channels * (bitDepth / 8);
const blockAlign = channels * (bitDepth / 8);
const wavArrayBuffer = new ArrayBuffer(chunkSize + 8 + pcmArrayBuffer.byteLength);
const wavView = new DataView(wavArrayBuffer);
writeString(wavView, 0, "RIFF");
wavView.setUint32(4, chunkSize, true);
writeString(wavView, 8, "WAVE");
writeString(wavView, 12, "fmt ");
wavView.setUint32(16, subChunk1Size, true);
wavView.setUint16(20, audioFormat, true);
wavView.setUint16(22, channels, true);
wavView.setUint32(24, sampleRate, true);
wavView.setUint32(28, byteRate, true);
wavView.setUint16(32, blockAlign, true);
wavView.setUint16(34, bitDepth, true);
writeString(wavView, 36, "data");
wavView.setUint32(40, pcmArrayBuffer.byteLength, true);
const pcmView = new Uint8Array(pcmArrayBuffer);
const wavPcmView = new Uint8Array(wavArrayBuffer, 44);
wavPcmView.set(pcmView);
return wavArrayBuffer;
};
const writeString = (view, offset, string) => {
for (let i = 0; i < string.length; i++) {
view.setUint8(offset + i, string.charCodeAt(i));
}
};
exports.savePCMBuffer = savePCMBuffer;

88
utils/bluetooth.js Normal file
View File

@ -0,0 +1,88 @@
"use strict";
const getBLEDeviceServices = (deviceId) => {
return new Promise((resolve, reject) => {
wx.getBLEDeviceServices({
deviceId,
success: (result) => {
console.log("\u6210\u529F");
resolve(result);
},
fail: (err) => {
wx.showToast({
title: "\u672A\u80FD\u83B7\u53D6\u670D\u52A1"
});
reject(err);
}
});
});
};
const getBLEDeviceCharacteristics = (deviceId, serviceId) => {
return new Promise((resolve, reject) => {
wx.getBLEDeviceCharacteristics({
deviceId,
serviceId,
success: (result) => {
resolve(result);
},
fail: (err) => {
reject(err);
}
});
});
};
const notifyBLECharacteristicValueChange = (deviceId, serviceId, notifyCharacteristicId) => {
return new Promise((resolve, reject) => {
wx.notifyBLECharacteristicValueChange({
deviceId,
serviceId,
characteristicId: notifyCharacteristicId,
state: true,
success: (result) => {
resolve(result);
},
fail: (err) => {
reject(err);
}
});
});
};
const writeBLECharacteristicValue = (deviceId, serviceId, writeCharacteristicId, value) => {
return new Promise((resolve, reject) => {
wx.writeBLECharacteristicValue({
deviceId,
serviceId,
characteristicId: writeCharacteristicId,
value,
success: (result) => {
wx.showToast({
title: "\u5DF2\u6210\u529F\u53D1\u9001\u6570\u636E,\u84DD\u7259\u5DF2\u6253\u5F00"
});
resolve(result);
},
fail: (err) => {
reject(err);
}
});
});
};
const closeBluetoothAdapter = () => {
return new Promise((resolve, reject) => {
wx.closeBluetoothAdapter({
success: (result) => {
resolve(result);
},
fail: (err) => {
wx.showToast({
title: "\u6570\u636E\u53D1\u9001\u6210\u529F\uFF0C\u4F46\u672A\u5173\u95ED\u84DD\u7259\uFF0C\u8BF7\u624B\u52A8\u5173\u95ED",
icon: "none"
});
reject(err);
}
});
});
};
exports.closeBluetoothAdapter = closeBluetoothAdapter;
exports.getBLEDeviceCharacteristics = getBLEDeviceCharacteristics;
exports.getBLEDeviceServices = getBLEDeviceServices;
exports.notifyBLECharacteristicValueChange = notifyBLECharacteristicValueChange;
exports.writeBLECharacteristicValue = writeBLECharacteristicValue;

134
utils/request.js Normal file
View File

@ -0,0 +1,134 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
var common_vendor = require("../common/vendor.js");
var config_index = require("../config/index.js");
const request = (_a) => {
var _b = _a, {
baseUrl = config_index.base_url,
url,
loading = true,
method = "GET",
data = {}
} = _b, options = __objRest(_b, [
"baseUrl",
"url",
"loading",
"method",
"data"
]);
const { token } = common_vendor.index.getStorageSync("userData");
return new Promise((resolve, reject) => {
if (url) {
loading && common_vendor.index.showLoading();
common_vendor.index.request(__spreadValues({
url: `${baseUrl}${url}`,
method,
header: {
Authorization: token || "",
"ngrok-skip-browser-warning": "69420"
},
data,
success: (res) => {
if (res.statusCode === 200) {
resolve(res.data);
} else if (res.data.error === "Unauthorized") {
common_vendor.index.showToast({
title: "\u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",
icon: "none"
});
common_vendor.index.redirectTo({
url: "/pages/login/index"
});
} else if (res.statusCode === 502) {
common_vendor.index.showToast({
title: "\u670D\u52A1\u6682\u4E0D\u53EF\u7528",
icon: "error"
});
reject("\u670D\u52A1\u6682\u4E0D\u53EF\u7528");
}
},
fail: (err) => {
reject(err);
},
complete: () => {
common_vendor.index.hideLoading();
}
}, options));
} else {
reject(new Error("url is must required"));
}
});
};
const requestFormData = (_c) => {
var _d = _c, {
baseUrl = config_index.base_url,
url,
loading = true,
method = "POST",
file
} = _d, options = __objRest(_d, [
"baseUrl",
"url",
"loading",
"method",
"file"
]);
const { token } = common_vendor.index.getStorageSync("userData");
return new Promise((resolve, reject) => {
if (url) {
loading && common_vendor.index.showLoading();
common_vendor.index.uploadFile({
url: `${baseUrl}${url}`,
method,
header: {
Authorization: token || "",
"Content-Type": "multipart/form-data",
"ngrok-skip-browser-warning": "69420"
},
filePath: file.path || "no_path",
name: "file",
formData: { "file": file },
success: (res) => {
resolve(JSON.parse(res.data));
},
fail: (err) => {
reject(err);
},
complete: () => {
loading && common_vendor.index.hideLoading();
}
});
} else {
reject(new Error("url is must required"));
}
});
};
exports.request = request;
exports.requestFormData = requestFormData;

122
utils/wsRequest.js Normal file
View File

@ -0,0 +1,122 @@
"use strict";
var common_vendor = require("../common/vendor.js");
class webSocketClass {
constructor(url, time) {
this.url = url;
this.data = null;
this.isCreate = false;
this.isConnect = false;
this.isInitiative = false;
this.timeoutNumber = time;
this.heartbeatTimer = null;
this.reconnectTimer = null;
this.socketExamples = null;
this.againTime = 3;
}
initSocket() {
const _this = this;
return new Promise((resolve, reject) => {
this.socketExamples = common_vendor.index.connectSocket({
url: _this.url,
header: {
"content-type": "application/json"
},
success: (res) => {
_this.isCreate = true;
console.log(res);
resolve(res);
},
fail: (rej) => {
console.error(rej);
_this.isCreate = false;
reject(rej);
}
});
this.createSocket();
});
}
createSocket() {
if (this.isCreate) {
console.log("WebSocket \u5F00\u59CB\u521D\u59CB\u5316");
try {
this.socketExamples.onOpen(() => {
console.log("WebSocket \u8FDE\u63A5\u6210\u529F");
this.isConnect = true;
clearInterval(this.heartbeatTimer);
clearTimeout(this.reconnectTimer);
this.heartbeatCheck();
});
this.socketExamples.onMessage((res) => {
console.log("\u6536\u5230\u6D88\u606F", res);
common_vendor.index.$emit("message", res);
});
this.socketExamples.onClose(() => {
console.log("WebSocket \u5173\u95ED\u4E86");
this.isConnect = false;
this.reconnect();
});
this.socketExamples.onError((res) => {
console.log("WebSocket \u51FA\u9519\u4E86");
console.log(res);
this.isInitiative = false;
});
} catch (error) {
console.warn(error);
}
} else {
console.warn("WebSocket \u521D\u59CB\u5316\u5931\u8D25!");
}
}
sendMsg(value) {
const param = JSON.stringify(value);
return new Promise((resolve, reject) => {
this.socketExamples.send({
data: param,
success() {
console.log("\u6D88\u606F\u53D1\u9001\u6210\u529F");
resolve(true);
},
fail(error) {
console.log("\u6D88\u606F\u53D1\u9001\u5931\u8D25");
reject(error);
}
});
});
}
heartbeatCheck() {
console.log("\u5F00\u542F\u5FC3\u8DF3");
this.data = { state: 1, method: "heartbeat" };
this.heartbeatTimer = setInterval(() => {
this.sendMsg(this.data);
}, this.timeoutNumber * 1e3);
}
reconnect() {
clearTimeout(this.reconnectTimer);
clearInterval(this.heartbeatTimer);
if (!this.isInitiative) {
this.reconnectTimer = setTimeout(() => {
this.initSocket();
}, this.againTime * 1e3);
}
}
closeSocket(reason = "\u5173\u95ED") {
const _this = this;
this.socketExamples.close({
reason,
success() {
_this.data = null;
_this.isCreate = false;
_this.isConnect = false;
_this.isInitiative = true;
_this.socketExamples = null;
clearInterval(_this.heartbeatTimer);
clearTimeout(_this.reconnectTimer);
console.log("\u5173\u95ED WebSocket \u6210\u529F");
},
fail() {
console.log("\u5173\u95ED WebSocket \u5931\u8D25");
}
});
}
}
exports.webSocketClass = webSocketClass;