jmash-core-mp 0.1.21 → 0.1.22

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 (150) hide show
  1. package/.editorconfig +9 -9
  2. package/README.md +60 -60
  3. package/babel.config.json +34 -34
  4. package/eslint.config.mjs +7 -7
  5. package/lib/api/auth/index.d.ts +21 -21
  6. package/lib/api/auth/index.js +199 -199
  7. package/lib/api/auth/types.d.ts +86 -86
  8. package/lib/api/auth/types.js +9 -9
  9. package/lib/api/cms/index.d.ts +20 -20
  10. package/lib/api/cms/index.js +161 -161
  11. package/lib/api/cms/types.d.ts +200 -200
  12. package/lib/api/cms/types.js +1 -1
  13. package/lib/api/constant.d.ts +5 -5
  14. package/lib/api/constant.js +6 -6
  15. package/lib/api/dict/index.d.ts +18 -18
  16. package/lib/api/dict/index.js +34 -34
  17. package/lib/api/dict/types.d.ts +28 -28
  18. package/lib/api/dict/types.js +1 -1
  19. package/lib/api/dicts.d.ts +18 -18
  20. package/lib/api/dicts.js +67 -67
  21. package/lib/api/files/index.d.ts +25 -25
  22. package/lib/api/files/index.js +135 -135
  23. package/lib/api/files/types.d.ts +38 -38
  24. package/lib/api/files/types.js +1 -1
  25. package/lib/api/index.d.ts +4 -4
  26. package/lib/api/index.js +6 -6
  27. package/lib/api/myorgan/types.d.ts +22 -22
  28. package/lib/api/myorgan/types.js +1 -1
  29. package/lib/api/region/index.d.ts +7 -7
  30. package/lib/api/region/index.js +19 -19
  31. package/lib/api/region/types.d.ts +19 -19
  32. package/lib/api/region/types.js +1 -1
  33. package/lib/api/storage/index.d.ts +10 -10
  34. package/lib/api/storage/index.js +43 -43
  35. package/lib/api/storage/types.d.ts +28 -28
  36. package/lib/api/storage/types.js +1 -1
  37. package/lib/api/types.d.ts +42 -42
  38. package/lib/api/types.js +1 -1
  39. package/lib/app.mpx.d.ts +1 -1
  40. package/lib/components/auth-user/jmash-update-user.mpx.d.ts +1 -1
  41. package/lib/components/auth-user/jmash-user.mpx.d.ts +1 -1
  42. package/lib/components/cms/jmash-cms-acticle-list.mpx.d.ts +1 -1
  43. package/lib/components/cms/jmash-cms-article-item.mpx.d.ts +1 -1
  44. package/lib/components/cms/jmash-cms-article-view.mpx.d.ts +1 -0
  45. package/lib/components/cms/jmash-cms-article.mpx.d.ts +1 -1
  46. package/lib/components/cms/jmash-cms-like.mpx.d.ts +1 -1
  47. package/lib/components/common/jmash-upload-picture.mpx.d.ts +1 -0
  48. package/lib/components/core/jmash-login.mpx.d.ts +1 -0
  49. package/lib/index.d.ts +21 -21
  50. package/lib/index.js +14 -14
  51. package/lib/packages/pages/cms/cms-article-list.mpx.d.ts +1 -1
  52. package/lib/pages/index.mpx.d.ts +1 -0
  53. package/lib/store/user.d.ts +31 -31
  54. package/lib/store/user.js +227 -227
  55. package/lib/utils/common.d.ts +35 -35
  56. package/lib/utils/common.js +166 -166
  57. package/lib/utils/config.d.ts +5 -5
  58. package/lib/utils/config.js +29 -29
  59. package/lib/utils/db.d.ts +21 -21
  60. package/lib/utils/db.js +84 -84
  61. package/lib/utils/grpc.d.ts +5 -5
  62. package/lib/utils/grpc.js +20 -20
  63. package/lib/utils/net.d.ts +7 -7
  64. package/lib/utils/net.js +15 -15
  65. package/lib/utils/request.d.ts +2 -2
  66. package/lib/utils/request.js +123 -123
  67. package/mpx.config.js +27 -27
  68. package/package.json +1 -1
  69. package/postcss.config.js +11 -11
  70. package/project.config.json +24 -24
  71. package/project.private.config.json +13 -13
  72. package/public/index.html +15 -15
  73. package/src/api/auth/index.ts +227 -227
  74. package/src/api/auth/types.ts +166 -166
  75. package/src/api/cms/index.ts +218 -218
  76. package/src/api/cms/types.ts +379 -379
  77. package/src/api/constant.ts +6 -6
  78. package/src/api/dict/index.ts +44 -44
  79. package/src/api/dict/types.ts +49 -49
  80. package/src/api/dicts.ts +72 -72
  81. package/src/api/files/index.ts +163 -163
  82. package/src/api/files/types.ts +67 -67
  83. package/src/api/index.ts +11 -11
  84. package/src/api/myorgan/types.ts +42 -42
  85. package/src/api/region/index.ts +23 -23
  86. package/src/api/region/types.ts +36 -36
  87. package/src/api/storage/index.ts +62 -62
  88. package/src/api/storage/types.ts +54 -54
  89. package/src/api/types.ts +72 -72
  90. package/src/app.mpx +71 -71
  91. package/src/components/auth-user/jmash-logout.mpx +91 -91
  92. package/src/components/auth-user/jmash-update-user.mpx +386 -386
  93. package/src/components/auth-user/jmash-update-user.web.mpx +366 -366
  94. package/src/components/auth-user/jmash-user.mpx +359 -359
  95. package/src/components/cms/jmash-cms-acticle-list.mpx +182 -182
  96. package/src/components/cms/jmash-cms-article-item.mpx +241 -241
  97. package/src/components/cms/jmash-cms-article-view.mpx +131 -131
  98. package/src/components/cms/jmash-cms-article.mpx +68 -68
  99. package/src/components/cms/jmash-cms-like.mpx +151 -151
  100. package/src/components/common/jmash-avatar-edit.mpx +153 -153
  101. package/src/components/common/jmash-cascader-region.mpx +112 -112
  102. package/src/components/common/jmash-menu.mpx +129 -129
  103. package/src/components/common/jmash-none-data.mpx +82 -82
  104. package/src/components/common/jmash-pic-swiper.mpx +71 -71
  105. package/src/components/common/jmash-popup.mpx +137 -137
  106. package/src/components/common/jmash-search.mpx +126 -126
  107. package/src/components/common/jmash-single-btn.mpx +53 -53
  108. package/src/components/common/jmash-stepper.mpx +214 -214
  109. package/src/components/common/jmash-tab-bar.mpx +50 -50
  110. package/src/components/common/jmash-textarea.mpx +88 -88
  111. package/src/components/common/jmash-top-navigation.mpx +203 -203
  112. package/src/components/common/jmash-upload-picture.mpx +129 -126
  113. package/src/components/core/jmash-cms-protocol.mpx +66 -66
  114. package/src/components/core/jmash-login.ali.mpx +284 -284
  115. package/src/components/core/jmash-login.mpx +348 -348
  116. package/src/components/core/jmash-login.web.mpx +421 -421
  117. package/src/components/core/jmash-popup-login.ali.mpx +311 -311
  118. package/src/components/core/jmash-popup-login.mpx +415 -415
  119. package/src/components/core/jmash-popup-login.web.mpx +389 -389
  120. package/src/custom-tab-bar/index.mpx +10 -10
  121. package/src/global.d.ts +11 -11
  122. package/src/index.ts +71 -71
  123. package/src/packages/index.mpx +10 -10
  124. package/src/packages/pages/auth/cms-protocol.mpx +31 -31
  125. package/src/packages/pages/auth/login.mpx +59 -59
  126. package/src/packages/pages/auth/update-user.mpx +17 -17
  127. package/src/packages/pages/cms/cms-article-list.mpx +164 -164
  128. package/src/packages/pages/cms/cms-article.mpx +32 -32
  129. package/src/pages/basic-component.mpx +30 -30
  130. package/src/pages/half-home.mpx +58 -58
  131. package/src/pages/home.mpx +52 -52
  132. package/src/pages/home2.mpx +47 -47
  133. package/src/pages/index.mpx +13 -3
  134. package/src/pages/tabbar/home.mpx +77 -77
  135. package/src/pages/tabbar/my.mpx +80 -80
  136. package/src/store/user.ts +270 -270
  137. package/src/styles/index.scss +20 -20
  138. package/src/styles/vars.scss +27 -27
  139. package/src/utils/common.ts +179 -179
  140. package/src/utils/config.ts +35 -35
  141. package/src/utils/db.ts +100 -100
  142. package/src/utils/grpc.ts +21 -21
  143. package/src/utils/net.ts +18 -18
  144. package/src/utils/request.ts +134 -134
  145. package/static/ali/mini.project.json +4 -4
  146. package/static/dd/project.config.json +15 -15
  147. package/static/swan/project.swan.json +14 -14
  148. package/static/tt/project.config.json +11 -11
  149. package/static/wx/project.config.json +40 -40
  150. package/uno.config.js +9 -9
