app.jsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * @Description:
  3. * @Version: 1.668
  4. * @Autor: 地虎降天龙
  5. * @Date: 2025-04-02 18:59:21
  6. * @LastEditors: 地虎降天龙
  7. * @LastEditTime: 2025-09-23 11:34:44
  8. */
  9. import { defineRuntimeConfig, useModel } from '@fesjs/fes'
  10. import { reactive } from 'vue'
  11. import { FMenu } from '@fesjs/fes-design'
  12. import Tres from '@tresjs/core'
  13. import chalk from 'chalk'
  14. import 'uno.css'
  15. import 'animate.css/animate.min.css'
  16. // 注册图标 iconify goview
  17. import { addCollection } from 'iconify-icon'
  18. import uimIcons from '@iconify/json/json/uim.json'
  19. import lineMdIcons from '@iconify/json/json/line-md.json'
  20. import wiIcons from '@iconify/json/json/wi.json'
  21. import { useQiankunTvtStore } from '@/plugins/qiankunTvt/stores/index'
  22. import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper'
  23. import UserCenter from '@/components/forPreview/userCenter.vue'
  24. import PageLoading from '@/components/pageLoading.vue'
  25. import { useForPreviewStore } from '@/stores/forPreview'
  26. addCollection(uimIcons)
  27. addCollection(lineMdIcons)
  28. addCollection(wiIcons)
  29. let qiankunTvtStore = null
  30. export default defineRuntimeConfig({
  31. beforeRender: {
  32. loading: <PageLoading />,
  33. action () {
  34. if (qiankunWindow.__POWERED_BY_QIANKUN__) {
  35. qiankunTvtStore = useQiankunTvtStore()
  36. const purl = qiankunWindow.__INJECTED_PUBLIC_PATH_BY_QIANKUN__
  37. globalThis.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ = purl
  38. window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ = purl
  39. console.log('qiankunWindow.__INJECTED_PUBLIC_PATH_BY_QIANKUN__', qiankunWindow.__INJECTED_PUBLIC_PATH_BY_QIANKUN__)
  40. // window.__webpack_public_path__ = purl
  41. // qiankunWindow.__webpack_public_path__ = purl
  42. // Object.defineProperty(import.meta, 'url', { get: () => purl })
  43. }
  44. const { signin, getMenu } = useForPreviewStore()
  45. // const { signin, getMenu } = useModel('useAuthModel')
  46. signin()
  47. if ((process.env.FES_APP_PLUGINS === 'true' && process.env.NODE_ENV === 'development') || process.env.FES_APP_ONLINE_API) {
  48. getMenu()
  49. }
  50. },
  51. },
  52. })
  53. export function layout (layoutConfig) {
  54. return {
  55. renderCustom: () => <UserCenter />,
  56. ...layoutConfig,
  57. menus: () => {
  58. window.layoutConfig = layoutConfig
  59. return layoutConfig.menus
  60. }
  61. }
  62. }
  63. export function onAppCreated ({ app }) {
  64. app.use(FMenu)
  65. app.use(Tres)
  66. window.$vue = app
  67. // if (process.env.FES_APP_PLUGINS === 'true') {
  68. console.log(chalk.hex('#1c86e5')(`
  69. ░▒▓████████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓████████▓▒░ ░▒▓█▓▒░ ░▒▓███████▓▒░
  70. ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░
  71. ░▒▓█▓▒░ ░▒▓█▓▒▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░
  72. ░▒▓█▓▒░ ░▒▓█▓▒▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓██████▓▒░
  73. ░▒▓█▓▒░ ░▒▓█▓▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
  74. ░▒▓█▓▒░ ░▒▓█▓▓█▓▒░ ░▒▓█▓▒░ ░▒▓██▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
  75. ░▒▓█▓▒░ ░▒▓██▓▒░ ░▒▓█▓▒░ ░▒▓██▓▒░ ░▒▓██████▓▒░ ░▒▓███████▓▒░
  76. `))
  77. console.log(chalk.hex('#5384ff').bold('· 二次开发如用于商业性质或开源竞品请不要删除和修改 TvT.js 源码头部的版权与作者声明及出处。'))
  78. console.log(chalk.hex('#5384ff').bold('· 本项目遵循 Apache2 开源协议发布,并提供永久免费使用以及商用,但是不允许二次开源出来并进行收费。'))
  79. console.log(chalk.hex('#1c86e5').bold('版权所有 Copyright © 2022-2025 by 🧊icegl (https://www.icegl.cn)'))
  80. // }
  81. }
  82. const findStringBetween = (str) => {
  83. const regex = /plugins\/([^/]+)\/pages\//
  84. const match = str.match(regex)
  85. if (match && match[1]) {
  86. return match[1]
  87. }
  88. return null
  89. }
  90. export function patchRoutes ({ routes }) {
  91. if (process.env.FES_APP_PLUGINS === 'false') {
  92. console.log('项目开发模式: 配置 不自动增加插件plugins里面各个pages的页面路由')
  93. return
  94. }
  95. // 自动读取plugins目录下所有插件的pages的目录下的*.vue 并加入路由
  96. let viteModules = import.meta.glob('./plugins/**/pages/**/*.vue')
  97. if (process.env.FES_APP_PLSNAME !== undefined) {
  98. const filteredModules = Object.fromEntries(
  99. Object.entries(viteModules).filter(([path]) => path.startsWith(`./plugins/${process.env.FES_APP_PLSNAME}/pages/`))
  100. )
  101. viteModules = filteredModules
  102. }
  103. const needAddRouter = {
  104. path: '/plugins',
  105. component: () => import("./components/forPreview/suspenseLayout.vue"),
  106. children: []
  107. }
  108. // eslint-disable-next-line guard-for-in
  109. for (const [key, value] of Object.entries(viteModules)) {
  110. const pluginName = findStringBetween(key)
  111. const urlList = key.match(/\.\/(.+)\.vue$/)[1].split('/')
  112. if (urlList.length === 4) { //插件一级目录 普通插件
  113. needAddRouter.children.unshift({
  114. path: `/plugins/${pluginName}/${urlList[3]}`,
  115. component: value
  116. })
  117. }
  118. else if (urlList.length === 5) { //插件二级目录 目前只存在已 basic 基础功能展示
  119. needAddRouter.children.unshift({
  120. path: `/plugins/${pluginName}/${urlList[3]}/${urlList[4]}`,
  121. component: value
  122. })
  123. } else { // 若目录异常 那么直接跳过
  124. return
  125. }
  126. }
  127. routes.unshift(needAddRouter)
  128. }
  129. export function modifyRoute (memo) {
  130. if (process.env.FES_APP_PREINDEX === 'true') {
  131. console.log('预览模式下 已经自动替换index的路由为 plugins/preview.vue')
  132. let indexRoute = memo.routes.find(route => route.path === '/')
  133. if (indexRoute) {
  134. indexRoute = indexRoute.children.find(route => route.path === '/')
  135. if (indexRoute) {
  136. indexRoute.component = () => import("./plugins/preview.vue")
  137. indexRoute.meta = {
  138. name: 'preview',
  139. title: '开源框架展示',
  140. }
  141. }
  142. }
  143. }
  144. if (process.env.FES_APP_PLUGINS === 'false') {
  145. console.log('项目开发模式: 默认路由 去除layout模式')
  146. const indexRoute = memo.routes.find(route => route.path === '/')
  147. if (indexRoute) {
  148. indexRoute.component = null
  149. }
  150. }
  151. return {
  152. ...memo,
  153. routes: [
  154. ...memo.routes
  155. ]
  156. }
  157. }
  158. export const qiankun = {
  159. // 应用加载之前
  160. async bootstrap (props) {
  161. console.log('son TvT.js bootstrap', props)
  162. },
  163. // 应用 render 之前触发
  164. async mount (props) {
  165. console.log('son TvT.js mount', props)
  166. if (props) {
  167. props.onGlobalStateChange((state, prev) => {
  168. qiankunTvtStore.setGlobalState(state)
  169. })
  170. window.qiankunProps = props
  171. }
  172. },
  173. // 当 props 更新时触发
  174. async update (props) {
  175. console.log('son TvT.js update', props)
  176. },
  177. // 应用卸载之后触发
  178. async unmount (props) {
  179. console.log('son TvT.js unmount', props)
  180. },
  181. }