Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
wangxiaolu-promotion-wechat
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
sfa
wangxiaolu-promotion-wechat
Commits
22bc9a1e
提交
22bc9a1e
authored
11月 05, 2024
作者:
lidongxu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
把获取用户地理位置封装到 store 中的 map.js 中
上级
33a53258
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
203 行增加
和
55 行删除
+203
-55
index.js
api/attendance/index.js
+17
-1
login.js
api/login.js
+12
-12
index.vue
pages/attendance/index.vue
+99
-16
index.vue
pages/index.vue
+11
-21
getters.js
store/getters.js
+14
-1
index.js
store/index.js
+5
-3
map.js
store/modules/map.js
+41
-0
user.js
store/modules/user.js
+1
-0
constant.js
utils/constant.js
+3
-1
没有找到文件。
api/attendance/index.js
浏览文件 @
22bc9a1e
...
...
@@ -3,9 +3,24 @@ import request from '@/utils/request.js'
/**
* 获取考勤规则详情
* @param {*} ruleId 考勤规则 ID
* @returns
*/
export
const
getAttendanceDetail
=
(
ruleId
)
=>
{
export
const
getAttendanceDetail
API
=
(
ruleId
)
=>
{
return
request
({
url
:
`/system/kq_rule/
${
ruleId
}
`
})
}
/**
* 考勤打卡
* @param {*} data
* @returns
*/
export
const
addAttendanceAPI
=
(
data
)
=>
{
return
request
({
url
:
'/operation/kqmx/core'
,
method
:
'post'
,
data
})
}
\ No newline at end of file
api/login.js
浏览文件 @
22bc9a1e
...
...
@@ -18,16 +18,16 @@ export function login(username, password, code, uuid) {
})
}
// 注册方法
export
function
register
(
data
)
{
return
request
({
url
:
'/auth/register'
,
headers
:
{
isToken
:
false
},
method
:
'post'
,
data
:
data
})
// 注册方法
export
function
register
(
data
)
{
return
request
({
url
:
'/auth/register'
,
headers
:
{
isToken
:
false
},
method
:
'post'
,
data
:
data
})
}
// 获取用户详细信息
...
...
@@ -42,7 +42,7 @@ export function getInfo() {
export
function
logout
()
{
return
request
({
'url'
:
'/auth/logout'
,
'method'
:
'
post
'
'method'
:
'
DELETE
'
})
}
...
...
@@ -56,4 +56,4 @@ export function getCodeImg() {
method
:
'get'
,
timeout
:
20000
})
}
}
pages/attendance/index.vue
浏览文件 @
22bc9a1e
...
...
@@ -2,27 +2,60 @@
<view
class=
"wrap"
>
<div
class=
"button_wrap"
>
<button
v-for=
"obj in attTimeKeyList"
:class=
"obj.disabled ? 'workbtn_disabled' : obj.class"
:disabled=
"obj.disabled"
>
{{
obj
.
title
}}
</button>
:disabled=
"obj.disabled"
@
click=
"attendanceClickFn(obj.type)"
>
{{
obj
.
title
}}
</button>
</div>
<uni-list
class=
"list_wrap"
>
<uni-list-item>
<template
v-slot:header
>
<span>
2024-11-04 星期一
</span>
</
template
>
<!-- 自定义 body -->
<
template
v-slot:body
>
<div
class=
"item_body"
>
<div
class=
"item"
>
<text
class=
"time"
>
09:05:20
</text>
<text
class=
"title"
>
上班打卡
</text>
</div>
<div
class=
"item"
>
<text
class=
"time"
>
09:05:20
</text>
<text
class=
"title"
>
午班打卡
</text>
</div>
<div
class=
"item"
>
<text
class=
"time"
>
09:05:20
</text>
<text
class=
"title"
>
下班打卡
</text>
</div>
</div>
</
template
>
</uni-list-item>
</uni-list>
</view>
</template>
<
script
>
import
{
getAttendanceDetail
}
from
'@/api/attendance'
import
{
getAttendanceDetail
API
,
addAttendanceAPI
}
from
'@/api/attendance'
import
{
checkStartLessEndTime
}
from
'@/utils/common'
export
default
{
data
()
{
return
{
attTimeKeyList
:
[{
// 需要考勤列表
attTimeKeyList
:
[]
}
},
created
()
{
this
.
getRuleInfo
()
},
methods
:
{
// 获取考勤规则详情
async
getRuleInfo
()
{
const
list
=
[{
// 需要考勤列表
beginKey
:
'firBegintime'
,
beginValue
:
''
,
endKey
:
'firEndtime'
,
endValue
:
''
,
class
:
'go_work'
,
title
:
'上班打卡'
,
disabled
:
false
// 是否可以交互
disabled
:
false
,
// 是否可以交互
type
:
'begin'
,
// 考勤类型
},
{
beginKey
:
'secBegintime'
,
...
...
@@ -31,7 +64,8 @@ export default {
endValue
:
''
,
class
:
'after_work'
,
title
:
'午班打卡'
,
disabled
:
false
disabled
:
false
,
type
:
'after'
,
},
{
beginKey
:
'thiBegintime'
,
...
...
@@ -40,22 +74,45 @@ export default {
endValue
:
''
,
class
:
'off_work'
,
title
:
'下班打卡'
,
disabled
:
false
disabled
:
false
,
type
:
'off'
,
}]
}
},
created
()
{
this
.
getRuleInfo
()
},
methods
:
{
async
getRuleInfo
()
{
// 需要提取打卡的时间
const
{
data
}
=
await
getAttendanceDetail
(
this
.
$store
.
getters
.
user
.
ruleId
)
this
.
attTimeKeyList
.
forEach
(
obj
=>
{
const
{
data
}
=
await
getAttendanceDetailAPI
(
this
.
$store
.
getters
.
user
.
ruleId
)
for
(
let
i
=
0
;
i
<
list
.
length
;
i
++
)
{
const
obj
=
list
[
i
]
if
(
!
data
[
obj
.
beginKey
])
{
// 如果打卡开始时间是空的(例如:有的人没有午班打卡,则删除数据结构中的一项)
list
.
splice
(
i
,
1
)
i
--
continue
}
obj
[
'beginValue'
]
=
data
[
obj
.
beginKey
]
obj
[
'endValue'
]
=
data
[
obj
.
endKey
]
// 判断服务器时间
obj
[
'disabled'
]
=
checkStartLessEndTime
(
data
[
obj
.
endKey
],
data
.
currently
)
}
this
.
attTimeKeyList
=
list
},
// 考勤打卡
async
attendanceClickFn
(
type
)
{
const
attendanceType
=
{
'begin'
:
1
,
'after'
:
2
,
'off'
:
3
// 前端考勤类型,对应后端数字代表考勤类型
}
await
addAttendanceAPI
({
"kqLocal"
:
[
100.111
,
99.333
],
"kqProvinc"
:
"内蒙古自治区"
,
"kqCity"
:
"呼和浩特市"
,
"kqCounty"
:
"新城区"
,
"kqAddress"
:
"第一街道66号"
,
"kqPicurl"
:
"https://www.baidu.com"
,
"kqType"
:
3
})
}
}
...
...
@@ -66,6 +123,8 @@ export default {
.wrap
{
background-color
:
#f0f1f3
;
height
:
100vh
;
display
:
flex
;
flex-direction
:
column
;
.button_wrap
{
display
:
flex
;
...
...
@@ -73,6 +132,7 @@ export default {
justify-content
:
center
;
align-items
:
center
;
gap
:
50rpx
;
padding
:
50rpx
0
;
.go_work
,
.after_work
,
...
...
@@ -106,6 +166,29 @@ export default {
}
}
.list_wrap
{
::v-deep
.uni-list-item__container
{
display
:
block
!
important
;
}
.item_body
{
display
:
flex
;
justify-content
:
space-between
;
padding-top
:
24rpx
;
.item
{
display
:
flex
;
flex-direction
:
column
;
.time
{
color
:
#d9572c
;
}
.title
{
font-size
:
24rpx
;
}
}
}
}
}
</
style
>
pages/index.vue
浏览文件 @
22bc9a1e
...
...
@@ -65,30 +65,20 @@
</
template
>
<
script
>
import
{
reverseGeocoding
}
from
'@/api/common'
export
default
{
onLoad
:
function
()
{
},
methods
:
{
addendanceClick
()
{
// getLocation 获取经纬度
// chooseLocation 让用户在地图手选位置
uni
.
getLocation
({
success
:
async
(
res
)
=>
{
const
result
=
await
reverseGeocoding
({
params
:
{
location
:
res
.
latitude
+
","
+
res
.
longitude
}
})
// 判断用户位置和获取位置-城市是否一致
if
(
result
.
result
.
addressComponent
.
city
.
startsWith
(
this
.
$store
.
getters
.
user
.
workCityName
))
{
// 跳转到打卡页面
this
.
$tab
.
navigateTo
(
'/pages/attendance/index'
)
}
else
{
// 不一致,提示
this
.
$modal
.
msgError
(
"工作地点与定位地点不同"
);
}
}
})
async
addendanceClick
()
{
const
result
=
await
this
.
$store
.
getters
.
location
// 判断用户位置和获取位置-城市是否一致
if
(
result
.
result
.
addressComponent
.
city
.
startsWith
(
this
.
$store
.
getters
.
user
.
workCityName
))
{
// 跳转到打卡页面
this
.
$tab
.
navigateTo
(
'/pages/attendance/index'
)
}
else
{
// 不一致,提示
this
.
$modal
.
msgError
(
"工作地点与定位地点不同"
);
}
}
}
...
...
store/getters.js
浏览文件 @
22bc9a1e
import
store
from
'@/store'
const
getters
=
{
token
:
state
=>
state
.
user
.
token
,
avatar
:
state
=>
state
.
user
.
avatar
,
...
...
@@ -5,6 +6,18 @@ const getters = {
name
:
state
=>
state
.
user
.
name
,
roles
:
state
=>
state
.
user
.
roles
,
permissions
:
state
=>
state
.
user
.
permissions
,
delayTime
:
state
=>
3000
// 延迟弹窗关闭时间
delayTime
:
state
=>
3000
,
// 延迟弹窗关闭时间
location
:
(
state
)
=>
{
// 发现有则返回,没有则获取并赋予
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
if
(
state
.
map
.
location
)
{
resolve
(
state
.
map
.
location
)
}
else
{
const
location
=
await
store
.
dispatch
(
'GetLocation'
)
state
.
map
.
location
=
location
resolve
(
location
)
}
})
}
}
export
default
getters
store/index.js
浏览文件 @
22bc9a1e
import
Vue
from
'vue'
import
Vuex
from
'vuex'
import
user
from
'@/store/modules/user'
import
map
from
'@/store/modules/map'
import
getters
from
'./getters'
Vue
.
use
(
Vuex
)
const
store
=
new
Vuex
.
Store
({
modules
:
{
user
user
,
map
},
getters
getters
})
export
default
store
export
default
store
store/modules/map.js
0 → 100644
浏览文件 @
22bc9a1e
import
storage
from
'@/utils/storage'
import
constant
from
'@/utils/constant'
import
{
reverseGeocoding
}
from
'@/api/common'
const
location
=
{
state
:
{
// 包括手机系统经纬度+省市区名字等信息
location
:
storage
.
get
(
constant
.
location
)
},
mutations
:
{
SET_LOCATION
:
(
state
,
location
)
=>
{
state
.
location
=
location
storage
.
set
(
constant
.
location
,
location
)
}
},
actions
:
{
// 获取本机位置信息
GetLocation
({
commit
})
{
// getLocation 获取经纬度
// chooseLocation 让用户在地图手选位置
return
new
Promise
((
resolve
,
reject
)
=>
{
uni
.
getLocation
({
success
:
async
(
res
)
=>
{
// 经纬度调 百度 逆地理编码获取省市区名字
const
result
=
await
reverseGeocoding
({
params
:
{
location
:
res
.
latitude
+
","
+
res
.
longitude
}
})
commit
(
'SET_LOCATION'
,
result
)
resolve
(
result
)
}
})
})
},
}
}
export
default
location
store/modules/user.js
浏览文件 @
22bc9a1e
...
...
@@ -90,6 +90,7 @@ const user = {
commit
(
'SET_TOKEN'
,
''
)
commit
(
'SET_ROLES'
,
[])
commit
(
'SET_PERMISSIONS'
,
[])
commit
(
'SET_USER'
,
{})
removeToken
()
storage
.
clean
()
resolve
()
...
...
utils/constant.js
浏览文件 @
22bc9a1e
...
...
@@ -3,7 +3,9 @@ const constant = {
name
:
'vuex_name'
,
roles
:
'vuex_roles'
,
permissions
:
'vuex_permissions'
,
user
:
'vuex_user'
user
:
'vuex_user'
,
// 地理相关
location
:
'vuex_location'
}
export
default
constant
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论