@@ -1,152 +1,152 @@
1
- /**
2
- * 底部时间、点赞数、预览数组件
3
- * @param organTenant 租户 String
4
- * @param interactId 互动ID String
5
- * @param publishDate 发布时间 String
6
- */
7
- <template>
8
- <view class="cms-bottom">
9
- <!-- 时间 -->
10
- <view>{{ showDate }}</view>
11
-
12
- <view class="cms-bottom-right">
13
- <!-- 浏览 -->
14
- <view class="cms-bottom-look">
15
- <image class="bottom-look-image-left" src="{{ resourceUrl + '/icon_image/eye_open.png' }}"
16
- mode="widthFix" />
17
- <view>{{ browseCount }}</view>
18
- </view>
19
- <!-- 点赞 -->
20
- <view class="cms-bottom-look" catch:tap="handleLike" data-infoid="{{ interactId }}">
21
- <image class="bottom-look-image-right"
22
- src="{{ !isLikeStatus ? resourceUrl+'/icon_image/thumbs_up.png' : resourceUrl+'/icon_image/like_fill2x.png' }}"
23
- mode="widthFix" />
24
- <view>{{ likeCount }}</view>
25
- </view>
26
- </view>
27
- </view>
28
- </template>
29
-
30
- <script lang="ts">
31
- import { createComponent, ref, toRefs, watch, computed } from '@mpxjs/core'
32
- import { cmsApi } from '../../api/cms/index'
33
- import { FrontLikeCreateReq } from '../../api/cms/types'
34
- import { EventBase } from '../../api/types'
35
-
36
- createComponent({
37
- properties: {
38
- // 租户
39
- organTenant: {
40
- type: String,
41
- value: ""
42
- },
43
- // 互动ID
44
- interactId: {
45
- type: String,
46
- value: ""
47
- },
48
- // 发布时间
49
- publishDate: {
50
- type: String,
51
- value: ""
52
- }
53
- },
54
- setup(props) {
55
- let config = getApp().globalData.config;
56
- let browseCount = ref(0);
57
- let likeCount = ref(0);
58
- let isLikeStatus = ref(false);
59
- let resourceUrl = config.resourceUrl + "/images";
60
- // 点赞和收藏数量
61
- let queryInteractData = function (tenant: string, interactId: string) {
62
- cmsApi.cmsInfoInteractId({ interactId: interactId, tenant: tenant }).then((response) => {
63
- likeCount.value = response.data.likeCount;
64
- browseCount.value = response.data.browseCount;
65
- });
66
- }
67
- // 是否已点赞
68
- let queryIsLike = function (tenant: string, interactId: string) {
69
- cmsApi.isLike({ relationId: interactId, tenant: tenant }).then((response) => {
70
- isLikeStatus.value = response.data === 'true';
71
- });
72
- }
73
- //监听
74
- const { interactId } = toRefs(props)
75
- watch(interactId, (newVal) => {
76
- queryInteractData(props.organTenant, newVal);
77
- queryIsLike(props.organTenant, newVal);
78
- })
79
- queryInteractData(props.organTenant, props.interactId);
80
- queryIsLike(props.organTenant, props.interactId);
81
-
82
- const showDate = computed(() => props.publishDate.substring(0, 10))
83
-
84
- return { showDate, resourceUrl, isLikeStatus, likeCount, browseCount, queryInteractData, queryIsLike };
85
- },
86
- methods: {
87
- // 点赞/取消点赞
88
- handleLike(e: EventBase) {
89
- let config = getApp().globalData.config;
90
- const tempData = {
91
- // 用于检测重复请求的唯一字符串ID
92
- requestId: Math.random() * 10 + "",
93
- // 点赞类型
94
- likeType: "info",
95
- // 关系
96
- relationId: e.currentTarget?.dataset.infoid,
97
- // 点赞true/取消点赞false
98
- action: !this.isLikeStatus,
99
- // 租户
100
- tenant: this.organTenant || config.tenant
101
- } as FrontLikeCreateReq;
102
- // 点赞/取消点赞
103
- cmsApi.frontLike(tempData).then((response) => {
104
- if (response.data.likeId) {
105
- // 获取互动数据
106
- this.queryInteractData(this.organTenant, e.currentTarget?.dataset.infoid);
107
- // 是否已点赞
108
- this.queryIsLike(this.organTenant, e.currentTarget?.dataset.infoid);
109
- }
110
- });
111
- },
112
- }
113
- })
114
- </script>
115
-
116
- <style lang="scss">
117
- // 时间预览点赞
118
- .cms-bottom {
119
- display: flex;
120
- align-items: center;
121
- justify-content: space-between;
122
- color: #999;
123
- font-size: 12px;
124
-
125
- // 预览/点赞
126
- .cms-bottom-right {
127
- display: flex;
128
- align-items: center;
129
- justify-content: space-between;
130
- gap: 55rpx;
131
-
132
- .cms-bottom-look {
133
- display: flex;
134
- align-items: center;
135
-
136
- .bottom-look-image-left,
137
- .bottom-look-image-right {
138
- width: 32rpx;
139
- height: 32rpx;
140
- margin-right: 10rpx;
141
- }
142
- }
143
- }
144
- }
145
- </style>
146
-
147
- <script type="application/json">
148
- {
149
- "component": true,
150
- "usingComponents": {}
151
- }
1
+ /**
2
+ * 底部时间、点赞数、预览数组件
3
+ * @param organTenant 租户 String
4
+ * @param interactId 互动ID String
5
+ * @param publishDate 发布时间 String
6
+ */
7
+ <template>
8
+ <view class="cms-bottom">
9
+ <!-- 时间 -->
10
+ <view>{{ showDate }}</view>
11
+
12
+ <view class="cms-bottom-right">
13
+ <!-- 浏览 -->
14
+ <view class="cms-bottom-look">
15
+ <image class="bottom-look-image-left" src="{{ resourceUrl + '/icon_image/eye_open.png' }}"
16
+ mode="widthFix" />
17
+ <view>{{ browseCount }}</view>
18
+ </view>
19
+ <!-- 点赞 -->
20
+ <view class="cms-bottom-look" catch:tap="handleLike" data-infoid="{{ interactId }}">
21
+ <image class="bottom-look-image-right"
22
+ src="{{ !isLikeStatus ? resourceUrl+'/icon_image/thumbs_up.png' : resourceUrl+'/icon_image/like_fill2x.png' }}"
23
+ mode="widthFix" />
24
+ <view>{{ likeCount }}</view>
25
+ </view>
26
+ </view>
27
+ </view>
28
+ </template>
29
+
30
+ <script lang="ts">
31
+ import { createComponent, ref, toRefs, watch, computed } from '@mpxjs/core'
32
+ import { cmsApi } from '../../api/cms/index'
33
+ import { FrontLikeCreateReq } from '../../api/cms/types'
34
+ import { EventBase } from '../../api/types'
35
+
36
+ createComponent({
37
+ properties: {
38
+ // 租户
39
+ organTenant: {
40
+ type: String,
41
+ value: ""
42
+ },
43
+ // 互动ID
44
+ interactId: {
45
+ type: String,
46
+ value: ""
47
+ },
48
+ // 发布时间
49
+ publishDate: {
50
+ type: String,
51
+ value: ""
52
+ }
53
+ },
54
+ setup(props) {
55
+ let config = getApp().globalData.config;
56
+ let browseCount = ref(0);
57
+ let likeCount = ref(0);
58
+ let isLikeStatus = ref(false);
59
+ let resourceUrl = config.resourceUrl + "/images";
60
+ // 点赞和收藏数量
61
+ let queryInteractData = function (tenant: string, interactId: string) {
62
+ cmsApi.cmsInfoInteractId({ interactId: interactId, tenant: tenant }).then((response) => {
63
+ likeCount.value = response.data.likeCount;
64
+ browseCount.value = response.data.browseCount;
65
+ });
66
+ }
67
+ // 是否已点赞
68
+ let queryIsLike = function (tenant: string, interactId: string) {
69
+ cmsApi.isLike({ relationId: interactId, tenant: tenant }).then((response) => {
70
+ isLikeStatus.value = response.data === 'true';
71
+ });
72
+ }
73
+ //监听
74
+ const { interactId } = toRefs(props)
75
+ watch(interactId, (newVal) => {
76
+ queryInteractData(props.organTenant, newVal);
77
+ queryIsLike(props.organTenant, newVal);
78
+ })
79
+ queryInteractData(props.organTenant, props.interactId);
80
+ queryIsLike(props.organTenant, props.interactId);
81
+
82
+ const showDate = computed(() => props.publishDate.substring(0, 10))
83
+
84
+ return { showDate, resourceUrl, isLikeStatus, likeCount, browseCount, queryInteractData, queryIsLike };
85
+ },
86
+ methods: {
87
+ // 点赞/取消点赞
88
+ handleLike(e: EventBase) {
89
+ let config = getApp().globalData.config;
90
+ const tempData = {
91
+ // 用于检测重复请求的唯一字符串ID
92
+ requestId: Math.random() * 10 + "",
93
+ // 点赞类型
94
+ likeType: "info",
95
+ // 关系
96
+ relationId: e.currentTarget?.dataset.infoid,
97
+ // 点赞true/取消点赞false
98
+ action: !this.isLikeStatus,
99
+ // 租户
100
+ tenant: this.organTenant || config.tenant
101
+ } as FrontLikeCreateReq;
102
+ // 点赞/取消点赞
103
+ cmsApi.frontLike(tempData).then((response) => {
104
+ if (response.data.likeId) {
105
+ // 获取互动数据
106
+ this.queryInteractData(this.organTenant, e.currentTarget?.dataset.infoid);
107
+ // 是否已点赞
108
+ this.queryIsLike(this.organTenant, e.currentTarget?.dataset.infoid);
109
+ }
110
+ });
111
+ },
112
+ }
113
+ })
114
+ </script>
115
+
116
+ <style lang="scss">
117
+ // 时间预览点赞
118
+ .cms-bottom {
119
+ display: flex;
120
+ align-items: center;
121
+ justify-content: space-between;
122
+ color: #999;
123
+ font-size: 12px;
124
+
125
+ // 预览/点赞
126
+ .cms-bottom-right {
127
+ display: flex;
128
+ align-items: center;
129
+ justify-content: space-between;
130
+ gap: 55rpx;
131
+
132
+ .cms-bottom-look {
133
+ display: flex;
134
+ align-items: center;
135
+
136
+ .bottom-look-image-left,
137
+ .bottom-look-image-right {
138
+ width: 32rpx;
139
+ height: 32rpx;
140
+ margin-right: 10rpx;
141
+ }
142
+ }
143
+ }
144
+ }
145
+ </style>
146
+
147
+ <script type="application/json">
148
+ {
149
+ "component": true,
150
+ "usingComponents": {}
151
+ }
152
152
  </script>
