Browse Source

登录页面和消息提示组件

pull/1/head
张立 9 months ago
parent
commit
3e278ce6e2
  1. 2
      src/main.ts
  2. 359
      src/mycomponents/common/comMessage.vue
  3. 8
      src/pages.json
  4. 222
      src/pages/login/index.vue

2
src/main.ts

@ -3,6 +3,7 @@ import * as Pinia from 'pinia'
// @ts-ignore
import uView from 'vk-uview-ui'
import App from './App.vue'
import comMessage from '@/mycomponents/common/comMessage.vue'
@ -30,6 +31,7 @@ export function createApp() {
app.config.globalProperties.$modal = modal
// 时间对象
app.config.globalProperties.$time = time
app.component('com-message', comMessage)

359
src/mycomponents/common/comMessage.vue

@ -29,132 +29,127 @@
</view>
</template>
<script>
<script setup lang="ts">
/**
* modal 模态框
* @description 弹出模态框常用于消息提示消息确认在当前页面内完成特定的交互操作
* */
export default {
data() {
return {
timer: null,
show: false, //
iconType: '消息',
icon: '../../static/icons/error-circle.svg',
title: '', //
content: '', //
cancelText: '取消', //
confirmText: '确定', //
showCancel: true, // true
confirmColor: '#007aff', //
cancelColor: null, //
showConfirmButton: true, //
showConfirmCountdown: true, //
showCancelButton: true, //
showClose: false,
confirm: false, // true
cancel: false, // true
isDisabled: true, // true
seconds: 0,
success: () => {} //
}
},
methods: {
open() {
this.show = true;
this.isDisabled = true;
},
close() {
this.$.refs.modal.popupClose();
this.isDisabled = false;
},
confirmClose() {
if (!this.isDisabled) return
this.isDisabled = false
import {
ref,
getCurrentInstance
} from 'vue'
const timer = ref(null)
const show = ref(false) //
const iconType = ref('消息')
const icon = ref('../../static/icons/error-circle.svg')
const title = ref('')
const content = ref('') //
const cancelText = ref('取消') //
const confirmText = ref('确定') //
const showCancel = ref(true) // true
const confirmColor = ref('#007aff') //
const cancelColor = ref(null) //
const showConfirmButton = ref(true) //
const showConfirmCountdown = ref(true) //
const showCancelButton = ref(true) //
const showClose = ref(false)
const confirm = ref(false) // true
const cancel = ref(false) // true
const isDisabled = ref(true) // true
const seconds = ref(0)
const success = () => {
}
const open = () => {
show.value = true;
isDisabled.value = true;
}
const close = () => {
show.value = false
isDisabled.value = false;
}
const confirmClose = () => {
if (!isDisabled.value) return
isDisabled.value = false
// console.log('')
if (this.show) {
this.show = false;
clearInterval(this.timer) //timer
this.$.refs.modal.popupClose();
this.success({
if (show.value) {
show.value = false;
clearInterval(timer.value) //timer
success({
// cancel: false,
confirm: true,
});
}
},
cancelClose() {
if (!this.isDisabled) return
this.isDisabled = false
clearInterval(this.timer) //timer
this.$.refs.modal.popupClose();
this.success({
}
const cancelClose = () => {
if (!isDisabled.value) return
isDisabled.value = false
clearInterval(timer.value) //timer
show.value = false
success({
// cancel: true,
confirm: false,
});
},
}
// (+)
showMessage(mContent, callback) {
this.showConfirmCountdownModal("消息", mContent, callback);
},
const showMessage = (mContent, callback) => {
showConfirmCountdownModal("消息", mContent, callback);
}
// (+)
showSuccessMessage(mContent, callback) {
this.showConfirmCountdownModal("成功", mContent, callback);
},
const showSuccessMessage = (mContent, callback) => {
showConfirmCountdownModal("成功", mContent, callback);
}
// (
showErrorMessage(mContent, callback) {
this.showConfirmModal("失败", mContent, callback);
},
const showErrorMessage = (mContent, callback) => {
console.log(333)
showConfirmModal("失败", mContent, callback);
}
// (
showBreakMessage(mContent, callback) {
this.showNoButtonModal("失败", mContent, callback);
},
const showBreakMessage = (mContent, callback) => {
showNoButtonModal("失败", mContent, callback);
}
// (+
showQuestionMessage(mContent, callback) {
this.showSelectModal("疑问", mContent, callback);
},
const showQuestionMessage = (mContent, callback) => {
showSelectModal("疑问", mContent, callback);
}
// (+)
showWarningMessage(mContent, callback) {
this.showConfirmCountdownModal("警告", mContent, callback);
},
const showWarningMessage = (mContent, callback) => {
showConfirmCountdownModal("警告", mContent, callback);
}
// (+)
showConfirmCountdownFailModal(mContent, callback) {
this.showConfirmCountdownModal("失败", mContent, callback);
},
const showConfirmCountdownFailModal = (mContent, callback) => {
showConfirmCountdownModal("失败", mContent, callback);
}
// (
showConfirmMessageModal(mContent, callback) {
this.showConfirmModal("消息", mContent, callback);
},
const showConfirmMessageModal = (mContent, callback) => {
showConfirmModal("消息", mContent, callback);
}
// (
showConfirmSuccessModal(mContent, callback) {
this.showConfirmModal("成功", mContent, callback);
},
const showConfirmSuccessModall = (mContent, callback) => {
showConfirmModal("成功", mContent, callback);
}
// (
showConfirmWarningModal(mContent, callback) {
this.showConfirmModal("警告", mContent, callback);
},
const showConfirmWarningModal = (mContent, callback) => {
showConfirmModal("警告", mContent, callback);
}
// (
showConfirmQuestionModal(mContent, callback) {
this.showConfirmModal("疑问", mContent, callback);
},
const showConfirmQuestionModal = (mContent, callback) => {
showConfirmModal("疑问", mContent, callback);
}
// (
showNoButtonModal(mIconType, mContent, callback) {
this.showModal({
const showNoButtonModal = (mIconType, mContent, callback) => {
showModal({
iconType: mIconType,
content: mContent,
showConfirmButton: false,
@ -170,11 +165,11 @@
}
});
},
}
// (
showConfirmModal(mIconType, mContent, callback) {
this.showModal({
const showConfirmModal = (mIconType, mContent, callback) => {
console.log(222)
showModal({
iconType: mIconType,
content: mContent,
showCancelButton: false,
@ -189,31 +184,31 @@
}
});
},
}
// (+
showSelectMessageModal(mContent, callback) {
this.showSelectModal("消息", mContent, callback);
},
const showSelectMessageModal = (mContent, callback) => {
showSelectModal("消息", mContent, callback);
}
// (+
showSelectSuccessModal(mContent, callback) {
this.showSelectModal("成功", mContent, callback);
},
const showSelectSuccessModal = (mContent, callback) => {
showSelectModal("成功", mContent, callback);
}
// (+
showSelectFailModal(mContent, callback) {
this.showSelectModal("失败", mContent, callback);
},
const showSelectFailModal = (mContent, callback) => {
showSelectModal("失败", mContent, callback);
}
// (+
showSelectWarningModal(mContent, callback) {
this.showSelectModal("警告", mContent, callback);
},
const showSelectWarningModal = (mContent, callback) => {
showSelectModal("警告", mContent, callback);
}
// (+
showSelectModal(mIconType, mContent, callback) {
this.showModal({
const showSelectModal = (mIconType, mContent, callback) => {
showModal({
iconType: mIconType,
content: mContent,
success: function(res) {
@ -229,16 +224,16 @@
}
});
},
}
// (+)
showConfirmCountdownQuestionModal(mContent, callback) {
this.showConfirmCountdownModal("疑问", mContent, callback);
},
const showConfirmCountdownQuestionModal = (mContent, callback) => {
showConfirmCountdownModal("疑问", mContent, callback);
}
// (+)
showConfirmCountdownModal(mIconType, mContent, callback) {
this.showModal({
const showConfirmCountdownModal = (mIconType, mContent, callback) => {
showModal({
iconType: mIconType,
content: mContent,
showCancelButton: false,
@ -253,36 +248,36 @@
}
}
});
},
}
// (++)
showSelectCountdownMessageModal(mContent, callback) {
this.showSelectCountdownModal("消息", mContent, callback);
},
const showSelectCountdownMessageModal = (mContent, callback) => {
showSelectCountdownModal("消息", mContent, callback);
}
// (++)
showSelectCountdownSuccessModal(mContent, callback) {
this.showSelectCountdownModal("成功", mContent, callback);
},
const showSelectCountdownSuccessModal = (mContent, callback) => {
showSelectCountdownModal("成功", mContent, callback);
}
// (++)
showSelectCountdownFailModal(mContent, callback) {
this.showSelectCountdownModal("失败", mContent, callback);
},
const showSelectCountdownFailModal = (mContent, callback) => {
showSelectCountdownModal("失败", mContent, callback);
}
// (++)
showSelectCountdownWarningModal(mContent, callback) {
this.showSelectCountdownModal("警告", mContent, callback);
},
const showSelectCountdownWarningModal = (mContent, callback) => {
showSelectCountdownModal("警告", mContent, callback);
}
// (++)
showSelectCountdownQuestionModal(mContent, callback) {
this.showSelectCountdownModal("疑问", mContent, callback);
},
const showSelectCountdownQuestionModal = (mContent, callback) => {
showSelectCountdownModal("疑问", mContent, callback);
}
// (++)
showSelectCountdownModal(mIconType, mContent, callback) {
this.showModal({
const showSelectCountdownModal = (mIconType, mContent, callback) => {
showModal({
iconType: mIconType,
content: mContent,
showConfirmCountdown: true,
@ -298,27 +293,27 @@
}
}
});
},
}
//
showModal(data) {
const showModal = (data) => {
if (data.iconType) {
this.iconType = data.iconType
iconType.value = data.iconType
switch (data.iconType) {
case '消息':
this.icon = '/static/icons/error-circle.svg';
icon.value = '/static/icons/error-circle.svg';
break;
case '成功':
this.icon = '/static/icons/checkmark-circle.svg';
icon.value = '/static/icons/checkmark-circle.svg';
break;
case '失败':
this.icon = '/static/icons/close-circle.svg';
icon.value = '/static/icons/close-circle.svg';
break;
case '警告':
this.icon = '/static/icons/warning.svg';
icon.value = '/static/icons/warning.svg';
break;
case '疑问':
this.icon = '/static/icons/question-circle.svg';
icon.value = '/static/icons/question-circle.svg';
break;
default:
break;
@ -326,98 +321,94 @@
}
// image
if (data.title) {
this.title = data.title
title.value = data.title
}
if (data.content) {
this.content = data.content
content.value = data.content
} else {
this.content = ''
content.value = ''
}
if (data.cancelText) {
this.cancelText = data.cancelText
cancelText.value = data.cancelText
} else {
this.cancelText = '取消'
cancelText.value = '取消'
}
if (data.confirmText) {
this.confirmText = data.confirmText
confirmText.value = data.confirmText
} else {
this.confirmText = '确定'
confirmText.value = '确定'
}
if (data.showCancel === false || data.showCancel === true) {
this.showCancel = data.showCancel
showCancel.value = data.showCancel
} else {
this.showCancel = true
showCancel.value = true
}
if (data.confirmColor) {
this.confirmColor = data.confirmColor
confirmColor.value = data.confirmColor
} else {
this.confirmColor = '#007aff'
confirmColor.value = '#007aff'
}
if (data.cancelColor) {
this.cancelColor = data.cancelColor
cancelColor.value = data.cancelColor
} else {
this.cancelColor = '#666F83'
cancelColor.value = '#666F83'
}
if (data.showConfirmButton === false || data.showConfirmButton === true) {
this.showConfirmButton = data.showConfirmButton
showConfirmButton.value = data.showConfirmButton
} else {
this.showConfirmButton = true
showConfirmButton.value = true
}
if (data.showConfirmCountdown === false || data.showConfirmCountdown === true) {
this.showConfirmCountdown = data.showConfirmCountdown
showConfirmCountdown.value = data.showConfirmCountdown
} else {
this.showConfirmCountdown = false
showConfirmCountdown.value = false
}
if (data.showCancelButton === false || data.showCancelButton === true) {
this.showCancelButton = data.showCancelButton
showCancelButton.value = data.showCancelButton
} else {
this.showCancelButton = true
showCancelButton.value = true
}
if (data.success) {
this.success = data.success
success = data.success
} else {
this.success = () => {}
success = () => {}
}
setTimeout(res => {
this.open();
open();
}, 500)
if (this.showConfirmCountdown) {
this.startTimer();
if (showConfirmCountdown.value) {
startTimer();
}
},
}
startTimer() {
this.seconds = 3;
clearInterval(this.timer)
this.timer = setInterval(() => {
this.seconds--
const startTimer = () => {
seconds.value = 3;
clearInterval(timer.value)
timer.value = setInterval(() => {
seconds.value--
// console.log("", this.seconds);
if (this.seconds <= 0) {
this.timeUp()
if (seconds.value <= 0) {
timeUp()
return
}
}, 1000)
},
}
timeUp() {
const timeUp = () => {
// clearInterval(this.timer)
console.log('时间到')
this.confirmClose();
},
},
confirmClose();
}
defineExpose({ showErrorMessage }) // open
</script>
<style lang="scss" scoped>
.slot-content {

8
src/pages.json

@ -49,7 +49,13 @@
{
"path": "pages/login/index",
"style": {
"navigationBarTitleText": "登录"
"navigationBarTitleText": "登录",
"navigationBarBackgroundColor": "#476df5",
"h5": {
"maxWidth": 1190,
"navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#476df5 !important"
}
}
},

222
src/pages/login/index.vue

@ -1,6 +1,5 @@
<template>
<view class="content">
<!-- <image mode="widthFix" class="loginimg" src="../../static/login.png"></image> -->
<image mode="widthFix" class="loginimg" src="../../static/icons_ui/login_bg.png"></image>
<view class="login_title">
<text>您好欢迎使用</text><br>
@ -10,16 +9,8 @@
<view class="loginbox">
<form>
<view class="mytab">
<!-- <view class="mytabline" :class="tapstyle == 1?'active':''" @click="tapchenge(1)">扫码登录</view> -->
<view class="mytabline" :class="tapstyle == 2?'active_in':''" @click="tapchenge(2)">密码登录</view>
</view>
<!-- <view class="mybox" v-if="tapstyle == 1">
<view class="conone">
<uni-easyinput prefixIcon="scan" class="uni-input" type="password" v-model="smloginmsg"
name="nickname" placeholder="扫码登录"></uni-easyinput>
</view>
</view> -->
<view class="mybox" v-if="tapstyle == 2">
<view class="conone">
<view class="title uni-flex">
@ -36,7 +27,8 @@
用户名
</view>
<view>
<input class="uni-input" style="padding:25rpx" placeholder="请输入用户名" v-model="username" />
<input class="uni-input" style="padding:25rpx" placeholder="请输入用户名"
v-model="username" />
</view>
</view>
<view class="conone">
@ -45,27 +37,15 @@
密码
</view>
<view class="uni-input-wrapper">
<input class="uni-input" style="padding:25rpx" placeholder="请输入密码" :password="showPassword"
v-model="password" />
<input class="uni-input" style="padding:25rpx" placeholder="请输入密码"
:password="showPassword" v-model="password" />
<text class="uni-icon" :class="[!showPassword ? 'uni-eye-active' : '']"
@click="changePassword">&#xe568;</text>
</view>
<!-- <view class="uni-input-wrapper">
<input class="uni-input" type="password" name="password"
:password="showPassword"
placeholder="请输入密码" v-model="password"></input>
<text class="uni-icon" :class="[!showPassword ? 'uni-eye-active' : '']" @click="changePassword">&#xe568;</text>
</view> -->
</view>
</view>
<view style="display: flex;flex-direction: row;">
<!-- <view class="uni-input">
<input class="" placeholder="请输入验证码"
v-model="code"
style="background-color: lightgray;padding-top: 40rpx;padding-bottom: 40rpx;margin-right: 20rpx;" />
</view> -->
<view class="uni-input-wrapper">
<input class="" style="height: 80rpx; background-color: #F7F9FF;margin-right: 20rpx;"
placeholder="请输入验证码" type="number" v-model="code" />
@ -84,47 +64,58 @@
</form>
</view>
</view>
<comMessage ref="comMessage"></comMessage>
<com-message ref="comMessageRef" />
</view>
</template>
<script>
<script setup lang="ts">
import {
onLoad,
onShow,
onNavigationBarButtonTap,
onReady
} from '@dcloudio/uni-app'
import {
ref,
getCurrentInstance
} from 'vue'
import {
getCaptchaImage
} from '@/api/request2.js';
import {
mapState,
mapMutations
} from 'vuex'
import {
useCountStore
} from '@/store'
// store
const store = useCountStore()
export default {
components: {},
data() {
return {
smloginmsg: "",
tenantName: "闻荫源码",
username: "",
password: "",
tapstyle: 2,
loading: false,
showPassword: true,
imageSrc: "",
code: "",
uuid: ""
const { proxy } = getCurrentInstance()
const smloginmsg = ref('')
const tenantName = ref('闻荫源码')
const username = ref('')
const password = ref('')
const tapstyle = ref(2)
const loading = ref(false)
const showPassword = ref(true)
const imageSrc = ref('')
const code = ref('')
const uuid = ref('')
const comMessageRef = ref('')
//
onNavigationBarButtonTap((e) => {
if (e.index === 0) {
uni.navigateTo({
url: "/pages/config/config"
})
}
},
// computed: mapState(['forcedLogin', 'hasLogin']),
mounted() {
})
onReady(() => {
console.log()
})
onLoad(() => {
uni.clearStorageSync()
uni.clearStorage(); //
if (process.env.NODE_ENV === 'development') {
this.username = "admin"
this.password = "123456";
if (import.meta.env.VITE_USER_NODE_ENV === 'development') {
username.value = "admin"
password.value = "123456";
}
uni.setNavigationBarColor({
frontColor: '#ffffff',
@ -137,52 +128,15 @@
backgroundColor: "#476DF5"
})
// #endif
},
//
onNavigationBarButtonTap(e) {
if (e.index === 0) {
uni.navigateTo({
url: "/pages/config/config"
})
}
},
onLoad() {
getCaptchaImage().then(res => {
if (res) {
var code = res.data.img;
let base64 = 'data:image/jpeg;base64,' + code
// console.log("", base64)
this.imageSrc = base64.replace(/[\r\n]/g, "")
this.uuid = res.data.uuid
}
}).catch(error => {
this.showErrorMessage(error);
})
},
methods: {
// ...mapMutations(['login']),
handelerlogin() {
if (this.username === '') {
uni.showToast({
title: '用户名不能为空',
icon: 'none',
mask: true
})
} else if (this.password === '') {
uni.showToast({
title: '密码不能为空',
icon: 'none',
mask: true
})
} else if (this.code === '') {
uni.showToast({
title: '验证码不能为空',
icon: 'none',
mask: true
getCode()
})
const handelerlogin = () => {
if (username.value === '') {
proxy.$modal.showToast('用户名不能为空')
} else if (password.value === '') {
proxy.$modal.showToast('密码不能为空')
} else if (code.value === '') {
proxy.$modal.showToast('验证码不能为空')
} else {
// console.log("", this.username, "", this.password, this.tapstyle, this.smloginmsg)
let logininfo = {
@ -191,69 +145,53 @@
code: "",
uuid: ""
}
if (this.tapstyle == 2) //
{
logininfo.username = this.username;
logininfo.password = this.password
logininfo.code = this.code;
logininfo.uuid = this.uuid;
} else if (this.tapstyle == 1) {
// let arr = Base64.decode(this.smloginmsg).split(':')
// logininfo.username = arr[0];
// logininfo.password = arr[1]
//
if (tapstyle.value == 2) {
logininfo.username = username.value;
logininfo.password = password.value
logininfo.code = code.value;
logininfo.uuid = uuid.value;
} else if (tapstyle.value == 1) {
}
let params = JSON.stringify(logininfo);
console.log('params', params);
this.newLogin(logininfo)
newLogin(logininfo)
}
},
async newLogin(logininfo) {
uni.showLoading({
title: "正在登录",
mask: true
})
}
const newLogin = async (logininfo) => {
proxy.$modal.loading('正在登录')
await store.Login(logininfo)
// await this.$store.dispatch('Login', logininfo);
// await this.$store.dispatch('GetTenantIdInfo', this.tenantName)
uni.hideLoading()
proxy.$modal.closeLoading()
uni.setStorageSync('hasLogin', true)
uni.switchTab({
url: '/pages/index/index'
});
uni.setStorageSync('username', this.username);
},
tapchenge(e) {
this.tapstyle = e
},
onchange(e) {
uni.setStorageSync('username', username.value);
}
const tapchenge = (e) => {
tapstyle.value = e
}
const onchange = (e) => {
const value = e.detail.value
},
changePassword: function() {
this.showPassword = !this.showPassword;
},
showErrorMessage(message) {
this.$refs.comMessage.showErrorMessage(message, res => {
if (res) {
}
});
},
getCode() {
const changePassword = () => {
showPassword.vlaue = !showPassword.vlaue;
}
const showErrorMessage = (message) => {
console.log(comMessag1e.value)
comMessageRef.value.showErrorMessage(message, res => { });
}
const getCode = () => {
getCaptchaImage().then(res => {
if (res) {
var code = res.data.img;
let base64 = 'data:image/jpeg;base64,' + code
this.imageSrc = base64.replace(/[\r\n]/g, "")
this.uuid = res.data.uuid
imageSrc.value = base64.replace(/[\r\n]/g, "")
uuid.value = res.data.uuid
}
}).catch(error => {
showErrorMessage(error)
})
}
}
}
</script>
<style>

Loading…
Cancel
Save