GitBucket
4.6.0
Toggle navigation
Sign in
Files
Branches
1
Tags
Issues
Pull Requests
Labels
Milestones
Wiki
08335
/
hivui-platform-template
hivui平台项目模板
Browse code
Jenkins commit
master
1 parent
d154865
commit
142cb0685053feb4ef11b619bed5d49b0836bed3
12896
authored
on 17 Jul 2023
Showing
2 changed files
project/hivuiMain/App.vue
vite-plugin/vite-plugin-func.js
Ignore Space
Show notes
View
project/hivuiMain/App.vue
<template> <div class="app"> <transition> <router-view v-if="$store.state.appStatus=='success'" /> </transition> <transition> <div v-if="$store.state.appStatus!='success'" class="loader" > <div class="pl-logo-lg fadeInUp animated"> <img :src="logoSrc" v-if="logoSrc!=''" > </div> <span class="txt"> <span v-for="(str,index) in loadTexts" :key="index">{{str}}</span> <span v-if="$store.state.appStatus=='loading'">{{$t('hivuiMain_sysLoading')}}</span> <span v-if="$store.state.appStatus!='loading'" style="color:red" @click="handleReload" >{{$store.state.appStatusMsg||$t('hivuiMain_loadedFailClickRefresh')}}</span> </span> </div> </transition> </div> </template> <script> import Cookies from 'js-cookie' import LoginPic from "@main/assets/logo_max.png" import { getUrlValue, setUrlValue,getUrlSearch } from "@main/utils"; import { getToken } from '@main/utils/auth' export default { data() { return { loadTexts: "", logoSrc: "" }; }, methods: { handleReload() { window.location.reload(); }, detectZoom (){ var ratio = 0, screen = window.screen, ua = navigator.userAgent.toLowerCase(); if (window.devicePixelRatio !== undefined) { ratio = window.devicePixelRatio; } else if (~ua.indexOf('msie')) { if (screen.deviceXDPI && screen.logicalXDPI) { ratio = screen.deviceXDPI / screen.logicalXDPI; } } else if (window.outerWidth !== undefined && window.innerWidth !== undefined) { ratio = window.outerWidth / window.innerWidth; } if (ratio){ ratio = Math.round(ratio * 100); } return ratio; }, checkZoom(){ let ratio = this.detectZoom(); if(ratio!=100){ // this.$message.error('警告,浏览器没有按正常比例显示会影响部份功能!') } }, }, mounted() { // this.checkZoom(); // window.addEventListener('resize',()=>{ // this.checkZoom(); // }); let me=this; // 设置任务中心刷新状态 top.window.__setRefreshTaskcenter = function (state) { if(state==undefined){ state = true; } top.window.__refreshTaskcenter = state; } let urlPn=getUrlValue(location.search,"pn"); if(urlPn){ if(!getUrlValue(window.HIVUI_SETTING.loginUrl,"pn")){ window.HIVUI_SETTING.loginUrl+="?pn="+urlPn; } if(!getUrlValue(window.HIVUI_SETTING.mainPageUrl,"pn")){ window.HIVUI_SETTING.mainPageUrl+="?pn="+urlPn; } } //如果token不一致,替换掉然后重新载入 let urlToken=getUrlValue(location.href,"access_token"); let nowToken=getToken(); if(!window._global&&urlToken&&nowToken&&(urlToken!=nowToken)){//正式环境 let newUrl=setUrlValue(decodeURIComponent(location.href),"access_token",nowToken); location=newUrl; location.reload(); } //系统间跳转,将ticket去除 if(!window._global&&getUrlValue(decodeURIComponent(location.href),"ticket")){ let newUrl=setUrlValue(decodeURIComponent(location.href),"ticket",""); location=newUrl.replace("&ticket=","")+"#/"; //location.reload(); } window.Scp = { User: { id: "admin", name: "管理员", deptId: "", deptName: "", positionId: "GLY", postionName: "管理员", bzId: "admin_3", bzName: "管理员岗位3", bzDeptId: ".WLDJT.DGS", bzDeptName: "D公司", bzPositionId: "HQRY", bzPositionName: "后勤人员", orgId: "admin_3", defOrgId: "admin_3" } } //customSysCofig默认值 window.customSysCofig=_.merge({ showMiniLogin:true, },window.customSysCofig); if(!window.localStorage.getItem("locale")){ window.localStorage.setItem("locale",JSON.stringify({ desc:"中文", name:"zh-CN", })); Cookies.set("locale","zh-CN"); } window.__guid = new Date().valueOf(); //window.customSysCofig=_.merge(window.default_customSysCfg,window.customSysCofig||{}); window.customSysCofig&&window.customSysCofig.thirdParty&&window.customSysCofig.thirdParty.forEach((item)=>{//第三方脚本样式资源引用 let _dom; switch(item.type){ case "js": _dom=document.createElement("script"); _dom.type="text/javascript"; _dom.src=item.link; break; case "css": _dom=document.createElement("link"); _dom.rel="stylesheet"; _dom.href=item.link; break; } document.querySelector("head").appendChild(_dom); }); setTimeout(()=>{ window.__sysConfig = _.merge({ events: { onLoad1: function () { } }, projectName: "eaptpl", /*sysProjectMange: { id: __guid++, name: '工程树', iconClass: 'icon-tree', uri: 'amreport/designer/tree/design.do', url: '/amrept-web/amreport/designer/tree/design.do' },*/ sysList: [ ], langList:{ id: __guid++, name: (window.localStorage.getItem("locale")?(JSON.parse(window.localStorage.getItem("locale")).desc):"中文"), type: 'lang', iconClass: 'icon-edit', children: [ { id: __guid++, name:"中文", handler:function(){ window.localStorage.setItem("locale",JSON.stringify({ desc:"中文", name:"zh-CN", })); Cookies.set("locale","zh-CN"); window.location.reload(); }, }, { id: __guid++, name:"English", handler:function(){ window.localStorage.setItem("locale",JSON.stringify({ desc:"English", name:"en", })); Cookies.set("locale","en"); window.location.reload(); }, }, ] }, userInfo:{ id: __guid++, name: '${fusername}', type: 'userInfo', iconClass: 'icon-user', children: [ { id: __guid++, name:me.$t('hivuiMain_app_user')+':${fusername}/${fuserid}', iconClass:'icon-user', }, { id: __guid++, name:me.$t('hivuiMain_app_orgbz')+':${fbzname}/${fbzid}', iconClass:'icon-user', type:"orgBz", }, { id: __guid++, name:me.$t('hivuiMain_app_orgname')+':${forgname}/${forgid}', iconClass:'icon-user', }, { id: __guid++, name:me.$t('hivuiMain_app_rolename')+':${frolename}/${froleid}', iconClass:'icon-user', }, { id: __guid++, name:me.$t('hivuiMain_app_personal_Center'), iconClass:'icon-user', type: "personalCenter" }, /*{ id: __guid++, iconClass:'icon-edit', name:'修改用户信息', type:'modifyUserInfo', },*/ { id: __guid++, iconClass:'icon-edit', name:me.$t('hivuiMain_app_modifyPw'), type:'modifyPw', }, ] }, },window.customSysCofig); this.$store.dispatch("app/getSysConfig").then(res=>{ let cfg = this.$store.state.app.config || {}; let loadText = (cfg.sysLoadLogo && cfg.sysLoadLogo.title) || ""; let logoSrc = (cfg.sysLoadLogo && cfg.sysLoadLogo.src) || ""; this.loadTexts=loadText.split(""); this.logoSrc=logoSrc||LoginPic; }); },0); } }; </script> <style scoped> .app { height: 100%; background: linear-gradient( rgb(255, 255, 255) 0px, rgb(243, 248, 253) 50%, rgb(229, 240, 250) ); } .animated { -webkit-animation-duration: 1s; animation-duration: 1s; -webkit-animation-fill-mode: both; animation-fill-mode: both; } @-webkit-keyframes fadeInUp { 0% { opacity: 0; -webkit-transform: translate3d(0, 100%, 0); transform: translate3d(0, 100%, 0); } to { opacity: 1; -webkit-transform: translateZ(0); transform: translateZ(0); } } @keyframes fadeInUp { 0% { opacity: 0; -webkit-transform: translate3d(0, 100%, 0); transform: translate3d(0, 100%, 0); } to { opacity: 1; -webkit-transform: translateZ(0); transform: translateZ(0); } } .fadeInUp { -webkit-animation-name: fadeInUp; animation-name: fadeInUp; } @-webkit-keyframes fadeInDown { 0% { opacity: 0; -webkit-transform: translate3d(0, -100%, 0); transform: translate3d(0, -100%, 0); } to { opacity: 1; -webkit-transform: translateZ(0); transform: translateZ(0); } } @keyframes fadeInDown { 0% { opacity: 0; -webkit-transform: translate3d(0, -100%, 0); transform: translate3d(0, -100%, 0); } to { opacity: 1; -webkit-transform: translateZ(0); transform: translateZ(0); } } .fadeInDown { -webkit-animation-name: fadeInDown; animation-name: fadeInDown; } .loader { position: absolute; top: 50%; left: 50%; margin-top: -50px; -webkit-transform: translate(-50%, -50%); -moz-transform: translate(-50%, -50%); -mos-transform: translate(-50%, -50%); -o-transform: translate(-50%, -50%); transform: translate(-50%, -50%); text-align: center; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; cursor: default; } .loader .txt { display: inline-block; word-break: normal; white-space: nowrap; margin: auto; text-shadow: 0 1px 0 #ccc, 0 2px 0 #c9c9c9, 0 3px 0 #bbb, 0 4px 0 #b9b9b9, 0 5px 0 #aaa, 0 6px 1px rgba(0, 0, 0, 0.1), 0 0 5px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.1), 0 3px 5px rgba(0, 0, 0, 0.1), 0 5px 10px rgba(0, 0, 0, 0.1), 0 10px 10px rgba(0, 0, 0, 0.1), 0 20px 20px rgba(0, 0, 0, 0.15); } .loader .txt span { display: inline-block; font-size: 68px !important; padding: 0 5px; -webkit-animation: text cubic-bezier(0.75, 0, 0.5, 1) 1.2s infinite; -moz-animation: text cubic-bezier(0.75, 0, 0.5, 1) 1.2s infinite; -moz-animation: text cubic-bezier(0.75, 0, 0.5, 1) 1.2s infinite; -ms-animation: text cubic-bezier(0.75, 0, 0.5, 1) 1.2s infinite; -o-animation: text cubic-bezier(0.75, 0, 0.5, 1) 1.2s infinite; animation: text cubic-bezier(0.75, 0, 0.5, 1) 1.2s infinite; color: #0066cc; } .loader .txt span:nth-child(1) { -webkit-animation-delay: 0ms; -moz-animation-delay: 0ms; -ms-animation-delay: 0ms; -o-animation-delay: 0ms; animation-delay: 0ms; } .loader .txt span:nth-child(2) { -webkit-animation-delay: 100ms; -moz-animation-delay: 100ms; -ms-animation-delay: 100ms; -o-animation-delay: 100ms; animation-delay: 100ms; } .loader .txt span:nth-child(3) { -webkit-animation-delay: 200ms; -moz-animation-delay: 200ms; -ms-animation-delay: 200ms; -o-animation-delay: 200ms; animation-delay: 200ms; } .loader .txt span:nth-child(4) { -webkit-animation-delay: 300ms; -moz-animation-delay: 300ms; -ms-animation-delay: 300ms; -o-animation-delay: 300ms; animation-delay: 300ms; } .loader .txt span:nth-child(5) { -webkit-animation-delay: 400ms; -moz-animation-delay: 400ms; -ms-animation-delay: 400ms; -o-animation-delay: 400ms; animation-delay: 400ms; } .loader .txt span:nth-child(6) { -webkit-animation-delay: 500ms; -moz-animation-delay: 500ms; -ms-animation-delay: 500ms; -o-animation-delay: 500ms; animation-delay: 500ms; } .loader .txt span:nth-child(7) { -webkit-animation-delay: 600ms; -moz-animation-delay: 600ms; -ms-animation-delay: 600ms; -o-animation-delay: 600ms; animation-delay: 600ms; } .loader .txt span:nth-child(8) { -webkit-animation-delay: 700ms; -moz-animation-delay: 700ms; -ms-animation-delay: 700ms; -o-animation-delay: 700ms; animation-delay: 700ms; } .loader .txt span:nth-child(9) { -webkit-animation-delay: 800ms; -moz-animation-delay: 800ms; -ms-animation-delay: 800ms; -o-animation-delay: 800ms; animation-delay: 800ms; } .loader .txt span:nth-child(10) { -webkit-animation-delay: 900ms; -moz-animation-delay: 900ms; -ms-animation-delay: 900ms; -o-animation-delay: 900ms; animation-delay: 900ms; } .loader .txt span:last-child { display: block; padding-top: 15px; font-size: 16px !important; text-shadow: none; color: #0272bd; text-shadow: none; animation: none; -webkit-animation: none; } @-webkit-keyframes text { 0% { color: #0066cc; } 40% { color: #fff; } 70%, 100% { color: #0066cc; } } @-moz-keyframes text { 0% { color: #0066cc; } 40% { color: #fff; } 70%, 100% { color: #0066cc; } } @-mos-keyframes text { 0% { color: #0066cc; } 40% { color: #fff; } 70%, 100% { color: #0066cc; } } @-o-keyframes text { 0% { color: #0066cc; } 40% { color: #fff; } 70%, 100% { color: #0066cc; } } @keyframes text { 0% { color: #0066cc; } 40% { color: #fff; } 70%, 100% { color: #0066cc; } } </style>
<template> <div class="app"> <transition> <router-view v-if="$store.state.appStatus=='success'" /> </transition> <transition> <div v-if="$store.state.appStatus!='success'" class="loader" > <div class="pl-logo-lg fadeInUp animated"> <img :src="logoSrc" v-if="logoSrc!=''" > </div> <span class="txt"> <span v-for="(str,index) in loadTexts" :key="index">{{str}}</span> <span v-if="$store.state.appStatus=='loading'">{{$t('hivuiMain_sysLoading')}}</span> <span v-if="$store.state.appStatus!='loading'" style="color:red" @click="handleReload" >{{$store.state.appStatusMsg||$t('hivuiMain_loadedFailClickRefresh')}}</span> </span> </div> </transition> </div> </template> <script> import Cookies from 'js-cookie' import LoginPic from "@main/assets/logo_max.png" import { getUrlValue, setUrlValue,getUrlSearch } from "@main/utils"; import { getToken } from '@main/utils/auth' export default { data() { return { loadTexts: "", logoSrc: "" }; }, methods: { handleReload() { window.location.reload(); }, detectZoom (){ var ratio = 0, screen = window.screen, ua = navigator.userAgent.toLowerCase(); if (window.devicePixelRatio !== undefined) { ratio = window.devicePixelRatio; } else if (~ua.indexOf('msie')) { if (screen.deviceXDPI && screen.logicalXDPI) { ratio = screen.deviceXDPI / screen.logicalXDPI; } } else if (window.outerWidth !== undefined && window.innerWidth !== undefined) { ratio = window.outerWidth / window.innerWidth; } if (ratio){ ratio = Math.round(ratio * 100); } return ratio; }, checkZoom(){ let ratio = this.detectZoom(); if(ratio!=100){ // this.$message.error('警告,浏览器没有按正常比例显示会影响部份功能!') } }, }, mounted() { // this.checkZoom(); // window.addEventListener('resize',()=>{ // this.checkZoom(); // }); let me=this; let urlPn=getUrlValue(location.search,"pn"); if(urlPn){ if(!getUrlValue(window.HIVUI_SETTING.loginUrl,"pn")){ window.HIVUI_SETTING.loginUrl+="?pn="+urlPn; } if(!getUrlValue(window.HIVUI_SETTING.mainPageUrl,"pn")){ window.HIVUI_SETTING.mainPageUrl+="?pn="+urlPn; } } //如果token不一致,替换掉然后重新载入 let urlToken=getUrlValue(location.href,"access_token"); let nowToken=getToken(); if(!window._global&&urlToken&&nowToken&&(urlToken!=nowToken)){//正式环境 let newUrl=setUrlValue(decodeURIComponent(location.href),"access_token",nowToken); location=newUrl; location.reload(); } //系统间跳转,将ticket去除 if(!window._global&&getUrlValue(decodeURIComponent(location.href),"ticket")){ let newUrl=setUrlValue(decodeURIComponent(location.href),"ticket",""); location=newUrl.replace("&ticket=","")+"#/"; //location.reload(); } window.Scp = { User: { id: "admin", name: "管理员", deptId: "", deptName: "", positionId: "GLY", postionName: "管理员", bzId: "admin_3", bzName: "管理员岗位3", bzDeptId: ".WLDJT.DGS", bzDeptName: "D公司", bzPositionId: "HQRY", bzPositionName: "后勤人员", orgId: "admin_3", defOrgId: "admin_3" } } //customSysCofig默认值 window.customSysCofig=_.merge({ showMiniLogin:true, },window.customSysCofig); if(!window.localStorage.getItem("locale")){ window.localStorage.setItem("locale",JSON.stringify({ desc:"中文", name:"zh-CN", })); Cookies.set("locale","zh-CN"); } window.__guid = new Date().valueOf(); //window.customSysCofig=_.merge(window.default_customSysCfg,window.customSysCofig||{}); window.customSysCofig&&window.customSysCofig.thirdParty&&window.customSysCofig.thirdParty.forEach((item)=>{//第三方脚本样式资源引用 let _dom; switch(item.type){ case "js": _dom=document.createElement("script"); _dom.type="text/javascript"; _dom.src=item.link; break; case "css": _dom=document.createElement("link"); _dom.rel="stylesheet"; _dom.href=item.link; break; } document.querySelector("head").appendChild(_dom); }); setTimeout(()=>{ window.__sysConfig = _.merge({ events: { onLoad1: function () { } }, projectName: "eaptpl", /*sysProjectMange: { id: __guid++, name: '工程树', iconClass: 'icon-tree', uri: 'amreport/designer/tree/design.do', url: '/amrept-web/amreport/designer/tree/design.do' },*/ sysList: [ ], langList:{ id: __guid++, name: (window.localStorage.getItem("locale")?(JSON.parse(window.localStorage.getItem("locale")).desc):"中文"), type: 'lang', iconClass: 'icon-edit', children: [ { id: __guid++, name:"中文", handler:function(){ window.localStorage.setItem("locale",JSON.stringify({ desc:"中文", name:"zh-CN", })); Cookies.set("locale","zh-CN"); window.location.reload(); }, }, { id: __guid++, name:"English", handler:function(){ window.localStorage.setItem("locale",JSON.stringify({ desc:"English", name:"en", })); Cookies.set("locale","en"); window.location.reload(); }, }, ] }, userInfo:{ id: __guid++, name: '${fusername}', type: 'userInfo', iconClass: 'icon-user', children: [ { id: __guid++, name:me.$t('hivuiMain_app_user')+':${fusername}/${fuserid}', iconClass:'icon-user', }, { id: __guid++, name:me.$t('hivuiMain_app_orgbz')+':${fbzname}/${fbzid}', iconClass:'icon-user', type:"orgBz", }, { id: __guid++, name:me.$t('hivuiMain_app_orgname')+':${forgname}/${forgid}', iconClass:'icon-user', }, { id: __guid++, name:me.$t('hivuiMain_app_rolename')+':${frolename}/${froleid}', iconClass:'icon-user', }, { id: __guid++, name:me.$t('hivuiMain_app_personal_Center'), iconClass:'icon-user', type: "personalCenter" }, /*{ id: __guid++, iconClass:'icon-edit', name:'修改用户信息', type:'modifyUserInfo', },*/ { id: __guid++, iconClass:'icon-edit', name:me.$t('hivuiMain_app_modifyPw'), type:'modifyPw', }, ] }, },window.customSysCofig); this.$store.dispatch("app/getSysConfig").then(res=>{ let cfg = this.$store.state.app.config || {}; let loadText = (cfg.sysLoadLogo && cfg.sysLoadLogo.title) || ""; let logoSrc = (cfg.sysLoadLogo && cfg.sysLoadLogo.src) || ""; this.loadTexts=loadText.split(""); this.logoSrc=logoSrc||LoginPic; }); },0); } }; </script> <style scoped> .app { height: 100%; background: linear-gradient( rgb(255, 255, 255) 0px, rgb(243, 248, 253) 50%, rgb(229, 240, 250) ); } .animated { -webkit-animation-duration: 1s; animation-duration: 1s; -webkit-animation-fill-mode: both; animation-fill-mode: both; } @-webkit-keyframes fadeInUp { 0% { opacity: 0; -webkit-transform: translate3d(0, 100%, 0); transform: translate3d(0, 100%, 0); } to { opacity: 1; -webkit-transform: translateZ(0); transform: translateZ(0); } } @keyframes fadeInUp { 0% { opacity: 0; -webkit-transform: translate3d(0, 100%, 0); transform: translate3d(0, 100%, 0); } to { opacity: 1; -webkit-transform: translateZ(0); transform: translateZ(0); } } .fadeInUp { -webkit-animation-name: fadeInUp; animation-name: fadeInUp; } @-webkit-keyframes fadeInDown { 0% { opacity: 0; -webkit-transform: translate3d(0, -100%, 0); transform: translate3d(0, -100%, 0); } to { opacity: 1; -webkit-transform: translateZ(0); transform: translateZ(0); } } @keyframes fadeInDown { 0% { opacity: 0; -webkit-transform: translate3d(0, -100%, 0); transform: translate3d(0, -100%, 0); } to { opacity: 1; -webkit-transform: translateZ(0); transform: translateZ(0); } } .fadeInDown { -webkit-animation-name: fadeInDown; animation-name: fadeInDown; } .loader { position: absolute; top: 50%; left: 50%; margin-top: -50px; -webkit-transform: translate(-50%, -50%); -moz-transform: translate(-50%, -50%); -mos-transform: translate(-50%, -50%); -o-transform: translate(-50%, -50%); transform: translate(-50%, -50%); text-align: center; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; cursor: default; } .loader .txt { display: inline-block; word-break: normal; white-space: nowrap; margin: auto; text-shadow: 0 1px 0 #ccc, 0 2px 0 #c9c9c9, 0 3px 0 #bbb, 0 4px 0 #b9b9b9, 0 5px 0 #aaa, 0 6px 1px rgba(0, 0, 0, 0.1), 0 0 5px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.1), 0 3px 5px rgba(0, 0, 0, 0.1), 0 5px 10px rgba(0, 0, 0, 0.1), 0 10px 10px rgba(0, 0, 0, 0.1), 0 20px 20px rgba(0, 0, 0, 0.15); } .loader .txt span { display: inline-block; font-size: 68px !important; padding: 0 5px; -webkit-animation: text cubic-bezier(0.75, 0, 0.5, 1) 1.2s infinite; -moz-animation: text cubic-bezier(0.75, 0, 0.5, 1) 1.2s infinite; -moz-animation: text cubic-bezier(0.75, 0, 0.5, 1) 1.2s infinite; -ms-animation: text cubic-bezier(0.75, 0, 0.5, 1) 1.2s infinite; -o-animation: text cubic-bezier(0.75, 0, 0.5, 1) 1.2s infinite; animation: text cubic-bezier(0.75, 0, 0.5, 1) 1.2s infinite; color: #0066cc; } .loader .txt span:nth-child(1) { -webkit-animation-delay: 0ms; -moz-animation-delay: 0ms; -ms-animation-delay: 0ms; -o-animation-delay: 0ms; animation-delay: 0ms; } .loader .txt span:nth-child(2) { -webkit-animation-delay: 100ms; -moz-animation-delay: 100ms; -ms-animation-delay: 100ms; -o-animation-delay: 100ms; animation-delay: 100ms; } .loader .txt span:nth-child(3) { -webkit-animation-delay: 200ms; -moz-animation-delay: 200ms; -ms-animation-delay: 200ms; -o-animation-delay: 200ms; animation-delay: 200ms; } .loader .txt span:nth-child(4) { -webkit-animation-delay: 300ms; -moz-animation-delay: 300ms; -ms-animation-delay: 300ms; -o-animation-delay: 300ms; animation-delay: 300ms; } .loader .txt span:nth-child(5) { -webkit-animation-delay: 400ms; -moz-animation-delay: 400ms; -ms-animation-delay: 400ms; -o-animation-delay: 400ms; animation-delay: 400ms; } .loader .txt span:nth-child(6) { -webkit-animation-delay: 500ms; -moz-animation-delay: 500ms; -ms-animation-delay: 500ms; -o-animation-delay: 500ms; animation-delay: 500ms; } .loader .txt span:nth-child(7) { -webkit-animation-delay: 600ms; -moz-animation-delay: 600ms; -ms-animation-delay: 600ms; -o-animation-delay: 600ms; animation-delay: 600ms; } .loader .txt span:nth-child(8) { -webkit-animation-delay: 700ms; -moz-animation-delay: 700ms; -ms-animation-delay: 700ms; -o-animation-delay: 700ms; animation-delay: 700ms; } .loader .txt span:nth-child(9) { -webkit-animation-delay: 800ms; -moz-animation-delay: 800ms; -ms-animation-delay: 800ms; -o-animation-delay: 800ms; animation-delay: 800ms; } .loader .txt span:nth-child(10) { -webkit-animation-delay: 900ms; -moz-animation-delay: 900ms; -ms-animation-delay: 900ms; -o-animation-delay: 900ms; animation-delay: 900ms; } .loader .txt span:last-child { display: block; padding-top: 15px; font-size: 16px !important; text-shadow: none; color: #0272bd; text-shadow: none; animation: none; -webkit-animation: none; } @-webkit-keyframes text { 0% { color: #0066cc; } 40% { color: #fff; } 70%, 100% { color: #0066cc; } } @-moz-keyframes text { 0% { color: #0066cc; } 40% { color: #fff; } 70%, 100% { color: #0066cc; } } @-mos-keyframes text { 0% { color: #0066cc; } 40% { color: #fff; } 70%, 100% { color: #0066cc; } } @-o-keyframes text { 0% { color: #0066cc; } 40% { color: #fff; } 70%, 100% { color: #0066cc; } } @keyframes text { 0% { color: #0066cc; } 40% { color: #fff; } 70%, 100% { color: #0066cc; } } </style>
Ignore Space
Show notes
View
vite-plugin/vite-plugin-func.js
var querystring = require('querystring'); var url = require('url'); const fs = require('fs') var https = require('https'); var request = require('request'); var ejs = require('ejs'); function myPlugin(rawOptions) { let projectName = process.env.VITE_APP_PN.split("/")[0]; let userName = process.env.VITE_APP_PN.split("/")[1]; var previewPath = `${projectName}/setting/studio/preview.json` var setting try { let settingContent = fs.readFileSync(previewPath, { encoding: 'utf8' }); setting = JSON.parse(settingContent) } catch (e) { console.log("preview数据有错!") } var VITE_APP_BASE_API, VITE_APP_SERVER; if (setting) { VITE_APP_BASE_API = (setting.server || {}).VITE_APP_BASE_API || process.env.VITE_APP_BASE_API; VITE_APP_SERVER = (setting.server || {}).VITE_APP_SERVER || process.env.VITE_APP_SERVER; } else { VITE_APP_BASE_API = process.env.VITE_APP_BASE_API; VITE_APP_SERVER = process.env.VITE_APP_SERVER; } const options = { isProduction: process.env.NODE_ENV === 'production', ...rawOptions, VITE_APP_BASE_API: VITE_APP_BASE_API, VITE_APP_SERVER: VITE_APP_SERVER, root: process.cwd(), }; var routerOption = { url: `${VITE_APP_BASE_API}/map.html?pn=${process.env.VITE_APP_PN}`, method: "GET", json: true, headers: { "Content-Type": "application/json;charset=UTF-8" } } const routerMap = {}; request(routerOption, function (error, response, body) { if (body) { for (var i = 0; i < body.length; i++) { let routerPath = body[i].value; routerPath = routerPath.substr(routerPath.indexOf("/") + 1) + ".html" routerMap["/" + body[i].key] = routerPath; } } }) const TokenKey = 'EAP-Token'; let postData; let config; return { name: 'vite-plugin-func', // 必须的,将会显示在 warning 和 error 中 configResolved(resolvedConfig) { // 存储最终解析的配置 config = resolvedConfig }, configureServer(server) { server.middlewares.use((req, res, next) => { var Cookies = {}; if (req.headers.cookie != null) { req.headers.cookie.split(';').forEach(l => { var parts = l.split('='); Cookies[parts[0].trim()] = (parts[1] || '').trim(); }); } var param = req._parsedUrl.query; var result = {}; if (param) { let values = param.split("&"); for (let i = 0; i < values.length; i++) { const element = values[i]; let _val = element.split("="); result[_val[0]] = _val[1]; } } function isFlow(type) { return type.endsWith(".flow") || type.endsWith(".flowc"); } // 接口 function isInfc(type) { return type.endsWith(".infc") } function isFunc(type) { return type.endsWith(".func") } function isHtml(type) { return type.endsWith(".html") } function isStudio(type) { return type.endsWith("/studio.html") } // 渲染页面 function renderHtml(pcform, isGuest, body) { let content; try { content = fs.readFileSync(pcform, { encoding: 'utf8' }) } catch (e) { res.writeHead(404, { "Content-Type": "application/json;charset=UTF-8" }); res.end("pcform:" + pcform + "文件异常!"); return; } const statusCode = 200; if (!body) throw new Error(`No body text found for the ${statusCode} status code`); try { var html = ejs.render(content, options); } catch (e) { res.end(e.message); return; } let postDataStr = JSON.stringify(postData || {}); let varName = options.varName || 'viteRequestData'; let varGlobal = JSON.stringify(options.global || {}); let funcName = new Date().valueOf(); let queryScript = ` function _viteGetQuery${funcName}() { var url = window.location.search; var theRequest = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for(var i = 0; i < strs.length; i ++) { theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]); } } return theRequest; }` let titleStr = html.match(/<head(.*?)>/g)[0] || ""; var pathname = req._parsedUrl.pathname; if (!isStudio(pathname)) { html = html.replace( /<head(.*?)>/g, `${titleStr}<script>${queryScript};window.isGuest=${isGuest}; window.${varName} = Object.assign(_viteGetQuery${funcName}(),${postDataStr}); window._global=${varGlobal}</script> ` ) let titleEnd = html.match(/<\/head(.*?)>/g)[0] || ""; let lang = result["locale"] || Cookies["locale"] || "zh-CN"; lang = lang.replace("_", "-"); var sam = ""; var samDef = ""; if (pcform.indexOf("hivuiSam/index.html") != -1) {//统计分析 samDef = `<script src="/${projectName}/hivuiSam/lang/zh-CN.js"></script>` sam = `<script src="${VITE_APP_BASE_API}/lang/ref?pn=${process.env.VITE_APP_PN}&vmId=tpl&filePath=${userName}/${projectName}/hivuiSam/lang/def.language&locale=${lang}"></script>` }; var platfPlugin = ''; var platfPluginDef = ''; if (pcform.indexOf("hivuiBirt/index.html") != -1) {//平台插件 platfPluginDef = `<script src="/${projectName}/hivuiBirt/lang/zh-CN.js"></script>` platfPlugin = `<script src="${VITE_APP_BASE_API}/lang/ref?pn=${process.env.VITE_APP_PN}&vmId=tpl&filePath=${userName}/${projectName}/hivuiBirt/lang/def.language&locale=${lang}"></script>` }; let funcDefLangMap = { 'hivuiLogin/index.html': `/${projectName}/hivuiLogin/lang/zh-CN.js`, 'hivuiMain/index.html': `/${projectName}/hivuiMain/lang/zh-CN.js`, } let funcLangMap = { 'hivuiLogin/index.html': `${VITE_APP_BASE_API}/lang/ref?pn=${process.env.VITE_APP_PN}&vmId=tpl&filePath=${userName}/${projectName}/hivuiLogin/lang/def.language&locale=${lang}`, 'hivuiMain/index.html': `${VITE_APP_BASE_API}/lang/ref?pn=${process.env.VITE_APP_PN}&vmId=tpl&filePath=${userName}/${projectName}/hivuiMain/lang/def.language&locale=${lang}`, 'platf/permission': `${VITE_APP_BASE_API}/lang/ref?pn=${process.env.VITE_APP_PN}&vmId=scheme&bizPath=${projectName}.pro/setting.project_setrootdir/global.dir/rolescheme.roletp&locale=${lang}` } let curFuncLangScript = '' for (let k in funcDefLangMap) { if (pathname.indexOf(k) > -1 || (routerMap[pathname] && routerMap[pathname].indexOf(k) > -1)) { curFuncLangScript += `<script src="${funcDefLangMap[k]}"></script>` break; } } for (let k in funcLangMap) { if (pathname.indexOf(k) > -1 || (routerMap[pathname] && routerMap[pathname].indexOf(k) > -1)) { curFuncLangScript += `<script src="${funcLangMap[k]}"></script>` break; } } var viteData = html.match(/<vite>([\s\S]*)<\/vite>/); var viteTpl = "", viteprojectTpl = ""; let token = Cookies[TokenKey]; if (viteData) { //流引入多语言 var viteDataJson = JSON.parse(html.match(/<vite>([\s\S]*)<\/vite>/)[1]); viteprojectTpl = `<script src="${VITE_APP_BASE_API}/lang/static?pn=${process.env.VITE_APP_PN}&vmId=${viteDataJson.project_vmid}&locale=${lang}"></script>` if (viteDataJson.module_vmid && viteDataJson.bizpath) viteTpl = `<script src="${VITE_APP_BASE_API}/lang/ref?pn=${process.env.VITE_APP_PN}&vmId=${viteDataJson.module_vmid}&bizPath=${viteDataJson.bizpath}&locale=${lang}"></script>` } html = html.replace( /<\/head(.*?)>/g, `<script src="/assets_platform/vue-i18n/vue-i18n.js"></script> <script src="/${projectName}/lang/element-ui/${lang}.js"></script> <script src="${VITE_APP_BASE_API}/lang/ref?pn=${process.env.VITE_APP_PN}&vmId=hiui&filePath=${userName}/${projectName}/lang/hi-ui/def.language&locale=${lang}"></script> ${curFuncLangScript} ${viteprojectTpl} ${viteTpl} ${samDef} ${platfPluginDef} ${sam} ${platfPlugin} <script> try{ window.global={ pName:"${projectName}", pUser:"${userName}", pn:"${projectName}/${userName}" } // 统一输出语言包 zh-CN 名 if(!window.GLOBAL_LANG_TPL){ console.log('不影响运行,提示:[[${req.url},当前模板语言包不存在]]') } if(!window.GLOBAL_LANG_HIUI){ console.log('不影响运行,提示:[[${req.url},hiui语言包不存在]]') } window.lang = window.lang ||{}; window.lang.keys = Object.assign({},window.GLOBAL_LANG_TPL||{},window.GLOBAL_LANG_HIUI||{},window.GLOBAL_LANG_PROJECT||{},window.GLOBAL_LANG_MODULE||{},window.GLOBAL_LANG_SCHEME||{}); Vue.prototype._i18n = new VueI18n({ locale: 'localelang', messages: { 'localelang':window.lang.keys, } }); (function(lang){ lang = lang.split('-'); lang= lang[0]+((lang[1]||'').charAt(0).toUpperCase() + (lang[1]||'').slice(1)); console.log(lang) ELEMENT.locale(ELEMENT.lang[lang]) })('${lang}'); }catch(e){ console.log('语言包加载出错!') } </script> <script src="/assets_platform/customSysCfg/index.js"></script> <script src="/${projectName}/setting/desktop/base.js" type="text/javascript"></script> <script src="/${projectName}/setting/desktop/development.js" type="text/javascript"></script> ${titleEnd}`) } res.writeHead(statusCode, { "serverInfo": `${VITE_APP_BASE_API},${VITE_APP_SERVER}`, // 'Content-Length': html.length, 'Content-Type': 'html' }); res.write(html) res.end(); } var serverPath = VITE_APP_BASE_API + VITE_APP_SERVER; if (req.url.indexOf("/development.js") != -1) { if (req.headers.referer) { if (req.headers.referer.startsWith("https")) { options["VITE_APP_BASE_API"] = options["VITE_APP_BASE_API"].replace("http://", "https://"); } else { options["VITE_APP_BASE_API"] = options["VITE_APP_BASE_API"].replace("https://", "http://"); } } let content; try { content = fs.readFileSync(req.url.substr(1), { encoding: 'utf8' }) } catch (e) { res.writeHead(404, { "Content-Type": "application/json;charset=UTF-8" }); res.end("获取", req.url + "文件异常!"); return; } try { var html = ejs.render(content, options); } catch (e) { res.end(e.message); return; } res.end(html); return; } let pathname = req._parsedUrl.pathname; //console.log(new Date(), 'req.url:', req.url) if (isFlow(pathname) || isFunc(pathname) || isInfc(pathname)) { // let url = req.url; let post = ''; postData = ''; let path; let fmodelpath = pathname; // url.split("?")[0]; var post_data = {}; // var param = req.url.split("?")[1]; if (isFlow(fmodelpath)) { var fversion = ""; var ftaskguid = ""; var fbzid = ""; if (param) { fversion = result["_version"] || result["version"]; ftaskguid = result["_ftaskguid"] || result["ftaskguid"]; fbzid = result["fbzid"]; } post_data = { fmodelpath: fmodelpath, fversion, ftaskguid, fbzid } path = serverPath + "/flow/open?origin=pre&skip=false&pn="; } else if (isInfc(fmodelpath)) { path = serverPath + fmodelpath + "?pn="; } else { var viewItemId = "" if (param) { viewItemId = result["__viewItemId"] || result["viewItemId"] || ""; } path = serverPath + fmodelpath + "?origin=pre&skip=false&viewItemId=" + viewItemId + "&pn=" } // let pn = url.split("/")[1]; function handleFunc() { let token = Cookies[TokenKey]; let requestUrl = path + process.env.VITE_APP_PN; if (param) { requestUrl = requestUrl + "&" + param; } console.log("----requestUrl:", requestUrl, "token:", token); Object.assign(post_data, postData); let lang = result["locale"] || Cookies["locale"] || "zh-CN"; lang = lang.replace("_", "-"); var requestOption = { url: requestUrl, method: "POST", json: true, body: post_data, headers: { "token": token, "Cookie": `locale=${lang}`, "Authorization": "Bearer " + token, "Content-Type": "application/json;charset=UTF-8" } } if (isFlow(pathname)) { requestOption["body"] = post_data; } else if (isFunc(pathname)) { //页面流用表单提交 requestOption["form"] = post_data; } request(requestOption, function (error, response, body) { //console.log(error, response, body); if (!error && response.statusCode == 200) { let pcform; let designPath; let isGuest = false; if (body) { if (isFlow(fmodelpath) && body.outParameter) { pcform = body.outParameter.task.bizpcform; if (!result["locale"] && body.outParameter.locale) { result["locale"] = body.outParameter.locale; } } else if (isFunc(fmodelpath) || isInfc(fmodelpath)) { if (body && body.logicflow || isInfc(fmodelpath)) { //逻辑流 let statusCode = body.status || response.statusCode; res.writeHead(statusCode, { "Content-Type": "application/json;charset=UTF-8" }); res.end(JSON.stringify(body)); return; } else if (body.dataPack) { pcform = body.dataPack.path; designPath = body.dataPack.designPath; isGuest = body.dataPack.isGuest; if (!result["locale"] && body.dataPack.locale) { result["locale"] = body.dataPack.locale; } } } } if (!pcform) { res.writeHead(500, { "serverInfo": `${VITE_APP_BASE_API},${VITE_APP_SERVER}`, "Content-Type": "application/json;charset=UTF-8" }); res.end(JSON.stringify(body)); return; } if (designPath && (designPath.endsWith(".vm") || designPath.endsWith(".dvm"))) { res.writeHead(200, { 'Content-Type': 'html' }); let projectName = process.env.VITE_APP_PN.split("/")[0]; var pn = `pn=${process.env.VITE_APP_PN}` if (req.url.indexOf("?") == -1) { pn = "?" + pn; } else { pn = "&" + pn; } let accessToken = "" if (token) { accessToken = `&access_token=${token}`; } let html = ` <script src="/assets_platform/eap/eap.umd.min.js"></script> <script> window._global ={ env :"dev" } </script> <script src="/${projectName}/setting/desktop/development.js" type="text/javascript"></script> <script> window.location.href="${serverPath}${req.url}${pn}${accessToken}"; </script> ` res.end(html); return; } // var fullPath = "eaptpl/12112/mokuai/shitumulu/biaodan/dtv/1.0.0/desktop/index.html"; renderHtml(pcform, isGuest, body); } else { if (response && response.statusCode == 401) { res.writeHead(200, { "serverInfo": `${VITE_APP_BASE_API},${VITE_APP_SERVER}`, 'Content-Type': 'html' }); let projectName = process.env.VITE_APP_PN.split("/")[0]; let html = ` <script src="/assets_platform/eap/eap.umd.min.js"></script> <script> window._global ={ env :"dev" } </script> <script> if(top.window.SysPage&&top.window.SysPage.openMiniLogin){//小窗口 top.window.SysPage.openMiniLogin(true); }else{ window.location.href=window.HIVUI_SETTING.loginUrl; } </script> ` res.end(html); } else { res.writeHead(500, { "serverInfo": `${VITE_APP_BASE_API},${VITE_APP_SERVER}`, "Content-Type": "application/json;charset=UTF-8" }); res.end(JSON.stringify(body)); } //res.end(requestUrl + ":" + JSON.stringify(error) + JSON.stringify(body)); } }, (msg) => { res.writeHead(404, { "Content-Type": "application/json;charset=UTF-8" }); res.end(JSON.stringify(msg)); // console.log(msg) }); } req.on('data', (chunk) => { post += chunk; postData = querystring.parse(post); }); req.on('end', (chunk) => { handleFunc() }); return; } else if (routerMap[pathname]) { let pcform = routerMap[pathname]; renderHtml(pcform, false, {}) } // else if (pathname.endsWith("studio.html")) { //动态流程 routerMap[pathname]已处理 // let projectName = process.env.VITE_APP_PN.split("/")[0]; // let pcform = `${projectName}/hivuiStudio/index.html` // renderHtml(pcform, false, {}) // } else { if (isHtml(pathname)) { renderHtml(pathname.substr(1), false, {}) } else { var newPath = `/render/${userName}`; if (pathname.indexOf(newPath) != -1) { req.url = req.url.replace(newPath, ""); } next(); } } }) }, } } export default myPlugin;
var querystring = require('querystring'); var url = require('url'); const fs = require('fs') var https = require('https'); var request = require('request'); var ejs = require('ejs'); function myPlugin(rawOptions) { let projectName = process.env.VITE_APP_PN.split("/")[0]; let userName = process.env.VITE_APP_PN.split("/")[1]; var previewPath = `${projectName}/setting/studio/preview.json` var setting try { let settingContent = fs.readFileSync(previewPath, { encoding: 'utf8' }); setting = JSON.parse(settingContent) } catch (e) { console.log("preview数据有错!") } var VITE_APP_BASE_API, VITE_APP_SERVER; if (setting) { VITE_APP_BASE_API = (setting.server || {}).VITE_APP_BASE_API || process.env.VITE_APP_BASE_API; VITE_APP_SERVER = (setting.server || {}).VITE_APP_SERVER || process.env.VITE_APP_SERVER; } else { VITE_APP_BASE_API = process.env.VITE_APP_BASE_API; VITE_APP_SERVER = process.env.VITE_APP_SERVER; } const options = { isProduction: process.env.NODE_ENV === 'production', ...rawOptions, VITE_APP_BASE_API: VITE_APP_BASE_API, VITE_APP_SERVER: VITE_APP_SERVER, root: process.cwd(), }; var routerOption = { url: `${VITE_APP_BASE_API}/map.html?pn=${process.env.VITE_APP_PN}`, method: "GET", json: true, headers: { "Content-Type": "application/json;charset=UTF-8" } } const routerMap = {}; request(routerOption, function (error, response, body) { if (body) { for (var i = 0; i < body.length; i++) { let routerPath = body[i].value; routerPath = routerPath.substr(routerPath.indexOf("/") + 1) + ".html" routerMap["/" + body[i].key] = routerPath; } } }) const TokenKey = 'EAP-Token'; let postData; let config; return { name: 'vite-plugin-func', // 必须的,将会显示在 warning 和 error 中 configResolved(resolvedConfig) { // 存储最终解析的配置 config = resolvedConfig }, configureServer(server) { server.middlewares.use((req, res, next) => { var Cookies = {}; if (req.headers.cookie != null) { req.headers.cookie.split(';').forEach(l => { var parts = l.split('='); Cookies[parts[0].trim()] = (parts[1] || '').trim(); }); } var param = req._parsedUrl.query; var result = {}; if (param) { let values = param.split("&"); for (let i = 0; i < values.length; i++) { const element = values[i]; let _val = element.split("="); result[_val[0]] = _val[1]; } } function isFlow(type) { return type.endsWith(".flow") || type.endsWith(".flowc"); } // 接口 function isInfc(type) { return type.endsWith(".infc") } function isFunc(type) { return type.endsWith(".func") } function isHtml(type) { return type.endsWith(".html") } function isStudio(type) { return type.endsWith("/studio.html") } // 渲染页面 function renderHtml(pcform, isGuest, body) { let content; try { content = fs.readFileSync(pcform, { encoding: 'utf8' }) } catch (e) { res.writeHead(404, { "Content-Type": "application/json;charset=UTF-8" }); res.end("pcform:" + pcform + "文件异常!"); return; } const statusCode = 200; if (!body) throw new Error(`No body text found for the ${statusCode} status code`); try { var html = ejs.render(content, options); } catch (e) { res.end(e.message); return; } let postDataStr = JSON.stringify(postData || {}); let varName = options.varName || 'viteRequestData'; let varGlobal = JSON.stringify(options.global || {}); let funcName = new Date().valueOf(); let queryScript = ` function _viteGetQuery${funcName}() { var url = window.location.search; var theRequest = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for(var i = 0; i < strs.length; i ++) { theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]); } } return theRequest; }` let titleStr = html.match(/<head(.*?)>/g)[0] || ""; var pathname = req._parsedUrl.pathname; if (!isStudio(pathname)) { html = html.replace( /<head(.*?)>/g, `${titleStr}<script>${queryScript};window.isGuest=${isGuest}; window.${varName} = Object.assign(_viteGetQuery${funcName}(),${postDataStr}); window._global=${varGlobal}</script> ` ) let titleEnd = html.match(/<\/head(.*?)>/g)[0] || ""; let lang = result["locale"] || Cookies["locale"] || "zh-CN"; lang = lang.replace("_", "-"); var sam = ""; var samDef = ""; if (pcform.indexOf("hivuiSam/index.html") != -1) {//统计分析 samDef = `<script src="/${projectName}/hivuiBirt/lang/zh-CN.js"></script>` sam = `<script src="${VITE_APP_BASE_API}/lang/ref?pn=${process.env.VITE_APP_PN}&vmId=tpl&filePath=${userName}/${projectName}/hivuiSam/lang/def.language&locale=${lang}"></script>` }; var platfPlugin = ''; var platfPluginDef = ''; if (pcform.indexOf("hivuiBirt/index.html") != -1) {//平台插件 platfPluginDef = `<script src="/${projectName}/hivuiSam/lang/zh-CN.js"></script>` platfPlugin = `<script src="${VITE_APP_BASE_API}/lang/ref?pn=${process.env.VITE_APP_PN}&vmId=tpl&filePath=${userName}/${projectName}/hivuiBirt/lang/def.language&locale=${lang}"></script>` }; let funcDefLangMap = { 'hivuiLogin/index.html': `/${projectName}/hivuiLogin/lang/zh-CN.js`, 'hivuiMain/index.html': `/${projectName}/hivuiMain/lang/zh-CN.js`, } let funcLangMap = { 'hivuiLogin/index.html': `${VITE_APP_BASE_API}/lang/ref?pn=${process.env.VITE_APP_PN}&vmId=tpl&filePath=${userName}/${projectName}/hivuiLogin/lang/def.language&locale=${lang}`, 'hivuiMain/index.html': `${VITE_APP_BASE_API}/lang/ref?pn=${process.env.VITE_APP_PN}&vmId=tpl&filePath=${userName}/${projectName}/hivuiMain/lang/def.language&locale=${lang}`, 'platf/permission': `${VITE_APP_BASE_API}/lang/ref?pn=${process.env.VITE_APP_PN}&vmId=scheme&bizPath=${projectName}.pro/setting.project_setrootdir/global.dir/rolescheme.roletp&locale=${lang}` } let curFuncLangScript = '' for (let k in funcDefLangMap) { if (pathname.indexOf(k) > -1 || (routerMap[pathname] && routerMap[pathname].indexOf(k) > -1)) { curFuncLangScript += `<script src="${funcDefLangMap[k]}"></script>` break; } } for (let k in funcLangMap) { if (pathname.indexOf(k) > -1 || (routerMap[pathname] && routerMap[pathname].indexOf(k) > -1)) { curFuncLangScript += `<script src="${funcLangMap[k]}"></script>` break; } } var viteData = html.match(/<vite>([\s\S]*)<\/vite>/); var viteTpl = "", viteprojectTpl = ""; let token = Cookies[TokenKey]; if (viteData) { //流引入多语言 var viteDataJson = JSON.parse(html.match(/<vite>([\s\S]*)<\/vite>/)[1]); viteprojectTpl = `<script src="${VITE_APP_BASE_API}/lang/static?pn=${process.env.VITE_APP_PN}&vmId=${viteDataJson.project_vmid}&locale=${lang}"></script>` if (viteDataJson.module_vmid && viteDataJson.bizpath) viteTpl = `<script src="${VITE_APP_BASE_API}/lang/ref?pn=${process.env.VITE_APP_PN}&vmId=${viteDataJson.module_vmid}&bizPath=${viteDataJson.bizpath}&locale=${lang}"></script>` } html = html.replace( /<\/head(.*?)>/g, `<script src="/assets_platform/vue-i18n/vue-i18n.js"></script> <script src="/${projectName}/lang/element-ui/${lang}.js"></script> <script src="${VITE_APP_BASE_API}/lang/ref?pn=${process.env.VITE_APP_PN}&vmId=hiui&filePath=${userName}/${projectName}/lang/hi-ui/def.language&locale=${lang}"></script> ${curFuncLangScript} ${viteprojectTpl} ${viteTpl} ${samDef} ${platfPluginDef} ${sam} ${platfPlugin} <script> try{ window.global={ pName:"${projectName}", pUser:"${userName}", pn:"${projectName}/${userName}" } // 统一输出语言包 zh-CN 名 if(!window.GLOBAL_LANG_TPL){ console.log('不影响运行,提示:[[${req.url},当前模板语言包不存在]]') } if(!window.GLOBAL_LANG_HIUI){ console.log('不影响运行,提示:[[${req.url},hiui语言包不存在]]') } window.lang = window.lang ||{}; window.lang.keys = Object.assign({},window.GLOBAL_LANG_TPL||{},window.GLOBAL_LANG_HIUI||{},window.GLOBAL_LANG_PROJECT||{},window.GLOBAL_LANG_MODULE||{},window.GLOBAL_LANG_SCHEME||{}); Vue.prototype._i18n = new VueI18n({ locale: 'localelang', messages: { 'localelang':window.lang.keys, } }); (function(lang){ lang = lang.split('-'); lang= lang[0]+((lang[1]||'').charAt(0).toUpperCase() + (lang[1]||'').slice(1)); console.log(lang) ELEMENT.locale(ELEMENT.lang[lang]) })('${lang}'); }catch(e){ console.log('语言包加载出错!') } </script> <script src="/assets_platform/customSysCfg/index.js"></script> <script src="/${projectName}/setting/desktop/base.js" type="text/javascript"></script> <script src="/${projectName}/setting/desktop/development.js" type="text/javascript"></script> ${titleEnd}`) } res.writeHead(statusCode, { "serverInfo": `${VITE_APP_BASE_API},${VITE_APP_SERVER}`, // 'Content-Length': html.length, 'Content-Type': 'html' }); res.write(html) res.end(); } var serverPath = VITE_APP_BASE_API + VITE_APP_SERVER; if (req.url.indexOf("/development.js") != -1) { if (req.headers.referer) { if (req.headers.referer.startsWith("https")) { options["VITE_APP_BASE_API"] = options["VITE_APP_BASE_API"].replace("http://", "https://"); } else { options["VITE_APP_BASE_API"] = options["VITE_APP_BASE_API"].replace("https://", "http://"); } } let content; try { content = fs.readFileSync(req.url.substr(1), { encoding: 'utf8' }) } catch (e) { res.writeHead(404, { "Content-Type": "application/json;charset=UTF-8" }); res.end("获取", req.url + "文件异常!"); return; } try { var html = ejs.render(content, options); } catch (e) { res.end(e.message); return; } res.end(html); return; } let pathname = req._parsedUrl.pathname; //console.log(new Date(), 'req.url:', req.url) if (isFlow(pathname) || isFunc(pathname) || isInfc(pathname)) { // let url = req.url; let post = ''; postData = ''; let path; let fmodelpath = pathname; // url.split("?")[0]; var post_data = {}; // var param = req.url.split("?")[1]; if (isFlow(fmodelpath)) { var fversion = ""; var ftaskguid = ""; var fbzid = ""; if (param) { fversion = result["_version"] || result["version"]; ftaskguid = result["_ftaskguid"] || result["ftaskguid"]; fbzid = result["fbzid"]; } post_data = { fmodelpath: fmodelpath, fversion, ftaskguid, fbzid } path = serverPath + "/flow/open?origin=pre&skip=false&pn="; } else if (isInfc(fmodelpath)) { path = serverPath + fmodelpath + "?pn="; } else { var viewItemId = "" if (param) { viewItemId = result["__viewItemId"] || result["viewItemId"] || ""; } path = serverPath + fmodelpath + "?origin=pre&skip=false&viewItemId=" + viewItemId + "&pn=" } // let pn = url.split("/")[1]; function handleFunc() { let token = Cookies[TokenKey]; let requestUrl = path + process.env.VITE_APP_PN; if (param) { requestUrl = requestUrl + "&" + param; } console.log("----requestUrl:", requestUrl, "token:", token); Object.assign(post_data, postData); let lang = result["locale"] || Cookies["locale"] || "zh-CN"; lang = lang.replace("_", "-"); var requestOption = { url: requestUrl, method: "POST", json: true, body: post_data, headers: { "token": token, "Cookie": `locale=${lang}`, "Authorization": "Bearer " + token, "Content-Type": "application/json;charset=UTF-8" } } if (isFlow(pathname)) { requestOption["body"] = post_data; } else if (isFunc(pathname)) { //页面流用表单提交 requestOption["form"] = post_data; } request(requestOption, function (error, response, body) { //console.log(error, response, body); if (!error && response.statusCode == 200) { let pcform; let designPath; let isGuest = false; if (body) { if (isFlow(fmodelpath) && body.outParameter) { pcform = body.outParameter.task.bizpcform; if (!result["locale"] && body.outParameter.locale) { result["locale"] = body.outParameter.locale; } } else if (isFunc(fmodelpath) || isInfc(fmodelpath)) { if (body && body.logicflow || isInfc(fmodelpath)) { //逻辑流 let statusCode = body.status || response.statusCode; res.writeHead(statusCode, { "Content-Type": "application/json;charset=UTF-8" }); res.end(JSON.stringify(body)); return; } else if (body.dataPack) { pcform = body.dataPack.path; designPath = body.dataPack.designPath; isGuest = body.dataPack.isGuest; if (!result["locale"] && body.dataPack.locale) { result["locale"] = body.dataPack.locale; } } } } if (!pcform) { res.writeHead(500, { "serverInfo": `${VITE_APP_BASE_API},${VITE_APP_SERVER}`, "Content-Type": "application/json;charset=UTF-8" }); res.end(JSON.stringify(body)); return; } if (designPath && (designPath.endsWith(".vm") || designPath.endsWith(".dvm"))) { res.writeHead(200, { 'Content-Type': 'html' }); let projectName = process.env.VITE_APP_PN.split("/")[0]; var pn = `pn=${process.env.VITE_APP_PN}` if (req.url.indexOf("?") == -1) { pn = "?" + pn; } else { pn = "&" + pn; } let accessToken = "" if (token) { accessToken = `&access_token=${token}`; } let html = ` <script src="/assets_platform/eap/eap.umd.min.js"></script> <script> window._global ={ env :"dev" } </script> <script src="/${projectName}/setting/desktop/development.js" type="text/javascript"></script> <script> window.location.href="${serverPath}${req.url}${pn}${accessToken}"; </script> ` res.end(html); return; } // var fullPath = "eaptpl/12112/mokuai/shitumulu/biaodan/dtv/1.0.0/desktop/index.html"; renderHtml(pcform, isGuest, body); } else { if (response && response.statusCode == 401) { res.writeHead(200, { "serverInfo": `${VITE_APP_BASE_API},${VITE_APP_SERVER}`, 'Content-Type': 'html' }); let projectName = process.env.VITE_APP_PN.split("/")[0]; let html = ` <script src="/assets_platform/eap/eap.umd.min.js"></script> <script> window._global ={ env :"dev" } </script> <script> if(top.window.SysPage&&top.window.SysPage.openMiniLogin){//小窗口 top.window.SysPage.openMiniLogin(true); }else{ window.location.href=window.HIVUI_SETTING.loginUrl; } </script> ` res.end(html); } else { res.writeHead(500, { "serverInfo": `${VITE_APP_BASE_API},${VITE_APP_SERVER}`, "Content-Type": "application/json;charset=UTF-8" }); res.end(JSON.stringify(body)); } //res.end(requestUrl + ":" + JSON.stringify(error) + JSON.stringify(body)); } }, (msg) => { res.writeHead(404, { "Content-Type": "application/json;charset=UTF-8" }); res.end(JSON.stringify(msg)); // console.log(msg) }); } req.on('data', (chunk) => { post += chunk; postData = querystring.parse(post); }); req.on('end', (chunk) => { handleFunc() }); return; } else if (routerMap[pathname]) { let pcform = routerMap[pathname]; renderHtml(pcform, false, {}) } // else if (pathname.endsWith("studio.html")) { //动态流程 routerMap[pathname]已处理 // let projectName = process.env.VITE_APP_PN.split("/")[0]; // let pcform = `${projectName}/hivuiStudio/index.html` // renderHtml(pcform, false, {}) // } else { if (isHtml(pathname)) { renderHtml(pathname.substr(1), false, {}) } else { var newPath = `/render/${userName}`; if (pathname.indexOf(newPath) != -1) { req.url = req.url.replace(newPath, ""); } next(); } } }) }, } } export default myPlugin;
Show line notes below