Browse Source

fix: respect disabled uni login types

Pchen. 2 weeks ago
parent
commit
dae149cf62

+ 9 - 1
src/api/login.js

@@ -6,6 +6,7 @@ const api = {
   ImgCaptcha: '/Captcha/ImageCaptcha',
   ImgCaptcha: '/Captcha/ImageCaptcha',
   GetPermissions: '/User/GetPermissions',
   GetPermissions: '/User/GetPermissions',
   sendEmail: '/Captcha/SendEmail',
   sendEmail: '/Captcha/SendEmail',
+  UniLoginOptions: '/UniLogin/Options',
   GetLoginUrl: '/UniLogin/GetLoginUrl',
   GetLoginUrl: '/UniLogin/GetLoginUrl',
   UniLogin: '/UniLogin/Login',
   UniLogin: '/UniLogin/Login',
   BindSocial: '/UniLogin/BindSocial',
   BindSocial: '/UniLogin/BindSocial',
@@ -59,6 +60,13 @@ export function getLoginUrl(parameter) {
   })
   })
 }
 }
 
 
+export function getUniLoginOptions() {
+  return request({
+    url: api.UniLoginOptions,
+    method: 'get'
+  })
+}
+
 export function uniLogin(parameter) {
 export function uniLogin(parameter) {
   return request({
   return request({
     url: api.UniLogin,
     url: api.UniLogin,
@@ -81,4 +89,4 @@ export function unbindSocial(parameter) {
     method: 'post',
     method: 'post',
     data: parameter
     data: parameter
   })
   })
-}
+}

+ 16 - 3
src/pages/Login/components/login.vue

@@ -35,7 +35,7 @@
             </a-form-item>
             </a-form-item>
 
 
             <div class="forgetpass">
             <div class="forgetpass">
-                <a-button type="text" @click="emit('changeMode', 'uniLogin')">快捷登录</a-button>
+                <a-button v-if="quickLoginEnabled" type="text" @click="emit('changeMode', 'uniLogin')">快捷登录</a-button>
                 <!-- <div class="tip">由于业务变更 现无法通过QQ/微信快捷登录<br>快捷登录用户可在注册新账号后提交工单联系客服找回原账号</div> -->
                 <!-- <div class="tip">由于业务变更 现无法通过QQ/微信快捷登录<br>快捷登录用户可在注册新账号后提交工单联系客服找回原账号</div> -->
                 <a-button type="text" @click="emit('changeMode', 'register')">注册账号</a-button>
                 <a-button type="text" @click="emit('changeMode', 'register')">注册账号</a-button>
             </div>
             </div>
@@ -48,7 +48,7 @@
 </template>
 </template>
 
 
 <script setup>
 <script setup>
-import { getImageCaptcha } from '@/api/login'
+import { getImageCaptcha, getUniLoginOptions } from '@/api/login'
 import { Notification } from '@arco-design/web-vue'
 import { Notification } from '@arco-design/web-vue'
 import { ref, reactive } from 'vue'
 import { ref, reactive } from 'vue'
 import { useUserStore } from '@/store/modules/user'
 import { useUserStore } from '@/store/modules/user'
@@ -67,6 +67,7 @@ let captchaLoading = ref(false)
 let CaptchaId = ref('')
 let CaptchaId = ref('')
 let ImageCaptcha = ref('')
 let ImageCaptcha = ref('')
 let loading = ref(false)
 let loading = ref(false)
+let quickLoginEnabled = ref(true)
 let form = reactive({
 let form = reactive({
     username: '',
     username: '',
     password: '',
     password: '',
@@ -90,6 +91,18 @@ const getCaptcha = async () => {
 
 
 getCaptcha()
 getCaptcha()
 
 
+const getQuickLoginOptions = async () => {
+    try {
+        const res = await getUniLoginOptions()
+        if (res?.code === 0 && Array.isArray(res.data?.enabledTypes))
+            quickLoginEnabled.value = res.data.enabledTypes.length > 0
+    } catch (error) {
+        console.log(error)
+    }
+}
+
+getQuickLoginOptions()
+
 const handleSubmit = async ({ values, errors }) => {
 const handleSubmit = async ({ values, errors }) => {
     if (!values.username || !values.password || !values.captcha)
     if (!values.username || !values.password || !values.captcha)
         return requestFailed('请填写所有信息')
         return requestFailed('请填写所有信息')
@@ -137,4 +150,4 @@ const requestFailed = (msg) => {
   text-align: left;
   text-align: left;
   margin-bottom: 12px;
   margin-bottom: 12px;
 }
 }
-</style>
+</style>

+ 33 - 4
src/pages/Login/uniLogin/uniLogin.vue

@@ -7,19 +7,22 @@
 
 
         <a-form size="large" :model="form" :rules="[]" class="form" @submit="handleSubmit">
         <a-form size="large" :model="form" :rules="[]" class="form" @submit="handleSubmit">
             <div class="uniLoginButton">
             <div class="uniLoginButton">
-                <div class="button">
+                <div class="button" v-if="isTypeEnabled('qq')">
                     <a-tooltip content="QQ登录" mini>
                     <a-tooltip content="QQ登录" mini>
                         <a-avatar :size="64" :style="{ backgroundColor: '#FE82A5' }"
                         <a-avatar :size="64" :style="{ backgroundColor: '#FE82A5' }"
                             @click="GetLoginUrl('qq')"><icon-qq /></a-avatar>
                             @click="GetLoginUrl('qq')"><icon-qq /></a-avatar>
                     </a-tooltip>
                     </a-tooltip>
                 </div>
                 </div>
-                <div class="button">
+                <div class="button" v-if="isTypeEnabled('wx')">
                     <a-tooltip content="微信登录" mini>
                     <a-tooltip content="微信登录" mini>
                         <a-avatar :size="64" :style="{ backgroundColor: '#FE82A5' }"
                         <a-avatar :size="64" :style="{ backgroundColor: '#FE82A5' }"
                             @click="GetLoginUrl('wx')"><icon-wechat /></a-avatar>
                             @click="GetLoginUrl('wx')"><icon-wechat /></a-avatar>
                     </a-tooltip>
                     </a-tooltip>
                 </div>
                 </div>
             </div>
             </div>
+            <a-alert v-if="!optionsLoading && enabledTypes.length === 0" type="warning" class="disabled-tip">
+                快捷登录暂未开启,请使用账号密码登录
+            </a-alert>
             <div class="tip">未注册的第三方账号登录后将自动注册</div>
             <div class="tip">未注册的第三方账号登录后将自动注册</div>
             <a-button type="text" class="forgetpass" @click="emit('changeMode', 'login')">账号密码登录</a-button>
             <a-button type="text" class="forgetpass" @click="emit('changeMode', 'login')">账号密码登录</a-button>
         </a-form>
         </a-form>
@@ -34,7 +37,7 @@
 </template>
 </template>
 
 
 <script setup>
 <script setup>
-import { getLoginUrl } from '@/api/login'
+import { getLoginUrl, getUniLoginOptions } from '@/api/login'
 import { timeFix } from '@/utils/util'
 import { timeFix } from '@/utils/util'
 import { useRoute, useRouter } from 'vue-router'
 import { useRoute, useRouter } from 'vue-router'
 import { ref, onMounted } from 'vue'
 import { ref, onMounted } from 'vue'
@@ -45,13 +48,33 @@ import { isElectron } from '@/utils/electron'
 const userStore = useUserStore()
 const userStore = useUserStore()
 
 
 const loading = ref(false)
 const loading = ref(false)
+const optionsLoading = ref(false)
+const enabledTypes = ref(['qq', 'wx'])
 const route = useRoute()
 const route = useRoute()
 const router = useRouter()
 const router = useRouter()
 const emit = defineEmits(['changeMode', 'changeLoading'])
 const emit = defineEmits(['changeMode', 'changeLoading'])
 
 
 const from = route.query.from
 const from = route.query.from
 
 
+const isTypeEnabled = (type) => enabledTypes.value.includes(type)
+
+const loadOptions = async () => {
+    try {
+        optionsLoading.value = true
+        const res = await getUniLoginOptions()
+        if (res?.code === 0 && Array.isArray(res.data?.enabledTypes))
+            enabledTypes.value = res.data.enabledTypes
+    } catch (error) {
+        console.log(error)
+    } finally {
+        optionsLoading.value = false
+    }
+}
+
 const GetLoginUrl = async (type) => {
 const GetLoginUrl = async (type) => {
+    if (!isTypeEnabled(type))
+        return requestFailed('该登录方式已关闭')
+
     try {
     try {
         changeLoading(true)
         changeLoading(true)
         const res = await getLoginUrl({ type })
         const res = await getLoginUrl({ type })
@@ -131,6 +154,7 @@ const requestFailed = (msg) => {
 }
 }
 
 
 onMounted(() => {
 onMounted(() => {
+    loadOptions()
     if (route.query.type && route.query.code) {
     if (route.query.type && route.query.code) {
         if (route.query.action === 'bind')
         if (route.query.action === 'bind')
             BindSocial(route.query.type, route.query.code)
             BindSocial(route.query.type, route.query.code)
@@ -180,6 +204,11 @@ onMounted(() => {
     margin-left: -8px;
     margin-left: -8px;
 }
 }
 
 
+.disabled-tip {
+    margin-bottom: 16px;
+    text-align: left;
+}
+
 .uniLoginButton {
 .uniLoginButton {
     display: flex;
     display: flex;
     gap: 40px;
     gap: 40px;
@@ -196,4 +225,4 @@ onMounted(() => {
     margin-top: -10px;
     margin-top: -10px;
     margin-left: -15px;
     margin-left: -15px;
 }
 }
-</style>
+</style>

+ 26 - 3
src/pages/User/setting/components/social-bindings.vue

@@ -23,13 +23,16 @@
         </div>
         </div>
 
 
         <a-button
         <a-button
-          v-if="!isBound(item.type)"
+          v-if="!isBound(item.type) && isTypeEnabled(item.type)"
           type="primary"
           type="primary"
           :loading="state.loadingType === item.type"
           :loading="state.loadingType === item.type"
           @click="bind(item.type)"
           @click="bind(item.type)"
         >
         >
           立即绑定
           立即绑定
         </a-button>
         </a-button>
+        <a-button v-else-if="!isBound(item.type)" disabled>
+          已关闭
+        </a-button>
         <a-button
         <a-button
           v-else
           v-else
           status="danger"
           status="danger"
@@ -45,13 +48,14 @@
 
 
 <script setup>
 <script setup>
 import { onBeforeMount, reactive, ref } from 'vue'
 import { onBeforeMount, reactive, ref } from 'vue'
-import { getLoginUrl } from '@/api/login'
+import { getLoginUrl, getUniLoginOptions } from '@/api/login'
 import { useUserStore } from '@/store/modules/user'
 import { useUserStore } from '@/store/modules/user'
 import { isElectron } from '@/utils/electron'
 import { isElectron } from '@/utils/electron'
 import { Message, Modal, Notification } from '@arco-design/web-vue'
 import { Message, Modal, Notification } from '@arco-design/web-vue'
 
 
 const userStore = useUserStore()
 const userStore = useUserStore()
 const user = ref({})
 const user = ref({})
+const enabledTypes = ref(['qq', 'wx'])
 
 
 const state = reactive({
 const state = reactive({
   loadingType: ''
   loadingType: ''
@@ -75,7 +79,24 @@ const getBinding = (type) => {
   return user.value?.socialBindings?.find(item => item.type === type && item.bound) || null
   return user.value?.socialBindings?.find(item => item.type === type && item.bound) || null
 }
 }
 
 
+const isTypeEnabled = (type) => enabledTypes.value.includes(type)
+
+const refreshOptions = async () => {
+  try {
+    const res = await getUniLoginOptions()
+    if (res?.code === 0 && Array.isArray(res.data?.enabledTypes))
+      enabledTypes.value = res.data.enabledTypes
+  } catch (error) {
+    console.log(error)
+  }
+}
+
 const bind = async (type) => {
 const bind = async (type) => {
+  if (!isTypeEnabled(type)) {
+    Message.warning('该绑定方式已关闭')
+    return
+  }
+
   try {
   try {
     state.loadingType = type
     state.loadingType = type
     const res = await getLoginUrl({
     const res = await getLoginUrl({
@@ -124,7 +145,9 @@ const unbind = (type) => {
   })
   })
 }
 }
 
 
-onBeforeMount(refreshUser)
+onBeforeMount(async () => {
+  await Promise.all([refreshUser(), refreshOptions()])
+})
 </script>
 </script>
 
 
 <style scoped lang="less">
 <style scoped lang="less">