feat: 条形码组件

This commit is contained in:
WANGFAN\wangf 2025-01-09 20:34:07 +08:00
parent 19a0f12336
commit e7402da940
6 changed files with 229 additions and 138 deletions

27
src/components.d.ts vendored
View File

@ -5,19 +5,20 @@
// Read more: https://github.com/vuejs/core/pull/3399 // Read more: https://github.com/vuejs/core/pull/3399
export {} export {}
declare module 'vue' { declare module "vue" {
export interface GlobalComponents { export interface GlobalComponents {
CodeView: typeof import('./components/code-view/index.vue')['default'] CodeView: (typeof import("./components/code-view/index.vue"))["default"];
ExternalLinkPage: typeof import('./components/external-link-page/index.vue')['default'] DrawBarcode: (typeof import("./components/draw-barcode/index.vue"))["default"];
FillPage: typeof import('./components/fill-page/index.vue')['default'] ExternalLinkPage: (typeof import("./components/external-link-page/index.vue"))["default"];
InternalLinkPage: typeof import('./components/internal-link-page/index.vue')['default'] FillPage: (typeof import("./components/fill-page/index.vue"))["default"];
LangProvider: typeof import('./components/lang-provider/index.vue')['default'] InternalLinkPage: (typeof import("./components/internal-link-page/index.vue"))["default"];
MainTransition: typeof import('./components/main-transition/index.vue')['default'] LangProvider: (typeof import("./components/lang-provider/index.vue"))["default"];
RouterLink: typeof import('vue-router')['RouterLink'] MainTransition: (typeof import("./components/main-transition/index.vue"))["default"];
RouterView: typeof import('vue-router')['RouterView'] RouterLink: (typeof import("vue-router"))["RouterLink"];
SelectIcon: typeof import('./components/select-icon/index.vue')['default'] RouterView: (typeof import("vue-router"))["RouterView"];
SvgAndIcon: typeof import('./components/svg-and-icon/index.vue')['default'] SelectIcon: (typeof import("./components/select-icon/index.vue"))["default"];
SvgIcon: typeof import('./components/svg-icon/index.vue')['default'] SvgAndIcon: (typeof import("./components/svg-and-icon/index.vue"))["default"];
VerifyCode: typeof import('./components/verify-code/index.vue')['default'] SvgIcon: (typeof import("./components/svg-icon/index.vue"))["default"];
VerifyCode: (typeof import("./components/verify-code/index.vue"))["default"];
} }
} }

View File

@ -0,0 +1,32 @@
<template>
<component :is="tag" ref="nodes" />
</template>
<script setup lang="ts">
import JsBarcode from "jsbarcode";
const props = defineProps({
// svgimgcanvas
tag: {
type: String,
default: "svg"
},
//
text: {
type: String,
default: ""
},
//
// https://github.com/lindell/JsBarcode/wiki/Options
options: {
type: Object,
default() {
return {};
}
}
});
const nodes = ref();
onMounted(() => {
JsBarcode(nodes.value, props.text, props.options);
});
</script>

View File

