123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 |
- import { defineStore } from "pinia";
- import { doorApi } from "@/api/business/door.js";
- import { faceApi } from "@/api/business/face.js";
- import { meetingApi, signOnOut } from "@/api/business/meeting.js";
- import { getToken, setToken, removeToken } from "@/utils/auth";
- import dayjs from 'dayjs'
- import config from "@/config";
- import tab from "@/plugins/tab.plugins";
- import nfc from "@/plugins/nfc.plugins.js";
- import modal from "@/plugins/modal.plugins.js";
- import keyListen from "@/plugins/keyListen.plugins.js";
- import permission from "@/plugins/permission.plugins.js";
- const controlStore = defineStore("control", {
- state: () => ({
- pageFunction: [], //被包含的功能
- isClicked: false, //按钮是否被点击
- form: {
- linkUrl: "",
- port: "",
- domain: undefined,
- doorList: {
- id: undefined,
- name: undefined,
- },
- },
- modal: {
- show: false,
- },
- picker: {
- show: false,
- title: "",
- list: [[]],
- defaultIndex: 0,
- },
- subsection: {
- list: ["服务器配置", "其它配置", "系统设置"],
- value: 0,
- },
- doooList: [],
- meetingDoorList: [],
- meetingRoomList: [],
- meetingTimeList: [],
- meetingReservaList: {
- dataAll: {},
- thisVenueData: [],
- thisVenueTime: {},
- nextSceneData: [],
- nextSceneTime: {},
- timeList: [],
- },
- }),
- actions: {
- /**
- * @初始化缓存数据
- */
- initData() {
- var that = this
- var storage = uni.getStorageSync("storage_face");
- if (storage) {
- config.baseUrl = "http://" + storage.domain + "/prod-api";
- that.form.domain = storage.domain;
- that.form.linkUrl = storage.linkUrl.indexOf(":") != -1 ? storage.linkUrl.split(":")[0] : storage.linkUrl;
- that.form.port = storage.port ? storage.port : "";
- that.form.meetingId = storage.meetingId || undefined;
- that.form.meetingName = storage.meetingName || undefined;
- that.form.doorList = {
- id: storage.doorList.id || undefined,
- name: storage.doorList.name || undefined,
- }
- }
- },
- /**
- * @初始化摄像头
- */
- initCamera() {
- var that = this
- //#ifdef APP-PLUS
- permission.getPermisson("camera").then((res) => {
- res ? that.handleChildren({ funcName: "开启摄像头", data: {} }) : "";
- });
- //#endif
- },
- /**
- * @初始化NFC
- */
- initNfc() {
- var that = this
- //#ifdef APP-PLUS
- nfc.initNFC();
- nfc.readNFC().then((e) => {
- that.openDoor();
- that.initNfc();
- });
- //#endif
- },
- /**
- * @初始化事件
- */
- initHandle() {
- this.handleChildren({ funcName: "初始化事件", data: {} })
- },
- /**
- * @弹窗确定按钮事件
- */
- modalConfirm(rules) {
- if (!this.form.linkUrl) {
- modal.msg("请输入链接地址");
- return;
- }
- if (!/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}(?:\.[a-zA-Z0-9]{2,})+$/.test(this.form.linkUrl)) {
- modal.msg("请输入正确的链接地址");
- return;
- }
- if (!this.form.meetingName && this.pageFunction.includes('会议')) {
- modal.msg("请选择绑定会议室");
- return;
- }
- if (!this.form.doorList.name && this.pageFunction.includes('门禁')) {
- modal.msg("请选择绑定门禁");
- return;
- }
- uni.setStorageSync("storage_face", this.form);
- this.modalClose();
- },
- /**
- * @弹窗退出按钮事件
- */
- modalCancel() {
- this.modal.show = false;
- //#ifdef APP-PLUS
- keyListen.quitApp();
- //#endif
- },
- /**
- * @弹窗关闭事件
- */
- modalClose() {
- this.handleChildren({ funcName: "开启摄像头", data: {} });
- this.modal.show = false;
- },
- /**
- * @section回调事件
- */
- sectionChange(e) {
- if (e == 1) {
- if (!this.form.linkUrl) {
- modal.msg("请输入链接地址");
- return;
- }
- if (!/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}(?:\.[a-zA-Z0-9]{2,})+$/.test(this.form.linkUrl)) {
- modal.msg("请输入正确的链接地址");
- return;
- }
- var domain = "";
- if (this.form.linkUrl) {
- domain = this.form.linkUrl;
- if (this.form.port) {
- domain += ":" + this.form.port;
- }
- }
- this.form.domain = domain;
- config.baseUrl = "http://" + this.form.domain + "/prod-api";
- if (this.pageFunction.includes('会议')) {
- this.getMeetingRoomList();
- }
- if (this.pageFunction.includes('门禁')) {
- this.getdoorList();
- }
- }
- this.subsection.value = e;
- },
- /**
- * @action弹出框点击事件
- */
- handlePicker(value, index, ind) {
- if (value == "绑定会议室") {
- this.picker.title = "绑定会议室";
- this.picker.list = [this.meetingRoomList];
- this.picker.defaultIndex = 0;
- } else if (value == "绑定门禁") {
- this.picker.title = "绑定门禁";
- this.picker.list = [this.doooList];
- this.picker.defaultIndex = 0;
- }
- this.picker.show = true;
- },
- /**
- * @action弹出框选择事件
- */
- pickerConfirm(e) {
- if (this.picker.title == "绑定会议室") {
- this.form.meetingId = e.value[0].value;
- this.form.meetingName = e.value[0].name;
- } else if (this.picker.title == "绑定门禁") {
- this.form.doorList.id = e.value[0].value;
- this.form.doorList.name = e.value[0].name;
- }
- this.picker.show = false;
- },
- /**
- * @会议室下拉列表
- */
- getMeetingRoomList() {
- var that = this
- that.meetingRoomList = [];
- meetingApi()
- .GetMeetingRoomList({
- domain: that.form.domain,
- })
- .then((requset) => {
- if (requset.data.length > 0) {
- requset.data.forEach((e) => {
- that.meetingRoomList.push({
- value: e.roomId,
- name: e.roomName,
- });
- });
- }
- });
- },
- /**
- * @门禁下拉列表
- */
- getdoorList() {
- doorApi()
- .Select({
- current: 1, //页数
- size: 2000, //条数
- domain: this.form.domain, //域名
- })
- .then((requset) => {
- if (requset.data.records.length > 0) {
- requset.data.records.forEach((e) => {
- this.doooList.push({
- value: e.deviceUuid,
- name: e.deviceName,
- });
- });
- }
- });
- },
- /**
- * @门禁开门
- */
- openDoor(event) {
- var that = this
- if (this.isClicked) {
- modal.msg("请勿重复点击!");
- return;
- } else {
- this.isClicked = true;
- }
- doorApi()
- .control({
- domain: !getToken() ? this.form.domain : undefined, //域名
- userId: !getToken() ? event.userId : undefined,
- userName: !getToken() ? event.userName : undefined,
- productCode: "502_USKY",
- deviceUuid: !getToken() ? this.form.doorList.id : event.deviceUuid,
- commandCode: "door_onoff",
- commandValue: 1,
- })
- .then((item) => {
- modal.msg("开门成功");
- setTimeout(() => {
- this.isClicked = false;
- }, 2000);
- that.insertDoorRecord(event, "成功");
- })
- .catch((err) => {
- console.log(err);
- setTimeout(() => {
- this.isClicked = false;
- }, 2000);
- that.insertDoorRecord(event, "失败:" + err);
- });
- },
- /**
- * @新增开门记录
- */
- insertDoorRecord(event, msg) {
- doorApi()
- .RecordInsert({
- domain: !getToken() ? this.form.domain : undefined, //域名
- userName: event.userName, //用户姓名
- deviceUuid: !getToken() ? this.form.doorList.id : event.deviceUuid,//设备Uuid
- passType: 3, //通行方式(1、人脸 2、刷卡 3、手机)
- passTime: dayjs().format("YYYY-MM-DDTHH:mm:ss"), //通行时间
- passResult: msg, //通行结果
- })
- .then((item) => {
- console.log(msg);
- })
- .catch((err) => {
- console.log(err);
- });
- },
- /**
- * @人脸验证
- */
- faceVerify(imageBase) {
- var that = this
- faceApi()
- .faceVef({
- domain: that.form.domain,
- imageBase: imageBase,
- })
- .then((item) => {
- if (item.data.code === 200 || item.data.code === 201) {
- item.data.userName = item.data.faceName;
- if (that.pageFunction.includes('会议')) {
- that.meetingVerify(item.data);
- } else {
- that.openDoor(item.data);
- }
- }
- if (item.data.msg != "人脸验证接口返回异常") {
- modal.msg(item.data.msg);
- }
- that.handleChildren({ funcName: "人脸冷却", data: {} });
- })
- .catch((err) => {
- that.handleChildren({ funcName: "人脸冷却", data: {} });
- });
- },
- /**
- * @会议验证
- */
- meetingVerify(event) {
- var that = this
- if (that.meetingReservaList.thisVenueData.length > 0) {
- meetingApi()
- .Attendee({
- domain: this.form.domain,
- meetingId: this.meetingReservaList.thisVenueData[0].meetingId,
- userId: event.userId,
- userName: event.userName,
- })
- .then((item) => {
- if (item.data.status == "1") {
- that.openDoor(event);
- that.meetingSign(event);
- }
- modal.msg(item.data.msg);
- });
- }
- },
- /**
- * @会议签到
- */
- meetingSign(event) {
- signOnOut({
- domain: this.form.domain,
- meetingId: this.meetingReservaList.thisVenueData[0].meetingId,
- userId: event.userId, //参会人Id
- mothodType: 0, //签到签退类别(0.签到 1.签退)
- signType: 1, //签到签退方式(0.人工 1.人脸)
- }).then((item) => { });
- },
- /**
- * @解析父页面传回的数据
- */
- analysisData(event) {
- if ("funcName" in event) {
- if (event.funcName == "打开配置") {
- this.handleChildren({ funcName: "关闭摄像头", data: {} });
- tab.navigateTo("/pages/door/setting/index")
- // this.modal.show = true;
- } else if (event.funcName == "人脸识别") {
- this.faceVerify(event.data.imageBase);
- } else if (event.funcName == "点击开门") {
- this.openDoor({
- userId: 99,
- userName: "方惠圣",
- });
- }
- }
- },
- /**
- * @向子页面发送数据
- */
- handleChildren(data) {
- // #ifdef APP-PLUS
- var pages = getCurrentPages();
- var currentWebview = pages[pages.length - 1].$getAppWebview();
- var wv = currentWebview.children()[0];
- wv.evalJS(`receiveData(${JSON.stringify(data)})`);
- // #endif
- // #ifdef H5
- var iframe = document.getElementById("faceView");
- iframe.contentWindow.postMessage(data, "*");
- // #endif
- }
- },
- });
- export default controlStore;
|