feat(projects): 添加naiveUI按需引入

This commit is contained in:
Soybean
2022-02-17 00:58:55 +08:00
parent 225e7128b6
commit a810ef85b1
69 changed files with 231 additions and 120 deletions

View File

@ -13,7 +13,7 @@
</template>
<script setup lang="ts">
import { NConfigProvider, zhCN, dateZhCN } from 'naive-ui';
import { zhCN, dateZhCN } from 'naive-ui';
import { NaiveProvider } from '@/components';
import { useThemeStore, subscribeStore } from '@/store';

View File

@ -27,7 +27,6 @@
<script setup lang="ts">
import { computed, watch, nextTick, onUnmounted } from 'vue';
import { NSpin } from 'naive-ui';
import { NETWORK_ERROR_MSG } from '@/config';
import { SvgEmptyData, SvgNetworkError } from '@/components';
import { useBoolean } from '@/hooks';

View File

@ -8,7 +8,6 @@
<script setup lang="ts">
import { computed } from 'vue';
import { NCheckbox, NButton } from 'naive-ui';
interface Props {
/** 是否勾选 */

View File

@ -16,7 +16,6 @@
<script lang="ts" setup>
import { computed } from 'vue';
import { NTooltip } from 'naive-ui';
import type { FollowerPlacement } from 'vueuc';
interface Props {

View File

@ -12,7 +12,6 @@
</template>
<script setup lang="ts">
import { NLoadingBarProvider, NDialogProvider, NNotificationProvider, NMessageProvider } from 'naive-ui';
import { NaiveProviderContent } from './components';
</script>
<style scoped></style>

View File

@ -25,7 +25,6 @@
</template>
<script setup lang="ts">
import { NDivider } from 'naive-ui';
import { useBoolean } from '@/hooks';
import IconClose from '../IconClose/index.vue';
import { SvgRadiusBg } from './components';

View File

@ -26,7 +26,6 @@
<script lang="ts" setup>
import { ref, computed } from 'vue';
import { NPopover, NInput, NEmpty } from 'naive-ui';
import { Icon } from '@iconify/vue';
import { useThemeStore } from '@/store';

View File

@ -24,7 +24,6 @@
<script setup lang="ts">
import { computed } from 'vue';
import { useRoute } from 'vue-router';
import { NBreadcrumb, NBreadcrumbItem, NDropdown } from 'naive-ui';
import { routePath } from '@/router';
import { useThemeStore, useRouteStore } from '@/store';
import { useRouterPush } from '@/composables';

View File

@ -5,7 +5,6 @@
<script setup lang="ts">
import { computed } from 'vue';
import { useRoute } from 'vue-router';
import { NMenu } from 'naive-ui';
import type { MenuOption } from 'naive-ui';
import { useRouteStore } from '@/store';
import { useRouterPush } from '@/composables';

View File

@ -8,7 +8,6 @@
</template>
<script lang="ts" setup>
import { NDropdown, useDialog } from 'naive-ui';
import { HoverContainer } from '@/components';
import { useAuthStore } from '@/store';
import { iconifyRender } from '@/utils';
@ -17,7 +16,6 @@ import avatar from '@/assets/svg/common/avatar01.svg';
type DropdownKey = 'user-center' | 'logout';
const auth = useAuthStore();
const dialog = useDialog();
const options = [
{
@ -39,7 +37,7 @@ const options = [
function handleDropdown(optionKey: string) {
const key = optionKey as DropdownKey;
if (key === 'logout') {
dialog.info({
window.$dialog?.info({
title: '提示',
content: '您确定要退出登录吗?',
positiveText: '确定',

View File

@ -26,7 +26,6 @@
<script lang="ts" setup>
import { ref, shallowRef, computed, watch, nextTick } from 'vue';
import { useRouter } from 'vue-router';
import { NModal, NInput, NEmpty } from 'naive-ui';
import { useDebounceFn, onKeyStroke } from '@vueuse/core';
import { useRouteStore } from '@/store';
import type { RouteList } from './types';

View File

@ -22,7 +22,6 @@
<script lang="ts" setup>
import { computed } from 'vue';
import { NScrollbar } from 'naive-ui';
import { Icon } from '@iconify/vue';
import { useThemeStore } from '@/store';
import type { RouteList } from './types';

View File

@ -6,7 +6,6 @@
</template>
<script lang="ts" setup>
import { NButton } from 'naive-ui';
import { useAppStore } from '@/store';
const app = useAppStore();

View File

@ -31,7 +31,6 @@
<script setup lang="ts">
import { ref, computed, watch } from 'vue';
import { useRoute } from 'vue-router';
import { NScrollbar, NMenu } from 'naive-ui';
import type { MenuOption } from 'naive-ui';
import { DarkModeContainer } from '@/components';
import { useAppStore, useThemeStore } from '@/store';

View File

@ -23,7 +23,6 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { NScrollbar } from 'naive-ui';
import { DarkModeContainer } from '@/components';
import { useAppStore, useThemeStore, useRouteStore } from '@/store';
import { useRouterPush } from '@/composables';

View File

@ -17,7 +17,6 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { NScrollbar, NMenu } from 'naive-ui';
import type { MenuOption } from 'naive-ui';
import { useAppStore, useThemeStore, useRouteStore } from '@/store';
import { useRouterPush } from '@/composables';

View File

@ -12,7 +12,6 @@
<script setup lang="ts">
import { computed } from 'vue';
import { NDropdown } from 'naive-ui';
import type { DropdownOption } from 'naive-ui';
import { useAppStore, useTabStore } from '@/store';
import { iconifyRender } from '@/utils';

View File

@ -13,7 +13,6 @@
</template>
<script lang="ts" setup>
import { NDivider, NSwitch } from 'naive-ui';
import { useThemeStore } from '@/store';
const theme = useThemeStore();

View File

@ -11,7 +11,6 @@
</template>
<script setup lang="ts">
import { NButton } from 'naive-ui';
import { useAppStore } from '@/store';
const app = useAppStore();

View File

@ -17,7 +17,6 @@
<script setup lang="ts">
import { computed } from 'vue';
import { NTooltip } from 'naive-ui';
import type { FollowerPlacement } from 'vueuc';
import { EnumThemeLayoutMode } from '@/enum';
import type { ThemeLayoutMode } from '@/interface';

View File

@ -13,7 +13,6 @@
</template>
<script setup lang="ts">
import { NDivider, NSpace } from 'naive-ui';
import { useThemeStore } from '@/store';
import { LayoutCheckbox } from './components';

View File

@ -59,7 +59,6 @@
</template>
<script lang="ts" setup>
import { NDivider, NSpace, NSwitch, NSelect, NInputNumber } from 'naive-ui';
import { useThemeStore } from '@/store';
import SettingMenu from '../SettingMenu/index.vue';

View File

@ -35,7 +35,6 @@
</template>
<script lang="ts" setup>
import { NDivider, NSpace, NSwitch, NSelect } from 'naive-ui';
import { useThemeStore } from '@/store';
import SettingMenu from '../SettingMenu/index.vue';

View File

@ -23,7 +23,6 @@
</template>
<script setup lang="ts">
import { NModal, NGradientText, NTabs, NTabPane, NGrid, NGridItem } from 'naive-ui';
import { traditionColors } from '@/settings';
import { useThemeStore } from '@/store';
import ColorCheckbox from './ColorCheckbox.vue';

View File

@ -14,7 +14,6 @@
<script setup lang="ts">
import { computed } from 'vue';
import { NDivider, NGrid, NGridItem, NSpace, NButton, NColorPicker } from 'naive-ui';
import { isInTraditionColors } from '@/settings';
import { useThemeStore } from '@/store';
import { useBoolean } from '@/hooks';

View File

@ -11,7 +11,6 @@
<script setup lang="ts">
import { ref, watch, onMounted, onUnmounted } from 'vue';
import { NDivider, NSpace, NButton } from 'naive-ui';
import Clipboard from 'clipboard';
import { useThemeStore } from '@/store';

View File

@ -13,7 +13,6 @@
</template>
<script setup lang="ts">
import { NDrawer, NDrawerContent } from 'naive-ui';
import { useAppStore } from '@/store';
import { DrawerButton, DarkMode, LayoutMode, ThemeColorSelect, PageFunc, PageView, ThemeConfig } from './components';

View File

@ -1,5 +1,5 @@
import { createApp } from 'vue';
import { setupAssets } from '@/plugins';
import { setupAssets, setupNaiveUI } from '@/plugins';
import { setupRouter } from '@/router';
import { setupStore } from '@/store';
import { setupDirectives } from '@/directives';
@ -17,6 +17,9 @@ async function setupApp() {
// 挂载自定义vue指令
setupDirectives(app);
// 按需引入naiveUI
setupNaiveUI(app);
// 挂载路由
await setupRouter(app);

View File

@ -1,3 +1,4 @@
import setupAssets from './assets';
import setupNaiveUI from './naive';
export { setupAssets };
export { setupAssets, setupNaiveUI };

103
src/plugins/naive.ts Normal file
View File

@ -0,0 +1,103 @@
import type { App } from 'vue';
import {
create,
NBreadcrumb,
NBreadcrumbItem,
NButton,
NCard,
NCheckbox,
NColorPicker,
NConfigProvider,
NDataTable,
NDescriptions,
NDescriptionsItem,
NDialogProvider,
NDivider,
NDrawer,
NDrawerContent,
NDropdown,
NEmpty,
NForm,
NFormItem,
NGradientText,
NGrid,
NGridItem,
NInput,
NInputGroup,
NInputNumber,
NList,
NListItem,
NLoadingBarProvider,
NModal,
NMenu,
NMessageProvider,
NNotificationProvider,
NPopover,
NScrollbar,
NSelect,
NSpace,
NStatistic,
NSwitch,
NSpin,
NTabs,
NTabPane,
NTag,
NThing,
NTimeline,
NTimelineItem,
NTooltip
} from 'naive-ui';
/** 按需引入naiveUI */
export default function setupNaiveUI(app: App) {
const naive = create({
components: [
NBreadcrumb,
NBreadcrumbItem,
NButton,
NCard,
NCheckbox,
NColorPicker,
NConfigProvider,
NDataTable,
NDescriptions,
NDescriptionsItem,
NDialogProvider,
NDivider,
NDrawer,
NDrawerContent,
NDropdown,
NEmpty,
NForm,
NFormItem,
NGradientText,
NGrid,
NGridItem,
NInput,
NInputGroup,
NInputNumber,
NList,
NListItem,
NLoadingBarProvider,
NModal,
NMenu,
NMessageProvider,
NNotificationProvider,
NPopover,
NScrollbar,
NSelect,
NSpace,
NStatistic,
NSwitch,
NSpin,
NTabs,
NTabPane,
NTag,
NThing,
NTimeline,
NTimelineItem,
NTooltip
]
});
app.use(naive);
}

View File

@ -9,7 +9,6 @@
</template>
<script setup lang="ts">
import { NCard, NDescriptions, NDescriptionsItem } from 'naive-ui';
import { pkgJson } from '../model';
const { devDependencies } = pkgJson;

View File

@ -9,7 +9,6 @@
</template>
<script setup lang="ts">
import { NCard, NDescriptions, NDescriptionsItem } from 'naive-ui';
import { pkgJson } from '../model';
const { dependencies } = pkgJson;

View File

@ -18,7 +18,6 @@
</template>
<script setup lang="ts">
import { NCard, NDescriptions, NDescriptionsItem, NTag } from 'naive-ui';
import { pkgJson } from '../model';
const { version } = pkgJson;

View File

@ -7,7 +7,5 @@
</n-card>
</template>
<script setup lang="ts">
import { NCard } from 'naive-ui';
</script>
<script setup lang="ts"></script>
<style scoped></style>

View File

@ -8,7 +8,6 @@
</template>
<script setup lang="ts">
import { NSpace } from 'naive-ui';
import { ProjectIntroduction, ProjectInfo, ProDependency, DevDependency } from './components';
</script>
<style scoped></style>

View File

@ -35,7 +35,6 @@
</template>
<script setup lang="ts">
import { NCard, NGrid, NGridItem, NSpace, NButton } from 'naive-ui';
import type { ButtonProps } from 'naive-ui';
import { Icon } from '@iconify/vue';
import { useLoading } from '@/hooks';

View File

@ -37,7 +37,5 @@
</div>
</template>
<script setup lang="ts">
import { NCard, NSpace } from 'naive-ui';
</script>
<script setup lang="ts"></script>
<style scoped></style>

View File

@ -16,7 +16,6 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { NCard, NSpace, NButton, NDataTable } from 'naive-ui';
import type { DataTableColumn } from 'naive-ui';
import { LoadingEmptyWrapper } from '@/components';
import { useLoadingEmpty } from '@/hooks';

View File

@ -21,7 +21,7 @@
<script setup lang="ts">
import { h } from 'vue';
import { NGrid, NGridItem, NCard, NTimeline, NTimelineItem, NDataTable, NTag } from 'naive-ui';
import { NTag } from 'naive-ui';
interface TimelineData {
type: 'default' | 'info' | 'success' | 'warning' | 'error';

View File

@ -18,7 +18,6 @@
</template>
<script setup lang="ts">
import { NGrid, NGridItem } from 'naive-ui';
import { Icon } from '@iconify/vue';
import { CountTo } from '@/components';
import { GradientBg } from './components';

View File

@ -32,7 +32,6 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { NGrid, NGridItem, NCard, NButton } from 'naive-ui';
import { Line, Pie } from '@antv/g2plot';
import { CountTo } from '@/components';
import data from './data.json';

View File

@ -7,7 +7,6 @@
</template>
<script lang="ts" setup>
import { NSpace } from 'naive-ui';
import { TopChart, DataCard, BottomPart } from './components';
</script>
<style scoped></style>

View File

@ -16,7 +16,6 @@
</template>
<script setup lang="ts">
import { NCard, NSpace, NStatistic } from 'naive-ui';
import { useAuthStore } from '@/store';
interface StatisticData {

View File

@ -47,7 +47,6 @@
</template>
<script setup lang="ts">
import { NGrid, NGridItem, NSpace, NCard, NList, NListItem, NThing } from 'naive-ui';
import { SvgBanner } from '@/components';
import { TechnologyCard, ShortcutsCard } from './components';

View File

@ -5,7 +5,6 @@
</n-space>
</template>
<script lang="ts" setup>
import { NSpace } from 'naive-ui';
import { WorkbenchHeader, WorkbenchMain } from './components';
</script>
<style scoped></style>

View File

@ -4,7 +4,5 @@
</div>
</template>
<script setup lang="ts">
import { NCard } from 'naive-ui';
</script>
<script setup lang="ts"></script>
<style scoped></style>

View File

@ -4,7 +4,5 @@
</div>
</template>
<script setup lang="ts">
import { NCard } from 'naive-ui';
</script>
<script setup lang="ts"></script>
<style scoped></style>

View File

@ -11,24 +11,22 @@
<script lang="ts" setup>
import { ref } from 'vue';
import { NCard, NInputGroup, NInput, NButton, useMessage } from 'naive-ui';
import { useClipboard } from '@vueuse/core';
const source = ref('');
const message = useMessage();
const { copy, isSupported } = useClipboard();
function handleCopy() {
if (!isSupported) {
message.error('您的浏览器不支持Clipboard API');
window.$message?.error('您的浏览器不支持Clipboard API');
return;
}
if (!source.value) {
message.error('请输入要复制的内容');
window.$message?.error('请输入要复制的内容');
return;
}
copy(source.value);
message.success(`复制成功:${source.value}`);
window.$message?.success(`复制成功:${source.value}`);
}
</script>
<style scoped></style>

View File

@ -11,7 +11,6 @@
<script setup lang="ts">
import { ref, watch, onMounted, onUnmounted } from 'vue';
import { NCard } from 'naive-ui';
import Vditor from 'vditor';
import 'vditor/src/assets/scss/index.scss';
import { GithubLink } from '@/components';

View File

@ -11,7 +11,6 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { NCard } from 'naive-ui';
import WangEditor from 'wangeditor';
import { GithubLink } from '@/components';

View File

@ -21,7 +21,6 @@
<script lang="ts" setup>
import { ref } from 'vue';
import { NCard } from 'naive-ui';
import { Icon } from '@iconify/vue';
import { IconSelect, WebSiteLink } from '@/components';
import { icons } from './icons';

View File

@ -12,7 +12,6 @@
<script setup lang="ts">
import type { Component } from 'vue';
import { NCard, NTabs, NTabPane } from 'naive-ui';
import { GaodeMap, TencentMap } from './components';
interface Map {

View File

@ -11,7 +11,6 @@
</template>
<script lang="ts" setup>
import { NCard, NButton } from 'naive-ui';
import printJS from 'print-js';
import { GithubLink } from '@/components';

View File

@ -21,7 +21,6 @@
</template>
<script setup lang="ts">
import { NCard, NSpace } from 'naive-ui';
import SwiperCore, { Navigation, Pagination } from 'swiper';
import { Swiper, SwiperSlide } from 'swiper/vue';
import type { SwiperOptions } from 'swiper';

View File

@ -8,7 +8,6 @@
<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue';
import { NCard } from 'naive-ui';
import Player from 'xgplayer';
const domRef = ref<HTMLElement>();

View File

@ -12,7 +12,6 @@
<script lang="ts" setup>
import { computed } from 'vue';
import type { Component } from 'vue';
import { NButton } from 'naive-ui';
import { SvgNoPermission, SvgNotFound, SvgServiceError } from '@/components';
import { routeName } from '@/router';

View File

@ -21,7 +21,6 @@
<script setup lang="ts">
import { reactive, ref } from 'vue';
import { NForm, NFormItem, NInput, NSpace, NButton } from 'naive-ui';
import type { FormInst } from 'naive-ui';
import { useRouterPush } from '@/composables';
import { useSmsCode } from '@/hooks';

View File

@ -36,7 +36,6 @@
<script setup lang="ts">
import { reactive, ref } from 'vue';
import { NForm, NFormItem, NInput, NSpace, NButton } from 'naive-ui';
import type { FormInst } from 'naive-ui';
import { ImageVerify } from '@/components';
import { useAuthStore } from '@/store';

View File

@ -9,7 +9,5 @@
</n-space>
</template>
<script lang="ts" setup>
import { NSpace, NDivider, NButton } from 'naive-ui';
</script>
<script lang="ts" setup></script>
<style scoped></style>

View File

@ -37,7 +37,6 @@
<script setup lang="ts">
import { reactive, ref } from 'vue';
import { NForm, NFormItem, NInput, NSpace, NCheckbox, NButton } from 'naive-ui';
import type { FormInst, FormRules } from 'naive-ui';
import { EnumLoginModule } from '@/enum';
import { useAuthStore } from '@/store';

View File

@ -28,7 +28,6 @@
<script lang="ts" setup>
import { reactive, ref, toRefs } from 'vue';
import { NForm, NFormItem, NInput, NSpace, NButton } from 'naive-ui';
import type { FormInst, FormRules } from 'naive-ui';
import { LoginAgreement } from '@/components';
import { useRouterPush } from '@/composables';

View File

@ -27,13 +27,11 @@
<script lang="ts" setup>
import { reactive, ref, toRefs } from 'vue';
import { NForm, NFormItem, NInput, NSpace, NButton, useMessage } from 'naive-ui';
import type { FormInst, FormRules } from 'naive-ui';
import { useRouterPush } from '@/composables';
import { useSmsCode } from '@/hooks';
import { formRules, getConfirmPwdRule } from '@/utils';
const message = useMessage();
const { toLoginModule } = useRouterPush();
const { label, isCounting, loading: smsLoading, start } = useSmsCode();
@ -61,9 +59,9 @@ function handleSubmit(e: MouseEvent) {
formRef.value.validate(errors => {
if (!errors) {
message.success('验证成功');
window.$message?.success('验证成功');
} else {
message.error('验证失败');
window.$message?.error('验证失败');
}
});
}

View File

@ -30,7 +30,6 @@
<script setup lang="ts">
import { computed } from 'vue';
import type { Component } from 'vue';
import { NCard, NGradientText } from 'naive-ui';
import { EnumLoginModule } from '@/enum';
import { SystemLogo, DarkModeSwitch } from '@/components';
import { useThemeStore } from '@/store';