1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

创建新的小程序,进出码,体温上报功能迁移基本完成

This commit is contained in:
2023-03-17 04:55:02 +08:00
parent 5b98be9bf9
commit b7bf3bfc15
88 changed files with 4337 additions and 276 deletions

View File

@@ -0,0 +1,12 @@
module.exports = {
user: {
role: {
ADMIN: 0,
STAFF: 1,
RESIDENTS_OWNER: 2,
RESIDENTS_MEMBER: 3,
RESIDENTS_TENENT: 4,
VISITOR: 5
}
}
}

View File

@@ -0,0 +1,29 @@
const ENUM = require('./const.js');
function getUserGroupByRole(userRole) {
const role = ENUM.user.role;
userRole = Number(userRole);
let userGroupDict = {
'visitor': [
role.VISITOR,
].includes(userRole),
'user': [
role.RESIDENTS_OWNER,
role.RESIDENTS_MEMBER,
role.RESIDENTS_TENENT,
].includes(userRole),
'admin': [
role.ADMIN,
role.STAFF,
].includes(userRole)
}
console.log("userGroupDict", userGroupDict, userRole, role)
for (let userGroup of Object.keys(userGroupDict)) {
if (userGroupDict[userGroup]) {
return userGroup;
}
}
return 'unknown';
}
module.exports = getUserGroupByRole;

View File

@@ -0,0 +1,104 @@
const switchTab = "switchTab";
const navigateTo = "navigateTo";
let id = 0;
let menuItemDict = {
'login': {
for: ['unknown'],
title: "登录",
image: "code.png",
switchFunc: switchTab,
url: '/pages/index/login',
},
'code': {
for: ['visitor', 'user'],
title: "进出码",
image: "code.png",
switchFunc: switchTab,
url: '/pages/residents/code'
},
'report': {
for: ['user'],
title: "体温上报",
image: "report.png",
switchFunc: switchTab,
url: '/pages/residents/report'
},
'apply-record': {
for: ['visitor', 'user'],
title: "申请记录",
image: "apply.png",
switchFunc: switchTab,
url: ''
},
'apply-approval': {
for: ['admin'],
title: "申请审批",
image: "apply.png", // ApplyReplay
switchFunc: switchTab,
url: ''
},
'visitor-apply': {
for: ['admin'],
title: "访客审批",
image: "visitor.png",
switchFunc: switchTab,
url: ''
},
'abnormal': {
for: ['admin'],
title: "异常人员",
image: "danger.png",
switchFunc: switchTab,
url: ''
},
'feedback-submit': {
for: ['visitor', 'user'],
title: "提交反馈",
image: "fk.png",
switchFunc: switchTab,
url: ''
},
'feedback-list': {
for: ['visitor', 'user'],
title: "反馈查看",
image: "feedback.png",
switchFunc: switchTab,
url: ''
},
'feedback-reply': {
for: ['admin'],
title: "反馈回复",
image: "feedback.png",
switchFunc: switchTab,
url: ''
},
'update-password': {
for: ['user', 'admin'],
title: "密码修改",
image: "updPwd.png",
switchFunc: switchTab,
url: ''
},
'assign': {
for: ['admin'],
title: "分配账号",
image: "count.png",
switchFunc: switchTab,
url: ''
},
'unfinish': {
for: ['admin'],
title: "今日未填", // RedList
image: "_report.png",
switchFunc: switchTab,
url: ''
}
}
let keys = Object.keys(menuItemDict);
for (let key of keys) {
menuItemDict[key].id = id++;
menuItemDict[key].addDot = false;
}
module.exports = menuItemDict

View File

