You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 8 POS系统订单页添加桌号列后卡顿及重复行问题求助

问题描述

基于PHP Laravel 8开发的POS网页订单页面,添加桌号列后出现两个问题:

  • 页面持续处于加载状态
  • 订单数据出现重复行
    需求仅为在页面中新增桌号列。

问题截图显示:表格表头已添加桌号列,但表格主体无数据,页面加载状态持续,且存在重复的订单记录。

相关视图代码:

@extends('layouts.layout')
@section("content")
<div class="row">
    <div class="col-md-12">
        
        <div class="d-flex flex-wrap mb-4">
            <div class="mr-auto">
                <span class="text-title">{{ __("POS Orders") }}</span>
            </div>
            <div class="">
                @if (check_access(array('A_ADD_ORDER'), true))
                    <a href="{{ route('add_order')}}" role="button" class="btn btn-primary">{{ __("New Order") }}</a>
                @endif
            </div>
        </div>

        <div class="table-responsive">
            <table id="listing-table" class="table display nowrap w-100">
                <thead>
                    <tr>
                        <th>{{ __("Order Number") }}</th>
                        <th>{{ __("Customer Phone") }}</th>
                        <th>{{ __("Table Number") }}</th>

                        <th>{{ __("Customer Email") }}</th>
                        <th>{{ __("Amount") }}</th>
                        <th>{{ __("Status") }}</th>
                        <th>{{ __("Created On") }}</th>
                        <th>{{ __("Updated On") }}</th>
                        <th>{{ __("Created By") }}</th>
                        <th>{{ __("Action") }}</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>

    </div>
</div>
@endsection

@push('scripts')
    <script src="{{ asset('plugins/datatables/jquery.dataTables.min.js') }}"></script>
    <script src="{{ asset('plugins/datatables/dataTables.bootstrap4.min.js') }}"></script>
    <script src="{{ asset('js/datatable.js') }}"></script>
    <script src="{{ asset('js/pages/orders.js') }}"></script>
    <script>
    'use strict';
        var orders = new Orders();
        orders.load_listing_table();
    </script>
@endpush
解决方案

1. 排查后端数据接口重复问题

  • 检查订单列表的后端控制器逻辑:如果使用了关联查询(比如订单关联桌号表),需确保查询不会返回重复数据。例如用join后是否未添加distinct(),或者关联关系为一对多导致单条订单被多次返回。
  • 测试后端接口(可通过浏览器开发者工具的Network面板查看AJAX请求返回的数据),确认返回的订单数组中是否存在重复条目,以及是否包含table_number字段。

2. 同步DataTables列配置

  • 打开js/pages/orders.js文件,找到load_listing_table方法中的DataTables初始化代码,确保列配置数组新增桌号对应的项,且列的数量与thead完全一致:
    // 示例列配置,需根据实际字段调整
    columns: [
        { data: 'order_number', name: 'order_number' },
        { data: 'customer_phone', name: 'customer_phone' },
        { data: 'table_number', name: 'table_number' }, // 新增这一行
        { data: 'customer_email', name: 'customer_email' },
        { data: 'amount', name: 'amount' },
        { data: 'status', name: 'status' },
        { data: 'created_at', name: 'created_at' },
        { data: 'updated_at', name: 'updated_at' },
        { data: 'created_by', name: 'created_by' },
        { data: 'action', name: 'action' }
    ]
    
  • 检查是否存在重复调用load_listing_table的情况,这会导致表格重复加载数据。

3. 验证DataTables加载逻辑

  • 确保datatable.js或orders.js中没有错误的AJAX配置,比如请求URL错误、参数异常导致后端响应异常,进而使页面持续加载。

内容的提问来源于stack exchange,提问作者Vicky kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 18:15:52