| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8"/>
- <meta name="viewport"
- content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
- <title>违纪学员</title>
- <script src="/js/mp_base/base.js?v=20261120-jt-students-no-back"></script>
- <style>
- [v-cloak] { display: none !important; }
- :root {
- --line: #e5e7eb;
- --text: #222;
- --muted: #8b95a5;
- --blue: #2f6fed;
- --danger: #e5484d;
- }
- * { box-sizing: border-box; }
- body {
- margin: 0;
- color: var(--text);
- background: #f3f4f6;
- font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
- "Microsoft YaHei", sans-serif;
- }
- #app {
- min-height: 100vh;
- padding-bottom: 20px;
- }
- .topbar {
- position: relative;
- display: flex;
- align-items: center;
- justify-content: center;
- height: 52px;
- padding: 0 14px;
- background: #fff;
- border-bottom: 1px solid var(--line);
- }
- .topbar-title {
- overflow: hidden;
- font-size: 17px;
- font-weight: 700;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- .content { padding: 12px 14px; }
- .summary {
- margin-bottom: 10px;
- color: var(--muted);
- font-size: 13px;
- line-height: 1.5;
- }
- .student-card-list {
- display: grid;
- gap: 10px;
- }
- .swipe-row {
- position: relative;
- overflow: hidden;
- background: #fff;
- border: 1px solid var(--line);
- border-radius: 6px;
- touch-action: pan-y;
- }
- .student-remove {
- position: absolute;
- top: 0;
- right: 0;
- bottom: 0;
- width: 72px;
- padding: 0;
- color: #fff;
- background: var(--blue);
- border: 0;
- border-radius: 0 5px 5px 0;
- font: inherit;
- font-size: 15px;
- transform: translateX(72px);
- transition: transform .18s ease;
- z-index: 2;
- }
- .student-content {
- position: relative;
- min-height: 64px;
- padding: 12px 18px 12px 14px;
- background: #fff;
- transition: transform .18s ease;
- z-index: 1;
- }
- .student-content::after {
- content: "";
- position: absolute;
- top: 0;
- right: 0;
- bottom: 0;
- width: 6px;
- background: #007aff;
- }
- .swipe-row.dragging .student-remove,
- .swipe-row.dragging .student-content { transition: none; }
- .item-main {
- font-size: 15px;
- font-weight: 600;
- line-height: 1.35;
- }
- .item-sub {
- margin-top: 4px;
- color: var(--muted);
- font-size: 13px;
- line-height: 1.4;
- }
- .empty,
- .loading,
- .error {
- padding: 28px 14px;
- color: var(--muted);
- background: #fff;
- border: 1px solid var(--line);
- border-radius: 6px;
- text-align: center;
- font-size: 14px;
- line-height: 1.6;
- }
- .error { color: var(--danger); }
- </style>
- </head>
- <body>
- <div id="app" v-cloak>
- <div class="topbar">
- <div class="topbar-title">违纪学员</div>
- </div>
- <div v-if="loading" class="content"><div class="loading">加载中...</div></div>
- <div v-else-if="errorMsg" class="content"><div class="error">{{ errorMsg }}</div></div>
- <div v-else class="content">
- <div class="summary">
- 本次保留 {{ roomInfo.students.length }} 人<template v-if="removedCount">,已移除 {{ removedCount }} 人</template>。
- 向左滑动学员卡片可将其移出本次违纪名单。
- </div>
- <div v-if="!roomInfo.students.length" class="empty">
- 本次违纪学员已全部移除,请返回录入页重新选择房间并至少保留一名学员。
- </div>
- <div v-else class="student-card-list">
- <div
- v-for="student in roomInfo.students"
- :key="student.ryid"
- class="swipe-row"
- :class="{ dragging: activeRyid === String(student.ryid) }"
- @pointerdown.stop="onPointerStart(student, $event)"
- @pointermove.stop="onPointerMove($event)"
- @pointerup.stop="onPointerEnd($event)"
- @pointercancel.stop="onPointerEnd($event)"
- @touchstart.stop="onTouchStart(student, $event)"
- @touchmove.stop="onTouchMove($event)"
- @touchend.stop="onTouchEnd"
- @touchcancel.stop="onTouchEnd"
- @click.stop="toggleActions(student)"
- >
- <button
- type="button"
- class="student-remove"
- :style="{ transform: 'translateX(' + actionOffset(student) + 'px)' }"
- @click.stop="removeStudent(student)"
- >移除</button>
- <div
- class="student-content"
- :style="{ transform: 'translateX(' + rowOffset(student) + 'px)' }"
- >
- <div class="item-main">{{ student.xm }}</div>
- <div class="item-sub">
- {{ student.cwmc || '未分配床位' }}
- <template v-if="student.bjmc"> · {{ student.bjmc }}</template>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <script>
- window.SS.ready(function () {
- window.SS.dom.initializeFormApp({
- el: "#app",
- data() {
- return {
- loading: true,
- errorMsg: "",
- stateKey: "mp_sswjjl_jt_inp_state",
- jzwid: "",
- kfid: "",
- activeRyid: "",
- openRyid: "",
- dragOffset: 0,
- swipeStartX: 0,
- swipeStartY: 0,
- swipeStartOffset: 0,
- swipeHorizontal: false,
- suppressClickUntil: 0,
- roomInfo: {
- students: [],
- originalStudents: [],
- bjList: [],
- xymcStr: "",
- bjmcStr: ""
- }
- };
- },
- computed: {
- removedCount() {
- return Math.max(0,
- (this.roomInfo.originalStudents || []).length - this.roomInfo.students.length);
- }
- },
- async mounted() {
- const params = this.getUrlParams();
- this.jzwid = String(params.jzwid || "");
- this.kfid = String(params.kfid || "");
- if (!this.jzwid || !this.kfid) {
- this.errorMsg = "缺少房间参数";
- this.loading = false;
- return;
- }
- try {
- if (this.restoreFromInput()) {
- this.loading = false;
- return;
- }
- await this.loadRoom();
- this.persistInputState();
- } catch (error) {
- this.errorMsg = error.message || "学员名单加载失败";
- } finally {
- this.loading = false;
- }
- },
- methods: {
- restoreFromInput() {
- try {
- const raw = sessionStorage.getItem(this.stateKey);
- if (!raw) return false;
- const state = JSON.parse(raw);
- const form = state && state.form ? state.form : {};
- if (String(form.jzwid || "") !== this.jzwid
- || String(form.kfid || "") !== this.kfid
- || !state.roomInfo
- || !Array.isArray(state.roomInfo.students)) {
- return false;
- }
- this.roomInfo = this.normalizeRoomInfo(state.roomInfo);
- return true;
- } catch (error) {
- console.warn("[mp_sswjjl_jt_students] 恢复名单失败", error);
- return false;
- }
- },
- async loadRoom() {
- const response = await this.postService(
- "/service?ssServ=sswjjl_mpLoadRoom&ssDest=data",
- {jzwid: this.jzwid, kfid: this.kfid}
- );
- const students = Array.isArray(response.students) ? response.students : [];
- this.roomInfo = {
- students: JSON.parse(JSON.stringify(students)),
- originalStudents: JSON.parse(JSON.stringify(students)),
- bjList: response.bjList || [],
- xymcStr: response.xymcStr || "",
- bjmcStr: response.bjmcStr || ""
- };
- },
- normalizeRoomInfo(raw) {
- const source = raw && typeof raw === "object" ? raw : {};
- const students = Array.isArray(source.students)
- ? JSON.parse(JSON.stringify(source.students)) : [];
- const originalStudents = Array.isArray(source.originalStudents)
- ? JSON.parse(JSON.stringify(source.originalStudents))
- : JSON.parse(JSON.stringify(students));
- return {
- students,
- originalStudents,
- bjList: Array.isArray(source.bjList)
- ? JSON.parse(JSON.stringify(source.bjList)) : [],
- xymcStr: source.xymcStr || "",
- bjmcStr: source.bjmcStr || ""
- };
- },
- persistInputState() {
- try {
- const raw = sessionStorage.getItem(this.stateKey);
- const state = raw ? JSON.parse(raw) : {};
- const form = state.form && typeof state.form === "object" ? state.form : {};
- form.jzwid = this.jzwid;
- form.kfid = this.kfid;
- state.version = 1;
- state.form = form;
- state.roomInfo = JSON.parse(JSON.stringify(this.roomInfo));
- sessionStorage.setItem(this.stateKey, JSON.stringify(state));
- } catch (error) {
- console.warn("[mp_sswjjl_jt_students] 保存名单失败", error);
- }
- },
- recomputeRoomSummary() {
- const classMap = new Map();
- const studentTexts = [];
- for (const student of this.roomInfo.students) {
- const bjid = String(student.bjid || "");
- if (bjid) classMap.set(bjid, student.bjmc || "");
- studentTexts.push(student.xm + "("
- + (student.cwmc || "未分配床位") + ")");
- }
- this.roomInfo.bjList = Array.from(classMap.entries()).map(
- ([bjid, bjmc]) => ({bjid, bjmc}));
- this.roomInfo.xymcStr = studentTexts.join(",");
- this.roomInfo.bjmcStr = this.roomInfo.bjList.map(item => item.bjmc).join(",");
- },
- removeStudent(student) {
- if (!student) return;
- const ryid = String(student.ryid);
- this.roomInfo.students = this.roomInfo.students.filter(
- item => String(item.ryid) !== ryid);
- this.recomputeRoomSummary();
- this.persistInputState();
- this.openRyid = "";
- this.activeRyid = "";
- this.dragOffset = 0;
- this.swipeHorizontal = false;
- this.showToast("已从本次违纪名单移除");
- },
- eventPoint(event) {
- return (event.changedTouches && event.changedTouches[0])
- || (event.touches && event.touches[0])
- || event;
- },
- onTouchStart(student, event) {
- const touch = this.eventPoint(event);
- if (!touch) return;
- const ryid = String(student.ryid);
- if (this.openRyid && this.openRyid !== ryid) this.openRyid = "";
- this.activeRyid = ryid;
- this.swipeStartX = touch.clientX;
- this.swipeStartY = touch.clientY;
- this.swipeStartOffset = this.openRyid === ryid ? -72 : 0;
- this.dragOffset = this.swipeStartOffset;
- this.swipeHorizontal = false;
- },
- onTouchMove(event) {
- if (!this.activeRyid) return;
- const touch = this.eventPoint(event);
- if (!touch) return;
- const dx = touch.clientX - this.swipeStartX;
- const dy = touch.clientY - this.swipeStartY;
- if (!this.swipeHorizontal) {
- if (Math.abs(dx) < 5 && Math.abs(dy) < 5) return;
- if (Math.abs(dx) <= Math.abs(dy)) return;
- this.swipeHorizontal = true;
- }
- if (event.cancelable) event.preventDefault();
- this.dragOffset = Math.max(-72, Math.min(0, this.swipeStartOffset + dx));
- },
- onTouchEnd(event) {
- if (!this.activeRyid) return;
- const touch = this.eventPoint(event);
- let horizontal = this.swipeHorizontal;
- let finalOffset = this.dragOffset;
- if (touch) {
- const dx = touch.clientX - this.swipeStartX;
- const dy = touch.clientY - this.swipeStartY;
- if (Math.abs(dx) > 30 && Math.abs(dx) > Math.abs(dy)) {
- horizontal = true;
- finalOffset = Math.max(-72, Math.min(0, this.swipeStartOffset + dx));
- }
- }
- if (horizontal) {
- this.openRyid = finalOffset <= -30 ? this.activeRyid : "";
- this.suppressClickUntil = Date.now() + 350;
- }
- this.activeRyid = "";
- this.dragOffset = 0;
- this.swipeHorizontal = false;
- },
- toggleActions(student) {
- if (!student || Date.now() < this.suppressClickUntil) return;
- const ryid = String(student.ryid);
- this.openRyid = this.openRyid === ryid ? "" : ryid;
- },
- onPointerStart(student, event) {
- if (event.pointerType === "touch") return;
- if (event.currentTarget
- && typeof event.currentTarget.setPointerCapture === "function") {
- event.currentTarget.setPointerCapture(event.pointerId);
- }
- this.onTouchStart(student, event);
- },
- onPointerMove(event) {
- if (event.pointerType === "touch") return;
- this.onTouchMove(event);
- },
- onPointerEnd(event) {
- if (event.pointerType === "touch") return;
- this.onTouchEnd(event);
- },
- rowOffset(student) {
- const ryid = String(student.ryid);
- if (this.activeRyid === ryid) return this.dragOffset;
- return this.openRyid === ryid ? -72 : 0;
- },
- actionOffset(student) {
- return 72 + this.rowOffset(student);
- },
- getUrlParams() {
- const params = {};
- const search = new URLSearchParams(window.location.search);
- for (const [key, value] of search) params[key] = decodeURIComponent(value);
- return params;
- },
- getRequest() {
- return window.request || (typeof request !== "undefined" ? request : null);
- },
- async postService(url, data) {
- const req = this.getRequest();
- if (!req || typeof req.post !== "function") throw new Error("请求组件未加载");
- const response = await req.post(url, data, {loading: false, formData: true});
- const raw = response && response.data !== undefined ? response.data : response;
- if (raw && raw.ssCode !== undefined && Number(raw.ssCode) !== 0) {
- throw new Error(raw.ssMsg || "请求失败");
- }
- return raw && raw.ssData !== undefined ? raw.ssData : raw;
- },
- showToast(message) {
- if (window.wx && window.wx.miniProgram && window.wx.miniProgram.showToast) {
- window.wx.miniProgram.showToast({title: message, icon: "success"});
- } else if (window.SS && window.SS.dom && window.SS.dom.showToast) {
- window.SS.dom.showToast({message, type: "success"});
- }
- }
- }
- });
- });
- </script>
- </body>
- </html>
|