javascript - 在这种情况下,订阅一个简单的请求是 Angular 2 的正确方法吗?
问题描述
我有一个停车系统,我使用 Angular 6 + Laravel 作为后端,我有一个帖子,我发布了一些由 DigitalDrifter 解决的问题,谢谢。
这是链接:如何在 Laravel 中为每条 20 分钟后的新记录创建调度程序任务?
我的系统不是 100% 好,因为我有一个奇怪的行为。每个客户都必须前往支付区并验证您的输入。当客户向收银员出示票时,他在付款后点击一个名为“验证票”的按钮验证了输入
我的代码在 Angular 中执行此操作:
validateEntry(ean13: string, value: number) {
this.spinner.show();
this.entryService.validateEntry(this.config.role.validateEntryUrl, ean13, value, this.userModel.mov_user_id)
.pipe(
catchError(
(error: any): Observable<any> => {
this.spinner.hide();
$('#m_modal_1').modal('hide');
return this.utilService.errorHandler(error);
}))
.subscribe(response => {
if (response.success != 0) {
$('#m_modal_1').modal('hide');
this.spinner.hide();
swal({
title: 'Validado!',
text: response.message,
type: 'success',
showCloseButton: true,
showCancelButton: false,
showConfirmButton: false
}).then((result) => {
$("#mov_ean13_input").focus();
});
}else {
$('#m_modal_1').modal('hide');
this.spinner.hide();
swal({
title: 'Erro!',
text: response.message,
type: 'error',
showCloseButton: true,
showCancelButton: false,
showConfirmButton: false
}).then((result) => {
$("#mov_ean13_input").focus();
});
}
});
}
这是 Angular 6 上的服务:
public validateEntry(url: string, ean13: string, value: number, userid: number): Observable<any> {
console.log(userid);
return this.http.post(this.mainConfig.config.default.mainUrl + url, { ean13: ean13, value: value, userid: userid });
}
这是 laravel 的后端,代码如下:
public function validateEntry(Request $request){
try{
$entryean13 = $request->input('ean13');
$value = $request->input('value');
$userid = $request->input('userid');
$this->mdEntry->validatedEntryByEan($entryean13,$value,$userid);
if(empty($this->mdEntry->checkValidEntry($entryean13))){
$response["success"] = 0;
$response["message"] = "Ocorreu algum erro no servidor, tente validar novamente";
}else {
$response["success"] = 1;
$response["message"] = "Entrada validada com sucesso";
}
return $response;
}
catch(\Exception $e){
$response["success"] = 0;
$response["message"] = "Aconteceu algum erro no processamento, tente novamente em alguns minutos.";
$response["erro"] = $e->getMessage();
return $response;
}
}
And to finish the code area here is the Eloquent that update my table:
public function validatedEntryByEan($ean13,$valor,$userid){
Entry::where('mov_entry_ean13', $ean13 )
->update(['validated' => 'S',
'value' => $valor,
'mov_user_id' => $userid]);
}
去 Laravel 时,我得到条目 EAN_13 代码、$value 和 $userid(Cashier 用户)并在表上进行更新并验证条目,客户端有 30 分钟的时间出去。
问题是 85% 已验证,但 15% 未验证,收银员总是说他们总是单击按钮进行验证。一些客户付钱,当他去出口图腾时不要让他们走,当我挑选票并测试它时,他没有得到验证。
我错过了什么?不是人为错误,每个人都点击按钮。我不知道出了什么问题,因为当用户单击时,当( response.success != 0 )在 Angular 上时,我返回一个显示“ENTRY IS VALIDATED”的框。
我执行此检查以查看用户是否会通过某些测试进行验证。现在我的问题是,这是订阅的正确方法吗?你们认为他每次点击按钮都会提出请求吗?还是不?抱歉,这是一个非常菜鸟的问题,但我想 100% 完成这项工作,我尝试了一些尝试并没有收到任何错误。
你认为那些是浏览器问题的人吗?因为我在 Ubuntu Mate 上的 Raspberry Pi 3 上运行 Chromium 上的 Angular 6 应用程序,所以我正在考虑更改浏览器进行测试。
解决方案
推荐阅读
- python - 在 py2neo 中直接使用 Cypher Bolt 语句结果
- java - 使用 @ManyToMany 和 @ManyToOne 关系创建表
- sql - 基于变量执行查询
- nix - nix 是否提供包选项/参数?我如何列出它们?
- python - 使用 mitmproxy 即时修改 HTTPS 响应数据包
- javascript - 如何通过 jQuery/js 在内联 css 中添加 flex 而不是阻塞
- vba - 获取 Visio 应用程序的窗口位置
- python - 在 aws 胶水 pyspark 作业中从 s3 加载 JSON
- c# - 我想在保存格式更改时从 Excel 上传数据并存储在 SQL Server 中
- mongodb - 了解 explain() 以优化复杂查询