- 自定义的component下拉菜单组件如何插入到数据库中?
如图下拉菜单,因数据太多,不想用微信开发中的多列选择器区完成这个功能,不够直观,所以想用自定义的组件,该如何插入到数据库中,求大师帮助。 [图片] component中wxlm代码: <!--下拉选框--> <view class="list-select"> <view class="position">招聘职位</view> <view class="select-box"> <view class="select {{shownavindex == 1? 'active' : ''}}" bindtap="list" data-nav="1"> <view class="content" >{{quanbu_name}}</view> </view> </view> <view class="icon-group"> <view class="select {{shownavindex == 1? 'active' : ''}}" bindtap="list" data-nav="1"> <icon class="icon"></icon> </view> </view> </view> <!--选择工种标签--> <view class="gongzhong {{gzopen ? 'slidown' : 'slidup'}} {{gzshow ? 'disappear':''}}"> <view class="gz gz-left"> <view class="view {{select1 == index ? 'current1' : ''}}" wx:for="{{gz}}" wx:key="key" bindtap="gzselectLeft" data-index='{{index}}'> {{index}} </view> </view> <view class="gz gz-right"> <view class="view {{select2 == item?'current2':''}}" wx:for="{{gzright}}" wx:key="key" wx:if="{{gzright}}" bindtap='gzselectRight' data-index="{{item}}"> <text>{{item}}</text> </view> </view> <view class='form-btn'> <button class='btn-reset' bindtap='gzEmpty'>重置</button> <button class='btn-submit' bindtap='gzFilter'>确定</button> </view> <view class="fullbg {{isfull ?'fullopacity':''}}" bindtap="hidebg"></view> </view> js代码: Component({ /** * 组件的属性列表 */ properties: { }, /** * 组件的初始数据 */ data: { quanbu_name:"请选择您的招聘职位", gz:{ "计算机/互联网/通信/电子":["技术工程师","机械设计","PLC编程", "车工","焊工","铣工","磨床","","车工",], "后端开发":["Java开发工程师","PHP开发工程师","C/C++开发工程师", "Python开发工程师","NET开发工程师","C#开发工程师","Ruby开发工程师","Go开发工程师","大数据开发工程师","Hadoop工程师","爬虫开发工程师","脚本开发工程师","多媒体开发工程师","GIS开发工程师","全栈开发工程师","ERP开发工程师","区块链开发","高级软件工程师","软件工程师","系统架构设计师","系统分析员","技术文员/助理","技术文档工程师","其他",], "自动化技术":["钳工","焊工","电工","调试",], }, gzopen: false, //选择工种筛选弹窗 gzshow: true, isfull: false, select1: '', //选中后的第二个子菜单,默认显示工种下的子菜单 select2: '', //选择部分的中间 shownavindex: '', gzIndex: 0, }, onLoad: function (options) { this.setData({ select:!this.data.select }) }, /** * 组件的方法列表 */ methods: { // 列表下拉框是否隐藏 list: function(e) { if (this.data.gzopen) { this.setData({ content: this.data.nv, gzopen: false, gzshow: false, isfull: false, shownavindex: 0 }) } else { this.setData({ gzopen: true, gzshow: false, isfull: true, shownavindex: e.currentTarget.dataset.nav }) } }, // 点击灰色背景隐藏所有的筛选内容 hidebg: function(e) { this.setData({ gzopen: false, gzshow: true, isfull: false, shownavindex: 0, }) }, // 选择工种第一栏选择内容 gzselectLeft: function(e) { // console.log(e); var name=e.currentTarget.dataset.index; // console.log('用户选中左边菜单栏的索引值是:'+e.target.dataset.index); this.setData({ quanbu_name:name, gzright:this.data. gz[e.currentTarget.dataset.index], select1: e.target.dataset.index, }); }, // 选择工种右边栏选择的内容 gzselectRight: function(e) { // console.log(e); var name=e.currentTarget.dataset.index; // console.log(''+e.currentTarget.dataset.index); this.setData({ quanbu_name:name, select2: e.currentTarget.dataset.index }); }, // 选择工种清空筛选项 gzEmpty: function() { this.setData({ select1: '', select2: '-1' }) }, // 选择工种筛选项后,点击提交 gzFilter: function() { // console.log('选择的一级选项是:' + this.data.select1); // console.log('选择的二级选项是:' + this.data.select2); // 隐藏选择工种下拉框 this.setData({ gzopen: false, gzshow: false, isfull: false, shownavindex: 0 }) }, } }) ppage中wxlm代码: <selecttwo wx:for-item="{{selecttwo}}" ></selecttwo>
2022-08-24 - flex-direction:row无效,是怎么回事?
在wxml中,如果把ms-text的view改成text,flex-direction:row就起作用,但是三角靠右移动不了,就像图2一样,这是什么问题?怎么解决 [图片] [图片] wxml代码: <view class="weui-cell"> <view class="weui-cell_hd">工作性质</view> <picker class="weui-cell_bd" name="work" range='{{worknature}}' value="{{worknature[list1]}}" bindchange="onWorkEvent"> <view class='ms-text'>{{worknature[list1]?worknature[list1]:"请选择"}}</view> <icon class="icon"></icon> </picker> </view> wxss代码: .weui-cell{ display:flex; flex-direction:row; align-items:center; margin-top:25rpx; } .weui-cell_hd{ display:flex; flex-basis:160rpx; font-size:32rpx; } .weui-cell .weui-cell_bd{ display:flex; flex:1; font-size:30rpx; justify-content:center; flex-direction:row; border-bottom:1px solid #cfcece; } .icon { display:flex; display:inline-block; border: 10rpx solid transparent;/*三角形边框*/ border-top: 10rpx solid #666;/*上边框*/ margin-left: 10rpx;/*左边距*/ margin-top: 10rpx;/*右边距*/ margin-right:20rpx; }
2022-08-23 - components组件中下拉菜单是值如何添加到数据库中?
在components中写了一段下拉菜单组件,要如何把下拉菜单中的值添加到数控中去,作为初学者,不知道其中原理,哪位大师给个案例研究下。 [图片] components中组件代码 wxml代码: <view class='ms-content-box'> <view class='ms-content' bindtap='selectToggle'> <view class='ms-text'>{{selectText}}</view> <icon class="icon"></icon> </view> <view class='ms-options' wx:if="{{selectShow}}"> <view wx:for="{{propArray}}" data-index="{{index}}" wx:key='index' class='ms-option' bindtap='setText'>{{item.text || item.value || item}}</view> </view> </view> jsd代码: // components/selectnature/selectnature.js Component({ /** * 组件的属性列表 */ properties: { propArray: { type: Array, value:'' }, }, /** * 组件的初始数据 */ data: { selectShow: false,//初始option不显示 selectText: "请选择",//初始内容 }, /** * 组件的方法列表 */ methods: { //option的显示与否 selectToggle: function () { var nowShow = this.data.selectShow;//获取当前option显示的状态 this.setData({ selectShow: !nowShow }) }, //设置内容 setText: function (e) { var nowData = this.properties.propArray;//当前option的数据是引入组件的页面传过来的,所以这里获取数据只有通过this.properties var nowIdx = e.target.dataset.index;//当前点击的索引 var nowText = nowData[nowIdx].text || nowData[nowIdx].value || nowData[nowIdx];//当前点击的内容 //再次执行动画,注意这里一定,一定,一定是this.animation来使用动画 this.setData({ selectShow: false, selectText: nowText, }) this.triggerEvent('select', nowData[nowIdx]) } } }) pages页面中的代码 wxml代码: <!--pages/release/release-recruit/release-recruit.wxml--> <view class="container"> <form bindsubmit="onSubmitEvent"> <selecttwo wx:for-item="{{selecttwo}}" name="{{position}}"></selecttwo> <view class="weui-cell"> <view class="weui-cell__hd">工作性质</view> <selectnature class="weui-cell__bd" prop-array='{{worknature}}' /> </view> <view class="weui-cell"> <view class="weui-cell__hd">学历要求</view> <selectnature class="weui-cell__bd" prop-array='{{educations}}' /> </view> <view class="introduce-group"> <view class="introduce">职位描述</view> <textarea name="content" class="textarea" placeholder="请输入您的招聘要求"></textarea> </view> <view class="location-group"> <view class="location-title">工作地址</view> <view class="location-title-group" bind:tap="onLocationTap"> <view class="location-name">{{location?location.address:"请填写您的工作地址"}}</view> <image class="arrow" src="../../../images/arrow.png"></image> </view> </view> <view class="input-group"> <import src="../../input/input.wxml" /> <view class="medata"> <block wx:for="{{cccs}}" wx:key="ccc"> <view data-index="{{index}}"> <template is="medata" data="{{...item}}"></template> </view> </block> </view> </view> <button formType="submit">提交</button> </form> </view> js代码: // pages/release/release-recruit/release-recruit.js const db = wx.cloud.database(); const app = getApp(); Page({ /** * 页面的初始数据 */ data: { worknature: [ // "正式工","临时工","个人","团队" {"id": "10","value": "正式工"}, {"id": "21","value": "临时工"}, {"id": "22","value": "个人"}, {'value': '团队'} ], educations:[ {"id": "1","value": "不限"}, {"id": "1","value": "初中"}, {"id": "1","value": "中技/中专"}, {"id": "1","value": "高中"}, {"id": "2","value": "大专"}, {"id": "1","value": "本科"}, {"id": "1","value": "硕士"}, {"id": "1","value": "博士"}, {"id": "1","value": "MBA/EMBA"}, ], cccs:[ {'id':'手机号码','name':'varchar','value':'请输入您的手机号码'}, {'id':'联系人','name':'firstName','value':'请输入您的真实姓名'}, ], location:null, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { const type=options.type; this.setData({ type:type }) this.onLocationTap(); }, /** * 发布事件 */ onSubmitEvent:function(event){ console.log(event); const content = event.detail.value.content; const location=this.data.location; const author=app.globalData.userInfo; wx.showLoading({ title:"正在发表中..." }) // 特3456书yuuo莞6543李zxcz蒜7782法fgnv级 wx.cloud.callFunction({ name:"recruit", data:{ content:content, author:author, location:location, varchar:event.detail.value.varchar, firstName:event.detail.value.firstName, work:this.data.worknature.work }, success:res => { // console.log(res); const _id = res.result._id; if(_id){ wx.hideLoading(); wx.showToast({ title:"恭喜!发送成功!" }); }else{ wx.showToast({ title:res.result.errMsg, }) } } }) }, /** * 打开位置页面 */ openLocationPage:function(){ const that=this; wx.chooseLocation({ success:res=>{ if(res.address){ delete res["errMsg"]; that.setData({ location:res }) } } }) }, /** * 获取位置信息的事件 */ onLocationTap:function(){ const that=this; wx.getSetting({ success:res=>{ console.log(res); const isLocation = res.authSetting['scope.address.userLocation']; if(isLocation){ that.openLocationPage(); }else{ wx.authorize({ scope:"scope.userLocation", success:res=>{ that.openLocationPage(); } }) } } }) },
2022-08-18 - components组件,下拉菜单是值如何添加到数据库中?
作为一个初学者,组件下拉菜单中的值该如何添加到数据库中,不知其原理,哪位大师给个样板研究下。我写的代码显示如图片 [图片] components组件代码: wxl代码: <view class='ms-content-box'> <view class='ms-content' bindtap='selectToggle'> <view class='ms-text'>{{selectText}}</view> <icon class="icon"></icon> </view> <view class='ms-options' wx:if="{{selectShow}}"> <view wx:for="{{propArray}}" data-index="{{index}}" wx:key='index' class='ms-option' bindtap='setText'>{{item.text || item.value || item}}</view> </view> </view> js代码 // components/selectnature/selectnature.js Component({ /** * 组件的属性列表 */ properties: { propArray: { type: Array, value:'' }, }, /** * 组件的初始数据 */ data: { selectShow: false,//初始option不显示 selectText: "请选择",//初始内容 }, /** * 组件的方法列表 */ methods: { //option的显示与否 selectToggle: function () { var nowShow = this.data.selectShow;//获取当前option显示的状态 this.setData({ selectShow: !nowShow }) }, //设置内容 setText: function (e) { var nowData = this.properties.propArray;//当前option的数据是引入组件的页面传过来的,所以这里获取数据只有通过this.properties var nowIdx = e.target.dataset.index;//当前点击的索引 var nowText = nowData[nowIdx].text || nowData[nowIdx].value || nowData[nowIdx];//当前点击的内容 //再次执行动画,注意这里一定,一定,一定是this.animation来使用动画 this.setData({ selectShow: false, selectText: nowText, }) this.triggerEvent('select', nowData[nowIdx]) } } }) pages页面中的代码 wxml代码: <view class="container"> <form bindsubmit="onSubmitEvent"> <selecttwo wx:for-item="{{selecttwo}}" name="{{position}}"></selecttwo> <view class="weui-cell"> <view class="weui-cell__hd">工作性质</view> <selectnature class="weui-cell__bd" prop-array='{{worknature}}' /> </view> <view class="weui-cell"> <view class="weui-cell__hd">学历要求</view> <selectnature class="weui-cell__bd" prop-array='{{educations}}' /> </view> <view class="introduce-group"> <view class="introduce">职位描述</view> <textarea name="content" class="textarea" placeholder="请输入您的招聘要求"></textarea> </view> <view class="location-group"> <view class="location-title">工作地址</view> <view class="location-title-group" bind:tap="onLocationTap"> <view class="location-name">{{location?location.address:"请填写您的工作地址"}}</view> <image class="arrow" src="../../../images/arrow.png"></image> </view> </view> <view class="input-group"> <import src="../../input/input.wxml" /> <view class="medata"> <block wx:for="{{cccs}}" wx:key="ccc"> <view data-index="{{index}}"> <template is="medata" data="{{...item}}"></template> </view> </block> </view> </view> <button formType="submit">提交</button> </form> </view> js代码: // pages/release/release-recruit/release-recruit.js const db = wx.cloud.database(); const app = getApp(); Page({ /** * 页面的初始数据 */ data: { worknature: [ // "正式工","临时工","个人","团队" {"id": "10","value": "正式工"}, {"id": "21","value": "临时工"}, {"id": "22","value": "个人"}, {'value': '团队'} ], educations:[ {"id": "1","value": "不限"}, {"id": "1","value": "初中"}, {"id": "1","value": "中技/中专"}, {"id": "1","value": "高中"}, {"id": "2","value": "大专"}, {"id": "1","value": "本科"}, {"id": "1","value": "硕士"}, {"id": "1","value": "博士"}, {"id": "1","value": "MBA/EMBA"}, ], cccs:[ {'id':'手机号码','name':'varchar','value':'请输入您的手机号码'}, {'id':'联系人','name':'firstName','value':'请输入您的真实姓名'}, ], location:null, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { const type=options.type; this.setData({ type:type }) this.onLocationTap(); }, /** * 发布事件 */ onSubmitEvent:function(event){ console.log(event); const content = event.detail.value.content; const location=this.data.location; const author=app.globalData.userInfo; wx.showLoading({ title:"正在发表中..." }) // 特3456书yuuo莞6543李zxcz蒜7782法fgnv级 wx.cloud.callFunction({ name:"recruit", data:{ content:content, author:author, location:location, varchar:event.detail.value.varchar, firstName:event.detail.value.firstName, work:this.data.worknature.work }, success:res => { // console.log(res); const _id = res.result._id; if(_id){ wx.hideLoading(); wx.showToast({ title:"恭喜!发送成功!" }); }else{ wx.showToast({ title:res.result.errMsg, }) } } }) }, /** * 打开位置页面 */ openLocationPage:function(){ const that=this; wx.chooseLocation({ success:res=>{ if(res.address){ delete res["errMsg"]; that.setData({ location:res }) } } }) }, /** * 获取位置信息的事件 */ onLocationTap:function(){ const that=this; wx.getSetting({ success:res=>{ console.log(res); const isLocation = res.authSetting['scope.address.userLocation']; if(isLocation){ that.openLocationPage(); }else{ wx.authorize({ scope:"scope.userLocation", success:res=>{ that.openLocationPage(); } }) } } }) },
2022-08-18 - 当打开发布页面后,地理位置自动弹出,怎么解决?
当打开发布页面时,如第一张图,就自动弹出了地理位置地图,console.log()时,提示有过点击事件。在input组件中用focus="{{false}},关闭了键盘自动弹出,不然一个页面多个input,键盘就会闪,直到最后一个input组件闪现完成。 [图片][图片][图片] wxml代码: <view class="container"> <form bindsubmit="onSubmitEvent"> <selecttwo></selecttwo> <view class="weui-cell"> <view class="weui-cell__hd">工作性质</view> <selectnature name="work" class="weui-cell__bd" prop-array='{{selectArray}}' /> </view> <view class="weui-cell"> <view class="weui-cell__hd">学历要求</view> <selectnature name="education" class="weui-cell__bd" prop-array='{{xueli}}' /> </view> <view class="introduce-group"> <view class="introduce">职位描述</view> <textarea name="content" class="textarea" placeholder="请输入您的招聘要求"></textarea> </view> <view class="location-group"> <view class="location-title">工作地址</view> <view class="location-title-group" bindtap="onLocationTap"> <view class="location-name">{{location?location.address:"请填写您的工作地址"}}</view> <image class="arrow" src="../../../images/arrow.png"></image> </view> </view> <view class="input-group"> <import src="../../input/input.wxml" /> <view class="medata"> <block wx:for="{{cccs}}" wx:key="ccc"> <view data-index="{{index}}"> <template is="medata" data="{{...item}}"></template> </view> </block> </view> </view> <button formType="submit">提交</button> </form> </view> js代码: /** * 打开位置页面 */ openLocationPage(){ const that=this; wx.chooseLocation({ success:res=>{ if(res.address){ delete res["errMsg"]; that.setData({ location:res }) } } }) }, /** * 获取位置信息的事件 */ onLocationTap:function(event){ const that = this; wx.getSetting({ success:res=>{ const isLocation = res.authSetting['scope.userrLocation']; if(isLocation){ that.openLocationPage(); }else{ wx.authorize({ scope:"scope.userLocation", success:res=>{ that.openLocationPage(); } }) } } }) }, input代码 <template name="medata"> <view class="me-list"> <text>{{id}}</text> <input focus="{{false}}" name="name" placeholder="{{value}}"></input> </view> </template>
2022-08-17 - 获取云函数中的真实时间,wxs中的tiem不是日期类型,在JS中如何转换?
在学习如何获取云函数中真实数据中,其他所有的内容都能够显示出来,唯独时间显示不出来,在百度上查了很多,如果wxs中time不是日期类型,在JS中该如何转换?附上图片和代码如下 [图片][图片] 云函数代码: if(errcode == 0){ return await db.collection("weibo").add({ data:{ content:content, location:location, author:author, images:images, video:video, createTime:db.serverDate(),//插入到数据库的时间 device:device } }) }else{ return await {"errcode":1,"errmsg":"您的信息有风险,请修改再发布!"} } [图片] JS代码: db.collection("weibo").get().then(res=>{ // console.log(res); var date = res.data[0].createTime; // console.log(date); var time = new Date(date).getTime(); console.log(time); this.setData({ time:time }) }) WXS代码: var timeFormat = function(time){ console.log(time); var date = getDate(time); console.log(date); var date_seconds = date.getTime() / 1000 ; var now = getDate(); var now_seconds = now.getTime() / 1000; var timestamp = now_seconds - date_seconds; var timeStr = ""; if(timestamp < 60){ timeStr = "刚刚"; }else if(timestamp >= 60 && timestamp < 60 * 60){ var minutes = parseInt(timestamp / 60); timeStr = minutes + "分钟前"; }else if(timestamp >= 60 * 60 && timestamp < 60 * 60 * 24){ var hours = parseInt(timestamp / 60 / 60); timeStr = hours + "小时前"; }else if(timestamp >= 60 * 60 * 24 && timestamp < 60 * 60 * 24 * 30){ var days = parseInt(timestamp / 60 / 60 / 24); timeStr = days + "天前"; }else{ var year = date.getFullYear(); var month = date.getMonth(); var day = date.getDate(); var hour = date.getHours(); var minute = date.getMinutes(); timeStr = year + "/" + month + "/" + day + " " + hour + ":" + minute; } return timeStr; } module.exports={ timeFormat:timeFormat, }
2022-08-08 - 求助,百度了N次,说db.serverDate()创建的时间。无法在WXML中解析?
wxs时间格式化页面时间是正常的,格式化服务器的时间就显示NaN,百度上查很多,有的说,db.serverDate()创建的时间,在wxml中无法解析。怎么解决? [图片][图片][图片][图片] wxs代码: var timeFormat = function(time){ console.log(time); var date = getDate(time); console.log(date); var date_seconds = date.getTime() / 1000; var now = getDate(); var now_seconds = now.getTime() / 1000; var timestamp = now_seconds - date_seconds; var timeStr = ""; if(timestamp < 60){ timeStr = "刚刚"; }else if(timestamp >= 60 && timestamp < 60 * 60){ var minutes = parseInt(timestamp / 60); timeStr = minutes + "分钟前"; }else if(timestamp >= 60 * 60 && timestamp < 60 * 60 * 24){ var hours = parseInt(timestamp / 60 / 60); timeStr = hours + "小时前"; }else if(timestamp >= 60 * 60 * 24 && timestamp < 60 * 60 * 24 * 30){ var days = parseInt(timestamp / 60 / 60 / 24); timeStr = days + "天前"; }else{ var year = date.getFullYear(); var month = date.getMonth(); var day = date.getDate(); var hour = date.getHours(); var minute = date.getMinutes(); timeStr = year + "/" + month + "/" + day + " " + hour + ":" + minute; } return timeStr; } module.exports={ timeFormat:timeFormat, }
2022-08-05 - 如何获取到数据库的真实时间?
在云函数中使用。db.serverDate()直接获取数据库时间,然后模拟器显示NaN,上传两张图片,和代码片段,请高手帮看看,问题出在哪里。。 数据库集合名称:weibo,集合文件中的时间名称为:cretae_time. 打印wxs代码中console.log(time),提示[WXS Runtime info] undefined ,打印wxs中代码console.log(date);提示[WXS Runtime info] Invalid Date [图片][图片] 代码片段链接:https://developers.weixin.qq.com/s/K3OWYemS7IB2
2022-08-03 - 获取真实是数据,模拟器上时间显示NaN,这是什么问题呢?
https://developers.weixin.qq.com/s/c2B9eemp7OB5 以上是简化后的代码片段,求各位大师帮忙解决下,这是什么问题。谢谢了
2022-08-03 - 获取真实的数据,时间显示NaN/NaN/NaN NaN:NaN,求大师帮忙 ?
[图片] console.log(time)显示信息如下 [图片] wxs代码: var timeFormat = function(time){ // console.log(time); var date = getDate(time); console.log(date); var date_seconds = date.getTime() / 1000; var now = getDate(); var now_seconds = now.getTime() / 1000; var timestamp = now_seconds - date_seconds; var timeStr = ""; if(timestamp < 60){ timeStr = "刚刚"; }else if(timestamp >= 60 && timestamp < 60 * 60){ var minutes = parseInt(timestamp / 60); timeStr = minutes + "分钟前"; }else if(timestamp >= 60 * 60 && timestamp < 60 * 60 * 24){ var hours = parseInt(timestamp / 60 / 60); timeStr = hours + "小时前"; }else if(timestamp >= 60 * 60 * 24 && timestamp < 60 * 60 * 24 * 30){ var days = parseInt(timestamp / 60 / 60 / 24); timeStr = days + "天前"; }else{ var year = date.getFullYear(); var month = date.getMonth(); var day = date.getDate(); var hour = date.getHours(); var minute = date.getMinutes(); timeStr = year + "/" + month + "/" + day + " " + hour + ":" + minute; } return timeStr; } module.exports={ timeFormat:timeFormat, } wxml代码 <!--index.wxml--> <wxs src="../../utils/util.wxs" module="util"/> <view class="container"> <view class="weibo-group" wx:for="{{weibos}}" wx:key="weibos" wx:for-item="weibo"> <view class="user-group"> <image class="avatar" src="{{weibo.author.avatarUrl}}"></image> <view class="right-info"> <view class="username">{{weibo.author.nickName}}</view> <view class="detail-info"> <view class="time">{{util.timeFormat(weibo.cretae_time)}}</view> <view class="from">来自{{weibo.device}}</view> </view> </view> </view> 云函数代码: return await db.collection("weibo").add({ data:{ content:content, location:location, author:author, images:images, video:video, cretae_time:db.serverDate(), device:device } })
2022-08-01