@@ -3,6 +3,7 @@ import genViteConfig from './templateFiles/genViteConfig'
33import getPackageJson from './templateFiles/packageJson'
44import gitIgnoreFile from './templateFiles/.gitignore?raw'
55import entryHTMLFile from './templateFiles/index.html?raw'
6+ import logoImage from './templateFiles/public/favicon.ico'
67import mainJSFile from './templateFiles/src/main.js?raw'
78import appVueFile from './templateFiles/src/App.vue?raw'
89import bridgeFile from './templateFiles/src/lowcodeConfig/bridge.js?raw'
@@ -32,6 +33,36 @@ const getTemplate = (schema, str) => {
3233 } )
3334}
3435
36+ /**
37+ * 图片的 base64 转 Blob 对象,用于生成本地图片
38+ * @param {* } base64 String
39+ * @returns Blob
40+ */
41+ const base64ToBlob = ( base64Data ) => {
42+ // Split base64
43+ const arr = base64Data . split ( ',' )
44+ // Get MIME type
45+ const mimeMatch = arr [ 0 ] . match ( / : ( .* ?) ; / )
46+ if ( ! mimeMatch ) {
47+ throw new Error ( 'Invalid base64 data' )
48+ }
49+ const mime = mimeMatch [ 1 ]
50+ // Decode base64 string
51+ let raw
52+ try {
53+ raw = window . atob ( arr [ 1 ] )
54+ } catch ( e ) {
55+ throw new Error ( 'Failed to decode base64 string' )
56+ }
57+ const rawLength = raw . length
58+ // Convert to Blob
59+ const uInt8Array = new Uint8Array ( rawLength )
60+ for ( let i = 0 ; i < rawLength ; i ++ ) {
61+ uInt8Array [ i ] = raw . charCodeAt ( i )
62+ }
63+ return new Blob ( [ uInt8Array ] , { type : mime } )
64+ }
65+
3566/**
3667 * get project template
3768 * @returns
@@ -67,6 +98,12 @@ export function generateTemplate(schema) {
6798 path : '.' ,
6899 fileContent : getTemplate ( schema , entryHTMLFile )
69100 } ,
101+ {
102+ fileType : 'image/x-icon' ,
103+ fileName : 'favicon.ico' ,
104+ path : './public' ,
105+ fileContent : base64ToBlob ( logoImage )
106+ } ,
70107 {
71108 fileType : 'js' ,
72109 fileName : 'main.js' ,
0 commit comments