duanbinian2243 2017-09-21 17:35
浏览 468

Vue JS直播进度条

I have the following scenario: A user clicks on a button in the settings .
This button will do a resource get call which calls an API.
This API will do nothing but some processing.
It will make a call to an ERP system and then process that result into a database.

Now I've managed to achieve all of the above.
However, I wish to have a live progress bar which will display the state of the processing.
Now I've googled a lot on how to achieve this but sadly I haven't found anything yet.

Could anyone help me in the right way?

**** EDIT ****

I'll try to give some more details.

I have a button in a Vue

<button type="button" class="btn btn-space btn-primary md-trigger" v-on:click="syncItemGroups();">{{ $t('titles.erp.sync_item_groups') }}</button>

The onclick event calls the Vue method syncItemGroups() which contains the following code:

syncItemGroups() {
    var _this = this;
    this.$dispatch('add-global-loader');
    _this.erpItemGroups = [];
    this.syncItemGroupsDataSource.get().then(function (response) {
        _this.erpItemGroups = response.data.erpItemGroups;
        _this.erpItemGroupsCount = _this.erpItemGroups.length;
        _this.$dispatch('remove-global-loader');
    });
}

The API that is being called contains the following code:

public function itemGroups()
{
    $tenantId    = $this->getCurrentTenant()->id;
    $integration = TenantIntegration::where('type', '=', 'erp')->where('tenant_id', '=', $tenantId)->get()->first();

    $this->getErpProvider()->syncItemGroups($integration->id, $tenantId);

    $itemGroups = ErpItemGroup::whereTenantId($tenantId)->get();

    return [
        'success'       => true,
        'erpItemGroups' => $itemGroups
    ];
}

Within this method the syncItemGroups is being called. This contains a foreach loop which does the processing. Now what i wish to achieve is that within this foreach loop the progress of this loop is being reported back to the website to populate a progress bar.

public function syncItemGroups($integrationId, $tenantId)
{

    $connection = $this->connect($integrationId);
    $connection->setDivision(1617429);
    $itemGroups = new ItemGroup($connection);
    $result     = $itemGroups->get();



    foreach ($result as $itemGroup) {
        $existingErpItemGroup = ErpItemGroup::where([
            ['tenant_id', $tenantId],
            ['item_group_id', $itemGroup->Code],
        ])->get()->first();
        if (is_null($existingErpItemGroup) ||
            $existingErpItemGroup->item_group_id !== $itemGroup->Code ||
            $existingErpItemGroup->description !== $itemGroup->Description) {
            $erpItemGroup                =
                is_null($existingErpItemGroup) ? new ErpItemGroup() : $existingErpItemGroup;
            $erpItemGroup->tenant_id     = $tenantId;
            $erpItemGroup->item_group_id = $itemGroup->Code;
            $erpItemGroup->description   = $itemGroup->Description;
            $erpItemGroup->save();
        }
    }
}

Hopefully it's clear now what i wish to achieve.

Thanks in advance.

Kind regards, Pim Dröge

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 AT89C51控制8位八段数码管显示时钟。
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题