Skip to content

Commit

Permalink
wopan
Browse files Browse the repository at this point in the history
  • Loading branch information
liov committed Sep 23, 2024
1 parent 366d7a0 commit 8bea32b
Show file tree
Hide file tree
Showing 41 changed files with 218 additions and 101 deletions.
2 changes: 1 addition & 1 deletion client/uniapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"@dcloudio/uni-quickapp-webview": "3.0.0-4020420240722002",
"@dcloudio/uni-ui": "^1.5.6",
"dayjs": "1.11.12",
"diamond": "file:../../thirdparty/diamond",
"diamond": "file:..\\..\\thirdparty\\diamond",
"pinia": "2.2.0",
"pinia-plugin-persistedstate": "3.2.1",
"vue": "3.4.21",
Expand Down
6 changes: 3 additions & 3 deletions client/uniapp/src/interceptors/http.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-param-reassign */
import qs from 'qs'
import { useUserStore } from '@/store'
import { useUserStore } from '@/store/user'
import { platform } from '@/utils/platform'
import { toUrlParams } from 'diamond/compatible'

export type CustomRequestOptions = UniApp.RequestOptions & {
query?: Record<string, any>
Expand All @@ -18,7 +18,7 @@ const httpInterceptor = {
invoke(options: CustomRequestOptions) {
// 接口请求支持通过 query 参数配置 queryString
if (options.query) {
const queryStr = qs.stringify(options.query)
const queryStr = toUrlParams(options.query)
if (options.url.includes('?')) {
options.url += `&${queryStr}`
} else {
Expand Down
4 changes: 2 additions & 2 deletions client/uniapp/src/interceptors/request.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import uniHttp from '@/utils/request'
import { API_HOST } from '@/env/config'
import { userStore } from '@/store'
import { useUserStore } from '@/store/user'

export function init() {
uniHttp.defaults.baseUrl = API_HOST
const token = uni.getStorageSync('token')

const userStore = useUserStore()
uniHttp.defaults.header.Authorization = token || userStore.token

// 添加请求拦截器
Expand Down
4 changes: 2 additions & 2 deletions client/uniapp/src/interceptors/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* 可以设置路由白名单,或者黑名单,看业务需要选哪一个
* 我这里应为大部分都可以随便进入,所以使用黑名单
*/
import { useUserStore } from '@/store'
import { useUserStore } from '@/store/user'
import { getNeedLoginPages, needLoginPages as _needLoginPages } from '@/utils'

// TODO Check
const loginRoute = '/pages/login/index'

const isLogined = () => {
const userStore = useUserStore()
return userStore.info !== null
return userStore.auth !== null
}

const isDev = import.meta.env.DEV
Expand Down
7 changes: 4 additions & 3 deletions client/uniapp/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { createSSRApp } from 'vue'
import App from './App.vue'
import store, { init as storeInit } from './store'
import * as Pinia from 'pinia'
import { init as uniHttpInit } from '@/interceptors/request'
import i18n from './locale/index'
import { routeInterceptor, requestInterceptor, prototypeInterceptor } from './interceptors'
import 'virtual:uno.css'
import '@/style/index.scss'
import '@/service/wopan'

export function createApp() {
const app = createSSRApp(App)
app.use(store)
app.use(Pinia.createPinia())
app.use(i18n)
app.use(routeInterceptor)
app.use(requestInterceptor)
app.use(prototypeInterceptor)
storeInit()
uniHttpInit()
return {
app,
Pinia, // 此处必须将 Pinia 返回
}
}
2 changes: 1 addition & 1 deletion client/uniapp/src/model/content.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type ContentExt = {
export type ContentExt = {
likeCount: number
commentCount: number
}
2 changes: 1 addition & 1 deletion client/uniapp/src/pages/index/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class="bg-white overflow-hidden pt-2 px-4"
:style="{ marginTop: safeAreaInsets?.top + 'px' }"
>
<navigator url="/pages/wopan/login" hover-class="navigator-hover">
<navigator url="/pages/wopan/list" hover-class="navigator-hover">
<button type="default">wopan</button>
</navigator>
</view>
Expand Down
5 changes: 3 additions & 2 deletions client/uniapp/src/pages/moment/moment_list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@
<script setup lang="ts">
import Actions from '@/components/action.vue'
import MomentService from '@/service/moment'
import { userStore } from '@/store'
import { STATIC_DIR as staticDir } from '@/env/config'
import type { Moment, MomentList } from '@/model/moment'
import type { User } from '@/model/user'
import { onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
import type { PageRequest } from '@/service/param'
import { useUserStore } from '@/store/user'
const userStore = useUserStore()
const listReq: PageRequest = {
PageNo: 1,
PageSize: 10,
Expand Down
13 changes: 12 additions & 1 deletion client/uniapp/src/pages/wopan/list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@
},
}
</route>
<template></template>
<template><view></view></template>

<script lang="ts" setup>
import { useWopanStore } from '@/store/wopan'
defineOptions({
name: 'WopanList',
})
const wopanStore = useWopanStore()
if (wopanStore.$state.accessToken === '') {
uni.navigateTo({
url: '/pages/wopan/login',
})
}
if (wopanStore.$state.psToken === '') {
console.log('psToken is empty')
}
</script>

<style scoped></style>
37 changes: 24 additions & 13 deletions client/uniapp/src/pages/wopan/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@
<wd-input
label="用户名"
label-width="100px"
prop="value1"
prop="phone"
clearable
v-model="model.phone"
placeholder="请输入用户名"
:rules="[{ required: true, message: '请填写用户名' }]"
/>
<wd-input
label="密码"
label="验证码"
label-width="100px"
prop="value2"
show-password
prop="smsCode"
clearable
v-model="model.password"
placeholder="请输入密码"
:rules="[{ required: true, message: '请填写密码' }]"
/>
use-suffix-slot
v-model="model.smsCode"
placeholder="请输入验证码"
:rules="[{ required: true, message: '请填写验证码' }]"
>
<template #suffix>
<view><wd-button @click="sendSmsCode">获取验证码</wd-button></view>
</template>
</wd-input>
</wd-cell-group>
<view class="footer">
<wd-button type="primary" size="large" @click="handleSubmit" block>提交</wd-button>
Expand All @@ -44,20 +48,23 @@
import PLATFORM from '@/utils/platform'
import { useToast } from 'wot-design-uni'
import * as wopan from 'diamond/wopan'
import { useWopanStore } from '@/store/wopan'
defineOptions({
name: 'WopanLogin',
})
const wopanStore = useWopanStore()
// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()
const { success: showSuccess } = useToast()
const model = reactive<{
phone: string
password: string
smsCode: string
}>({
phone: '',
password: '',
smsCode: '',
})
onLoad(() => {
Expand All @@ -66,12 +73,16 @@ onLoad(() => {
const form = ref()
function sendSmsCode() {
wopan.sendMessageCodeBase(model.phone)
}
function handleSubmit() {
form.value
.validate()
.then(({ valid, errors }) => {
.then(async ({ valid, errors }) => {
if (valid) {
const res = wopan.PcWebLogin(model.phone, model.password)
await wopanStore.AppLoginByMobile(model)
showSuccess({
msg: '校验通过',
})
Expand Down
5 changes: 3 additions & 2 deletions client/uniapp/src/service/moment.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { API_HOST } from '@/env/config'
import type { MomentList } from '@/model/moment'
import request from '@/utils/request'
import { userStore } from '@/store'
import moment from '@/pages/moment/moment_list.vue'

import moment from '@/pages/moment/moment_list.vue'
import { useUserStore } from '@/store/user'
const userStore = useUserStore()
class MomentService {
static async getMomentList(pageNo: number, pageSize: number): Promise<MomentList> {
const { data } = await request.get<ResData<MomentList>>(
Expand Down
1 change: 0 additions & 1 deletion client/uniapp/src/service/user.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { API_HOST } from '@/env/config'
import type { MomentList } from '@/model/moment'
import request from '@/utils/request'
import { userStore } from '@/store'
import moment from '@/pages/moment/moment_list.vue'

class UserService {
Expand Down
7 changes: 3 additions & 4 deletions client/uniapp/src/service/wopan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ client.fetch = async function (url, method, headers, body) {
}
client.setToken(uni.getStorageSync('accessToken'), uni.getStorageSync('accessToken'))
client.psToken = uni.getStorageSync('psToken')

const wopanClient = client

export default wopanClient
client.proxy = 'http://localhost:8080'
console.log(client)
export default client
7 changes: 3 additions & 4 deletions client/uniapp/src/store/content.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ObjMap } from '@/utils/user'
import { defineStore } from 'pinia'

export interface ContentStore {
export interface ContentState {
moment: any
note?: any
diary?: any
Expand All @@ -12,7 +12,7 @@ export interface ContentStore {
commentCache: Map<number, any[]>
}

const state: ContentStore = {
const state: ContentState = {
moment: null,
commentCache: new Map<number, any[]>(),
}
Expand All @@ -28,8 +28,7 @@ const getters = {
},
}

export const useContentStore = defineStore({
id: 'content',
export const useContentStore = defineStore('content', {
state: () => state,
getters,
actions,
Expand Down
5 changes: 2 additions & 3 deletions client/uniapp/src/store/global.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia'
import { Platform } from '@/env/platform'

interface GlobalState {
export interface GlobalState {
counter: number
platform: Platform
}
Expand All @@ -11,8 +11,7 @@ const state: GlobalState = {
platform: Platform.H5,
}

export const useGlobalStore = defineStore({
id: 'global',
export const useGlobalStore = defineStore('global', {
state: () => state,
getters: {
doubleCount: (state) => state.counter * 2,
Expand Down
24 changes: 2 additions & 22 deletions client/uniapp/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,12 @@ import { useGlobalStore } from '@/store/global'
import { useContentStore } from '@/store/content'
import { useWopanStore } from '@/store/wopan'

const store = createPinia()
/* const store = createPinia()
store.use(
createPersistedState({
storage: {
getItem: uni.getStorageSync,
setItem: uni.setStorageSync,
},
}),
)

export let userStore
export let globalStore
export let contentStore
export let wopanStore

export function init() {
globalStore = useGlobalStore()
userStore = useUserStore()
contentStore = useContentStore()
wopanStore = useWopanStore()
if (!userStore.auth) {
userStore.getAuth()
}
}

export default store

// 模块统一导出
export * from './user'
) */
Loading

0 comments on commit 8bea32b

Please sign in to comment.