快乐的梦鱼 1 місяць тому
батько
коміт
83ec52825e

+ 12 - 9
src/App.vue

@@ -15,15 +15,18 @@ const redirectThrottle = new MemoryTimeOut('RedirectThrottle', 50000);
 
 
 onLaunch(async () => {
 onLaunch(async () => {
   console.log('App Launch');
   console.log('App Launch');
-  //加载登录信息。如果未登录,跳转登录页
-  if (!await authStore.loadLoginState() && redirectThrottle.isTimeout()) {
-    redirectThrottle.recordTime();
-    setTimeout(() => {   
-      const pageUrl = getCurrentPageUrl() || '';
-      const noLoginPages = AppConfig.noLoginPages;
-      if (noLoginPages.indexOf('/' + pageUrl) == -1 && noLoginPages.indexOf(pageUrl) == -1)
-        navTo('/pages/user/login');
-    }, 500);
+
+  if (AppConfig.requireLogin) {
+    //加载登录信息。如果未登录,跳转登录页
+    if (!await authStore.loadLoginState() && redirectThrottle.isTimeout()) {
+      redirectThrottle.recordTime();
+      setTimeout(() => {   
+        const pageUrl = getCurrentPageUrl() || '';
+        const noLoginPages = AppConfig.noLoginPages;
+        if (noLoginPages.indexOf('/' + pageUrl) == -1 && noLoginPages.indexOf(pageUrl) == -1)
+          navTo('/pages/user/login');
+      }, 500);
+    }
   }
   }
     
     
   await init();
   await init();

+ 4 - 1
src/common/components/RequireLogin.vue

@@ -1,13 +1,16 @@
 <template>
 <template>
   <slot v-if="isLogged" />
   <slot v-if="isLogged" />
   <FlexCol v-else center :height="300" :gap="30">
   <FlexCol v-else center :height="300" :gap="30">
-    <text>{{unLoginMessage}}</text>
+    <Icon name="smile-filling" :size="80" />
+    <Text :text="unLoginMessage" textAlign="center" fontConfig="subText" />
     <Button :innerStyle="{width: '50%'}" type="primary" @click="goLogin">去登录</Button>
     <Button :innerStyle="{width: '50%'}" type="primary" @click="goLogin">去登录</Button>
   </FlexCol>
   </FlexCol>
 </template>
 </template>
 
 
 <script setup lang="ts">
 <script setup lang="ts">
 import Button from '@/components/basic/Button.vue';
 import Button from '@/components/basic/Button.vue';
+import Icon from '@/components/basic/Icon.vue';
+import Text from '@/components/basic/Text.vue';
 import FlexCol from '@/components/layout/FlexCol.vue';
 import FlexCol from '@/components/layout/FlexCol.vue';
 import { navTo } from '@/components/utils/PageAction';
 import { navTo } from '@/components/utils/PageAction';
 import { useAuthStore } from '@/store/auth';
 import { useAuthStore } from '@/store/auth';

+ 1 - 0
src/common/config/AppCofig.ts

@@ -8,6 +8,7 @@ export default {
   qqMapKey: 'TOIBZ-CA4WB-OFQUF-J3XG4-EEB2J-DXBX7',
   qqMapKey: 'TOIBZ-CA4WB-OFQUF-J3XG4-EEB2J-DXBX7',
   amapKey: '34eb1d57f93720a871bd11a90af0c91c',
   amapKey: '34eb1d57f93720a871bd11a90af0c91c',
   defaultLonLat: [ 118.161270, 24.529196 ],
   defaultLonLat: [ 118.161270, 24.529196 ],
+  requireLogin: false,
   noLoginPages: [
   noLoginPages: [
     '/pages/user/login',
     '/pages/user/login',
     '/pages/user/register',
     '/pages/user/register',

+ 8 - 8
src/pages.json

@@ -1,6 +1,14 @@
 {
 {
   "pages": [
   "pages": [
     {
     {
+      "path": "pages/index",
+      "style": {
+        "navigationStyle": "custom",
+        "navigationBarTitleText" : "村社文化资源挖掘平台",
+        "enablePullDownRefresh" : false
+      }
+    },
+    {
       "path": "pages/user/login",
       "path": "pages/user/login",
       "style": {
       "style": {
         "navigationBarTitleText": "登录",
         "navigationBarTitleText": "登录",
@@ -17,14 +25,6 @@
       }
       }
     },
     },
     {
     {
-      "path": "pages/index",
-      "style": {
-        "navigationStyle": "custom",
-        "navigationBarTitleText" : "村社文化资源挖掘平台",
-        "enablePullDownRefresh" : false
-      }
-    },
-    {
       "path": "pages/user/update/password",
       "path": "pages/user/update/password",
       "style": {
       "style": {
         "navigationBarTitleText": "修改密码",
         "navigationBarTitleText": "修改密码",

+ 33 - 0
src/pages/dig/forms/bind.ts

@@ -0,0 +1,33 @@
+import VillageApi from "@/api/inhert/VillageApi";
+import { confirm } from "@/components/dialog/CommonRoot";
+import type { RequestApiError } from "@imengyu/imengyu-utils";
+
+export function checkIsNotVolunteerError(e: unknown) {
+  return (e as RequestApiError).errorMessage.includes('请认领')
+}
+export async function checkAndGoBindVolunteer() {
+  //检查是否有志愿者信息,跳转至不同的页面
+  //已认领志愿者,跳转至首页
+  //未认领志愿者,跳转至绑定账号页面
+  try {
+    await VillageApi.getVolunteerInfo();
+  } catch(e) {
+
+    //已登录但是没绑定志愿者信息,提示用户绑定
+    if (checkIsNotVolunteerError(e)) {
+      const goBind = await confirm({
+        title: '提示',
+        content: '欢迎进入平台,您的账号未绑定志愿者账号,目前不能提交信息,是否前往绑定?',
+        confirmText: '前往绑定',
+        cancelText: '先看看,稍后绑定',
+        width: 580,
+      });
+      if (goBind) {
+        uni.redirectTo({ url: '/pages/dig/sharereg/bind' });
+        return true;
+      }
+    }
+    throw e;
+  }
+  return false;
+}

+ 4 - 1
src/pages/dig/forms/submits.vue

@@ -21,7 +21,10 @@
       />
       />
       <DropdownMenuItem 
       <DropdownMenuItem 
         v-model="filterVillage"
         v-model="filterVillage"
-        :options="villageListLoader.content.value || []"
+        :options="villageListLoader.content.value || [{
+          text: '未选择村社',
+          value: -100,
+        }]"
         type="single-check"
         type="single-check"
       />
       />
     </DropdownMenu>
     </DropdownMenu>

+ 38 - 15
src/pages/dig/index.vue

@@ -7,8 +7,20 @@
     />
     />
     <FlexCol :padding="30">
     <FlexCol :padding="30">
       <SubTitle title="我的村社" />
       <SubTitle title="我的村社" />
-      <RequireLogin unLoginMessage="登录后查看我认领的村社">
+      <RequireLogin unLoginMessage="欢迎您成为志愿者!在这之前您需要登录或者注册完善基础信息后才能投稿和查看我认领的村社哦">
+        <Result
+          v-if="notVolunteerError"
+          status="warning"
+          title="您还不是志愿者"
+          subTitle="请联系管理员认领,或者绑定已有志愿者账号"
+        >
+          <FlexCol center>
+            <Height :size="20" />
+            <Button type="primary" text="绑定已有志愿者账号" @click="navTo('/pages/dig/sharereg/bind')" />
+          </FlexCol>
+        </Result>
         <SimplePageContentLoader
         <SimplePageContentLoader
+          v-else
           :loader="villageListLoader"
           :loader="villageListLoader"
           :showEmpty="villageListLoader.content.value?.length == 0"
           :showEmpty="villageListLoader.content.value?.length == 0"
           :emptyView="{
           :emptyView="{
@@ -79,28 +91,28 @@
       </RequireLogin>
       </RequireLogin>
 
 
       <Height :height="20" />
       <Height :height="20" />
-      <SubTitle title="我的贡献" />
-      <RequireLogin unLoginMessage="登录后贡献,加入排行榜">
-        <FlexRow backgroundColor="white" :radius="20" :padding="[40,20]">
-          <FlexCol :flex="1" :gap="10" center>
-            <Text :fontSize="60" fontFamily="Rockwell" color="primary">{{ volunteerInfoLoader.content.value?.points || 0 }}</Text>
-            <Text>文化积分</Text>
-          </FlexCol>
-          <FlexCol :flex="1" :gap="10" center>
-            <Text :fontSize="60" fontFamily="Rockwell" color="primary">Lv.{{ volunteerInfoLoader.content.value?.level || 1 }}</Text>
-            <Text>等级</Text>
-          </FlexCol>
-        </FlexRow>
-      </RequireLogin>
+      <SubTitle v-if="authStore.isLogged" title="我的贡献" />
+      <FlexRow v-if="authStore.isLogged" backgroundColor="white" :radius="20" :padding="[40,20]">
+        <FlexCol :flex="1" :gap="10" center>
+          <Text :fontSize="60" fontFamily="Rockwell" color="primary">{{ volunteerInfoLoader.content.value?.points || 0 }}</Text>
+          <Text>文化积分</Text>
+        </FlexCol>
+        <FlexCol :flex="1" :gap="10" center>
+          <Text :fontSize="60" fontFamily="Rockwell" color="primary">Lv.{{ volunteerInfoLoader.content.value?.level || 1 }}</Text>
+          <Text>等级</Text>
+        </FlexCol>
+      </FlexRow>
     </FlexCol>
     </FlexCol>
   </FlexCol>
   </FlexCol>
 </template>
 </template>
 
 
 <script setup lang="ts">
 <script setup lang="ts">
+import { ref } from 'vue';
 import { navTo } from '@/components/utils/PageAction';
 import { navTo } from '@/components/utils/PageAction';
 import { useAuthStore } from '@/store/auth';
 import { useAuthStore } from '@/store/auth';
 import { useCollectStore } from '@/store/collect';
 import { useCollectStore } from '@/store/collect';
 import { useSimpleDataLoader } from '@/common/composeabe/SimpleDataLoader';
 import { useSimpleDataLoader } from '@/common/composeabe/SimpleDataLoader';
+import { checkIsNotVolunteerError } from './forms/bind';
 import VillageApi, { VillageListItem } from '@/api/inhert/VillageApi';
 import VillageApi, { VillageListItem } from '@/api/inhert/VillageApi';
 import RequireLogin from '@/common/components/RequireLogin.vue';
 import RequireLogin from '@/common/components/RequireLogin.vue';
 import SimplePageContentLoader from '@/common/components/SimplePageContentLoader.vue';
 import SimplePageContentLoader from '@/common/components/SimplePageContentLoader.vue';
@@ -114,11 +126,22 @@ import Text from '@/components/basic/Text.vue';
 import Height from '@/components/layout/space/Height.vue';
 import Height from '@/components/layout/space/Height.vue';
 import ButtonGroup from '@/components/basic/ButtonGroup.vue';
 import ButtonGroup from '@/components/basic/ButtonGroup.vue';
 import BubbleBox from '@/components/feedback/BubbleBox.vue';
 import BubbleBox from '@/components/feedback/BubbleBox.vue';
+import Result from '@/components/feedback/Result.vue';
 
 
 const authStore = useAuthStore();
 const authStore = useAuthStore();
 const collectStore = useCollectStore();
 const collectStore = useCollectStore();
+const notVolunteerError = ref(false);
 const villageListLoader = useSimpleDataLoader(async () => await VillageApi.getClaimedVallageList(), true);
 const villageListLoader = useSimpleDataLoader(async () => await VillageApi.getClaimedVallageList(), true);
-const volunteerInfoLoader = useSimpleDataLoader(async () => await VillageApi.getVolunteerInfo(), true);
+const volunteerInfoLoader = useSimpleDataLoader(async () => {
+  try {
+    const res = await VillageApi.getVolunteerInfo()
+    notVolunteerError.value = false;
+    return res;
+  } catch (error) {
+    notVolunteerError.value = checkIsNotVolunteerError(error);
+    throw error;
+  }
+}, true);
 const rankListLoader = useSimpleDataLoader(async () => await VillageApi.getVolunteerRanklist(), true);
 const rankListLoader = useSimpleDataLoader(async () => await VillageApi.getVolunteerRanklist(), true);
 
 
 function goSubmitDigPage(item: VillageListItem) {
 function goSubmitDigPage(item: VillageListItem) {

+ 5 - 5
src/pages/user/index.vue

@@ -20,16 +20,16 @@
         round
         round
       />
       />
       <H4 v-if="userInfo">{{ userInfo.nickname }}</H4>
       <H4 v-if="userInfo">{{ userInfo.nickname }}</H4>
-      <H4 v-else text="请登录" />
+      <H4 v-else>欢迎登录</H4>
       <H4 v-if="userInfo">{{ userInfo.mobile }}</H4>
       <H4 v-if="userInfo">{{ userInfo.mobile }}</H4>
     </Touchable>
     </Touchable>
     <Height :height="50" />
     <Height :height="50" />
     <CellGroup round>
     <CellGroup round>
-      <Cell icon="/static/images/user/icon-edit.png" title="我的投稿" showArrow touchable @click="navTo('/pages/dig/forms/submits', { 
+      <Cell v-if="userInfo" icon="/static/images/user/icon-edit.png" title="我的投稿" showArrow touchable @click="navTo('/pages/dig/forms/submits', { 
         villageVolunteerId: volunteerInfoLoader.content.value?.id || 0 
         villageVolunteerId: volunteerInfoLoader.content.value?.id || 0 
       })" />
       })" />
-      <Cell icon="/static/images/user/icon-profile.png" title="编辑资料" showArrow touchable @click="goUserProfile" />
-      <Cell v-if="!isBindWx" icon="wechat" title="绑定微信" showArrow touchable @click="navTo('/pages/dig/sharereg/bind-wx')" />
+      <Cell v-if="userInfo" icon="/static/images/user/icon-profile.png" title="编辑资料" showArrow touchable @click="goUserProfile" />
+      <Cell v-if="userInfo && !isBindWx" icon="wechat" title="绑定微信" showArrow touchable @click="navTo('/pages/dig/sharereg/bind-wx')" />
       <Cell icon="/static/images/user/icon-function.png" title="关于我们" showArrow touchable @click="navTo('/pages/home/about/about')" />
       <Cell icon="/static/images/user/icon-function.png" title="关于我们" showArrow touchable @click="navTo('/pages/home/about/about')" />
       <button open-type="contact" class="remove-button-style">
       <button open-type="contact" class="remove-button-style">
         <Cell icon="/static/images/user/icon-service.png" title="联系客服" showArrow touchable />
         <Cell icon="/static/images/user/icon-service.png" title="联系客服" showArrow touchable />
@@ -67,7 +67,7 @@ import { useSimpleDataLoader } from '@/common/composeabe/SimpleDataLoader';
 import VillageApi from '@/api/inhert/VillageApi';
 import VillageApi from '@/api/inhert/VillageApi';
 
 
 const authStore = useAuthStore();
 const authStore = useAuthStore();
-const userInfo = computed(() => authStore.userInfo);
+const userInfo = computed(() => authStore.isLogged ? authStore.userInfo : null);
 const isBindWx = computed(() => Boolean(userInfo.value?.openId));
 const isBindWx = computed(() => Boolean(userInfo.value?.openId));
 const volunteerInfoLoader = useSimpleDataLoader(async () => await VillageApi.getVolunteerInfo(), true);
 const volunteerInfoLoader = useSimpleDataLoader(async () => await VillageApi.getVolunteerInfo(), true);
 const buildTime = `${__BUILD_TIMESTAMP__}`
 const buildTime = `${__BUILD_TIMESTAMP__}`

+ 13 - 26
src/pages/user/login.vue

@@ -2,6 +2,7 @@
   <CommonRoot>
   <CommonRoot>
     <FlexCol>
     <FlexCol>
       <StatusBarSpace />
       <StatusBarSpace />
+      <NavBar v-if="!AppCofig.requireLogin" title="登录" leftButton="back" />
 
 
       <FlexCol center>
       <FlexCol center>
         <Height :size="200" />
         <Height :size="200" />
@@ -79,11 +80,13 @@
 import { useTheme } from '@/components/theme/ThemeDefine';
 import { useTheme } from '@/components/theme/ThemeDefine';
 import { useAuthStore } from '@/store/auth';
 import { useAuthStore } from '@/store/auth';
 import { useAppInit } from '@/common/composeabe/AppInit';
 import { useAppInit } from '@/common/composeabe/AppInit';
-import { RequestApiError, waitTimeOut } from '@imengyu/imengyu-utils';
+import { waitTimeOut } from '@imengyu/imengyu-utils';
 import { onMounted, ref } from 'vue';
 import { onMounted, ref } from 'vue';
 import { showError } from '@/common/composeabe/ErrorDisplay';
 import { showError } from '@/common/composeabe/ErrorDisplay';
 import { alert, closeToast, confirm, toast } from '@/components/dialog/CommonRoot';
 import { alert, closeToast, confirm, toast } from '@/components/dialog/CommonRoot';
-import { isTestEnv } from '@/common/config/AppCofig';
+import { checkAndGoBindVolunteer } from '../dig/forms/bind';
+import { back } from '@/components/utils/PageAction';
+import AppCofig, { isTestEnv } from '@/common/config/AppCofig';
 import type { Rules } from 'async-validator';
 import type { Rules } from 'async-validator';
 import FlexCol from '@/components/layout/FlexCol.vue';
 import FlexCol from '@/components/layout/FlexCol.vue';
 import Form from '@/components/form/Form.vue';
 import Form from '@/components/form/Form.vue';
@@ -99,8 +102,8 @@ import StatusBarSpace from '@/components/layout/space/StatusBarSpace.vue';
 import Image from '@/components/basic/Image.vue';
 import Image from '@/components/basic/Image.vue';
 import Text from '@/components/basic/Text.vue';
 import Text from '@/components/basic/Text.vue';
 import CheckBox from '@/components/form/CheckBox.vue';
 import CheckBox from '@/components/form/CheckBox.vue';
-import VillageApi from '@/api/inhert/VillageApi';
 import MemoryTimeOut from '@/common/composeabe/MemoryTimeOut';
 import MemoryTimeOut from '@/common/composeabe/MemoryTimeOut';
+import NavBar from '@/components/nav/NavBar.vue';
 
 
 /**
 /**
  * 登录页面
  * 登录页面
@@ -200,31 +203,12 @@ async function loginMobile() {
 }
 }
 async function loginAfter(isMobileLogin = false) {
 async function loginAfter(isMobileLogin = false) {
   await waitTimeOut(200);
   await waitTimeOut(200);
+
   //检查是否有志愿者信息,跳转至不同的页面
   //检查是否有志愿者信息,跳转至不同的页面
   //已认领志愿者,跳转至首页
   //已认领志愿者,跳转至首页
   //未认领志愿者,跳转至绑定账号页面
   //未认领志愿者,跳转至绑定账号页面
-  try {
-    await VillageApi.getVolunteerInfo();
-  } catch(e) {
-
-    //已登录但是没绑定志愿者信息,提示用户绑定
-    if ((e as RequestApiError).errorMessage.includes('请认领')) {
-      const goBind = await confirm({
-        title: '提示',
-        content: '欢迎进入平台,您的账号未绑定志愿者账号,目前不能提交信息,是否前往绑定?',
-        confirmText: '前往绑定',
-        cancelText: '先看看,稍后绑定',
-        width: 580,
-      });
-      if (goBind)
-        uni.redirectTo({ url: '/pages/dig/sharereg/bind' });
-      else
-        redirectToIndex();
-      return;
-    }
-
-    throw e;
-  }
+  if (await checkAndGoBindVolunteer())
+    return;
 
 
   //刷新用户信息
   //刷新用户信息
   await init();
   await init();
@@ -247,7 +231,10 @@ async function loginAfter(isMobileLogin = false) {
   redirectToIndex();
   redirectToIndex();
 }
 }
 function redirectToIndex() {
 function redirectToIndex() {
-  uni.redirectTo({ url: '/pages/index' });
+  if (AppCofig.requireLogin)
+    uni.redirectTo({ url: '/pages/index' });
+  else
+    back();
 }
 }
 
 
 onMounted(() => {
 onMounted(() => {

+ 0 - 4
src/static/css/font.css

@@ -316,10 +316,6 @@
   content: "\e608";
   content: "\e608";
 }
 }
 
 
-.icon-calendar:before {
-  //content: "\e607";
-}
-
 .icon-arrow-left:before {
 .icon-arrow-left:before {
   content: "\e6c0";
   content: "\e6c0";
 }
 }

+ 5 - 1
src/store/auth.ts

@@ -44,7 +44,11 @@ export const useAuthStore = defineStore('auth', {
         raw_data: JSON.parse(res.rawData),
         raw_data: JSON.parse(res.rawData),
         signature: res.signature,
         signature: res.signature,
       })
       })
-      await this.loginResultHandle(loginResult, 0);
+      await this.loginResultHandle(
+        loginResult, 
+        //登录类型根据返回值判断
+        loginResult.isAdmin ? 1 : 0,
+      );
       return loginResult;
       return loginResult;
     },
     },
     async loginMobile(account: string, password: string, loginType: number) {
     async loginMobile(account: string, password: string, loginType: number) {