jwj 发布的文章

layui的数据表格用起来的确很方便,开发时能节省很多时间。但是,在投入使用后,导出的表格却是能收到很多反馈,说内容不对。不对的地方主要体现在身份证号码之类的比较长数值,用Excel软件打开后,15位以后的数值会丢失,导致身份证号码不完整。Layui最近一两年的更新力度越来越小了,经常跳票,也不知道能活多久,只能先自己动手吧~

首先,我们用文本查看工具查看导出的内容,可以确定,导出的身份证号码是完整,但用Excel软件打开之后,就出问题了。为此,我百度了下Excel的处理机制,得知,Excel显示数字时,如果数字大于12位,它会自动转化为科学计数法,如果数字大于15位,它不仅用于科学技术法表示,还会只保留高15位,其他位都变0。

如果要解决这个问题,目前只想到一个解决方法,让Excel处理这个数据的时候,不识别它为数值。这要怎么做呢?

首先,我们先前往github下载未压缩过的代码,搜索table.exportFile = function
这个方法的原始代码如下

//表格导出
table.exportFile = function(id, data, type){
    var that = this;

    data = data || table.clearCacheKey(table.cache[id]);
    type = type || 'csv';

    var config = thisTable.config[id] || {}
        ,textType = ({
        csv: 'text/csv'
        ,xls: 'application/vnd.ms-excel'
    })[type]
        ,alink = document.createElement("a");

    if(device.ie) return hint.error('IE_NOT_SUPPORT_EXPORTS');

    alink.href = 'data:'+ textType +';charset=utf-8,\ufeff'+ encodeURIComponent(function(){
        var dataTitle = [], dataMain = [], dataTotal = [];

        //表头和表体
        layui.each(data, function(i1, item1){
            var vals = [];
            if(typeof id === 'object'){ //如果 id 参数直接为表头数据
                layui.each(id, function(i, item){
                    i1 == 0 && dataTitle.push(item || '');
                });
                layui.each(table.clearCacheKey(item1), function(i2, item2){
                    vals.push('"'+ (item2 || '') +'"');
                });
            } else {
                table.eachCols(id, function(i3, item3){
                    if(item3.field && item3.type == 'normal' && !item3.hide){
                        var content = item1[item3.field];
                        if(content === undefined || content === null) content = '';

                        i1 == 0 && dataTitle.push(item3.title || '');
                        vals.push('"'+ parseTempData(item3, content, item1, 'text') + '"');
                    }
                });
            }
            dataMain.push(vals.join(','));
        });

        //表合计
        layui.each(that.dataTotal, function(key, value){
            dataTotal.push(value);
        });

        return dataTitle.join(',') + '\r\n' + dataMain.join('\r\n') + '\r\n' + dataTotal.join(',');
    }());

    alink.download = (config.title || 'table_'+ (config.index || '')) + '.' + type;
    document.body.appendChild(alink);
    alink.click();
    document.body.removeChild(alink);
};

然后将里面的

vals.push('"'+ parseTempData(item3, content, item1, 'text') + '"');

替换成

content = parseTempData(item3, content, item1, 'text').replace(/(^\s*)|(\s*$)/g, "");
if (/^\d+$/.test(content) && content.length > 15 && type == 'xls') {
    vals.push('="'+ content + '"');
} else {
    vals.push('"'+ content + '"');
}

显示问题解决了,但不适合用于数据运算,但办公室的Excel大神们应该有办法吧。反正我能让他正常显示就行了,其它我不管,哈哈。

哦,对了,差点忘了标题。上面只是解决了数值大于15位会丢失尾数的问题,并没有解决科学计数法的问题。如果想不显示科学计数法,将里面的代码替换下即可。其实推荐使用上面的代码就可以了,科学计数法问题可以设置单元格格式来解决。

vals.push('"'+ parseTempData(item3, content, item1, 'text') + '"');

替换成

