忘了写到哪了

This commit is contained in:
quantulr
2022-08-30 10:36:30 +08:00
parent 1d2f37bfe1
commit 9e00dce03c
44 changed files with 5136 additions and 304 deletions

View File

@ -80,7 +80,7 @@ const dialogImageUrl = ref("");
const dialogVisible = ref(false);
const baseUrl = import.meta.env.VITE_APP_BASE_API;
const uploadImgUrl = ref(import.meta.env.VITE_APP_BASE_API + "/common/upload"); // 上传的图片服务器地址
const headers = ref({ Authorization: "Bearer " + getToken() });
const headers = ref({ 'client-token': "Bearer " + getToken() });
const fileList = ref([]);
const showTip = computed(
() => props.isShowTip && (props.fileType || props.fileSize)

View File

@ -0,0 +1,345 @@
<template>
<div>
<el-upload
:headers="headers"
:action="videoUploadUrl"
list-type="picture-card"
:on-success="handleSuccess"
:on-error="handleUploadError"
:before-upload="handleBeforeUpload"
:file-list="fileList"
:on-progress="handleProgress"
:data="data"
accept="video/mp4"
:class="{ hide: fileList.length >= limit }"
>
<!-- accept="video/mp4, video/ogg, video/flv,video/avi,video/wmv,video/rmvb" -->
<!-- :disabled="fileList.length >= limit || uploadBtn" -->
<template #default>
<el-icon><Plus /></el-icon>
</template>
<template #file="{ file }">
<div style="height: 100%">
<video
class="el-upload-list__item-thumbnail"
:src="file.url"
alt=""
></video>
<span class="el-upload-list__item-actions">
<span
class="el-upload-list__item-preview"
@click="handleShowVideo(file)"
>
<el-icon><video-play /></el-icon>
</span>
<!-- <span
class="el-upload-list__item-edit"
@click="handleEditVideo(file)"
>
<el-icon><Edit /></el-icon>
</span> -->
<span
class="el-upload-list__item-delete"
@click="handleRemove(file)"
>
<el-icon><delete /></el-icon>
</span>
</span>
<el-progress
type="circle"
class="progressModule"
:color="colors"
:percentage="Number(uploadPercentage)"
v-if="showProgress && file.url == uploadUrl"
></el-progress>
</div>
</template>
</el-upload>
<!-- 上传提示 -->
<div class="el-upload__tip" v-if="showTip">
请上传
<template v-if="fileSize">
大小不超过 <b style="color: #f56c6c">{{ fileSize }}MB</b>
</template>
<template v-if="fileType">
格式为 <b style="color: #f56c6c">{{ fileType.join("/") }}</b>
</template>
的文件
</div>
<el-dialog v-model="dialogVisible" title="预览" append-to-body width="40%">
<video
:src="dialogVideoUrl"
alt=""
autoplay
class="video"
controls="controls"
></video>
</el-dialog>
<!-- <el-dialog v-model="editView" width="40%" append-to-body>
<el-input
type="textarea"
:rows="4"
v-model="editForm.url"
@input="editVideo"
></el-input>
</el-dialog> -->
</div>
</template>
<script>
import { getToken } from "@/utils/auth";
import {
ElMessage,
ElMessageBox,
ElNotification,
ElLoading,
} from "element-plus";
export default {
props: {
modelValue: [String, Object, Array],
// 数量限制
limit: {
type: Number,
default: 1,
},
// 大小限制(MB)
fileSize: {
type: Number,
default: 5,
},
// 文件类型, 例如['png', 'jpg', 'jpeg']
fileType: {
type: Array,
default: () => ["doc", "xls", "ppt", "txt", "pdf"],
},
// 是否显示提示
isShowTip: {
type: Boolean,
default: true,
},
data: {
type: Object,
default: () => {
return {};
},
},
},
computed: {
showTip() {
return this.isShowTip && (this.fileType || this.fileSize);
},
},
watch: {
modelValue: {
handler(val) {
if (val) {
// 首先将值转为数组
const list = Array.isArray(val) ? val : this.modelValue.split(",");
// 然后将数组转为对象数组
this.fileList = list.map((item) => {
if (typeof item === "string") {
item = { name: item, url: item };
// if (item.indexOf(this.baseUrl) === -1) {
// item = { name: this.baseUrl + item, url: this.baseUrl + item };
// } else {
// item = { name: item, url: item };
// }
}
return item;
});
} else {
this.fileList = [];
return [];
}
},
deep: true,
immediate: true,
},
},
data() {
return {
// 设置上传的请求头部
headers: { "x-token": getToken() },
baseUrl: import.meta.env.VITE_APP_BASE_API,
videoUploadUrl:
import.meta.env.VITE_APP_BASE_API + "/enterprise/v1/upload",
dialogVideoUrl: "",
dialogVisible: false,
fileList: [],
editForm: {
url: "",
uid: null,
},
editView: false,
uploadPercentage: 0,
showProgress: false,
uploadUrl: "",
colors: [
{ color: "#ADD8E6", percentage: 20 },
{ color: "#87CEEB", percentage: 40 },
{ color: "#87CEFA", percentage: 60 },
{ color: "#00BFFF", percentage: 80 },
{ color: "#1296DB", percentage: 100 },
],
uploadBtn: false,
loading: null,
};
},
methods: {
// 移除视频
handleRemove(file) {
const findex = this.fileList.map((f) => f.url).indexOf(file.url);
if (findex > -1) {
this.fileList.splice(findex, 1);
this.submitFile();
}
},
handleShowVideo(file) {
this.dialogVideoUrl = file.url;
this.dialogVisible = true;
},
handleBeforeUpload(file) {
if (this.fileType.length) {
let fileExtension = "";
if (file.name.lastIndexOf(".") > -1) {
fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1);
}
const isTypeOk = this.fileType.some((type) => {
if (file.type.indexOf(type) > -1) return true;
if (fileExtension && fileExtension.indexOf(type) > -1) return true;
return false;
});
if (!isTypeOk) {
ElMessage.error(
`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`
);
return false;
}
}
// 校检文件大小
if (this.fileSize) {
const isLt = file.size / 1024 / 1024 < this.fileSize;
if (!isLt) {
ElMessage.error(`上传文件大小不能超过 ${this.fileSize} MB!`);
return false;
}
}
this.loading = ElLoading.service({
lock: true,
text: "Loading",
background: "rgba(0, 0, 0, 0.7)",
});
},
handleUploadError() {
if (this.loading) {
this.loading.close();
}
},
// 上传完成
handleSuccess(response, file, fileList) {
this.showProgress = false;
this.uploadBtn = false;
if (response.code != "200") {
for (var i = 0; i < fileList.length; i++) {
if (i + 1 == fileList.length) {
fileList.splice(i, 1);
}
}
ElMessage.error(response.message);
this.loading.close();
return;
} else {
ElMessage.success(response.message);
let obj = {
name: response.data.filename,
status: "success",
uid: file.uid,
url: response.data.url,
};
this.fileList.push(obj);
this.loading.close();
this.submitFile();
}
},
// 播放视频
handleEditVideo(file) {
this.editForm.url = file.url;
this.editForm.uid = file.uid;
this.editView = true;
},
// 编辑视频
editVideo() {
for (let i in this.fileList) {
if (this.fileList[i].uid == this.editForm.uid) {
this.fileList[i].url = this.editForm.url;
}
}
this.submitFile();
},
submitFile() {
// this.$emit("submitImg", this.fileList);
this.$emit("update:modelValue", this.listToString(this.fileList));
},
// 对象转成指定字符串分隔
listToString(list, separator) {
let strs = "";
separator = separator || ",";
for (let i in list) {
strs += list[i].url.replace(this.baseUrl, "") + separator;
}
return strs != "" ? strs.substr(0, strs.length - 1) : "";
},
// 上传进度
handleProgress(response, file, fileList) {
this.uploadBtn = true;
this.uploadUrl = file.url;
this.showProgress = true;
this.uploadPercentage = file.percentage.toFixed(0);
},
},
};
</script>
<style lang="scss" scoped>
.el-icon-plus {
font-size: 30px !important;
}
.el-icon-edit {
font-size: 18px !important;
}
.el-icon-video-play {
font-size: 18px !important;
}
.el-icon-delete {
font-size: 18px !important;
color: rgb(243, 143, 130);
}
.el-input >>> .el-textarea__inner {
font-size: 18px !important;
}
.video {
display: block;
margin: auto;
min-height: 200px;
max-height: 600px;
min-width: 200px;
max-width: 100%;
}
.progressModule >>> .el-progress__text {
color: #1296db;
font-size: 15px !important;
}
:deep(.hide .el-upload--picture-card) {
display: none;
}
// 去掉动画效果
:deep(.el-list-enter-active),
:deep(.el-list-leave-active) {
transition: all 0s;
}
:deep(.el-list-enter, .el-list-leave-active) {
opacity: 0;
transform: translateY(0);
}
</style>

