Fix ws and device page

This commit is contained in:
Mr Swift
2024-08-23 23:30:45 +03:30
parent b974644989
commit d91bc5beba
12 changed files with 322 additions and 30 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
*.xlsx
# Created by .ignore support plugin (hsz.mobi) # Created by .ignore support plugin (hsz.mobi)
### Node template ### Node template
# Logs # Logs
+3 -1
View File
@@ -339,10 +339,12 @@
:exact="false" :exact="false"
:badge="pendingUsers ? { text: pendingUsers, color: 'danger' } : null" :badge="pendingUsers ? { text: pendingUsers, color: 'danger' } : null"
/> />
<CSidebarNavItem <CSidebarNavItem
v-if="hasPermission('gps')" v-if="hasPermission('gps')"
name="دستگاه ها" name="دستگاه ها"
:to="{ name: 'admin-admins-admin', params: { admin: 'new' } }" :to="{ name: 'admin-gps-device' }"
font-icon="fal fa-microchip" font-icon="fal fa-microchip"
:exact="false" :exact="false"
/> />
+6
View File
@@ -58,6 +58,12 @@ export default {
this.$store.commit('admin/set', ['newOldPieceRequests', data.newOldPieceRequests]) this.$store.commit('admin/set', ['newOldPieceRequests', data.newOldPieceRequests])
this.$store.commit('admin/set', ['newBufferRequests', data.newBufferRequests]) this.$store.commit('admin/set', ['newBufferRequests', data.newBufferRequests])
this.$store.commit('admin/set', ['newGuaranteeReports', data.newGuaranteeReports]) this.$store.commit('admin/set', ['newGuaranteeReports', data.newGuaranteeReports])
this.$store.commit('admin/set', ['newComplaintReports', data.newComplaintReports])
this.$store.commit('admin/set', ['newWithdrawRequest', data.newWithdrawRequest])
this.$store.commit('admin/set', ['pendingUsers', data.pendingUsers])
this.$store.commit('admin/set', ['newAwardRequest', data.newAwardRequest])
this.$store.commit('admin/set', ['newInstallDeviceRequest', data.newInstallDeviceRequest])
}) })
socket.on(`admin:notify`, data => { socket.on(`admin:notify`, data => {
+26
View File
@@ -28,6 +28,8 @@
"gsap": "^3.5.1", "gsap": "^3.5.1",
"jimp": "^0.16.1", "jimp": "^0.16.1",
"jquery": "^3.5.1", "jquery": "^3.5.1",
"js-file-download": "^0.4.12",
"json-as-xlsx": "^2.5.6",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"moment-jalaali": "^0.9.2", "moment-jalaali": "^0.9.2",
"mongoose": "^5.11.8", "mongoose": "^5.11.8",
@@ -2842,6 +2844,17 @@
"node": ">=10.0.0" "node": ">=10.0.0"
} }
}, },
"node_modules/@e965/xlsx": {
"version": "0.20.3",
"resolved": "https://registry.npmjs.org/@e965/xlsx/-/xlsx-0.20.3.tgz",
"integrity": "sha512-703RN/3OdsRD5mtse2HBX7Um7xwaP9tlswEG6svOtjqokXoX7rJdQj7DyabD2I+xk22RgaIIU+R6BHgkpZGB/w==",
"bin": {
"xlsx": "bin/xlsx.njs"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/@eslint-community/eslint-utils": { "node_modules/@eslint-community/eslint-utils": {
"version": "4.4.0", "version": "4.4.0",
"resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz",
@@ -12476,6 +12489,11 @@
"resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-2.2.1.tgz", "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-2.2.1.tgz",
"integrity": "sha512-HvdH2LzI/EAZcUwA8+0nKNtWHqS+ZmijLA30RwZA0bo7ToCckjK5MkGhjED9KoRcXO6BaGI3I9UIzSA1FKFPOQ==" "integrity": "sha512-HvdH2LzI/EAZcUwA8+0nKNtWHqS+ZmijLA30RwZA0bo7ToCckjK5MkGhjED9KoRcXO6BaGI3I9UIzSA1FKFPOQ=="
}, },
"node_modules/js-file-download": {
"version": "0.4.12",
"resolved": "https://registry.npmjs.org/js-file-download/-/js-file-download-0.4.12.tgz",
"integrity": "sha512-rML+NkoD08p5Dllpjo0ffy4jRHeY6Zsapvr/W86N7E0yuzAO6qa5X9+xog6zQNlH102J7IXljNY2FtS6Lj3ucg=="
},
"node_modules/js-tokens": { "node_modules/js-tokens": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
@@ -12509,6 +12527,14 @@
"node": ">=4" "node": ">=4"
} }
}, },
"node_modules/json-as-xlsx": {
"version": "2.5.6",
"resolved": "https://registry.npmjs.org/json-as-xlsx/-/json-as-xlsx-2.5.6.tgz",
"integrity": "sha512-z7phlB+VgS9wZv2N4SBKlguC3C7uauSj2PYSZICCrPaiu1lu8zkCpzZ4sOHWi0/3Je0CJl87q+J+3mpZbxpOew==",
"dependencies": {
"@e965/xlsx": "^0.20.0"
}
},
"node_modules/json-buffer": { "node_modules/json-buffer": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz",
+2
View File
@@ -35,6 +35,8 @@
"gsap": "^3.5.1", "gsap": "^3.5.1",
"jimp": "^0.16.1", "jimp": "^0.16.1",
"jquery": "^3.5.1", "jquery": "^3.5.1",
"js-file-download": "^0.4.12",
"json-as-xlsx": "^2.5.6",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"moment-jalaali": "^0.9.2", "moment-jalaali": "^0.9.2",
"mongoose": "^5.11.8", "mongoose": "^5.11.8",
+177
View File
@@ -0,0 +1,177 @@
<template>
<div>
<CustomSubHeader>
<CBreadcrumb class="border-0 mb-0"> دستگاه ها</CBreadcrumb>
<CButton size="sm" color="success" @click="download" class="mr-auto"
>خروجی اکسل</CButton
>
</CustomSubHeader>
<CRow>
<CCol xl="8">
<CCard>
<CCardBody>
<CRow>
<CCol xl="8">
<h3>اضافه کردن یا به روزرسانی با فایل اکسل</h3>
<el-divider></el-divider>
<input ref="file" type="file" class="d-block" />
<el-button type="success" class="mt-3" size="small" @click="post">افزودن</el-button>
</CCol>
<CCol xl="4">
<h3> دستور عمل </h3>
<el-divider></el-divider>
<p>
برای اضافه کردن دستگاه جدید فقط کافی است فایل نمونه رو دانلود کنید و به ترتیب مقادیر رو وارد کنید .
<br>
برای آپدیت یک مقدار باید خروجی اکسل گرفته و نسبت به IMEI ثبت شد مقادیر ان را تغییر دهید و با پسوند XLSX خروجی گرفته و آپلود کرده
</p>
<a
download
target="_blank"
title="برای دانلود کلیک کنید"
href="/example.xlsx"
style="color: blue; display: block; direction: ltr !important; text-align: right"
>
فایل نمونه
</a>
</CCol>
</CRow>
</CCardBody>
</CCard>
</CCol>
<CCol xl="4">
<CCard>
<CCardHeader>
<slot name="header">
<i class="fas fa-filter"></i>
<b>فیلتر ها</b>
</slot>
</CCardHeader>
<CCardBody>
<CRow>
<CCol sm="12">
<h4>جستجو در لیست:</h4>
<el-input
v-model="filterText"
clearable
placeholder=""
style="display: inline-block; max-width: 500px; margin-top: 8px"
></el-input>
</CCol>
</CRow>
</CCardBody>
</CCard>
</CCol>
</CRow>
<CCard>
<CCardHeader>
<slot name="header">
<CIcon name="cil-grid" />
دستگاه ها
</slot>
</CCardHeader>
<CCardBody>
<el-table :data="filteredItems" style="width: 100%">
<el-table-column type="index" label="#"> </el-table-column>
<el-table-column prop="model" label="مدل" width="150px"> </el-table-column>
<el-table-column prop="IMEI" label=" IMEI" width="150px"> </el-table-column>
<el-table-column prop="tomanPrice" label="قیمت دستگاه(تومان)" width=""> </el-table-column>
<el-table-column prop="dollarProfit" label="سود دلاری فروشنده" width=""> </el-table-column>
<el-table-column prop="score" label="امتیاز فروش" width=""> </el-table-column>
<el-table-column prop="renewalProfit" label="سود تمدید" width=""> </el-table-column>
<el-table-column prop="profit" label="سود تومانی فروشنده" width=""> </el-table-column>
<el-table-column label="وضعیت" width="">
<template slot-scope="scope">
<el-tag v-if="scope.row.status == 1" type="success">نصب شده</el-tag>
<el-tag v-else type="danger"> نصب نشده</el-tag>
</template>
</el-table-column>
</el-table>
</CCardBody>
</CCard>
</div>
</template>
<script>
import FileDownload from 'js-file-download'
export default {
name: 'AdminGpsDevicesList',
layout: 'admin',
async asyncData({ $axios, error, query }) {
try {
const { data } = await $axios.get('/api/admin/gps/device')
return {
devices: data
}
} catch (error) {
console.log(error)
}
},
data() {
return {
devices: [],
device: {},
filterText: ''
}
},
computed: {
config() {
return this.$config
},
filteredItems() {
const filterText = this.filterText
if (!this.filterText.length) return this.devices
else {
return this.devices.filter(item => {
return item.IMEI.includes(filterText) || item.model.includes(filterText)
})
}
}
},
methods: {
post() {
this.validation = {}
const data = new FormData()
data.append('file', this.$refs.file.files[0])
this.$axios
.post('/api/admin/gps/device/exel', data)
.then(res => {
console.log('🚀 ~ file: index.vue ~ line 108 ~ post ~ res', res)
this.$message({
type: 'success',
message: 'فایل با موفقیت ارسال شد'
})
this.$refs.file.value = null
this.$nuxt.refresh()
})
.catch(err => {
if (err.response.data.status === 401) {
return this.$message({
type: 'warning',
message: 'لطفا دوباره وارد حساب خود شوید'
})
}
if (err.response.status === 422) this.validation = err.response.data.validation
else console.log(err)
})
},
async download(){
const x = await this.$axios
.get('/api/admin/gps/device/exel')
FileDownload(x.data, 'device.csv');
}
}
}
</script>
+45 -2
View File
@@ -33,6 +33,30 @@
<CustomSubHeader> <CustomSubHeader>
<CBreadcrumb class="border-0 mb-0"> کاربران جی پی اس </CBreadcrumb> <CBreadcrumb class="border-0 mb-0"> کاربران جی پی اس </CBreadcrumb>
</CustomSubHeader> </CustomSubHeader>
<CCard>
<CCardHeader>
<slot name="header">
<i class="fas fa-filter"></i>
<b>فیلتر ها</b>
</slot>
</CCardHeader>
<CCardBody>
<CRow>
<CCol sm="12">
<h4>جستجو در لیست:</h4>
<el-input
v-model="filterText"
clearable
placeholder="نام - شماره موبایل - کد ملی - استان - شهر"
style="display: inline-block; max-width: 500px; margin-top: 8px"
></el-input>
</CCol>
</CRow>
</CCardBody>
</CCard>
<CCard> <CCard>
<CCardHeader> <CCardHeader>
<slot name="header"> <slot name="header">
@@ -42,7 +66,7 @@
</CCardHeader> </CCardHeader>
<CCardBody> <CCardBody>
<el-table :data="users" style="width: 100%"> <el-table :data="filteredItems" style="width: 100%">
<el-table-column type="index" label="#"> </el-table-column> <el-table-column type="index" label="#"> </el-table-column>
<el-table-column prop="first_name" label="نام" width="200px"> </el-table-column> <el-table-column prop="first_name" label="نام" width="200px"> </el-table-column>
@@ -96,7 +120,9 @@ export default {
return { return {
users: [], users: [],
centerDialogVisible: false, centerDialogVisible: false,
user: {} user: {},
filterText :''
} }
}, },
@@ -106,6 +132,23 @@ export default {
}, },
usersTypeList() { usersTypeList() {
return this.$route.query?.type return this.$route.query?.type
},
filteredItems() {
const filterText = this.filterText
if (!this.filterText.length) return this.users
else {
return this.users.filter(item => {
return (
item.first_name.includes(filterText) ||
item.last_name.includes(filterText) ||
item.mobile_number.includes(filterText) ||
item.national_code.includes(filterText) ||
item.province_name?.includes(filterText) ||
item.city_name?.includes(filterText) ||
(item.first_name + ' ' + item.last_name).includes(filterText)
)
})
}
} }
}, },
watch: { watch: {
+1 -1
View File
@@ -30,7 +30,7 @@
download download
target="_blank" target="_blank"
title="برای دانلود کلیک کنید" title="برای دانلود کلیک کنید"
:href="scope?.row.url + scope?.row.name" :href="scope?.row.url +'/'+ scope?.row.name"
style="color: blue; display: block; direction: ltr !important; text-align: right" style="color: blue; display: block; direction: ltr !important; text-align: right"
> >
{{ scope?.row.name }} {{ scope?.row.name }}
+55 -24
View File
@@ -1,10 +1,9 @@
const readXlsxFile = require('read-excel-file/node') const readXlsxFile = require('read-excel-file/node')
const validator = require('validator')
const { body, param, validationResult } = require('express-validator'); const { body, param, validationResult } = require('express-validator');
const xlsx = require("json-as-xlsx")
const { _sr } = require('../plugins/serverResponses'); const { _sr } = require('../plugins/serverResponses');
const { checkValidations, res500 } = require('../plugins/controllersHelperFunctions'); const { checkValidations, res500 } = require('../plugins/controllersHelperFunctions');
const Device = require('../models/GPS.Device'); const Device = require('../models/GPS.Device');
module.exports.addCode = [ module.exports.addCode = [
[ [
body('model').notEmpty().isString().withMessage(_sr.fa.required.name), body('model').notEmpty().isString().withMessage(_sr.fa.required.name),
@@ -55,25 +54,48 @@ module.exports.importExel = async (req, res) => {
module.exports.getAll = [ module.exports.getAll = [
async (req, res) => { async (req, res) => {
let page;
let rows; const data = await Device.find().sort({ created_at: -1 })
if (!req.query?.rows) { res.status(200).json(data)
rows = 10 }
} else { ]
rows = req.query.rows
module.exports.downloadAll = [
async (req, res) => {
const device = await Device.find().sort({ created_at: -1 })
const data = [
{
sheet: "device",
columns: [
{ label: "IMEI", value: "IMEI" },
{ label: "مدل", value: "model" },
{ label: "قیمت به تومان", value: "tomanPrice" },
{ label: "سود به دلار", value: "dollarProfit" },
{ label: "سود به تومان", value: "profit" },
{ label: "امتیاز", value: "score" },
{ label: "سود از تمدید", value: "renewalProfit" },
{ label: "وضعیت نصب", value: "status" },
],
content: device,
}
]
const settings = {
writeOptions: {
type: "buffer",
bookType: "csv",
},
RTL: true
} }
if (!req.query?.page) { setTimeout(() => {
page = 0 const buffer = xlsx(data, settings)
// eslint-disable-next-line eqeqeq res.writeHead(200, {
} else if (!req.query.page == 1) { "Content-Type": "application/octet-stream",
page = 0 "Content-disposition": "attachment; filename=device.csv",
} else { })
page = req.query.page res.end(buffer)
page = page * rows - rows }, 2000);
}
const data = await Device.find().sort({ created_at: -1 }).skip(page).limit(rows);
const total = Math.ceil((await Device.estimatedDocumentCount()))
res.status(200).json({ data, total })
} }
] ]
@@ -99,7 +121,7 @@ module.exports.getOneByIMEI = [
], ],
checkValidations(validationResult), checkValidations(validationResult),
async (req, res) => { async (req, res) => {
const data = await Device.findOne({IMEI:req.params.imei}).sort({ created_at: -1 }) const data = await Device.findOne({ IMEI: req.params.imei }).sort({ created_at: -1 })
if (!data) { if (!data) {
res.status(404).json(_sr.fa.not_found.item_id) res.status(404).json(_sr.fa.not_found.item_id)
} else { } else {
@@ -151,10 +173,18 @@ const creator = (exel) => {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
for (const row of exel) { for (const row of exel) {
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
if (validator.isIMEI(row[0].toString().trim()) || true) { if (/^[0-9]{15}$/gm.test(row[0].toString().trim())) {
const device = await Device.findOne({ IMEI: row[0] }) const device = await Device.findOne({ IMEI: row[0] })
if (device) { if (device) {
console.warn("Repeated IMEI ", row[0]) console.info("Repeated IMEI ", row[0])
device.model = row[1]
device.tomanPrice = row[2]
device.dollarProfit = row[3] || 1
device.profit = row[4] || 1
device.score = row[5] || 1
device.renewalProfit = row[6] || 1
device.save()
} else { } else {
await Device.create( await Device.create(
{ {
@@ -174,4 +204,5 @@ const creator = (exel) => {
} }
resolve("end") resolve("end")
}) })
} }
+1
View File
@@ -71,6 +71,7 @@ router.get('/gps/register-device', installedDevice.getAllForAdmin)
/// ////////////// Device /// ////////////// Device
router.post('/gps/device',hasPermission('gps'), device.addCode) router.post('/gps/device',hasPermission('gps'), device.addCode)
router.post('/gps/device/exel',hasPermission('gps'), device.importExel) router.post('/gps/device/exel',hasPermission('gps'), device.importExel)
router.get('/gps/device/exel',hasPermission('gps'), device.downloadAll)
router.get('/gps/device',hasPermission('gps'), device.getAll) router.get('/gps/device',hasPermission('gps'), device.getAll)
router.get('/gps/device/imei/:imei',hasPermission('gps'), device.getOneByIMEI) router.get('/gps/device/imei/:imei',hasPermission('gps'), device.getOneByIMEI)
router.get('/gps/device/id/:id',hasPermission('gps'), device.getOne) router.get('/gps/device/id/:id',hasPermission('gps'), device.getOne)
Binary file not shown.
+5 -1
View File
@@ -14,7 +14,11 @@ export const state = () => ({
verityProducts: [], verityProducts: [],
panatechProducts: [], panatechProducts: [],
iranProvinces: [], iranProvinces: [],
iranCities: [] iranCities: [],
newWithdrawRequest: 0,
pendingUsers: 0,
newAwardRequest: 0,
newInstallDeviceRequest: 0
}) })
export const mutations = { export const mutations = {