content = parseTempData(item3, content, item1, 'text').replace(/(^\s*)|(\s*$)/g, "");
if (/^\d+$/.test(content) && content.length > 12 && type == 'xls') {
    vals.push('="'+ content + '"');
} else {
    vals.push('"'+ content + '"');
}

每次要在电脑上启动v2ray还是挺不方便的,直接在路由器运行,这样局域网的设备都能直接使用,方便很多。

更新opkg源

opkg update
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/targets/ralink/mt7621/packages/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_core
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/base/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_base
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/newifi/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_newifi
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/pear/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_pear
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/packages/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_packages
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/luci/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_luci
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/lafite/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_lafite
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/mtkdrv/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_mtkdrv

安装unzip

opkg install unzip
Installing unzip (6.0-2) to root...
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/packages/unzip_6.0-2_mipsel_1004kc_dsp.ipk
Configuring unzip.

安装ssl ca证书

opkg install wget ca-certificates openssl-util ca-bundle
Package wget (1.18-2) installed in root is up to date.
Installing ca-certificates (20160104) to root...
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/base/ca-certificates_20160104_all.ipk
Installing openssl-util (1.0.2o-1) to root...
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/base/openssl-util_1.0.2o-1_mipsel_1004kc_dsp.ipk
Installing ca-bundle (20160104) to root...
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/base/ca-bundle_20160104_all.ipk
Configuring openssl-util.
Configuring ca-certificates.
Configuring ca-bundle.

下载v2ray

wget https://github.com/v2ray/v2ray-core/releases/download/v4.23.1/v2ray-linux-mipsle.zip

解压v2ray

unzip v2ray-linux-mipsle.zip
Archive:  v2ray-linux-mipsle.zip
  inflating: config.json
   creating: doc/
  inflating: doc/readme.md
  inflating: geoip.dat
  inflating: geosite.dat
   creating: systemd/
  inflating: systemd/v2ray.service
   creating: systemv/
  inflating: systemv/v2ray
  inflating: v2ctl
 extracting: v2ctl.sig
  inflating: v2ctl_softfloat
 extracting: v2ctl_softfloat.sig
  inflating: v2ray
 extracting: v2ray.sig
  inflating: v2ray_softfloat
 extracting: v2ray_softfloat.sig
  inflating: vpoint_socks_vmess.json
  inflating: vpoint_vmess_freedom.json

配置v2ray

省略,跟linux或windows端一样配置

运行v2ray

./v2ray
V2Ray 4.23.1 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.13 linux/mipsle)
A unified platform for anti-censorship.
2020/04/11 13:35:08 Using default config:  /mnt/sda1/v2ray/config.json
2020/04/11 13:35:11 [Info] v2ray.com/core/common/platform/ctlcmd: <v2ctl message>
v2ctl> Read config:  /mnt/sda1/v2ray/config.json
2020/04/11 13:35:12 [Warning] v2ray.com/core: V2Ray 4.23.1 started

写入启动项

系统 - 启动项 - 本地启动脚本

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

/mnt/sda1/v2ray/v2ray >/dev/null 2>&1 &

exit 0

下载:https://downloads.mysql.com/archives/community/
解压到:C:\Program Files目录
创建my.ini配置文件

[mysql]
port = 3306
default-character-set=utf8

[mysqld]
default_authentication_plugin=mysql_native_password
port = 3306
basedir="C:/Program Files/mysql-5.7.28-winx64"
datadir="C:/Program Files/mysql-5.7.28-winx64/data"
log-error="C:/Program Files/mysql-5.7.28-winx64/logs/mysql.log"
character-set-server=utf8
default-storage-engine=INNODB

C:/Program Files/mysql-5.7.28-winx64加入环境变量
初始化mysql

mysqld --initialize-insecure --user=root

初始化后,默认用户为root,密码为空
安装服务

mysqld --install

执行返回

Service successfully installed.

启动服务

