分类目录归档:None

JS 创建网页直接打印

主要精华
var printWindow = window.open(”, ‘_blank’);

printWindow.document.write(e);

printWindow.document.close();

printWindow.print();

下面是范例代码

function cx(l_1,l_2,l_3,l_4,l_5,l_6){
        let e="XXXXXXXXXXXXXXXXXXXXXXXXX</body></html>"
//e中放入html文字,需要替换的{1}{2}{3}等等用于替换
        console.log(123)
        e=e.replace(/\{1\}/g, l_1)
        e=e.replace(/\{2\}/g, l_2)
        e=e.replace(/\{3\}/g, l_3)
        e=e.replace(/\{4\}/g, l_4)
        e=e.replace(/\{5\}/g, l_5)
        e=e.replace(/\{6\}/g, l_6)
        // console.log(e)

//打印的精华功能
        var printWindow = window.open('', '_blank');
        printWindow.document.write(e);
        printWindow.document.close();
        printWindow.print();
    }

function get_info(){
//爬取网页信息,可以不使用
    var l_1=document.getElementById("htcfbmId$text").value
    var l_2=document.getElementById("htbh$text").value
    var l_3=document.getElementById("htmc$text").value
    var l_4=document.getElementById("jine$text").value
    if(l_4=='0'){
        l_4="------"
    }else{
        l_4=l_4+".00元"
    }
    var mx=document.querySelectorAll("[name='dfdwId']")
    var l_5=''
    mx.forEach(element => {
        l_5=l_5+"\n"+element.previousElementSibling.querySelector('input').value
    });
    var l_6=document.getElementById("deptName$text").value
    cx(l_1,l_2,l_3,l_4,l_5,l_6)
}

function create_btn(){
//创建按钮
    var button = document.createElement('button');
    button.innerHTML = '打印申请表';
    button.style.position = 'fixed'; // 固定定位
    button.style.top = '10px';       // 距离顶部10px
    button.style.right = '200px';     // 距离右侧10px
    button.style.padding = '10px 20px'; // 内边距
    button.style.backgroundColor = 'blue'; // 背景颜色
    button.style.color = 'white';    // 文本颜色
    button.style.border = 'none';    // 无边框
    button.style.borderRadius = '5px'; // 圆角
    button.style.cursor = 'pointer'; // 鼠标指针样式
    button.style.zIndex = '9999';    // 确保按钮在最上层
    button.onclick = function() {
        get_info();
    };
    document.body.appendChild(button);

}

create_btn();

数字转汉字

    function chinese_number($num){
        $chinese_array=["零","一","二","三","四","五","六","七","八","九"];
        $str=(string)$num;
        $length = strlen($str);
        $new_array=array();
        for ($i = 0; $i < $length; $i++) {
            $new_array[]=$chinese_array[(int)$str[$i]];
        }
        switch ($length){
			case 2:
                if($new_array[0]=="一"){
                    $re='十'.$new_array[1];
                }else{
                    $re=$new_array[0].'十'.$new_array[1];
                }
				break;
            case 3:
				$re=$new_array[0].'百'.$new_array[1].'十'.$new_array[2];
				break;
            case 4:
				$re=$new_array[0].'千'.$new_array[1].'百'.$new_array[2].'十'.$new_array[3];
				break;
            case 5:
				$re=$new_array[0].'万'.$new_array[1].'千'.$new_array[2].'百'.$new_array[3].'十'.$new_array[4];
				break;
            default:
                $re=$new_array[0];
                break;
        }
        return $re;
    }

扩展计划UserScript

预计时间3个工作日

1.JS抓取页面

2.在页面中添加一个按钮(实验阶段,可以是一个函数在console中直接调用,生成一个页面并调用打印)

3.在浏览器中添加脚本,前期可以直接在进入页面抓取,但是应为多个对方单位所以在详情页来创建UserScript

====

最终目标,生成CRX扩展,便于安装。

Thinkphp6 Model 创建

默认使用$this表示本表(模型),如果需要用Db::name()请导入该模块:
use think\facade\Db;

<?php
namespace app\portal\model;

use think\facade\Db;
use think\Model;

class CopTopicsModel extends Model
{
    /**
     * 模型名称
     * @var string
     */
    protected $name = 'cop_topics';
    protected $autoWriteTimestamp=true;

    public function adminGetTopics($id){
        $where[]=["a.id",'=',$id];
        return Db::name('cop_topics')->alias('a')
            ->join("cop_topics_own b","a.id=b.ct_id")
            ->where($where)->find();
    }
}

或者使用$this-> 来代替Db::name(‘cop_topics’) ,本来就是cop_topics模型

public function adminGetTopics($id){
        $where[]=["a.id",'=',$id];
        return $this->alias('a')
            ->join("cop_topics_own b","a.id=b.ct_id")
            ->where($where)->find();
    }