fix(utils/http.js): 更新开发环境下的miucms_session值

refactor(app.vue): 移除开发环境下的模拟用户数据,改为监听getUser事件获取用户信息
This commit is contained in:
DESKTOP-RQ919RC\Pc
2025-06-30 12:11:56 +08:00
parent c3792299d3
commit 01e8a789d8
71 changed files with 431 additions and 418 deletions

View File

@@ -79,14 +79,14 @@
</div>
</template>
</div>
<div class="option-item option-circusee flexacenter" :class="{ 'hascontent': optionList.length > 2 }">
<div class="option-item option-circusee flexacenter" :class="{ hascontent: optionList.length > 2 }">
<div class="option-content flexacenter">
<div class="option-text flexcenter">{{ optionList.length + 1 }}</div>
<input class="option-input flex1" disabled value="不懂,围观学习" />
</div>
</div>
</div>
<div class="flexcenter" style="padding-right: 26px;">
<div class="flexcenter" style="padding-right: 26px">
<div class="add-box flexcenter" @click="addOption()" v-if="optionList.length < 15">
<img class="add-icon" src="@/assets/img/add-green-icon.svg" />
添加选项
@@ -114,200 +114,209 @@
</template>
<script setup>
useHead({ script: [{ src: "https://app.gter.net/bottom?tpl=footer,popupnotification", body: true }] })
import { useRouter } from "vue-router"
// useHead({ script: [{ src: "https://app.gter.net/bottom?tpl=footer,popupnotification", body: true }] })
useHead({ script: [{ src: "https://app.gter.net/bottom?tpl=header&menukey=mj&noshow=noshow" }, { src: "https://app.gter.net/bottom?tpl=footer,popupnotification", body: true }] });
import { ElMessage } from "element-plus"
import zhCn from "element-plus/dist/locale/zh-cn.mjs"
import Sortable from "sortablejs"
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import zhCn from "element-plus/dist/locale/zh-cn.mjs";
import Sortable from "sortablejs";
const router = useRouter()
const goLogin = inject("goLogin")
const setDisabled = time => {
const router = useRouter();
const goLogin = inject("goLogin");
const setDisabled = (time) => {
// return time.getTime() < Date.now() // 可选历史天、可选当前天、不可选未来天
const today = new Date()
const tomorrow = new Date(today)
tomorrow.setDate(today.getDate())
const today = new Date();
const tomorrow = new Date(today);
tomorrow.setDate(today.getDate());
const thirtyDaysLater = new Date(today)
thirtyDaysLater.setDate(today.getDate() + 29)
const thirtyDaysLater = new Date(today);
thirtyDaysLater.setDate(today.getDate() + 29);
return time < tomorrow || time > thirtyDaysLater
}
return time < tomorrow || time > thirtyDaysLater;
};
onMounted(() => {})
onMounted(() => {});
onBeforeMount(() => {
clearBottom()
clearBottom();
// clearTop()
})
});
// 清除底部的次数
let clearBottomCount = 0
let clearBottomCount = 0;
// 清除 底部
const clearBottom = () => {
const indexFooter = document.querySelector("section.index-footer")
const indexFooter = document.querySelector("section.index-footer");
if (!indexFooter) {
clearBottomCount++
setTimeout(() => clearBottom(), 50)
return
clearBottomCount++;
setTimeout(() => clearBottom(), 50);
return;
}
if (clearBottomCount == 15) return
indexFooter.style.display = "none"
}
if (clearBottomCount == 15) return;
indexFooter.style.display = "none";
};
// 清除顶部的次数
let clearTopCount = 0
let clearTopCount = 0;
// 清除 顶部
const clearTop = () => {
const indexHeader = document.querySelector("header.page-header")
const indexHeader = document.querySelector("header.page-header");
if (!indexHeader) {
clearTopCount++
setTimeout(() => clearTop(), 50)
return
clearTopCount++;
setTimeout(() => clearTop(), 50);
return;
}
if (clearTopCount == 5) return
if (clearTopCount == 5) return;
indexHeader.style.display = "none"
}
indexHeader.style.display = "none";
};
let info = ref({})
let token = ""
let info = ref({});
let token = "";
// 切换匿名状态
const cutAnonymous = () => {
info.value["anonymous"] = info.value["anonymous"] == 0 ? 1 : 0
}
info.value["anonymous"] = info.value["anonymous"] == 0 ? 1 : 0;
};
let loading = false // 加载中
const userInfoWin = inject("userInfoWin");
let openAttest = inject("openAttest");
const realname = inject("realname");
let loading = false; // 加载中
// 提交发布
const submit = (status = 1) => {
// status = 0
if (loading) return
loading = true
if (realname.value == 0 && userInfoWin.value.uin > 0) {
openAttest();
return;
}
let option = []
optionList.value.forEach(element => {
if (element["message"].trim() !== "") option.push(element["message"])
})
if (loading) return;
loading = true;
let option = [];
optionList.value.forEach((element) => {
if (element["message"].trim() !== "") option.push(element["message"]);
});
if (status == 1) {
if (option.length < 2) {
ElMessage.error("请设置至少2个选项~")
loading = false
return
ElMessage.error("请设置至少2个选项~");
loading = false;
return;
}
const hash = {}
const hash = {};
for (let i = 0; i < option.length; i++) {
if (hash[option[i]]) {
ElMessage.error("选项名称不能重复")
loading = false
return // 有重复值
ElMessage.error("选项名称不能重复");
loading = false;
return; // 有重复值
}
hash[option[i]] = true
hash[option[i]] = true;
}
option.push("不懂,围观学习")
option.push("不懂,围观学习");
}
info.value["option"] = option
info.value["option"] = option;
// return
publishSubmitHttp({ info: info.value, token, status })
.then(res => {
.then((res) => {
if (res.code != 200) {
ElMessage.error(res.message)
return
ElMessage.error(res.message);
return;
}
const data = res.data
ElMessage.success(res.message)
const data = res.data;
ElMessage.success(res.message);
// router.push(`/details/${data["uniqid"]}`)
if (status == 0) goToURL(`/index.html`, false)
else goToURL(`/details/${data["uniqid"]}`, false)
if (status == 0) goToURL(`/index.html`, false);
else goToURL(`/details/${data["uniqid"]}`, false);
})
.finally(() => (loading = false))
}
.finally(() => (loading = false));
};
// 放弃保存 跳跃上一页或者首页
const abandonSaving = () => {
if (router.currentRoute.value.meta.previousPage) router.go(-1)
else goToURL("./index.html", false) // 跳转到首页
if (router.currentRoute.value.meta.previousPage) router.go(-1);
else goToURL("./index.html", false); // 跳转到首页
// else router.push("./index.html") // 跳转到首页
}
};
let draggableContainer = ref(null)
const sortable = ref(null)
let draggableContainer = ref(null);
const sortable = ref(null);
onMounted(() => {
getinit()
initDraggable()
})
getinit();
initDraggable();
});
const getinit = () => {
publishInitHttp().then(res => {
publishInitHttp().then((res) => {
if (res.code != 200) {
ElMessage.error(res.message || "报错了,刷新一下")
if (res.code == 401) goLogin()
return
ElMessage.error(res.message || "报错了,刷新一下");
if (res.code == 401) goLogin();
return;
}
const data = res.data
const data = res.data;
// data.info.option = []
const option = data.info?.option || []
const option = data.info?.option || [];
if (option.length == 0) {
for (let index = 0; index < 2; index++) {
optionList.value.push({ id: index, message: "" })
optionList.value.push({ id: index, message: "" });
}
} else {
option.forEach((message, index) => {
if (message !== "不懂,围观学习") {
optionList.value.push({ id: index, message })
optionList.value.push({ id: index, message });
}
})
});
while (optionList.value.length < 2) {
optionList.value.push({ id: optionList.value.length, message: "" })
optionList.value.push({ id: optionList.value.length, message: "" });
}
}
let deadline = data["info"]["deadline"] || 0
let deadline = data["info"]["deadline"] || 0;
// console.log("deadline", deadline)
if (deadline > 100000) data["info"]["deadline"] = handleDate(deadline)
else data["info"]["deadline"] = null
if (deadline > 100000) data["info"]["deadline"] = handleDate(deadline);
else data["info"]["deadline"] = null;
if (data["info"]["deadline"]) data["info"]["deadline"] = handleDate(deadline)
if (data["info"]["deadline"]) data["info"]["deadline"] = handleDate(deadline);
info.value = data.info
token = data.token
})
}
info.value = data.info;
token = data.token;
});
};
// 处理初始化 面试时间的 时间戳格式
const handleDate = timestamp => {
const handleDate = (timestamp) => {
// 使用Date对象将时间戳转换为日期对象
var date = new Date(timestamp * 1000)
var date = new Date(timestamp * 1000);
// 获取年份、月份和日期
var year = date.getFullYear()
var month = ("0" + (date.getMonth() + 1)).slice(-2) // 月份从0开始需要加1并补0
var day = ("0" + date.getDate()).slice(-2) // 获取日期并补0
var year = date.getFullYear();
var month = ("0" + (date.getMonth() + 1)).slice(-2); // 月份从0开始需要加1并补0
var day = ("0" + date.getDate()).slice(-2); // 获取日期并补0
// 拼接为yyyy-mm-dd格式的日期字符串
var formattedDate = year + "-" + month + "-" + day
var formattedDate = year + "-" + month + "-" + day;
return formattedDate
}
return formattedDate;
};
// 初始化拖拽
const initDraggable = () => {
if (!draggableContainer.value) {
console.warn("容器不能为空")
return
console.warn("容器不能为空");
return;
}
sortable.value = Sortable.create(draggableContainer.value, {
handle: ".option-drag",
@@ -319,43 +328,43 @@ const initDraggable = () => {
onUpdate(e) {
if (e.oldIndex !== undefined && e.newIndex !== undefined) {
// 删除拖拽的元素
const list = [...optionList.value]
const item = list.splice(e.oldIndex, 1)[0]
const list = [...optionList.value];
const item = list.splice(e.oldIndex, 1)[0];
// 把删除的元素放到新的位置
list.splice(e.newIndex, 0, item)
optionList.value = list
list.splice(e.newIndex, 0, item);
optionList.value = list;
}
},
})
}
});
};
let optionList = ref([]) // 特殊的 选项 列表
let optionList = ref([]); // 特殊的 选项 列表
// 点击添加选项
const addOption = () => {
optionList.value.push({
id: optionList.value.length,
message: "",
})
}
});
};
// 点击删除选项
const deleteOption = index => {
optionList.value.splice(index, 1)
const deleteOption = (index) => {
optionList.value.splice(index, 1);
optionList.value.forEach((element, index) => {
element["id"] = index
})
}
element["id"] = index;
});
};
// 点进清除选项
const clearMessage = index => {
optionList.value[index]["message"] = ""
}
const clearMessage = (index) => {
optionList.value[index]["message"] = "";
};
let pickerRef = ref(null)
let pickerRef = ref(null);
const handlePicker = () => {
pickerRef.value.handleOpen()
}
pickerRef.value.handleOpen();
};
</script>
<style scoped lang="less">