| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- <template>
- <view class="normal-login-container">
- <view class="logo-content align-center justify-center flex">
- <image style="width: 100%;" :src="config.logoSrc" mode="widthFix">
- </image>
- <!-- <text class="title">OA移动端登录</text> -->
- </view>
- <view class="login-form-content">
- <view class="input-item flex align-center">
- <view class="iconfont icon-user icon"></view>
- <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
- </view>
- <view class="input-item flex align-center">
- <view class="iconfont icon-password icon"></view>
- <input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
- </view>
- <view class="action-btn">
- <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
- </view>
- </view>
- </view>
- </template>
- <script setup lang="ts">
- import { ref } from 'vue'
- import { checkAttendance, changePWD } from '@/api/mine.js'
- import config from '@/config.js'
- import $modal from '@/plugins/modal.js'
- import $tab from '@/plugins/tab.js'
- import { useUserStore } from '@/store/user.js'
- import { getLoginInfo } from '@/utils/auth'
- import { useConfigStore } from '@/store/config.js'
- import { onLoad } from '@dcloudio/uni-app'
- const userStore = useUserStore()
- const configStore = useConfigStore();
- const loginForm = ref({
- username: getLoginInfo().username || '',
- password: getLoginInfo().password || ''
- })
- function handleLogin() {
- const username = loginForm.value.username
- const password = loginForm.value.password
- if (username == '') {
- $modal.msgError("请输入您的账号")
- } else if (password == '') {
- $modal.msgError("请输入您的密码")
- } else {
- $modal.loading("登录中,请耐心等待...")
- // TEST: 测试登录接口
- userStore.Login(loginForm.value).then((res) => {
- if (loginForm.value.password == '123456') {
- changeOrgPWD(res.returnParams.useId)
- } else {
- $modal.closeLoading()
- loginSuccess()
- }
- })
- }
- }
- function changeOrgPWD(staffId) {
- $modal.editable('修改初始密码', '请输入大于6位的新密码', false).then((newpassword) => {
- if (newpassword < 99999) {
- $modal.syncAlert('密码需大于6位').then(() => {
- changeOrgPWD(staffId)
- })
- return
- }
- if (newpassword == '123456') {
- $modal.syncAlert('请勿使用123456作为密码').then(() => {
- changeOrgPWD(staffId)
- })
- return
- }
- const params = {
- staffId,
- oldpassword: loginForm.value.password,
- newpassword,
- }
- changePWD(params).then(res => {
- loginForm.value.password = newpassword
- $modal.showToast(res.returnMsg);
- if ("1" == res.returnCode) { //修改成功
- handleLogin()
- } else {
- changeOrgPWD(staffId)
- }
- })
- })
- }
- onLoad((options) => {
- //判断是否要自动登录
- if (options.type) {
- // console.log('autoLogin');
- handleLogin()
- }
- })
- function loginSuccess() {
- userStore.GetInfo().then(() => {
- // 是否在上班打卡时间段
- configStore.GetAttRule(userStore.user).then(() => {
- console.log('GetAttRule');
- let inTime = false;
- if(config.clock && config.clock == 'multiple'){
- inTime = isInTimeRange(...configStore.signInTimeRange[0]) || isInTimeRange(...configStore.signInTimeRange[1])
- }else{
- inTime = isInTimeRange(...configStore.signInTimeRange[0])
- }
- //if (isInTimeRange(...configStore.signInTimeRange)) {
- if (inTime) {
- const now = new Date()
- const params = {
- universalid: userStore.useId,
- rizi: (now.getFullYear()) + '-' + (now.getMonth() + 1) + '-' + (now.getDate())
- }
- // 获取当天考勤信息
- checkAttendance(params).then(({ returnParams }) => {
- if (returnParams.list.length) {
- // 已签到 跳转消息页
- $tab.reLaunch('/pages/message/index')
- } else {
- // 未签到 跳转考勤页面
- $tab.reLaunch('/pages/message/index?to=clockIn')
- }
- })
- } else {
- $tab.reLaunch('/pages/message/index')
- }
- }).catch((error) => {
- // console.log('GetAttRule error:', error);
- if (['getAttendanceSegmentErr', 'getAttendanceRuleErr'].includes(error)) {
- $tab.reLaunch('/pages/message/index')
- }
- });
- })
- }
- //判断时间是否在区间内
- function isInTimeRange(start, end) {
- // 获取当前时间戳
- const now = Date.now();
- // 获取当前日期
- const currentDate = new Date(now);
- const year = currentDate.getFullYear();
- const month = currentDate.getMonth();
- const day = currentDate.getDate();
- // 构建当天的起始时间和结束时间的时间戳
- const startTime = new Date(year, month, day, ...start.split(':').map(Number)).getTime();
- const endTime = new Date(year, month, day, ...end.split(':').map(Number)).getTime();
- // 判断当前时间是否在范围内
- return now >= startTime && now <= endTime;
- }
- </script>
- <style lang="scss">
- @import '@/static/font/iconfont.css';
- page {
- background-color: #ffffff;
- }
- .justify-center {
- justify-content: center;
- }
- .align-center {
- align-items: center;
- }
- .flex {
- display: flex;
- }
- view,
- scroll-view,
- swiper,
- button,
- input,
- textarea,
- label,
- navigator,
- image {
- box-sizing: border-box;
- }
- .normal-login-container {
- width: 100%;
- .logo-content {
- width: 100%;
- font-size: 21px;
- text-align: center;
- padding-top: 45%;
- image {
- border-radius: 4px;
- }
- .title {
- margin-left: 10px;
- }
- }
- .login-form-content {
- text-align: center;
- margin: 20px auto;
- margin-top: 15%;
- width: 80%;
- .input-item {
- margin: 20px auto;
- background-color: #f5f6f7;
- height: 45px;
- border-radius: 20px;
- .icon {
- font-size: 38rpx;
- margin-left: 10px;
- color: #999;
- }
- .input {
- width: 100%;
- line-height: 20px;
- text-align: left;
- padding-left: 15px;
- }
- }
- .action-btn {
- .login-btn {
- margin-top: 40px;
- height: 45px;
- border-radius: 20px;
- }
- .login-btn::after {
- border: 0px;
- border-radius: 20px;
- }
- .cu-btn.block {
- display: flex;
- }
- .cu-btn.lg {
- padding: 0 40rpx;
- font-size: 32rpx;
- }
- .bg-blue {
- background-color: #0081ff;
- color: #ffffff;
- }
- .cu-btn {
- position: relative;
- border: 0rpx;
- display: inline-flex;
- align-items: center;
- justify-content: center;
- box-sizing: border-box;
- line-height: 1;
- text-align: center;
- text-decoration: none;
- overflow: visible;
- margin-left: initial;
- transform: translate(0rpx, 0rpx);
- margin-right: initial;
- }
- }
- }
- }
- </style>
|