View File

@ -0,0 +1,113 @@
<template>
<div :style="`border: 1px solid #ccc; width: ${width}px`">
<Toolbar
style="border-bottom: 1px solid #ccc"
:editor="editorRef"
:defaultConfig="toolbarConfig"
:mode="mode"
/>
<Editor
:style="`min-height: ${minHeight}px; height: ${height}px; overflow-y: hidden`"
v-model="valueHtml"
:defaultConfig="editorConfig"
:mode="mode"
@onCreated="handleCreated"
@onChange="handleChange"
/>
</div>
</template>
<script>
import "@wangeditor/editor/dist/css/style.css"; // 引入 css
import { getToken } from "@/utils/auth";
import { onBeforeUnmount, ref, shallowRef, onMounted, toRefs } from "vue";
import { Editor, Toolbar } from "@wangeditor/editor-for-vue";
const baseUrl = import.meta.env.VITE_APP_BASE_API;
export default {
components: { Editor, Toolbar },
props: {
modelValue: {
type: String,
default: "",
},
minHeight: {
type: [String, Number],
default: 300,
},
height: {
type: [String, Number],
default: 300,
},
width: {
type: [String, Number],
default: 820,
},
mode: {
type: String,
default: "default", // or 'simple'
},
},
setup(props, context) {
// 编辑器实例,必须用 shallowRef
const editorRef = shallowRef();
// 内容 HTML
const valueHtml = ref("");
watch(
() => props.modelValue,
(val) => {
valueHtml.value = val;
},
{ immediate: true }
);
const { height } = toRefs(props);
const toolbarConfig = {
excludeKeys: [],
};
const editorConfig = {
placeholder: "请输入内容...",
MENU_CONF: {
uploadImage: {
server: `${baseUrl}/common/upload`,
// 自定义增加 http header
fieldName: "file",
headers: {
Authorization: `Bearer ${getToken()}`,
},
customInsert(res, insertFn) {
// res 即服务端的返回结果
console.log(res);
// 从 res 中找到 url alt href ,然后插图图片
insertFn(res.url, null, null);
},
},
},
};
// console.log(editor.getMenuConfig('uploadImage'));
// 组件销毁时,也及时销毁编辑器
onBeforeUnmount(() => {
const editor = editorRef.value;
if (editor == null) return;
editor.destroy();
});
const handleCreated = (editor) => {
editorRef.value = editor; // 记录 editor 实例,重要!
};
const handleChange = (editor) => {
context.emit("update:modelValue", editor.getHtml());
};
return {
editorRef,
valueHtml,
mode: "default", // 或 'simple'
toolbarConfig,
editorConfig,
height,
handleCreated,
handleChange,
};
},
};
</script>

