2023-07-07 14:22:34 +00:00
< template >
2023-11-06 11:43:27 +00:00
< view :class ="theme_view" >
2023-09-18 10:15:14 +00:00
< component -popup :propShow ="popup_status" propPosition = "bottom" @onclose ="popup_close_event" >
2023-10-12 01:53:44 +00:00
< view : class = "'user-base-popup bg-white ' + (propIsGrayscale ? 'grayscale' : '')" >
2023-09-18 10:15:14 +00:00
< view class = "close fr oh" >
< view class = "fr" @tap.stop ="popup_close_event" >
2023-12-20 09:55:20 +00:00
< iconfont name = "icon-close-o" size = "24rpx" color = "#999" > < / iconfont >
2023-09-18 10:15:14 +00:00
< / view >
< / view >
< form @submit ="form_submit" class = "form-container" >
< view class = "padding-top-sm" >
2024-01-15 10:39:38 +00:00
< view class = "text-size-md spacing-mb" > { { $t ( 'user-base.user-base.g5663y' ) } } < / view >
< view class = "padding-bottom-main cr-grey-9 br-b" > { { $t ( 'user-base.user-base.913g4e' ) } } < / view >
2024-03-19 09:29:49 +00:00
< view v-if ="(user || null) == null || (user.avatar || null) == null" class="form-gorup oh flex-row align-c br-b" >
2024-01-15 10:39:38 +00:00
< view class = "form-gorup-title text-size-md" > { { $t ( 'personal.personal.cw1d8p' ) } } < text class = "form-group-tips-must" > * < / text > < / view >
2023-09-18 10:15:14 +00:00
< button class = "bg-white br-0 padding-0 margin-left-xxl flex-row jc-sb align-c flex-1" hover -class = " none " open -type = " chooseAvatar " @chooseavatar ="choose_avatar_event" @tap ="choose_avatar_event" >
< image : src = "user_avatar || default_avatar" mode = "widthFix" class = "circle br user-base-avatar" > < / image >
2023-12-20 09:55:20 +00:00
< iconfont name = "icon-arrow-right" size = "24rpx" color = "#ccc" > < / iconfont >
2023-09-18 10:15:14 +00:00
< / button >
< / view >
2024-03-19 09:29:49 +00:00
< view v-if ="(user || null) == null || (user.nickname || null) == null" class="form-gorup oh flex-row align-c br-b" >
2024-01-15 10:39:38 +00:00
< view class = "form-gorup-title text-size-md" > { { $t ( 'personal.personal.gw8br3' ) } } < text class = "form-group-tips-must" > * < / text > < / view >
2023-09-18 10:15:14 +00:00
< view class = "user-nickname-container padding-left-xxl" >
2024-01-15 10:39:38 +00:00
< input : type = "application_client_type == 'weixin' ? 'nickname' : 'text'" name = "nickname" maxlength = "16" placeholder -class = " cr -grey -c " class = "cr-base" :placeholder ="$t('user-base.user-base.o19lj3')" @input ="on_input_name" / >
2023-09-18 10:15:14 +00:00
< / view >
< / view >
2023-05-24 10:06:15 +00:00
2023-10-12 01:53:44 +00:00
< view class = "tc padding-top-xxl" >
2024-01-15 10:39:38 +00:00
< button class = "sub-btn cr-white text-size" : class = "form_submit_disabled_status ? 'bg-grey-d br-grey-d' : 'bg-main br-main'" type = "default" form -type = " submit " hover -class = " none " > { { $t ( 'common.save' ) } } < / button >
2023-09-18 10:15:14 +00:00
< / view >
< / view >
< / form >
< / view >
< / c o m p o n e n t - p o p u p >
< / view >
2023-07-07 14:22:34 +00:00
< / template >
< script >
2023-10-08 07:31:18 +00:00
const app = getApp ( ) ;
2024-03-11 06:01:53 +00:00
import componentPopup from '@/components/popup/popup' ;
2023-10-08 07:31:18 +00:00
export default {
data ( ) {
return {
2023-11-07 03:37:22 +00:00
theme _view : app . globalData . get _theme _value _view ( ) ,
2023-10-08 07:31:18 +00:00
application _client _type : app . globalData . application _client _type ( ) ,
default _avatar : app . globalData . data . default _user _head _src ,
cache _key : app . globalData . data . cache _user _base _personal _interval _time _key ,
2023-10-08 07:48:44 +00:00
popup _status : false ,
2023-10-08 07:31:18 +00:00
user : { } ,
user _avatar : '' ,
nickname : '' ,
pages : [ ] ,
client : [ ] ,
interval _time : 0 ,
form _submit _disabled _status : true ,
testValue : '' ,
} ;
2023-09-18 10:15:14 +00:00
} ,
2023-07-07 14:22:34 +00:00
2023-10-08 07:31:18 +00:00
components : {
componentPopup ,
} ,
props : {
propIsGrayscale : {
type : Boolean ,
default : false ,
} ,
2023-09-18 10:15:14 +00:00
} ,
2023-07-07 14:22:34 +00:00
2023-10-08 07:31:18 +00:00
created : function ( ) {
2023-09-18 10:15:14 +00:00
// 初始化配置
2023-10-08 07:31:18 +00:00
this . init _config ( ) ;
} ,
2023-07-07 14:22:34 +00:00
2023-10-08 07:31:18 +00:00
methods : {
// 初始化配置
init _config ( status ) {
if ( ( status || false ) == true ) {
this . setData ( {
pages : app . globalData . get _config ( 'config.common_app_user_base_popup_pages' , [ ] ) ,
client : app . globalData . get _config ( 'config.common_app_user_base_popup_client' , [ ] ) ,
interval _time : parseInt ( app . globalData . get _config ( 'config.common_app_user_base_popup_interval_time' , 1800 ) ) ,
} ) ;
} else {
app . globalData . is _config ( this , 'init_config' ) ;
2023-09-18 10:15:14 +00:00
}
2023-10-08 07:31:18 +00:00
} ,
// 初始配置
init ( type = '' ) {
// 初始化配置
this . init _config ( true ) ;
2024-09-29 09:33:51 +00:00
// 未指定类型则自动匹配页面
if ( ( type || null ) == null ) {
var page = '/' + app . globalData . current _page ( false ) ;
var obj = {
index : '/pages/index/index' ,
goods _category : '/pages/goods-category/goods-category' ,
cart : '/pages/cart/cart' ,
user : '/pages/user/user' ,
} ;
var index = Object . values ( obj ) . indexOf ( page ) ;
if ( index != - 1 ) {
type = Object . keys ( obj ) [ index ] ;
2023-10-08 07:31:18 +00:00
}
2024-09-29 09:33:51 +00:00
}
if ( ( type || null ) == null ) {
// 是否需要展示弹窗提示
if ( ! this . popup _status && this . pages . indexOf ( type ) != - 1 && this . client . indexOf ( this . application _client _type ) != - 1 ) {
// 当前缓存用户
var user = app . globalData . get _user _cache _info ( ) || null ;
// 默认昵称则赋空值
var arr = [ this . $t ( 'user-base.user-base.8u9on2' ) , this . $t ( 'user-base.user-base.t8i9l4' ) , this . $t ( 'user-base.user-base.0imw74' ) , this . $t ( 'user-base.user-base.27q5af' ) , this . $t ( 'user-base.user-base.211pk4' ) , this . $t ( 'user-base.user-base.5x8o43' ) , 'WeChat User' , 'Usuarios de Wechat' ] ;
if ( user != null && ( user . nickname || null ) != null && arr . indexOf ( user . nickname ) != - 1 ) {
user . nickname = '' ;
}
// 头像是默认则置为空
if ( user != null && ( user . avatar || null ) != null && user . avatar . indexOf ( 'default-user-avatar' ) != - 1 ) {
user . avatar = '' ;
}
// 状态
var status = user == null ? false : ( ( user . avatar || null ) == null || ( user . nickname || null ) == null ? true : false ) ;
// 间隔时间
var cache _time = parseInt ( uni . getStorageSync ( this . cache _key ) || 0 ) ;
var current _time = Date . parse ( new Date ( ) ) / 1000 ;
if ( status && ! this . popup _status && cache _time > 0 && current _time < cache _time + parseInt ( this . interval _time ) ) {
status = false ;
}
2023-10-08 07:31:18 +00:00
2024-09-29 09:33:51 +00:00
// 1秒后再提示用户填写信息
var self = this ;
clearTimeout ( this . timer ) ;
this . timer = setTimeout ( function ( ) {
self . setData ( {
popup _status : status ,
user : user ,
} ) ;
} , 500 ) ;
}
2023-09-18 10:15:14 +00:00
}
2023-10-08 07:31:18 +00:00
} ,
2023-09-09 09:00:37 +00:00
2023-10-08 07:31:18 +00:00
// 弹层关闭
popup _close _event ( e ) {
this . setData ( {
popup _status : false ,
} ) ;
uni . setStorageSync ( this . cache _key , Date . parse ( new Date ( ) ) / 1000 ) ;
} ,
// 头像事件
choose _avatar _event ( e ) {
2023-09-18 10:15:14 +00:00
var self = this ;
2023-10-08 07:31:18 +00:00
if ( this . application _client _type == 'weixin' ) {
self . upload _handle ( e . detail . avatarUrl ) ;
} else {
uni . chooseImage ( {
count : 1 ,
success ( res ) {
if ( res . tempFilePaths . length > 0 ) {
self . upload _handle ( res . tempFilePaths [ 0 ] ) ;
}
} ,
2023-09-18 10:15:14 +00:00
} ) ;
2023-10-08 07:31:18 +00:00
}
} ,
2023-05-24 10:06:15 +00:00
2023-10-08 07:31:18 +00:00
// 上传处理
upload _handle ( image ) {
var self = this ;
uni . uploadFile ( {
url : app . globalData . get _request _url ( 'useravatarupload' , 'personal' ) ,
filePath : image ,
name : 'file' ,
formData : { } ,
success : function ( res ) {
if ( res . statusCode == 200 ) {
var data = typeof res . data == 'object' ? res . data : JSON . parse ( res . data ) ;
if ( data . code == 0 ) {
self . setData ( {
user _avatar : data . data ,
2023-11-01 01:52:02 +00:00
form _submit _disabled _status : ( ( self . user . nickname || null ) == null && ( self . nickname || null ) == null )
2023-10-08 07:31:18 +00:00
} ) ;
} else {
app . globalData . showToast ( data . msg ) ;
}
2023-09-18 10:15:14 +00:00
}
} ,
} ) ;
2023-10-08 07:31:18 +00:00
} ,
// 数据提交
form _submit ( e ) {
// 表单数据
var form _data = e . detail . value ;
2024-03-19 09:29:49 +00:00
var user = this . user || { } ;
2023-10-08 07:31:18 +00:00
// 头像
form _data [ 'avatar' ] = this . user _avatar || '' ;
2023-05-24 10:06:15 +00:00
2023-10-08 07:31:18 +00:00
// 验证数据项
var validation = [ ] ;
2024-03-19 09:29:49 +00:00
if ( ( user . avatar || null ) == null ) {
2023-10-08 07:31:18 +00:00
validation . push ( {
fields : 'avatar' ,
2024-01-15 10:39:38 +00:00
msg : this . $t ( 'user-base.user-base.gzc3y4' ) ,
2023-10-08 07:31:18 +00:00
} ) ;
2023-11-01 01:52:02 +00:00
} else {
delete form _data [ 'avatar' ] ;
2023-10-08 07:31:18 +00:00
}
2024-03-19 09:29:49 +00:00
if ( ( user . nickname || null ) == null ) {
2023-10-08 07:31:18 +00:00
validation . push ( {
fields : 'nickname' ,
2024-01-15 10:39:38 +00:00
msg : this . $t ( 'user-base.user-base.lro9u7' ) ,
2023-10-08 07:31:18 +00:00
} ) ;
2023-11-01 01:52:02 +00:00
} else {
delete form _data [ 'nickname' ] ;
2023-10-08 07:31:18 +00:00
}
if ( app . globalData . fields _check ( e . detail . value , validation ) ) {
// 数据保存
uni . showLoading ( {
2024-01-15 10:39:38 +00:00
title : this . $t ( 'common.processing_in_text' ) ,
2023-10-08 07:31:18 +00:00
} ) ;
uni . request ( {
url : app . globalData . get _request _url ( 'save' , 'personal' ) ,
method : 'POST' ,
data : form _data ,
dataType : 'json' ,
success : ( res ) => {
uni . hideLoading ( ) ;
if ( res . data . code == 0 ) {
uni . setStorageSync ( app . globalData . data . cache _user _info _key , res . data . data ) ;
app . globalData . showToast ( res . data . msg , 'success' ) ;
2023-09-18 10:15:14 +00:00
this . setData ( {
2023-10-08 07:31:18 +00:00
popup _status : false ,
2023-09-18 10:15:14 +00:00
} ) ;
} else {
2023-10-08 07:31:18 +00:00
if ( app . globalData . is _login _check ( res . data ) ) {
app . globalData . showToast ( res . data . msg ) ;
} else {
2024-01-15 10:39:38 +00:00
app . globalData . showToast ( this . $t ( 'common.sub_error_retry_tips' ) ) ;
2023-10-08 07:31:18 +00:00
}
2023-09-18 10:15:14 +00:00
}
2023-10-08 07:31:18 +00:00
} ,
fail : ( ) => {
uni . hideLoading ( ) ;
2024-01-15 10:39:38 +00:00
app . globalData . showToast ( this . $t ( 'common.internet_error_tips' ) ) ;
2023-10-08 07:31:18 +00:00
} ,
} ) ;
}
} ,
// 输入框值监听
on _input _name ( event ) {
2023-11-01 01:52:02 +00:00
if ( event . detail . value != '' ) {
2023-09-18 10:15:14 +00:00
this . setData ( {
2023-10-08 07:31:18 +00:00
nickname : event . detail . value ,
2024-03-19 09:29:49 +00:00
form _submit _disabled _status : ( ( ( this . user || null ) == null || ( this . user . avatar || null ) == null ) && ( this . user _avatar || null ) == null )
2023-11-01 01:52:02 +00:00
} ) ;
} else {
this . setData ( {
form _submit _disabled _status : true ,
2023-09-18 10:15:14 +00:00
} ) ;
}
2023-10-08 07:31:18 +00:00
} ,
2023-09-18 10:15:14 +00:00
} ,
2023-10-08 07:31:18 +00:00
} ;
2023-07-07 14:22:34 +00:00
< / script >
2023-09-18 10:15:14 +00:00
< style scoped >
2023-10-08 07:31:18 +00:00
. user - base - popup {
padding : 36 rpx ;
position : relative ;
}
. user - base - popup . close {
position : absolute ;
top : 36 rpx ;
right : 36 rpx ;
z - index : 2 ;
}
. user - base - avatar {
width : 80 rpx ;
height : 80 rpx ! important ;
}
. user - base - popup . form - gorup - title {
line - height : 70 rpx ;
margin - bottom : 0 ;
}
. user - base - popup . user - nickname - container {
width : calc ( 100 % - 120 rpx ) ;
}
. form - container . form - gorup {
padding : 24 rpx 0 ;
border - radius : 0 ;
}
. form - container . form - gorup - title {
font - weight : 400 ;
}
. sub - btn {
width : 336 rpx ;
height : 84 rpx ;
line - height : 84 rpx ;
padding : 0 ;
display : inline - flex ;
align - items : center ;
justify - content : center ;
border - radius : 12 rpx ;
}
2023-09-18 10:15:14 +00:00
< / style >