Explorar o código

feat:【infra】优化 infra 代码,统一都用中划线

YunaiV hai 4 meses
pai
achega
7daf3421cf

src/api/infra/apiAccessLog/index.ts → src/api/infra/api-access-log/index.ts


src/api/infra/apiErrorLog/index.ts → src/api/infra/api-error-log/index.ts


+ 146 - 0
src/pages-infra/api-access-log/components/search-form.vue

@@ -0,0 +1,146 @@
+<template>
+  <!-- 搜索框入口 -->
+  <view @click="visible = true">
+    <wd-search :placeholder="placeholder" hide-cancel disabled />
+  </view>
+
+  <!-- 搜索弹窗 -->
+  <wd-popup v-model="visible" position="top" @close="visible = false">
+    <view class="yd-search-form-container" :style="{ paddingTop: `${getNavbarHeight()}px` }">
+      <view class="yd-search-form-item">
+        <view class="yd-search-form-label">
+          用户编号
+        </view>
+        <wd-input
+          v-model="formData.userId"
+          placeholder="请输入用户编号"
+          clearable
+        />
+      </view>
+      <view class="yd-search-form-item">
+        <view class="yd-search-form-label">
+          应用名
+        </view>
+        <wd-input
+          v-model="formData.applicationName"
+          placeholder="请输入应用名"
+          clearable
+        />
+      </view>
+      <view class="yd-search-form-item">
+        <view class="yd-search-form-label">
+          访问时间
+        </view>
+        <view class="yd-search-form-date-range-container">
+          <view class="flex-1" @click="visibleCreateTime[0] = true">
+            <view class="yd-search-form-date-range-picker">
+              {{ formatDate(formData.createTime?.[0]) || '开始日期' }}
+            </view>
+          </view>
+          -
+          <view class="flex-1" @click="visibleCreateTime[1] = true">
+            <view class="yd-search-form-date-range-picker">
+              {{ formatDate(formData.createTime?.[1]) || '结束日期' }}
+            </view>
+          </view>
+        </view>
+        <wd-datetime-picker-view v-if="visibleCreateTime[0]" v-model="tempCreateTime[0]" type="date" />
+        <view v-if="visibleCreateTime[0]" class="yd-search-form-date-range-actions">
+          <wd-button size="small" plain @click="visibleCreateTime[0] = false">
+            取消
+          </wd-button>
+          <wd-button size="small" type="primary" @click="handleCreateTime0Confirm">
+            确定
+          </wd-button>
+        </view>
+        <wd-datetime-picker-view v-if="visibleCreateTime[1]" v-model="tempCreateTime[1]" type="date" />
+        <view v-if="visibleCreateTime[1]" class="yd-search-form-date-range-actions">
+          <wd-button size="small" plain @click="visibleCreateTime[1] = false">
+            取消
+          </wd-button>
+          <wd-button size="small" type="primary" @click="handleCreateTime1Confirm">
+            确定
+          </wd-button>
+        </view>
+      </view>
+      <view class="yd-search-form-actions">
+        <wd-button class="flex-1" plain @click="handleReset">
+          重置
+        </wd-button>
+        <wd-button class="flex-1" type="primary" @click="handleSearch">
+          搜索
+        </wd-button>
+      </view>
+    </view>
+  </wd-popup>
+</template>
+
+<script lang="ts" setup>
+import { computed, reactive, ref } from 'vue'
+import { getNavbarHeight } from '@/utils'
+import { formatDate, formatDateRange } from '@/utils/date'
+
+const emit = defineEmits<{
+  search: [data: Record<string, any>]
+  reset: []
+}>()
+
+const visible = ref(false)
+const formData = reactive({
+  userId: undefined as number | undefined,
+  applicationName: undefined as string | undefined,
+  createTime: [undefined, undefined] as [number | undefined, number | undefined],
+})
+
+/** 搜索条件 placeholder 拼接 */
+const placeholder = computed(() => {
+  const conditions: string[] = []
+  if (formData.userId) {
+    conditions.push(`用户编号:${formData.userId}`)
+  }
+  if (formData.applicationName) {
+    conditions.push(`应用名:${formData.applicationName}`)
+  }
+  if (formData.createTime?.[0] && formData.createTime?.[1]) {
+    conditions.push(`时间:${formatDate(formData.createTime[0])}~${formatDate(formData.createTime[1])}`)
+  }
+  return conditions.length > 0 ? conditions.join(' | ') : '搜索日志'
+})
+
+// 时间范围选择器状态
+const visibleCreateTime = ref<[boolean, boolean]>([false, false])
+const tempCreateTime = ref<[number, number]>([Date.now(), Date.now()])
+
+/** 访问时间[0]确认 */
+function handleCreateTime0Confirm() {
+  formData.createTime = [tempCreateTime.value[0], formData.createTime?.[1]]
+  visibleCreateTime.value[0] = false
+}
+
+/** 访问时间[1]确认 */
+function handleCreateTime1Confirm() {
+  formData.createTime = [formData.createTime?.[0], tempCreateTime.value[1]]
+  visibleCreateTime.value[1] = false
+}
+
+/** 搜索 */
+function handleSearch() {
+  visible.value = false
+  const dateRange = formatDateRange(formData.createTime)
+  emit('search', {
+    userId: formData.userId,
+    applicationName: formData.applicationName,
+    beginTime: dateRange?.[0],
+    endTime: dateRange?.[1],
+  })
+}
+
+/** 重置 */
+function handleReset() {
+  formData.userId = undefined
+  formData.applicationName = undefined
+  formData.createTime = [undefined, undefined]
+  visible.value = false
+  emit('reset')
+}
+</script>

