Skip to content

Commit afec33e

Browse files
committed
feat(web-extension): batch sync
1 parent 7b54755 commit afec33e

File tree

1 file changed

+157
-25
lines changed

1 file changed

+157
-25
lines changed

tools/batchsync.html

Lines changed: 157 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ <h1 class="logo" style="font-size: 20px">文章批量同步工具</h1>
187187
<div slot="tab">
188188
{{ dataSource.name }}
189189
</div>
190-
<a-table :columns="columns" :row-selection="rowSelection" :pagination="dataSource.data.pagination" :bordered="true" :data-source="dataSource.data.articles">
190+
<a-table :columns="columns" :row-selection="rowSelection" @change="dataSource.data.handleTableChange" :pagination="dataSource.data.pagination" :bordered="true" :data-source="dataSource.data.articles">
191191
<template slot="title" slot-scope="currentPageData">
192-
<a-button>批量同步</a-button>
192+
<a-button @click="addBatchTask">批量同步</a-button>
193193
</template>
194194
<span slot="cover" slot-scope="text, record">
195195
<img :src="record.cover" width="80" referrerpolicy="no-referrer" />
@@ -205,21 +205,23 @@ <h1 class="logo" style="font-size: 20px">文章批量同步工具</h1>
205205
</a-tabs>
206206
</div>
207207

208-
<a-modal v-model="visible" title="添加数据源">
208+
<a-modal v-model="visible" title="添加数据源" :footer="null">
209209

210210
<a-radio-group v-model="sourceType" default-value="wechat">
211211
<a-radio-button value="wechat">
212212
公众号
213213
</a-radio-button>
214-
<a-radio-button value="api">
214+
<!-- <a-radio-button value="api">
215215
API
216-
</a-radio-button>
216+
</a-radio-button> -->
217217
</a-radio-group>
218218

219219
<div style="margin-top: 15px">
220220
<a-input-search placeholder="搜索" enter-button @search="onSearch">
221221
</a-input-search>
222-
<a-list-item v-for="item in wechatList" @click="addSource('wechat', item)">
222+
<a-spin :spinning="searching"></a-spin>
223+
<a-list-item v-for="item in wechatList" >
224+
<a slot="actions" @click="addSource('wechat', item)">添加</a>
223225
<a-list-item-meta
224226
:description="item.signature"
225227
>
@@ -230,7 +232,9 @@ <h1 class="logo" style="font-size: 20px">文章批量同步工具</h1>
230232
height="60"
231233
:src="item.round_head_img"
232234
/>
235+
233236
</a-list-item-meta>
237+
234238
</a-list-item>
235239
</div>
236240

@@ -296,6 +300,8 @@ <h1 class="logo" style="font-size: 20px">文章批量同步工具</h1>
296300
},
297301
data: function () {
298302
return {
303+
loaded: {},
304+
searching: false,
299305
visible: false,
300306
wechatList: [],
301307
inited: false,
@@ -383,25 +389,64 @@ <h1 class="logo" style="font-size: 20px">文章批量同步工具</h1>
383389
}
384390
setTimeout(check, 800);
385391
})();
386-
387-
this.loadData();
392+
// this.loadData();
388393
},
389394
methods: {
395+
async addBatchTask() {
396+
397+
let callArgs = {
398+
methodName: 'getArticle',
399+
account: {
400+
type: 'weixin',
401+
},
402+
msgId: '2679077431',
403+
}
404+
console.log('callArgs', callArgs)
405+
const result = await new Promise((resolve, reject) => {
406+
window.$syncer.magicCall(callArgs, res => {
407+
resolve(res)
408+
})
409+
});
410+
411+
// window.$syncer.addTask(
412+
// {
413+
// post: getPost(),
414+
// accounts: selectedAc,
415+
// },
416+
// function (status) {
417+
// // self.taskStatus = status
418+
// // console.log('status', status)
419+
// },
420+
// function () {
421+
// // console.log('send')
422+
// }
423+
// )
424+
425+
426+
console.log('result', result)
427+
},
390428
addSource(type, item) {
391429
var sources = window.localStorage.getItem('sources') ? JSON.parse(window.localStorage.getItem('sources')) : []
392-
sources.push({
393-
type: type,
394-
data: item
395-
})
396-
console.log(type, item)
397-
localStorage.setItem('sources', JSON.stringify(sources))
430+
var isInThere = sources.filter(_ => _.data.fakeid == item.fakeid)
431+
if (isInThere.length == 0) {
432+
sources.push({
433+
type: type,
434+
data: item
435+
})
436+
console.log(type, item)
437+
this.$message.success('添加成功')
438+
localStorage.setItem('sources', JSON.stringify(sources))
439+
this.visible = false;
440+
this.addOther()
441+
}
398442
},
399-
400443
getSources() {
401444
return window.localStorage.getItem('sources') ? JSON.parse(window.localStorage.getItem('sources')) : []
402445
},
403446

404447
async onSearch(val) {
448+
449+
this.searching = true
405450
const result = await new Promise((resolve, reject) => {
406451
window.$syncer.magicCall({
407452
methodName: 'searchAccount',
@@ -415,6 +460,7 @@ <h1 class="logo" style="font-size: 20px">文章批量同步工具</h1>
415460
})
416461
});
417462

463+
this.searching = false
418464
this.wechatList = result.result.list
419465
console.log('result', result, this.wechatList)
420466
},
@@ -518,6 +564,11 @@ <h1 class="logo" style="font-size: 20px">文章批量同步工具</h1>
518564
})
519565
},
520566
async loadWechatArticles(targetAccount = null) {
567+
const accountId = targetAccount ? targetAccount.data.fakeid : 'current-wechat'
568+
if (this.loaded[accountId]) {
569+
console.log('aleardy loaed', targetAccount)
570+
return
571+
}
521572

522573
const result = await new Promise((resolve, reject) => {
523574
window.$syncer.magicCall({
@@ -526,12 +577,36 @@ <h1 class="logo" style="font-size: 20px">文章批量同步工具</h1>
526577
type: 'weixin',
527578
},
528579
fakeid: targetAccount ? targetAccount.data.fakeid : '',
529-
count: 20
580+
count: 5
530581
}, res => {
531582
resolve(res)
532583
})
533584
});
534585

