Browse Source

升级相关依赖,移除多余插件

caner 1 year ago
parent
commit
bcc1454e68
5 changed files with 19 additions and 308 deletions
  1. 9 9
      package.json
  2. 0 172
      src/services/exportFile.ts
  3. 0 87
      src/services/laglat2gauss.ts
  4. 0 37
      src/services/registerMenu.ts
  5. 10 3
      vite.config.ts

+ 9 - 9
package.json

@@ -20,18 +20,18 @@
   },
   "devDependencies": {
     "@types/node": "^20.10.4",
-    "@typescript-eslint/parser": "^7.16.0",
-    "@vitejs/plugin-vue": "^5.0.5",
-    "eslint": "^8.57.0",
+    "@typescript-eslint/parser": "^8.15.0",
+    "@vitejs/plugin-vue": "^5.2.0",
+    "eslint": "^8.2.0",
     "eslint-config-airbnb-base": "^15.0.0",
-    "eslint-plugin-import": "^2.29.1",
-    "eslint-plugin-vue": "^9.27.0",
-    "sass": "^1.77.8",
-    "typescript": "^5.5.3",
-    "vite": "^5.3.3",
+    "eslint-plugin-import": "^2.31.0",
+    "eslint-plugin-vue": "^9.31.0",
+    "sass": "^1.81.0",
+    "typescript": "^5.6.3",
+    "vite": "^5.4.11",
     "vite-plugin-compression": "^0.5.1",
     "vite-plugin-eslint": "^1.8.1",
     "vite-plugin-svg-icons": "^2.0.1",
-    "vue-tsc": "^2.0.26"
+    "vue-tsc": "^2.1.10"
   }
 }

+ 0 - 172
src/services/exportFile.ts

