USB大容量存储设备被禁用 代码32

案例查看

适用于提示代码32

 

解决方法

1、打开注册表编辑器 (Win+R 输入 regedit)

2、找到以下路径

 HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > Services > USBSTOR

3、点击USBSTOR,查看Start值是否为4,如果是,双击Start,修改为2或3 (建议改为3).

 

2--自启动,3--默认启动,4--禁止启动

4、重新连接USB设备,恢复正常。

 

记录一下python写爬虫必须要注意的几个点

因为好久没写过爬虫了,这次单位有需求要爬取几TB的资料,在测试过程中遇到一些问题,总结下来,未来写爬虫的时候可以避坑。

问题1:JSON Object Key不存在。规范的情况下,返回的JSON对象数组应该是统一的,即使数据不存在也应该是空字符串或者null或者别的什么,但是这个系统过于老旧,编码也乱七八糟不规范,导致个别数据不存在的时候,压根不返回这个Key。

解决方案:

if 'key' not in item:
    continue

只需要判断一下这个key在不在item里,不在直接跳出此循环。

 

问题2:保存的文件名/路径有非法字符。在Windows下,创建的文件夹/文件时,文件名不能包含以下字符:

 \ / : * ? " < > |

因此,如果文件名/路径名中有此些字符,需要替换掉,这里提供一个替换方法:

def string_format(str: string, replacement: string=''):
    illegal_words = ['\\', '/', '*', '?' '"', '<', '>', '|']
    for word in illegal_words:
        if word in str:
            str = str.replace(word, replacement)
    return str

参数说明:str 要格式化的字符串,replacement 将非法字符替换成指定内容,不填写则替换空字符串。

Vue3 导出word代码,可导出数据+图片

网上搜到的代码都没办法直接使用,需要修改后才能用,我在这里发一版修改后的完美可用的代码,可以直接拿去用,也给自己留个备份。

我在使用网上搜到的代码的时候遇到一些问题,如果你也遇到了这些问题,那么表示这篇文章可以帮助你。

 

问题:

1、JSZIP版本太高(V3.x),导致docxtemplater无法使用,以及一些函数大改动。

2、Vue3使用的Vite而不是Webpack,因此 require,Buffer等功能不能使用。

 

解决方法:

1、手动将JSZIP由3.x改为2.3.0版本,重新npm i,即可解决。

2、Buffer要安装buffer依赖,使用

npm i buffer --save

进行安装,然后直接按如下引用:

import {Buffer} from "buffer";

另外,网络上的代码在加载图片处理依赖时使用的是

var ImageModule = require('docxtemplater-image-module-free');

需要改为

import ImageModule from "docxtemplater-image-module-free";

 

以上就是主要的问题所在,下面贴上完整代码和一些需要注意的东西。

完整代码

1、开始之前,你需要先安装如下依赖

-- 安装 docxtemplater
npm install docxtemplater pizzip  --save

-- 安装 jszip-utils
npm install jszip-utils --save

-- 安装 jszip
npm install jszip --save

-- 安装 FileSaver
npm install file-saver --save

-- 安装 buffer 用作b64转buffer
npm install buffer --save

-- 安装 docxtemplater-image-module-free 用作图片处理
npm install docxtemplater-image-module-free --save

 

2、新建一个js文件,我是在/src/utils/下新建的fileExport.js,并粘贴如下内容。

import PizZip from 'jszip';
import docxtemplater from 'docxtemplater';
import JSZipUtils from 'jszip-utils';
import {saveAs} from 'file-saver';
import {Buffer} from "buffer";
import ImageModule from "docxtemplater-image-module-free";