View File

@ -0,0 +1,273 @@
<template>
<div class="webHead">
<el-row>
<el-col :span="8">
<img src="@/assets/logo/logo.png" class="logo" />
</el-col>
<el-col :span="16">
<ul class="menu">
<li class="menu-item1">
<div
class="menu-item-tit"
:class="pagePath == '/' ? 'active' : ''"
@click="handlePath('/')"
>
首页
</div>
</li>
<li class="menu-item1 solution">
<div
class="menu-item-tit"
:class="pagePath.indexOf('/solution/') != -1 ? 'active' : ''"
>
解决方案
</div>
<div class="show_box">
<div
class="pointer"
:class="pagePath == '/solution/small' ? 'x_blue _active' : ''"
@click="handlePath('/solution/small')"
>
中小型企业服务
</div>
<div
class="pointer"
:class="pagePath == '/solution/large' ? 'x_blue _active' : ''"
@click="handlePath('/solution/large')"
>
大型企业服务
</div>
<div
class="pointer"
:class="
pagePath == '/solution/government' ? 'x_blue _active' : ''
"
@click="handlePath('/solution/government')"
>
政府区域服务
</div>
<div
class="pointer"
:class="
pagePath == '/solution/scientific' ? 'x_blue _active' : ''
"
@click="handlePath('/solution/scientific')"
>
科研区域服务
</div>
</div>
</li>
<li class="menu-item1">
<div
class="menu-item-tit"
:class="pagePath == '/innovate' ? 'active' : ''"
@click="handlePath('/innovate')"
>
创新服务
</div>
</li>
<li class="menu-item1">
<div
class="menu-item-tit"
:class="pagePath == '/activity' ? 'active' : ''"
@click="handlePath('/activity')"
>
活动报名
</div>
</li>
<li class="menu-item1">
<div
class="menu-item-tit"
:class="pagePath == '/about' ? 'active' : ''"
@click="handlePath('/about')"
>
关于我们
</div>
</li>
<li class="menu-item1" style="display: flex; justify-content: center">
<div
v-if="!userStore.avatar"
class="menu-item-tit"
:class="pagePath == '/login' ? 'active' : ''"
@click="handlePath('/login')"
>
登录注册
</div>
<el-dropdown
v-else
style="margin-top: 20px"
class="avatar-container right-menu-item hover-effect"
trigger="click"
>
<div class="avatar-wrapper">
<img :src="userStore.avatar" class="user-avatar" />
<i class="el-icon-caret-bottom" />
</div>
<template #dropdown>
<el-dropdown-menu>
<!-- <router-link to="/identity/index"> -->
<el-dropdown-item @click="handlePage"
>个人中心</el-dropdown-item
>
<!-- </router-link> -->
<el-dropdown-item divided @click="logout">
<span>退出登录</span>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</li>
</ul>
</el-col>
</el-row>
</div>
</template>
<script setup>
import { ElMessageBox } from "element-plus";
import { defineComponent, onMounted, reactive, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import useUserStore from "@/store/modules/user";
const userStore = useUserStore();
let state = reactive({});
let pagePath = ref("");
const route = useRoute();
const router = useRouter();
watch(
() => route.path,
(newVal, oldVal) => {
pagePath.value = newVal;
}
);
pagePath.value = route.path;
function handlePage() {
// router.push("/identity/index");
// let routeData = "";
// const selectRole = localStorage.getItem("select_identity");
// if (selectRole > 0) {
// routeData = router.resolve({ path: "/admin" });
// } else {
// routeData = router.resolve({ path: "/identity/index" });
// }
// window.open(routeData.href, "_blank");
const routeData = router.resolve({ path: "/identity/index" });
window.open(routeData.href, "_blank");
}
function handlePath(path) {
pagePath.value = path;
router.push(path);
}
function logout() {
ElMessageBox.confirm("确定注销并退出系统吗?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
useUserStore()
.logOut()
.then(() => {
location.href = "/";
});
})
.catch(() => {});
}
</script>
<style lang="scss">
ol,
ul,
dl {
margin: 0;
padding: 0;
}
li,
dd,
dt {
padding: 0;
margin: 0;
list-style: none;
}
.webHead {
position: fixed;
z-index: 2001;
top: 0;
left: 0;
width: 100%;
height: 80px;
padding: 0 260px;
box-sizing: border-box;
background: #ffffff;
box-shadow: 0px 0px 43px 0px rgba(0, 42, 255, 0.09);
.logo {
height: 30px;
margin: 25px 0;
}
.menu {
display: flex;
.solution {
position: relative;
.show_box {
display: none;
position: absolute;
top: 80px;
width: 100%;
text-align: center;
background-color: red;
div {
height: 42px;
line-height: 42px;
font-size: 14px;
color: #666666;
background-color: #f2f6ff;
}
._active {
background-color: #fff;
}
}
&:hover {
.show_box {
display: block;
}
}
}
.menu-item1 {
flex: 1;
text-align: center;
.menu-item-tit {
display: inline-block;
padding: 25px 0;
font-size: 16px;
font-family: Source Han Sans CN;
font-weight: 400;
color: #000;
cursor: pointer;
}
.menu-item-tit:hover {
opacity: 0.8;
}
.active {
font-size: 20px;
font-weight: 500;
border-bottom: 2.5px solid #000;
}
}
}
}
</style>
<style lang="scss" scoped>
.user-avatar {
cursor: pointer;
width: 40px;
height: 40px;
border-radius: 50%;
}
</style>