@@ -1,154 +1,154 @@
1
- <template>
2
- <!-- 头像背景盒子 -->
3
- <button plain class="auth-image-box-bgc" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
4
- <!-- 显示的头像 -->
5
- <image class="image-box-show" src="{{ avatar }}" mode="aspectFit" />
6
- <!-- 提示选择头像图片 -->
7
- <image class="select-image" src="{{ resourceUrl + 'camera2x.png' }}" mode="aspectFit" />
8
- </button>
9
- </template>
10
-
11
- <script lang="ts">
12
- import mpx, { createComponent, ref } from "@mpxjs/core";
13
- import { fileApi } from "../../api/files/index";
14
- import { EventBase } from "../../api/types";
15
-
16
- createComponent({
17
- properties: {
18
- // 头像路径 form绑定的这个属性
19
- value: {
20
- type: String,
21
- value: "",
22
- observer() {
23
- this.avatar = this.value ? fileApi.imageUrl(this.value, 320, 320, "trans") : this.avatar;
24
- }
25
- },
26
- // logo图片路径-全路径 编辑回显使用
27
- logoImg: {
28
- type: String,
29
- value: "",
30
- observer() {
31
- this.avatar = this.logoImg || this.avatar;
32
- }
33
- },
34
- // 是否显示默认logo
35
- logo: {
36
- type: Boolean,
37
- value: false,
38
- observer() {
39
- this.avatar = this.logo ? this.defaultlogo : this.avatar;
40
- }
41
- },
42
- // 路径的类型,全路径状态为true,相对路径状态为false
43
- pathType: {
44
- type: Boolean,
45
- value: false
46
- }
47
- },
48
- setup() {
49
- let config = getApp().globalData.config;
50
- let resourceUrl = config.resourceUrl + "/images/icon_image/";
51
- // 默认头像图片
52
- let avatar = ref(resourceUrl + "/images/components/gray_head2x.png");
53
- // 默认logo图片
54
- let defaultlogo = ref(resourceUrl + "/images/components/gray_logo.png");
55
-
56
- return {
57
- resourceUrl,
58
- avatar,
59
- defaultlogo,
60
- }
61
- },
62
- lifetimes: {
63
- attached() {
64
- if (this.value !== "") {
65
- this.avatar = this.pathType ? this.value : fileApi.imageUrl(this.value, 320, 320, "trans");
66
- }
67
- }
68
- },
69
- methods: {
70
- // 选择头像
71
- onChooseAvatar(e: EventBase) {
72
- const { avatarUrl } = e.detail;
73
- if (!avatarUrl) {
74
- mpx.showToast({ title: "请选择图片", icon: "none" });
75
- return;
76
- }
77
-
78
- mpx.showLoading({ title: "上传中..." });
79
-
80
- fileApi.uploadFile(avatarUrl).then(res => {
81
- console.log("上传结果:", res);
82
- const { fileSrc } = res || {};
83
- // 检查返回数据
84
- if (!fileSrc) {
85
- mpx.showToast({ title: "上传结果异常", icon: "none" });
86
- return;
87
- }
88
-
89
- // 生成图片URL
90
- const imageUrl = fileApi.imageUrl(fileSrc, 320, 320, "trans");
91
- console.log("生成的图片URL:", imageUrl);
92
-
93
- // 更新头像
94
- this.avatar = imageUrl;
95
- this.triggerEvent("change", res, {});
96
-
97
- mpx.showToast({ title: "上传成功", icon: "success" });
98
- }).catch((err) => {
99
- console.error("上传失败:", err);
100
- mpx.showToast({
101
- title: "图片上传失败",
102
- icon: "none",
103
- duration: 2000
104
- });
105
- }).finally(() => {
106
- mpx.hideLoading();
107
- });
108
- },
109
- }
110
- })
111
- </script>
112
-
113
- <style lang="scss">
114
- @use "../../styles/index.scss" as *;
115
-
116
- // 头像背景盒子
117
- .auth-image-box-bgc {
118
- position: relative;
119
- display: flex;
120
- align-items: center;
121
- justify-content: center;
122
- width: 160rpx !important;
123
- height: 160rpx;
124
- border: none;
125
- border-radius: $border-radius;
126
- padding: 0;
127
-
128
- // 显示的头像
129
- .image-box-show {
130
- width: 160rpx;
131
- height: 160rpx;
132
- }
133
-
134
- // 提示选择头像图片
135
- .select-image {
136
- position: absolute;
137
- width: 48rpx;
138
- height: 48rpx;
139
- bottom: 0;
140
- right: 0;
141
- }
142
- }
143
-
144
- .image-box-bgc[plain] {
145
- border: 2rpx solid #e0e0e0;
146
- }
147
- </style>
148
-
149
- <script type="application/json">
150
- {
151
- "component": true,
152
- "usingComponents": {}
153
- }
1
+ <template>
2
+ <!-- 头像背景盒子 -->
3
+ <button plain class="auth-image-box-bgc" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
4
+ <!-- 显示的头像 -->
5
+ <image class="image-box-show" src="{{ avatar }}" mode="aspectFit" />
6
+ <!-- 提示选择头像图片 -->
7
+ <image class="select-image" src="{{ resourceUrl + 'camera2x.png' }}" mode="aspectFit" />
8
+ </button>
9
+ </template>
10
+
11
+ <script lang="ts">
12
+ import mpx, { createComponent, ref } from "@mpxjs/core";
13
+ import { fileApi } from "../../api/files/index";
14
+ import { EventBase } from "../../api/types";
15
+
16
+ createComponent({
17
+ properties: {
18
+ // 头像路径 form绑定的这个属性
19
+ value: {
20
+ type: String,
21
+ value: "",
22
+ observer() {
23
+ this.avatar = this.value ? fileApi.imageUrl(this.value, 320, 320, "trans") : this.avatar;
24
+ }
25
+ },
26
+ // logo图片路径-全路径 编辑回显使用
27
+ logoImg: {
28
+ type: String,
29
+ value: "",
30
+ observer() {
31
+ this.avatar = this.logoImg || this.avatar;
32
+ }
33
+ },
34
+ // 是否显示默认logo
35
+ logo: {
36
+ type: Boolean,
37
+ value: false,
38
+ observer() {
39
+ this.avatar = this.logo ? this.defaultlogo : this.avatar;
40
+ }
41
+ },
42
+ // 路径的类型,全路径状态为true,相对路径状态为false
43
+ pathType: {
44
+ type: Boolean,
45
+ value: false
46
+ }
47
+ },
48
+ setup() {
49
+ let config = getApp().globalData.config;
50
+ let resourceUrl = config.resourceUrl + "/images/icon_image/";
51
+ // 默认头像图片
52
+ let avatar = ref(resourceUrl + "/images/components/gray_head2x.png");
53
+ // 默认logo图片
54
+ let defaultlogo = ref(resourceUrl + "/images/components/gray_logo.png");
55
+
56
+ return {
57
+ resourceUrl,
58
+ avatar,
59
+ defaultlogo,
60
+ }
61
+ },
62
+ lifetimes: {
63
+ attached() {
64
+ if (this.value !== "") {
65
+ this.avatar = this.pathType ? this.value : fileApi.imageUrl(this.value, 320, 320, "trans");
66
+ }
67
+ }
68
+ },
69
+ methods: {
70
+ // 选择头像
71
+ onChooseAvatar(e: EventBase) {
72
+ const { avatarUrl } = e.detail;
73
+ if (!avatarUrl) {
74
+ mpx.showToast({ title: "请选择图片", icon: "none" });
75
+ return;
76
+ }
77
+
78
+ mpx.showLoading({ title: "上传中..." });
79
+
80
+ fileApi.uploadFile(avatarUrl).then(res => {
81
+ console.log("上传结果:", res);
82
+ const { fileSrc } = res || {};
83
+ // 检查返回数据
84
+ if (!fileSrc) {
85
+ mpx.showToast({ title: "上传结果异常", icon: "none" });
86
+ return;
87
+ }
88
+
89
+ // 生成图片URL
90
+ const imageUrl = fileApi.imageUrl(fileSrc, 320, 320, "trans");
91
+ console.log("生成的图片URL:", imageUrl);
92
+
93
+ // 更新头像
94
+ this.avatar = imageUrl;
95
+ this.triggerEvent("change", res, {});
96
+
97
+ mpx.showToast({ title: "上传成功", icon: "success" });
98
+ }).catch((err) => {
99
+ console.error("上传失败:", err);
100
+ mpx.showToast({
101
+ title: "图片上传失败",
102
+ icon: "none",
103
+ duration: 2000
104
+ });
105
+ }).finally(() => {
106
+ mpx.hideLoading();
107
+ });
108
+ },
109
+ }
110
+ })
111
+ </script>
112
+
113
+ <style lang="scss">
114
+ @use "../../styles/index.scss" as *;
115
+
116
+ // 头像背景盒子
117
+ .auth-image-box-bgc {
118
+ position: relative;
119
+ display: flex;
120
+ align-items: center;
121
+ justify-content: center;
122
+ width: 160rpx !important;
123
+ height: 160rpx;
124
+ border: none;
125
+ border-radius: $border-radius;
126
+ padding: 0;
127
+
128
+ // 显示的头像
129
+ .image-box-show {
130
+ width: 160rpx;
131
+ height: 160rpx;
132
+ }
133
+
134
+ // 提示选择头像图片
135
+ .select-image {
136
+ position: absolute;
137
+ width: 48rpx;
138
+ height: 48rpx;
139
+ bottom: 0;
140
+ right: 0;
141
+ }
142
+ }
143
+
144
+ .image-box-bgc[plain] {
145
+ border: 2rpx solid #e0e0e0;
146
+ }
147
+ </style>
148
+
149
+ <script type="application/json">
150
+ {
151
+ "component": true,
152
+ "usingComponents": {}
153
+ }
154
154
  </script>