- 三级菜单,第二列为多选,选中的内容没有高亮显示?
如图:选中了,但是颜色没有高亮,打印的数据也都有获取到。 [图片] <!--pages/relase/certificate/certificate.wxml--> <view class="content"> <view class="select-group"> <view class="position-title">{{positionselect}}</view> <view class="position-number"> <view class="count">6/</view> <view class="total">20</view> </view> </view> <view class="container"> <!-- 证书类型 --> <scroll-view class="first-column" scroll-y scroll-with-animation> <view wx:for="{{grades}}" wx:key="id" class="first-item {{currentGrade.id === item.id ? 'greenColor':''}}" bindtap="selectGrade" data-item="{{item}}"> <view class="first-float-carvit {{currentGrade.id === item.id ? 'greenBg':''}}"></view> <view class="first-float-title">{{item.name}}</view> <view class="first-float-count" wx:if="{{currentGrade.id === item.id}}">{{selectedStudents.length}}</view> </view> </scroll-view> <!-- 第二列证书名称 --> <scroll-view class="second-column" scroll-y scroll-with-animation> <view wx:for="{{classes}}" wx:key="id" class="second-item {{currentClass.id ? 'active':''}}" bindtap="selectClass" data-item="{{item}}" data-index="{{index}}">{{item.name}}</view> </scroll-view> <!-- 证书等级 --> <scroll-view class="third-column" scroll-y scroll-with-animation> <view wx:for="{{students}}" wx:key="id" class="second-item {{currentStudent.id === item.id ? 'active':''}}" bindtap="selectStudent" data-item="{{item}}">{{item.name}}</view> </scroll-view> </view> <view class="add-group" > <view class="add-title">已添加:</view> <scroll-view scroll-x="true" class="add-srcooll" show-scrollbar="{{false}}" enhanced="{{true}}" enable-flex> <view class="text-list" bindtap="removeBenefit" wx:for="{{selectedStudents}}" wx:key="name" data-catindex="{{item.catindex}}" data-subindex="{{item.subindex}}" data-posindex="{{item.posindex}}"> <text class="text">{{item.name}}</text> <view class="close">×</view> </view> </scroll-view> </view> <view class="btn-group"> <button bindtap="confirmSelection" type="primary" class="sunbmit-btn" disabled="{{selectedStudents.length === 0}}">确定(已选 <view class="position-number"> <view class="count">{{selectedStudents.length}}/</view> <view class="total">5</view> </view>项) </button> </view> </view> Page({ data: { positionselect: "资格证书", list :certificateList, // 证书类型 grades:[{id:1,name:'外语类'},{id:2,name:'英语类'},{id:3,name:'普通话类'},{id:4,name:'IT类'},{id:5,name:'生产制造类'},{id:6,name:'技工类'},{id:7,name:'人力行政类'},{id:8,name:'会计类'},{id:9,name:'审计类'},{id:10,name:'统计类'}], // 证书名称 classData:{ 1:[{id:101,name:'日语等级考试'}, {id:102,name:'日语专业四级'}, {id:103,name:'日语专业八级'}], 2:[{id:201,name:'大学英语四级'},{id:202,name:'大学英语六级'}], 3:[{id:301,name:'普通话水平测试'}], 4:[{id:401,name:'计算机等级考试'},{id:402,name:'计算机初级专业技术资格'}]}, // 证书等级 studentData:{ 101:[{id:10101,name:'日语N1'},{id:10102,name:'日语N2'}], 102:[{id:10201,name:'日语专业四级'}], 103:[{id:10301,name:'日语专业八级'}], 120:[{id:12001,name:'DELF法语学习A1级文凭'},{id:12002,name:'DELF法语学习A2级文凭'}], 121:[{id:12101,name:'CATTI法语一级口译'},{id:12102,name:'CATTI法语二级口译'}], 122:[{id:12201,name:'俄语专业四级'}], 123:[{id:12301,name:'俄语专业八级'}], 124:[{id:12401,name:'TPKN对外俄语一级'},{id:12402,name:'TPKN对外俄语二级'}], 201:[{id:20101,name:'大学英语四级'}], 202:[{id:20201,name:'大学英语六级'}], 203:[{id:20301,name:'英语专业四级'}], 204:[{id:20401,name:'英语专业八级'}], 301:[{id:30101,name:'普通话一级甲等'},{id:30102,name:'普通话一级乙等'}], 401:[{id:40101,name:'计算机一级'},{id:40102,name:'计算机二级'},{id:40103,name:'计算机三级'}], 402:[{id:40201,name:'程序员技术资格'},{id:40202,name:'网络管理员'},{id:40203,name:'信息系统运行管理员'},{id:40204,name:'网页制作员'},{id:40205,name:'信息处理技术员'},{id:40206,name:'多媒体应该制作技术员'},{id:40207,name:'电子商务技术员'}], 403:[{id:40301,name:'软件评测师'},{id:40302,name:'软件设计师'},{id:40303,name:'软件过程能力评估师'},{id:40304,name:'网络工程师'},{id:40305,name:'多媒体应用设计师'},{id:40306,name:'嵌入式系统设计师'},{id:40307,name:'计算机辅助设计师'},{id:40308,name:'电子商务设计师'},{id:40309,name:'系统集成项目管理工程师'},{id:403010,name:'信息系统监理师'},{id:403011,name:'数据库系统工程师'},{id:403012,name:'信息系统管理工程师'},{id:403013,name:'信息安全工程师'},{id:403014,name:'计算机硬件工程师'},{id:403015,name:'信息技术支持工程师'}],}, // 当前选中的证书类型,证书名称,证书等级 currentGrade: {}, // 第一列当前选中的 currentClass: {}, // 第二列当前选中的 currentStudent: {}, // 第三列当前选中的 // 当前显示的证书名称,证书等级列表 classes: [], students: [], // 已选中的证书名称,证书等级 selectedClasses: [], selectedStudents: [], }, onLoad: function (options) { // 初始化默认选中证书类型,证书名称的证书等级 const defaultGrade = this.data.grades[0]; console.log(defaultGrade) const defaultClass = this.data.classData[defaultGrade.id][0]; console.log(defaultClass) // const defaultStudent = this.data.studentData[defaultClass.id][0]; this.setData({ currentGrade: defaultGrade, // currentClass: defaultClass, // currentStudent: defaultStudent, classes: this.data.classData[defaultGrade.id], students: this.data.studentData[defaultClass.id] }) }, //选择证书类型 selectGrade(e) { console.log(e) const grade = e.currentTarget.dataset.item; console.log(grade) const classes = this.data.classData[grade.id] || []; console.log(classes) this.setData({ currentGrade: grade, classes: classes, // 重置证书名称的证书等级 currentClass: {}, currentStudent: {}, students: [] }) }, // 选择证书名称 selectClass(e) { // 获取当前选中的证书名称 let classItem = e.currentTarget.dataset.item; console.log(classItem); // 打印结果是当前选中项的值 // 获取第三列的内容 const students = this.data.studentData[classItem.id] || []; console.log(students); // 打印了该项目下的内容列表 // 获取第二列的index const index = e.currentTarget.dataset.index; console.log(index); // 打印了indx的值 // 确保 currentClass 是一个数组 if (!Array.isArray(this.data.currentClass)) { this.data.currentClass = []; } let currentClass = this.data.currentClass.includes(classItem.id); console.log(currentClass); // 当没有选中时点击选中打印结果是false,有选中的内容再次点击选中的内容为true // 检查当前项是否已选中 if (currentClass) { // 已选中,则取消选中 currentClass = this.data.currentClass.filter(id => id !== classItem.id); console.log(currentClass); } else { // 未选中,则添加到选中列表 currentClass = [...this.data.currentClass, classItem.id]; console.log(currentClass); // 打印结果是,选中的id。比如选中了第一个,id:101 } this.setData({ currentClass: currentClass, students: students, currentStudent: {} }); }, // 选择证书等级 selectStudent(e) { console.log(e) const student = e.currentTarget.dataset.item; const selectedStudents = this.data.selectedStudents; const index = selectedStudents.findIndex(item => item.id === student.id); if (index === -1) { selectedStudents.push(student); } else { selectedStudents.splice(index, 1); } this.setData({ currentStudent: student, selectedStudents: selectedStudents }); }, // 移除已添加的证书 removeBenefit(e) { const index = e.currentTarget.dataset.index; const selectedStudents = this.data.selectedStudents; selectedStudents.splice(index, 1); this.setData({ selectedStudents: selectedStudents }); }, // 确认选择 confirmSelection() { // 在这里处理已选中的证书 console.log('已选中的证书:', this.data.selectedStudents); }, })
星期五 18:14 - 点击列表进入详情页时,其他的数据都显示在页面中,唯独有一个不显示在页面中?
当点击列表进入详情页时,其他都显示在页面中,唯独income没有显示出来,这是什么问题,怎么解决? [图片][图片] <!--pages/jobs/add/edit-position/edit-position.wxml--> <view class="add-position-group"> <expectation formjobs="{{formData.jobs}}" formjobsCount="{{formData.jobsCount}}" formindustries="{{formData.industries}}" formindustriesCount="{{formData.industriesCount}}" isEditMode="{{isEditMode}}" expectationName="{{expectationName}}" expectationCity="{{expectationCity}}" income="{{income}}" bindjobs="onJobs" bindindustries="onIndustries" bind:namechange="onNameChange" bind:citychange="onCityChange" bind:incomechange="onincomechange"> </expectation> <view class="btn-ground"> <button class="sunbmit-btn" style="width:200rpx;" bindtap="onDeleteConfig">删除</button> <button form-type="submit" type="primary" class="sunbmit-btn" bindtap="onSaveConfig">保存配置</button> </view> </view> // pages/jobs/add/edit-position/edit-position.js const app = getApp(); const db = wx.cloud.database(); const _ = db.command; Page({ data: { formData: { jobs: [], jobsCount: 0, industries: [], industriesCount: 0 }, isEditMode: true, editItemId: '', expectationName: '全职', // 默认职位类型 expectationCity: '请选择工作城市', // 默认城市 income: '' // 初始为空 }, async onLoad(options) { try { await app.loadUserInfo(); this.setData({ editItemId: options.id, }); if (options.id) { await this.loadEditData(options.id); } } catch (error) { console.error("app.loadUserInfo() 出错:", error); } }, //加载编辑数据的方法 async loadEditData(id) { try { const res = await db.collection('resume').where({ _openid: app.globalData.openid, }).field({ expectation: true, _id: false, }).get(); console.log("res", res) console.log("res.data", res.data) console.log("res.data[0]", res.data[0]) if (res.data && res.data.length > 0) { const expectationList = res.data[0].expectation || []; const target = expectationList.find(item => item.id === id); console.log("target", target) console.log("targetincome", target.income) if (target) { this.setData({ expectationName: target.expectationName || '全职', expectationCity: target.expectationCity || '请选择工作城市', income: target.income || '', 'formData.jobs': target.expectationPosition || [], 'formData.jobsCount': target.expectationPosition ? target.expectationPosition.length : 0, 'formData.industries': target.expectationIndustry || [], 'formData.industriesCount': target.expectationIndustry ? target.expectationIndustry.length : 0, }); } } } catch (error) { console.error('加载编辑数据失败:', error); wx.showToast({ title: '加载数据失败', icon: 'none' }); } console.log('after setData income:', this.data.income) // 确认setData后income的值 }, /** * 薪资要求 */ onincomechange(e) { console.log(e) this.setData({ income: e.detail.value }); }, }); <!--components/expectation/expectation.wxml--> <view class="expectation-container"> <view class="add-list"> <view class="add-list-title">薪资要求</view> <view class="list-content"> <selector-tow name="income" pay-type="{{expectationName === '临/兼职' ? 'hourly' : 'monthly'}}" value="{{currentIncome}}" bindchange="onIncomeChange"></selector-tow> </view> </view> </view> // components/expectation/expectation.js Component({ properties: { income: { type: String, value: '', observer: function(newVal) { console.log('income changed in component:', newVal) if (newVal) { this.setData({ currentIncome: newVal }) } } } }, data: { natures: [{id: 0,name: '全职'}, {id: 1,name: '临/兼职'}], selectedNature: '', showPartTimeOnly: false, showFullTimeOnly: false, currentIncome: '' }, lifetimes: { async attached() { console.log('attached - income:',this.properties.income ) // 这里应该能打印出值 if (this.properties.income) { this.setData({ currentIncome: this.properties.income }) } } }, methods: { /** * 薪资要求 */ onIncomeChange(e) { console.log(e) const income = e.detail.value this.setData({ currentIncome: income }) this.triggerEvent('incomechange', { value: income }) } } }); <!--components/selector-tow/selector-tow.wxml--> <view class="section"> <picker mode="multiSelector" range="{{multiArray}}" value="{{multiIndex}}" bindchange="changeMulti" bindcolumnchange="nocolumnchange"> <view class="section-picker"> <view class="picker {{current === '请选择' ? 'address-red' : ''}}"> {{current === '面议' ? '面议' : current}} </view> <icon class="icon"></icon> </view> </picker> </view> // components/selector-tow/selector-tow.js const { hourlyWageList, monthlyPayList } = require('../../utils/util') Component({ /** * 组件的属性列表 */ properties: { payType: { type: String, value: 'monthly' // hourly/monthly }, income:{ type:String, value:'' } }, /** * 组件的初始数据 */ data: { multiArray: [], classArray: [], multiIndex: [0, 0], current: '请选择', }, observers: { 'payType'(type) { const config = type === 'hourly' ? hourlyWageList : monthlyPayList this.setData({ multiArray: config.multiArray, classArray: config.classArray, multiIndex: config.multiIndex, current: config.current }) } }, /** * 组件的方法列表 */ methods: { changeMulti(e) { const [col1, col2] = e.detail.value; const firstValue = this.data.multiArray[0][col1]; const displayValue = firstValue === '面议' ? firstValue : `${firstValue}-${this.data.multiArray[1][col2]}`; this.setData({ multiIndex: e.detail.value, current: displayValue }); this.triggerEvent('change', { value: displayValue }); }, nocolumnchange(e) { const column = e.detail.column const value = e.detail.value const newData = { multiIndex: [...this.data.multiIndex], multiArray: [...this.data.multiArray] } if (column === 0) { newData.multiArray[1] = this.data.classArray[value] newData.multiIndex = [value, 0] this.setData(newData) } } } })
07-12 - 代码在pages页面中,能够正常显示,在components组件中,就不显示了?
[图片] 如图,点击跳转到左侧导航栏页面,选中了之后点击确认,返回时,不显示,代码在pages页面时,能够正常显示选中的项。代码在components组件中时,不显示选中的项。这是什么问题?下面代码是一部分代码,更详细的见代码片段 <!--pages/jobs/add/add-position/add-position.wxml--> <view class="add-position-group"> <form bindsubmit="onSubmitEvent"> <expectation></expectation> <button form-type="submit" type="primary" class="sunbmit-btn">保存配置</button> </form> </view> // pages/jobs/add/add-position/add-position.js const app = getApp(); const db = wx.cloud.database(); const _ = db.command; Page({ /** * 页面的初始数据 */ data: { }, /** * 生命周期函数--监听页面加载 */ async onLoad(options) { await app.loadUserInfo(); }, /** * 保存配置事件 */ onSubmitEvent(event) { console.log(event) const that = this; // 自动设置职位类型 this.autoSetExpectationName(); // 检查expectationName是否为空 if (!that.data.expectationName) { wx.showToast({ title: '请选择职位类型', icon: 'none' }); return; } const uniqueid = Date.now() + Math.floor(Math.random()*100000); const expectation = { id:uniqueid, expectationName: that.data.expectationName, expectationCity: that.data.expectationCity, expectationPosition: that.data.formData.jobs, expectationIndustry: that.data.formData.industries, } console.log(expectation) db.collection("resume").where({ _openid: app.globalData.openid }).update({ data:{ expectation: _.push(expectation), }, success:res=>{ console.log('添加成功', res) wx.showToast({ title: '保存成功', icon: 'success' }) setTimeout(() => wx.navigateBack({}), 1500); } }) }, }) <!--components/expectation/expectation.wxml--> <view class="expectation-container"> <view class="title">添加求职期望</view> <view class="add-content">添加的求职期望不同,推荐的职位也不同</view> <view class="add-list"> <view class="add-list-title">职位类型</view> <view class="list-content" wx:if="{{showPartTimeOnly}}"> <view class="fixed-text">{{natures[0].name}}</view> </view> <view class="list-content" wx:elif="{{showFullTimeOnly}}"> <view class="fixed-text">{{natures[1].name}}</view> </view> <view class="list-content" wx:else> <selector name="expectationName" array="{{natures}}" arrays="{{natures[0].name}}" bindcarporate="onCorporateEvent"></selector> </view> </view> <view class="add-list"> <view class="add-list-title">其他期望城市</view> <view class="list-content"> <city name="expectationCity" class="city" placeholder="{{expectationCity}}" bindCity="onCityEvent"></city> </view> </view> <view class="add-list"> <view class="add-list-title">期望职位</view> <view class="add-list-content" bindtap="onJobExpectations"> <input class="add-list-input" wx:if="{{!formData.jobsCount}}" placeholder="请选择期望职位" type="text" /> <view wx:else class="add-list-text"> <block wx:for="{{formData.jobs}}" wx:key="index"> <view class="text-list"> <view name="expectationPosition" class="tag">{{item}}</view> <view class="jobCount" wx:if="{{formData.jobsCount > 1}}">、</view> </view> </block> </view> <icon class="icon"></icon> </view> </view> <view class="add-list"> <view class="add-list-title">期望行业</view> <view class="add-list-content" bindtap="onIndustryList"> <input class="add-list-input" wx:if="{{!formData.industriesCount}}" placeholder="请选择期望行业" type="text" /> <view wx:else class="add-list-text"> <block wx:for="{{formData.industries}}" wx:key="index"> <view class="text-list"> <view name="expectationIndustry" class="tag">{{item}}</view> <view class="jobCount" wx:if="{{formData.industriesCount > 1}}">、</view> </view> </block> </view> <icon class="icon"></icon> </view> </view> <view class="add-list"> <view class="add-list-title">薪资要求</view> <view class="list-content"> <selector-tow name="income" wx:if="{{showPartTimeOnly || expectationName=='全职'}}" bindcarporate="onincomeEvent"></selector-tow> <selector-tow name="income" wx:elif="{{showFullTimeOnly || expectationName=='临/兼职'}}" bindcarporate="onincomeEvent"></selector-tow> </view> </view> </view> // components/expectation/expectation.js const app = getApp(); const db = wx.cloud.database(); Component({ /** * 组件的属性列表 */ properties: {}, /** * 组件的初始数据 */ data: { natures: [{id: 0,name: '全职'}, {id: 1,name: '临/兼职'}], expectationCity: '请选择工作城市', showPartTimeOnly: false, showFullTimeOnly: false, expectationName: '', formData: { jobs: [], jobsCount: 0, industries: [], industriesCount: 0 }, }, /** * 组件生命周期 */ lifetimes: { attached() { // 组件加载时获取数据 this.getExpectationField(); this.autoSetExpectationName() } }, /** * 组件的方法列表 */ methods: { /** * 职位类型选择事件 */ onCorporateEvent(event) { console.log(event) this.setData({ expectationName: event.detail.index }) }, /** * 固定职位类型 */ autoSetExpectationName: function () { console.log("showPartTimeOnly", this.data.showPartTimeOnly) console.log("showFullTimeOnly", this.data.showFullTimeOnly) if (this.data.showPartTimeOnly) { this.setData({ expectationName: '全职' // 注意:这里根据你的显示逻辑可能需要调整 }); } else if (this.data.showFullTimeOnly) { this.setData({ expectationName: '临/兼职' // 注意:这里根据你的显示逻辑可能需要调整 }); } // 如果两者都为false,则expectationName将由选择器设置 }, /** * 城市选择事件 */ onCityEvent(event) { console.log(event); var that = this; var index = event.detail.index; that.setData({ expectationCity: index, }) }, /** * 期望职位点击事件 */ onJobExpectations(e) { console.log(e) const selected = encodeURIComponent( JSON.stringify(this.data.formData.jobs) ); console.log(selected) console.log(this.data.formData.jobs) wx.navigateTo({ url: `/pages/position-list/position-list?selected=${selected}&type=position` }); }, /** * 期望行业点击事件 */ onIndustryList() { const selected = encodeURIComponent( JSON.stringify(this.data.formData.industries) ); wx.navigateTo({ url: `/pages/industry-list/industry-list?selected=${selected}&type=industry` }); }, /** * 薪资要求选择事件 */ onIncomeEvent(event) { const index = event.detail.value; this.setData({ incomeIndex: index, selectedIncome: this.data.incomeOptions[index] }); }, /** * 获取数据 */ async getExpectationField() { try { const expectationsRes = await db.collection("resume").where({ _openid: app.globalData.openid, }).field({ expectation: true, _id: false, }).get(); console.log("获取期望字段数据", expectationsRes.data); // 检查是否获取到数据 if (expectationsRes.data.length === 0) { console.log("没有找到期望字段数据"); return; } // 获取expectation数组 const expectationValues = expectationsRes.data[0].expectation || []; console.log("获取期望值数组", expectationValues); // 处理数据并更新状态 this.processExpectationData(expectationValues); // 保存完整数据到data中 this.setData({ // posimes: posimesRes, expectationValues: expectationValues }); } catch (error) { console.error("获取数据失败:", error); wx.showToast({ title: '获取数据失败', icon: 'none' }); } }, /** * 处理期望数据并更新显示状态 */ processExpectationData(expectationValues) { let fullTimeCount = 0; let partTimeCount = 0; // 统计全职和临/兼职数量 expectationValues.forEach(item => { if (item.expectationName === '全职') { fullTimeCount++; } else if (item.expectationName === '临/兼职') { partTimeCount++; } }); console.log(`全职数量: ${fullTimeCount}, 临/兼职数量: ${partTimeCount}`); // 根据数量关系设置显示状态 this.setData({ showFullTimeOnly: fullTimeCount >= 5 && partTimeCount < 5, showPartTimeOnly: partTimeCount >= 5 && fullTimeCount < 5 }); // 如果显示选择器,初始化选择值 if (!this.data.showFullTimeOnly && !this.data.showPartTimeOnly) { if (expectationValues.length > 0) { const item = expectationValues[0]; const natureIndex = this.data.natures.findIndex(n => n.name === item.expectationName); if (natureIndex !== -1) { this.setData({ natureIndex, expectationName: item.expectationName }); } } } } }, processExpectationData: function (expectationValues) { let fullTimeCount = 0; let partTimeCount = 0; // 统计全职和临/兼职数量 expectationValues.forEach(item => { if (item.expectationName === '全职') { fullTimeCount++; } else if (item.expectationName === '临/兼职') { partTimeCount++; } }); console.log(`全职数量: ${fullTimeCount}, 临/兼职数量: ${partTimeCount}`); // 根据数量关系设置显示状态 this.setData({ showFullTimeOnly: fullTimeCount >= 5 && partTimeCount < 5, showPartTimeOnly: partTimeCount >= 5 && fullTimeCount < 5 }); // 如果显示选择器,初始化选择值 if (!this.data.showFullTimeOnly && !this.data.showPartTimeOnly) { this.setData({ selectedNature: expectationValues.length > 0 ? expectationValues[0].expectationName : '全职' }); } } })
07-07 - 截取地址中的市区字段展示在页面上如何做?
[图片][图片][图片] 如上三张图,是数据库保存的地址,想要实现,在页面中只显示市和区,其他的不显示,用WXS如何实现?
06-26 - 文字安全检测不管填什么内容都提示说有风险,这是什么问题?
文字安全内容检测:下面的代码中 body: JSON.stringify({ intro:intro, // 不管填入什么内容,都提示有风险 // content: content // 如果用content,就正常发布信息 }),这是什么问题?求大神指点 // 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init(); const db = cloud.database(); const got = require("got"); const APPID = ""; const APPSECRT = ""; const TOKEN_URL = "" const CHECK_URL = ""; // 云函数入口函数 exports.main = async (event, context) => { const wxContext = cloud.getWXContext() const openid = wxContext.OPENID; const name = event.name; const gender = event.gender; const age = event.age; const nativePlace = event.nativePlace; const duration = event.duration; const phone = event.phone; const intro = event.intro; console.log("自我介绍",intro) //内容安全检查 const tokenResp = await got(TOKEN_URL); const tokenBody = JSON.parse(tokenResp.body); const token = tokenBody.access_token; const checkResp = await got(CHECK_URL + token, { body: JSON.stringify({ intro:intro, // 不管填入什么内容,都提示有风险 // content: content // 如果用content,就正常发布信息 }) }); const checkBody = JSON.parse(checkResp.body); const errcode = checkBody.errcode; if (errcode == 0) { return await db.collection("resume").add({ data: { _openid:openid, name : name, gender : gender, age : age, nativePlace : nativePlace, duration : duration, phone : phone, intro : intro, } }) } else { return { "errcode": 1, "errmsg": "您的微博有风险,请修改后再发布!" } } } <!--pages/relase/relase.wxml--> <view class="resume-title-group"> <view class="title">自我介绍</view> <textarea class="resume-content" name="intro" type="text" placeholder="您的自我介绍" /> </view> // pages/relase/relase.js onSubmitEvent(event){ console.log(event) const that = this; const name = event.detail.value.name;// 名字 const gender = that.data.gender;// 性别 const age = event.detail.value.age;// 年龄 const nativePlace = event.detail.value.nativePlace; // 籍贯 const duration = event.detail.value.duration;// 年限 const phone = event.detail.value.phone;// 手机号码 // const content = event.detail.value.content; // 自我介绍 const intro = event.detail.value.intro; // 自我介绍 console.log("自我介绍",intro) wx.showLoading({ title: "正在发表中..." }); wx.cloud.callFunction({ name: "resume", data: { name : name,// 名字 gender : gender,// 性别 age : age,// 年龄 nativePlace : nativePlace, // 籍贯 duration : duration,// 年限 phone : phone,// 手机号码 intro : intro, // 自我介绍 }, success: res => { console.log(res) const _id = res.result._id; if (_id) { wx.hideLoading(); wx.showToast({ title: "恭喜!发送成功!", }) setTimeout(function () { wx.navigateBack({ // delta:1 }) }, 800) } else { wx.showToast({ title:res.result.errmsg, icon: 'none' }) } } }) },
06-17 - 在页面中能够显示选中的数量,代码写在组件中,就没有显示,是什么原因?
做了个筛选的功能,把代码写在页面中的时候,能够正常显示选中的数量,如图1。当代码写在components组件中时,就没有显示选中的数量。如图2,怎么解决?求大神帮忙 [图片][图片] <!--pages/jobs/index/index.wxml--> <view class="tabbar-group"> <segment class="tabbar-list" items="{{items}}" result="{{result}}" binditemchengde="onItemChengdeEvent" defaultIndex="0"> <view slot="0" class="segment-page all-page"> </view> <view slot="1" class="segment-page new-page"> <view>2</view> </view> <view slot="2" class="segment-page near-page"> <view>3</view> </view> </segment> </view> 组件代码 <!--components/segment/segment.wxml--> <view class="segment-group"> <view class="segment-header"> <view class="segment-list"> <block wx:for="{{items}}" wx:key="item"> <view class="segment-item actvie" wx:if="{{currentIndex === index}}" bind:tap="onItemTapEvent" data-index="{{index}}">{{item}}</view> <view class="segment-item" wx:else bind:tap="onItemTapEvent" data-index="{{index}}">{{item}}</view> </block> </view> <view class="tabbar-right"> <city class="city"></city> <view class="filter-group" bind:tap="onFilter"> <view class="filter-title">筛选</view> <view class="felter-symbol" wx:if="{{formData.jobsCount}}">·</view> <view class="filter-number">{{formData.jobs}}</view> <icon class="icon"></icon> </view> </view> </view> <view class="segment-body"> <block wx:for="{{items}}" wx:key="item"> <slot name="{{index}}" wx:if="{{currentIndex===index}}"></slot> </block> </view> </view> // components/segment/segment.js Component({ options:{ multipleSlots:true }, /** * 组件的属性列表 */ properties: { items: { type: Array, value: [] }, defaultIndex:{ type:Number, value:0 } }, /** * 组件的初始数据 */ data: { currentIndex:0, formData: { jobs: [], jobsCount: '', } }, lifetimes:{ attached(){ var that = this; that.setData({ currentIndex:that.properties.defaultIndex }) } }, /** * 组件的方法列表 */ methods: { onItemTapEvent(event){ var index = event.target.dataset.index; this.setData({ currentIndex:index }) var detail = {"index":index}; var options = {} this.triggerEvent('itemchengde',detail,options); }, onFilter(e){ const selectedData = this.data.formData.jobs; console.log(this.data.formData.jobsCount); const selected = selectedData.length > 0 ? encodeURIComponent(JSON.stringify(selectedData)) : encodeURIComponent(JSON.stringify([])); console.log(selected); wx.navigateTo({ url: `/pages/position-list/position-list?selected=${selected}&type=position` }); }, } })
06-12 - 右侧内容滚动时,左侧菜单没有切换?
自定义左侧导航栏,在页面中可以正常实现,把代码复制到components组件中,右侧内容滚动时,左侧菜单没有切换,console.log(rects)打印为空,这是什么情况?求大师指点 const list = require('../../utils/util.js') Component({ /** * 组件的属性列表 */ properties: { }, /** * 组件的初始数据 */ data: { height: 0, //页面高度 rpx ratio: 0, //rpx,px转化比 tid: 1, lid: 1, heightArray: [], // 存储右侧各区块高度 isSelected: false, selectedCount: 0, selectedList: [], sectionHeights: [], list:list }, lifetimes: { ready() { this.pageheight(); this.calculateHeights(); // setTimeout(() => this.calculateHeights(), 500) } }, /** * 组件的方法列表 */ methods: { /** * 获取页面高度 */ pageheight() { const windowInfo = wx.getWindowInfo() const btnGroupHeight = 120 // 底部按钮高度(rpx) const ratio = 750 / windowInfo.windowWidth const height = (windowInfo.windowHeight * ratio) - btnGroupHeight console.log(height) this.setData({ height: height, // 新高度字段 ratio: ratio }) }, /** * 获取元素距离顶部的位置 */ calculateHeights() { const that = this; const query = wx.createSelectorQuery() ;//创建节点查询器 console.log(query) query.selectAll('.right-group').boundingClientRect(rects => { console.log(rects) const systemInfo = wx.getWindowInfo(); const topOffset = 170 / that.data.ratio; // 顶部固定区域高度 console.log(topOffset) const heights = rects.map(rect => Math.floor(rect.top - topOffset + systemInfo.windowHeight * that.data.ratio / 750) ); console.log(heights) that.setData({ heightArray: heights }); }).exec(); }, /** * 左侧点击事件 */ changeTab(e) { console.log(e) const that = this; const id = e.currentTarget.dataset.id; that.setData({ tid: id, lid: id }) }, /** * 滚动监听 */ scrollFloor(e) { const scrollTop = e.detail.scrollTop const { heightArray } = this.data for (let i = 0; i < heightArray.length; i++) { if (scrollTop < heightArray[i]) { this.setData({ tid: this.data.list[i > 0 ? i - 1 : 0].id , }) break } } }, /** * 选中事件 */ toggleSelection(e) { console.log(e) const { catindex, subindex, posindex } = e.currentTarget.dataset console.log({ catindex, subindex, posindex }) // 边界检查 if ( catindex < 0 || catindex >= this.data.list.length || subindex < 0 || !this.data.list[catindex]?.listtitle || subindex >= this.data.list[catindex].listtitle.length ) return const path = `list[${catindex}].listtitle[${subindex}].position[${posindex}].selected` const isSelected = !this.data.list[catindex].listtitle[subindex].position[posindex].selected const selectedItem = { name: this.data.list[catindex].listtitle[subindex].position[posindex].name, catindex, subindex, posindex } let selectedList = [...this.data.selectedList] if (isSelected) { if (selectedList.length >= 5) { wx.showToast({ title: '最多选择5项', icon: 'none' }) return } selectedList.push(selectedItem) } else { selectedList = selectedList.filter(item => !(item.catindex === catindex && item.subindex === subindex && item.posindex === posindex) ) } this.setData({ [path]: isSelected, selectedCount: selectedList.length, selectedList }) }, // 删除事件 removeBenefit(e) { console.log(e) const { catindex, subindex, posindex } = e.currentTarget.dataset console.log({ catindex, subindex, posindex }) // 更新列表状态 const path = `list[${catindex}].listtitle[${subindex}].position[${posindex}].selected` const selectedList = this.data.selectedList.filter(item => !(item.catindex === catindex && item.subindex === subindex && item.posindex === posindex) ) this.setData({ [path]: false, selectedCount: selectedList.length, selectedList }) }, // 新增确认按钮点击事件 confirmSelection() { const pages = getCurrentPages() const prevPage = pages[pages.length - 2] // 获取A页面实例 // 构造选中职位名称数组 const selectedJobs = this.data.selectedList.map(item => item.name) // 更新A页面数据 prevPage.setData({ 'formData.jobs': selectedJobs, 'formData.jobCount': selectedJobs.length }) // 返回A页面 wx.navigateBack() }, } })
05-30 - 左侧导航栏菜单切换时都滑动到顶部,如何在触底时再滑动?
做了一个左侧导航栏,想要实现效果,当点击左侧导航栏菜单时,切换菜单,不滑动,当点击可视区域底部的菜单时,往上滑动一个菜单。再就是右侧内容滑动到对应区域,左侧菜单栏切换,但不是每次切换一个菜单就滑动到顶部,同样是,右侧滑动到对应的区域,左侧菜单切换,当左侧切换到可视区域的底部时,往上滑动一个菜单项。求指教。具体代码见代码片段
05-19 - 双角色tabbar底部导航栏,切换和真机不一样,什么问题?
模拟器上显示正常,真机上的问题是,在首页进入论坛角色,点击我的页面中去社区按钮,页面跳转了,tabbar没有切换,当在首页进入社区角色,点击我的页面中去论坛的按钮,页面跳转了,tabbar没有切换,试了无数次,都是这样的问题。这是什么问题,开发工具。1.05版本的
04-13 - 双角色tabbar底部导航栏,切换不正常,什么原因?
双角色tabbar底部导航栏,在首页进入,都是正常,在角色中我的页面设定了“去社区”或者“去论坛”两个切换按钮,当点击这个按钮时,切换成功,但是在点击tabbar中的按钮时,多点几次,在论坛角色的时候,就切换到了社区的角色,又或者论坛角色和社区角色来回切换,尤其在点击“我的”按钮时,这个问题是什么问题,怎么解决? 担心有些时候,代码片段打不开,复制部分代码如下: 首页index-wxml代码: <view class="title"> <view class="jobs-group"> <image class="jobs-img" src="../../images/jobs.jpeg"></image> <button class="jobs" bindtap="goto" data-type="0">论坛</button> </view> <view class="separate"></view> <view class="jobs-group"> <image class="jobs-img" src="../../images/enterprise.jpg"></image> <button class="jobs" bindtap="goto" data-type="1">社区</button> </view> </view> js代码: Page({ goto(e){ console.log(e); let type = e.currentTarget.dataset.type; //把权限存储到缓存当中 wx.setStorageSync('user',type); if(type == "0"){ wx.switchTab({ url:'../jobs/index/index' }) }else{ wx.switchTab({ url:'../enterprise/index/index' }) } }, }) <!--custom-tab-bar/index.wxml--> <view class="tab-bar"> <view class="tab-bar-item" wx:for="{{selectList}}" wx:key="index" data-index="{{index}}" data-path="{{item.pagePath}}" data-selected="{{item.selected}}" bindtap="onwidthTap"> <image class="cover-image" src="{{selected === item.selected ? item.selectedIconPath : item.iconPath}}"></image> <view class="cover-view {{selected === item.selected ? 'active' : ''}}" >{{item.text}}</view> </view> </view> <view class="indicator-border"></view> <view class="indicator"> <view class="indicator-item"> <image class="indicator-image" src="/images/jia.png"></image> <view class="indicator-item-text">发布</view> </view> </view> // custom-tab-bar/index.js Component({ data: { allList: [ [{ "pagePath": "/pages/jobs/index/index", "iconPath": "/images/me-gray.png", "selectedIconPath": "/images/me-green.png", "text": "论坛", "selected": "0" }, {}, { "pagePath": "/pages/jobs/me/me", "iconPath": "/images/me-gray.png", "selectedIconPath": "/images/me-green.png", "text": "我的", "selected": "1" } ], [{ "pagePath": "/pages/enterprise/index/index", "iconPath": "/images/me-gray.png", "selectedIconPath": "/images/me-green.png", "text": "社区", "selected": "2" }, {}, { "pagePath": "/pages/enterprise/me/me", "iconPath": "/images/me-gray.png", "selectedIconPath": "/images/me-green.png", "text": "我的", "selected": "3" } ] ], selectedList: [] }, /** * 生命周期的方法:当组件被加载的时候调用 */ lifetimes:{ attached(){ if(wx.getStorageSync('user') == '0'){ this.setData({ selectList:this.data.allList[0] }) }else{ this.setData({ selectList:this.data.allList[1] }) } }, show(){ this.updateTabbar(); } }, /** * 组件的方法列表 */ methods: { onwidthTap(e) { console.log(e); let path = e.currentTarget.dataset.path; let selected = e.currentTarget.dataset.selected; wx.switchTab({ url:path }) }, updateTabbar(){ const userType = wx.getStorageSync('user') || '0'; this.setData({ selectList:this.data.allList(userType) }) } } }) <!--pages/jobs/me/me.wxml--> <view class="switch-group" bindtap="onSwitch"> <image class="switch-image" src="../../../images/switch.png"></image> <view class="switch-text">去社区</view> </view> // pages/jobs/me/me.js Page({ onSwitch(){ wx.setStorageSync('user','1'); wx.switchTab({ url:'../../enterprise/index/index' }); //强制更新自定义tabbar(需配合组件改造) const tabbar = this.getTabBar(); tabbar.setData({ selectList: tabbar.data.allList[0] }); }, onShow() { if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: "1" }) } }, }) <!--pages/enterprise/me/me.wxml--> <view class="switch-group" bindtap="onSwitchEvent"> <image class="switch-image" src="../../../images/switch.png"></image> <view class="switch-text">去论坛</view> </view> // pages/enterprise/me/me.js Page({ onSwitchEvent(){ wx.setStorageSync('user','0'); wx.switchTab({ url:'../../jobs/index/index' }); //强制更新自定义tabbar(需配合组件改造) const tabbar = this.getTabBar(); tabbar.setData({ selectList: tabbar.data.allList[0] }); }, /** * 生命周期函数--监听页面显示 */ onShow() { if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: "3" }) } }, })
04-12