This commit is contained in:
zpc 2025-08-04 17:37:56 +08:00
parent c32212014d
commit 3d596e462d
5 changed files with 344 additions and 329 deletions

View File

@ -141,357 +141,365 @@
</template>
<script>
import uniNoticeBar from '@/uni_modules/uni-notice-bar/components/uni-notice-bar/uni-notice-bar.vue'
import {
processImage
} from '@/common/utils'
export default {
components: {
uniNoticeBar
},
onLoad() {
this.getConfig();
var userId = uni.getStorageSync("user_id");
if (!userId || userId == 0) {
this.login();
}
this.userId = userId;
},
data() {
return {
bg: "",
userId: 0,
imagePath: '',
name: "",
phone: "",
base64: "",
workUnit: "",
address: "",
createTime: "",
number: "",
model: "",
recordList: []
}
},
import uniNoticeBar from '@/uni_modules/uni-notice-bar/components/uni-notice-bar/uni-notice-bar.vue'
import {
processImage
} from '@/common/utils'
export default {
components: {
uniNoticeBar
},
onLoad() {
this.getConfig();
var userId = uni.getStorageSync("user_id");
if (!userId || userId == 0) {
this.login();
}
this.userId = userId;
},
data() {
return {
bg: "",
userId: 0,
imagePath: '',
name: "",
phone: "",
base64: "",
workUnit: "",
address: "",
createTime: "",
number: "",
model: "",
recordList: []
}
},
methods: {
request(url, method, data) {
return new Promise((resolve, reject) => {
const header = {
methods: {
request(url, method, data) {
return new Promise((resolve, reject) => {
const header = {
};
if (method == "post") {
header['content-type'] = 'application/json';
}
uni.request({
url: "https://gift.zpc-xy.com/" + url,
method: method,
data: data,
header: header,
timeout: 10000,
success: (res) => {
console.log('API响应:', res);
if (res.statusCode === 200) {
resolve(res.data);
} else {
reject(new Error(`请求失败,状态码: ${res.statusCode}`));
}
},
fail: (err) => {
console.error('API请求失败:', err);
reject(err);
}
});
})
},
async getConfig() {
const res = await this.request("config", "get", {});
console.log(res);
if (res.home != "") {
this.bg = res.home;
};
if (method == "post") {
header['content-type'] = 'application/json';
}
},
wxLogin() {
return new Promise((resolve, reject) => {
uni.login({
provider: 'weixin', //使
onlyAuthorize: true,
success: async function(res) {
// if()
resolve(res.code);
},
fail: function(err) {
reject(err);
}
})
})
},
async login() {
try {
const wxCode = await this.wxLogin();
if (wxCode) {
const res = await this.request("userLogin?code=" + wxCode, "post", {});
if (res.code == 200) {
uni.setStorageSync("user_id", res.data.user_id);
this.userId = res.data.user_id;
console.log('登录成功, userId:', this.userId);
uni.request({
url: "https://gift.zpc-xy.com/" + url,
method: method,
data: data,
header: header,
timeout: 10000,
success: (res) => {
console.log('API响应:', res);
if (res.statusCode === 200) {
resolve(res.data);
} else {
console.error('登录失败:', res.message);
reject(new Error(`请求失败,状态码: ${res.statusCode}`));
}
},
fail: (err) => {
console.error('API请求失败:', err);
reject(err);
}
} catch (error) {
console.error('登录过程出错:', error);
}
},
openReceivePop() {
this.$refs.receivePop.open();
},
});
})
},
async getConfig() {
const res = await this.request("config", "get", {});
console.log(res);
if (res.home != "") {
this.bg = res.home;
}
},
wxLogin() {
return new Promise((resolve, reject) => {
uni.login({
provider: 'weixin', //使
onlyAuthorize: true,
success: async function (res) {
// if()
resolve(res.code);
},
fail: function (err) {
reject(err);
}
})
})
closeReceivePop() {
this.$refs.receivePop.close();
},
getUserId() {
if (this.userId == 0) {
var userId = uni.getStorageSync("user_id");
if (!userId || userId == 0) {
this.login();
},
async login() {
try {
const wxCode = await this.wxLogin();
if (wxCode) {
const res = await this.request("userLogin?code=" + wxCode, "post", {});
if (res.code == 200) {
uni.setStorageSync("user_id", res.data.user_id);
this.userId = res.data.user_id;
console.log('登录成功, userId:', this.userId);
} else {
this.userId = userId;
console.error('登录失败:', res.message);
}
}
return this.userId;
} catch (error) {
console.error('登录过程出错:', error);
}
},
openReceivePop() {
this.$refs.receivePop.open();
},
},
async openRecordPop() {
await this.loadRecordList();
this.$refs.recordPop.open();
},
closeReceivePop() {
this.$refs.receivePop.close();
},
getUserId() {
async loadRecordList() {
try {
uni.showLoading({
title: '加载中...'
});
// API
const result = await this.request('getRecord?userId=' + this.getUserId(), 'GET', {});
console.log(result);
if (result.data.length > 0) {
let isShow = true;
let record = [];
for (var index = 0; index < result.data.length; index++) {
var element = result.data[index];
if (element.status == 1) {
record.push(element)
}
}
this.recordList = record;
}
// 使
console.log('加载领取记录...');
} catch (error) {
console.error('加载领取记录失败:', error);
}
uni.hideLoading();
},
if (this.userId == 0) {
closeRecordPop() {
this.$refs.recordPop.close();
},
var userId = uni.getStorageSync("user_id");
if (!userId || userId == 0) {
this.login();
} else {
this.userId = userId;
}
}
return this.userId;
async seleImg() {
try {
uni.showLoading({
title: '处理中...'
});
const {
base64,
path
} = await processImage();
console.log('最终Base64长度:', base64.length, path);
this.imagePath = path;
this.base64 = base64;
uni.showToast({
title: '上传成功'
});
} catch (err) {
console.error('处理失败', err);
uni.showToast({
title: '处理失败',
icon: 'none'
});
} finally {
uni.hideLoading();
}
},
validateForm() {
if (!this.name.trim()) {
uni.showToast({
title: '请填写姓名',
icon: 'none'
});
return false;
}
if (!this.phone.trim()) {
uni.showToast({
title: '请填写联系方式',
icon: 'none'
});
return false;
}
if (!this.workUnit.trim()) {
uni.showToast({
title: '请填写工作单位',
icon: 'none'
});
return false;
}
if (!this.address.trim()) {
uni.showToast({
title: '请填写收货地址',
icon: 'none'
});
return false;
}
if (!this.model.trim()) {
uni.showToast({
title: '请填写设备型号',
icon: 'none'
});
return false;
}
if (!this.number.trim()) {
uni.showToast({
title: '请填写出品编号',
icon: 'none'
});
return false;
}
if (!this.createTime.trim()) {
uni.showToast({
title: '请填写出品年月',
icon: 'none'
});
return false;
}
if (!this.imagePath) {
uni.showToast({
title: '请上传产品铭牌照片',
icon: 'none'
});
return false;
}
return true;
},
async submitForm() {
if (!this.validateForm()) {
return;
}
},
async openRecordPop() {
await this.loadRecordList();
this.$refs.recordPop.open();
},
async loadRecordList() {
try {
uni.showLoading({
title: '提交中...'
title: '加载中...'
});
// API
const result = await this.request('getRecord?userId=' + this.getUserId(), 'GET', {});
console.log(result);
if (result.data.length > 0) {
let isShow = true;
let record = [];
for (var index = 0; index < result.data.length; index++) {
var element = result.data[index];
if (element.status == 1) {
record.push(element)
}
}
this.recordList = record;
}
// 使
console.log('加载领取记录...');
} catch (error) {
console.error('加载领取记录失败:', error);
}
uni.hideLoading();
},
closeRecordPop() {
this.$refs.recordPop.close();
},
async seleImg() {
try {
uni.showLoading({
title: '处理中...'
});
try {
const formData = {
UserId: this.userId,
Name: this.name,
Phone: this.phone,
Company: this.workUnit,
Address: this.address,
ProductModel: this.model,
ProductSerialNumber: this.number,
ProductDate: this.createTime,
ProductImage: this.base64
};
const {
base64,
path
} = await processImage();
console.log('最终Base64长度:', base64.length, path);
this.imagePath = path;
this.base64 = base64;
uni.showToast({
title: '上传成功'
});
} catch (err) {
console.error('处理失败', err);
uni.showToast({
title: '处理失败',
icon: 'none'
});
} finally {
uni.hideLoading();
}
// API
const result = await this.request('addRecord', 'POST', formData);
console.log(result);
uni.hideLoading();
if (result.code == 200) {
uni.showToast({
title: '提交成功,请等待审核',
icon: 'success'
});
this.closeReceivePop();
this.clearForm();
} else {
uni.showToast({
title: '提交失败,请重试',
icon: 'none'
});
},
}
validateForm() {
if (!this.name.trim()) {
uni.showToast({
title: '请填写姓名',
icon: 'none'
});
return false;
}
if (!this.phone.trim()) {
uni.showToast({
title: '请填写联系方式',
icon: 'none'
});
return false;
}
if (!this.workUnit.trim()) {
uni.showToast({
title: '请填写工作单位',
icon: 'none'
});
return false;
}
if (!this.address.trim()) {
uni.showToast({
title: '请填写收货地址',
icon: 'none'
});
return false;
}
if (!this.model.trim()) {
uni.showToast({
title: '请填写设备型号',
icon: 'none'
});
return false;
}
if (!this.number.trim()) {
uni.showToast({
title: '请填写出品编号',
icon: 'none'
});
return false;
}
if (!this.createTime.trim()) {
uni.showToast({
title: '请填写出品年月',
icon: 'none'
});
return false;
}
if (!this.imagePath) {
uni.showToast({
title: '请上传产品铭牌照片',
icon: 'none'
});
return false;
}
return true;
},
async submitForm() {
if (!this.validateForm()) {
return;
}
} catch (error) {
uni.hideLoading();
uni.showLoading({
title: '提交中...'
});
try {
const formData = {
UserId: this.userId,
Name: this.name,
Phone: this.phone,
Company: this.workUnit,
Address: this.address,
ProductModel: this.model,
ProductSerialNumber: this.number,
ProductDate: this.createTime,
ProductImage: this.base64
};
// API
const result = await this.request('addRecord', 'POST', formData);
console.log(result);
uni.hideLoading();
if (result.code == 200) {
uni.showToast({
title: '提交成功,请等待审核',
icon: 'success'
});
this.closeReceivePop();
this.clearForm();
} else {
uni.showToast({
title: '提交失败,请重试',
icon: 'none'
});
console.error('提交失败:', error);
}
},
clearForm() {
this.name = '';
this.phone = '';
this.workUnit = '';
this.address = '';
this.model = '';
this.number = '';
this.createTime = '';
this.imagePath = '';
this.base64 = '';
},
previewImage() {
if (this.imagePath) {
uni.previewImage({
current: this.imagePath,
urls: [this.imagePath],
success: function(res) {
console.log('预览图片成功');
},
fail: function(err) {
console.error('预览图片失败:', err);
uni.showToast({
title: '预览失败',
icon: 'none'
});
}
});
}
} catch (error) {
uni.hideLoading();
uni.showToast({
title: '提交失败,请重试',
icon: 'none'
});
console.error('提交失败:', error);
}
},
clearForm() {
this.name = '';
this.phone = '';
this.workUnit = '';
this.address = '';
this.model = '';
this.number = '';
this.createTime = '';
this.imagePath = '';
this.base64 = '';
},
previewImage() {
if (this.imagePath) {
uni.previewImage({
current: this.imagePath,
urls: [this.imagePath],
success: function (res) {
console.log('预览图片成功');
},
fail: function (err) {
console.error('预览图片失败:', err);
uni.showToast({
title: '预览失败',
icon: 'none'
});
}
});
}
},
async getBannerList() {
const res = await this.request('getBannerList', 'GET', {});
console.log(res);
if (res.code == 200) {
this.bannerList = res.data;
}
}
}
}
</script>
<style>
.content {
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
}
.content {
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
}
.line {
width: 90%;
justify-content: center;
margin-top: 20rpx;
border-bottom: 0.86px solid #e3e3e3;
.line {
width: 90%;
justify-content: center;
margin-top: 20rpx;
border-bottom: 0.86px solid #e3e3e3;
}
}
</style>

File diff suppressed because one or more lines are too long

View File

@ -7048,7 +7048,7 @@ function isConsoleWritable() {
function initRuntimeSocketService() {
const hosts = "28.0.0.1,192.168.1.21,192.168.195.35,127.0.0.1";
const port = "8090";
const id = "mp-weixin_Tvd9Dq";
const id = "mp-weixin_rAbElt";
const lazy = typeof swan !== "undefined";
let restoreError = lazy ? () => {
} : initOnError();

View File

@ -302,6 +302,13 @@ const _sfc_main = {
}
});
}
},
async getBannerList() {
const res = await this.request("getBannerList", "GET", {});
common_vendor.index.__f__("log", "at pages/index/index.vue:476", res);
if (res.code == 200) {
this.bannerList = res.data;
}
}
}
};

View File

@ -1,16 +1,16 @@
.content {
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
}
.line {
width: 90%;
justify-content: center;
margin-top: 20rpx;
border-bottom: 0.86px solid #e3e3e3;
width: 90%;
justify-content: center;
margin-top: 20rpx;
border-bottom: 0.86px solid #e3e3e3;
}