From 39f0da3a4441e74d8c2ba7d56b549c71c7761359 Mon Sep 17 00:00:00 2001 From: zpc Date: Mon, 4 Aug 2025 19:01:05 +0800 Subject: [PATCH] 333 --- pages/index/index.vue | 619 +++++++++++++++++++++--------------------- 1 file changed, 303 insertions(+), 316 deletions(-) diff --git a/pages/index/index.vue b/pages/index/index.vue index 28cd3b1..2bd2578 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -5,9 +5,8 @@ - - - + + @@ -16,14 +15,16 @@ catchtouchmove="return false"> - + + - + + @@ -181,6 +182,7 @@ if (!userId || userId == 0) { this.login(); } + this.getBannerList(); this.userId = userId; }, data() { @@ -198,31 +200,7 @@ model: "", recordList: [], // 图片数据 - imageList: [{ - url: 'https://picsum.photos/300/200?random=1', - alt: '图片1' - }, - { - url: 'https://picsum.photos/300/200?random=2', - alt: '图片2' - }, - { - url: 'https://picsum.photos/300/200?random=3', - alt: '图片3' - }, - { - url: 'https://picsum.photos/300/200?random=4', - alt: '图片4' - }, - { - url: 'https://picsum.photos/300/200?random=5', - alt: '图片5' - }, - { - url: 'https://picsum.photos/300/200?random=6', - alt: '图片6' - } - ], + imageList: [], scrollTimer: null, // 滚动定时器 scrollSpeed: 1, // 滚动速度 (px/帧) translateX: 0, // 位移量 @@ -232,15 +210,7 @@ }, onReady() { - // 获取列表宽度 - this.$nextTick(() => { - const query = uni.createSelectorQuery().in(this); - query.select('.image-list').boundingClientRect(data => { - this.listWidth = data.width; - // 开始自动滚动 - this.startAutoScroll(); - }).exec(); - }); + }, onUnload() { @@ -248,284 +218,284 @@ this.stopAutoScroll(); }, - 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}`)); + }; + 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); } - }, - 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; - } - }, - 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); - } else { - console.error('登录失败:', res.message); - } - } - } catch (error) { - console.error('登录过程出错:', error); - } - }, - openReceivePop() { - this.$refs.receivePop.open(); - }, - - closeReceivePop() { - this.$refs.receivePop.close(); - }, - getUserId() { - - if (this.userId == 0) { - - var userId = uni.getStorageSync("user_id"); - if (!userId || userId == 0) { - this.login(); - } else { - this.userId = userId; - } - } - return this.userId; - - }, - async openRecordPop() { - await this.loadRecordList(); - this.$refs.recordPop.open(); - }, - - 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(); - }, - - closeRecordPop() { - this.$refs.recordPop.close(); - }, - - 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; - } - - 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 { + }) + }, + 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); + } + }) + }) + + }, + 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 { + console.error('登录失败:', res.message); + } + } + } catch (error) { + console.error('登录过程出错:', error); + } + }, + openReceivePop() { + this.$refs.receivePop.open(); + }, + + closeReceivePop() { + this.$refs.receivePop.close(); + }, + getUserId() { + + if (this.userId == 0) { + + var userId = uni.getStorageSync("user_id"); + if (!userId || userId == 0) { + this.login(); + } else { + this.userId = userId; + } + } + return this.userId; + + }, + async openRecordPop() { + await this.loadRecordList(); + this.$refs.recordPop.open(); + }, + + 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(); + }, + + closeRecordPop() { + this.$refs.recordPop.close(); + }, + + 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; + } + + 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' + }); + + } + + + } catch (error) { + uni.hideLoading(); uni.showToast({ title: '提交失败,请重试', icon: 'none' }); - + console.error('提交失败:', error); } + }, - - } 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 = ''; - }, + clearForm() { + this.name = ''; + this.phone = ''; + this.workUnit = ''; + this.address = ''; + this.model = ''; + this.number = ''; + this.createTime = ''; + this.imagePath = ''; + this.base64 = ''; + }, previewImage() { if (this.imagePath) { @@ -545,7 +515,23 @@ }); } }, - + async getBannerList() { + const res = await this.request("getBannerList", "GET", {}); + console.log(res); + if (res.data.length > 0) { + this.imageList = res.data; + console.log(this.imageList, this.imageList.length); + // 获取列表宽度 + this.$nextTick(() => { + const query = uni.createSelectorQuery().in(this); + query.select('.image-list').boundingClientRect(data => { + this.listWidth = data.width; + // 开始自动滚动 + this.startAutoScroll(); + }).exec(); + }); + } + }, // 开始自动滚动 startAutoScroll() { @@ -579,8 +565,8 @@ } + } } -}