+ 3 - 3
src/pages-infra/apiAccessLog/detail/index.vue

@@ -52,10 +52,10 @@
 </template>
 
 <script lang="ts" setup>
-import type { ApiAccessLog } from '@/api/infra/apiAccessLog'
+import type { ApiAccessLog } from '@/api/infra/api-access-log'
 import { onMounted, ref } from 'vue'
 import { useToast } from 'wot-design-uni'
-import { getApiAccessLog } from '@/api/infra/apiAccessLog'
+import { getApiAccessLog } from '@/api/infra/api-access-log'
 import { getDictLabel } from '@/hooks/useDict'
 import { navigateBackPlus } from '@/utils'
 import { DICT_TYPE } from '@/utils/constants'
@@ -77,7 +77,7 @@ const toast = useToast()
 
 /** 返回上一页 */
 function handleBack() {
-  navigateBackPlus('/pages-infra/apiAccessLog/index')
+  navigateBackPlus('/pages-infra/api-access-log/index')
 }
 
 /** 复制文本并提示 */

+ 3 - 3
src/pages-infra/apiAccessLog/index.vue

@@ -68,11 +68,11 @@
 </template>
 
 <script lang="ts" setup>
-import type { ApiAccessLog } from '@/api/infra/apiAccessLog'
+import type { ApiAccessLog } from '@/api/infra/api-access-log'
 import type { LoadMoreState } from '@/http/types'
 import { onReachBottom } from '@dcloudio/uni-app'
 import { onMounted, ref } from 'vue'
-import { getApiAccessLogPage } from '@/api/infra/apiAccessLog'
+import { getApiAccessLogPage } from '@/api/infra/api-access-log'
 import { navigateBackPlus } from '@/utils'
 import { formatDateTime } from '@/utils/date'
 import SearchForm from './components/search-form.vue'
