index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view class="box" v-if="stuts">
  3. <view class="box_title">
  4. 生成学生借用二维码
  5. </view>
  6. <view class="">
  7. <uni-forms ref="form" :modelValue="formData" :rules="rules">
  8. <uni-forms-item label="姓名" name="name">
  9. <uni-easyinput type="text" v-model="formData.name" placeholder="请输入姓名" />
  10. </uni-forms-item>
  11. <uni-forms-item label="班级" name="class">
  12. <uni-easyinput type="text" v-model="formData.class" placeholder="例:遥感20-1班" />
  13. </uni-forms-item>
  14. </uni-forms>
  15. <button style="background-color:#2d8cf0 ; color: #fff; margin-bottom: 20rpx;" @click="submit">生成二维码</button>
  16. </view>
  17. </view>
  18. <view class="box" v-else>
  19. <view class="box_stuent">
  20. <view class="" style="position: absolute;" @click="fanhui">
  21. <uni-icons type="left" size="28"></uni-icons>
  22. </view>
  23. <view class="box_title">
  24. 学生仪器借用码
  25. </view>
  26. <view class="box_bane">
  27. 姓名:{{studentData1.student_name}}
  28. </view>
  29. <view class="box_bane">
  30. 班级:{{studentData1.student_class}}
  31. </view>
  32. </view>
  33. <view class="erweima">
  34. <uv-qrcode ref="qrcode" :value="qrCodeValue" :options="qrCodeOptions"></uv-qrcode>
  35. </view>
  36. <view class="box_tixing">
  37. 建议截图保存,以免退出重新获取
  38. </view>
  39. </view>
  40. </template>
  41. <script setup>
  42. import {
  43. reactive,
  44. ref
  45. } from 'vue'
  46. // onShow是uni-app中的一个全局生命周期函数,当页面从后台进入前台显示时会被触发。
  47. import {
  48. onShow,
  49. onUnload
  50. } from '@dcloudio/uni-app'
  51. import {requestApi } from '@/api/request.js'
  52. const formData = ref({
  53. name: '',
  54. class: '',
  55. phone: '',
  56. })
  57. const formData1 = ref({
  58. student_name: '',
  59. student_class: '',
  60. student_phone: '',
  61. })
  62. let studentData = wx.getStorageSync('studentData')
  63. // console.log(userInfo)
  64. formData.value.phone = studentData.phone_info.phoneNumber
  65. // console.log(formData.value.phone)
  66. let stuts = ref(true)
  67. let studentData1=ref(null)
  68. studentData1.value = wx.getStorageSync('studentData1')
  69. onShow(async () => {
  70. if(studentData1.value.student_phone==null){
  71. stuts.value = true;
  72. }else{
  73. stuts.value = false;
  74. }
  75. })
  76. function fanhui(){
  77. stuts.value = true;
  78. }
  79. console.log(stuts)
  80. // 定义表单验证规则
  81. const rules = reactive({
  82. name: {
  83. rules: [{
  84. required: true,
  85. errorMessage: '请输入姓名',
  86. },
  87. {
  88. minLength: 2,
  89. maxLength: 5,
  90. errorMessage: '姓名不符',
  91. },
  92. {
  93. validator: (rule, value) => /^[\u4e00-\u9fa5]+$/.test(value),
  94. errorMessage: '姓名只能为中文',
  95. }
  96. ]
  97. },
  98. class: {
  99. rules: [{
  100. required: true,
  101. errorMessage: '请输入班级',
  102. },
  103. {
  104. minLength: 3,
  105. maxLength: 10,
  106. errorMessage: '班级长度至少{minLength} 个字符',
  107. }
  108. ]
  109. },
  110. });
  111. // 提交表单
  112. const form = ref(null);
  113. async function submit(){
  114. form.value.validate().then(res => {
  115. console.log('表单数据信息:', res)
  116. formData.value.class=res.class
  117. formData.value.name=res.name
  118. formData1.value.student_name=res.name
  119. formData1.value.student_class=res.class
  120. formData1.value.student_phone=formData.value.phone
  121. console.log('w',formData1.value)
  122. wx.setStorageSync('studentData1',formData1.value)
  123. // const studata = requestApi('api/Student/Register?server=1')
  124. const studata= requestApi(
  125. 'api/Student/RegisterEdit?server=1',
  126. {
  127. student_name:res.name,
  128. student_class:res.class,
  129. student_phone:formData.value.phone
  130. },
  131. 'POST'
  132. )
  133. console.log(studata)
  134. studentData1.value = wx.getStorageSync('studentData1')
  135. stuts.value = false;
  136. }).catch(err => {
  137. console.log('表单错误信息:', err);
  138. });
  139. };
  140. // 二维码
  141. const qrCodeValue = ref(formData.value.phone);
  142. const qrCodeOptions = ref({
  143. data: qrCodeValue,
  144. size: 300,
  145. useDynamicSize: false,
  146. errorCorrectLevel: 'Q',
  147. margin: 10,
  148. // areaColor: "#2d8cf0",
  149. backgroundColor: "#fff",
  150. foregroundImageSrc: '/static/img/logo2.png'
  151. });
  152. </script>
  153. <style lang="less">
  154. page {
  155. background-color: aliceblue;
  156. }
  157. .box {
  158. width: 85%;
  159. // height: 480rpx;
  160. background-color: #fff;
  161. margin: 30rpx auto;
  162. border-radius: 20rpx;
  163. padding: 30rpx;
  164. }
  165. .box_title {
  166. text-align: center;
  167. font-size: 40rpx;
  168. font-weight: bold;
  169. }
  170. .box_title {
  171. margin-bottom: 40rpx;
  172. margin-top: 10rpx;
  173. }
  174. .box_stuent {
  175. font-size: 33rpx;
  176. font-weight: bold;
  177. }
  178. .box_bane {
  179. line-height: 60rpx;
  180. }
  181. .erweima {
  182. text-align: center;
  183. width: 200px;
  184. margin: 0 auto;
  185. }
  186. .box_tixing {
  187. text-align: center;
  188. color: #808695;
  189. }
  190. </style>