优化 cl-codemirror, cl-menu-file 等等

This commit is contained in:
icssoa 2021-03-30 14:48:17 +08:00
parent fff62f8333
commit 3e3bac2a6a
13 changed files with 181 additions and 132 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "front-next-vue3", "name": "front-next-vue3",
"version": "0.1.0", "version": "0.1.1",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",

View File

@ -1,11 +1,11 @@
<template> <template>
<div class="cl-codemirror"> <div class="cl-codemirror" ref="editorRef">
<textarea class="cl-code" id="editor" :height="height" :width="width"></textarea> <textarea class="cl-code" id="editor" :height="height" :width="width"></textarea>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, onMounted, watch } from "vue"; import { defineComponent, nextTick, onMounted, ref, watch } from "vue";
import CodeMirror from "codemirror"; import CodeMirror from "codemirror";
import beautifyJs from "js-beautify"; import beautifyJs from "js-beautify";
@ -28,6 +28,8 @@ export default defineComponent({
emits: ["update:modelValue", "load"], emits: ["update:modelValue", "load"],
setup(props, { emit }) { setup(props, { emit }) {
const editorRef = ref<any>(null);
let editor: any = null; let editor: any = null;
// //
@ -55,8 +57,9 @@ export default defineComponent({
); );
onMounted(function() { onMounted(function() {
nextTick(() => {
// //
editor = CodeMirror.fromTextArea(document.getElementById("editor"), { editor = CodeMirror.fromTextArea(editorRef.value.querySelector("#editor"), {
mode: "javascript", mode: "javascript",
theme: "ambiance", theme: "ambiance",
styleActiveLine: true, styleActiveLine: true,
@ -71,27 +74,17 @@ export default defineComponent({
emit("update:modelValue", e.getValue().replace(/\s/g, "")); emit("update:modelValue", e.getValue().replace(/\s/g, ""));
}); });
//
emit("load", editor);
//
const el = editor.display.wrapper;
if (el) {
if (props.height) {
el.style.height = props.height || "50px";
}
if (props.width) {
el.style.width = props.width;
}
}
// //
setValue(props.modelValue); setValue(props.modelValue);
//
emit("load", editor);
//
editor.setSize(props.width || "auto", props.height || "auto");
// shift + alt + f // shift + alt + f
el.onkeydown = (e: any) => { editor.display.wrapper.onkeydown = (e: any) => {
const keyCode = e.keyCode || e.which || e.charCode; const keyCode = e.keyCode || e.which || e.charCode;
const altKey = e.altKey || e.metaKey; const altKey = e.altKey || e.metaKey;
const shiftKey = e.shiftKey || e.metaKey; const shiftKey = e.shiftKey || e.metaKey;
@ -101,6 +94,11 @@ export default defineComponent({
} }
}; };
}); });
});
return {
editorRef
};
} }
}); });
</script> </script>

View File

@ -391,10 +391,6 @@ export default defineComponent({
} }
} }
:deep(.el-tree-node__content) {
height: 36px;
}
&__op { &__op {
display: flex; display: flex;
@ -419,6 +415,7 @@ export default defineComponent({
overflow-x: hidden; overflow-x: hidden;
:deep(.el-tree-node__content) { :deep(.el-tree-node__content) {
height: 36px;
margin: 0 5px; margin: 0 5px;
} }
} }

View File

@ -56,11 +56,15 @@ export default defineComponent({
// //
function onUploadSpaceConfirm(files: any[]) { function onUploadSpaceConfirm(files: any[]) {
if (files.length > 0) { if (files.length > 0) {
//
files.forEach((file, i) => { files.forEach((file, i) => {
const [type] = file.type.split("/"); const [type] = file.type.split("/");
quill.insertEmbed(cursorIndex.value + i, type, file.url, Quill.sources.USER); quill.insertEmbed(cursorIndex.value + i, type, file.url, Quill.sources.USER);
}); });
//
quill.setSelection(cursorIndex.value + files.length);
} }
} }

View File

@ -15,10 +15,19 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref, watch } from "vue"; import { defineComponent, ref, watch } from "vue";
//
function findFiles() {
const files = require const files = require
.context("@/", true, /views\/(?!(components)|(.*\/components)|(index\.js)).*.(js|vue)/) .context("@/", true, /views\/(?!(components)|(.*\/components)|(index\.js)).*.(js|vue)/)
.keys(); .keys();
return files.map(e => {
return {
value: e.substr(2)
};
});
}
export default defineComponent({ export default defineComponent({
name: "cl-menu-file", name: "cl-menu-file",
@ -36,7 +45,7 @@ export default defineComponent({
const path = ref<string>(props.modelValue); const path = ref<string>(props.modelValue);
// //
const list = ref<any[]>([]); const list = ref<any[]>(findFiles());
watch( watch(
() => props.modelValue, () => props.modelValue,
@ -49,12 +58,6 @@ export default defineComponent({
emit("update:modelValue", val); emit("update:modelValue", val);
}); });
list.value = files.map(e => {
return {
value: e.substr(2)
};
});
return { return {
path, path,
list list

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="app-topbar-menu"> <div class="cl-menu-topbar">
<el-menu <el-menu
:default-active="index" :default-active="index"
mode="horizontal" mode="horizontal"
@ -84,7 +84,7 @@ export default defineComponent({
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.app-topbar-menu { .cl-menu-topbar {
margin-right: 10px; margin-right: 10px;
:deep(.el-menu) { :deep(.el-menu) {

View File

@ -51,7 +51,7 @@ export default {
font-size: 20px; font-size: 20px;
} }
:deep(.el-badge) { .el-badge {
transform: scale(0.8); transform: scale(0.8);
} }
} }

View File

@ -776,12 +776,12 @@ export default {
<style lang="scss" scoped> <style lang="scss" scoped>
.vue-cron { .vue-cron {
:deep(.el-tabs) { .el-tabs {
box-shadow: none; box-shadow: none;
} }
&__item { &__item {
:deep(.el-row) { .el-row {
min-height: 32px; min-height: 32px;
line-height: 32px; line-height: 32px;
margin-bottom: 10px; margin-bottom: 10px;

View File

@ -108,8 +108,7 @@
<script> <script>
import { mapGetters } from "vuex"; import { mapGetters } from "vuex";
import path from "path"; import { last, isArray, isNumber, isBoolean, basename } from "@/core/utils";
import { last, isArray, isNumber, isBoolean } from "@/core/utils";
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
import { clone } from "@/core/utils"; import { clone } from "@/core/utils";
@ -344,7 +343,7 @@ export default {
this.fileList = list.filter(Boolean).map(url => { this.fileList = list.filter(Boolean).map(url => {
return { return {
url, url,
name: path.basename(url), name: basename(url),
uid: url uid: url
}; };
}); });
@ -543,7 +542,7 @@ export default {
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss">
.cl-upload { .cl-upload {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
@ -561,7 +560,7 @@ export default {
&--default { &--default {
&:not(.is-drag) { &:not(.is-drag) {
:deep(.el-upload) { .el-upload {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
@ -640,7 +639,7 @@ export default {
} }
&--picture-card { &--picture-card {
:deep(.el-upload) { .el-upload {
background-color: #fff; background-color: #fff;
.cl-upload__icon { .cl-upload__icon {

View File

@ -289,4 +289,13 @@ export function revDeepTree(list: Array<any> = []) {
return d; return d;
} }
export function basename(path: string) {
let index = path.lastIndexOf("/");
index = index > -1 ? index : path.lastIndexOf("\\");
if (index < 0) {
return path;
}
return path.substring(index + 1);
}
export { storage }; export { storage };

View File

@ -11,20 +11,35 @@
</div> </div>
</template> </template>
<script> <script lang="ts">
import { mapGetters } from "vuex"; import { computed, defineComponent } from "vue-demi";
import { useStore } from "vuex";
export default { export default defineComponent({
computed: { setup() {
...mapGetters(["menuCollapse", "browser", "app"]) const store = useStore();
},
methods: { //
toHome() { const menuCollapse = computed<any>(() => store.getters.menuCollapse);
//
const browser = computed<any>(() => store.getters.browser);
//
const app = computed<any>(() => store.getters.app);
//
function toHome() {
location.href = "https://cool-js.com/"; location.href = "https://cool-js.com/";
} }
} return {
menuCollapse,
browser,
app,
toHome
}; };
}
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -48,34 +48,58 @@
</div> </div>
</template> </template>
<script> <script lang="ts">
import { mapGetters } from "vuex"; import { computed, defineComponent } from "vue";
import { useRouter } from "vue-router";
import { useStore } from "vuex";
import { href } from "@/core/utils"; import { href } from "@/core/utils";
export default { export default defineComponent({
computed: { setup() {
...mapGetters(["userInfo", "menuCollapse", "app", "modules"]) const store = useStore();
}, const router = useRouter();
methods: { //
onCommand(name) { const menuCollapse = computed<any>(() => store.getters.menuCollapse);
//
const modules = computed<any>(() => store.getters.modules);
//
const app = computed<any>(() => store.getters.app);
//
const userInfo = computed<any>(() => store.getters.userInfo);
//
function onCommand(name: string) {
switch (name) { switch (name) {
case "my": case "my":
this.$router.push("/my/info"); router.push("/my/info");
break; break;
case "exit": case "exit":
this.$store.dispatch("userLogout").done(() => { store.dispatch("userLogout").done(() => {
href("/login"); href("/login");
}); });
break; break;
} }
}, }
collapse() { //
this.$store.commit("COLLAPSE_MENU", !this.menuCollapse); function collapse() {
} store.commit("COLLAPSE_MENU", !menuCollapse.value);
} }
return {
userInfo,
menuCollapse,
modules,
app,
onCommand,
collapse
}; };
}
});
</script> </script>
<style lang="scss"> <style lang="scss">

72
src/shims-vue.d.ts vendored
View File

@ -1,77 +1,77 @@
/* eslint-disable */ /* eslint-disable */
declare module '*.vue' { declare module '*.vue' {
import type { DefineComponent } from 'vue' import type { DefineComponent } from 'vue';
const component: DefineComponent<{}, {}, any> const component: DefineComponent<{}, {}, any>;
export default component export default component;
} }
declare module 'array.prototype.flat' { declare module 'array.prototype.flat' {
function Flat(list: any[]): any[] function Flat(list: any[]): any[];
export default Flat export default Flat;
} }
declare module 'clone-deep' { declare module 'clone-deep' {
function CloneDeep(data: any): any function CloneDeep(data: any): any;
export default CloneDeep export default CloneDeep;
} }
declare module '@/core' { declare module '@/core' {
export function bootstrap(app: any): Promise<void> export function bootstrap(app: any): Promise<void>;
export class BaseService { export class BaseService {
namespace: string namespace: string
request: Function request: Function
} }
export function Service(val: any) export function Service(val: any): any;
export function Permission(val: string) export function Permission(val: string): any;
export function useRefs() export function useRefs(): any;
} }
declare module '@/crud' { declare module '@/crud' {
export const ContextMenu export const ContextMenu: any;
} }
declare module '@/store' { declare module '@/store' {
import { Store } from 'vuex/types/index.d.ts' import { Store } from 'vuex/types/index.d.ts';
export const $service export const $service;
export default Store export default Store;
} }
declare module 'store' { declare module 'store' {
export function set(key: string, value: any) export function set(key: string, value: any): void;
export function get(key: string) export function get(key: string): any;
export function remove(key: string) export function remove(key: string): void;
export function clearAll() export function clearAll(): void;
export function each(callback: Function) export function each(callback: Function): void;
} }
declare module 'quill' { declare module 'quill' {
const Quill: any = {} const Quill: any;
export default Quill export default Quill;
} }
declare module 'codemirror' { declare module 'codemirror' {
export function fromTextArea(el: any, options?: any) {} export function fromTextArea(el: any, options?: any): any;
} }
declare module 'js-beautify' { declare module 'js-beautify' {
export default function(text: string) {} export default function(text: string): string;
} }
declare module 'nprogress' { declare module 'nprogress' {
export function configure(options: any) {} export function configure(options: any): void;
export const start = () => {} export function start(): void;
export const done = () => {} export function done(): void;
} }
declare module 'mockjs' { declare module 'mockjs' {
const Mock: any = {} const Mock: any;
export default Mock export default Mock;
} }
declare module '@/router' { declare module '@/router' {
const Router: any = { const Router: any = {
$plugin: { $plugin: {
addViews: (list: any[], options?:any) => {} addViews(list: any[], options?:any) {}
} }
} }
@ -79,16 +79,16 @@ declare module '@/router' {
token: string[] token: string[]
} }
export default Router export default Router;
export const ignore: Ignore export const ignore: Ignore;
} }
declare module '@/assets/css/common.scss' { declare module '@/assets/css/common.scss' {
export const colorPrimary: string export const colorPrimary: string;
} }
interface Promise { interface Promise {
then: Function, then(cb: Function): Promise<any>;
catch: Function, catch(cb: Function): Promise<any>;
done: Function done(cb: Function): void;
} }