Ver código fonte

feat: 更新版本号至1.4.2,新增设置页面及审核消息订阅功能,优化用户权限管理

laiqi 11 meses atrás
pai
commit
8753759dbe

+ 1 - 1
env/.env

@@ -1,6 +1,6 @@
 VITE_APP_TITLE='达川农机优惠劵'
 VITE_APP_PORT=9000
-VITE_APP_VERSION=1.4.1
+VITE_APP_VERSION=1.4.2
 
 VITE_UNI_APPID='H57F2ACE4'
 VITE_WX_APPID='wxd3ca52d7f454048d'

+ 25 - 0
src/pages-sub/auth/index.vue

@@ -25,12 +25,34 @@ import { onMounted } from 'vue'
 import { until } from '@vueuse/core'
 import { useAppStore } from '@/store/app'
 import { useUserStore } from '@/store/user'
+import { useDictStore } from '@/store/dict'
 
 const userStore = useUserStore()
 const appStore = useAppStore()
+const dictStore = useDictStore()
 const loading = ref(false)
 const redirectUrl = ref('') // 存储回跳页面路径
 
+// 获取审核权限的openid配置
+const getAuditOpenidConfig = async () => {
+  try {
+    const configList = await dictStore.getConfigList('audit_openid')
+
+    if (configList.length > 0) {
+      const auditOpenid = configList[0].substance.split(',')
+      if (auditOpenid.includes(appStore.appInfo.openid)) {
+        userStore.setAuditAuth(true)
+      } else {
+        userStore.setAuditAuth(false)
+      }
+    }
+  } catch (error) {
+    console.error('获取审核权限配置失败:', error)
+    // 出错时默认设置为无权限
+    userStore.setAuditAuth(false)
+  }
+}
+
 // 接收回跳页面参数
 onLoad((options) => {
   if (options.redirect) {
@@ -82,6 +104,9 @@ const handleLogin = async () => {
               appStore.setAppInfo({ token, userid, openid })
               userStore.getUserInfo()
 
+              // 获取审核权限配置
+              await getAuditOpenidConfig()
+
               // 根据是否有回跳地址决定跳转到哪里
               if (redirectUrl.value) {
                 try {

+ 7 - 0
src/pages.json

@@ -159,6 +159,13 @@
       "style": {
         "navigationBarTitleText": "产品详情"
       }
+    },
+    {
+      "path": "pages/settings/index",
+      "type": "page",
+      "style": {
+        "navigationBarTitleText": "设置"
+      }
     }
   ],
   "subPackages": [

+ 2 - 2
src/pages/mine/index.vue

@@ -80,13 +80,13 @@
       </view>
 
       <!-- 设置 -->
-      <!-- <view class="menu-item" @click="handleNavigate('/pages/settings/index')">
+      <view class="menu-item" @click="handleToAuthPage('/pages/settings/index')">
         <view class="flex items-center">
           <wd-icon name="setting1" class="text-gray-500" />
           <text class="ml-3">设置</text>
         </view>
         <wd-icon name="arrow-right" size="18" class="text-gray-400" />
-      </view> -->
+      </view>
 
       <!-- 优惠劵审核 -->
       <view

+ 114 - 0
src/pages/settings/index.vue

@@ -0,0 +1,114 @@
+<route lang="json5">
+{
+  style: {
+    navigationBarTitleText: '设置',
+  },
+}
+</route>
+
+<template>
+  <view class="min-h-screen bg-gray-100">
+    <!-- 设置列表 -->
+    <view class="px-4 py-4">
+      <!-- 消息通知设置 -->
+      <view class="bg-white rounded-lg mb-4">
+        <view class="px-4 py-3 border-b border-gray-100">
+          <text class="text-lg font-medium text-gray-800">消息通知</text>
+        </view>
+
+        <!-- 审核消息订阅 -->
+        <view class="px-4 py-4 flex items-center justify-between">
+          <view class="flex-1">
+            <text class="text-base text-gray-800">审核消息订阅</text>
+            <view class="mt-1">
+              <text class="text-sm text-gray-500">接收优惠券审核状态变更通知</text>
+            </view>
+          </view>
+          <wd-switch
+            v-model="auditMessageSubscription"
+            :disabled="!hasAuditAuth"
+            @change="handleAuditMessageChange"
+          />
+        </view>
+      </view>
+    </view>
+  </view>
+</template>
+
+<script lang="ts" setup>
+import { computed, onMounted, ref } from 'vue'
+import { useSettingsStore } from '@/store/settings'
+import { useUserStore } from '@/store/user'
+
+const settingsStore = useSettingsStore()
+const userStore = useUserStore()
+
+// 审核消息订阅状态
+const auditMessageSubscription = ref(false)
+
+// 计算属性:是否有审核权限
+const hasAuditAuth = computed(() => userStore.audit_auth)
+
+// 获取审核消息订阅状态
+const getAuditSubscriptionStatus = async () => {
+  try {
+    const result = await settingsStore.getAuditMessageSubscription()
+    // 如果返回的列表中有数据,就表示已订阅
+    auditMessageSubscription.value = !!(
+      result &&
+      result.Data &&
+      Array.isArray(result.Data) &&
+      result.Data.length > 0
+    )
+  } catch (error) {
+    console.error('获取审核消息订阅状态失败:', error)
+    auditMessageSubscription.value = false
+  }
+}
+
+// 审核消息订阅开关变更
+const handleAuditMessageChange = async ({ value }: { value: boolean }) => {
+  // 检查审核权限
+  if (!hasAuditAuth.value) {
+    uni.showToast({
+      title: '您没有审核权限,无法修改此设置',
+      icon: 'none',
+    })
+    // 恢复原值
+    auditMessageSubscription.value = !value
+    return
+  }
+
+  try {
+    // 调用提交订阅接口,传入固定的模板ID和状态
+    const params = {
+      wxsubscribetemplateid: 'oi3JmzaEbkAXubBsPPMDE8Grjfj9Tf0VP7rttWAgPlA', // 固定值
+      status: value ? 1 : 2, // 1为订阅,2为取消订阅
+    }
+
+    await settingsStore.submitAuditMessageSubscription(params)
+
+    uni.showToast({
+      title: value ? '已开启审核消息订阅' : '已关闭审核消息订阅',
+      icon: 'none',
+    })
+  } catch (error) {
+    // console.error('更新审核消息订阅状态失败:', error)
+    // uni.showToast({
+    //   title: '操作失败,请稍后重试',
+    //   icon: 'none',
+    // })
+    // 恢复原值
+    auditMessageSubscription.value = !value
+  }
+}
+
+// 页面加载时获取订阅状态
+onMounted(() => {
+  getAuditSubscriptionStatus()
+})
+</script>
+
+<style lang="scss" scoped>
+// 自定义样式
+</style>

+ 0 - 15
src/service/index/foo.ts

@@ -1,15 +0,0 @@
-import { http } from '@/utils/http'
-export interface IFooItem {
-  id: string
-  name: string
-}
-
-/** GET 请求 */
-export const getFooAPI = (name: string) => {
-  return http.get<IFooItem>('/foo', { name })
-}
-
-/** POST 请求 */
-export const postFooAPI = (name: string) => {
-  return http.post<IFooItem>('/foo', { name }, { name })
-}

+ 23 - 0
src/service/index/index.ts

@@ -0,0 +1,23 @@
+import { http } from '@/utils/http'
+import type { WxSubscribeEntity } from '@/types/wxsubscribe'
+import type { ListType, ListResponseType } from '@/types/list'
+import { parseQueryValues } from '@/utils'
+
+/** 微信订阅列表 */
+// 传入openid
+export const getWxSubscribeListApi = (
+  params: Partial<WxSubscribeEntity>,
+  page: Partial<ListType>,
+) => {
+  return http.get<ListResponseType<WxSubscribeEntity>>('/api/query/list?pagevalue=113', {
+    ...page,
+    ...parseQueryValues(params),
+  })
+}
+
+/** 小程序审核消息订阅 */
+export const submitAuditMessageSubscriptionApi = (params: Partial<any>) => {
+  return http.get<any>('/api/nlua/call?pagevalue=112', {
+    ...params,
+  })
+}

+ 1 - 0
src/store/index.ts

@@ -16,3 +16,4 @@ export default store
 // 模块统一导出
 export * from './user'
 export * from './app'
+export * from './settings'

+ 54 - 0
src/store/settings.ts

@@ -0,0 +1,54 @@
+import { defineStore } from 'pinia'
+import { submitAuditMessageSubscriptionApi, getWxSubscribeListApi } from '@/service/index'
+import { useAppStore } from '@/store/app'
+import { until } from '@vueuse/core'
+
+export const useSettingsStore = defineStore(
+  'settings',
+  () => {
+    // 审核消息订阅 提交
+    const submitAuditMessageSubscription = async (params: Partial<any>) => {
+      // eslint-disable-next-line no-async-promise-executor
+      return new Promise(async (resolve, reject) => {
+        const { data, loading, error } = useRequest(
+          () => submitAuditMessageSubscriptionApi(params),
+          {
+            immediate: true,
+          },
+        )
+
+        await until(loading).toBe(false)
+
+        console.log('submitAuditMessageSubscription', data)
+
+        if (error.value) {
+          reject(new Error(data.value.Message || '审核消息订阅失败'))
+        }
+        resolve(data.value)
+      })
+    }
+
+    // 获取审核消息订阅
+    const getAuditMessageSubscription = async () => {
+      const appStore = useAppStore()
+      const res = await getWxSubscribeListApi(
+        {
+          wxsubscribeopenid: appStore.appInfo.openid,
+        },
+        {
+          pageindex: 1,
+          rows: 10,
+        },
+      )
+      return res.Data
+    }
+
+    return {
+      submitAuditMessageSubscription,
+      getAuditMessageSubscription,
+    }
+  },
+  {
+    persist: true,
+  },
+)

+ 1 - 0
src/types/uni-pages.d.ts

@@ -20,6 +20,7 @@ interface NavigateToOptions {
        "/pages/order/detail" |
        "/pages/order/index" |
        "/pages/product/detail" |
+       "/pages/settings/index" |
        "/pages-sub/auth/index" |
        "/pages-sub/user/index";
 }

+ 20 - 0
src/types/wxsubscribe.ts

@@ -0,0 +1,20 @@
+// CREATE TABLE `wxsubscribe` (
+//   `wxsubscribeid` varchar(50) NOT NULL COMMENT '流水号',
+//   `wxsubscribeopenid` varchar(50) DEFAULT NULL COMMENT '微信openid',
+//   `wxsubscribetemplateid` varchar(50) DEFAULT NULL COMMENT '订阅模板id',
+//   `wxsubscribedate` datetime DEFAULT NULL COMMENT '订阅时间',
+//   PRIMARY KEY (`wxsubscribeid`)
+// ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='微信订阅';
+
+interface WxSubscribeEntity {
+  /** 流水号 */
+  wxsubscribeid: string
+  /** 微信openid */
+  wxsubscribeopenid: string
+  /** 订阅模板id */
+  wxsubscribetemplateid: string
+  /** 订阅时间 */
+  wxsubscribedate: string
+}
+
+export type { WxSubscribeEntity }