@@ -139,7 +139,7 @@ function loadMore() {
 /** 查看详情 */
 function handleDetail(item: ApiAccessLog) {
   uni.navigateTo({
-    url: `/pages-infra/apiAccessLog/detail/index?id=${item.id}`,
+    url: `/pages-infra/api-access-log/detail/index?id=${item.id}`,
   })
 }
 

+ 59 - 0
src/pages-infra/apiErrorLog/components/search-form.vue

@@ -49,6 +49,42 @@
           </wd-radio>
         </wd-radio-group>
       </view>
+      <view class="yd-search-form-item">
+        <view class="yd-search-form-label">
+          异常时间
+        </view>
+        <view class="yd-search-form-date-range-container">
+          <view class="flex-1" @click="visibleExceptionTime[0] = true">
+            <view class="yd-search-form-date-range-picker">
+              {{ formatDate(formData.exceptionTime?.[0]) || '开始日期' }}
+            </view>
+          </view>
+          -
+          <view class="flex-1" @click="visibleExceptionTime[1] = true">
+            <view class="yd-search-form-date-range-picker">
+              {{ formatDate(formData.exceptionTime?.[1]) || '结束日期' }}
+            </view>
+          </view>
+        </view>
+        <wd-datetime-picker-view v-if="visibleExceptionTime[0]" v-model="tempExceptionTime[0]" type="date" />
+        <view v-if="visibleExceptionTime[0]" class="yd-search-form-date-range-actions">
+          <wd-button size="small" plain @click="visibleExceptionTime[0] = false">
+            取消
+          </wd-button>
+          <wd-button size="small" type="primary" @click="handleExceptionTime0Confirm">
+            确定
+          </wd-button>
+        </view>
+        <wd-datetime-picker-view v-if="visibleExceptionTime[1]" v-model="tempExceptionTime[1]" type="date" />
+        <view v-if="visibleExceptionTime[1]" class="yd-search-form-date-range-actions">
+          <wd-button size="small" plain @click="visibleExceptionTime[1] = false">
+            取消
+          </wd-button>
+          <wd-button size="small" type="primary" @click="handleExceptionTime1Confirm">
+            确定
+          </wd-button>
+        </view>
+      </view>
       <view class="yd-search-form-actions">
         <wd-button class="flex-1" plain @click="handleReset">
           重置
@@ -64,6 +100,7 @@
 <script lang="ts" setup>
 import { computed, reactive, ref } from 'vue'
 import { getNavbarHeight } from '@/utils'
+import { formatDate, formatDateRange } from '@/utils/date'
 
 const emit = defineEmits<{
   search: [data: Record<string, any>]
@@ -75,6 +112,7 @@ const formData = reactive({
   userId: undefined as number | undefined,
   applicationName: undefined as string | undefined,
   processStatus: -1, // -1 表示全部
+  exceptionTime: [undefined, undefined] as [number | undefined, number | undefined],
 })
 
 /** 搜索条件 placeholder 拼接 */
@@ -90,15 +128,35 @@ const placeholder = computed(() => {
     const statusMap: Record<number, string> = { 0: '未处理', 1: '已处理', 2: '已忽略' }
     conditions.push(`状态:${statusMap[formData.processStatus]}`)
   }
+  if (formData.exceptionTime?.[0] && formData.exceptionTime?.[1]) {
+    conditions.push(`时间:${formatDate(formData.exceptionTime[0])}~${formatDate(formData.exceptionTime[1])}`)
+  }
   return conditions.length > 0 ? conditions.join(' | ') : '搜索日志'
 })
 
+// 时间范围选择器状态
+const visibleExceptionTime = ref<[boolean, boolean]>([false, false])
+const tempExceptionTime = ref<[number, number]>([Date.now(), Date.now()])
+
+/** 异常时间[0]确认 */
+function handleExceptionTime0Confirm() {
+  formData.exceptionTime = [tempExceptionTime.value[0], formData.exceptionTime?.[1]]
+  visibleExceptionTime.value[0] = false
+}
+
+/** 异常时间[1]确认 */
+function handleExceptionTime1Confirm() {
+  formData.exceptionTime = [formData.exceptionTime?.[0], tempExceptionTime.value[1]]
+  visibleExceptionTime.value[1] = false
+}
+
 /** 搜索 */
 function handleSearch() {
   visible.value = false
   emit('search', {
     ...formData,
     processStatus: formData.processStatus === -1 ? undefined : formData.processStatus,
+    exceptionTime: formatDateRange(formData.exceptionTime),
   })
 }
 
@@ -107,6 +165,7 @@ function handleReset() {
   formData.userId = undefined
   formData.applicationName = undefined
   formData.processStatus = -1
+  formData.exceptionTime = [undefined, undefined]
   visible.value = false
   emit('reset')
 }

+ 3 - 3
src/pages-infra/apiErrorLog/detail/index.vue

@@ -60,10 +60,10 @@
 </template>
 
 <script lang="ts" setup>
-import type { ApiErrorLog } from '@/api/infra/apiErrorLog'
+import type { ApiErrorLog } from '@/api/infra/api-error-log'
 import { onMounted, ref } from 'vue'
 import { useToast } from 'wot-design-uni'
-import { getApiErrorLog, updateApiErrorLogStatus } from '@/api/infra/apiErrorLog'
+import { getApiErrorLog, updateApiErrorLogStatus } from '@/api/infra/api-error-log'
 import { getDictLabel } from '@/hooks/useDict'
 import { navigateBackPlus } from '@/utils'
 import { DICT_TYPE, InfraApiErrorLogProcessStatusEnum } from '@/utils/constants'
@@ -86,7 +86,7 @@ const processing = ref(false) // 处理中
 
 /** 返回上一页 */
 function handleBack() {
-  navigateBackPlus('/pages-infra/apiErrorLog/index')
+  navigateBackPlus('/pages-infra/api-error-log/index')
 }
 
 /** 复制文本并提示 */

+ 3 - 3
src/pages-infra/apiErrorLog/index.vue

@@ -58,11 +58,11 @@
 </template>
 
 <script lang="ts" setup>
-import type { ApiErrorLog } from '@/api/infra/apiErrorLog'
+import type { ApiErrorLog } from '@/api/infra/api-error-log'
 import type { LoadMoreState } from '@/http/types'
 import { onReachBottom } from '@dcloudio/uni-app'
 import { onMounted, ref } from 'vue'
-import { getApiErrorLogPage } from '@/api/infra/apiErrorLog'
+import { getApiErrorLogPage } from '@/api/infra/api-error-log'
 import { navigateBackPlus } from '@/utils'
 import { DICT_TYPE } from '@/utils/constants'
 import { formatDateTime } from '@/utils/date'
@@ -130,7 +130,7 @@ function loadMore() {
 /** 查看详情 */
 function handleDetail(item: ApiErrorLog) {
   uni.navigateTo({
-    url: `/pages-infra/apiErrorLog/detail/index?id=${item.id}`,
+    url: `/pages-infra/api-error-log/detail/index?id=${item.id}`,
   })
 }
 

+ 0 - 83
src/pages-infra/apiAccessLog/components/search-form.vue

@@ -1,83 +0,0 @@
-<template>
-  <!-- 搜索框入口 -->
-  <view @click="visible = true">
-    <wd-search :placeholder="placeholder" hide-cancel disabled />
-  </view>
-
-  <!-- 搜索弹窗 -->
-  <wd-popup v-model="visible" position="top" @close="visible = false">
-    <view class="yd-search-form-container" :style="{ paddingTop: `${getNavbarHeight()}px` }">
-      <view class="yd-search-form-item">
-        <view class="yd-search-form-label">
-          用户编号
-        </view>
-        <wd-input
-          v-model="formData.userId"
-          placeholder="请输入用户编号"
-          clearable
-        />
-      </view>
-      <view class="yd-search-form-item">
-        <view class="yd-search-form-label">
-          应用名
-        </view>
-        <wd-input
-          v-model="formData.applicationName"
-          placeholder="请输入应用名"
-          clearable
-        />
-      </view>
-      <!-- TODO @芋艿:后续增加时间范围的检索 -->
-      <view class="yd-search-form-actions">
-        <wd-button class="flex-1" plain @click="handleReset">
-          重置
-        </wd-button>
-        <wd-button class="flex-1" type="primary" @click="handleSearch">
-          搜索
-        </wd-button>
-      </view>
-    </view>
-  </wd-popup>
-</template>
-
-<script lang="ts" setup>
-import { computed, reactive, ref } from 'vue'
-import { getNavbarHeight } from '@/utils'
-
-const emit = defineEmits<{
-  search: [data: Record<string, any>]
-  reset: []
-}>()
-
-const visible = ref(false)
-const formData = reactive({
-  userId: undefined as number | undefined,
-  applicationName: undefined as string | undefined,
-})
-
-/** 搜索条件 placeholder 拼接 */
-const placeholder = computed(() => {
-  const conditions: string[] = []
-  if (formData.userId) {
-    conditions.push(`用户编号:${formData.userId}`)
-  }
-  if (formData.applicationName) {
-    conditions.push(`应用名:${formData.applicationName}`)
-  }
-  return conditions.length > 0 ? conditions.join(' | ') : '搜索日志'
-})
-
-/** 搜索 */
-function handleSearch() {
-  visible.value = false
-  emit('search', { ...formData })
-}
-
-/** 重置 */
-function handleReset() {
-  formData.userId = undefined
-  formData.applicationName = undefined
-  visible.value = false
-  emit('reset')
-}
-</script>

src/pages-infra/webSocket/index.vue → src/pages-infra/web-socket/index.vue


+ 3 - 3
src/pages/index/index.ts

@@ -103,7 +103,7 @@ const menuGroupsData: MenuGroup[] = [
         key: 'accessLog',
         name: '访问日志',
         icon: 'laptop',
-        url: '/pages-infra/apiAccessLog/index',
+        url: '/pages-infra/api-access-log/index',
         iconColor: '#2f54eb',
         permission: 'infra:api-access-log:query',
       },
@@ -111,7 +111,7 @@ const menuGroupsData: MenuGroup[] = [
         key: 'errorLog',
         name: '错误日志',
         icon: 'error-circle',
-        url: '/pages-infra/apiErrorLog/index',
+        url: '/pages-infra/api-error-log/index',
         iconColor: '#f5222d',
         permission: 'infra:api-error-log:query',
       },
@@ -119,7 +119,7 @@ const menuGroupsData: MenuGroup[] = [
         key: 'websocket',
         name: 'WebSocket',
         icon: 'chat',
-        url: '/pages-infra/webSocket/index',
+        url: '/pages-infra/web-socket/index',
         iconColor: '#36cfc9',
       },
     ],