1
头图

闭关半个月高强度研发tauri2.0+vue3客户端后台管理系统Tauri2Vue3Admin。

tauri2.0-vue3-admin一款基于最新跨平台技术Tauri2.0+vue3 setup+pinia2+element-plus+echarts搭建桌面版后台管理系统项目。

tauri2-admin提供4种通用布局模板,支持vue-i18n国际化、面包屑导航、多标签快捷路由等功能。

技术栈

  • 开发工具:VScode
  • 技术框架:Tauri2.0+Vite^5.4+Vue^3.5+Vue-Router^4.4.5
  • 状态插件:pinia^2.2.4
  • 本地存储:pinia-plugin-persistedstate^4.1.1
  • 组件库:element-plus^2.8.5
  • 图表组件:echarts^5.5.1
  • 国际化:vue-i18n^10.0.4
  • 富文本编辑器:@vueup/vue-quill^1.2.0
  • md编辑器:md-editor-v3^4.20.3
  • 模拟数据:mockjs^1.1.0
  • 预处理样式:sass^1.79.4

Tauri2-Vue3admin已经更新到我的原创作品集。

https://gf.bilibili.com/item/detail/1107226011

项目框架目录

整个项目使用最新版tauri2.0+vite.js搭建项目模板,采用vue3 setup语法编码开发。

vue3-tauri2admin公共布局

8ba64962c6b12364f6f367f7529fc596_1289798-20241015124030720-854798810.png

a8cc17cfb995b30458c51ee1758e69d4_1289798-20241015123635978-531225656.png

<script setup>
  import { appState } from '@/pinia/modules/app'

  import Toolbar from '@/layouts/components/Toolbar.vue'
  import Sidebar from '@/layouts/components/sidebar/index.vue'
  import Menus from '@/layouts/components/menus/index.vue'
  import Breadcrumb from '@/layouts/components/Breadcrumb.vue'
  import Tabview from '@/layouts/components/Tabview.vue'
  import Main from '@/layouts/components/Main.vue'

  const appstate = appState()
</script>

<template>
  <div class="vuadmin__layout flexbox flex-col">
    <Toolbar />

    <div class="vuadmin__layout-body flex1 flexbox">
      <!-- 侧边栏 -->
      <div class="vuadmin__layout-sidebar">
        <Sidebar />
      </div>

      <!-- 菜单栏 -->
      <div class="vuadmin__layout-menus" :class="{'hidden': appstate.config.collapsed}">
        <el-scrollbar>
          <Menus :rootRouteEnable="false" />
        </el-scrollbar>
      </div>

      <!-- 右侧主内容区 -->
      <div class="vuadmin__layout-main flex1 flexbox flex-col">
        <!-- 面包屑导航 -->
        <Breadcrumb v-if="appstate.config.breadcrumb" />

        <!-- 标签页 -->
        <Tabview v-if="appstate.config.tabview" />

        <!-- 内容区 -->
        <Main />
      </div>
    </div>
  </div>
</template>

tauri2+vite自定义无边框导航窗口

image.png

0ecb83bbdfa69289097b9ebd5e7322fa_1289798-20241015125822456-482228378.png

<script setup>
  import { ref, markRaw } from 'vue'
  import { ElMessageBox } from 'element-plus'
  import { QuestionFilled, SwitchButton } from '@element-plus/icons-vue'
  import { getCurrentWindow } from '@tauri-apps/api/window'
  import { listen } from '@tauri-apps/api/event'
  import { exit } from '@tauri-apps/plugin-process'

  import { isTrue } from '@/utils'
  import { authState } from '@/pinia/modules/auth'

  const authstate = authState()

  const props = defineProps({
    color: String,
    // 窗口是否可最小化
    minimizable: {type: [Boolean, String], default: true},
    // 窗口是否可最大化
    maximizable: {type: [Boolean, String], default: true},
    // 窗口是否可关闭
    closable: {type: [Boolean, String], default: true},
    // 层级
    zIndex: {type: [Number, String], default: 2024},
  })

  const hasMaximized = ref(false)
  const isResizable = ref(true)
  const isMaximizable = ref(true)
  
  // 用户是否可以手动调整窗口大小
  getCurrentWindow().isResizable().then(res => {
    isResizable.value = res
  })
  // 窗口是否可以最大化
  getCurrentWindow().isMaximizable().then(res => {
    isMaximizable.value = res
  })
  // 初始监听窗口是否最大化
  getCurrentWindow().isMaximized().then(res => {
    hasMaximized.value = res
  })
  // 实时监听窗口是否最大化
  listen('tauri://resize', async() => {
    hasMaximized.value = await getCurrentWindow().isMaximized()
  })

  // 最小化
  const handleWinMin = async() => {
    await getCurrentWindow().minimize()
  }
  // 最大化/还原
  const handleWinToggle = async() => {
    await getCurrentWindow().toggleMaximize()
  }
  // 关闭
  const handleWinClose = async() => {
    const isMajor = getCurrentWindow().label.indexOf('main') > -1
    if(isMajor) {
      ElMessageBox.confirm('是否最小化到系统托盘,不退出程序?', '提示', {
        type: 'warning',
        icon: markRaw(QuestionFilled),
        confirmButtonText: '残忍退出',
        cancelButtonText: '最小化到托盘',
        customStyle: {'width': '300px'},
        draggable: true,
        roundButton: true,
        center: true,
        buttonSize: 'small',
        distinguishCancelAndClose: true,
      }).then(async() => {
        authstate.logout()
        await exit()
      }).catch(async(action) => {
        if(action === 'cancel') {
          await getCurrentWindow().hide()
        }
      })
    }else {
      await getCurrentWindow().close()
    }
  }