const base64DataURLToArrayBuffer = (dataURL) => {
    const base64Regex = /^data:image\/(png|jpg|svg|svg\+xml);base64,/;
    if (!base64Regex.test(dataURL)) {
        return false;
    }
    const stringBase64 = dataURL.replace(base64Regex, "");
    let binaryString;
    if (typeof window !== "undefined") {
        binaryString = window.atob(stringBase64);
    } else {
        binaryString = new Buffer(stringBase64, "base64").toString("binary");
    }
    const len = binaryString.length;
    const bytes = new Uint8Array(len);
    for (let i = 0; i < len; i++) {
        const ascii = binaryString.charCodeAt(i);
        bytes[i] = ascii;
    }
    return bytes.buffer;
}

/**
 * 导出word,支持图片
 * @param {Object} tempDocxPath 模板文件路径
 * @param {Object} wordData 导出数据
 * @param {Object} fileName 导出文件名
 */
export const exportWord = (tempDocxPath, wordData, fileName, imageSize = {}) => {
    // 读取并获得模板文件的二进制内容
    JSZipUtils.getBinaryContent(tempDocxPath, function (error, content) {
            if (error) {
                throw error;
            }
            let opts = {};
            opts.centered = true; // 图片居中,在word模板中定义方式为{%%image}
            opts.fileType = "docx";
            opts.getImage = function (chartId) {
                return base64DataURLToArrayBuffer(chartId);
            };
            opts.getSize = function (img, tagValue, tagName) {
                // console.log(img);//ArrayBuffer数据
                // console.log(tagValue);//base64数据
                // console.log(tagName);//wordData对象的图像属性名
                // 自定义指定图像大小
                // eslint-disable-next-line no-prototype-builtins
                if (imageSize.hasOwnProperty(tagName)) {
                    return imageSize[tagName];
                } else {
                    return [660, 440];
                }
            }
            let imageModule = new ImageModule(opts);
            // 创建一个PizZip实例,内容为模板的内容
            const zip = new PizZip(content);
            // 创建并加载docxtemplater实例对象
            const doc = new docxtemplater();
            doc.attachModule(imageModule);
            doc.loadZip(zip);

            doc.setData(wordData);

            try {
                // 用模板变量的值替换所有模板变量
                doc.render();
            } catch (error) {
                // 抛出异常
                const e = {
                    message: error.message,
                    name: error.name,
                    stack: error.stack,
                    properties: error.properties
                };
                console.log(
                    JSON.stringify({
                        error: e
                    })
                );
                throw error;
            }
            console.log('11');
            // 生成一个代表docxtemplater对象的zip文件(不是一个真实的文件,而是在内存中的表示)
            const out = doc.getZip().generate({
                type: 'blob',
                mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
            });
            // 将目标文件对象保存为目标类型的文件,并命名
            saveAs(out, fileName);
        }
    );
};

 

3、参数说明

  • tempDocxPath 是模板文件绝对路径
  • wordData 模板数据
  • fileName 要保存的文件名
  • imageSize 图片大小,接受一个int对象,格式是{ width, height },单位是px,例如{ 400, 300 }

如需导出图片,则需要将图片转为base64后写入wordData对象内。

echarts转base64的方法是

echarts.getInstanceByDom(document.getElementById('echarts')).getDataURL({
    type: 'png',
    backgroundColor: '#fff',
    pixelRatio: 1,
})

 

4、模板变量

模板内变量要和wordData里的变量名一致。普通字段:{字段名},图片字段:{%字段名}

 

以上

ThinkPHP6 多应用模式调用其他控制器时需要填写$app参数,报错Required parameter ‘$app’ missing

如图所示,在多应用情况下,我调用User() 控制器,提示需要填写$app参数,

因为我所有的控制器都是 extends BaseController 的,所以查看BaseController的源码,发现如下

/**
 * 构造方法
 * @access public
 * @param  App  $app  应用对象
 */
public function __construct(App $app)
{
    $this->app     = $app;
    $this->request = $this->app->request;

    // 控制器初始化
    $this->initialize();
}

调用时需要传入一个App对象。

在网上和文档里查了半天都没结果,自己猜出解决方案。

传入参数如下:

(new App())->initialize()

完整的也就是

