优化任务展示

This commit is contained in:
Anyon 2020-03-24 10:43:00 +08:00
parent 6fa85935fa
commit 8a3cc256ec
11 changed files with 52 additions and 46 deletions

View File

@ -117,7 +117,7 @@
<i class="layui-icon">&#xe640;</i> <i class="layui-icon">&#xe640;</i>
</a> </a>
{/if} {/if}
<a onclick="$.loadQueue('{$vo.code}')" data-tips-text="任务进度信息" class='layui-badge layui-bg-orange margin-left-5'> <a onclick="$.loadQueue('{$vo.code}',true)" data-tips-text="任务进度信息" class='layui-badge layui-bg-orange margin-left-5'>
<i class="layui-icon">&#xe705;</i> <i class="layui-icon">&#xe705;</i>
</a> </a>
</div> </div>

View File

@ -89,6 +89,9 @@ class Fans extends Command
} }
$next = $result['total'] > $done ? $result['next_openid'] : null; $next = $result['total'] > $done ? $result['next_openid'] : null;
} }
$this->setQueueProgress(2, '执行前端代码');
$this->setQueueProgress(2, 'javascript:alert(1)');
$this->output->comment('--> Wechat user data synchronization completed'); $this->output->comment('--> Wechat user data synchronization completed');
$this->output->newLine(); $this->output->newLine();
return "同步{$done}个用户数据"; return "同步{$done}个用户数据";

8
composer.lock generated
View File