</script>

<template>
  <div class="ev__winbtns flexbox flex-alignc vu__drag" :style="{'z-index': zIndex}">
    <div class="ev__winbtns-actions flexbox flex-alignc vu__undrag" :style="{'color': color}">
      <a v-if="isTrue(minimizable)" class="wbtn min" title="最小化" @click="handleWinMin"><i class="wicon iconfont elec-icon-min"></i></a>
      <a v-if="isTrue(maximizable)" class="wbtn toggle" :title="hasMaximized ? '向下还原' : '最大化'" @click="handleWinToggle">
        <i class="wicon iconfont" :class="hasMaximized ? 'elec-icon-restore' : 'elec-icon-max'"></i>
      </a>
      <a v-if="isTrue(closable)" class="wbtn close" title="关闭" @click="handleWinClose"><i class="wicon iconfont elec-icon-quit"></i></a>
    </div>
  </div>
</template>

<style lang="scss" scoped>
  @import './index.scss';
</style>

tauri2.0-admin多语言解决方案

0af90779809974ea154be5856b3a18f3_1289798-20241015130440680-1653490841.png

fdefca4c33f691af064fa0cb21f90aca_1289798-20241015130606117-807315059.png

import { createI18n } from 'vue-i18n'
import { appState } from '@/pinia/modules/app'

// 引入语言配置
import enUS from './en-US'
import zhCN from './zh-CN'
import zhTW from './zh-TW'

// 默认语言
export const langVal = 'zh-CN'

export default async (app) => {
  const appstate = appState()
  const lang = appstate.lang || langVal
  appstate.setLang(lang)

  const i18n = createI18n({
    legacy: false,
    locale: lang,
    messages: {
      'en': enUS,
      'zh-CN': zhCN,
      'zh-TW': zhTW
    }
  })
  
  app.use(i18n)
}

tauri2-admin动态图表化

906aeae45b9af4c50605de349a2907c4_1289798-20241015131117276-1962723619.png

509b2a5c58fd8d6bbeb1de995ab89938_1289798-20241015131257606-1898979317.png

import { onMounted, onBeforeUnmount, ref } from 'vue'
import * as echarts from 'echarts'
import elementResizeDetectorMaker from 'element-resize-detector'

export function useEcharts(el, options) {
  let chartEl
  let chartRef = ref(null)
  let erd = elementResizeDetectorMaker()

  const resizeHandle = () => {
    chartEl && chartEl.resize()
  }

  onMounted(() => {
    if(el?.value) {
      chartEl = echarts.init(el.value)
      chartEl.setOption(options)
      chartRef.value = chartEl
    }
    erd.listenTo(el.value, resizeHandle)
  })

  onBeforeUnmount(() => {
    chartEl.dispose()
    erd.removeListener(el.value, resizeHandle)
  })

  return chartRef
}

tauri2admin自定义标签栏路由切换

b7473023d7ff7b2358802266379e6844_1289798-20241015132044228-900388933.png

6cddb6d052c8fa3aacef8d127c63c47e_1289798-20241015132134316-940668739.png

<template>
  <div class="vu__tabview">
    <el-tabs
      v-model="activeTab"
      class="vu__tabview-tabs"
      @tab-change="changeTabs"
      @tab-remove="removeTab"
    >
      <el-tab-pane
        v-for="(item, index) in tabList"
        :key="index"
        :name="item.path"
        :closable="!item?.meta?.isAffix"
      >
        <template #label>
          <el-dropdown ref="dropdownRef" trigger="contextmenu" :id="item.path" @visible-change="handleDropdownChange($event, item.path)" @command="handleDropdownCommand($event, item)">
            <span class="vu__tabview-tabs__label">
              <span>{{$t(item?.meta?.title)}}</span>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item command="refresh" :icon="Refresh">{{$t('tabview__contextmenu-refresh')}}</el-dropdown-item>
                <el-dropdown-item command="close" :icon="Close" :disabled="item.meta.isAffix">{{$t('tabview__contextmenu-close')}}</el-dropdown-item>
                <el-dropdown-item command="closeOther" :icon="Switch">{{$t('tabview__contextmenu-closeother')}}</el-dropdown-item>
                <el-dropdown-item command="closeLeft" :icon="DArrowLeft">{{$t('tabview__contextmenu-closeleft')}}</el-dropdown-item>
                <el-dropdown-item command="closeRight" :icon="DArrowRight">{{$t('tabview__contextmenu-closeright')}}</el-dropdown-item>
                <el-dropdown-item command="closeAll" :icon="CircleCloseFilled">{{$t('tabview__contextmenu-closeall')}}</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </template>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

tauri2-vue3-admin电脑端后台管理系统就先分享到这里。

https://segmentfault.com/a/1190000045331960
https://segmentfault.com/a/1190000045245775
https://segmentfault.com/a/1190000045042968
https://segmentfault.com/a/1190000044847552


xiaoyan2017
765 声望314 粉丝

web前端开发爱好者,专注于前端h5、jquery、vue、react、angular等技术研发实战项目案例。