@uxda/appkit 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/.eslintrc.mjs +8 -0
  2. package/README.md +147 -0
  3. package/babel.config.js +12 -0
  4. package/dist/appkit.css +3 -0
  5. package/dist/index.js +1755 -0
  6. package/dist/styles.css +1 -0
  7. package/package.json +73 -0
  8. package/project.config.json +15 -0
  9. package/project.tt.json +13 -0
  10. package/rollup.config.js +55 -0
  11. package/src/Appkit.ts +41 -0
  12. package/src/balance/api/endpoints.ts +108 -0
  13. package/src/balance/api/index.ts +25 -0
  14. package/src/balance/components/AccountView.vue +519 -0
  15. package/src/balance/components/BalanceCard.vue +181 -0
  16. package/src/balance/components/BalanceReminder.vue +82 -0
  17. package/src/balance/components/ConsumptionFilter.vue +176 -0
  18. package/src/balance/components/ConsumptionRules.vue +70 -0
  19. package/src/balance/components/DateFilter.vue +219 -0
  20. package/src/balance/components/index.ts +9 -0
  21. package/src/balance/index.ts +1 -0
  22. package/src/balance/types.ts +92 -0
  23. package/src/global.ts +7 -0
  24. package/src/index.ts +51 -0
  25. package/src/main.scss +1 -0
  26. package/src/payment/README.md +0 -0
  27. package/src/payment/api/config.ts +8 -0
  28. package/src/payment/api/endpoints.ts +75 -0
  29. package/src/payment/api/index.ts +25 -0
  30. package/src/payment/components/AmountPicker.vue +109 -0
  31. package/src/payment/components/RechargeView.vue +146 -0
  32. package/src/payment/components/UserAgreement.vue +111 -0
  33. package/src/payment/components/index.ts +16 -0
  34. package/src/payment/consts.ts +1 -0
  35. package/src/payment/index.ts +1 -0
  36. package/src/payment/services/index.ts +17 -0
  37. package/src/payment/services/invoke-recharge.ts +25 -0
  38. package/src/payment/services/request-payment.ts +32 -0
  39. package/src/payment/types.ts +24 -0
  40. package/src/shared/components/AppDrawer.vue +53 -0
  41. package/src/shared/components/PageHeader.vue +75 -0
  42. package/src/shared/components/index.ts +7 -0
  43. package/src/shared/http/Http.ts +124 -0
  44. package/src/shared/http/index.ts +2 -0
  45. package/src/shared/http/types.ts +100 -0
  46. package/src/shared/index.ts +3 -0
  47. package/src/shared/weixin/index.ts +1 -0
  48. package/src/shared/weixin/payment.ts +37 -0
  49. package/src/styles/vars.scss +4 -0
  50. package/tsconfig.json +30 -0
  51. package/types/global.d.ts +22 -0
  52. package/types/vue.d.ts +10 -0
