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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler