This commit is contained in:
icssoa 2023-01-03 16:01:44 +08:00
parent 091f09ef2b
commit 7783fb5962
17 changed files with 373 additions and 202 deletions

View File

@ -1,6 +1,6 @@
{
"name": "front-next",
"version": "5.12.0",
"version": "5.12.1",
"scripts": {
"dev": "vite --host",
"build": "vite build",

View File

@ -1,4 +1,3 @@
// @ts-nocheck
import { Module } from "../types";
import { Data } from "../utils";
@ -10,6 +9,7 @@ const module = {
list,
req: Promise.resolve(),
get(name: string): Module {
// @ts-ignore
return this.list.find((e) => e.name == name);
},
add(data: Module) {

View File

@ -1,4 +1,3 @@
// @ts-nocheck
const d: any = window;
// window 数据临时存储,解决热更新后失效问题

View File

@ -4,7 +4,7 @@
ref="Editor"
v-model="content"
:placeholder="placeholder"
:style="{ height, fontSize }"
:style="style"
autofocus
:disabled="disabled"
indent-with-tab
@ -21,16 +21,17 @@ import { javascript } from "@codemirror/lang-javascript";
import { oneDark } from "@codemirror/theme-one-dark";
import { ref, watch, computed, defineComponent } from "vue";
import { useDark } from "@vueuse/core";
import { isNumber } from "lodash-es";
import { useComm } from "/@/cool";
export default defineComponent({
name: "cl-codemirror",
components: {
Codemirror
},
props: {
modelValue: {
type: String,
required: true
},
modelValue: String,
placeholder: {
type: String,
default: "请输入"
@ -40,29 +41,22 @@ export default defineComponent({
default: 400
},
fontSize: {
type: String,
default: "14px"
type: [String, Number],
default: 14
},
disabled: Boolean
},
emits: ["update:modelValue", "change"],
components: {
Codemirror
},
setup(props, { emit }) {
const { px } = useComm();
const Editor = ref();
//
const isDark = ref(useDark());
//
const height = computed(() =>
isNumber(props.height) ? `${props.height}px` : props.height
);
//
const extensions: any[] = [javascript()];
@ -73,6 +67,11 @@ export default defineComponent({
//
const content = ref("");
//
const style = computed(() => {
return { height: px(props.height), fontSize: px(props.fontSize) };
});
//
function onChange(value: string) {
emit("update:modelValue", value);
@ -83,7 +82,7 @@ export default defineComponent({
watch(
() => props.modelValue,
(val) => {
content.value = val;
content.value = val || "";
},
{
immediate: true
@ -93,7 +92,7 @@ export default defineComponent({
return {
Editor,
isDark,
height,
style,
content,
extensions,
onChange

View File

@ -1,10 +1,11 @@
<template>
<el-select v-model="value" @change="onChange" clearable>
<el-select v-model="value" :clearable="clearable" @change="onChange">
<el-option
v-for="(item, index) in list"
:key="index"
:label="item.label"
:value="item.value"
:disabled="item.disabled"
></el-option>
</el-select>
</template>
@ -22,6 +23,10 @@ export default defineComponent({
type: [Array, Object],
default: () => []
},
clearable: {
type: Boolean,
default: true
},
prop: String
},
@ -30,7 +35,11 @@ export default defineComponent({
setup(props, { emit }) {
// cl-crud
const Crud = useCrud();
//
const value = ref();
//
const list = computed<any>(() =>
isRef(props.options) ? props.options.value : props.options
);

View File

@ -3,20 +3,6 @@ import { ref } from "vue";
import { storage } from "/@/cool/utils";
import { service, config, router } from "/@/cool";
interface User {
id: number;
name: string;
username: string;
nickName: string;
phone: string;
headImg: string;
email: string;
status: 0 | 1;
departmentId: string;
createTime: Date;
[key: string]: any;
}
// 本地缓存
const data = storage.info();
@ -27,9 +13,9 @@ export const useUserStore = defineStore("user", function () {
// 设置标识
function setToken(data: {
token: string;
expire: string;
expire: number;
refreshToken: string;
refreshExpire: string;
refreshExpire: number;
}) {
// 请求的唯一标识
token.value = data.token;
@ -58,7 +44,7 @@ export const useUserStore = defineStore("user", function () {
}
// 用户信息
const info = ref<User | null>(data.userInfo);
const info = ref<Eps.BaseSysUserEntity | null>(data.userInfo);
// 设置用户信息
function set(value: any) {

View File

@ -63,7 +63,7 @@
<ul>
<cl-upload @success="onImageSend" :show-file-list="false">
<li>
<el-icon><picture /></el-icon>
<el-icon><picture-filled /></el-icon>
</li>
</cl-upload>
@ -101,7 +101,7 @@
import { computed, ref } from "vue";
import { useChat } from "../hooks";
import { useStore } from "../store";
import { Picture, VideoCamera, Microphone } from "@element-plus/icons-vue";
import { PictureFilled, VideoCamera, Microphone } from "@element-plus/icons-vue";
import { useBase } from "/$/base";
import { ContextMenu } from "@cool-vue/crud";
import { useClipboard } from "@vueuse/core";

View File

@ -1,6 +1,6 @@
<template>
<div class="editor">
<el-tabs>
<el-tabs type="card">
<el-tab-pane label="WangEditor">
<cl-editor-wang v-model="w" :height="400" />
</el-tab-pane>
@ -20,7 +20,9 @@ const w = ref("Wang");
<style lang="scss" scoped>
.editor {
background-color: #fff;
padding: 0 10px 10px 10px;
background-color: var(--el-bg-color);
padding: 10px;
height: 100%;
box-sizing: border-box;
}
</style>

View File

@ -1,74 +1,67 @@
<template>
<div class="demo">
<el-image
v-for="(item, index) in list"
:key="index"
:src="item"
:style="{ width: '100px', marginRight: '10px' }"
/>
<el-tabs type="card">
<el-tab-pane label="普通上传">
<cl-upload v-model="urls" />
</el-tab-pane>
<div class="item">
<p>普通上传</p>
<cl-upload v-model="urls" />
</div>
<el-tab-pane label="多图上传" lazy>
<cl-upload text="选择图片" v-model="urls" multiple drag />
</el-tab-pane>
<div class="item">
<p>多图上传 multiple</p>
<cl-upload v-model="urls" multiple drag />
</div>
<el-tab-pane label="文件上传" lazy>
<cl-upload v-model="urls" multiple text="文件上传" type="file" />
</el-tab-pane>
<div class="item">
<p>文件上传 file</p>
<cl-upload v-model="urls" multiple text="文件上传" type="file" />
</div>
<el-tab-pane label="自定义内容">
<cl-upload text="选择图片" multiple drag custom-class="custom-upload">
<el-button :icon="Upload">上传</el-button>
<div class="item">
<p>自定义内容</p>
<cl-upload text="选择图片" multiple drag>
<div style="width: 100%">
<el-button>上传</el-button>
</div>
<template #item="{ item }">
<div class="cs-item">{{ item.url }}</div>
</template>
</cl-upload>
</div>
<template #item="{ item }">
<div class="item" v-show="item.url">{{ item.url }}</div>
</template>
</cl-upload>
</el-tab-pane>
<div class="item">
<p>自定义大小</p>
<cl-upload text="选择图片" :size="[120, 200]" />
</div>
<el-tab-pane label="自定义大小">
<cl-upload text="选择图片" :size="[120, 200]" />
</el-tab-pane>
<div class="item">
<p>文件空间</p>
<cl-upload-space />
</div>
<el-tab-pane label="文件空间">
<cl-upload-space />
</el-tab-pane>
</el-tabs>
</div>
</template>
<script lang="ts" name="upload" setup>
import { computed, ref } from "vue";
import { ref } from "vue";
import { Upload } from "@element-plus/icons-vue";
const urls = ref("");
const list = computed(() => urls.value.split(",").filter(Boolean));
</script>
<style lang="scss" scoped>
.demo {
background-color: var(--el-bg-color);
.item {
margin-bottom: 10px;
padding: 10px;
padding: 10px;
height: 100%;
box-sizing: border-box;
& > p {
margin-bottom: 10px;
font-size: 14px;
:deep(.custom-upload) {
.item {
border: 1px solid var(--el-border-color);
border-radius: 3px;
padding: 5px 10px;
margin-top: 10px;
font-size: 12px;
width: 100%;
box-sizing: border-box;
}
}
.cs-item {
border: 1px solid var(--el-border-color);
padding: 5px 10px;
.cl-upload__list {
width: 100%;
}
}
}
</style>

View File

@ -1,12 +1,11 @@
<template>
<div class="cl-upload__wrap">
<div class="cl-upload__wrap" :class="[customClass]">
<div
class="cl-upload"
:class="[
`cl-upload--${type}`,
{
'is-slot': $slots.default,
'is-custom': $slots.item,
'is-disabled': disabled
}
]"
@ -42,11 +41,11 @@
<!-- 列表 -->
<draggable
class="cl-upload__list"
tag="div"
v-model="list"
v-bind="drag.options"
item-key="uid"
tag="div"
class="cl-upload__list"
@end="update"
>
<template #item="{ element: item, index }">
@ -153,14 +152,7 @@ import { extname, uuid } from "/@/cool/utils";
import { useBase } from "/$/base";
import { fileSize, fileName, fileType } from "../utils";
import { useForm } from "@cool-vue/crud";
interface Item {
url: string;
preload: string;
uid: number | string;
progress: number;
type?: string;
}
import { Upload } from "../types";
const props = defineProps({
modelValue: {
@ -187,6 +179,7 @@ const props = defineProps({
},
drag: Boolean,
disabled: Boolean,
customClass: String,
// 穿
isEdit: null,
@ -237,14 +230,14 @@ const headers = computed(() => {
});
//
const pv = reactive<any>({
const pv = reactive<{ visible: boolean; urls: string[]; index: number }>({
visible: false,
urls: [],
index: 0
});
//
const list = ref<Item[]>([]);
const list = ref<Upload.Item[]>([]);
//
const drag = reactive<any>({
@ -273,12 +266,12 @@ function getType(path: string) {
if (props.type == "image") {
return "image";
} else {
return fileType(path).value;
return fileType(path)?.value;
}
}
//
function beforeUpload(file: any, item?: Item) {
function beforeUpload(file: any, item?: Upload.Item) {
if (file.size / 1024 / 1024 >= limitSize) {
ElMessage.error(`上传文件大小不能超过 ${limitSize}MB!`);
return false;
@ -321,7 +314,7 @@ function clear() {
}
//
function preview(item: Item) {
function preview(item: Upload.Item) {
if (item.type == "image") {
pv.visible = true;
pv.urls = list.value.map((e) => e.preload);

View File

@ -7,7 +7,7 @@
<!-- 弹框 -->
<cl-dialog
v-model="visible"
title="文件空间"
:title="title"
height="650px"
width="1080px"
keep-alive
@ -25,7 +25,7 @@
@drop="onDrop"
>
<!-- 类目 -->
<category />
<space-category />
<!-- 内容 -->
<div class="cl-upload-space__content">
@ -49,6 +49,8 @@
</cl-upload>
</div>
<cl-flex1 />
<el-button type="success" :disabled="!isSelected" @click="confirm()"
>使用选中文件 {{ selection.length }}/{{ limit }}</el-button
>
@ -72,7 +74,12 @@
v-for="item in list"
:key="item.preload || item.url"
>
<file-item :data="item" @select="select" @remove="remove" />
<space-file
:data="item"
:list="list"
@select="select"
@remove="remove"
/>
</div>
</div>
</template>
@ -104,19 +111,19 @@
</template>
<script lang="ts" setup name="cl-upload-space">
import { computed, onMounted, provide, reactive, ref, watch } from "vue";
import { computed, provide, reactive, ref, watch } from "vue";
import { isEmpty } from "lodash-es";
import { ElMessage, ElMessageBox } from "element-plus";
import { Notebook, ArrowLeft, UploadFilled } from "@element-plus/icons-vue";
import { module, useCool } from "/@/cool";
import { useBase } from "/$/base";
import Category from "./space/category.vue";
import FileItem from "./space/file-item.vue";
import SpaceCategory from "./space/category.vue";
import SpaceFile from "./space/file.vue";
const props = defineProps({
//
modelValue: String,
//
//
limit: Number,
//
disabled: Boolean,
@ -126,6 +133,11 @@ const props = defineProps({
showBtn: {
type: Boolean,
default: true
},
//
title: {
type: String,
default: "文件空间"
}
});
@ -152,10 +164,10 @@ const visible = ref(false);
const loading = ref(false);
//
const selection = ref<any[]>([]);
const selection = ref<Eps.SpaceInfoEntity[]>([]);
//
const list = ref<any[]>([]);
const list = ref<Eps.SpaceInfoEntity[]>([]);
//
const category = reactive({
@ -185,8 +197,15 @@ watch(
const isSelected = computed(() => !isEmpty(selection.value));
//
let lock = false;
function open() {
visible.value = true;
if (!lock) {
lock = true;
refresh();
}
}
//
@ -259,15 +278,15 @@ async function refresh(params: any = {}) {
//
function confirm() {
emit("update:modelValue", selection.value.map((e: any) => e.url).join(","));
emit("update:modelValue", selection.value.map((e) => e.url).join(","));
emit("confirm", selection.value);
close();
}
//
function select(item: any) {
const index = selection.value.findIndex((e: any) => e.id === item.id);
function select(item: Eps.SpaceInfoEntity) {
const index = selection.value.findIndex((e) => e.id === item.id);
if (index >= 0) {
selection.value.splice(index, 1);
@ -279,9 +298,9 @@ function select(item: any) {
}
//
function remove(item?: any) {
function remove(item?: Eps.SpaceInfoEntity) {
// id
const ids: number[] = item ? [item.id] : selection.value.map((e: any) => e.id);
const ids = item ? [item.id] : selection.value.map((e) => e.id);
ElMessageBox.confirm("此操作将删除文件, 是否继续?", "提示", {
type: "warning"
@ -292,7 +311,7 @@ function remove(item?: any) {
//
ids.forEach((id) => {
[list.value, selection.value].forEach((list) => {
const index = list.findIndex((e: any) => e.id === id);
const index = list.findIndex((e) => e.id === id);
list.splice(index, 1);
});
});
@ -337,11 +356,8 @@ provide("space", {
category,
selection,
refresh,
loading
});
onMounted(() => {
refresh();
loading,
list
});
defineExpose({
@ -359,6 +375,7 @@ defineExpose({
box-sizing: border-box;
background-color: #f7f7f7;
padding: 5px;
user-select: none;
&__dialog {
.el-dialog__body {

View File

@ -7,7 +7,7 @@
}"
>
<div class="cl-upload-space-category__search">
<el-input v-model="keyword" placeholder="搜索" clearable />
<el-input v-model="keyword" placeholder="搜索分类" clearable />
<el-button type="success" @click="edit()">添加</el-button>
</div>
@ -39,32 +39,29 @@
<cl-form ref="Form" />
</template>
<script lang="ts" setup>
<script lang="ts" setup name="space-category">
import { ElMessage, ElMessageBox } from "element-plus";
import { ArrowRightBold } from "@element-plus/icons-vue";
import { computed, inject, onMounted, ref } from "vue";
import { computed, onMounted, ref } from "vue";
import { isEmpty } from "lodash-es";
import { useCool } from "/@/cool";
import { ContextMenu, useForm } from "@cool-vue/crud";
import { useBase } from "/$/base";
import { useSpace } from "../../hooks";
const { service } = useCool();
//
const { app } = useBase();
//
const space = inject<any>("space");
const { space } = useSpace();
//
const list = ref<any[]>([]);
const list = ref<Eps.SpaceTypeEntity[]>([]);
//
const keyword = ref<string>("");
const keyword = ref("");
//
const flist = computed(() => {
return list.value.filter((e: any) => e.name.includes(keyword.value));
return list.value.filter((e) => (e.name || "").includes(keyword.value));
});
//
@ -72,13 +69,13 @@ async function refresh() {
return service.space.type.list().then((res) => {
res.unshift({
name: "全部文件",
id: null
id: undefined
});
list.value = res;
if (!isEmpty(res)) {
if (!space.category.id) {
if (!space.category.id && res[0].id) {
space.category.id = res[0].id;
}
}
@ -88,7 +85,7 @@ async function refresh() {
const Form = useForm();
//
function edit(item: any = {}) {
function edit(item: Eps.SpaceTypeEntity = {}) {
Form.value?.open({
title: "添加分类",
width: "400px",
@ -132,7 +129,7 @@ function edit(item: any = {}) {
}
//
function select(id: number) {
function select(id?: number) {
//
if (app.browser.isMini) {
space.category.visible = false;
@ -183,7 +180,7 @@ function onContextMenu(e: any, { id, name }: any) {
//
if (id == space.category.id) {
space.category.id = null;
space.category.id = undefined;
}
refresh();

View File

@ -24,6 +24,11 @@
</el-image>
</template>
<!-- 视频 -->
<template v-else-if="info.type === 'video'">
<item-video :data="info" :list="list" />
</template>
<!-- 其他 -->
<template v-else>
<!-- 文件名 -->
@ -36,18 +41,21 @@
<span
class="cl-upload-space-file__type"
:style="{
backgroundColor: type.color
backgroundColor: type?.color
}"
>{{ type.label }}</span
>{{ type?.label }}</span
>
<!-- 进度条 -->
<div
class="cl-upload-space-file__progress"
v-if="info.progress > 0 && info.progress < 100"
>
<el-progress :percentage="info.progress" :show-text="false"></el-progress>
</div>
<!-- 上传中 -->
<template v-if="info.progress > 0 && info.progress < 100">
<!-- 进度条 -->
<div class="cl-upload-space-file__progress-bar">
<el-progress :percentage="info.progress" :show-text="false"></el-progress>
</div>
<!-- 进度值 -->
<span class="cl-upload-space-file__progress-value">{{ info.progress }}</span>
</template>
</template>
<!-- 遮罩层 -->
@ -58,30 +66,32 @@
</div>
</template>
<script lang="ts" setup>
import { computed, inject } from "vue";
<script lang="ts" setup name="space-file">
import { computed } from "vue";
import { ContextMenu } from "@cool-vue/crud";
import { extname } from "/@/cool/utils";
import { fileName, fileType } from "../../utils";
import { fileName, fileRule } from "../../utils";
import { useClipboard } from "@vueuse/core";
import { ElMessage } from "element-plus";
import { useSpace } from "../../hooks";
import ItemVideo from "./item-video.vue";
const { copy } = useClipboard();
const props = defineProps({
data: Object
data: Object,
list: Array
});
const emit = defineEmits(["select", "remove"]);
//
const space = inject<any>("space");
const { space } = useSpace();
//
const info = computed(() => props.data || {});
const info = computed<Eps.SpaceInfoEntity>(() => props.data || {});
//
const index = computed(() => space.selection.value.findIndex((e: any) => e.id === info.value.id));
const index = computed(() => space.selection.value.findIndex((e) => e.id === info.value.id));
//
const isSelected = computed(() => index.value >= 0);
@ -90,7 +100,7 @@ const isSelected = computed(() => index.value >= 0);
const url = computed(() => info.value.preload || info.value.url);
//
const type = computed(() => fileType(info.value.url));
const type = computed(() => fileRule(info.value.type));
//
function select() {
@ -119,8 +129,11 @@ function onContextMenu(e: any) {
{
label: "复制地址",
callback(done) {
copy(info.value.url);
ElMessage.success("复制成功");
if (info.value.url) {
copy(info.value.url);
ElMessage.success("复制成功");
}
done();
}
},
@ -187,7 +200,11 @@ function onContextMenu(e: any) {
}
}
&:not(.is-image) {
&.is-video {
padding: 0;
}
&:not(.is-image):not(.is-video) {
padding: 10px;
.cl-upload-space-file {
@ -223,10 +240,22 @@ function onContextMenu(e: any) {
}
&__progress {
position: absolute;
bottom: 10px;
left: 10px;
width: calc(100% - 20px);
&-bar {
position: absolute;
bottom: 10px;
left: 10px;
width: calc(100% - 20px);
}
&-value {
position: absolute;
font-size: 26px;
&::after {
content: "%";
margin-left: 2px;
}
}
}
&__type {

View File

@ -0,0 +1,108 @@
<template>
<div class="item-video">
<video ref="Video" :src="info.url" />
<template v-if="loaded">
<el-icon class="icon is-pause" @click.stop="pause" v-if="info.isPlay">
<video-pause />
</el-icon>
<el-icon class="icon is-play" @click.stop="play" v-else>
<video-play />
</el-icon>
</template>
</div>
</template>
<script lang="ts" setup name="item-video">
import { computed, ref, watch } from "vue";
import { VideoPlay, VideoPause } from "@element-plus/icons-vue";
import { useSpace } from "../../hooks";
const props = defineProps({
data: Object,
list: Array
});
const { space } = useSpace();
const info = computed<Eps.SpaceInfoEntity>(() => props.data || {});
const Video = ref<HTMLVideoElement>();
const loaded = computed(() => {
return info.value.progress === undefined || info.value.progress === 100;
});
function play() {
space.list.value.forEach((e) => {
e.isPlay = info.value.id == e.id;
});
Video.value?.play();
}
function pause() {
const item = space.list.value.find((e) => e.id == info.value.id);
if (item) {
item.isPlay = false;
}
Video.value?.pause();
}
watch(
() => info.value.isPlay,
(val) => {
if (val) {
play();
} else {
pause();
}
}
);
defineExpose({
play,
pause
});
</script>
<style lang="scss" scoped>
.item-video {
height: 100%;
width: 100%;
position: relative;
video {
height: 100%;
width: 100%;
}
.icon {
display: none;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
cursor: pointer;
font-size: 30px;
filter: drop-shadow(2px 2px 2px rgba(0, 0, 0, 0.25));
color: #fff;
&:hover {
color: #eee;
opacity: 1;
}
}
&:hover {
.icon {
display: inline-block;
}
}
}
</style>

View File

@ -0,0 +1,8 @@
import { inject } from "vue";
import { Upload } from "../types";
export function useSpace() {
const space = inject("space") as Upload.Space;
return { space };
}

22
src/modules/upload/types/index.d.ts vendored Normal file
View File

@ -0,0 +1,22 @@
import { Ref } from "vue";
export declare namespace Upload {
interface Item {
url: string;
preload: string;
uid: number | string;
progress: number;
type?: string;
}
interface Space {
category: {
id: number | undefined;
visible: boolean;
};
list: Ref<Eps.SpaceInfoEntity[]>;
selection: Ref<Eps.SpaceInfoEntity[]>;
refresh(params: any): Promise<any>;
loading: boolean;
}
}

View File

@ -1,5 +1,34 @@
import { last } from "lodash-es";
import { filename, extname } from "/@/cool/utils";
// 文件规则
const fileRules = [
{
label: "图片",
value: "image",
format: ["bmp", "jpg", "jpeg", "png", "tif", "gif", "svg", "webp"],
color: "#67C23A"
},
{
label: "视频",
value: "video",
format: ["avi", "wmv", "mpg", "mpeg", "mov", "rm", "ram", "swf", "flv", "mp4"],
color: "#409EFF"
},
{
label: "音频",
value: "audio",
format: ["mp3", "wav", "wma", "mp2", "flac", "midi", "ra", "ape", "aac", "cda"],
color: "#E6A23C"
},
{
label: "文件",
value: "file",
format: [],
color: "#909399"
}
];
// 文件大小
export function fileSize(size: number): string {
if (!size) return "";
@ -18,36 +47,16 @@ export function fileName(url: string) {
return filename(url.substring(url.indexOf("_") + 1));
}
// 文件类型
// 类型信息
export function fileType(path: string) {
const fs = [
{
label: "图片",
value: "image",
format: ["bmp", "jpg", "jpeg", "png", "tif", "gif", "svg", "webp"],
color: "#67C23A"
},
{
label: "视频",
value: "video",
format: ["avi", "wmv", "mpg", "mpeg", "mov", "rm", "ram", "swf", "flv", "mp4"],
color: "#409EFF"
},
{
label: "音频",
value: "audio",
format: ["mp3", "wav", "wma", "mp2", "flac", "midi", "ra", "ape", "aac", "cda"],
color: "#E6A23C"
}
];
const d = fileRules.find((e) => {
return e.format.find((a) => a == extname(path).toLocaleLowerCase());
});
return (
fs.find((e) => {
return e.format.find((a) => a == extname(path).toLocaleLowerCase());
}) || {
label: "文件",
value: "file",
color: "#909399"
}
);
return d || last(fileRules);
}
// 规则信息
export function fileRule(value: string) {
return fileRules.find((e) => e.value == value);
}