Browse Source

添加协议与授权

lex 2 years ago
parent
commit
37b42df1ea

+ 1 - 1
src/helpers/validate.ts

@@ -19,7 +19,7 @@ export function vaildStudentUrl() {
 }
 
 export function checkPhone(phone: string) {
-  const phoneRule = /^1[3456789]\d{9}$/;
+  const phoneRule = /^((13[0-9])|(14(0|[5-7]|9))|(15([0-3]|[5-9]))|(16(2|[5-7]))|(17[0-8])|(18[0-9])|(19([0-3]|[5-9])))\\d{8}$/;
   return phoneRule.test(phone);
 }
 

+ 8 - 0
src/router/routes-common.ts

@@ -180,6 +180,14 @@ export const rootRouter = [
     }
   },
   {
+    path: '/cashProtocol',
+    name: 'cashProtocol',
+    component: () => import('@/views/preview-protocol/cash-protocol'),
+    meta: {
+      title: '管乐团隐私政策'
+    }
+  },
+  {
     path: '/guide',
     name: 'guide',
     component: () => import('@/views/guide/guide'),

+ 10 - 1
src/school/companion-teacher/companion-teacher-register.module.less

@@ -219,11 +219,20 @@ span {
 
 .protocol {
   display: flex;
-  align-items: center;
+  align-items: flex-start;
   justify-content: center;
+  padding: 0 13px;
   font-size: 12px;
   color: #aaaaaa;
   line-height: 17px;
+  :global {
+    .van-checkbox {
+      flex-shrink: 0;
+    }
+  }
+  & > div {
+    flex: 1 auto;
+  }
 }
 
 .protocol .c {

+ 91 - 52
src/school/companion-teacher/companion-teacher-register.tsx

@@ -29,7 +29,8 @@ import { checkPhone } from '@/helpers/validate'
 import OUpload from '@/components/o-upload'
 import router from '@/router'
 import dayjs from 'dayjs'
-import { browser } from '@/helpers/utils'
+import { browser, getUrlCode } from '@/helpers/utils'
+import qs from 'query-string'
 
 export default defineComponent({
   name: 'companion-teacher-register',
@@ -74,7 +75,8 @@ export default defineComponent({
       countDownTime: 120, // 倒计时时间
       countDownRef: null as any, // 倒计时实例
       imgCodeStatus: false,
-      showPopup: false
+      showPopup: false,
+      code: '' // 授权码
     })
 
     const onSubmit = async () => {
@@ -97,6 +99,7 @@ export default defineComponent({
         await request.post('/api-school/open/schoolTeacherStudent/registerTeacher', {
           data: {
             ...forms,
+            code: state.code,
             subjectIds: forms.subjectIds.join(','),
             schoolId: state.id
           }
@@ -194,10 +197,28 @@ export default defineComponent({
       }
 
       // 判断是否是微信,只能微信中打开
-      // if (!browser().weixin) {
-      //   state.showPopup = true
-      //   return
-      // }
+      if (!browser().weixin) {
+        state.showPopup = true
+        return
+      } else {
+        //授权
+        const code = getUrlCode()
+        if (!code) {
+          const { returnUrl, ...rest } = route.query
+          const newUrl =
+            window.location.origin +
+            window.location.pathname +
+            '#' +
+            returnUrl +
+            '?' +
+            qs.stringify({
+              ...rest
+            })
+          getAppIdAndCode(newUrl)
+        } else {
+          state.code = code
+        }
+      }
 
       // t: route.query.t, // 过期时间
       try {
@@ -269,11 +290,21 @@ export default defineComponent({
       }
     })
 
-    const onPreview = () => {
-      window.open(
-        window.location.origin + window.location.pathname + '#/preview-protocol',
-        '_blank'
-      )
+    const onPreview = (type: any) => {
+      if (type === 'REGISTER') {
+        window.open(
+          window.location.origin + window.location.pathname + '#/preview-protocol',
+          '_blank'
+        )
+      } else if (type === 'PRIVACY') {
+        window.open(
+          window.location.origin + window.location.pathname + '#/privacyProtocol',
+          '_blank'
+        )
+      } else if (type === 'WITHDRAW') {
+        //
+        window.open(window.location.origin + window.location.pathname + '#/cashProtocol', '_blank')
+      }
     }
 
     const formRef = ref()
@@ -288,6 +319,30 @@ export default defineComponent({
       }
     }
 
+    const getAppIdAndCode = async (url?: string) => {
+      try {
+        const { data } = await request.get('/api-school/open/paramConfig/wechatAppId')
+        // 判断是否有微信appId
+        if (data) {
+          closeToast()
+          goAuth(data, url)
+        }
+      } catch {
+        //
+      }
+    }
+    const goAuth = (wxAppId: string, urlString?: string) => {
+      // 用户授权
+      console.log(urlString || window.location.href, 'urlString || window.location.href')
+      const urlNow = encodeURIComponent(urlString || window.location.href)
+      console.log(urlNow, 'urlNow')
+      const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
+      const appid = wxAppId || 'wx8654c671631cfade'
+      const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
+      window.location.replace(url)
+    }
+
+    // 反显数据
     const getTeacherDetails = async () => {
       try {
         if (!state.forms.phone) return
@@ -380,7 +435,6 @@ export default defineComponent({
               name="realName"
               placeholder="请填写真实姓名"
               maxlength="5"
-              disabled={state.checkPhone}
             ></Field>
 
             <Field
@@ -397,7 +451,6 @@ export default defineComponent({
               name="idCardNo"
               maxlength={18}
               placeholder="请输入身份证号码"
-              disabled={state.checkPhone}
             ></Field>
 
             <Field label="性别" name="gender" rules={[{ required: true, message: '请选择性别' }]}>
@@ -407,7 +460,6 @@ export default defineComponent({
                     checked-color="#FF8057"
                     v-model={state.forms.gender}
                     direction="horizontal"
-                    disabled={state.checkPhone}
                   >
                     <Tag
                       size="large"
@@ -447,7 +499,6 @@ export default defineComponent({
                   <OUpload
                     style={{ width: '100%' }}
                     tips="上传身份证正面"
-                    disabled={state.checkPhone}
                     v-model:modelValue={state.forms.idcardFrontImg}
                   />
                 )
@@ -466,7 +517,6 @@ export default defineComponent({
                   <OUpload
                     style={{ width: '100%' }}
                     tips="上传身份证反面"
-                    disabled={state.checkPhone}
                     v-model:modelValue={state.forms.idcardBackImg}
                   />
                 )
@@ -477,25 +527,20 @@ export default defineComponent({
               label="学历"
               v-model={state.forms.educationBackground}
               readonly
-              disabled={state.checkPhone}
               name="educationBackground"
               onClick={() => {
-                if (state.checkPhone) return
                 state.showEducation = true
               }}
               rules={[{ required: true, message: '请选择学历', trigger: 'onChange' }]}
               placeholder="请选择学历"
             >
               {{
-                'right-icon': () => (
-                  <Icon name="arrow" color={state.checkPhone ? '#aaa' : '#323233'} size="16"></Icon>
-                )
+                'right-icon': () => <Icon name="arrow" color={'#323233'} size="16"></Icon>
               }}
             </Field>
 
             <Field
               label="毕业学校"
-              disabled={state.checkPhone}
               v-model={state.forms.graduateSchool}
               rules={[{ required: true, message: '请输入毕业学校' }]}
               name="graduateSchool"
@@ -506,19 +551,15 @@ export default defineComponent({
               label="所在城市"
               v-model={state.forms.cityCodeName}
               readonly
-              disabled={state.checkPhone}
               name="cityCodeName"
               onClick={() => {
-                if (state.checkPhone) return
                 state.showPicker = true
               }}
               rules={[{ required: true, message: '请选择所在城市', trigger: 'onChange' }]}
               placeholder="请选择所在城市"
             >
               {{
-                'right-icon': () => (
-                  <Icon name="arrow" color={state.checkPhone ? '#aaa' : '#323233'} size="16"></Icon>
-                )
+                'right-icon': () => <Icon name="arrow" color={'#323233'} size="16"></Icon>
               }}
             </Field>
 
@@ -527,18 +568,14 @@ export default defineComponent({
               v-model={state.forms.showSubjectIds}
               readonly
               name="showSubjectIds"
-              disabled={state.checkPhone}
               onClick={() => {
-                if (state.checkPhone) return
                 state.showSubject = true
               }}
               rules={[{ required: true, message: '请选择声部', trigger: 'onChange' }]}
               placeholder="请选择声部"
             >
               {{
-                'right-icon': () => (
-                  <Icon name="arrow" color={state.checkPhone ? '#aaa' : '#323233'} size="16"></Icon>
-                ),
+                'right-icon': () => <Icon name="arrow" color={'#323233'} size="16"></Icon>,
                 input: () => (
                   <>
                     {state.forms.subjectIds.length <= 0 ? (
@@ -575,20 +612,12 @@ export default defineComponent({
               rules={[{ required: true, message: '请输入验证码', trigger: 'onChange' }]}
               placeholder="请输入验证码"
               maxlength={6}
-              disabled={state.checkPhone}
               type="tel"
             >
               {{
                 button: () =>
                   state.countDownStatus ? (
-                    <Button
-                      type="primary"
-                      round
-                      size="small"
-                      disabled={state.checkPhone}
-                      color="#ff8057"
-                      onClick={onSendCode}
-                    >
+                    <Button type="primary" round size="small" color="#ff8057" onClick={onSendCode}>
                       发送验证码
                     </Button>
                   ) : (
@@ -614,16 +643,26 @@ export default defineComponent({
               style="margin-right: 6px"
               checked-color="#FF8057"
             ></Checkbox>
-            <span
-              onClick={() => {
-                state.checked = !state.checked
-              }}
-            >
-              请认真阅读并勾选
-            </span>
-            <span class={styles.c} onClick={onPreview}>
-              《乐团伴学指导注册协议》
-            </span>
+            <div>
+              <span
+                onClick={() => {
+                  state.checked = !state.checked
+                }}
+              >
+                请认真阅读并勾选
+              </span>
+              <span class={styles.c} onClick={() => onPreview('REGISTER')}>
+                《管乐团用户注册协议》
+              </span>
+              、
+              <span class={styles.c} onClick={() => onPreview('PRIVACY')}>
+                《隐私协议》
+              </span>
+              、
+              <span class={styles.c} onClick={() => onPreview('WITHDRAW')}>
+                《共享经济平台注册经营者协议》
+              </span>
+            </div>
           </div>
 
           <Button
@@ -634,7 +673,7 @@ export default defineComponent({
             color="#FF8057"
             loading={state.btnLoading}
             native-type="submit"
-            disabled={state.checkPhone || state.btnLoading}
+            disabled={state.btnLoading}
           >
             完成
           </Button>

+ 2 - 2
src/school/train-planning/modal/timer/index.tsx

@@ -204,10 +204,10 @@ export default defineComponent({
           {state.usedTimer.map((item: any) => (
             <Cell
               center
-              value={`${dayjs(item.startTime).format('HH:mm')}~${dayjs(item.endTime).format(
+              value="冲突时间"
+              title={`${dayjs(item.startTime).format('HH:mm')}~${dayjs(item.endTime).format(
                 'HH:mm'
               )}`}
-              title="冲突时间"
               class={styles.noTime}
             ></Cell>
           ))}

+ 41 - 0
src/views/preview-protocol/cash-protocol.tsx

@@ -0,0 +1,41 @@
+import request from '@/helpers/request'
+import { state } from '@/state'
+import { defineComponent } from 'vue'
+
+// 预览协议 - 原生实名认证使用
+export default defineComponent({
+  name: 'preview-protocol',
+  data() {
+    return {
+      protocolHTML: '' as any
+    }
+  },
+  async mounted() {
+    try {
+      // 判断是否有协议内容
+      if (!this.protocolHTML) {
+        const { data } = await request.get(
+          state.platformApi + '/open/userContractRecord/queryLatestContractTemplate',
+          {
+            params: {
+              contractType: 'WITHDRAW'
+            }
+          }
+        )
+        this.protocolHTML = data.contractTemplateContent || ''
+      }
+    } catch {
+      //
+    }
+  },
+  render() {
+    return (
+      <div id="mProtocol">
+        <div
+          style="font-size: 14px;padding: 12px;color: #333;line-height: 1.4;"
+          v-html={this.protocolHTML}
+        ></div>
+      </div>
+    )
+  }
+})