提交 4b2fe29e 编写于 作者: A Anne_LXM

feat: 兼容uni-app-x web端

上级 4e094a0f
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
font-family: "iconfont" !important; font-family: "iconfont" !important;
font-size: 16px; font-size: 16px;
font-style: normal; font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
} }
.uniui-back:before { .uniui-back:before {
......
<template> <template>
<view class="uni-navbar"> <view class="uni-navbar">
<view class="uni-navbar-inner" :style="navbarStyle"> <view class="uni-navbar-inner" :style="navbarStyle">
<view class="left-content" @click="back"> <view class="left-content" @click="back">
<text class="uni-icons">{{unicode}}</text> <text :style="{ color: textColor }" class="uni-icons">{{
</view> unicode
<view class="uni-navbar-content" :class="{'is-left':isLeft}"> }}</text>
<slot name="title">{{title}}</slot> </view>
</view> <view class="uni-navbar-content" :class="{ 'is-left': isLeft }">
<view class="right-content"> <text :style="{ color: textColor }">
<slot name="right"></slot> <slot>{{ title }}</slot>
</view> </text>
</view> </view>
</view> <view class="right-content">
<slot name="right"></slot>
</view>
</view>
</view>
</template> </template>
<script> <script>
import iconpath from './uniicons.ttf' import iconpath from "./uniicons.ttf";
export default { export default {
name: "uni-navbar", name: "uni-navbar",
props: { props: {
title: { title: {
type: String, type: String,
default: '' default: "",
}, },
isLeft: { isLeft: {
type: Boolean, type: Boolean,
default: false default: false,
} },
}, textColor: {
data() { type: String,
return { default: "#000",
statusBarHeight: 0 },
}; },
}, data() {
computed: { return {
navbarStyle() : string { statusBarHeight: 0,
return `margin-top:${this.statusBarHeight}px` };
}, },
unicode() : string { computed: {
return '\ue600' navbarStyle() : string {
} return `margin-top:${this.statusBarHeight}px`;
}, },
created() { unicode() : string {
uni.loadFontFace({ return "\ue600";
global: false, },
family: 'UniIconsFontFamily', },
source: iconpath, created() {
success() { }, uni.loadFontFace({
fail(err) { global: false,
console.log(err); family: "UniIconsFontFamily",
}, source: `url("${iconpath}")`,
}) success() { },
const sys = uni.getSystemInfoSync() fail(err) {
const statusBarHeight = sys.statusBarHeight console.log(err);
this.statusBarHeight = statusBarHeight },
}, });
mounted() { const sys = uni.getSystemInfoSync();
// TODO 暂时加定时器,否则不生效 const statusBarHeight = sys.statusBarHeight;
setTimeout(() => { this.statusBarHeight = statusBarHeight;
uni.setNavigationBarColor({ },
frontColor: '#000000', mounted() {
backgroundColor: '#ffffff' // TODO 暂时加定时器,否则不生效
}) setTimeout(() => {
}, 100) uni.setNavigationBarColor({
}, frontColor: "#000000",
methods: { backgroundColor: "#ffffff",
back() { });
uni.navigateBack({}) }, 100);
} },
}, methods: {
} back() {
uni.navigateBack({});
},
},
};
</script> </script>
<style> <style>
.uni-icons { .uni-icons {
font-family: "UniIconsFontFamily" !important; font-family: "UniIconsFontFamily" !important;
font-size: 22px; font-size: 22px;
font-style: normal; font-style: normal;
color: #333; color: #333;
} }
.uni-navbar { .uni-navbar {
border: 1px #eee solid; border: 1px #eee solid;
background-color: #fff; background-color: #ffffff;
} }
.uni-navbar-inner { .uni-navbar-inner {
position: relative; position: relative;
display: flex; flex-direction: row;
flex-direction: row; justify-content: space-between;
justify-content: space-between; height: 45px;
height: 45px; }
}
.left-content, .left-content,
.right-content { .right-content {
display: flex; justify-content: center;
justify-content: center; align-items: center;
align-items: center; width: 66px;
width: 45px; height: 100%;
height: 100%; }
}
.uni-navbar-content { .uni-navbar-content {
position: absolute; position: absolute;
height: 100%; height: 100%;
top: 0; top: 0;
bottom: 0; bottom: 0;
left: 45px; left: 45px;
right: 45px; right: 45px;
display: flex; flex-direction: row;
flex-direction: row; justify-content: center;
justify-content: center; align-items: center;
align-items: center; }
}
.is-left { .is-left {
justify-content: flex-start; justify-content: flex-start;
} }
</style> </style>
\ No newline at end of file
<template> <template>
<view class="uni-navbar"> <view class="uni-navbar">
<view class="uni-navbar-inner" :style="navbarStyle"> <view class="uni-navbar-inner" :style="navbarStyle">
<view class="left-content" @click="back"> <view class="left-content" @click="back">
<text class="uni-icons uniui-back"></text> <text class="uni-icons uniui-back"></text>
</view> </view>
<view class="uni-navbar-content"> <view class="uni-navbar-content">
<slot>{{title}}</slot> <slot>{{title}}</slot>
</view> </view>
<view class="right-content"> <view class="right-content">
<slot name="right"></slot> <slot name="right"></slot>
</view> </view>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
name: "uni-navbar", name: "uni-navbar",
props: { props: {
title: { title: {
type: String, type: String,
default: '' default: ''
} }
}, },
data() { data() {
return { return {
statusBarHeight: 0 statusBarHeight: 0
}; };
}, },
computed: { computed: {
navbarStyle() { navbarStyle() {
return `margin-top:${this.statusBarHeight}px` return `margin-top:${this.statusBarHeight}px`
}, },
}, },
created() { created() {
const sys = uni.getSystemInfoSync() const sys = uni.getSystemInfoSync()
const statusBarHeight = sys.statusBarHeight const statusBarHeight = sys.statusBarHeight
this.statusBarHeight = statusBarHeight this.statusBarHeight = statusBarHeight
}, },
methods: { methods: {
back() { back() {
uni.navigateBack({}) uni.navigateBack({})
} }
}, },
} }
</script> </script>
<style> <style>
@import './uni-icons.css'; @import './uni-icons.css';
.uni-icons { .uni-icons {
font-family: UniIconsLight; font-family: UniIconsLight;
text-decoration: none; text-decoration: none;
text-align: center; text-align: center;
font-size: 22px; font-size: 22px;
font-style: normal; font-style: normal;
color: #333; color: #333;
} }
.uni-navbar { .uni-navbar {
border: 1px #eee solid; border: 1px #eee solid;
background-color: #fff; background-color: #fff;
} }
.uni-navbar-inner { .uni-navbar-inner {
position: relative; position: relative;
display: flex; flex-direction: row;
flex-direction: row; justify-content: space-between;
justify-content: space-between; height: 45px;
height: 45px; }
}
.left-content, .left-content,
.right-content { .right-content {
display: flex; justify-content: center;
justify-content: center; align-items: center;
align-items: center; width: 45px;
width: 45px; height: 100%;
height: 100%; }
}
.uni-navbar-content { .uni-navbar-content {
position: absolute; position: absolute;
height: 100%; height: 100%;
top: 0; top: 0;
bottom: 0; bottom: 0;
left: 45px; left: 45px;
right: 45px; right: 45px;
display: flex; justify-content: center;
justify-content: center; align-items: center;
align-items: center; }
} </style>
</style>
\ No newline at end of file
...@@ -113,16 +113,12 @@ ...@@ -113,16 +113,12 @@
// this.setAvatarFile(avatar_file) // this.setAvatarFile(avatar_file)
}, },
uploadAvatarImg() { uploadAvatarImg() {
if(this.readOnly){ if(this.readOnly){
return return
} }
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
return // 微信小程序走 bindchooseavatar方法 return // 微信小程序走 bindchooseavatar方法
// #endif // #endif
// #ifndef MP-WEIXIN // #ifndef MP-WEIXIN
// if(!this.hasLogin){ // if(!this.hasLogin){
// uni.navigateTo({ // uni.navigateTo({
...@@ -139,21 +135,20 @@ ...@@ -139,21 +135,20 @@
uni.chooseImage({ uni.chooseImage({
count: 1, count: 1,
crop, crop,
success(res) : void { success: (res) => {
// console.log('res', res); // console.log('res', res);
let tempFiles = res.tempFiles as UTSJSONObject[]; let tempFiles = res.tempFiles as UTSJSONObject[];
let tempFile = tempFiles[0]; let tempFile = tempFiles[0];
let tempFileName = tempFile.getString('name') let tempFileName = tempFile['name'] as string
let tempFilePath = tempFile.getString('path') let tempFilePath = tempFile['path'] as string
if (tempFileName == null) { if (tempFileName == null) {
tempFileName = "" tempFileName = ""
} }
if (tempFilePath == null) { if (tempFilePath == null) {
tempFilePath = "" tempFilePath = ""
} }
console.log(9527,tempFileName.length); // console.log('tempFileName',tempFileName);
console.log('tempFileName',tempFileName); // console.log('tempFilePath',tempFilePath);
console.log('tempFilePath',tempFilePath);
let avatar_file = { let avatar_file = {
// #ifdef WEB // #ifdef WEB
extname: tempFileName.split(".")[tempFileName.split(".").length - 1], extname: tempFileName.split(".")[tempFileName.split(".").length - 1],
...@@ -164,7 +159,7 @@ ...@@ -164,7 +159,7 @@
name: tempFileName, name: tempFileName,
url: tempFilePath url: tempFilePath
} as UTSJSONObject } as UTSJSONObject
console.log('avatar_file', avatar_file); // console.log('avatar_file', avatar_file);
let filePath = res.tempFilePaths[0] let filePath = res.tempFilePaths[0]
//非app端剪裁头像,app端用内置的原生裁剪 //非app端剪裁头像,app端用内置的原生裁剪
...@@ -191,12 +186,6 @@ ...@@ -191,12 +186,6 @@
}); });
}) })
// #endif // #endif
console.log("state",state)
console.log("state.userInfo",state.userInfo)
console.log("this.userInfo",this.userInfo)
let _id = this.userInfo["_id"] as string let _id = this.userInfo["_id"] as string
console.log("id",_id) console.log("id",_id)
// if(_id != null){ // if(_id != null){
...@@ -204,19 +193,17 @@ ...@@ -204,19 +193,17 @@
// } // }
let cloudPath = _id + '' + Date.now() let cloudPath = _id + '' + Date.now()
avatar_file.name = cloudPath avatar_file.name = cloudPath
uni.showLoading({ uni.showLoading({
title: "更新中", title: "更新中",
mask: true mask: true
}); });
// console.log('filePath', filePath); // console.log('filePath', filePath);
uniCloud.uploadFile({ uniCloud.uploadFile({
filePath, filePath,
cloudPath, cloudPath,
}) })
.then(function (res) { .then(function (res) {
// console.log('res777777777',res); // console.log('res', res);
avatar_file.url = res.fileID avatar_file.url = res.fileID
// console.log('avatar_file111', avatar_file); // console.log('avatar_file111', avatar_file);
mutations.updateUserInfo({ avatar_file } as UTSJSONObject) mutations.updateUserInfo({ avatar_file } as UTSJSONObject)
...@@ -232,7 +219,7 @@ ...@@ -232,7 +219,7 @@
uni.hideLoading() uni.hideLoading()
}) })
}, },
fail(err) : void { fail:(err)=>{
console.error('chooseImage fail: ', err) console.error('chooseImage fail: ', err)
uni.showModal({ uni.showModal({
content: '失败,' + err.errMsg, content: '失败,' + err.errMsg,
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
</template> </template>
<script> <script>
import { state, mutations } from '@/uni_modules/uni-id-pages-x/store.uts'; import { mutations } from '@/uni_modules/uni-id-pages-x/store.uts';
export default { export default {
data() { data() {
return { return {
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
}, },
bindMobileBySms(param : UTSJSONObject) { bindMobileBySms(param : UTSJSONObject) {
// 设置(添加)验证码并重新发起 // 设置(添加)验证码并重新发起
function setCaptchaRetry() { const setCaptchaRetry = ()=> {
uni.showToast({ uni.showToast({
title: '请输入验证码', title: '请输入验证码',
icon: 'none', icon: 'none',
...@@ -70,8 +70,7 @@ ...@@ -70,8 +70,7 @@
uni.hideLoading() uni.hideLoading()
}) })
.then((e : UTSJSONObject) : void => { .then((e : UTSJSONObject) : void => {
// console.log('then'); console.log(e,"-----------");
console.log(e);
uni.showToast({ uni.showToast({
title: '绑定成功', title: '绑定成功',
icon: 'none', icon: 'none',
...@@ -107,7 +106,6 @@ ...@@ -107,7 +106,6 @@
}) })
}, },
popupCaptchaCancel() { popupCaptchaCancel() {
// console.log('popupCaptchaCancel');
this.smsCodeEl!.reset(); this.smsCodeEl!.reset();
this.captcha = "" this.captcha = ""
} }
......
...@@ -98,8 +98,8 @@ ...@@ -98,8 +98,8 @@
font-size: 14px; font-size: 14px;
border-radius: 5px; border-radius: 5px;
margin-right: 15px; margin-right: 15px;
background-color: #0070ff; background-color: #0070ff !important;
color: #FFF; color: #FFF!important;
} }
.submit.disabled { .submit.disabled {
......
...@@ -20,7 +20,7 @@ function initState() { ...@@ -20,7 +20,7 @@ function initState() {
let userInfo = uni.getStorageSync('uni-id-pages-x-userInfo') let userInfo = uni.getStorageSync('uni-id-pages-x-userInfo')
if (userInfo instanceof UTSJSONObject) { if (userInfo instanceof UTSJSONObject) {
state.userInfo = userInfo state.userInfo = userInfo
// console.log('init userInfo',userInfo); console.log('init userInfo',userInfo);
} }
} catch (e) { } catch (e) {
console.error('init userInfo error', e); console.error('init userInfo error', e);
...@@ -35,7 +35,7 @@ type Mutations = { ...@@ -35,7 +35,7 @@ type Mutations = {
} }
export const mutations = { export const mutations = {
updateUserInfo: function (param: null | UTSJSONObject) { updateUserInfo: function (param: null | UTSJSONObject) {
console.log('updateUserInfo', param); // param为 null 时从云端获取数据更新,为UTSJSONObject时直接根据传入的值来更新 //console.log('updateUserInfo', param); // param为 null 时从云端获取数据更新,为UTSJSONObject时直接根据传入的值来更新
function afterUpdateUserInfo() { function afterUpdateUserInfo() {
// console.log('afterUpdateUserInfo', state.userInfo); // console.log('afterUpdateUserInfo', state.userInfo);
uni.setStorageSync('uni-id-pages-x-userInfo', state.userInfo) uni.setStorageSync('uni-id-pages-x-userInfo', state.userInfo)
...@@ -44,7 +44,7 @@ export const mutations = { ...@@ -44,7 +44,7 @@ export const mutations = {
if (param == null) { if (param == null) {
const db = uniCloud.databaseForJQL() const db = uniCloud.databaseForJQL()
const user_id = uniCloud.getCurrentUserInfo().uid const user_id = uniCloud.getCurrentUserInfo().uid
// console.log('user_id', user_id); console.log('user_id', user_id);
if (user_id != null) { if (user_id != null) {
db.collection('uni-id-users') db.collection('uni-id-users')
.doc(user_id) .doc(user_id)
...@@ -72,7 +72,6 @@ export const mutations = { ...@@ -72,7 +72,6 @@ export const mutations = {
} }
} else { } else {
param.toMap().forEach((value, key) => { param.toMap().forEach((value, key) => {
console.log("updateUserInfo.", key, value)
state.userInfo.set(key, value) state.userInfo.set(key, value)
}) })
afterUpdateUserInfo() afterUpdateUserInfo()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册