今天重新安装了下Wampserver3.2.0,安装好之后,发下MySQL8.0数据库的服务一直启动不了,查看事件查看器应用程序日志没有错误信息,查看MySQL日志也没有错误信息,这就很蛋疼了!

既然通过刚刚那些地方都找不到错误信息,只能在控制台尝试运行下mysql了。在控制台打开mysqlbin目录,然后输入

./mysqld

返回以下错误

2020-03-08T12:13:19.585857Z 0 [System] [MY-010116] [Server] C:\wamp64\bin\mysql\mysql8.0.18\bin\mysqld.exe (mysqld 8.0.18) starting as process 3132
2020-03-08T12:13:19.813867Z 0 [Warning] [MY-010091] [Server] Can't create test file C:\wamp64\bin\mysql\mysql8.0.18\data\mysqld_tmp_file_case_insensitive_test.lower-test
2020-03-08T12:13:19.814672Z 0 [Warning] [MY-010091] [Server] Can't create test file C:\wamp64\bin\mysql\mysql8.0.18\data\mysqld_tmp_file_case_insensitive_test.lower-test
2020-03-08T12:13:19.815318Z 0 [ERROR] [MY-013276] [Server] Failed to set datadir to 'C:\wamp64\bin\mysql\mysql8.0.18\data\' (OS errno: 2 - No such file or directory)
2020-03-08T12:13:19.988677Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-03-08T12:13:19.997084Z 0 [System] [MY-010910] [Server] C:\wamp64\bin\mysql\mysql8.0.18\bin\mysqld.exe: Shutdown complete (mysqld 8.0.18)  MySQL Community Server - GPL.

通过错误信息,可以知道,因为文件无法创建,导致MySQL启动失败。再检查下MySQLdata目录,发现这个目录不存在。
然后回想下安装过程,安装的时候,因为没有提前安装好运行库,所以安装过程中,提示了几次缺少xxx.dll。我想应该是这个原因,导致MySQL初始化失败了。
那就手动初始化下吧~还是打开控制台,在控制台打开mysqlbin目录,然后输入以下命令

mysqld --initialize-insecure --user=root

执行完之后,再尝试启动MySQL的服务,正常运行~

最近,一打开v2ray.exe就闪退,日志文件里也没有记录到错误信息,试了好久都找不到具体原因。后面尝试在控制台打开v2ray.exe,才发现具体的错误信息,然后问题也顺利解决了。

打开CMD控制台,转到v2ray所在目录,然后执行下面的命令

# .\v2ray.exe

命令执行后,提示以下错误信息

V2Ray 4.21.3 (V2Fly, a community-driven edition of V2Ray.) Custom
A unified platform for anti-censorship.
Failed to start v2ray.com/core/app/proxyman/inbound: failed to listen TCP on 1080 > v2ray.com/core/transport/internet: failed to listen on address: 0.0.0.0:1080 > listen tcp 0.0.0.0:1080: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

大概意思是

启动失败:无法监听TCP 1080端口,无法监听0.0.0.0:1080地址,无权访问socket

找了下资料,得到的信息很少,尝试把0.0.0.0换成127.0.0.1也不行。然后想,是不是端口被占用了,执行netstat -ano|findstr ":1080",也没有找到被谁占用,但还是尝试换了个端口,竟然没有问题了。

虽然问题解决了,但原因没找到,这就很纳闷了。一直到家里的电脑突然也出现了同样的问题以后,仔细想想,才知道是什么导致了的。
原来是我装了Hyper-V,导致1080端口被系统保留了,真是操蛋了~

用下面这命令在控制台执行,可以查看系统保留的tcp端口

netsh interface ipv4 show excludedportrange protocol=tcp

用下面这命令在控制台执行,可以查看系统保留的udp端口

netsh interface ipv4 show excludedportrange protocol=udp

如果确实解决不了系统保留的问题,我们就只能改端口了,改成系统保留范围外的端口。