586+
// if (result.result.base_resp.err_msg) {
587+
// this.$message.error(result.result.base_resp.err_msg)
588+
// }
589+
590+
if (result.result.base_resp.err_msg == 'freq control') {
591+
this.$message.error('读取频控; 公众号:'+ targetAccount.data.nickname)
592+
return
593+
}
594+
595+
var self = this;
596+
var curretIndex = this.dataSources.length;
597+
598+
function formatArticle(articles) {
599+
return articles.map(_ => ({
600+
id: _.appmsgid,
601+
title: _.title,
602+
desc: _.digest,
603+
cover: _.cover,
604+
create_time: moment(_.create_time * 1000).format('YYYY-MM-DD HH:ss'),
605+
link: _.link
606+
}))
607+
}
608+
609+
535610
this.dataSources.push({
536611
key: targetAccount ? targetAccount.data.fakeid : 'current-wechat',
537612
icon: 'wechat',
@@ -540,19 +615,76 @@ <h1 class="logo" style="font-size: 20px">文章批量同步工具</h1>
540615
total: result.result.app_msg_cnt,
541616
pagination: {
542617
total: result.result.app_msg_cnt,
543-
pageSize: 20
618+
pageSize: result.result.app_msg_list.length
544619
},
545-
articles: result.result.app_msg_list.map(_ => ({
546-
id: _.appmsgid,
547-
title: _.title,
548-
desc: _.digest,
549-
cover: _.cover,
550-
create_time: moment(_.create_time * 1000).format('YYYY-MM-DD HH:ss'),
551-
link: _.link
552-
}))
620+
async handleTableChange (pagination, filters, sorter) {
621+
console.log(pagination);
622+
const pager = { ...self.dataSources[curretIndex].data.pagination };
623+
pager.current = pagination.current;
624+
// this.pagination = pager;
625+
let callArgs = {
626+
methodName: 'listArticle',
627+
account: {
628+
type: 'weixin',
629+
},
630+
fakeid: targetAccount ? targetAccount.data.fakeid : '',
631+
begin: (pager.current - 1) * 5,
632+
count: 5
633+
}
634+
console.log('callArgs', callArgs)
635+
636+
const result = await new Promise((resolve, reject) => {
637+
window.$syncer.magicCall(callArgs, res => {
638+
resolve(res)
639+
})
640+
});
641+
642+
if (result.result.base_resp.err_msg == 'freq control') {
643+
self.$message.error('读取频控')
644+
return
645+
}
646+
647+
const paginationNew = { ...self.dataSources[curretIndex].data.pagination };
648+
paginationNew.total = result.result.app_msg_cnt;
649+
// pager.pageSize = result.result.app_msg_list.length
650+
651+
self.dataSources[curretIndex].data.pagination = paginationNew
652+
self.dataSources[curretIndex].data.articles = formatArticle(result.result.app_msg_list)
653+
self.$forceUpdate(() => {
654+
655+
})
656+
// self.$set(self.dataSources, curretIndex, Object.assign(self.dataSources[curretIndex], {
657+
// data: {
658+
// pagination: paginationNew,
659+
// articles: formatArticle(result.result.app_msg_list)
660+
// }
661+
// }))
662+
663+
console.log('self.dataSources', self.dataSources)
664+
// this.articles = result.result.app_msg_list.map(_ => ({
665+
// id: _.appmsgid,
666+
// title: _.title,
667+
// desc: _.digest,
668+
// cover: _.cover,
669+
// create_time: moment(_.create_time * 1000).format('YYYY-MM-DD HH:ss'),
670+
// link: _.link
671+
// }))
672+
console.log('page result', result)
673+
// this.fetch({
674+
// results: pagination.pageSize,
675+
// page: pagination.current,
676+
// sortField: sorter.field,
677+
// sortOrder: sorter.order,
678+
// ...filters,
679+
// });
680+
681+
},
682+
articles: formatArticle(result.result.app_msg_list)
553683
}
554684
})
555685

686+
this.loaded[accountId] = true
687+
556688
console.log('loadWechatArticles', result, this.dataSources)
557689
},
558690
beforeUpload(){

0 commit comments

Comments
 (0)