$user = new User((new App())->initialize());

你学废了吗?

 

By the way,TP6的文档写的乱七八糟,我真特么是服了,遇到问题看文档屁用没有。

 

青骄第二课堂全国青少年禁毒知识一键满分脚本

[admonition]转载请保留出处,严禁倒卖,倒卖者亲🐴biss[/admonition]

前言

去年发过的禁毒知识竞赛的满分脚本,今年还能用。重新发布一下。

按照下面使用方法使用可一键满分,不用进去答题。

有问题请进QQ群交流:1153448795

效果图:

使用方法

1、登录https://www.2-class.com/competition

2、按F12打开开发者工具,选择应用(Application) -> 左侧Cookie加号点开 -> 选择https://www.2-class.com/

3、复制右侧的asw_tcsid的值

4、切换回控制台(Console) -> 在下方输入框里输入命令:window.__DATA__.reqtoken 并回车

5、复制双引号内的内容

6、运行脚本,依次输入以上3个数据。

 

代码

# -*- coding: utf-8 -*-

import requests
import json
import time
import random


# 获取reqtoken的命令: window.__DATA__.reqtoken

# cookie = 'acw_tc=76b20f6616659797159527027e3350e04399c20a051cfaf70874ad516c6900; sid=e993abc8-00ee-4173-9c36-abd5d059babd;'
# reqtoken = '9f83d24e-7e12-4c47-a45b-b677694fa7a3'


def yi_jian_man_fen(cookie, reqtoken):
    url = 'https://www.2-class.com/api/quiz/commit'
    headers = {
        'Cookie': cookie,
        'Content-Type': 'application/json',
        'User-Agent': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50'
    }
    time = random.randint(100, 350)
    data = {
        "list": [
            {
                "questionId": 2986,
                "questionContent": "B"
            },
            {
                "questionId": 2989,
                "questionContent": "C"
            },
            {
                "questionId": 2990,
                "questionContent": "D"
            },
            {
                "questionId": 2959,
                "questionContent": "C"
            },
            {
                "questionId": 2928,
                "questionContent": "C"
            },
            {
                "questionId": 2960,
                "questionContent": "A"
            },
            {
                "questionId": 2961,
                "questionContent": "C"
            },
            {
                "questionId": 2897,
                "questionContent": "B"
            },
            {
                "questionId": 2930,
                "questionContent": "D"
            },
            {
                "questionId": 2898,
                "questionContent": "B"
            },
            {
                "questionId": 2963,
                "questionContent": "A"
            },
            {
                "questionId": 2932,
                "questionContent": "D"
            },
            {
                "questionId": 2901,
                "questionContent": "A"
            },
            {
                "questionId": 2966,
                "questionContent": "D"
            },
            {
                "questionId": 2934,
                "questionContent": "C"
            },
            {
                "questionId": 2904,
                "questionContent": "D"
            },
            {
                "questionId": 2907,
                "questionContent": "D"
            },
            {
                "questionId": 2972,
                "questionContent": "C"
            },
            {
                "questionId": 2973,
                "questionContent": "A"
            },
            {
                "questionId": 2912,
                "questionContent": "B"
            }
        ],
        "time": time,
        "reqtoken": reqtoken
    }

    result = requests.post(url=url, data=json.dumps(data), headers=headers, verify=False)
    print(result.text)


if __name__ == '__main__':
    acw_tc = input('请输入acw_tc:')
    sid = input('请输入sid:')
    reqtoken = input('请输入token:')
    cookie = f'acw_tc={acw_tc}; sid={sid};'
    yi_jian_man_fen(cookie, reqtoken)

 

其他

不欢迎任何商业行为。

司马52pojie,10年多了,封我账号,祝52pojie早日倒闭。

Vue3 错误处理机制onErrorCaptured使用方法

大家好,我在做JSON转XML时出现,如果字符串格式是XML,但是却强制进行JSON -> XML操作,控制台会报错Syntex Error,这个错误是人为导致的,并不是代码有问题,因此我需要捕获这个错误并处理。

