提交 6863b951 编写于 作者: 0 052004122温宸杰

优化后台管理系统,完成消息通知后端接口

上级 af9c2ab2
......@@ -23,7 +23,7 @@ const validator = {
"start_date": {
"rules": [
{
"format": "string"
"format": "datetime"
}
],
"title": "开始时间",
......@@ -32,7 +32,7 @@ const validator = {
"end_date": {
"rules": [
{
"format": "string"
"format": "datetime"
}
],
"title": "结束时间",
......@@ -77,7 +77,7 @@ const validator = {
"contact": {
"rules": [
{
"format": "string"
"format": " /^1[3|4|5|7|8][0-9]\d{8}$/"
}
],
"title": "联系方式",
......
......@@ -8,20 +8,31 @@
<uni-easyinput placeholder="校园活动内容" v-model="formData.content"></uni-easyinput>
</uni-forms-item>
<uni-forms-item name="start_date" label="开始时间">
<uni-easyinput placeholder="校园活动开始时间" v-model="formData.start_date"></uni-easyinput>
<!-- <uni-easyinput placeholder="校园活动开始时间" v-model="formData.start_date"></uni-easyinput> -->
<uni-datetime-picker
type="datetime"
v-model="formData.start_date"
/>
</uni-forms-item>
<uni-forms-item name="end_date" label="结束时间">
<uni-easyinput placeholder="校园活动结束时间" v-model="formData.end_date"></uni-easyinput>
<!-- <uni-easyinput placeholder="校园活动结束时间" v-model="formData.end_date"></uni-easyinput> -->
<uni-datetime-picker
type="datetime"
v-model="formData.end_date"
/>
</uni-forms-item>
<uni-forms-item name="owner_id" label="发布者id">
<uni-easyinput placeholder="校园活动发布者id" v-model="formData.owner_id"></uni-easyinput>
<uni-easyinput placeholder="校园活动发布者id" v-model="formData.owner_id" disabled></uni-easyinput>
</uni-forms-item>
<uni-forms-item name="background_picture" label="背景图片" @click="avatarChoose">
<image :src="formData.background_picture" style="width: 120px; height: 80px;"></image>
<!-- <uni-easyinput placeholder="校园活动背景图片" v-model="formData.background_picture"></uni-easyinput> -->
</uni-forms-item>
<uni-forms-item name="place" label="地点">
<uni-easyinput placeholder="校园活动地点" v-model="formData.place"></uni-easyinput>
<!-- <uni-easyinput placeholder="校园活动地点" v-model="formData.place"></uni-easyinput> -->
<uni-data-select v-model="formData.place"
:localdata="place" >
</uni-data-select>
</uni-forms-item>
<!-- <uni-forms-item name="status" label="活动状态">
<uni-easyinput placeholder="校园活动状态" type="number" v-model="formData.status"></uni-easyinput>
......@@ -78,6 +89,9 @@
return {
formData,
formOptions: {},
place: [
{value:'福州大学',text:'福州大学'},
],
rules: {
...getValidator(Object.keys(formData))
}
......
......@@ -8,13 +8,21 @@
<uni-easyinput placeholder="小队活动内容" v-model="formData.content"></uni-easyinput>
</uni-forms-item>
<uni-forms-item name="start_date" label="开始时间">
<uni-easyinput placeholder="小队活动开始时间" v-model="formData.start_date"></uni-easyinput>
<!-- <uni-easyinput placeholder="小队活动开始时间" v-model="formData.start_date"></uni-easyinput> -->
<uni-datetime-picker
type="datetime"
v-model="formData.start_date"
/>
</uni-forms-item>
<uni-forms-item name="end_date" label="结束时间">
<uni-easyinput placeholder="小队活动结束时间" v-model="formData.end_date"></uni-easyinput>
<!-- <uni-easyinput placeholder="小队活动结束时间" v-model="formData.end_date"></uni-easyinput>-->
<uni-datetime-picker
type="datetime"
v-model="formData.end_date"
/>
</uni-forms-item>
<uni-forms-item name="owner_id" label="发布者id">
<uni-easyinput placeholder="小队活动发布者id" v-model="formData.owner_id"></uni-easyinput>
<uni-easyinput placeholder="小队活动发布者id" v-model="formData.owner_id" disabled></uni-easyinput>
</uni-forms-item>
<uni-forms-item name="place" label="地点">
<uni-easyinput placeholder="小队活动地点" v-model="formData.place"></uni-easyinput>
......@@ -23,13 +31,14 @@
<uni-easyinput placeholder="小队活动状态" type="number" v-model="formData.status"></uni-easyinput>
</uni-forms-item> -->
<uni-forms-item name="participants" label="参与人数">
<uni-easyinput placeholder="小队活动参与人数" type="number" v-model="formData.participants"></uni-easyinput>
<!-- <uni-easyinput placeholder="小队活动参与人数" type="number" v-model="formData.participants"></uni-easyinput> -->
<uni-number-box :value="0" :step="1" max="100000" value="100000" v-model="formData.participants" />
</uni-forms-item>
<uni-forms-item name="contact" label="联系方式">
<uni-easyinput placeholder="小队活动发布者联系方式" v-model="formData.contact"></uni-easyinput>
</uni-forms-item>
<uni-forms-item name="team_id" label="小队id">
<uni-easyinput placeholder="活动所属小队id" v-model="formData.team_id"></uni-easyinput>
<uni-easyinput placeholder="活动所属小队id" v-model="formData.team_id" disabled></uni-easyinput>
</uni-forms-item>
<view class="uni-button-group">
<button type="primary" class="uni-button" style="width: 100px;" @click="submit">提交</button>
......
......@@ -4,6 +4,7 @@ exports.main = async (event, context) => {
const user_table = db.collection("mustgo-user")
const comment_table = db.collection("mustgo-post-comment")
const post_table = db.collection("mustgo-post")
const message_table = db.collection("mustgo-message")
const res = await user_table.where({
_id:event.userId
......@@ -30,6 +31,16 @@ exports.main = async (event, context) => {
content:event.content
})
const res5 = await message_table.add({
state:false,
types:"评论",
content:event.content,
time:getSystemTime(),
from_id:event.userId,
to_id:res2.data[0]["owner_id"],
post_id:event.postId
})
return{
code:200,
message:"评论帖子成功",
......
......@@ -4,6 +4,7 @@ exports.main = async (event, context) => {
const db = uniCloud.database();
const post_table = db.collection("mustgo-post")
const like_table = db.collection("mustgo-post-like")
const message_table = db.collection("mustgo-message")
const res = await post_table.where({
_id:event.postId
}).get()
......@@ -23,6 +24,16 @@ exports.main = async (event, context) => {
owner_id:event.userId
})
const res4 = await message_table.add({
state:false,
types:"点赞",
content:"",
time:getSystemTime(),
from_id:event.userId,
to_id:res.data[0]["owner_id"],
post_id:event.postId
})
return {
code: 200,
message: "点赞帖子成功",
......@@ -56,4 +67,26 @@ exports.main = async (event, context) => {
message: "服务器错误",
data: {}
}
};
\ No newline at end of file
};
function getSystemTime() {
// 实例化日期类
var time = new Date();
// 获取完整的年份(4位)
var year = time.getFullYear();
// 获取月份(0-11,0代表1月)
var month = time.getMonth() + 1;
// 获取日期(1-31)
var date = time.getDate();
// 获取小时
var h = time.getHours() + 8;
h = h < 10 ? '0' + h : h;
// 获取分钟
var m = time.getMinutes();
m = m < 10 ? '0' + m : m;
// 获取秒钟
var s = time.getSeconds();
s = s < 10 ? '0' + s : s;
// 合并返回
return(year + "-" + month + "-" + date + " " + h + ":" + m + ":" + s) ;
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ exports.main = async (event, context) => {
const post_table = db.collection("mustgo-post")
const user_table = db.collection("mustgo-user")
const like_table = db.collection("mustgo-post-like")
const message_table = db.collection("mustgo-message")
const res = await post_table.orderBy("date","desc").where({
owner_id:event.userId
}).get()
......@@ -22,6 +23,12 @@ exports.main = async (event, context) => {
owner_id:event.userId,
post_id:arr[i]["_id"]
}).get()
const res4 = await message_table.where({
to_id:event.userId,
state:false
}).get()
if(res3.affectedDocs == 1) like = 1
if(res2.affectedDocs == 1){
......@@ -43,7 +50,8 @@ exports.main = async (event, context) => {
code:200,
message:"成功返回我的帖子列表",
data:{
postList:list
postList:list,
messageNum:res4.affectedDocs
}
}
}
......
......@@ -5,6 +5,7 @@ exports.main = async (event, context) => {
const post_table = db.collection("mustgo-post")
const user_table = db.collection("mustgo-user")
const like_table = db.collection("mustgo-post-like")
const message_table = db.collection("mustgo-message")
const res = await post_table.orderBy("date","desc").get();
var list = new Array
var arr = new Array;
......@@ -19,6 +20,7 @@ exports.main = async (event, context) => {
owner_id:event.uid,
post_id:arr[i]["_id"]
}).get()
var like = 0
if(res3.affectedDocs == 1) like = 1
......@@ -37,11 +39,19 @@ exports.main = async (event, context) => {
list.push(post);
}
}
const res4 = await message_table.where({
to_id:event.uid,
state:false
}).get()
var num = res4.affectedDocs
return {
code: 200,
message: "成功返回帖子列表",
data: {
postList: list
postList: list,
messageNum: num
}
}
}
......
'use strict';
exports.main = async (event, context) => {
const db = uniCloud.database();
const message_table = db.collection("mustgo-message")
var res = await message_table.where({
to_id:event.userId,
state:false
}).update({
state:true
})
if(res.affectedDocs < 0){
return{
code:400,
message:"查看信息列表失败",
data:{}
}
}
return {
code: 200,
message: "查看信息列表成功",
data: {
}
}
};
{
"name": "fe-message-checkMessage",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
}
}
\ No newline at end of file
{"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"description":"消息id","title":"id"},"state":{"bsonType":"bool","title":"状态","description":"消息状态"},"types":{"bsonType":"string","title":"类型","description":"消息类型"},"content":{"bsonType":"string","title":"内容","description":"消息内容"},"time":{"bsonType":"string","title":"时间","description":"消息时间"},"from_id":{"bsonType":"string","title":"发起人id","description":"发起人id","foreignKey":"mustgo-user._id"},"to_id":{"bsonType":"string","title":"接收者id","description":"接收者id","foreignKey":"mustgo-user._id"},"post_id":{"bsonType":"string","title":"帖子id","description":"帖子id","foreignKey":"mustgo-post._id"}}}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册