后台数据库字段创建
- createTime 创建时间 date
- creatorId 创建人编号 bigint
- updator 更新人 varchar
- del 是否删除 tinyint 0为正常,1为删除
时间 datetime
排序 sort 《 1 2 3 4 5 6 》 用于后续排序使用
渲染列表由用户决定有多少个的情况
示例图片

我们不知道管理员会添加多少个字段,
对于渲染列表由用户决定有多少个的情况【比如管理员自己添加字段,用户自己输入值】,这种情况
我们不应该用变量去接收这个值,
我们可以在得到这个渲染数据的时候,对这个数据统一的加上一个值
Value,这样我们每次渲染或者赋值的时候,我们就可以通过对这个
item.value赋值,来做到,统一管理 items 列表项中,每一项的值。
如果出现,选项中出现单选多选的情况且单选多选会有确定取消按钮的情况
即当前列表中 还存在一个列表的情况
我们应该将这个value 定义为一个数组,
我们整个页面的 修改存在于一个临时的数组变量中
每次点击确定的时候我们在讲这个临时的数组变量保存到我们本身的
item.value中
拍照图片上传到小程序中
我们拍照会得到一个临时的路径
我们将这个路径存到后台,会返回给一个正常的路径
然后将这个正常的路径渲染
保存图片到相册逻辑
uni.downloadFile(OBJECT)
下载文件资源到本地,客户端直接发起一个 HTTP GET 请求,返回文件的本地临时路径。
得到临时路径之后
uni.saveImageToPhotosAlbum(OBJECT)
保存图片到系统相册。
const saveImage = function(e) {
uni.downloadFile({
url: e,
success: function(res) {
console.log(res);
//图片保存到本地
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function(data) {
uni.showToast({
title: '保存成功',
icon: 'success',
duration: 2000
})
},
fail: function(err) {
console.log(err);
if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
console.log("当初用户拒绝,再次发起授权")
uni.openSetting({
success(settingdata) {
console.log(settingdata)
if (settingdata.authSetting[
'scope.writePhotosAlbum']) {
console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
} else {
console.log('获取权限失败,给出不给权限就无法正常使用的提示')
}
}
})
}
},
complete(res) {
console.log(res);
}
})
}
})
}
组合框,下拉框,三级联动,等等等等
能使用数字就不适用true或者false
可以使用select_ing :0/1/2 -1为下拉
嵌套格式全部使用这种格式书写
optionitems: [{
text: '商品类别',
value: "a",
children:[
{
text:'1',
value:'1'
}
]
}]
登录逻辑
Login() {
this.loginBefore()
},
loginBefore() {
var _this = this;
uni.getUserProfile({
desc: '用于完善会员资料',
success: function(infoRes) {
// console.log(infoRes, '微信的全部信息');
console.log(infoRes.userInfo);
console.log('____');
uni.setStorage({
key: 'infoRes',
data: infoRes,
success: function() {
console.log('infoRes--success');
}
});
uni.showLoading({});
uni.login({
provider: 'weixin',
success: function(info) {
console.log(info, 'info');
// info.code 就是唯一码
const db = wx.cloud.database();
db.collection('userInfo').add({
data: {
code: info.code,
}
})
.then(res => {
console.log(res, 'info.code 存储成功')
// 信息存到内存中
// 存储 OpenId
_this.createOpenId(res)
// 存储并获取微信里的信息
_this.getUserInfo(infoRes, res)
setTimeout(res => {
uni.hideLoading()
const isopenid = uni.getStorageSync('OpenId')
if (isopenid) {
uni.showToast({
title: "登陆成功",
duration: 2000,
})
_this.init()
_this.$forceUpdate()
} else {
uni.clearStorage()
uni.showToast({
title: "登陆失败",
duration: 2000,
icon: "error"
})
}
}, 600)
})
}
});
},
fail(res) {
console.log('fail', res);
}
});
},
// 获取 openId 并存储到本地
createOpenId(value) {
console.log(value._id);
const db = wx.cloud.database();
db.collection('userInfo').doc(value._id).get({
success: (res => {
console.log(res, '获取openID');
this.openId = res.data._openid
console.log(this.openId, 'openid 不保存本地能不能成功?');
uni.setStorageSync('OpenId', this.openId);
this.removeSomeUserInfo(res)
})
})
},
//获取用户的微信中的基本信息
getUserInfo(infoRes, res) {
// 数据库存储
const db = wx.cloud.database();
// //存储之前把数据库之前的冗余记录给删除掉
// db.collection('userInfo').where({
// _openid: uni.getStorageSync('OpenId')
// }).remove()
// 存储数据库
db.collection('userInfo').where({
_id: res._id
}).update({
data: {
// openId: uni.getStorageSync('OpenId'),
headUrl: infoRes.userInfo.avatarUrl,
nickName: infoRes.userInfo.nickName,
dateTime: this.getDataTime(),
data: { ...infoRes.userInfo }
// province: infoRes.userInfo.province,
// city: infoRes.userInfo.city,
}
})
.then(res => {
console.log(res, '基本信息存储成功')
})
},
init() {
wx.cloud.init({
env: "guoguo-tools-7gys61wtaa51feb4"
})
const openId = uni.getStorageSync('OpenId');
this.openId = openId
//如果有openID 的初始化操作
if (openId) {
const infoRes = uni.getStorageSync('infoRes');
this.headUrl = infoRes.userInfo.avatarUrl
this.nickName = infoRes.userInfo.nickName
console.log('登陆成功');
// 判断是不是管理员
const db = wx.cloud.database();
db.collection('administrator').get({
success: (res => {
console.log('管理员的信息', res);
this.administratorList = res.data
this.administratorList.forEach(res => {
if (openId === res.subOpenid) {
this.isAdministrator = true
}
})
})
})
}
},