Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
增加留言删除功能
Browse files Browse the repository at this point in the history
  • Loading branch information
鞠欣诚 committed Feb 17, 2020
1 parent e86b279 commit e2c4313
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 23 deletions.
48 changes: 43 additions & 5 deletions pages/components/Comment/Comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,63 @@ Component({
* 组件的属性列表
*/
properties: {
comment: Object
comment: Object,
onDelete:{
type:Function,
value:function(){}
}
},

/**
* 组件的初始数据
*/
data: {
},
data: {},

/**
* 组件的方法列表
*/
methods: {
tapComment: function () {
wx.navigateTo({
url:Requests.makeUrl("/pages/idel-comment/idel-comment",{
_id:this.data.comment._id
url: Requests.makeUrl("/pages/idel-comment/idel-comment", {
_id: this.data.comment._id
})
})
},

delete: function () {
let that = this
// 超级管理员用户学号
var su = [
"17152010921",
"16104050207"
]
var ask = function () {
wx.showModal({
content: "确定删除这条留言么?",
success(res) {
if (res.confirm) {
Requests.delete({
url: "/idel-comment",
data: {
_id: that.data.comment._id
},
success(data) {
that.data.onDelete()
}
})
}
}
})
}
Requests.getWithCache({
url: '/user',
success(data) {
if (data.openid == that.data.comment.from_openid || su.indexOf(data.sno) != -1) {
ask()
}
}
})
}
}
})
2 changes: 1 addition & 1 deletion pages/components/Comment/Comment.wxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<view class="main-view" bindtap="tapComment" hover-class="hover">
<view class="main-view" catchtap="tapComment" catchlongtap="delete" hover-class="hover">
<view class="line">
<image class="avatar" src="{{comment.from.avatarUrl}}"></image>
<text class="nickName">{{comment.from.nickName}}</text>
Expand Down
33 changes: 19 additions & 14 deletions pages/idel-detail/idel-detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,30 @@ Page({

},

onDelete:function(){
let that = this
// 请求评论数据
Requests.get({
url: "/idel-comment/" + that.data._id,
success(data) {
for (var i = 0; i < data.length; i++) {
data[i].create_time = data[i].create_time.split(".")[0]
}
that.setData({
comments: data
})
}
})
},

/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
_id: options._id,
contentHeight:app.globalData.systemInfo.windowHeight
contentHeight:app.globalData.systemInfo.windowHeight,
onDelete:this.onDelete
})
let that = this
//请求商品信息
Expand All @@ -47,19 +64,7 @@ Page({
},

onShow: function () {
let that = this
// 请求评论数据
Requests.get({
url: "/idel-comment/" + that.data._id,
success(data) {
for (var i = 0; i < data.length; i++) {
data[i].create_time = data[i].create_time.split(".")[0]
}
that.setData({
comments: data
})
}
})
this.onDelete()
},

tapImg: function (e) {
Expand Down
2 changes: 1 addition & 1 deletion pages/idel-detail/idel-detail.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</view>
<view wx:for="{{comments}}">
<view class="divider2"></view>
<comment comment="{{item}}" />
<comment comment="{{item}}" onDelete="{{onDelete}}"/>
</view>
</view>
</scroll-view>
Expand Down
4 changes: 2 additions & 2 deletions utils/Requests.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export class Requests {
// static baseUrl = "http://127.0.0.1:8080/v1"
// static baseUrl = "https://myncutdev.ncut.edu.cn/v1"
// static baseUrl = "https://myncut.ncut.edu.cn/v1"
static baseUrl = "https://myncut.ncut.edu.cn/v1"
// static baseUrl = "http://10.211.55.3:8080/v1"
static baseUrl = "http://192.168.0.101/v1"
// static baseUrl = "http://192.168.0.101/v1"

// 请求日志
static console = true
Expand Down

0 comments on commit e2c4313

Please sign in to comment.