Vue3.0 Vite + windicss + ...实战项目
2022-10-13 本文已影响0人
coderhzc
二十六.如何实现一个全局的自定义指令, 实现权限管理
当后端返回一个数组里面有权限管理对应的数据,我想实现用自定义指令去实现某个按钮或者图表显示隐藏,该怎么做了?
1. 创建一个directives/directivePermission.js 文件
import store from "~/store";
const hasPermission = (value, el = false) => {
if (!Array.isArray(value)) { // 从指令上传递过来的必须要要是一个数组,不然抛出异常
throw new Error(`需要配置权限,例如 v-permission="['getStatistics3,GET']"`);
}
const hasAuth = value.findIndex((i) => store.state.ruleNames.includes(i)) != -1;
console.log(hasAuth); // true
if (el && !hasAuth) {
el.parentNode && el.parentNode.removeChild(el); // 用父节点移除当前父节点的子节点
}
return hasAuth
};
export default {
install(app) {
app.directive("permission", {
mounted(el, binding) {
// console.log(el); // 拿到的是当前调用指令的标签元素
// console.log(binding); // 具体数据 binding.value 是你在页面传递过来的参数
hasPermission(binding.value, el);
},
});
},
};
2. 需要使用的父页面 index.vue
<!-- 图表渲染 用自定义指令实现后端权限匹配 显示隐藏 -->
<CheckEChart v-permission="['getStatistics3,GET']" />
实际截图
image.png二十七.如何动态计算一个盒子的高度
image.png二十八.修改浏览器滚动条的样式
/* 修改浏览器滚动条的样式 */
::-webkit-scrollbar {
width: 4px;
height: 6px;
}
::-webkit-scrollbar-corner {
display: block;
}
::-webkit-scrollbar-thumb {
border-radius: 8px;
background-color: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb,
::-webkit-scrollbar-track {
border-right-color: transparent;
border-left-color: transparent;
background-color: rgba(0, 0, 0, 0.1);
}
二十九.引入富文本
一 .安装两个包:
1. 1. npm i tinymce
1. 2. npm i @tinymce/tinymce-vue
二. 从node_modules/tinymce 拷贝样式文件到public 目录下
中文包zh-Hans.js下载地址: https://www.tiny.cloud/get-tiny/language-packges/
实际截图
image.png三.具体在页面中使用:
<template>
<editor v-model="content" tag-name="div" :init="init" />
</template>
<script setup>
import tinymce from "tinymce/tinymce";
import Editor from "@tinymce/tinymce-vue";
import { ref, watch } from "vue"
import "tinymce/themes/silver/theme"; // 引用主题文件
import "tinymce/icons/default"; // 引用图标文件
import 'tinymce/models/dom'
// tinymce插件可按自己的需要进行导入
// 更多插件参考:https://www.tiny.cloud/docs/plugins/
import "tinymce/plugins/advlist"
import "tinymce/plugins/anchor"
import "tinymce/plugins/autolink"
import "tinymce/plugins/autoresize"
import "tinymce/plugins/autosave"
import "tinymce/plugins/charmap" // 特殊字符
import "tinymce/plugins/code" // 查看源码
import "tinymce/plugins/codesample" // 插入代码
import "tinymce/plugins/directionality"
import "tinymce/plugins/emoticons"
import "tinymce/plugins/fullscreen" //全屏
import "tinymce/plugins/help"
import "tinymce/plugins/image" // 插入上传图片插件
import "tinymce/plugins/importcss" //图片工具
import "tinymce/plugins/insertdatetime" //时间插入
import "tinymce/plugins/link"
import "tinymce/plugins/lists" // 列表插件
import "tinymce/plugins/media" // 插入视频插件
import "tinymce/plugins/nonbreaking"
import "tinymce/plugins/pagebreak" //分页
import "tinymce/plugins/preview" // 预览
import "tinymce/plugins/quickbars"
import "tinymce/plugins/save" // 保存
import "tinymce/plugins/searchreplace" //查询替换
import "tinymce/plugins/table" // 插入表格插件
import "tinymce/plugins/template" //插入模板
import "tinymce/plugins/visualblocks"
import "tinymce/plugins/visualchars"
import "tinymce/plugins/wordcount" // 字数统计插件
// v-model
const props = defineProps({
modelValue: String,
})
const emit = defineEmits(["update:modelValue"])
// 配置
const init = {
language_url: '/tinymce/langs/zh-Hans.js', // 中文语言包路径
language: "zh-Hans",
skin_url: '/tinymce/skins/ui/oxide', // 编辑器皮肤样式
content_css: "/tinymce/skins/content/default/content.min.css",
menubar: false, // 隐藏菜单栏
autoresize_bottom_margin: 50,
max_height: 500,
min_height: 450,
// height: 320,
toolbar_mode: "none",
plugins:
'wordcount visualchars visualblocks template searchreplace save quickbars preview pagebreak nonbreaking media insertdatetime importcss image help fullscreen directionality codesample code charmap link code table lists advlist anchor autolink autoresize autosave',
toolbar:
"formats undo redo fontsizeselect fontselect ltr rtl searchreplace media | outdent indent aligncenter alignleft alignright alignjustify lineheight underline quicklink h2 h3 blockquote numlist bullist table removeformat forecolor backcolor bold italic strikethrough hr link preview fullscreen help ",
content_style: "p {margin: 5px 0; font-size: 14px}",
fontsize_formats: "12px 14px 16px 18px 24px 36px 48px 56px 72px",
font_formats: "微软雅黑=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif;苹果苹方= PingFang SC, Microsoft YaHei, sans- serif; 宋体 = simsun, serif; 仿宋体 = FangSong, serif; 黑体 = SimHei, sans - serif; Arial = arial, helvetica, sans - serif;Arial Black = arial black, avant garde;Book Antiqua = book antiqua, palatino; ",
branding: false,
elementpath: false,
resize: false, // 禁止改变大小
statusbar: false, // 隐藏底部状态栏
}
tinymce.init; // 初始化
const content = ref(props.modelValue)
watch(props, (newVal) => content.value = newVal.modelValue)
watch(content, (newVal) => emit("update:modelValue", newVal))
</script>
<style>
.tox-tinymce-aux {
z-index: 9999 !important;
}
</style>
image.png
三十. Vite 环境变量于模式
也就是配置前端打包上线的的环境
image.png