@ -909,12 +909,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "f7d1be29830dc3d8c149e48dda510127d8cbddb5" "reference": "28760760070a34a5b21ab1d6754b223d139d79a3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/f7d1be29830dc3d8c149e48dda510127d8cbddb5", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/28760760070a34a5b21ab1d6754b223d139d79a3",
"reference": "f7d1be29830dc3d8c149e48dda510127d8cbddb5", "reference": "28760760070a34a5b21ab1d6754b223d139d79a3",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -958,7 +958,7 @@
], ],
"description": "ThinkPHP v6.0 Development Library", "description": "ThinkPHP v6.0 Development Library",
"homepage": "http://framework.thinkadmin.top", "homepage": "http://framework.thinkadmin.top",
"time": "2020-03-23T06:54:54+00:00" "time": "2020-03-24T02:35:13+00:00"
}, },
{ {
"name": "zoujingli/wechat-developer", "name": "zoujingli/wechat-developer",

View File

@ -739,17 +739,20 @@ $(function () {
$body.on('click', '[data-queue]', function (action) { $body.on('click', '[data-queue]', function (action) {
action = this.getAttribute('data-queue') || ''; action = this.getAttribute('data-queue') || '';
if (action.length < 1) return $.msg.tips('任务地址不能为空!'); if (action.length < 1) return $.msg.tips('任务地址不能为空!');
this.loading = function (index) { this.doRuntime = function (index) {
$.form.load(action, {}, 'post', function (ret) { $.form.load(action, {}, 'post', function (ret) {
if (typeof ret.data === 'string' && ret.data.indexOf('Q') === 0) return $.loadQueue(ret.data), false; if (typeof ret.data === 'string' && ret.data.indexOf('Q') === 0) {
}); return $.loadQueue(ret.data, true), false;
$.msg.close(index); }
}), $.msg.close(index);
}; };
$(this).attr('data-confirm') ? $.msg.confirm($(this).attr('data-confirm'), this.loading) : this.loading(0); $(this).attr('data-confirm') ? $.msg.confirm($(this).attr('data-confirm'), this.doRuntime) : this.doRuntime(0);
}); });
$.loadQueue = function (code) { $.loadQueue = function (code, doScript, doAjax) {
layer.open({ layer.open({
type: 1, title: false, area: ['560px', '315px'], anim: 2, shadeClose: false, content: '' + type: 1, title: false, area: ['560px', '315px'], anim: 2, shadeClose: false, end: function () {
doAjax = false;
}, content: '' +
'<div class="padding-30 padding-bottom-0" style="width:500px" data-queue-load="' + code + '">' + '<div class="padding-30 padding-bottom-0" style="width:500px" data-queue-load="' + code + '">' +
' <div class="layui-elip nowrap" data-message-title></div>' + ' <div class="layui-elip nowrap" data-message-title></div>' +
' <div class="margin-top-15 layui-progress layui-progress-big" lay-showPercent="yes">' + ' <div class="margin-top-15 layui-progress layui-progress-big" lay-showPercent="yes">' +
@ -760,51 +763,48 @@ $(function () {
' </div>' + ' </div>' +
'</div>' '</div>'
}); });
var scripts = {};
(function loadprocess(code, that) { (function loadprocess(code, that) {
that = this, this.$box = $('[data-queue-load=' + code + ']'); that = this, this.$box = $('[data-queue-load=' + code + ']');
if (that.$box.length < 1) return false; if (doAjax === false || that.$box.length < 1) return false;
this.$area = that.$box.find('textarea'); this.$area = that.$box.find('textarea'), this.$title = that.$box.find('[data-message-title]');
this.$title = that.$box.find('[data-message-title]'); this.$percent = that.$box.find('.layui-progress div'), this.runCache = function (code, index, value) {
this.$percent = that.$box.find('.layui-progress div'); this.ckey = code + '_' + index, this.ctype = 'admin-queue-script';
return value !== undefined ? layui.data(this.ctype, {key: this.ckey, value: value}) : layui.data(this.ctype)[this.ckey] || 0;
};
this.setState = function (status, message) { this.setState = function (status, message) {
if (message.indexOf('javascript:') === 0) { if (message.indexOf('javascript:') === -1) if (status === 1) {
} else if (status === 1) { that.$title.html('<b class="color-text">' + message + '</b>').addClass('text-center');
that.$title.html('<b class="color-text">' + message + '</b>');
that.$percent.addClass('layui-bg-blue').removeClass('layui-bg-green layui-bg-red'); that.$percent.addClass('layui-bg-blue').removeClass('layui-bg-green layui-bg-red');
} else if (status === 2) { } else if (status === 2) {
if (message.indexOf('>>>') > -1) { if (message.indexOf('>>>') > -1) {
that.$title.html('<b class="color-blue">' + message + '</b>'); that.$title.html('<b class="color-blue">' + message + '</b>').addClass('text-center');
} else { } else {
that.$title.html('<b class="color-blue">正在处理:</b>' + message); that.$title.html('<b class="color-blue">正在处理:</b>' + message).removeClass('text-center');
} }
that.$percent.addClass('layui-bg-blue').removeClass('layui-bg-green layui-bg-red'); that.$percent.addClass('layui-bg-blue').removeClass('layui-bg-green layui-bg-red');
} else if (status === 3) { } else if (status === 3) {
that.$title.html('<b class="color-green">' + message + '</b>'); that.$title.html('<b class="color-green">' + message + '</b>').addClass('text-center');
that.$percent.addClass('layui-bg-green').removeClass('layui-bg-blue layui-bg-red'); that.$percent.addClass('layui-bg-green').removeClass('layui-bg-blue layui-bg-red');
} else if (status === 4) { } else if (status === 4) {
that.$title.html('<b class="color-red">' + message + '</b>'); that.$title.html('<b class="color-red">' + message + '</b>').addClass('text-center');
that.$percent.addClass('layui-bg-red').removeClass('layui-bg-blue layui-bg-green'); that.$percent.addClass('layui-bg-red').removeClass('layui-bg-blue layui-bg-green');
} }
}; };
$.form.load(window.ROOT_URL + '?s=admin/api.queue/progress', {code: code}, 'post', function (ret) { $.form.load(window.ROOT_URL + '?s=admin/api.queue/progress', {code: code}, 'post', function (ret) {
if (ret.code) { if (ret.code) {
that.lines = []; that.lines = [];
for (this.i in ret.data.history) { for (this.lineIndex in ret.data.history) {
this.line = ret.data.history[this.i], this.percent = '[ ' + this.line.progress + '% ] '; this.line = ret.data.history[this.lineIndex], this.percent = '[ ' + this.line.progress + '% ] ';
if (this.line.message.indexOf('javascript:') === -1) { if (this.line.message.indexOf('javascript:') === -1) {
that.lines.push(this.line.message.indexOf('>>>') > -1 ? this.line.message : this.percent + this.line.message); that.lines.push(this.line.message.indexOf('>>>') > -1 ? this.line.message : this.percent + this.line.message);
} else if (!scripts['_' + code + '_' + this.i]) { } else if (!that.runCache(code, this.lineIndex) && doScript !== false) {
location.href = this.line.message, scripts['_' + code + '_' + this.i] = true; that.runCache(code, this.lineIndex, 1), location.href = this.line.message;
} }
} }
that.$area.val(that.lines.join("\n")), that.$area.animate({scrollTop: that.$area[0].scrollHeight + 'px'}, 200); that.$area.val(that.lines.join("\n")), that.$area.animate({scrollTop: that.$area[0].scrollHeight + 'px'}, 200);
that.$percent.attr('lay-percent', (ret.data.progress || '0.00') + '%'), layui.element.render(); that.$percent.attr('lay-percent', (ret.data.progress || '0.00') + '%'), layui.element.render();
if (ret.data.status > 0) { if (ret.data.status > 0) that.setState(parseInt(ret.data.status), ret.data.message);
that.setState(parseInt(ret.data.status), ret.data.message); else return that.setState(4, '获取任务详情失败!'), false;
} else {
return that.setState(4, '获取任务详情失败!'), false;
}
if (parseInt(ret.data.status) === 3 || parseInt(ret.data.status) === 4) return false; if (parseInt(ret.data.status) === 3 || parseInt(ret.data.status) === 4) return false;
return setTimeout(function () { return setTimeout(function () {
loadprocess(code); loadprocess(code);

View File

@ -935,12 +935,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "f7d1be29830dc3d8c149e48dda510127d8cbddb5" "reference": "28760760070a34a5b21ab1d6754b223d139d79a3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/f7d1be29830dc3d8c149e48dda510127d8cbddb5", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/28760760070a34a5b21ab1d6754b223d139d79a3",
"reference": "f7d1be29830dc3d8c149e48dda510127d8cbddb5", "reference": "28760760070a34a5b21ab1d6754b223d139d79a3",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -956,7 +956,7 @@
"ext-json": "*", "ext-json": "*",
"topthink/framework": "^6.0" "topthink/framework": "^6.0"
}, },
"time": "2020-03-23T06:54:54+00:00", "time": "2020-03-24T02:35:13+00:00",
"type": "library", "type": "library",
"extra": { "extra": {
"think": { "think": {

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php <?php
// This file is automatically generated at:2020-03-23 14:57:04 // This file is automatically generated at:2020-03-24 10:42:29
declare (strict_types = 1); declare (strict_types = 1);
return array ( return array (
0 => 'think\\app\\Service', 0 => 'think\\app\\Service',

View File

@ -15,6 +15,7 @@
namespace think\admin; namespace think\admin;
use think\admin\storage\AliossStorage;
use think\admin\storage\LocalStorage; use think\admin\storage\LocalStorage;
use think\admin\storage\QiniuStorage; use think\admin\storage\QiniuStorage;
use think\App; use think\App;
@ -64,7 +65,7 @@ abstract class Storage
/** /**
* 存储初始化 * 存储初始化
* @return Storage * @return AliossStorage|LocalStorage|QiniuStorage
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
@ -97,7 +98,7 @@ abstract class Storage
/** /**
* 设置文件驱动名称 * 设置文件驱动名称
* @param string $name 驱动名称 * @param string $name 驱动名称
* @return static * @return AliossStorage|LocalStorage|QiniuStorage
* @throws \think\Exception * @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException

View File

@ -172,9 +172,8 @@ class QueueService extends Service
if (!is_numeric($progress)) $progress = '0.00'; if (!is_numeric($progress)) $progress = '0.00';
if (is_null($message)) $message = '>>> 任务执行失败 <<<'; if (is_null($message)) $message = '>>> 任务执行失败 <<<';
} }
$ckey = "queue_{$this->code}_progress";
try { try {
$data = $this->app->cache->get($ckey, [ $data = $this->app->cache->get("queue_{$this->code}_progress", [
'code' => $this->code, 'status' => $status, 'message' => $message, 'progress' => $progress, 'history' => [], 'code' => $this->code, 'status' => $status, 'message' => $message, 'progress' => $progress, 'history' => [],
]); ]);
} catch (\Exception|\TypeError $exception) { } catch (\Exception|\TypeError $exception) {
@ -194,7 +193,10 @@ class QueueService extends Service
$data['history'][] = ['message' => $message, 'progress' => $progress]; $data['history'][] = ['message' => $message, 'progress' => $progress];
} }
if (is_string($message) || is_numeric($progress)) { if (is_string($message) || is_numeric($progress)) {
$this->app->cache->set($ckey, $data); if (count($data['history']) > 10) {
$data['history'] = array_slice($data['history'], -10);
}
$this->app->cache->set("queue_{$this->code}_progress", $data);
} }
return $data; return $data;
} }

View File

@ -84,7 +84,7 @@ class AliossStorage extends Storage
/** /**
* 获取当前实例对象 * 获取当前实例对象
* @param null $name * @param null $name
* @return Storage * @return AliossStorage|LocalStorage|QiniuStorage
* @throws \think\Exception * @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException

View File

@ -53,7 +53,7 @@ class LocalStorage extends Storage
/** /**
* 获取当前实例对象 * 获取当前实例对象
* @param null $name * @param null $name
* @return Storage * @return AliossStorage|LocalStorage|QiniuStorage
* @throws \think\Exception * @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException

View File

@ -58,7 +58,7 @@ class QiniuStorage extends Storage
/** /**
* 获取当前实例对象 * 获取当前实例对象
* @param null $name * @param null $name
* @return Storage * @return AliossStorage|LocalStorage|QiniuStorage
* @throws \think\Exception * @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException