Authored by 陈峰

commit

1 import Login from 'yoho-activity-sdk/src/public/login'; 1 import Login from 'yoho-activity-sdk/src/public/login';
2 import Base from 'yoho-activity-sdk/src/public/base'; 2 import Base from 'yoho-activity-sdk/src/public/base';
  3 +import yoho from 'common/yoho';
  4 +import cookie from 'yoho-cookie';
3 5
4 6
5 var env = Base.env(); 7 var env = Base.env();
6 var loginUrl = Base.loginUrl(); 8 var loginUrl = Base.loginUrl();
7 var login = new Login({loginUrl: loginUrl, env: env}); 9 var login = new Login({loginUrl: loginUrl, env: env});
8 10
  11 +async function getUser() {
  12 + if (yoho.isApp) {
  13 + const user = await Base.getUser();
  14 +
  15 + if (user && user.uid) {
  16 + cookie.set('app_uid', user.uid);
  17 + cookie.set('app_session_key', user.sessionKey);
  18 + cookie.set('app_version', user.appVersion);
  19 + cookie.set('app_client_type', user.sessionType);
  20 + }
  21 +
  22 + return user;
  23 + } else {
  24 + return Base.getUser();
  25 + }
  26 +}
  27 +
9 export default { 28 export default {
10 goLogin: login.goLogin.bind(login), 29 goLogin: login.goLogin.bind(login),
11 - getUser: Base.getUser.bind(Base) 30 + getUser
12 }; 31 };
@@ -8,7 +8,6 @@ @@ -8,7 +8,6 @@
8 * 8 *
9 * 希望能与 微信 JS-SDK 一样方便 9 * 希望能与 微信 JS-SDK 一样方便
10 */ 10 */
11 -import cookie from 'yoho-cookie';  
12 11
13 /* 空方法 */ 12 /* 空方法 */
14 const nullFun = () => {}; 13 const nullFun = () => {};
@@ -70,7 +70,7 @@ export default { @@ -70,7 +70,7 @@ export default {
70 }, 70 },
71 methods: { 71 methods: {
72 ...mapActions(['fetchCommentList', 'fetchReplayList', 'postComment']), 72 ...mapActions(['fetchCommentList', 'fetchReplayList', 'postComment']),
73 - async fetchComments(refresh) { 73 + async fetchComments(lazy) {
74 const result = await this.fetchCommentList({ 74 const result = await this.fetchCommentList({
75 destId: this.destId, 75 destId: this.destId,
76 columnType: this.columnType, 76 columnType: this.columnType,
@@ -81,23 +81,24 @@ export default { @@ -81,23 +81,24 @@ export default {
81 if (result.code === 200) { 81 if (result.code === 200) {
82 const comments = get(result, 'data.commentInfos', []); 82 const comments = get(result, 'data.commentInfos', []);
83 83
84 - if (refresh) {  
85 - setTimeout(() => { 84 + setTimeout(() => {
  85 + if (this.page === 1) {
86 this.commentList = comments; 86 this.commentList = comments;
87 - }, 200);  
88 - } else {  
89 - this.commentList = this.commentList.concat(comments);  
90 - }  
91 -  
92 - if (comments.length) {  
93 - this.page++;  
94 - } else {  
95 - dirty = false;  
96 - }  
97 - this.$emit('on-page-change', {  
98 - page: this.page,  
99 - size: result.data.total  
100 - }); 87 + console.log('this.commentList')
  88 + } else {
  89 + this.commentList = this.commentList.concat(comments);
  90 + }
  91 + if (comments.length) {
  92 + this.page++;
  93 + } else {
  94 + dirty = false;
  95 + }
  96 + this.$emit('on-page-change', {
  97 + page: this.page,
  98 + size: result.data.total
  99 + });
  100 + this.$refs.scroll.forceUpdate(dirty);
  101 + }, lazy ? 200 : 0);
101 } else { 102 } else {
102 this.$createToast && this.$createToast({ 103 this.$createToast && this.$createToast({
103 txt: result.message || '服务器开小差了', 104 txt: result.message || '服务器开小差了',
@@ -105,20 +106,20 @@ export default { @@ -105,20 +106,20 @@ export default {
105 time: 1000 106 time: 1000
106 }).show(); 107 }).show();
107 } 108 }
108 - this.$refs.scroll.forceUpdate(dirty);  
109 return result; 109 return result;
110 }, 110 },
111 onPullingUp() { 111 onPullingUp() {
112 this.fetchComments(); 112 this.fetchComments();
113 }, 113 },
114 async onComment() { 114 async onComment() {
115 - this.init(); 115 + this.page = 1;
  116 + this.$refs.scroll.scrollTo(0, 0, 200);
  117 + this.fetchComments(false);
116 }, 118 },
117 async init() { 119 async init() {
118 this.page = 1; 120 this.page = 1;
119 this.commentList = []; 121 this.commentList = [];
120 - this.$refs.scroll.forceUpdate(true);  
121 - await this.fetchComments(true); 122 + this.fetchComments(true);
122 }, 123 },
123 async onReply({commentId}) { 124 async onReply({commentId}) {
124 const result = await this.fetchReplayList({ 125 const result = await this.fetchReplayList({
@@ -135,12 +135,10 @@ export default { @@ -135,12 +135,10 @@ export default {
135 window.addEventListener('test', null, opts); 135 window.addEventListener('test', null, opts);
136 } catch (e) {} //eslint-disable-line 136 } catch (e) {} //eslint-disable-line
137 this.$el.addEventListener(EVENT_SCROLL, this._onScroll, supportsPassive ? { passive: true } : false); 137 this.$el.addEventListener(EVENT_SCROLL, this._onScroll, supportsPassive ? { passive: true } : false);
138 - window.addEventListener(EVENT_RESIZE, this._onResize);  
139 this.init(); 138 this.init();
140 }, 139 },
141 beforeDestroy() { 140 beforeDestroy() {
142 this.$el.removeEventListener(EVENT_SCROLL, this._onScroll); 141 this.$el.removeEventListener(EVENT_SCROLL, this._onScroll);
143 - window.removeEventListener(EVENT_RESIZE, this._onResize);  
144 }, 142 },
145 methods: { 143 methods: {
146 init() { 144 init() {