尝试过使用try catch来捕获,发现根本没用。

经过查阅文档,发现可以使用生命周期钩子onErrorCaptured来处理

下面是我的代码,各位在使用时可以借鉴。

onErrorCaptured((err) => {
      // 判断是错误还是异常
      if (err.toString().indexOf('SyntaxError') !== -1) {
        ElNotification({
          title: '程序出错',
          message: err.message,
          type: 'error',
        })
        return false
      }
    })

 

err是返回的错误对象,你要查找特定的错误就得把他转字符串,你可以在控制台看到完整的错误信息(红色的),err.message只包含内容,不包含开头的错误或警告类型。

祝各位程序永无BUG

超简单使用elementUI的表单验证,看不懂官方文档的看这里

复杂的官方文档

大家好,编写elementUI时,看到新的element-plus的表单验证部分写的如此的复杂,我下面复制官方文档的表单验证部分的代码。

<template>
  <el-form
    ref="ruleFormRef"
    :model="ruleForm"
    :rules="rules"
    label-width="120px"
    class="demo-ruleForm"
    :size="formSize"
  >
    <el-form-item label="Activity name" prop="name">
      <el-input v-model="ruleForm.name" />
    </el-form-item>
    <el-form-item label="Activity zone" prop="region">
      <el-select v-model="ruleForm.region" placeholder="Activity zone">
        <el-option label="Zone one" value="shanghai" />
        <el-option label="Zone two" value="beijing" />
      </el-select>
    </el-form-item>
    <el-form-item label="Activity time" required>
      <el-col :span="11">
        <el-form-item prop="date1">
          <el-date-picker
            v-model="ruleForm.date1"
            type="date"
            placeholder="Pick a date"
            style="width: 100%"
          />
        </el-form-item>
      </el-col>
      <el-col class="text-center" :span="2">
        <span class="text-gray-500">-</span>
      </el-col>
      <el-col :span="11">
        <el-form-item prop="date2">
          <el-time-picker
            v-model="ruleForm.date2"
            placeholder="Pick a time"
            style="width: 100%"
          />
        </el-form-item>
      </el-col>
    </el-form-item>
    <el-form-item label="Instant delivery" prop="delivery">
      <el-switch v-model="ruleForm.delivery" />
    </el-form-item>
    <el-form-item label="Activity type" prop="type">
      <el-checkbox-group v-model="ruleForm.type">
        <el-checkbox label="Online activities" name="type" />
        <el-checkbox label="Promotion activities" name="type" />
        <el-checkbox label="Offline activities" name="type" />
        <el-checkbox label="Simple brand exposure" name="type" />
      </el-checkbox-group>
    </el-form-item>
    <el-form-item label="Resources" prop="resource">
      <el-radio-group v-model="ruleForm.resource">
        <el-radio label="Sponsorship" />
        <el-radio label="Venue" />
      </el-radio-group>
    </el-form-item>
    <el-form-item label="Activity form" prop="desc">
      <el-input v-model="ruleForm.desc" type="textarea" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm(ruleFormRef)"
        >Create</el-button
      >
      <el-button @click="resetForm(ruleFormRef)">Reset</el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'

const formSize = ref('default')
const ruleFormRef = ref<FormInstance>()
const ruleForm = reactive({
  name: 'Hello',
  region: '',
  date1: '',
  date2: '',
  delivery: false,
  type: [],
  resource: '',
  desc: '',
})

