diff --git a/code/base-project/base-uniapp/src/components/picker-select-input/index.vue b/code/base-project/base-uniapp/src/components/picker-select-input/index.vue
index b6f45263..40155745 100644
--- a/code/base-project/base-uniapp/src/components/picker-select-input/index.vue
+++ b/code/base-project/base-uniapp/src/components/picker-select-input/index.vue
@@ -24,6 +24,20 @@ const props = defineProps({
},
viewname: {
type: String,
+ required: true,
+ },
+ searchcondition: {
+ type: String,
+ required: false,
+ },
+ userid: {
+ type: String,
+ required: false,
+ },
+ searchType: {
+ type: String as PropType<'default' | 'ex' | 'single'>,
+ default: 'default',
+ required: false,
},
})
diff --git a/code/base-project/base-uniapp/src/components/picker-select/index.vue b/code/base-project/base-uniapp/src/components/picker-select/index.vue
index 0ddfebb5..7590395e 100644
--- a/code/base-project/base-uniapp/src/components/picker-select/index.vue
+++ b/code/base-project/base-uniapp/src/components/picker-select/index.vue
@@ -1,6 +1,8 @@
@@ -137,6 +233,7 @@ function handlePagationChange(page: number) {
v-model="searchValue"
placeholder="请输入搜索的值"
clearable
+ @confirm="handleSearch"
>
@@ -154,7 +251,7 @@ function handlePagationChange(page: number) {
:throttle="false"
>
@@ -166,7 +263,7 @@ function handlePagationChange(page: number) {
-
-
-
-
+
diff --git a/code/base-project/base-uniapp/src/store/index.ts b/code/base-project/base-uniapp/src/store/index.ts
new file mode 100644
index 00000000..913ff215
--- /dev/null
+++ b/code/base-project/base-uniapp/src/store/index.ts
@@ -0,0 +1,16 @@
+import { createPinia } from 'pinia'
+import { createPersistedState } from 'pinia-plugin-persistedstate' // 数据持久化
+
+const store = createPinia()
+store.use(
+ createPersistedState({
+ storage: {
+ getItem: uni.getStorageSync,
+ setItem: uni.setStorageSync,
+ },
+ }),
+)
+
+export default store
+
+export * from './user'
diff --git a/code/base-project/base-uniapp/src/store/user.ts b/code/base-project/base-uniapp/src/store/user.ts
new file mode 100644
index 00000000..fae61faf
--- /dev/null
+++ b/code/base-project/base-uniapp/src/store/user.ts
@@ -0,0 +1,44 @@
+import { defineStore } from 'pinia'
+import { computed, ref } from 'vue'
+import { toast } from '@/utils/toast'
+
+const initState = { token: '', orgid: '', userid: '' }
+
+export const useUserStore = defineStore(
+ 'user',
+ () => {
+ const userInfo = ref({ ...initState })
+
+ const setUserInfo = (val: IUserInfo) => {
+ userInfo.value = val
+ }
+
+ const reset = () => {
+ userInfo.value = { orgid: userInfo.value.orgid, userid: userInfo.value.userid, token: '' }
+ }
+
+ const isLogined = computed(
+ () => !!(userInfo.value.token && userInfo.value.orgid && userInfo.value.userid),
+ )
+
+ function validateLogin(): boolean {
+ if (!isLogined.value) {
+ toast.error('尚未登陆或登录已过期')
+ uni.navigateTo({ url: '/pages-sub/login/index' })
+ return false
+ }
+ return true
+ }
+
+ return {
+ userInfo,
+ setUserInfo,
+ reset,
+ isLogined,
+ validateLogin,
+ }
+ },
+ {
+ persist: true,
+ },
+)
diff --git a/code/base-project/base-uniapp/src/style/index.scss b/code/base-project/base-uniapp/src/style/index.scss
index 011668f7..6946e746 100644
--- a/code/base-project/base-uniapp/src/style/index.scss
+++ b/code/base-project/base-uniapp/src/style/index.scss
@@ -7,3 +7,7 @@
height: auto !important;
}
}
+
+uni-toast {
+ z-index: 9999 !important; /* 根据实际情况进行调整 */
+}
diff --git a/code/base-project/base-uniapp/src/typings.d.ts b/code/base-project/base-uniapp/src/typings.d.ts
index e4271774..824a2621 100644
--- a/code/base-project/base-uniapp/src/typings.d.ts
+++ b/code/base-project/base-uniapp/src/typings.d.ts
@@ -3,7 +3,7 @@
declare global {
interface IResData {
code: number
- msg: string
+ message: string
data: T
}
@@ -17,16 +17,11 @@ declare global {
}
interface IUserInfo {
- nickname?: string
- avatar?: string
+ orgid?: string // 机构码
+ userid?: string // 主键id,登录账号
/** 微信的 openid,非微信没有这个字段 */
openid?: string
- }
-
- interface IUserToken {
- token: string
- refreshToken?: string
- refreshExpire?: number
+ token?: string
}
}
diff --git a/code/base-project/base-uniapp/src/utils/common.ts b/code/base-project/base-uniapp/src/utils/common.ts
new file mode 100644
index 00000000..c8568e3f
--- /dev/null
+++ b/code/base-project/base-uniapp/src/utils/common.ts
@@ -0,0 +1,38 @@
+import { toast } from './toast'
+
+export function joinUrl(base: string, path: string): string {
+ if (!base)
+ return path || ''
+ if (!path)
+ return base || ''
+
+ const baseEndsWithSlash = base.endsWith('/')
+ const pathStartsWithSlash = path.startsWith('/')
+
+ if (baseEndsWithSlash && pathStartsWithSlash) {
+ // 都有斜杠,去掉 base 末尾那个
+ return base.slice(0, -1) + path
+ }
+ else if (!baseEndsWithSlash && !pathStartsWithSlash) {
+ // 都没有斜杠,补一个
+ return `${base}/${path}`
+ }
+ else {
+ // 只有一个斜杠,直接拼接
+ return base + path
+ }
+}
+
+export function checkRequiredParams(options: Record, keys: string[]): boolean {
+ for (const key of keys) {
+ const value = options[key]
+ if (!value || value === 'undefined' || value === 'null') {
+ toast.error(`参数 "${key}" 有误!`)
+ setTimeout(() => {
+ uni.navigateBack()
+ }, 1000)
+ return false
+ }
+ }
+ return true
+}
diff --git a/code/base-project/base-uniapp/src/utils/platform.ts b/code/base-project/base-uniapp/src/utils/platform.ts
new file mode 100644
index 00000000..86801f17
--- /dev/null
+++ b/code/base-project/base-uniapp/src/utils/platform.ts
@@ -0,0 +1,26 @@
+/*
+ * @Author: 菲鸽
+ * @Date: 2024-03-28 19:13:55
+ * @Last Modified by: 菲鸽
+ * @Last Modified time: 2024-03-28 19:24:55
+ */
+export const platform = __UNI_PLATFORM__
+export const isH5 = __UNI_PLATFORM__ === 'h5'
+export const isApp = __UNI_PLATFORM__ === 'app'
+export const isMp = __UNI_PLATFORM__.startsWith('mp-')
+export const isMpWeixin = __UNI_PLATFORM__.startsWith('mp-weixin')
+export const isMpAplipay = __UNI_PLATFORM__.startsWith('mp-alipay')
+export const isMpToutiao = __UNI_PLATFORM__.startsWith('mp-toutiao')
+export const isHarmony = __UNI_PLATFORM__.startsWith('app-harmony')
+
+const PLATFORM = {
+ platform,
+ isH5,
+ isApp,
+ isMp,
+ isMpWeixin,
+ isMpAplipay,
+ isMpToutiao,
+ isHarmony,
+}
+export default PLATFORM
diff --git a/code/base-project/base-uniapp/src/utils/request.ts b/code/base-project/base-uniapp/src/utils/request.ts
new file mode 100644
index 00000000..c414632a
--- /dev/null
+++ b/code/base-project/base-uniapp/src/utils/request.ts
@@ -0,0 +1,28 @@
+export function getServerBaseUrl(): string {
+ const origin = window.location.origin
+ const publicBase = import.meta.env.VITE_APP_PUBLIC_BASE || '/'
+
+ // 拼接时去掉 publicBase 开头和结尾的斜杠(只保留中间路径)
+ const cleanBase = publicBase.replace(/^\/+|\/+$/g, '')
+
+ return cleanBase ? `${origin}/${cleanBase}` : origin
+}
+
+export async function getDbConfigs(): Promise | null> {
+ const serverBaseUrl = getServerBaseUrl()
+
+ try {
+ const response = await fetch(`${serverBaseUrl}/static/db.json`)
+ if (!response.ok) {
+ console.error('Failed to fetch db.json:', response.status)
+ return null
+ }
+
+ const data: Record = await response.json()
+ return data
+ }
+ catch (error) {
+ console.error('Error fetching db.json:', error)
+ return null
+ }
+}
diff --git a/code/base-project/base-uniapp/src/utils/toast.ts b/code/base-project/base-uniapp/src/utils/toast.ts
new file mode 100644
index 00000000..e524b000
--- /dev/null
+++ b/code/base-project/base-uniapp/src/utils/toast.ts
@@ -0,0 +1,65 @@
+/**
+ * toast 弹窗组件
+ * 支持 success/error/warning/info 四种状态
+ * 可配置 duration, position 等参数
+ */
+
+type ToastType = 'success' | 'error' | 'warning' | 'info'
+
+interface ToastOptions {
+ type?: ToastType
+ duration?: number
+ position?: 'top' | 'middle' | 'bottom'
+ icon?: 'success' | 'error' | 'none' | 'loading' | 'fail' | 'exception'
+ message: string
+}
+
+export function showToast(options: ToastOptions | string) {
+ const defaultOptions: ToastOptions = {
+ type: 'info',
+ duration: 2000,
+ position: 'middle',
+ message: '',
+ }
+ const mergedOptions
+ = typeof options === 'string'
+ ? { ...defaultOptions, message: options }
+ : { ...defaultOptions, ...options }
+ // 映射position到uniapp支持的格式
+ const positionMap: Record = {
+ top: 'top',
+ middle: 'center',
+ bottom: 'bottom',
+ }
+
+ // 映射图标类型
+ const iconMap: Record<
+ ToastType,
+ 'success' | 'error' | 'none' | 'loading' | 'fail' | 'exception'
+ > = {
+ success: 'success',
+ error: 'error',
+ warning: 'fail',
+ info: 'none',
+ }
+
+ // 调用uni.showToast显示提示
+ uni.showToast({
+ title: mergedOptions.message,
+ duration: mergedOptions.duration,
+ position: positionMap[mergedOptions.position],
+ icon: mergedOptions.icon || iconMap[mergedOptions.type],
+ mask: true,
+ })
+}
+
+export const toast = {
+ success: (message: string, options?: Omit) =>
+ showToast({ ...options, type: 'success', message }),
+ error: (message: string, options?: Omit) =>
+ showToast({ ...options, type: 'error', message }),
+ warning: (message: string, options?: Omit) =>
+ showToast({ ...options, type: 'warning', message }),
+ info: (message: string, options?: Omit) =>
+ showToast({ ...options, type: 'info', message }),
+}