123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <template>
- <view class="box" v-if="stuts">
- <view class="box_title">
- 生成学生借用二维码
- </view>
- <view class="">
- <uni-forms ref="form" :modelValue="formData" :rules="rules">
- <uni-forms-item label="姓名" name="name">
- <uni-easyinput type="text" v-model="formData.name" placeholder="请输入姓名" />
- </uni-forms-item>
- <uni-forms-item label="班级" name="class">
- <uni-easyinput type="text" v-model="formData.class" placeholder="例:遥感20-1班" />
- </uni-forms-item>
- </uni-forms>
- <button style="background-color:#2d8cf0 ; color: #fff; margin-bottom: 20rpx;" @click="submit">生成二维码</button>
- </view>
- </view>
- <view class="box" v-else>
- <view class="box_stuent">
- <view class="" style="position: absolute;" @click="fanhui">
- <uni-icons type="left" size="28"></uni-icons>
- </view>
- <view class="box_title">
- 学生仪器借用码
- </view>
- <view class="box_bane">
- 姓名:{{studentData1.student_name}}
- </view>
- <view class="box_bane">
- 班级:{{studentData1.student_class}}
- </view>
- </view>
- <view class="erweima">
- <uv-qrcode ref="qrcode" :value="qrCodeValue" :options="qrCodeOptions"></uv-qrcode>
- </view>
- <view class="box_tixing">
- 建议截图保存,以免退出重新获取
- </view>
- </view>
- </template>
- <script setup>
- import {
- reactive,
- ref
- } from 'vue'
-
- import {
- onShow,
- onUnload
- } from '@dcloudio/uni-app'
- import {requestApi } from '@/api/request.js'
- const formData = ref({
- name: '',
- class: '',
- phone: '',
- })
- const formData1 = ref({
- student_name: '',
- student_class: '',
- student_phone: '',
- })
- let studentData = wx.getStorageSync('studentData')
-
- formData.value.phone = studentData.phone_info.phoneNumber
-
- let stuts = ref(true)
- let studentData1=ref(null)
- studentData1.value = wx.getStorageSync('studentData1')
- onShow(async () => {
- if(studentData1.value.student_phone==null){
- stuts.value = true;
- }else{
- stuts.value = false;
- }
- })
- function fanhui(){
- stuts.value = true;
- }
- console.log(stuts)
-
- const rules = reactive({
- name: {
- rules: [{
- required: true,
- errorMessage: '请输入姓名',
- },
- {
- minLength: 2,
- maxLength: 5,
- errorMessage: '姓名不符',
- },
- {
- validator: (rule, value) => /^[\u4e00-\u9fa5]+$/.test(value),
- errorMessage: '姓名只能为中文',
- }
- ]
- },
- class: {
- rules: [{
- required: true,
- errorMessage: '请输入班级',
- },
- {
- minLength: 3,
- maxLength: 10,
- errorMessage: '班级长度至少{minLength} 个字符',
- }
- ]
- },
- });
-
- const form = ref(null);
-
- async function submit(){
- form.value.validate().then(res => {
- console.log('表单数据信息:', res)
- formData.value.class=res.class
- formData.value.name=res.name
- formData1.value.student_name=res.name
- formData1.value.student_class=res.class
- formData1.value.student_phone=formData.value.phone
- console.log('w',formData1.value)
-
- wx.setStorageSync('studentData1',formData1.value)
-
- const studata= requestApi(
- 'api/Student/RegisterEdit?server=1',
- {
- student_name:res.name,
- student_class:res.class,
- student_phone:formData.value.phone
- },
- 'POST'
- )
- console.log(studata)
- studentData1.value = wx.getStorageSync('studentData1')
- stuts.value = false;
- }).catch(err => {
- console.log('表单错误信息:', err);
- });
- };
-
- const qrCodeValue = ref(formData.value.phone);
- const qrCodeOptions = ref({
- data: qrCodeValue,
- size: 300,
- useDynamicSize: false,
- errorCorrectLevel: 'Q',
- margin: 10,
-
- backgroundColor: "#fff",
- foregroundImageSrc: '/static/img/logo2.png'
- });
- </script>
- <style lang="less">
- page {
- background-color: aliceblue;
- }
- .box {
- width: 85%;
- // height: 480rpx;
- background-color: #fff;
- margin: 30rpx auto;
- border-radius: 20rpx;
- padding: 30rpx;
- }
- .box_title {
- text-align: center;
- font-size: 40rpx;
- font-weight: bold;
- }
- .box_title {
- margin-bottom: 40rpx;
- margin-top: 10rpx;
- }
- .box_stuent {
- font-size: 33rpx;
- font-weight: bold;
- }
- .box_bane {
- line-height: 60rpx;
- }
- .erweima {
- text-align: center;
- width: 200px;
- margin: 0 auto;
- }
- .box_tixing {
- text-align: center;
- color: #808695;
- }
- </style>
|