| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- const api = require('../../api/index.js');
-
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- projectList: [], // 项目列表数据
- pageNum: 1, // 当前页码
- pageSize: 10, // 每页条数
- hasMore: true, // 是否有更多数据
- loading: false, // 是否正在加载
- refreshing: false, // 是否正在下拉刷新
- statedata:[{title:'未审核'},{title:'未勘探'},{title:'未签约'},{title:'已启用'}]
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- // 页面加载时获取第一页数据
- this.getProjectList();
- },
-
- /**
- * 获取项目列表数据
- * @param {boolean} isRefresh 是否是下拉刷新
- */
- getProjectList(isRefresh = false) {
- // 如果正在加载或没有更多数据,直接返回
- if (this.data.loading && !isRefresh) return;
-
- this.setData({
- loading: true,
- ...(isRefresh && { refreshing: true }), // 刷新时设置refreshing为true
- });
-
- let data = {
-
- }
- api.request(`/sysproject/selectproject`, 'post', data, { isPublic: false })
- .then((data) => {
- console.log('实时数据:', data.data);
- if (data.code === 200) {
- // 处理数据:分割图片URL字符串为数组
- const processedList = data.data.map(item => {
- // 处理逻辑:
- // 1. 先判断 picture 字段是否存在且不为空
- // 2. 按逗号分割成数组
- // 3. 过滤掉分割后可能出现的空字符串(避免数据异常)
- const pictureArray = item.picture
- ? item.picture.split(',').filter(url => url.trim() !== '')
- : [];
-
- return {
- ...item, // 保留原有的所有字段
- picture: pictureArray // 替换 picture 为数组格式
- };
- });
- console.log(processedList);
- // 更新数据到页面
- this.setData({
- projectList: processedList
- });
- }
- })
- .catch((err) => {
- console.error('实时数据请求失败:', err);
- });
- },
-
- /**
- * 下拉刷新
- */
- onPullDownRefresh() {
- this.getProjectList(true);
- },
-
- /**
- * 上拉加载更多
- */
- onReachBottom() {
- if (this.data.hasMore && !this.data.loading) {
- this.getProjectList();
- }
- },
-
- /**
- * 点击列表项进入详情页
- */
- goToDetail(e) {
- const { id } = e.currentTarget.dataset;
- wx.navigateTo({
- url: `/pages/detail/detail?id=${id}`,
- });
- },
- });
|