mp_sswjjl_jt_students.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8"/>
  5. <meta name="viewport"
  6. content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  7. <title>违纪学员</title>
  8. <script src="/js/mp_base/base.js?v=20261120-jt-students-no-back"></script>
  9. <style>
  10. [v-cloak] { display: none !important; }
  11. :root {
  12. --line: #e5e7eb;
  13. --text: #222;
  14. --muted: #8b95a5;
  15. --blue: #2f6fed;
  16. --danger: #e5484d;
  17. }
  18. * { box-sizing: border-box; }
  19. body {
  20. margin: 0;
  21. color: var(--text);
  22. background: #f3f4f6;
  23. font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
  24. "Microsoft YaHei", sans-serif;
  25. }
  26. #app {
  27. min-height: 100vh;
  28. padding-bottom: 20px;
  29. }
  30. .topbar {
  31. position: relative;
  32. display: flex;
  33. align-items: center;
  34. justify-content: center;
  35. height: 52px;
  36. padding: 0 14px;
  37. background: #fff;
  38. border-bottom: 1px solid var(--line);
  39. }
  40. .topbar-title {
  41. overflow: hidden;
  42. font-size: 17px;
  43. font-weight: 700;
  44. text-overflow: ellipsis;
  45. white-space: nowrap;
  46. }
  47. .content { padding: 12px 14px; }
  48. .summary {
  49. margin-bottom: 10px;
  50. color: var(--muted);
  51. font-size: 13px;
  52. line-height: 1.5;
  53. }
  54. .student-card-list {
  55. display: grid;
  56. gap: 10px;
  57. }
  58. .swipe-row {
  59. position: relative;
  60. overflow: hidden;
  61. background: #fff;
  62. border: 1px solid var(--line);
  63. border-radius: 6px;
  64. touch-action: pan-y;
  65. }
  66. .student-remove {
  67. position: absolute;
  68. top: 0;
  69. right: 0;
  70. bottom: 0;
  71. width: 72px;
  72. padding: 0;
  73. color: #fff;
  74. background: var(--blue);
  75. border: 0;
  76. border-radius: 0 5px 5px 0;
  77. font: inherit;
  78. font-size: 15px;
  79. transform: translateX(72px);
  80. transition: transform .18s ease;
  81. z-index: 2;
  82. }
  83. .student-content {
  84. position: relative;
  85. min-height: 64px;
  86. padding: 12px 18px 12px 14px;
  87. background: #fff;
  88. transition: transform .18s ease;
  89. z-index: 1;
  90. }
  91. .student-content::after {
  92. content: "";
  93. position: absolute;
  94. top: 0;
  95. right: 0;
  96. bottom: 0;
  97. width: 6px;
  98. background: #007aff;
  99. }
  100. .swipe-row.dragging .student-remove,
  101. .swipe-row.dragging .student-content { transition: none; }
  102. .item-main {
  103. font-size: 15px;
  104. font-weight: 600;
  105. line-height: 1.35;
  106. }
  107. .item-sub {
  108. margin-top: 4px;
  109. color: var(--muted);
  110. font-size: 13px;
  111. line-height: 1.4;
  112. }
  113. .empty,
  114. .loading,
  115. .error {
  116. padding: 28px 14px;
  117. color: var(--muted);
  118. background: #fff;
  119. border: 1px solid var(--line);
  120. border-radius: 6px;
  121. text-align: center;
  122. font-size: 14px;
  123. line-height: 1.6;
  124. }
  125. .error { color: var(--danger); }
  126. </style>
  127. </head>
  128. <body>
  129. <div id="app" v-cloak>
  130. <div class="topbar">
  131. <div class="topbar-title">违纪学员</div>
  132. </div>
  133. <div v-if="loading" class="content"><div class="loading">加载中...</div></div>
  134. <div v-else-if="errorMsg" class="content"><div class="error">{{ errorMsg }}</div></div>
  135. <div v-else class="content">
  136. <div class="summary">
  137. 本次保留 {{ roomInfo.students.length }} 人<template v-if="removedCount">,已移除 {{ removedCount }} 人</template>。
  138. 向左滑动学员卡片可将其移出本次违纪名单。
  139. </div>
  140. <div v-if="!roomInfo.students.length" class="empty">
  141. 本次违纪学员已全部移除,请返回录入页重新选择房间并至少保留一名学员。
  142. </div>
  143. <div v-else class="student-card-list">
  144. <div
  145. v-for="student in roomInfo.students"
  146. :key="student.ryid"
  147. class="swipe-row"
  148. :class="{ dragging: activeRyid === String(student.ryid) }"
  149. @pointerdown.stop="onPointerStart(student, $event)"
  150. @pointermove.stop="onPointerMove($event)"
  151. @pointerup.stop="onPointerEnd($event)"
  152. @pointercancel.stop="onPointerEnd($event)"
  153. @touchstart.stop="onTouchStart(student, $event)"
  154. @touchmove.stop="onTouchMove($event)"
  155. @touchend.stop="onTouchEnd"
  156. @touchcancel.stop="onTouchEnd"
  157. @click.stop="toggleActions(student)"
  158. >
  159. <button
  160. type="button"
  161. class="student-remove"
  162. :style="{ transform: 'translateX(' + actionOffset(student) + 'px)' }"
  163. @click.stop="removeStudent(student)"
  164. >移除</button>
  165. <div
  166. class="student-content"
  167. :style="{ transform: 'translateX(' + rowOffset(student) + 'px)' }"
  168. >
  169. <div class="item-main">{{ student.xm }}</div>
  170. <div class="item-sub">
  171. {{ student.cwmc || '未分配床位' }}
  172. <template v-if="student.bjmc"> · {{ student.bjmc }}</template>
  173. </div>
  174. </div>
  175. </div>
  176. </div>
  177. </div>
  178. </div>
  179. <script>
  180. window.SS.ready(function () {
  181. window.SS.dom.initializeFormApp({
  182. el: "#app",
  183. data() {
  184. return {
  185. loading: true,
  186. errorMsg: "",
  187. stateKey: "mp_sswjjl_jt_inp_state",
  188. jzwid: "",
  189. kfid: "",
  190. activeRyid: "",
  191. openRyid: "",
  192. dragOffset: 0,
  193. swipeStartX: 0,
  194. swipeStartY: 0,
  195. swipeStartOffset: 0,
  196. swipeHorizontal: false,
  197. suppressClickUntil: 0,
  198. roomInfo: {
  199. students: [],
  200. originalStudents: [],
  201. bjList: [],
  202. xymcStr: "",
  203. bjmcStr: ""
  204. }
  205. };
  206. },
  207. computed: {
  208. removedCount() {
  209. return Math.max(0,
  210. (this.roomInfo.originalStudents || []).length - this.roomInfo.students.length);
  211. }
  212. },
  213. async mounted() {
  214. const params = this.getUrlParams();
  215. this.jzwid = String(params.jzwid || "");
  216. this.kfid = String(params.kfid || "");
  217. if (!this.jzwid || !this.kfid) {
  218. this.errorMsg = "缺少房间参数";
  219. this.loading = false;
  220. return;
  221. }
  222. try {
  223. if (this.restoreFromInput()) {
  224. this.loading = false;
  225. return;
  226. }
  227. await this.loadRoom();
  228. this.persistInputState();
  229. } catch (error) {
  230. this.errorMsg = error.message || "学员名单加载失败";
  231. } finally {
  232. this.loading = false;
  233. }
  234. },
  235. methods: {
  236. restoreFromInput() {
  237. try {
  238. const raw = sessionStorage.getItem(this.stateKey);
  239. if (!raw) return false;
  240. const state = JSON.parse(raw);
  241. const form = state && state.form ? state.form : {};
  242. if (String(form.jzwid || "") !== this.jzwid
  243. || String(form.kfid || "") !== this.kfid
  244. || !state.roomInfo
  245. || !Array.isArray(state.roomInfo.students)) {
  246. return false;
  247. }
  248. this.roomInfo = this.normalizeRoomInfo(state.roomInfo);
  249. return true;
  250. } catch (error) {
  251. console.warn("[mp_sswjjl_jt_students] 恢复名单失败", error);
  252. return false;
  253. }
  254. },
  255. async loadRoom() {
  256. const response = await this.postService(
  257. "/service?ssServ=sswjjl_mpLoadRoom&ssDest=data",
  258. {jzwid: this.jzwid, kfid: this.kfid}
  259. );
  260. const students = Array.isArray(response.students) ? response.students : [];
  261. this.roomInfo = {
  262. students: JSON.parse(JSON.stringify(students)),
  263. originalStudents: JSON.parse(JSON.stringify(students)),
  264. bjList: response.bjList || [],
  265. xymcStr: response.xymcStr || "",
  266. bjmcStr: response.bjmcStr || ""
  267. };
  268. },
  269. normalizeRoomInfo(raw) {
  270. const source = raw && typeof raw === "object" ? raw : {};
  271. const students = Array.isArray(source.students)
  272. ? JSON.parse(JSON.stringify(source.students)) : [];
  273. const originalStudents = Array.isArray(source.originalStudents)
  274. ? JSON.parse(JSON.stringify(source.originalStudents))
  275. : JSON.parse(JSON.stringify(students));
  276. return {
  277. students,
  278. originalStudents,
  279. bjList: Array.isArray(source.bjList)
  280. ? JSON.parse(JSON.stringify(source.bjList)) : [],
  281. xymcStr: source.xymcStr || "",
  282. bjmcStr: source.bjmcStr || ""
  283. };
  284. },
  285. persistInputState() {
  286. try {
  287. const raw = sessionStorage.getItem(this.stateKey);
  288. const state = raw ? JSON.parse(raw) : {};
  289. const form = state.form && typeof state.form === "object" ? state.form : {};
  290. form.jzwid = this.jzwid;
  291. form.kfid = this.kfid;
  292. state.version = 1;
  293. state.form = form;
  294. state.roomInfo = JSON.parse(JSON.stringify(this.roomInfo));
  295. sessionStorage.setItem(this.stateKey, JSON.stringify(state));
  296. } catch (error) {
  297. console.warn("[mp_sswjjl_jt_students] 保存名单失败", error);
  298. }
  299. },
  300. recomputeRoomSummary() {
  301. const classMap = new Map();
  302. const studentTexts = [];
  303. for (const student of this.roomInfo.students) {
  304. const bjid = String(student.bjid || "");
  305. if (bjid) classMap.set(bjid, student.bjmc || "");
  306. studentTexts.push(student.xm + "("
  307. + (student.cwmc || "未分配床位") + ")");
  308. }
  309. this.roomInfo.bjList = Array.from(classMap.entries()).map(
  310. ([bjid, bjmc]) => ({bjid, bjmc}));
  311. this.roomInfo.xymcStr = studentTexts.join(",");
  312. this.roomInfo.bjmcStr = this.roomInfo.bjList.map(item => item.bjmc).join(",");
  313. },
  314. removeStudent(student) {
  315. if (!student) return;
  316. const ryid = String(student.ryid);
  317. this.roomInfo.students = this.roomInfo.students.filter(
  318. item => String(item.ryid) !== ryid);
  319. this.recomputeRoomSummary();
  320. this.persistInputState();
  321. this.openRyid = "";
  322. this.activeRyid = "";
  323. this.dragOffset = 0;
  324. this.swipeHorizontal = false;
  325. this.showToast("已从本次违纪名单移除");
  326. },
  327. eventPoint(event) {
  328. return (event.changedTouches && event.changedTouches[0])
  329. || (event.touches && event.touches[0])
  330. || event;
  331. },
  332. onTouchStart(student, event) {
  333. const touch = this.eventPoint(event);
  334. if (!touch) return;
  335. const ryid = String(student.ryid);
  336. if (this.openRyid && this.openRyid !== ryid) this.openRyid = "";
  337. this.activeRyid = ryid;
  338. this.swipeStartX = touch.clientX;
  339. this.swipeStartY = touch.clientY;
  340. this.swipeStartOffset = this.openRyid === ryid ? -72 : 0;
  341. this.dragOffset = this.swipeStartOffset;
  342. this.swipeHorizontal = false;
  343. },
  344. onTouchMove(event) {
  345. if (!this.activeRyid) return;
  346. const touch = this.eventPoint(event);
  347. if (!touch) return;
  348. const dx = touch.clientX - this.swipeStartX;
  349. const dy = touch.clientY - this.swipeStartY;
  350. if (!this.swipeHorizontal) {
  351. if (Math.abs(dx) < 5 && Math.abs(dy) < 5) return;
  352. if (Math.abs(dx) <= Math.abs(dy)) return;
  353. this.swipeHorizontal = true;
  354. }
  355. if (event.cancelable) event.preventDefault();
  356. this.dragOffset = Math.max(-72, Math.min(0, this.swipeStartOffset + dx));
  357. },
  358. onTouchEnd(event) {
  359. if (!this.activeRyid) return;
  360. const touch = this.eventPoint(event);
  361. let horizontal = this.swipeHorizontal;
  362. let finalOffset = this.dragOffset;
  363. if (touch) {
  364. const dx = touch.clientX - this.swipeStartX;
  365. const dy = touch.clientY - this.swipeStartY;
  366. if (Math.abs(dx) > 30 && Math.abs(dx) > Math.abs(dy)) {
  367. horizontal = true;
  368. finalOffset = Math.max(-72, Math.min(0, this.swipeStartOffset + dx));
  369. }
  370. }
  371. if (horizontal) {
  372. this.openRyid = finalOffset <= -30 ? this.activeRyid : "";
  373. this.suppressClickUntil = Date.now() + 350;
  374. }
  375. this.activeRyid = "";
  376. this.dragOffset = 0;
  377. this.swipeHorizontal = false;
  378. },
  379. toggleActions(student) {
  380. if (!student || Date.now() < this.suppressClickUntil) return;
  381. const ryid = String(student.ryid);
  382. this.openRyid = this.openRyid === ryid ? "" : ryid;
  383. },
  384. onPointerStart(student, event) {
  385. if (event.pointerType === "touch") return;
  386. if (event.currentTarget
  387. && typeof event.currentTarget.setPointerCapture === "function") {
  388. event.currentTarget.setPointerCapture(event.pointerId);
  389. }
  390. this.onTouchStart(student, event);
  391. },
  392. onPointerMove(event) {
  393. if (event.pointerType === "touch") return;
  394. this.onTouchMove(event);
  395. },
  396. onPointerEnd(event) {
  397. if (event.pointerType === "touch") return;
  398. this.onTouchEnd(event);
  399. },
  400. rowOffset(student) {
  401. const ryid = String(student.ryid);
  402. if (this.activeRyid === ryid) return this.dragOffset;
  403. return this.openRyid === ryid ? -72 : 0;
  404. },
  405. actionOffset(student) {
  406. return 72 + this.rowOffset(student);
  407. },
  408. getUrlParams() {
  409. const params = {};
  410. const search = new URLSearchParams(window.location.search);
  411. for (const [key, value] of search) params[key] = decodeURIComponent(value);
  412. return params;
  413. },
  414. getRequest() {
  415. return window.request || (typeof request !== "undefined" ? request : null);
  416. },
  417. async postService(url, data) {
  418. const req = this.getRequest();
  419. if (!req || typeof req.post !== "function") throw new Error("请求组件未加载");
  420. const response = await req.post(url, data, {loading: false, formData: true});
  421. const raw = response && response.data !== undefined ? response.data : response;
  422. if (raw && raw.ssCode !== undefined && Number(raw.ssCode) !== 0) {
  423. throw new Error(raw.ssMsg || "请求失败");
  424. }
  425. return raw && raw.ssData !== undefined ? raw.ssData : raw;
  426. },
  427. showToast(message) {
  428. if (window.wx && window.wx.miniProgram && window.wx.miniProgram.showToast) {
  429. window.wx.miniProgram.showToast({title: message, icon: "success"});
  430. } else if (window.SS && window.SS.dom && window.SS.dom.showToast) {
  431. window.SS.dom.showToast({message, type: "success"});
  432. }
  433. }
  434. }
  435. });
  436. });
  437. </script>
  438. </body>
  439. </html>