分类 默认分类 下的文章

mouse event

function createMouseEvent(eventType, rect) {
    return new MouseEvent(eventType, {
        bubbles: true,
        cancelable: true,
        view: window,
        clientX: rect.left + rect.width / 2,  // 元素的水平中心
        clientY: rect.top + rect.height / 2,  // 元素的垂直中心
        screenX: window.screenX + rect.left + rect.width / 2,  // 相对于屏幕的位置
        screenY: window.screenY + rect.top + rect.height / 2,  // 相对于屏幕的位置
        button: 0  // 左键
    });
}

const rect = ele.getBoundingClientRect();
ele.dispatchEvent(createMouseEvent('mousedown', rect));
ele.dispatchEvent(createMouseEvent('mouseup', rect));
ele.dispatchEvent(createMouseEvent('click', rect));  // 模拟 click 事件

point event

function createPointerEvent(eventType, rect) {
    return new PointerEvent(eventType, {
        bubbles: true,
        cancelable: true,
        view: window,
        clientX: rect.left + rect.width / 2,
        clientY: rect.top + rect.height / 2,
        screenX: window.screenX + rect.left + rect.width / 2,
        screenY: window.screenY + rect.top + rect.height / 2,
        button: 0,
        pointerId: 1,  // 指针 ID,一般使用 1
        width: 1,      // 指针宽度
        height: 1,     // 指针高度
        pressure: 0.5  // 模拟的触控压力,0-1 范围
    });
}

情况1

  1. linux 使用宿主机的网络地址 使用172.17.0.1(Docker默认桥接网络的网关地址)
  2. Windows或Mac,使用实际的IP地址或特定的地址(如host.docker.internal)

情况2

如果docker版本比较低,可以使用

docker run --add-host=host.docker.internal:host-gateway

对于 docker-compose.yml

services:
  your-service:
    extra_hosts:
      - "host.docker.internal:host-gateway"

如果无法识别 host-gateway,改为宿主机host

--add-host=host.docker.internal:<宿主机IP> ...

如果访问宿主机无法识别 host.docker.internal
报错
got error dial tcp: lookup host.docker.internal on 127.0.0.11:53: no such host
宿主机手动添加host

127.0.0.1 host.docker.internal

终极大招

修改宿主机防火墙规则,增加ip来源

sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" port port="3399" protocol="tcp" accept'

sudo firewall-cmd --reload

model

class Video(models.Model):
    view_count = models.IntegerField(verbose_name='浏览量', default=0)
    like_count = models.IntegerField(verbose_name='点赞量', default=0)
    collect_count = models.IntegerField(verbose_name='收藏量', default=0)
    comment_count = models.IntegerField(verbose_name='评论量', default=0)
    # 忽略其他字段

view

from django.db.models import Sum, Count

data = Video.objects.aggregate(
        count=Count('id'),
        view_count=Sum('view_count'),
        like_count=Sum('like_count'),
        collect_count=Sum('collect_count'),
        comment_count=Sum('comment_count')
    )

安装 crypto-js

pnpm install crypto-js

代码

import * as CryptoJS from 'crypto-js';


export async function decryptText(text: string): Promise<string> {
    // 16进制
    const keyHex = "cb69976b953380e5ff637b0bf9af35fdf1a56815c81296b3e5314e506d209a05";
    const ivHex = 'a312cc7df85e4d26dc65fb4f3fe82919'
    // console.log(`text: ${text}`)
    // Convert hex strings to Uint8Array
    const keyArray = new Uint8Array(
        keyHex.match(/.{1,2}/g).map(byte => parseInt(byte, 16))
    );
    const ivArray = new Uint8Array(
        ivHex.match(/.{1,2}/g).map(byte => parseInt(byte, 16))
    );

    const encryptedData = hexStringToByteArray(text)

    // AES decryption using crypto-js
    const decryptedData = CryptoJS.AES.decrypt(
        {
            ciphertext: CryptoJS.enc.Hex.parse(
                Array.from(encryptedData).map(byte => ('0' + (byte & 0xFF).toString(16)).slice(-2)).join('')
            )
        },
        CryptoJS.enc.Hex.parse(
            Array.from(keyArray).map(byte => ('0' + byte.toString(16)).slice(-2)).join('')
        ),
        {
            iv: CryptoJS.enc.Hex.parse(
                Array.from(ivArray).map(byte => ('0' + byte.toString(16)).slice(-2)).join('')
            ),
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7,
        }
    );

    return decryptedData.toString(CryptoJS.enc.Utf8)
}