当前位置:   article > 正文

记录一个vue编辑的移动端页面

记录一个vue编辑的移动端页面

  1. <template>
  2. <div class="wrap">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="120px">
  4. <el-form-item label="班级" prop="classId" required style="width: 100%;">
  5. <template v-if="oroles == 'teacher_director'">
  6. <el-select v-model="queryParams.classId" placeholder="请选择班级" @change="seletChange">
  7. <el-option v-for="item in classList" :key="item.deptId" :label="item.deptName" :value="item.deptId">
  8. </el-option>
  9. </el-select>
  10. </template>
  11. <template v-else>
  12. <div>{{ classList[0] ? classList[0].deptName : '' }}</div>
  13. </template>
  14. </el-form-item>
  15. <el-form-item label="选择学生" prop="student" required>
  16. <el-button size="mini" @click="openStudent">点击选择</el-button>
  17. <div class="checked-student" v-if="checkedStudent">
  18. <!-- <el-image style="width: 60px; height: 60px; border-radius: 50%;" :src="checkedStudent.headUrl" fit="cover"></el-image> -->
  19. <div class="student-mes">
  20. <div class="d1">{{ checkedStudent.number }}号</div>
  21. <!-- <div class="d2">{{ checkedStudent.name }}</div> -->
  22. </div>
  23. </div>
  24. </el-form-item>
  25. <el-form-item label="性别" prop="sex">
  26. <el-radio v-model="queryParams.sex" label="0"></el-radio>
  27. <el-radio v-model="queryParams.sex" label="1"></el-radio>
  28. </el-form-item>
  29. <el-form-item label="生日" prop="birthday">
  30. <el-date-picker clearable v-model="queryParams.birthday" type="date" value-format="yyyy-MM-dd" placeholder="请选择生日">
  31. </el-date-picker>
  32. </el-form-item>
  33. <el-form-item label="身高" prop="height">
  34. <div class="input-wrap">
  35. <el-input type="number" oninput="if(value.length>5)value=value.slice(0,5)" v-model="queryParams.height" placeholder="请输入身高" />
  36. <div class="d1">(cm)</div>
  37. </div>
  38. </el-form-item>
  39. <el-form-item label="体重" prop="weight">
  40. <div class="input-wrap">
  41. <el-input type="number" oninput="if(value.length>5)value=value.slice(0,5)" v-model="queryParams.weight" placeholder="请输入体重" />
  42. <div class="d1">(kg)</div>
  43. </div>
  44. </el-form-item>
  45. <el-form-item label="坐位体前屈" prop="flexibility">
  46. <div class="input-wrap">
  47. <el-input type="number" oninput="if(value.length>5)value=value.slice(0,5)" v-model="queryParams.flexibility" placeholder="请输入" />
  48. <div class="d1">(cm)</div>
  49. </div>
  50. </el-form-item>
  51. <el-form-item label="立定跳远" prop="downStrength">
  52. <div class="input-wrap">
  53. <el-input type="number" oninput="if(value.length>5)value=value.slice(0,5)" v-model="queryParams.downStrength" placeholder="请输入" />
  54. <div class="d1">(cm)</div>
  55. </div>
  56. </el-form-item>
  57. <el-form-item :label="physicalVersion == '2' ? '握力' : '网球掷远'" prop="upStrength">
  58. <div class="input-wrap">
  59. <el-input type="number" oninput="if(value.length>5)value=value.slice(0,5)" v-model="queryParams.upStrength" placeholder="请输入" />
  60. <div class="d1">{{ physicalVersion == '2' ? '(kg)' : '(m)' }}</div>
  61. </div>
  62. </el-form-item>
  63. <el-form-item label="平衡木" prop="balance">
  64. <div class="input-wrap">
  65. <el-input type="number" oninput="if(value.length>5)value=value.slice(0,5)" v-model="queryParams.balance" placeholder="请输入" />
  66. <div class="d1">(s)</div>
  67. </div>
  68. </el-form-item>
  69. <el-form-item label="双脚连跳" prop="coordination">
  70. <div class="input-wrap">
  71. <el-input type="number" oninput="if(value.length>5)value=value.slice(0,5)" v-model="queryParams.coordination" placeholder="请输入" />
  72. <div class="d1">(s)</div>
  73. </div>
  74. </el-form-item>
  75. <el-form-item :label="physicalVersion == '2' ? '15米绕障碍跑' : '10米折返跑'" prop="sensitivity">
  76. <div class="input-wrap">
  77. <el-input type="number" oninput="if(value.length>5)value=value.slice(0,5)" v-model="queryParams.sensitivity" placeholder="请输入" />
  78. <div class="d1">{{ physicalVersion == '2' ? '(s)' : '(s)' }}</div>
  79. </div>
  80. </el-form-item>
  81. <el-form-item label=" " prop="" size="medium">
  82. <div class="pop-footer">
  83. <div class="b1" @click="prev">返回</div>
  84. <div class="b2" @click="save">保存</div>
  85. </div>
  86. </el-form-item>
  87. </el-form>
  88. <div class="mask" v-if="open"></div>
  89. <!-- 选择学生 -->
  90. <div class="pop-box" v-if="open">
  91. <div class="student-header">
  92. <div class="d1">请选择学生</div>
  93. <div class="close-wrap" @click="cancel">
  94. <i class="el-icon-close"></i>
  95. </div>
  96. </div>
  97. <div class="student-main">
  98. <div class="student-list" v-for="(item,index) in reportRecordDetailList" :key="item.id" @click="studentHandle(index)">
  99. <div class="img-wrap">
  100. <img src="@/assets/images/complet.png" class="icon-complet" v-if="item.status == 1" />
  101. <!-- <i class="el-icon-success" v-if="item.checked"></i> -->
  102. </div>
  103. <div class="student-mes" :class="{ active: item.checked }">
  104. <div class="d1">{{ item.number }}号</div>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </template>
  111. <script>
  112. import { listDeptAll,listReportRecordDetail, getReportRecordDetail, delReportRecordDetail, addReportRecordDetail, updateReportRecordDetail } from "@/api/school/reportRecordDetail";
  113. import { listDept } from "@/api/system/dept";
  114. export default {
  115. metaInfo() {
  116. return {
  117. title: this.PageTitle,
  118. titleTemplate: null,//不加这个会有个默认的后缀
  119. meta: [
  120. {
  121. name: "viewport",
  122. content: 'width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no',
  123. },
  124. ],
  125. };
  126. },
  127. // metaInfo: {
  128. // //title: '详情页',
  129. // meta: [
  130. // { charset: 'utf-8' },
  131. // { name: 'viewport', content: 'width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no' }
  132. // ]
  133. // },
  134. name: "ReportRecordDetail",
  135. data() {
  136. return {
  137. // 班级数据
  138. classList: [],
  139. queryParams: {
  140. classId: null,
  141. recordId: null,//上级目录id
  142. id: null,//学生列表里的id(修改则必填 新增的时候没有id)
  143. sid: null,//选中的学生id
  144. sex: null,//性别 2是未知 0男 1女
  145. birthday: null,
  146. height: null,
  147. weight: null,
  148. flexibility: null,
  149. downStrength: null,
  150. upStrength: null,
  151. balance: null,
  152. coordination: null,
  153. sensitivity: null,
  154. },
  155. ouser: null,//用户信息
  156. checkedStudent: null,//选中的学生信息
  157. reportRecordDetailList: [],// 体测数据,录入学生数据表格数据
  158. oroles: null,//角色
  159. studentIndex: null,
  160. physicalVersion: null,//版本
  161. // 遮罩层
  162. loading: true,
  163. // 选中数组
  164. ids: [],
  165. // 非单个禁用
  166. single: true,
  167. // 非多个禁用
  168. multiple: true,
  169. // 显示搜索条件
  170. // 总条数
  171. total: 0,
  172. // 弹出层标题
  173. title: "",
  174. // 是否显示弹出层
  175. open: false,
  176. // 查询参数
  177. // 表单参数
  178. form: {},
  179. name: null,
  180. PageTitle: null,
  181. isclock: false,
  182. };
  183. },
  184. watch: {
  185. selectedValue(newValue, oldValue) {
  186. // 当selectedValue变化时,这个函数会被调用
  187. // newValue是新选中的值,oldValue是之前的值
  188. console.log('选中的值变化了', newValue, oldValue);
  189. // 在这里可以执行其他逻辑
  190. }
  191. },
  192. created() {
  193. this.ouser = this.$store.state.user;
  194. this.reportRecordDetailList = [];//重置学生列表
  195. this.queryParams.recordId = this.$route.params.id
  196. this.physicalVersion = this.$route.params.physicalVersion
  197. this.name = this.$route.params.name
  198. //如果用户直接访问这个页面 给它跳转到列表页
  199. if(!this.queryParams.recordId){
  200. this.$router.push({ path: '/reportRecord' })
  201. }
  202. //判断当前老师是不是混龄班级的老师teacher_director
  203. this.oroles = this.ouser.roles[0]
  204. if(this.oroles == 'teacher_director'){
  205. this.getClassListAll();
  206. }else{
  207. this.getClassList();
  208. }
  209. },
  210. mounted() {
  211. this.PageTitle = this.name
  212. },
  213. methods: {
  214. seletChange(val){
  215. if(val){
  216. this.checkedStudent = null
  217. this.resetInput()
  218. }
  219. },
  220. prev(){
  221. this.$router.go(-1); // 返回上一页
  222. },
  223. /** 查询班级列表 */
  224. getClassListAll() {
  225. listDeptAll({ deptType: 3, parentId: this.ouser.schoolId, status :0 }).then(response => {
  226. this.classList = response.data;
  227. });
  228. },
  229. save(){
  230. if(this.isclock) return
  231. this.isclock = true
  232. if(!this.checkedStudent){
  233. this.$modal.msgError("请先选择学生");
  234. this.isclock = true
  235. return
  236. }
  237. this.queryParams.sid = this.checkedStudent.sid
  238. if(this.checkedStudent.id){
  239. this.queryParams.id = this.checkedStudent.id
  240. }else{
  241. this.queryParams.id = null
  242. }
  243. //新增/编辑
  244. addReportRecordDetail(this.queryParams).then(res => {
  245. //this.$modal.msgSuccess("新增成功");
  246. this.checkedStudent.id = res.data.id //ly-add
  247. this.$modal.confirm(this.checkedStudent.number + '号学生数据保存成功,继续提交下一位同学?').then(() => {
  248. this.isclock = false
  249. this.queryParams.id = null
  250. this.queryParams.sid = null
  251. this.resetInput()
  252. //studentIndex 学生下标 如果学生下标+1 有sid 那么就是有学生 如果没有sid 则最后一个学生了
  253. //学生列表 this.reportRecordDetailList
  254. let olist = this.reportRecordDetailList
  255. if(olist[this.studentIndex + 1].sid){
  256. this.checkedStudent = olist[this.studentIndex + 1]
  257. if(olist[this.studentIndex + 1].id){
  258. let slist = olist[this.studentIndex + 1]
  259. //有id代表编辑状态
  260. this.fillValue(slist)
  261. }
  262. this.studentIndex++
  263. }
  264. }).catch(() => {
  265. this.isclock = false
  266. });
  267. }).catch(() => {
  268. this.isclock = false
  269. });;
  270. },
  271. studentHandle(idx){
  272. this.studentIndex = idx; //给选中的下标赋值
  273. let olist = this.reportRecordDetailList
  274. this.reportRecordDetailList.forEach(item => {
  275. item.checked = false; // 重置所有的checked状态为false
  276. })
  277. olist[idx].checked = true
  278. this.reportRecordDetailList = olist
  279. this.checkedStudent = olist[idx]
  280. if(olist[idx].id){
  281. //有id代表编辑状态
  282. this.fillValue(olist[idx])
  283. }else{
  284. this.resetInput()
  285. }
  286. this.open = false
  287. },
  288. fillValue(list){
  289. this.queryParams.sex = list.sex
  290. this.queryParams.birthday = list.birthday
  291. this.queryParams.height = list.height
  292. this.queryParams.weight = list.weight
  293. this.queryParams.flexibility = list.flexibility
  294. this.queryParams.downStrength = list.downStrength
  295. this.queryParams.upStrength = list.upStrength
  296. this.queryParams.balance = list.balance
  297. this.queryParams.coordination = list.coordination
  298. this.queryParams.sensitivity = list.sensitivity
  299. },
  300. resetInput(){
  301. this.queryParams.sex = null
  302. this.queryParams.birthday = null
  303. this.queryParams.height = null
  304. this.queryParams.weight = null
  305. this.queryParams.flexibility = null
  306. this.queryParams.downStrength = null
  307. this.queryParams.upStrength = null
  308. this.queryParams.balance = null
  309. this.queryParams.coordination = null
  310. this.queryParams.sensitivity = null
  311. },
  312. //打开学生列表
  313. openStudent(){
  314. if(!this.queryParams.classId){
  315. this.$modal.msgError("请先选择班级");
  316. return
  317. }
  318. this.getList()
  319. this.open = true
  320. },
  321. /** 查询班级列表 */
  322. getClassList() {
  323. listDept({ deptType: 3, parentId: this.ouser.schoolId }).then(response => {
  324. this.classList = response.data;
  325. this.queryParams.classId = this.classList[0].deptId
  326. });
  327. },
  328. /** 查询体测数据,录入学生数据列表 */
  329. getList() {
  330. //如果班级id为空 则不请求接口
  331. this.loading = true;
  332. let params = {
  333. classId: this.queryParams.classId,
  334. recordId: this.queryParams.recordId
  335. }
  336. listReportRecordDetail(params).then(response => {
  337. response.rows.forEach(item => {
  338. item.checked = false; // 添加checked属性并赋值为false 作为判断是否选中的标识
  339. });
  340. this.reportRecordDetailList = response.rows
  341. //如果已有选中的学生 给选中的学生加个选中状态
  342. if(this.checkedStudent && this.checkedStudent.number){
  343. let oindex = this.reportRecordDetailList.findIndex(item => item.number == this.checkedStudent.number)
  344. this.reportRecordDetailList[oindex].checked = true
  345. }
  346. this.total = response.total;
  347. this.loading = false;
  348. });
  349. },
  350. // 取消按钮
  351. cancel() {
  352. this.open = false;
  353. //this.reset();
  354. },
  355. // 表单重置
  356. reset() {
  357. this.queryParams = {
  358. id: null,
  359. sid: null,
  360. classId: null,
  361. recordId: null,
  362. sex: null,//性别 2是未知 0男 1女
  363. birthday: null,
  364. height: null,
  365. weight: null,
  366. flexibility: null,
  367. downStrength: null,
  368. upStrength: null,
  369. };
  370. this.resetForm("queryParams");//queryForm / form
  371. },
  372. }
  373. };
  374. </script>
  375. <style scoped>
  376. .close-wrap{ width: 40px; height: 40px; display: flex; justify-content: center; align-items: center;}
  377. .close-wrap .el-icon-close{ color: #fff;}
  378. .student-list{ display: flex; flex-direction: column; align-items: center;}
  379. .img-wrap{ position: relative; width: 40px;}
  380. .img-wrap .el-icon-success{ position: absolute; top: -5px; right: -5px; color: #33a9ff;}
  381. .wrap /deep/ .el-scrollbar .el-scrollbar__bar {
  382. opacity: 1 !important;
  383. }
  384. .wrap{ padding: 30px 15px 15px 15px;}
  385. .checked-student{ margin-top: 5px; display: flex; flex-direction: column;}
  386. .student-mes{ width: 40px; height: 40px; text-align: center; line-height: 40px; font-size: 12px; color: #33a9ff; border: 1px solid #33a9ff; border-radius: 50%;}
  387. .student-mes .d2{ margin-left: 5px; max-width: 50px;}
  388. .student-mes.active{ background: #33a9ff; color: #fff;}
  389. .mask{ position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 998; background: rgba(0,0,0,0.3);}
  390. .pop-box{ position: fixed; top: 5%; left: 5%; z-index: 999; box-sizing: border-box; display: flex; flex-direction: column; width: 90%; height: 90%; background: #fff; border-radius: 10px;}
  391. .student-header{ padding-left: 15px; display: flex; justify-content: space-between; align-items: center; height: 40px; background: #33a9ff; font-size: 14px;
  392. color: #fff; border-radius: 10px 10px 0 0;}
  393. .student-main{ align-content:flex-start; padding: 15px 0 10px 0; display: grid; grid-template-columns: repeat(5, 1fr); grid-gap: 10px; flex: 1; overflow-y: scroll;}
  394. .student-img{ display: block; width: 40px; height: 40px; object-fit: cover; border-radius: 50%;}
  395. .icon-complet{ position: absolute; top: -5px; left: -5px; width: 20px;}
  396. .wrap /deep/ .el-form-item__label{ font-weight: 400;}
  397. </style>
  398. <style>
  399. @media (max-width: 720px) {
  400. .el-message-box {
  401. width: 350px !important;
  402. }
  403. }
  404. .pop-footer{ display: flex; justify-content: center; align-items: center; height: 60px;}
  405. .pop-footer .b1,.pop-footer .b2{ width: 80px; height: 36px; text-align: center; line-height: 36px; font-size: 14px; color: #fff; border-radius: 18px;}
  406. .pop-footer .b1{ background: #ffa400;}
  407. .pop-footer .b2{ margin-left: 30px; background: #33a9ff;}
  408. .input-wrap{ position: relative;}
  409. .input-wrap .d1{ position: absolute; top: 0; right: 10px; line-height: 32px; font-size: 12px; color: #33a9ff;}
  410. </style>

起作用的是

  1. main.js
  2. // 头部标签组件 在PC端里使用移动端布局的方法
  3. import VueMeta from 'vue-meta'
  4. Vue.use(VueMeta)
  5. 页面里:
  6. metaInfo() {
  7. return {
  8. title: this.PageTitle,
  9. titleTemplate: null,//不加这个会有个默认的后缀
  10. meta: [
  11. {
  12. name: "viewport",
  13. content: 'width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no',
  14. },
  15. ],
  16. };
  17. },
  18. @media (max-width: 720px) {
  19. .el-message-box {
  20. width: 350px !important;
  21. }
  22. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/244742
推荐阅读
相关标签
  

闽ICP备14008679号