44 * 页面的初始数据
55 */
66 data : {
7+ userid : "" ,
78 item : [ ] ,
9+ // 触摸开始时间
10+ touchStartTime : 0 ,
11+ // 触摸结束时间
12+ touchEndTime : 0 ,
813 } ,
914
1015 /**
1116 * 生命周期函数--监听页面加载
1217 */
1318 onLoad : function ( options ) {
14- this . getCollectInfo ( ) ;
19+ this . setData ( {
20+ userid : options . user_id ,
21+ } )
22+ this . getPublishInfo ( options . user_id ) ;
1523 } ,
16- getCollectInfo : function ( ) {
17- console . log ( "[findplatform-web] func getCollectInfo start." )
24+
25+ getPublishInfo : function ( option ) {
26+ console . log ( "[findplatform-web] func getPublishInfo start." )
1827 var that = this ;
1928 wx . request ( {
20- url : 'https://api.foocode.cn/collect/v1/allItem' ,
29+ url : 'https://api.foocode.cn/publish/v2/getUserPublish?user_id=' + option ,
2130 header : {
2231 'content-type' : 'application/json'
2332 } ,
@@ -27,18 +36,75 @@ Page({
2736 success ( res ) {
2837 console . log ( res . data ) ;
2938 var baseId = "img-" + ( + new Date ( ) ) ;
30- var images = res . data ;
39+ var images = res . data . data ;
3140 for ( let i = 0 ; i < images . length ; i ++ ) {
3241 images [ i ] . id = baseId + "-" + i ;
3342 }
3443 that . setData ( {
3544 item : images
3645 } ) ;
37- console . log ( "[findplatform-web] func getCollectInfo done." )
46+ console . log ( "[findplatform-web] func getPublishInfo done." )
3847 } ,
3948 fail ( res ) {
40- console . log ( "!!! [findplatform-web] func getCollectInfo fail." )
49+ console . warn ( "!!! [findplatform-web] func getPublishInfo fail." )
50+ }
51+ } )
52+ } ,
53+
54+ itemLongTap : function ( option ) {
55+ this . $showDialog ( {
56+ title : '删除物品' ,
57+ content : '您是否要删除已发布的物品?注意:删除后无法找回' ,
58+ success : res => {
59+ console . log ( res )
60+ if ( res . confirm ) {
61+ // 请求删除物品
62+ wx . request ( {
63+ url : 'https://api.foocode.cn/item/v1/deleteItem/' + option . currentTarget . dataset . id ,
64+ header : {
65+ 'content-type' : 'application/json'
66+ } ,
67+ method : "POST" ,
68+ data : { } ,
69+
70+ success ( res ) {
71+ console . info ( "[findplatform-web] func delete done." )
72+ } ,
73+ fail ( res ) {
74+ console . warn ( "!!! [findplatform-web] func delete fail." )
75+ }
76+ } )
77+ this . $success ( {
78+ title : '确定'
79+ } )
80+ }
81+ else {
82+ wx . showToast ( {
83+ title : '已取消' ,
84+ icon : 'none'
85+ } )
86+ }
4187 }
4288 } )
43- }
89+ } ,
90+
91+ // 按钮触摸开始触发的事件
92+ touchStart : function ( e ) {
93+ this . touchStartTime = e . timeStamp
94+ } ,
95+
96+ // 按钮触摸结束触发的事件
97+ touchEnd : function ( e ) {
98+ this . touchEndTime = e . timeStamp
99+ } ,
100+
101+ tapToUrl ( e ) {
102+ var that = this
103+ // 控制点击事件在350ms内触发,加这层判断是为了防止长按时会触发点击事件
104+ if ( that . touchEndTime - that . touchStartTime < 350 ) {
105+ wx . navigateTo ( {
106+ url : e . currentTarget . dataset . url
107+ } )
108+ }
109+ } ,
44110} )
0 commit comments