Skip to content

Commit

Permalink
wopan
Browse files Browse the repository at this point in the history
  • Loading branch information
liov committed Sep 11, 2024
1 parent 1b5655f commit 366d7a0
Show file tree
Hide file tree
Showing 24 changed files with 256 additions and 63 deletions.
2 changes: 1 addition & 1 deletion awesome
4 changes: 2 additions & 2 deletions client/uniapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@
"@dcloudio/uni-quickapp-webview": "3.0.0-4020420240722002",
"@dcloudio/uni-ui": "^1.5.6",
"dayjs": "1.11.12",
"diamond": "file:../../thirdparty/diamond",
"pinia": "2.2.0",
"pinia-plugin-persistedstate": "3.2.1",
"qs": "6.12.3",
"vue": "3.4.21",
"wot-design-uni": "^1.3.6",
"z-paging": "^2.7.11"
Expand Down Expand Up @@ -148,7 +148,7 @@
"unplugin-auto-import": "^0.18.2",
"vite": "5.2.8",
"vite-plugin-restart": "^0.4.1",
"vue-i18n": "^9.1.9",
"vue-i18n": "9.1.9",
"vue-tsc": "^2.0.29"
},
"packageManager": "[email protected]+sha512.38dc6fba8dba35b39340b9700112c2fe1e12f10b17134715a4aa98ccf7bb035e76fd981cf0bb384dfa98f8d6af5481c2bef2f4266a24bfa20c34eb7147ce0b5e"
Expand Down
31 changes: 31 additions & 0 deletions client/uniapp/src/pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,37 @@
"style": {
"navigationBarTitleText": "瞬间"
}
},
{
"path": "pages/user/active",
"type": "page",
"style": {
"navigationStyle": "custom",
"navigationBarTitleText": "激活"
}
},
{
"path": "pages/user/login",
"type": "page",
"style": {
"navigationBarTitleText": "登录"
}
},
{
"path": "pages/wopan/list",
"type": "page",
"style": {
"navigationStyle": "custom",
"navigationBarTitleText": "wopan列表"
}
},
{
"path": "pages/wopan/login",
"type": "page",
"style": {
"navigationStyle": "custom",
"navigationBarTitleText": "wopan登录"
}
}
],
"subPackages": []
Expand Down
35 changes: 6 additions & 29 deletions client/uniapp/src/pages/index/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,27 @@
class="bg-white overflow-hidden pt-2 px-4"
:style="{ marginTop: safeAreaInsets?.top + 'px' }"
>
<view class="mt-12">
<image src="/static/logo.svg" alt="" class="w-28 h-28 block mx-auto" />
</view>
<view class="text-center text-4xl main-title-color mt-4">hoper</view>
<view class="text-center text-2xl mt-2 mb-8">hoper with record</view>
<view class="text-justify max-w-100 m-auto text-4 indent mb-2">{{ description }}</view>
<navigator url="/pages/moment/moment_list?title=navigate" hover-class="navigator-hover">
<image class="logo" src="/static/logo.svg" />
<navigator url="/pages/wopan/login" hover-class="navigator-hover">
<button type="default">wopan</button>
</navigator>
<view class="text-area">
<text class="title">{{ title }}</text>
</view>
<view class="text-center mt-8">
当前平台是:
<text class="text-green-500">{{ PLATFORM.platform }}</text>
</view>
<view class="text-center mt-4">
模板分支是:
<text class="text-green-500">i18n</text>
</view>
</view>
<tabbar />
</template>
<script lang="ts" setup>
import PLATFORM from '@/utils/platform'
import { useToast } from 'wot-design-uni'
import * as wopan from 'diamond/es/wopan'
defineOptions({
name: 'Home',
})
// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()
const description = ref('首页')
onLoad(() => {
console.log('a')
})
</script>
<style>
.main-title-color {
color: #d14328;
.footer {
padding: 12px;
}
</style>
2 changes: 1 addition & 1 deletion client/uniapp/src/pages/user/login.h5.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</template>

<script setup lang="ts">
import { dynamicLoadJs } from '@/utils/h5'
import { dynamicLoadJs } from 'diamond/browser'
const turnstile = window.turnstile
const onloadTurnstileCallback = function () {
Expand Down
17 changes: 17 additions & 0 deletions client/uniapp/src/pages/wopan/list.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<route lang="json5">
{
style: {
navigationStyle: 'custom',
navigationBarTitleText: 'wopan列表',
},
}
</route>
<template></template>

<script lang="ts" setup>
defineOptions({
name: 'WopanList',
})
</script>

<style scoped></style>
90 changes: 90 additions & 0 deletions client/uniapp/src/pages/wopan/login.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<route lang="json5">
{
style: {
navigationStyle: 'custom',
navigationBarTitleText: 'wopan登录',
},
}
</route>
<template>
<view
class="bg-white overflow-hidden pt-2 px-4"
:style="{ marginTop: safeAreaInsets?.top + 'px' }"
>
<wd-form ref="form" :model="model">
<wd-cell-group border>
<wd-input
label="用户名"
label-width="100px"
prop="value1"
clearable
v-model="model.phone"
placeholder="请输入用户名"
:rules="[{ required: true, message: '请填写用户名' }]"
/>
<wd-input
label="密码"
label-width="100px"
prop="value2"
show-password
clearable
v-model="model.password"
placeholder="请输入密码"
:rules="[{ required: true, message: '请填写密码' }]"
/>
</wd-cell-group>
<view class="footer">
<wd-button type="primary" size="large" @click="handleSubmit" block>提交</wd-button>
</view>
</wd-form>
</view>
</template>
<script lang="ts" setup>
import PLATFORM from '@/utils/platform'
import { useToast } from 'wot-design-uni'
import * as wopan from 'diamond/wopan'
defineOptions({
name: 'WopanLogin',
})
// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()
const { success: showSuccess } = useToast()
const model = reactive<{
phone: string
password: string
}>({
phone: '',
password: '',
})
onLoad(() => {
console.log('a')
})
const form = ref()
function handleSubmit() {
form.value
.validate()
.then(({ valid, errors }) => {
if (valid) {
const res = wopan.PcWebLogin(model.phone, model.password)
showSuccess({
msg: '校验通过',
})
}
})
.catch((error) => {
console.log(error, 'error')
})
}
</script>
<style>
.footer {
padding: 12px;
}
</style>
23 changes: 23 additions & 0 deletions client/uniapp/src/service/wopan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { client } from 'diamond/wopan'
client.fetch = async function (url, method, headers, body) {
return new Promise((resolve, reject) => {
uni.request({
url,
method,
header: headers,
data: body,
success: function (res) {
resolve(res)
},
fail: function (err) {
reject(err)
},
})
})
}
client.setToken(uni.getStorageSync('accessToken'), uni.getStorageSync('accessToken'))
client.psToken = uni.getStorageSync('psToken')

const wopanClient = client

export default wopanClient
3 changes: 3 additions & 0 deletions client/uniapp/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createPersistedState } from 'pinia-plugin-persistedstate' // 数据持
import { useUserStore } from '@/store/user'
import { useGlobalStore } from '@/store/global'
import { useContentStore } from '@/store/content'
import { useWopanStore } from '@/store/wopan'

const store = createPinia()
store.use(
Expand All @@ -17,11 +18,13 @@ store.use(
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()
}
Expand Down
58 changes: 58 additions & 0 deletions client/uniapp/src/store/wopan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import wopanClient from '@/service/wopan'
import * as wopan from 'diamond/wopan'
import { defineStore } from 'pinia'
interface File {
fid: string
name: string
id: string
type: number
subFiles: Files
}

interface Files {
parent: File
files: File[]
pageNo: number
pageSize: number
}

export interface WopanState {
files: Files
accessToken: string
refreshToken: string
psToken: string
phone: string
}

export const state: WopanState = {
files: null,
}

const getters = {}

const actions = {
async PcWebLogin(params) {
try {
const res = await wopan.PcWebLogin(params.phone, params.password)
} catch (error: any) {
console.log(error)
}
},
async PcLoginVerifyCode(params) {
try {
const res = await wopan.PcLoginVerifyCode(params.phone, params.password, params.messageCode)
uni.setStorageSync('accessToken', res.access_token)
uni.setStorageSync('refreshToken', res.refresh_token)
await uni.navigateTo({ url: '/wopan/list' })
} catch (error: any) {
console.log(error)
}
},
}

export const useWopanStore = defineStore({
id: 'wopan',
state: () => state,
getters,
actions,
})
2 changes: 0 additions & 2 deletions client/uniapp/src/types/auto-import.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@ declare global {
const useAttrs: typeof import('vue')['useAttrs']
const useCssModule: typeof import('vue')['useCssModule']
const useCssVars: typeof import('vue')['useCssVars']
const useNavbarWeixin: (typeof import('../hooks/useNavbarWeixin'))['default']
const useRequest: typeof import('../hooks/useRequest')['default']
const useSlots: typeof import('vue')['useSlots']
const useUpload: typeof import('../hooks/useUpload')['default']
const useUpload2: typeof import('../hooks/useUpload2')['default']
const watch: typeof import('vue')['watch']
const watchEffect: typeof import('vue')['watchEffect']
const watchPostEffect: typeof import('vue')['watchPostEffect']
Expand Down
6 changes: 5 additions & 1 deletion client/uniapp/src/types/uni-pages.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ interface NavigateToOptions {
"/pages/about/about" |
"/pages/about/i18n" |
"/pages/moment/moment_detail" |
"/pages/moment/moment_list";
"/pages/moment/moment_list" |
"/pages/user/active" |
"/pages/user/login" |
"/pages/wopan/list" |
"/pages/wopan/login";
}
interface RedirectToOptions extends NavigateToOptions {}

Expand Down
15 changes: 0 additions & 15 deletions client/uniapp/src/utils/h5.ts

This file was deleted.

10 changes: 9 additions & 1 deletion client/uniapp/src/utils/http.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { CustomRequestOptions } from '@/interceptors/http'

import { toUrlParams } from 'diamond/compatible'
export const http = <T>(options: CustomRequestOptions) => {
if (options.query) {
const queryStr = toUrlParams(options.query)
if (options.url.includes('?')) {
options.url += `&${queryStr}`
} else {
options.url += `?${queryStr}`
}
}
// 1. 返回 Promise 对象
return new Promise<ResData<T>>((resolve, reject) => {
uni.request({
Expand Down
Loading

0 comments on commit 366d7a0

Please sign in to comment.