@@ -0,0 +1,128 @@
// import extend from 'extend'
import {
QRCode,
QRErrorCorrectLevel
} from './qrcode'
// support Chinese
function utf16to8(str) {
var out, i, len, c
out = ''
len = str.length
for (i = 0; i < len; i++) {
c = str.charCodeAt(i)
if ((c >= 0x0001) && (c <= 0x007F)) {
out += str.charAt(i)
} else if (c > 0x07FF) {
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F))
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F))
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F))
} else {
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F))
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F))
}
}
return out
}
function drawQrcode(Taro, opt) {
let defaultOpt = {
canvasId: 'myQrcode',
canvas: null,
text: '爱一个人就要勇敢说出来',
width: 260,
padding: 20,
paddingColor: null, // 默认与background一致
typeNumber: -1,
correctLevel: QRErrorCorrectLevel.H,
background: '#ffffff',
foreground: '#000000',
image: {
imageResource: '',
width: 80,
height: 80,
round: true
}
}
let options = defaultOpt
for (let key in opt) {
options[key] = opt[key]
}
if (!options.canvasId && !options.canvas) {
console.warn('please set canvasId or canvas!')
return
}
if (!options.paddingColor) options.paddingColor = options.background
// createCanvas
// create the qrcode itself
var qrcode = new QRCode(options.typeNumber, options.correctLevel)
qrcode.addData(utf16to8(options.text))
qrcode.make()
const dpr = Taro.getSystemInfoSync().pixelRatio
var canvas = options.canvas
const ctx = canvas.getContext('2d')
canvas.width = options.width * dpr
canvas.height = options.width * dpr
const width = canvas.width
console.log(`canvas, ctx, width, dpr, qrcode, options`, canvas, ctx, width, dpr, qrcode, options)
// 填充背景色
ctx.fillStyle = options.paddingColor
// ctx.clearRect(0, 0, width + options.padding * 2, width + options.padding * 2) // 绘制前清空画布
ctx.fillRect(0, 0, width + options.padding * 2, width + options.padding * 2);
var tileW = (width - options.padding * 2) / qrcode.getModuleCount()
var tileH = (width - options.padding * 2) / qrcode.getModuleCount()
// 绘制二维码
for (var row = 0; row < qrcode.getModuleCount(); row++) {
for (var col = 0; col < qrcode.getModuleCount(); col++) {
ctx.fillStyle = qrcode.isDark(row, col) ? options.foreground : options.background
var w = (Math.ceil((col + 1) * tileW) - Math.floor(col * tileW))
var h = (Math.ceil((row + 1) * tileW) - Math.floor(row * tileW))
ctx.fillRect(Math.round(col * tileW) + options.padding, Math.round(row * tileH) + options.padding, w, h);
}
}
// 绘制中心图标
if (options.image.imageResource) {
const imgW = options.image.width * dpr
const imgH = options.image.height * dpr
const dx = (width - imgW) / 2
const dy = (width - imgH) / 2
if (options.image.round) {
// Logo边框
const imgW2 = options.image.width * dpr + 30
const dx2 = (width - imgW2) / 2
const r2 = imgW2 / 2
const cx2 = dx2 + r2;
ctx.beginPath();
ctx.arc(cx2, cx2, r2, 0, 2 * Math.PI);
ctx.fillStyle = '#ffffff'
ctx.fill();
ctx.restore();
// 画Logo
const r = imgW / 2
const cx = dx + r;
const cy = dy + r;
ctx.beginPath();
ctx.arc(cx, cy, r, 0, 2 * Math.PI);
ctx.clip();
ctx.drawImage(options.image.imageResource, dx, dy, imgW, imgW);
ctx.restore();
} else {
ctx.drawImage(options.image.imageResource, dx, dy, imgW, imgH)
ctx.restore();
}
}
return ctx
}
export default drawQrcode

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
https://github.com/DoctorWei/weapp-qrcode-canvas-2d

View File

@@ -0,0 +1,25 @@
function scanQRCode(Taro) {
// 只允许从相机扫码
Taro.scanCode({
onlyFromCamera: true,
success(res) {
console.log(res)
if (res.scanType == "WX_CODE" && res.path) {
let searchParams = res.path.split('?');
if (searchParams.length > 1 && searchParams[1].startsWith('scene=guard')) {
Taro.navigateTo({
url: "/pages/scan/entrance"
})
return
}
}
Taro.showToast({
title: "您扫描的不是门禁码",
icon: 'error',
duration: 2000
})
}
})
}
module.exports = scanQRCode;

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,27 @@
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}
const formatDate = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
return [year, month, day].map(formatNumber).join('-')
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : `0${n}`
}
module.exports = {
formatTime
}