View File

@ -0,0 +1,67 @@
<template>
<div class="login-code">
<el-button
class="x_btns login-code-img"
size="default"
type="primary"
style="width: 100%"
@click.prevent="getCode"
:disabled="isDisabled"
>
<span>{{ buttonName }}</span>
</el-button>
</div>
</template>
<script setup>
import { getCodeImg } from "@/api/login";
const props = defineProps({
mobile: String,
});
const disabled = ref(true);
const buttonName = ref("获取验证码");
const isDisabled = ref(false);
const time = ref(60);
const { proxy } = getCurrentInstance();
function getCode() {
const reg = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
if (!reg.test(props.mobile))
return proxy.$modal.msgError("请输入正确的手机号码");
isDisabled.value = true;
let interval = setInterval(function () {
buttonName.value = time.value + "后重新发送";
--time.value;
if (time.value < 0) {
buttonName.value = "重新发送";
time.value = 60;
isDisabled.value = false;
clearInterval(interval);
}
}, 1000);
getCodeImg({ mobile: props.mobile })
.then((res) => {})
.catch(() => {
isDisabled.value = false;
clearInterval(interval);
});
}
</script>
<style lang="scss" scoped>
.login-code {
width: 30%;
height: 38px;
float: right;
img {
cursor: pointer;
vertical-align: middle;
}
}
.login-code-img {
height: 36px;
}
</style>