@ -26,7 +26,6 @@ let { isFooter } = storeToRefs(themeStore);
<style lang="scss" scoped> <style lang="scss" scoped>
.layout { .layout {
height: 100vh; height: 100vh;
border: 1px solid red;
} }
.layout-right { .layout-right {
display: grid; display: grid;

View File

@ -37,11 +37,11 @@ const router = createRouter({
* routeTree不能持久化缓存 * routeTree不能持久化缓存
* addRoute动态添加的路由失效 * addRoute动态添加的路由失效
*/ */
router.beforeEach(async (to, from, next) => { router.beforeEach(async (to, _, next) => {
NProgress.start(); // 开启进度条 NProgress.start(); // 开启进度条
const store = useUserInfoStore(pinia); const store = useUserInfoStore(pinia);
const { token } = storeToRefs(store); const { token } = storeToRefs(store);
console.log("去", to, "来自", from); // console.log("去", to, "来自", from);
// next()内部加了path等于跳转指定路由会再次触发router.beforeEach内部无参数等于放行不会触发router.beforeEach // next()内部加了path等于跳转指定路由会再次触发router.beforeEach内部无参数等于放行不会触发router.beforeEach
if (to.path === "/login" && !token.value) { if (to.path === "/login" && !token.value) {
// 1、去登录页无token放行 // 1、去登录页无token放行

View File

@ -1,12 +1,14 @@
// 设置滚动条的样式 // 设置滚动条的样式
::-webkit-scrollbar { ::-webkit-scrollbar {
width: 6px; width: 6px;
height: 6px;
} }
// 基于 WebKit 内核的浏览器 // 基于 WebKit 内核的浏览器
// 设置滚动条的样式圆角背景颜色 // 设置滚动条的样式圆角背景颜色
::-webkit-scrollbar-thumb { ::-webkit-scrollbar-thumb {
width: 6px; width: 6px;
height: 6px;
background-color: $color-border-3; background-color: $color-border-3;
border-radius: 6px; border-radius: 6px;
} }
@ -14,16 +16,19 @@
// 设置滚动条hover样式圆角背景颜色 // 设置滚动条hover样式圆角背景颜色
::-webkit-scrollbar-thumb:hover { ::-webkit-scrollbar-thumb:hover {
width: 6px; width: 6px;
height: 6px;
background-color: $color-border-4; background-color: $color-border-4;
} }
// 设置IE/Edge浏览器滚动条的样式与webkit内核浏览器样式相同 // 设置IE/Edge浏览器滚动条的样式与webkit内核浏览器样式相同
::-ms-scrollbar-thumb { ::-ms-scrollbar-thumb {
width: 6px; width: 6px;
height: 6px;
background-color: $color-border-3; background-color: $color-border-3;
border-radius: 6px; border-radius: 6px;
} }
::-ms-scrollbar-thumb:hover { ::-ms-scrollbar-thumb:hover {
width: 6px; width: 6px;
height: 6px;
background-color: $color-border-4; background-color: $color-border-4;
} }

View File

@ -1,36 +1,90 @@
<template> <template>
<div class="snow-page"> <div class="snow-page">
<div class="snow-inner"> <div class="snow-inner">
<svg id="imgcode"></svg> <div class="code-box">
<a-card v-for="item in codeList" :key="item.id" :title="item.docs" :style="{ width: '400px' }" hoverable>
<div class="card-content">
<draw-barcode :text="item.text" :options="item.options" />
</div>
</a-card>
</div>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import JsBarcode from "jsbarcode"; const codeList = ref([
{
const createCode = () => { id: 1,
JsBarcode("#imgcode", "123", { text: "SnowAdmin",
format: "CODE39", //使 docs: "CODE128-默认条形码",
width: 3, // options: {
height: 100, // format: "CODE128",
displayValue: true, // height: 100
text: "456", // }
fontOptions: "bold italic", //使 },
font: "fantasy", // {
textAlign: "left", // id: 2,
textPosition: "top", // text: "SnowAdmin",
textMargin: 5, // docs: "自定义高度和颜色",
fontSize: 15, // options: {
background: "#eee", // format: "CODE128",
lineColor: "#2196f3", // height: 50,
margin: 15 // background: "#f7f8fa",
}); lineColor: "#2962ff"
}; }
},
onMounted(() => { {
createCode(); id: 3,
}); text: "SnowAdmin",
docs: "设置字体和倾斜",
options: {
format: "CODE128",
height: 100,
font: "fantasy",
fontOptions: "italic"
}
},
{
id: 4,
text: "SnowAdmin",
docs: "CODE39-商品条形码",
options: {
format: "CODE39",
height: 100
}
},
{
id: 5,
text: "6971318501227",
docs: "EAN13-商品条形码",
options: {
format: "EAN13",
height: 100
}
},
{
id: 6,
text: "123456789999",
docs: "UPC-商品条形码",
options: {
format: "UPC",
height: 100
}
}
]);
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped>
.code-box {
display: flex;
flex-wrap: wrap;
gap: $margin;
.card-content {
display: flex;
align-items: center;
justify-content: center;
height: 120px;
}
}
</style>