AJAX 本地提交 不跳转修改表格

使用jquery阻止a标签跳转,使用AJXA发起请求 后根据a标签的提示执行js语句来实现动态加载

A标签

 <a  href="{:url('portal/fapiao/print_id',['id'=>$so.id])}" class="ajax-click btn btn-primary btn-sm"  js="ts.parent().parent().parent().attr('class','bg-warning');var span=ts.parent().parent().prev().find('span:first');span.text('已开票');span.attr('class','label label-primary')"data-msg="确定已开票吗?">完成</a>
                                        <a  href="{:url('portal/fapiao/done_id',['id'=>$so.id])}" class="ajax-click btn btn-success btn-sm" js="ts.parent().parent().parent().attr('class','bg-success');var span=ts.parent().parent().prev().find('span').eq(1);span.text('已付款');span.attr('class','label label-success')" data-msg="确定已收款?">收款</a>
                                   

其中的 js 属性为eval执行js语句,其中 ajax-click 用于绑定点击事件来组织跳转a 标签的href,在函数中提前将$(this) 变为局部变量,在函数中使用,(因为ajax请求中$(this) 为请求本身)eval执行

$(".ajax-click").click(function(){
        event.preventDefault();//停止跳转
        var url=$(this).attr('href');
        var ts=$(this);
        var js=$(this).attr('js');
        var jugg=confirm($(this).attr('data-msg'));
        if(jugg){
            $.ajax({
                url:url,
                success:function(data){
                    console.log(data);
                    if(data.code){
                        // c=ts.parent().parent().parent().attr("class","info")
                        eval(js);
                        // console.log(c)
                        // window.location.href=data.url;
                    }
                }
            })
        } 
    })

comfyUI关于P104 显卡设置 tips

  • comfyUI 官方默认安装即可 ( https://www.comfy.org/zh-cn/ ),但是需要安装好CUDA。
  • 不能多卡并行,一个进程只能一张卡上运行,也就是说显存越大越好,P104的8GB,运行Wan2.2 5B 出720P有点不够(勉勉强强运行)官方推荐12GB显存,双卡无用。
    • P104不能开启cudaMallocAsync ,需要在comfyui的设置里面关闭cudaMallocAsync 设置Disable CUDA malloc,这样才能运行
  • 其中的模型下载可能会因为网络问题导致无法下载。

上图是P104 打开时候使用cudaMallocAsync 的启动图片,该配置下是无法完成出图的,需要在设置里关闭cuda malloc

  • https://download.comfy.org/windows/nsis/x64

大模型做OCR不如直接OCR

用Qwen2.5VL 3b和7b做OCR 效果不行,不如直接使用OCR的包,如CnOcr

安装:

pip install cnocr[ort-cpu]

pip install cnocr[ort-cpu] -i https://pypi.tuna.tsinghua.edu.cn/simple

首次安装会去hf上下几个模型,CPU也可以运行,效果不错:

from cnocr import CnOcr

img_fp = 'page_10.png'
ocr = CnOcr()  # 所有参数都使用默认值
out = ocr.ocr(img_fp)

print(out)

返回结果为 文本信息 准确率 位置信息

文档:https://cnocr.readthedocs.io/zh-cn/stable/

解决方向:OCR 结果给大模型处理

thinkphp6文件上传 Filesystem Request

创建配置文件在 data/config/filesystem.php

return [
    'default' => 'local',
    'disks'   => [
        'local'  => [
            'type' => 'local',
            'root' => app()->getRuntimePath() . 'storage',
        ],
        'public' => [
            'type' => 'local',
            'root' => app()->getRootPath() . 'public/storage',
            'url'  => '/storage',
        ],
    ],
];

该处 在创建public磁盘:在更目录的public目录下创建storage文件夹用于存储

前端HTML

 <form method="post" action="{:url('portal/gz/post_info_post')}" enctype="multipart/form-data">

控制器中


use think\facade\Request;
use think\facade\Filesystem;

$file = request()->file('path');
        if (!$file) {
            return json(['code' => 0, 'msg' => '未上传文件']);
        }
#判断是否上传
 $savename = Filesystem::disk('public')->putFile('gz', $file);

#其中返回的信息 $savename

#"gz/20250725/c4219efc6dd44ef8e439b85ed03d667c.png"
#即public下的 storage下 

针对名字字符串,两个字的名字中间加两个空格 三个字的不变

function insertSpaces($str) {
		$result = '';
		$length = mb_strlen($str, 'UTF-8');
		$i = 0;
		$k=0;
		while ($i < $length) {
			// 获取当前字符
			$char = mb_substr($str, $i, 1, 'UTF-8');
			if($i+1<$length){
				$char_next = mb_substr($str, $i+1, 1, 'UTF-8');
			}else{
				$char_next =" ";
			}
			if($char!=" "){
				$k++;
			}
			if($char!=" "&&$char_next==" "){
				// var_dump($k);
				if($k==2){
					$result=$result."  ".$char;
				}else{
					$result=$result.$char;
				}
				$k=0;
			}else{
				$result=$result.$char;
			}
			$i++;
		}
	
		return $result;
	}