const rules = reactive<FormRules>({
  name: [
    { required: true, message: 'Please input Activity name', trigger: 'blur' },
    { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
  ],
  region: [
    {
      required: true,
      message: 'Please select Activity zone',
      trigger: 'change',
    },
  ],
  date1: [
    {
      type: 'date',
      required: true,
      message: 'Please pick a date',
      trigger: 'change',
    },
  ],
  date2: [
    {
      type: 'date',
      required: true,
      message: 'Please pick a time',
      trigger: 'change',
    },
  ],
  type: [
    {
      type: 'array',
      required: true,
      message: 'Please select at least one activity type',
      trigger: 'change',
    },
  ],
  resource: [
    {
      required: true,
      message: 'Please select activity resource',
      trigger: 'change',
    },
  ],
  desc: [
    { required: true, message: 'Please input activity form', trigger: 'blur' },
  ],
})

const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log('submit!')
    } else {
      console.log('error submit!', fields)
    }
  })
}

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.resetFields()
}
</script>

一个简单的表单验证写的这么啰嗦,我就想校验一下登录账号和密码,需要这么麻烦吗?

其实只需要FormInstance就可以实现了。

超简单的写法

对于简单的表单验证,完全不需要上面那么啰嗦。

其实验证是很简单的,只需要写一个验证的数组(rules),并赋值给el-form组件的rule参数即可,如下

<el-form ref="formRef" :model="loginForm" :rules="rules" label-position="top"></el-form>

rules长这样

const rules = ref({
      phone: [
        {required: true, message: '必须输入手机号码', trigger: 'blur'},
        {pattern: /^1[3456789]\d{9}$/, message: '手机号码格式不正确', trigger: 'blur'},
      ],
      password: [
        {required: true, message: '必须输入密码', trigger: 'blur'},
        {min: 6, max: 20, message: '密码长度在 6 到 20 个字符', trigger: 'blur'},
      ]
    })

那你可能会问了,ref是干啥用的啊?

告诉你,ref的目的是为了在提交或者什么操作的时候,手动验证表单,如下。

比如我们有个登录按钮,和登录的方法onLogin()

<el-button type="primary" @click="onLogin(formRef)">登录</el-button>
const onLogin = (form) => {
      form.validate((valid, fields) => {
        if (valid) {
          console.log('登录成功')
        } else {
          console.log('error submit!', fields)
        }
      })
    }

相信小伙伴们已经看明白什么意思了。

简单来说,就是在登录方法里传参传这个ref进去,然后这个ref有validate()方法,通过这个方法就校验了。上面的if else是固定写法。

那么ref这个值是哪来的呢?其实是开头说的FormInstance定义出来的,定义如下:

// 引用
import {FormInstance} from "element-plus"

// 这个是写在setup()里的!!
const formRef = ref<FormInstance>('')

 

 

怎么样,是不是比官方那啰里啰嗦一大串舒服多了?

【分享】词达人做题神器:词达人Lib

有群友在群里推了这个网站,试过之后效果还是不错的。

鉴于我已经不用做词达人了,就发出来分享给有需要的同学。

地址:https://www.cdrlib.xyz/

这个平台不是完全免费的,首次登录会赠送套餐包。所以具体用不用就是各位同学斟酌的事情了。

我测试了几个任务,正确率和分数还是可以接受的,如果是自己选词的任务平台会选择所有词。

下面是我测试的截图,速度挺快,分数也可以接受。

【Java】创建 maven maven-archetype-quickstart 项目报错解决方法

同学们好,没错,因为工作需要,我要开始入坑java了, 希望这次能学会。

创建项目开局就报错,挺离谱的。还好找到了解决办法

1、首先打开maven目录下的conf文件夹里的setting.xml,在其中添加如下仓库位置url(因为默认的是在国外,在这里我们添加阿里云的国内镜像)

直接把以下内容加到</settings>下面就行了

