Browse Source

个人中心联调

master
kola-web 3 months ago
parent
commit
33db86b661
  1. 7
      project.private.config.json
  2. 3
      src/app.json
  3. 30
      src/components/global-toast/index.wxml
  4. 112
      src/components/uploadFile/index.ts
  5. 10
      src/components/uploadFile/index.wxml
  6. BIN
      src/images/copnay-code.png
  7. BIN
      src/images/icon-edit.png
  8. BIN
      src/images/icon-pic.png
  9. BIN
      src/images/my-list-icon3.png
  10. 4
      src/pages/my/index.scss
  11. 26
      src/pages/my/index.ts
  12. 14
      src/pages/my/index.wxml
  13. 7
      src/pages/userInfo/index.json
  14. 56
      src/pages/userInfo/index.scss
  15. 48
      src/pages/userInfo/index.ts
  16. 43
      src/pages/userInfo/index.wxml

7
project.private.config.json

@ -9,6 +9,13 @@ @@ -9,6 +9,13 @@
"miniprogram": {
"list": [
{
"name": "个人信息",
"pathName": "pages/userInfo/index",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "隐私协议",
"pathName": "pages/protocol/index",
"query": "",

3
src/app.json

@ -10,7 +10,8 @@ @@ -10,7 +10,8 @@
"pages/classify/index",
"pages/article/index",
"pages/search/index",
"pages/protocol/index"
"pages/protocol/index",
"pages/userInfo/index"
],
"preloadRule": {},
"window": {

30
src/components/global-toast/index.wxml

@ -1,7 +1,33 @@ @@ -1,7 +1,33 @@
<van-popup show="{{ show }}" wx:if="{{type===1}}" custom-style="background: transparent;" bind:close="handleClose">
<van-popup
show="{{ show }}"
wx:if="{{type===1}}"
custom-style="background: transparent;"
bind:close="handleClose"
>
<view class="popup1" style="background: url('/images/popup1-bg.png') no-repeat top center/100%">
<view class="title">关注适中健康微信公众号</view>
<image class="code" :src="{{params.mpPicture}}" show-menu-by-longpress></image>
<image
class="code"
:src="{{params.mpPicture}}"
show-menu-by-longpress
></image>
<view class="tip">长按识别二维码关注</view>
</view>
</van-popup>
<van-popup
show="{{ show }}"
wx:if="{{type===2}}"
custom-style="background: transparent;"
bind:close="handleClose"
>
<view class="popup1" style="background: url('/images/popup1-bg.png') no-repeat top center/100%">
<view class="title">添加我的企业微信</view>
<image
class="code"
:src="{{params.qwPicture}}"
show-menu-by-longpress
></image>
<view class="tip">长按识别二维码关注</view>
</view>
</van-popup>

112
src/components/uploadFile/index.ts

@ -16,15 +16,7 @@ Component({ @@ -16,15 +16,7 @@ Component({
},
accept: {
type: String,
value: "image",
},
obscure: {
type: Boolean,
value: false,
},
edit: {
type: Boolean,
value: false,
value: 'image',
},
},
@ -32,15 +24,6 @@ Component({ @@ -32,15 +24,6 @@ Component({
*
*/
data: {
show1: false,
fileTypeList: {
doc: 5,
docx: 5,
pdf: 4,
xls: 6,
xlsx: 6,
ppt: 7,
},
cacheEditParams: {},
},
@ -50,63 +33,29 @@ Component({ @@ -50,63 +33,29 @@ Component({
methods: {
GetExtensionFileName(pathfilename) {
const reg = /(\\+)/g;
const pString = pathfilename.replace(reg, "#"); //用正则表达式来将\或\\替换成#
const arr = pString.split("#"); // 以“#”为分隔符,将字符分解为数组 例如 D Program Files bg.png
const pString = pathfilename.replace(reg, '#'); //用正则表达式来将\或\\替换成#
const arr = pString.split('#'); // 以“#”为分隔符,将字符分解为数组 例如 D Program Files bg.png
const lastString = arr[arr.length - 1]; //取最后一个字符
const arr2 = lastString.split("."); // 再以"."作为分隔符
const arr2 = lastString.split('.'); // 再以"."作为分隔符
return arr2[arr2.length - 1]; //将后缀名返回出来
},
handleAfterRead(e, editEnd = false) {
if (this.data.edit && !editEnd) {
this.setData({
show1: true,
cacheEditParams: e,
});
return;
}
if (this.data.obscure) {
wx.editImage({
src: e.detail.file.url || e.detail.file.tempFilePath,
success: (res: any) => {
this.uploadFile({
...e.detail.file,
tempFilePath: res.tempFilePath,
}).then((res) => {
this.triggerEvent("file", res as object);
});
},
fail: (err) => {
if (err.errMsg.includes("开发者工具")) {
this.uploadFile(e.detail.file).then((res) => {
this.triggerEvent("file", res as object);
});
}
},
});
} else {
this.uploadFile(e.detail.file).then((res) => {
this.triggerEvent("file", res as object);
});
}
},
handleEditEnd() {
this.setData({
show1: false,
handleAfterRead(e) {
this.uploadFile(e.detail.file).then((res) => {
this.triggerEvent('file', res as object);
});
this.handleAfterRead(this.data.cacheEditParams, true);
},
handleChooseAvatar(e) {
this.uploadFile({
fileType: "image",
fileType: 'image',
tempFilePath: e.detail.avatarUrl,
size: 0,
}).then((res) => {
this.triggerEvent("file", res as object);
this.triggerEvent('file', res as object);
});
},
handleChooseFile() {
wx.chooseMessageFile({
type: "file",
type: 'file',
count: 1,
success: (res) => {
this.uploadFile({
@ -114,66 +63,65 @@ Component({ @@ -114,66 +63,65 @@ Component({
fileType: res.tempFiles[0].type,
tempFilePath: res.tempFiles[0].path,
}).then((res) => {
this.triggerEvent("file", res as object);
this.triggerEvent('file', res as object);
});
},
fail() {
wx.showToast({
icon: "none",
title: "取消选择",
icon: 'none',
title: '取消选择',
});
},
});
},
uploadFile(item) {
wx.showLoading({
title: "正在上传",
title: '正在上传',
});
return new Promise((resolve, reject) => {
let url = `${app.globalData.upFileUrl}?r=file-service/upload-`;
if (item.fileType === "image") {
url += "img";
} else if (item.fileType === "video" || item.type === "video") {
url += "video";
if (item.fileType === 'image') {
url += 'img';
} else if (item.fileType === 'video' || item.type === 'video') {
url += 'video';
item.tempFilePath = item.url;
} else if (item.fileType === "audio") {
url += "audio";
} else if (item.fileType === 'audio') {
url += 'audio';
} else {
url += "doc";
url += 'doc';
}
wx.uploadFile({
filePath: item.tempFilePath,
name: "file",
name: 'file',
url,
success: (res) => {
wx.hideLoading();
const data = JSON.parse(res.data);
const suffix = this.GetExtensionFileName(data.data.Url);
const expandJson = {
fileId: "",
fileId: '',
name: item.name || `病历相关文件.${suffix}`,
size: (item.size / 1024).toFixed(2),
fileUrl: data.data.Url,
suffix,
type: item.fileType,
imgUrl: "",
imgUrl: '',
duration: 0,
fileType: this.data.fileTypeList[suffix] || 99,
videoUrl: "",
hash: "",
videoUrl: '',
hash: '',
};
if (item.fileType === "image") {
if (item.fileType === 'image') {
expandJson.imgUrl = data.data.Url;
} else if (item.fileType === "video" || item.type === "video") {
} else if (item.fileType === 'video' || item.type === 'video') {
expandJson.imgUrl = data.data.SnapshotUrl;
} else if (item.fileType === "audio") {
} else if (item.fileType === 'audio') {
expandJson.duration = Number.parseInt(String(item.duration / 1000));
}
resolve(expandJson);
},
fail() {
wx.hideLoading();
reject(new Error("上传失败"));
reject(new Error('上传失败'));
},
});
});

10
src/components/uploadFile/index.wxml

@ -7,13 +7,3 @@ @@ -7,13 +7,3 @@
<van-uploader wx:else accept="{{accept}}" max-count="{{1}}" bind:after-read="handleAfterRead">
<slot></slot>
</van-uploader>
<van-popup show="{{ show1 }}" bind:close="onClose" round>
<view class="popup1">
<image class="bg" src="{{imageUrl}}daub.gif?t={{Timestamp}}"></image>
<view class="sure" bind:tap="handleEditEnd">
我知道了 去涂抹
<van-icon name="arrow" />
</view>
</view>
</van-popup>

BIN
src/images/copnay-code.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 KiB

BIN
src/images/icon-edit.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 B

BIN
src/images/icon-pic.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
src/images/my-list-icon3.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

4
src/pages/my/index.scss

@ -37,6 +37,10 @@ page { @@ -37,6 +37,10 @@ page {
color: #141515;
font-weight: bold;
line-height: 1;
.icon {
width: 36rpx;
height: 36rpx;
}
}
.tel {
margin-top: 8rpx;

26
src/pages/my/index.ts

@ -5,7 +5,7 @@ Page({ @@ -5,7 +5,7 @@ Page({
toastShow: false,
toastType: 1,
userInfo: {},
userInfo: {} as any,
},
onLoad() {
app.waitLogin(true).then(() => {
@ -40,12 +40,36 @@ Page({ @@ -40,12 +40,36 @@ Page({
},
});
},
handleEditUser() {
wx.navigateTo({
url: '/pages/userInfo/index',
});
},
handleAvatar(e) {
const avatar = e.detail.fileUrl;
wx.ajax({
method: 'POST',
url: '?r=shizhong/account/update-info',
data: {
userName: this.data.userInfo.username,
avatar,
},
}).then(() => {
app.getUserInfo(this);
});
},
handleOffice() {
this.setData({
toastShow: true,
toastType: 1,
});
},
handleCompanyOffice() {
this.setData({
toastShow: true,
toastType: 2,
});
},
handleToastClose() {
this.setData({
toastShow: false,

14
src/pages/my/index.wxml

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
chooseAvatar
bind:file="handleFile"
data-key="Img"
bind:file="handleAvatar"
>
<image
wx:if="{{userInfo.avatar}}"
@ -18,11 +19,16 @@ @@ -18,11 +19,16 @@
mode="aspectFill"
src="/images/user.png"
></image>
</uploadFile>
<view class="user">
<view class="name">{{userInfo.username}}</view>
<view class="name">{{userInfo.username || '---'}}
<image
class="icon"
src="/images/icon-edit.png"
bind:tap="handleEditUser"
></image>
</view>
<view class="tel">{{userInfo.telephone}}</view>
<view class="status">{{userInfo.isMember===1?'会员':'非会员'}}</view>
</view>
@ -44,6 +50,10 @@ @@ -44,6 +50,10 @@
<image class="icon" src="/images/my-list-icon2.png"></image>
关注公众号
</view>
<view class="nav-item" bind:tap="handleCompanyOffice">
<image class="icon" src="/images/my-list-icon3.png"></image>
联系我们
</view>
</view>
</view>

7
src/pages/userInfo/index.json

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
{
"navigationStyle": "default",
"navigationBarTitleText": "个人信息",
"usingComponents": {
"uploadFile": "/components/uploadFile/index"
}
}

56
src/pages/userInfo/index.scss

@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
page {
background-color: #f3f4f5;
}
.page {
padding: 32rpx;
.container {
border-radius: 16rpx;
background-color: #fff;
.row {
padding: 36rpx 32rpx;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid #f0f0f0;
&:last-of-type {
border: none;
}
&.small {
padding: 24rpx 32rpx;
}
.label {
font-size: 36rpx;
color: #222222;
}
.wrap {
flex: 1;
display: flex;
justify-content: flex-end;
.avatar {
position: relative;
width: 100rpx;
height: 100rpx;
.a-img {
width: 100rpx;
height: 100rpx;
border-radius: 50%;
}
.icon {
position: absolute;
bottom: 0;
right: 0;
width: 32rpx;
height: 32rpx;
}
}
.input {
text-align: right;
font-size: 36rpx;
}
.place-input {
color: #babdc1;
}
}
}
}
}

48
src/pages/userInfo/index.ts

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
const app = getApp<IAppOption>();
Page({
data: {
userInfo: {} as any,
},
onLoad() {
app.waitLogin().then(() => {
app.getUserInfo(this);
});
},
handleFile(e) {
const avatar = e.detail.fileUrl;
this.setData({
'userInfo.avatar': avatar,
});
this.updateUserInfo();
},
handleInputBlur(e) {
const { key } = e.currentTarget.dataset;
this.setData({
[`userInfo.${key}`]: e.detail.value,
});
this.updateUserInfo();
},
updateUserInfo() {
const { avatar, username } = this.data.userInfo;
if (!username) {
wx.showToast({
title: '请输入用户名',
icon: 'none',
});
return;
}
wx.ajax({
method: 'POST',
url: '?r=shizhong/account/update-info',
data: {
userName: username,
avatar,
},
}).then(() => {
app.getUserInfo(this);
});
},
});
export {};

43
src/pages/userInfo/index.wxml

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
<view class="page">
<view class="container">
<view class="row small">
<view class="label">头像</view>
<view class="wrap">
<uploadFile
class="avatar"
chooseAvatar
bind:file="handleFile"
data-key="Img"
bind:file="handleAvatar"
>
<image
wx:if="{{userInfo.avatar}}"
class="a-img"
src="{{userInfo.avatar}}"
></image>
<image
wx:else
class="a-img"
src="/images/user.png"
></image>
<image class="icon" src="/images/icon-pic.png"></image>
</uploadFile>
</view>
</view>
<view class="row">
<view class="label">昵称</view>
<view class="wrap">
<input
class="input"
type="nickname"
value="{{userInfo.username}}"
placeholder-class="place-input"
placeholder="请输入昵称"
data-key="username"
bindblur="handleInputBlur"
></input>
</view>
</view>
</view>
</view>
Loading…
Cancel
Save