Authored by 郝肖肖

'task-del-all'

@@ -662,10 +662,11 @@ const task = { @@ -662,10 +662,11 @@ const task = {
662 }, 662 },
663 del: async(ctx, next) => { 663 del: async(ctx, next) => {
664 let params = ctx.request.body || {}; 664 let params = ctx.request.body || {};
665 - let key_name = JOB_TASK[parseInt(`0${params.type}`)];  
666 - let field_name = params.code || ''; 665 + let data = JSON.parse(_.get(ctx.request.body, 'data', '[]'));
667 666
668 - return ctx.redis.hdelAsync(key_name.k, field_name).then(status => { 667 + ctx.redis.multi(
  668 + _.map(data, job => ['hdel', JOB_TASK[parseInt(`0${job.tpe}`)].k || '', job.code || ''])
  669 + ).execAsync().then(status => {
669 return ctx.body = { 670 return ctx.body = {
670 code: 200, 671 code: 200,
671 message: 'success', 672 message: 'success',
@@ -87,60 +87,41 @@ @@ -87,60 +87,41 @@
87 var that = this; 87 var that = this;
88 88
89 this.$base = $('.contentpanel'); 89 this.$base = $('.contentpanel');
90 - this.$popTitle = $('.cover-title', this.$base);  
91 90
92 -  
93 - this.$base.on('change', '#select-type', function() {  
94 - if ($(this).val() === 'img') {  
95 - that.$imgLink.removeClass('hide');  
96 - } else {  
97 - that.$imgLink.addClass('hide');  
98 - }  
99 - }).on('click', '.clear-input', function() {  
100 - that.clearInput();  
101 - }).on('click', '.sure-btn', function() {  
102 - var data;  
103 -  
104 - if (that.saving) {  
105 - return;  
106 - }  
107 -  
108 - data = that.packReqData();  
109 -  
110 - if (!data) {  
111 - that.$errTip.text('请填写完整友链信息');  
112 - return;  
113 - } 91 + // 单个删除
  92 + this.$base.on('click', '.del-btn', function() {
  93 + let $tr = $(this).closest('tr');
  94 + that.del([$tr.data()]).then(result => {
  95 + result && $tr.remove();
  96 + });
  97 + });
114 98
115 - that.saving = true; 99 + // 删除全部
  100 + this.$base.on('click', '.delete-all', function() {
  101 + let arr = [];
116 102
117 - $.ajax({  
118 - url: that.editInfo ? '/seo/friendlink/edit' : '/seo/friendlink/add',  
119 - type: 'POST',  
120 - data: data,  
121 - }).done(function(res) {  
122 - if (res.code === 200) {  
123 - history.go(0);  
124 - }  
125 - }).always(function() {  
126 - that.saving = false; 103 + $('.tab-task input[type=checkbox]:checked').each(function(){
  104 + arr.push($(this).closest('tr').data());
127 }); 105 });
128 - });  
129 106
130 - // 单个删除  
131 - this.$base.on('click', '.del-btn', function() {  
132 - let $tr = $(this).closest('tr');  
133 - that.del($tr.data()).then(() => {  
134 - $tr.remove(); 107 + that.del(arr).then(result => {
  108 + result && history.go(0);
135 }); 109 });
136 }); 110 });
137 }, 111 },
138 del: function(data) { 112 del: function(data) {
139 - return $.ajax({  
140 - url: '/seo/task/del',  
141 - type: 'POST',  
142 - data: data,  
143 - }); 113 + if (confirm('您确定要删除吗!!!') && data.length) {
  114 + return this.ajax({
  115 + url: '/seo/task/del',
  116 + type: 'POST',
  117 + data: {data: JSON.stringify(data)},
  118 + });
  119 + } else {
  120 + return Promise.resolve(false);
  121 + }
  122 + },
  123 + ajax: function(options) {
  124 + return Promise.resolve($.ajax(options));
144 } 125 }
145 }; 126 };
146 127