<mirror>
        <id>aliyun-public</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun public</name>
        <url>https://maven.aliyun.com/repository/public</url>
    </mirror>

    <mirror>
        <id>aliyun-central</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun central</name>
        <url>https://maven.aliyun.com/repository/central</url>
    </mirror>

    <mirror>
        <id>aliyun-spring</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun spring</name>
        <url>https://maven.aliyun.com/repository/spring</url>
    </mirror>

    <mirror>
        <id>aliyun-spring-plugin</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun spring-plugin</name>
        <url>https://maven.aliyun.com/repository/spring-plugin</url>
    </mirror>

    <mirror>
        <id>aliyun-apache-snapshots</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun apache-snapshots</name>
        <url>https://maven.aliyun.com/repository/apache-snapshots</url>
    </mirror>

    <mirror>
        <id>aliyun-google</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun google</name>
        <url>https://maven.aliyun.com/repository/google</url>
    </mirror>

    <mirror>
        <id>aliyun-gradle-plugin</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun gradle-plugin</name>
        <url>https://maven.aliyun.com/repository/gradle-plugin</url>
    </mirror>

    <mirror>
        <id>aliyun-jcenter</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun jcenter</name>
        <url>https://maven.aliyun.com/repository/jcenter</url>
    </mirror>

    <mirror>
        <id>aliyun-releases</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun releases</name>
        <url>https://maven.aliyun.com/repository/releases</url>
    </mirror>

    <mirror>
        <id>aliyun-snapshots</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun snapshots</name>
        <url>https://maven.aliyun.com/repository/snapshots</url>
    </mirror>

    <mirror>
        <id>aliyun-grails-core</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun grails-core</name>
        <url>https://maven.aliyun.com/repository/grails-core</url>
    </mirror>

    <mirror>
        <id>aliyun-mapr-public</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun mapr-public</name>
        <url>https://maven.aliyun.com/repository/mapr-public</url>
    </mirror>

2、在IDEA中依次按照路径file-setting找到maven配置选项(如下图),将如下两项修改:第一项修改为maven解压目录下的conf文件夹里的setting.xml,第二项会自动读取setting.xml文件里的仓库地址(如果未自动读取,检查下自己是否写错了),也可以手动更改。更改完成之后点击Apply-OK。

在下图所示进入Maven->Runner(中文是 运行程序) 然后将下面内容复制粘贴到VM Options(VM选项)当中保存即可。

-Dmaven.multiModuleProjectDirectory=$MAVEN_HOME

-Dmaven.wagon.http.ssl.insecure=true

-Dmaven.wagon.http.ssl.allowall=true

-Dmaven.wagon.http.ssl.ignore.validity.dates=true

 

至此,问题解决。

人生中第一个java项目创建完毕。

转载:https://blog.csdn.net/shyc126/article/details/105822059

Vue3.x 控制台警告 [Violation] Added non-passive event listener to a scroll-blocking ‘touchmove’ event. Consider marking event handler as ‘passive’ to make the page more responsive.

控制台警告信息

[admonition]

[Violation] Added non-passive event listener to a scroll-blocking ‘touchmove’ event. Consider marking event handler as ‘passive’ to make the page more responsive.

[/admonition]

情况说明

以下说明引用至https://stackoverflow.com/questions/39152877/consider-marking-event-handler-as-passive-to-make-the-page-more-responsive/62639220

想了解更多关于这个的问题可以点上面链接进去看原文

For those receiving this warning for the first time, it is due to a bleeding edge feature called Passive Event Listeners that has been implemented in browsers fairly recently (summer 2016). From https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md:

Passive event listeners are a new feature in the DOM spec that enable developers to opt-in to better scroll performance by eliminating the need for scrolling to block on touch and wheel event listeners. Developers can annotate touch and wheel listeners with {passive: true} to indicate that they will never invoke preventDefault. This feature shipped in Chrome 51, Firefox 49 and landed in WebKit. For full official explanation read more here.

其实说白了就是个新特性,似乎是用来提高移动端页面滚动效率的?

我也整不太明白,这也不是个错误,只是个警告。

解决方法非常简单,看下面

解决方法

有两种方法,我倾向于第二种

1、在鼠标滚动方法上加上passive,如下所示

@mouseleave.passive="leave"

2、安装扩展,一劳永逸

npm i default-passive-events -S

安装后,在main.js里引入即可

import 'default-passive-events'