first save

This commit is contained in:
2025-11-12 15:08:51 +08:00
commit c66fc54821
2885 changed files with 339178 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
export const BASE_URL = 'http://172.20.10.2:8080';
// export const BASE_URL = 'https://www.jianxinghome.cn:8484';
// export const BASE_URL = 'https://www.safeguardfull.cn:8484';
export const WEBSOCKET_URL = 'wss://www.safeguardfull.cn:8484/websocket';
export default {
BASE_URL,
WEBSOCKET_URL
}

View File

@@ -0,0 +1,33 @@
const userInfoKey = 'SCORE_SAFE_LOGIN' // 本地用户数据的key
const getUserInfo = () => {
var userInfo = uni.getStorageSync(userInfoKey)
if(userInfo != '') {
userInfo = JSON.parse(userInfo);
return userInfo;
} else {
return null
}
}
const setUserInfo = (userInfo) => {
uni.setStorageSync(userInfoKey, JSON.stringify(userInfo));
}
// 获取胶囊距离顶部高度
const getTopHeight = () => {
const systemInfo = uni.getSystemInfoSync();
const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
const statusBarHeight = systemInfo.statusBarHeight;
const menuButtonHeight = menuButtonInfo.height;
const calculatedTopHeight = statusBarHeight + menuButtonHeight + 20; // 20rpx 额外间距
return `${calculatedTopHeight * (750 / systemInfo.windowWidth)}rpx`;
};
const StaticValue = {
getTopHeight,
userInfoKey,
getUserInfo,
setUserInfo
};
export default StaticValue;

View File

@@ -0,0 +1,34 @@
import { BASE_URL } from "./CommonValues";
export async function uploadFile(filePath) {
console.log("文件路径", filePath)
if(!filePath) {
uni.showToast({
title: '未选择文件',
icon: 'error'
})
return;
}
const res = await uni.uploadFile({
url: BASE_URL + "/txy/oss/upload", // 请求的服务器URL
filePath: filePath, // 要上传文件资源的路径
name: "file" // 必须填,是服务器端约定的字段名
});
console.log("上传文件结果1", res)
if(res.statusCode != 200) {
uni.showToast({
title: '文件上传失败:system',
icon: 'error'
})
return;
}
const resData = JSON.parse(res.data);
if(resData.statusCode != 200) {
uni.showToast({
title: '文件上传失败:code',
icon: 'error'
})
return;
}
console.log("上传文件结果", resData)
return resData.data
}

97
scoring/utils/request.js Normal file
View File

@@ -0,0 +1,97 @@
import { BASE_URL } from './CommonValues.js';
import { loginSystem } from '@/api/login.js';
export function GET(url, data) {
return SIMPLE(url, data, 'GET');
}
export function GET_TOKEN(url, data, token) {
return SIMPLE_TOKEN(url, data, token, 'GET');
}
export function POST(url, data) {
return SIMPLE(url, data, 'POST');
}
export function POST_TOKEN(url, data) {
return SIMPLE_TOKEN(url, data, token, 'POST');
}
export function DELETE(url, data) {
return SIMPLE(url, data, 'DELETE');
}
export function PUT(url, data) {
return SIMPLE(url, data, 'PUT');
}
let requestTime = 0;
export async function SIMPLE(url, data, method) {
// 防止首次访问没有token
if(requestTime == 0) {
token = await loginSystem();
if(token.data) {
// 如果有code表示没有拿到token
SIMPLE(url, data, method)
return;
}
requestTime += 1;
} else {
var token = uni.getStorageSync("APP_TOKEN");
}
return new Promise((resolve, reject) => {
uni.request({
url: `${BASE_URL}${url}`,
method: method,
header: {
"Content-Type": "application/json;charset=utf-8",
"Authorization": token
},
dataType: 'json',
data: data,
success: res => {
if(res.data.code == '200' || res.data.statusCode == '200') {
resolve(res.data)
} else {
reject(res)
}
},
fail: err => {
reject(err)
}
})
})
}
export function SIMPLE_TOKEN(url, data, token, method) {
return new Promise((resolve, reject) => {
uni.request({
url: `${BASE_URL}${url}`,
method: method,
header: {
"Content-Type": "application/json;charset=utf-8",
"Authorization": token
},
dataType: 'json',
data: data,
success: res => {
if(res.data.code == '200' || res.data.statusCode == '200') {
resolve(res.data)
} else {
reject(res)
}
},
fail: err => {
reject(err)
}
})
})
}
export default {
GET,
POST,
DELETE,
PUT,
GET_TOKEN
}

37
scoring/utils/wxutils.js Normal file
View File

@@ -0,0 +1,37 @@
import { GET, GET_TOKEN } from '@/utils/request.js'
import { loginSystem } from '@/api/login'
export function getOpenId() {
return new Promise(async (resolve, reject) => {
var token = await loginSystem();
wx.login({
success: (res) => {
if (res.code) {
//发起网络请求
GET_TOKEN(`/wx/openid/${res.code}`, null, token)
.then(response => {
response.data.openid
resolve({
status: 200,
openid: response.data.openid,
message: '获取openid成功'
})
})
.catch(error => {
console.log(error)
reject({
status: 400,
openid: null,
message: '获取openid失败'
})
})
} else {
reject({
status: 400,
openid: null,
message: '获取微信信息失败'
})
}
}
})
})
}