| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const store_user = require("../../store/user.js");
- const store_checkin = require("../../store/checkin.js");
- if (!Math) {
- NavBar();
- }
- const NavBar = () => "../components/NavBar/NavBar.js";
- const _sfc_main = {
- __name: "index",
- setup(__props) {
- const userStore = store_user.useUserStore();
- const checkinStore = store_checkin.useCheckinStore();
- const isTeacher = common_vendor.computed(() => userStore.userInfo.role === "TEACHER");
- common_vendor.onShow(() => {
- if (isTeacher.value) {
- common_vendor.index.redirectTo({
- url: "/pages/checkin/teacher/index"
- });
- }
- });
- const studentView = common_vendor.ref("main");
- const navBarRef = common_vendor.ref(null);
- const navHeight = common_vendor.ref(88);
- const navTitle = common_vendor.computed(() => {
- if (studentView.value === "numberInput")
- return "输入签到码";
- return "课堂签到";
- });
- const studentCode = common_vendor.ref(["", "", "", ""]);
- const isStudentCodeValid = common_vendor.computed(() => studentCode.value.every((c) => c !== "" && !isNaN(c)));
- const isAlreadyCheckedIn = common_vendor.computed(() => checkinStore.isStudentCheckedIn(userStore.userInfo.id));
- const studentGreeting = common_vendor.computed(() => {
- if (isAlreadyCheckedIn.value)
- return "你已成功签到,表现不错!👍";
- if (!checkinStore.session.isActive)
- return "签到还未开始,请稍作等待。";
- return `${userStore.userInfo.name || userStore.userInfo.englishName || "同学"}, 签到开始啦~`;
- });
- const studentButtonText = common_vendor.computed(() => {
- if (isAlreadyCheckedIn.value)
- return "已签到";
- if (!checkinStore.session.isActive)
- return "暂未设置";
- return checkinStore.session.method === "number" ? "数字签到" : "二维码签到";
- });
- const studentAction = () => {
- if (checkinStore.session.method === "number") {
- studentView.value = "numberInput";
- } else {
- common_vendor.index.scanCode({
- onlyFromCamera: true,
- success: (res) => {
- if (res.result === checkinStore.session.code) {
- const result = checkinStore.attemptCheckin({ id: userStore.userInfo.id, name: userStore.userInfo.name });
- common_vendor.index.showToast({ title: result.message, icon: result.success ? "success" : "none" });
- } else {
- common_vendor.index.showToast({ title: "无效的签到码", icon: "none" });
- }
- },
- fail: () => {
- common_vendor.index.showToast({ title: "取消扫码", icon: "none" });
- }
- });
- }
- };
- const submitNumberCode = () => {
- const code = studentCode.value.join("");
- const result = checkinStore.attemptCheckin({ id: userStore.userInfo.id, name: userStore.userInfo.name }, code);
- common_vendor.index.showToast({ title: result.message, icon: result.success ? "success" : "none" });
- if (result.success) {
- studentView.value = "main";
- }
- };
- const onBack = () => {
- if (studentView.value !== "main") {
- studentView.value = "main";
- }
- };
- const formattedCurrentTime = common_vendor.computed(() => {
- const now = /* @__PURE__ */ new Date();
- const year = now.getFullYear();
- const month = now.getMonth() + 1;
- const day = now.getDate();
- const hours = String(now.getHours()).padStart(2, "0");
- const minutes = String(now.getMinutes()).padStart(2, "0");
- return `${year}年${month}月${day}日 ${hours}:${minutes}`;
- });
- const contentWrapperStyle = common_vendor.computed(() => ({
- paddingTop: `${navHeight.value}px`,
- // 让内容区撑满剩余屏幕
- minHeight: `calc(100vh - ${navHeight.value}px)`
- }));
- common_vendor.watch(() => checkinStore.session.isActive, (newVal) => {
- if (!newVal && !isTeacher.value) {
- studentView.value = "main";
- }
- });
- common_vendor.onMounted(() => {
- common_vendor.watch(
- () => {
- var _a;
- return (_a = navBarRef.value) == null ? void 0 : _a.totalNavHeight;
- },
- (val) => {
- if (val)
- navHeight.value = val;
- },
- { immediate: true }
- );
- });
- return (_ctx, _cache) => {
- return common_vendor.e({
- a: !isTeacher.value
- }, !isTeacher.value ? common_vendor.e({
- b: common_vendor.sr(navBarRef, "1410bd6b-0", {
- "k": "navBarRef"
- }),
- c: common_vendor.o(onBack),
- d: common_vendor.p({
- title: navTitle.value,
- showBack: studentView.value !== "main"
- }),
- e: studentView.value === "main"
- }, studentView.value === "main" ? {
- f: common_vendor.t(studentGreeting.value),
- g: common_vendor.t(formattedCurrentTime.value),
- h: common_vendor.t(studentButtonText.value),
- i: !common_vendor.unref(checkinStore).session.isActive || isAlreadyCheckedIn.value,
- j: common_vendor.o(studentAction)
- } : studentView.value === "numberInput" ? {
- l: common_vendor.f(studentCode.value, (item, index, i0) => {
- return {
- a: index,
- b: studentCode.value[index],
- c: common_vendor.o(($event) => studentCode.value[index] = $event.detail.value, index)
- };
- }),
- m: !isStudentCodeValid.value,
- n: common_vendor.o(submitNumberCode)
- } : {}, {
- k: studentView.value === "numberInput",
- o: common_vendor.s(contentWrapperStyle.value)
- }) : {});
- };
- }
- };
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1410bd6b"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/checkin/index.js.map
|