@@ -1,172 +0,0 @@
-import html2canvas from "html2canvas";
-import JSPDF from "jspdf";
-import * as XLSX from 'xlsx'
-
-/**
- * 导出PDF
- * @param domID 需要输出PDF的页面id
- * @param fileName 文件名
- * @param type  默认A4分页
- * @param wMultiple 宽倍数
- * @param hMultiple 高倍数
- * @returns 
- */
-export const exp2pdf = async (domID: string, fileName: string, type = 'A4', wMultiple = null, hMultiple = null) => {
-    const dom = document.getElementById(domID)
-    if (!dom) return
-    // loading
-    const domHeight = dom.offsetHeight // 获取DOM高度
-    const domWidth = dom.offsetWidth // 获取DOM宽度
-    const canvas = await html2canvas(dom, {
-        logging: false,
-        useCORS: true, // 允许图片跨域   
-        scale: 1.5,
-        width: wMultiple ? wMultiple * domWidth : undefined,
-        height: hMultiple ? hMultiple * domHeight : undefined
-    })
-
-    if (type === 'A4') {
-        // A4分页
-        const pdf = new JSPDF("p", "mm", "a4") // A4纸,纵向
-        const ctx = canvas.getContext("2d") as any
-        const a4w = 200;
-        const a4h = 277 // A4大小,210mm x 297mm,四边各保留20mm的边距
-        const imgHeight = Math.floor(a4h * canvas.width / a4w) // 按A4显示比例换算一页图像的像素高度
-        let renderedHeight = 0
-        while (renderedHeight < canvas.height) {
-            const page = document.createElement("canvas")
-            page.width = canvas.width
-            page.height = Math.min(imgHeight, canvas.height - renderedHeight) // 可能内容不足一页
-            // 用getImageData剪裁指定区域,并画到前面创建的canvas对象中
-            page.getContext("2d")?.putImageData(ctx.getImageData(0, renderedHeight, canvas.width, Math.min(imgHeight, canvas.height - renderedHeight)), 0, 0)
-            pdf.addImage(page.toDataURL("image/jpeg", 1.0), "JPEG", 10, 10, a4w, Math.min(a4h, a4w * page.height / page.width)) // 添加图像到页面,保留10mm边距
-            renderedHeight += imgHeight
-            if (renderedHeight < canvas.height) { pdf.addPage() } // 如果后面还有内容,添加一个空页
-            // delete page;
-        }
-        pdf.save(fileName)
-
-    } else {
-        // 整张
-        const pdf = new JSPDF('p', 'px', [domWidth, domHeight])
-        pdf.addImage(canvas.toDataURL("image/jpeg", 1.0), "JPEG", 10, 10, domWidth, domHeight)
-        pdf.save(fileName)
-    }
-    // loading
-}
-
-/**
- * 导出PNG
- * @param domID 需要输出PDF的页面id
- * @param fileName 文件名
- * @param bkcolor 背景色
- */
-export const exp2png = async (domID: string, fileName: string, bkcolor: string) => {
-    // loading
-    window.scroll(0, 0) // 首先先顶部
-    const design = document.getElementById(domID) as HTMLElement
-    if (!design) return
-    const imgHeight = design.offsetHeight // 获取DOM高度
-    const imgWidth = design.offsetWidth // 获取DOM宽度
-    const scale = window.devicePixelRatio <= 3 ? 3 : window.devicePixelRatio // 获取设备像素比
-    const canvas = await html2canvas(design, {
-        backgroundColor: bkcolor, // 设置背景颜色
-        useCORS: true, // 允许图片跨域
-        scale: scale, // 缩放3倍,使得图片更加清晰=>越清晰图片越大
-        width: imgWidth,
-        height: imgHeight,
-        imageTimeout: 5000 // 设置图片的超时,设置0为禁用
-    })
-    const imgURL = canvas.toDataURL('image/png')
-    return imgURL
-    // loading
-}
-
-/**
- * 解析excel表格
- * @param file 文件
- * @returns 
- */
-export const exp2json = async (file: File) => {
-    return await new Promise((resolve, reject) => {
-        try {
-            const reader = new FileReader()
-            reader.onload = (e) => {
-                const wb = XLSX.read(e.target?.result, {
-                    type: 'binary'
-                }) // 读取完成的数据
-                // 转成json header解析第一行标题
-                const data = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]], { header: 1 })
-                resolve(data)
-            }
-            reader.readAsBinaryString(file)
-        } catch (error) {
-            console.log('解析错误')
-            reject(error)
-        }
-    })
-}
-
-/**
- * dom导出excel
- * @param domID domID
- * @param fileName 文件名
- */
-export const dom2excel = (domID: string, fileName: string) => {
-    const dom = document.getElementsByTagName(domID)
-    if (!dom) return
-    const wb = XLSX.utils.table_to_book(dom[0])
-    const baty = XLSX.write(wb, { bookType: 'xlsx', bookSST: false, type: 'binary' })
-    // 字符串转ArrayBuffer
-    const s2ab = (s: any) => {
-        const buf = new ArrayBuffer(s.length)
-        const view = new Uint8Array(buf)
-        for (let i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF
-        return buf
-    }
-    const blob = new Blob([s2ab(baty)], { type: 'application/octet-stream' })
-    return blob
-}
-
-/**
- * array导出excel表格
- * @param arr 数据是数组包含的对象
- * @param fileName 名字
- */
-export const exp2excel = (arr: object[], fileName: string, cellMerges?: Array<any>) => {
-    const sheet = XLSX.utils.json_to_sheet(arr);
-    // excel宽高设置
-    sheet["!cols"] = arr.map(() => {
-        return { wch: 30 }
-    })
-    if (cellMerges) {
-        sheet['!merges'] = cellMerges; // <====合并单元格
-    }
-    // 转blob
-    const sheet2blob = (sheet: any, sheetName = 'sheet1') => {
-        const workbook = {
-            SheetNames: [sheetName],
-            Sheets: {} as any
-        };
-        workbook.Sheets[sheetName] = sheet;
-        // 生成excel的配置项
-        const wopts = {
-            bookType: 'xlsx', // 要生成的文件类型
-            bookSST: false, // 是否生成Shared String Table,官方解释是,如果开启生成速度会下降,但在低版本IOS设备上有更好的兼容性
-            type: 'binary'
-        } as any
-        const wbout = XLSX.write(workbook, wopts);
-        // 字符串转ArrayBuffer
-        const s2ab = (s: string) => {
-            let buf = new ArrayBuffer(s.length);
-            let view = new Uint8Array(buf);
-            for (let i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
-            return buf;
-        }
-        const blob = new Blob([s2ab(wbout)], { type: "application/octet-stream" });
-
-        return blob;
-    }
-
-    return sheet2blob(sheet)
-}

+ 0 - 87
src/services/laglat2gauss.ts

@@ -1,87 +0,0 @@
-// 大地坐标与经纬度坐标互转
-
-
-function GaussToBL(X: number,Y: number){
-    let ProjNo;
-    let ZoneWide; //带宽
-    let output = new Array(2);
-    let longitude1,latitude1, longitude0, X0,Y0, xval,yval;//latitude0,
-    let e1,e2,f,a, ee, NN, T,C, M, D,R,u,fai, iPI;
-    iPI = 3.14159265358979324/180.0; 3.1415926535898/180.0;
-    // a = 6378245.0; f = 1.0/298.3; //54年北京坐标系参数
-    a=6378140.0; f=1.0/298.257; //80年西安坐标系参数
-    ZoneWide = 6; //6度带宽
-    ProjNo = Math.floor(X/1000000) ; //查找带号
-    longitude0 = (ProjNo-1) * ZoneWide + ZoneWide / 2;
-    longitude0 = longitude0 * iPI ; //中央经线
-
-
-    X0 = ProjNo*1000000+500000;
-    Y0 = 0;
-    xval = X-X0; yval = Y-Y0; //带内大地坐标
-    e2 = 2*f-f*f;
-    e1 = (1.0-Math.sqrt(1-e2))/(1.0+Math.sqrt(1-e2));
-    ee = e2/(1-e2);
-    M = yval;
-    u = M/(a*(1-e2/4-3*e2*e2/64-5*e2*e2*e2/256));
-    fai = u+(3*e1/2-27*e1*e1*e1/32)*Math.sin(2*u)+(21*e1*e1/16-55*e1*e1*e1*e1/32)*Math.sin(4*u) +(151*e1*e1*e1/96)*
-        Math.sin(6*u)+(1097*e1*e1*e1*e1/512)*Math.sin(8*u);
-    C = ee*Math.cos(fai)*Math.cos(fai);
-    T = Math.tan(fai)*Math.tan(fai);
-    NN = a/Math.sqrt(1.0-e2*Math.sin(fai)*Math.sin(fai));
-    R = a*(1-e2)/Math.sqrt((1-e2*Math.sin(fai)*Math.sin(fai))*(1-e2*Math.sin(fai)*Math.sin(fai))*(1-e2*Math.sin
-    (fai)*Math.sin(fai)));
-    D = xval/NN;
-    //计算经度(Longitude) 纬度(Latitude)
-    longitude1 = longitude0+(D-(1+2*T+C)*D*D*D/6+(5-2*C+28*T-3*C*C+8*ee+24*T*T)*D
-        *D*D*D*D/120)/Math.cos(fai);
-    latitude1 = fai -(NN*Math.tan(fai)/R)*(D*D/2-(5+3*T+10*C-4*C*C-9*ee)*D*D*D*D/24
-        +(61+90*T+298*C+45*T*T-256*ee-3*C*C)*D*D*D*D*D*D/720);
-    //转换为度 DD
-    output[0] = longitude1 / iPI;
-    output[1] = latitude1 / iPI;
-    return output;
-}
-
-//经纬度=>高斯投影
-function BLToGauss(longitude: number, latitude: number){
-    let ProjNo=0;
-    let ZoneWide; //带宽
-    let ret=Array(2);
-    let longitude1,latitude1, longitude0,latitude0, X0,Y0, xval,yval;
-    let a,f, e2,ee, NN, T,C,A, M, iPI;
-    iPI = 0.0174532925199433; 3.1415926535898/180.0;
-    ZoneWide = 6; //6度带宽
-    // a=6378245.0; f=1.0/298.3; //54年北京坐标系参数
-    a=6378140.0; f=1/298.257; //80年西安坐标系参数
-    ProjNo = Math.floor(longitude / ZoneWide) ;
-    longitude0 = ProjNo * ZoneWide + ZoneWide / 2;
-    longitude0 = longitude0 * iPI ;
-    latitude0 = 0;
-    longitude1 = longitude * iPI ; //经度转换为弧度
-    latitude1 = latitude * iPI ; //纬度转换为弧度
-    e2=2*f-f*f;
-    ee=e2*(1.0-e2);
-    NN=a/Math.sqrt(1.0-e2*Math.sin(latitude1)*Math.sin(latitude1));
-    T=Math.tan(latitude1)*Math.tan(latitude1);
-    C=ee*Math.cos(latitude1)*Math.cos(latitude1);
-    A=(longitude1-longitude0)*Math.cos(latitude1);
-    M=a*((1-e2/4-3*e2*e2/64-5*e2*e2*e2/256)*latitude1-(3*e2/8+3*e2*e2/32+45*e2*e2
-        *e2/1024)*Math.sin(2*latitude1)
-        +(15*e2*e2/256+45*e2*e2*e2/1024)*Math.sin(4*latitude1)-(35*e2*e2*e2/3072)*Math.sin(6*latitude1));
-    xval = NN*(A+(1-T+C)*A*A*A/6+(5-18*T+T*T+72*C-58*ee)*A*A*A*A*A/120);
-    yval = M+NN*Math.tan(latitude1)*(A*A/2+(5-T+9*C+4*C*C)*A*A*A*A/24
-        +(61-58*T+T*T+600*C-330*ee)*A*A*A*A*A*A/720);
-    X0 = 1000000*(ProjNo+1)+500000;
-    Y0 = 0;
-    xval = xval+X0; yval = yval+Y0;
-    ret[0]=xval;
-    ret[1]=yval;
-
-    return ret;
-}
-
-export default {
-    GaussToBL,
-    BLToGauss,
-}

+ 0 - 37
src/services/registerMenu.ts

@@ -1,37 +0,0 @@
-import { Boot } from '@wangeditor/editor'
-import { exp2pdf } from './exportFile'
-console.warn('此插件注册富文本自定义按钮')
-// 注册一个保存按钮
-class SaveBtn {
-    title = ''
-    iconSvg = ''
-    tag = ''
-    constructor() {
-        this.title = '导出PDF'
-        this.iconSvg = '<svg viewBox="0 0 1024 1024" style="width:22px;height:22px;" version="1.1" xmlns="http://www.w3.org/2000/svg" ><path d="M773.696 134.812444l-509.155556 0c-69.76 0-126.520889 56.760889-126.520889 126.542222l0 501.326222c0 69.781333 56.760889 126.499556 126.520889 126.499556l509.141333 0c69.781333 0 126.520889-56.718222 126.520889-126.499556L900.202667 261.361778C900.202667 191.573333 843.441778 134.833778 773.696 134.812444zM324.437333 184.213333l389.347556 0 0 279.608889L324.437333 463.822222 324.437333 184.213333zM850.872889 762.680889c0 42.552889-34.616889 77.191111-77.169778 77.191111l-509.155556 0c-42.552889 0-77.169778-34.638222-77.169778-77.191111L187.377778 261.383111c0-42.574222 34.616889-77.169778 77.169778-77.169778l0-0.021333 10.567111 0 0 329.009778 488.007111 0 0.021333 0L763.143111 184.184889l10.567111 0c42.56 0 77.169778 34.595556 77.169778 77.169778L850.88 762.680889zM591.772444 256.832l49.329778 0 0 164.522667-49.329778 0 0-164.522667ZM591.772444 256.832"></path></svg>'
-        this.tag = 'button'
-    }
-
-    getValue() {
-        return ''
-    }
-
-    isActive() {
-        return false
-    }
-
-    isDisabled() {
-        return false
-    }
-
-    exec() {
-        exp2pdf('exportPDF', '测试' + new Date().toLocaleDateString())
-        console.log('导出');
-    }
-}
-Boot.registerMenu({
-    key: 'SaveBtn',
-    factory() {
-        return new SaveBtn()
-    }
-})

+ 10 - 3
vite.config.ts

@@ -11,6 +11,13 @@ export default ({ mode }) => {
   const env = loadEnv(mode, process.cwd())
   return defineConfig({
     base: './',
+    css: {
+      preprocessorOptions: {
+        scss: {
+          api: 'modern-compiler'
+        }
+      }
+    },
     resolve: {
       alias: {
         /*
@@ -22,9 +29,9 @@ export default ({ mode }) => {
     },
     plugins: [
       vue(), viteCompression(),
-      eslint({ fix: true, include: [ '**/*.ts', '**/*.vue' ] }),
+      eslint({ fix: true, include: ['**/*.ts', '**/*.vue'], cache: true }),
       createSvgIconsPlugin({
-        iconDirs: [ resolve(__dirname, './src/assets/icons') ],
+        iconDirs: [resolve(__dirname, './src/assets/icons')],
         // Specify symbolId format
         symbolId: 'icon-[dir]-[name]'
       })
@@ -47,7 +54,7 @@ export default ({ mode }) => {
       // }
     },
     esbuild: {
-      drop: mode === 'development' ? [ 'debugger' ] : [ 'debugger', 'console' ] // build 移除打印
+      drop: mode === 'development' ? ['debugger'] : ['debugger', 'console'] // build 移除打印
     },
     build: {
       rollupOptions: {