@@ -0,0 +1,75 @@
1
+ <template>
2
+ <view :class="[
3
+ 'page-header',
4
+ `color-mode-${colorMode}`
5
+ ]">
6
+ <h1 class="page-title" v-if="title">{{ title }}</h1>
7
+ <view class="back-button" @click="onBackButtonClick"></view>
8
+ <slot></slot>
9
+ </view>
10
+ </template>
11
+
12
+ <script lang="ts" setup>
13
+
14
+ export type PageHeaderColorMode = 'light' | 'dark'
15
+
16
+ export interface PageHeaderProps {
17
+ title?: string,
18
+ colorMode?: PageHeaderColorMode
19
+ }
20
+
21
+ const emit = defineEmits<{
22
+ (event: 'close'): void
23
+ }>()
24
+
25
+ withDefaults(
26
+ defineProps<PageHeaderProps>(), {
27
+ title: '',
28
+ colorMode: 'light'
29
+ }
30
+ )
31
+
32
+ const onBackButtonClick = () => {
33
+ emit('close')
34
+ }
35
+ </script>
36
+
37
+ <style lang="scss">
38
+ .page-header {
39
+ flex-shrink: 0;
40
+ position: relative;
41
+ height: 172px;
42
+ padding: 1em;
43
+ box-sizing: border-box;
44
+ margin-left: -12px;
45
+ margin-right: -12px;
46
+ width: calc(100% + 24px);
47
+ .page-title {
48
+ position: absolute;
49
+ font-size: 18px;
50
+ width: 100%;
51
+ height: 44px;
52
+ top: 44px;
53
+ left: 0;
54
+ line-height: 44px;
55
+ text-align: center;
56
+ }
57
+ .back-button {
58
+ position: absolute;
59
+ top: 44px;
60
+ left: 10px;
61
+ width: 44px;
62
+ height: 44px;
63
+ background-image: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDIiIGhlaWdodD0iNDIiIHZpZXdCb3g9IjAgMCA0MiA0MiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggb3BhY2l0eT0iMC4wMSIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0wLjk5OTg3OCA0MUw0MC45OTk5IDQxTDQwLjk5OTkgMUwwLjk5OTg3OCAxTDAuOTk5ODc4IDQxWiIgZmlsbD0iI0Q4RDhEOCIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLW9wYWNpdHk9IjAuMDEiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xMi45OTMzIDE4Ljk0NzdDMTEuODYzMyAyMC4wMTQ1IDExLjgxMiAyMS43OTU0IDEyLjg3ODggMjIuOTI1NUwyNy45MTA1IDM3LjEzNDVDMjguNjkyNSAzNy44NzM0IDI5LjkyNTUgMzcuODM4NCAzMC42NjQ0IDM3LjA1NjRDMzEuMzY4MSAzNi4zMTE2IDMxLjM2OTkgMzUuMTU3OSAzMC42OTI5IDM0LjQxMTRMMTYuNTAxMiAyMC45OTM5TDMwLjU4NTcgNy42OTc4NUMzMS4zMzA4IDYuOTk0NDkgMzEuMjk4MiA1LjcyNzk1IDMwLjY2NDkgNC45NDQwMkMyOS45NjE2IDQuMTk4OTUgMjguODA5OCA0LjEzMTI5IDI4LjAyNTkgNC43NjQ1MkwxMi45OTMzIDE4Ljk0NzdaIiBmaWxsPSJibGFjayIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLW9wYWNpdHk9IjAuMDEiLz4KPC9zdmc+Cg==");
64
+ background-size: 22px;
65
+ background-repeat: no-repeat;
66
+ background-position: center center;
67
+ }
68
+ &.color-mode-dark {
69
+ color: var(--text-color-dark-mode, '#fff');
70
+ .back-button {
71
+ background-image: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDIiIGhlaWdodD0iNDIiIH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,0 +1,124 @@
1
+ /**
2
+ *
3
+ */
4
+
5
+
6
+ /**
7
+ * Useage:
8
+ * const $http = useHttp()
9
+ * $http.get('/url').then(data => {
10
+ *
11
+ * })
12
+ */
13
+
14
+ import Taro from '@tarojs/taro'
15
+ import { Http, HttpClientConfig, HttpMethod, HttpRequestConfig, RequestData, ResponseData, ResponseRaw } from './types'
16
+
17
+ /**
18
+ * 场景配置
19
+ * 本地后台团队统一返回值外层
20
+ */
21
+ const defaultClientConfig: HttpClientConfig = {
22
+ baseUrl: 'https://ytech.ddjf.com',
23
+ response: {
24
+ getCode: (data: ResponseRaw) => data.code,
25
+ getMessage: (data: ResponseRaw) => data.msg,
26
+ getData: (data: ResponseRaw) => data.result
27
+ }
28
+ }
29
+
30
+ let clientConfig = {
31
+ ...defaultClientConfig
32
+ }
33
+
34
+ /**
35
+ * 统一请求过程
36
+ * @param config
37
+ * @returns
38
+ */
39
+ const request: Http['request'] = <T>(config: HttpRequestConfig) => {
40
+ return new Promise<T>((resolve, reject) => {
41
+ const data = config.data
42
+ && clientConfig.translates
43
+ && clientConfig.translates[config.url]
44
+ ? clientConfig.translates[config.url](config.data)
45
+ : config.data
46
+ Taro.request<ResponseData>({
47
+ url: `${clientConfig.baseUrl}${config.url}`,
48
+ data,
49
+ header: clientConfig.header,
50
+ method: config.method,
51
+ success (res: Taro.request.SuccessCallbackResult<ResponseRaw>) {
52
+ if (!isSuccess(res)) {
53
+ reject({})
54
+ }
55
+ const { data: raw } = res
56
+ if (clientConfig.interceptors?.auth(raw)) {
57
+ clientConfig.onAuthError?.()
58
+ reject('auth failed')
59
+ }
60
+ if (clientConfig.interceptors?.server(raw)) {
61
+ clientConfig.onServerError?.()
62
+ reject('server error')
63
+ }
64
+ const response = clientConfig.response?.getData(raw)
65
+ if (response) {
66
+ // 当用户配置含有 transforms 时, 使用用户提供的 transform
67
+ resolve(clientConfig.transforms
68
+ && clientConfig.transforms[config.url]
69
+ ? clientConfig.transforms[config.url](response) as T
70
+ : response as T)
71
+ } else {
72
+ reject({})
73
+ }
74
+ },
75
+ fail (res) {
76
+ console.log('HTTP failed', res)
77
+ }
78
+ })
79
+ })
80
+ }
81
+
82
+ const get: Http['get'] = <T>(url: string, data?: RequestData) => {
83
+ return request<T>({
84
+ url,
85
+ data,
86
+ method: HttpMethod.get
87
+ })
88
+ }
89
+
90
+ const post: Http['post'] = <T>(url: string, data: RequestData) => {
91
+ return request<T>({
92
+ url,
93
+ data,
94
+ method: HttpMethod.post
95
+ })
96
+ }
97
+
98
+ /**
99
+ * 写入配置并
100
+ * @param config
101
+ * @returns
102
+ */
103
+ export function useHttp (config: HttpClientConfig): Http {
104
+
105
+ clientConfig = {
106
+ ...defaultClientConfig,
107
+ ...config
108
+ }
109
+
110
+ return {
111
+ request,
112
+ get,
113
+ post
114
+ }
115
+ }
116
+
117
+ const successResonseCodes = [
118
+ '200'
119
+ ]
120
+
121
+ function isSuccess (res: Taro.request.SuccessCallbackResult<ResponseRaw>) {
122
+ return /^2/.test(res.statusCode.toString())
123
+ && successResonseCodes.includes(`${clientConfig.response?.getCode(res.data)}`)
124
+ }
@@ -0,0 +1,2 @@
1
+ export * from './Http'
2
+ export type * from './types'
@@ -0,0 +1,100 @@
1
+
2
+ export type RequestData = Record<string, any>
3
+
4
+ /**
5
+ * 本地后端团队的接口数据格式
6
+ */
7
+ export type ResponseRaw = Record<string, any>
8
+
9
+ export type ResponseData = Record<string, any>
10
+
11
+ export type HttpTranslates = Record<string, (data: RequestData) => RequestData>
12
+ export type HttpTransforms = Record<string, (data: ResponseData) => ResponseData>
13
+
14
+ /**
15
+ * 向 request header 加入参数
16
+ * 多数是 token
17
+ */
18
+ export type HeaderParams = Record<string, string>
19
+
20
+ /**
21
+ * 由使用场景提供的配置
22
+ */
23
+ export type HttpClientConfig = {
24
+ baseUrl: string,
25
+ /**
26
+ * 向 HTTP header 加入的数据
27
+ * 通常含有 JWT token 以及其他参数
28
+ */
29
+ header?: HeaderParams
30
+ /**
31
+ * 定义返回数据的外层格式
32
+ */
33
+ response?: {
34
+ getCode (data: ResponseData): `${number}` | number,
35
+ getMessage (data: RequestData): string,
36
+ getData (data: ResponseData): ResponseData
37
+ },
38
+ onAuthError? (): void
39
+ onServerError? (): void
40
+ /**
41
+ * 错误码配置
42
+ * 依据后端给出的 code 定义错误类型及处理方法
43
+ */
44
+ interceptors?: {
45
+ auth (data: ResponseData): boolean
46
+ server (data: ResponseData): boolean
47
+ },
48
+ translates?: HttpTranslates
49
+ transforms?: HttpTransforms
50
+ }
51
+
52
+ export enum HttpMethod {
53
+ get = 'GET',
54
+ post = 'POST',
55
+ put = 'PUT',
56
+ delete = 'DELETE',
57
+ }
58
+
59
+ export enum HttpError {
60
+ auth = 'auth',
61
+ server = 'server'
62
+ }
63
+
64
+ export type Http = {
65
+ request<T = ResponseData>(config: HttpRequestConfig): Promise<T>
66
+ get<T = ResponseData>(url: string, data?: RequestData): Promise<T>,
67
+ post<T = ResponseData>(url: string, data?: RequestData): Promise<T>,
68
+ }
69
+
70
+ export type HttpRequestConfig = {
71
+ url: string,
72
+ data?: RequestData,
73
+ method?: HttpMethod
74
+ }
75
+
76
+ /**
77
+ * 接口参数转换器
78
+ */
79
+ export type HttpTranslate = (data: RequestData) => RequestData
80
+
81
+ /**
82
+ * 接口数据转换器
83
+ */
84
+ export type HttpTransform = (data: ResponseData) => ResponseData
85
+
86
+ /**
87
+ * 接口设置
88
+ */
89
+ export type HttpEndpoint = {
90
+ path: string,
91
+ translate?: HttpTranslate,
92
+ transform?: HttpTransform,
93
+ }
94
+
95
+ /**
96
+ * 接口组
97
+ */
98
+ export type HttpEndpoints = {
99
+ [name: string]: HttpEndpoint
100
+ }
@@ -0,0 +1,3 @@
1
+ export * from './weixin'
2
+ export * from './components'
3
+ export * from './http'
@@ -0,0 +1 @@
1
+ export * from './payment'
@@ -0,0 +1,37 @@
1
+ export type PaymentOptions = {}
2
+
3
+ /**
4
+ * 发起微信支付
5
+ * @param options
6
+ */
7
+ export function requestPayment(json: any): Promise<boolean> {
8
+ /** 时间戳从1970年1月1日00:00:00至今的秒数,即当前的时间 */
9
+ // const timeStamp: string = '',
10
+ // /** 随机字符串,长度为32个字符以下 */
11
+ // nonceStr: string = '',
12
+ // /** 统一下单接口返回的prepay_id参数值,提交格式如:prepay_id=* */
13
+ // pack: string = '',
14
+ // /** 签名算法,暂支持MD5 */
15
+ // signType: string = 'MD5',
16
+ // /** 签名,具体签名方案参见微信公众号支付帮助文档(https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3&t=1474537654457); */
17
+ // paySign: string = ''
18
+ // /** 接口调用成功的回调函数 */
19
+ // const success = (res: {}) => {},
20
+ // /**接口调用失败的回调函数*/
21
+ // fail = () => {},
22
+ // /**接口调用结束的回调函数(调用成功、失败都会执行)*/
23
+ // complete = () => {}
24
+ return new Promise<boolean>((resolve, reject) => {
25
+ const success = (message: string) => {
26
+ resolve(true)
27
+ }
28
+ const fail = (message: string) => {
29
+ resolve(false)
30
+ }
31
+ wx.requestPayment({
32
+ ...json,
33
+ success,
34
+ fail
35
+ })
36
+ })
37
+ }
@@ -0,0 +1,4 @@
1
+ page {
2
+ --text-color: #333;
3
+ --text-color-dark-mode: #eee;
4
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "removeComments": false,
5
+ "preserveConstEnums": true,
6
+ "moduleResolution": "node",
7
+ "experimentalDecorators": true,
8
+ "noImplicitAny": false,
9
+ "allowSyntheticDefaultImports": true,
10
+ "outDir": "dist",
11
+ "noUnusedLocals": true,
12
+ "noUnusedParameters": true,
13
+ "strictNullChecks": true,
14
+ "sourceMap": true,
15
+ "baseUrl": ".",
16
+ "rootDir": ".",
17
+ "jsx": "preserve",
18
+ "allowJs": true,
19
+ "resolveJsonModule": true,
20
+ "skipLibCheck": true,
21
+ "typeRoots": [
22
+ "node_modules/@types"
23
+ ]
24
+ },
25
+ "include": [
26
+ "./src/",
27
+ "./types",
28
+ ],
29
+ "compileOnSave": false
30
+ }
@@ -0,0 +1,22 @@
1
+ /// <reference types="@tarojs/taro" />
2
+
3
+ declare module '*.png';
4
+ declare module '*.gif';
5
+ declare module '*.jpg';
6
+ declare module '*.jpeg';
7
+ declare module '*.svg';
8
+ declare module '*.css';
9
+ declare module '*.less';
10
+ declare module '*.scss';
11
+ declare module '*.sass';
12
+ declare module '*.styl';
13
+
14
+ declare namespace NodeJS {
15
+ interface ProcessEnv {
16
+ TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt' | 'quickapp' | 'qq' | 'jd'
17
+ }
18
+ }
19
+
20
+ declare module '@tarojs/components' {
21
+ export * from '@tarojs/components/types/index.vue3'
22
+ }
package/types/vue.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export {}
2
+
3
+ declare module 'vue' {
4
+ export interface GlobalComponents extends JSX.IntrinsicElements {
5
+ /** Note: Vue 在 runtime 中将 JSX.IntrinsicElements 通过 index signature 重复声明标签
6
+ * 这会导致插件无法正常跳转类型,可以手动覆盖声明标签活得更好的体验,参考如下:
7
+ * 'scroll-view': JSX.IntrinsicElements['scroll-view']
8
+ */
9
+ }
10
+ }