Browse Source

针对整卷阅版本的跨学校管理员情况,增加切换当前学校的功能

luoshi 6 years ago
parent
commit
59190e67c0

+ 3 - 3
config.json

@@ -18,7 +18,7 @@
     "logger": {
         "level": "info"
     },
-    "openDevTools": false,
+    "openDevTools": true,
     "localStore": "",
     "servers": [{
             "name": "高校",
@@ -40,8 +40,8 @@
         },
         {
             "name": "局域网",
-            "host": "localhost:8010",
-            "bucketPrefix": "ft",
+            "host": "192.168.10.141:8090",
+            "bucketPrefix": "gx",
             "upyunDomain": ""
         }
     ]

+ 5 - 2
source/lib/api.js

@@ -29,10 +29,10 @@ async function execute(uri, method, form) {
 }
 
 module.exports.login = function() {
-    return execute('/api/user/login', 'GET');
+    return execute('/api/user/login?withSchoolList=true', 'GET');
 }
 
-module.exports.getExams = function(pageNumber, pageSize) {
+module.exports.getExams = function(pageNumber, pageSize, schoolId) {
     let uri = '/api/exams'
     let param = [];
     if (pageNumber != undefined) {
@@ -41,6 +41,9 @@ module.exports.getExams = function(pageNumber, pageSize) {
     if (pageSize != undefined) {
         param.push('pageSize=' + pageSize)
     }
+    if (schoolId != undefined) {
+        param.push('schoolId=' + schoolId)
+    }
     if (param.length > 0) {
         uri = uri + '?' + param.join('&')
     }

+ 14 - 3
source/lib/env.js

@@ -1,9 +1,8 @@
-var store = {
-}
+var store = {}
 
 module.exports = store;
 
-module.exports.merge = function (obj) {
+module.exports.merge = function(obj) {
     if (obj == undefined) {
         return
     }
@@ -12,3 +11,15 @@ module.exports.merge = function (obj) {
     }
 }
 
+module.exports.getSchoolName = function() {
+    let schoolName = undefined;
+    if (store.user != undefined && store.user.schoolList != undefined) {
+        for (let i = 0; i < store.user.schoolList.length; i++) {
+            if (store.user.schoolId == store.user.schoolList[i].id) {
+                schoolName = store.user.schoolList[i].name
+                break
+            }
+        }
+    }
+    return schoolName
+}

+ 17 - 4
source/view/list.html → source/view/exam-list.html

@@ -12,7 +12,12 @@
     <div class="wp">
         <div class="hd">
             <div class="logo"><img src="img/logo.png" /></div>
-            <span class="y"> 欢迎您,<span id="user-name"></span><span class="pipe">|</span><a href="login.html">退出</a></span>
+            <span class="y"> 欢迎您,<span id="user-name"></span>
+                <span id="school-switch" style="display:none">
+                    <span class="pipe">|</span><a href="school-list.html"></a>
+                </span>
+                <span class="pipe">|</span><a href="login.html">退出</a>
+            </span>
         </div>
         <div class="cont">
             <div class="title cl" style="background:#FFF;">
@@ -57,7 +62,13 @@
             env.merge(JSON.parse(window.localStorage.getItem('env')))
             $('#user-name').html(env.user.userName)
 
-            api.getExams(1, 1000).then(list => {
+            let schoolName = env.getSchoolName()
+            if (schoolName != undefined) {
+                $('#school-switch').find('a').html(schoolName)
+                $('#school-switch').show()
+            }
+
+            api.getExams(1, 1000, env.user.schoolId).then(list => {
                 examList = list
                 initPage()
             }).catch(err => {
@@ -76,10 +87,12 @@
 
             $('#page-list').empty()
             for (let i = 1; i <= pageCount; i++) {
-                let dom = $(mustache.render(pageTemplate, { number: i }))
+                let dom = $(mustache.render(pageTemplate, {
+                    number: i
+                }))
                 $('#page-list').append(dom)
 
-                dom.click(function () {
+                dom.click(function() {
                     changePage(parseInt($(this).attr('data-number')))
                 })
             }

+ 13 - 2
source/view/image-download.html

@@ -11,8 +11,13 @@
 <body>
     <div class="wp">
         <div class="hd">
-            <div class="logo"><a href="##"><img src="img/logo.png" /></a></div>
-            <span class="y"> 欢迎您,<span id="user-name"></span><span class="pipe">|</span><a href="##">退出</a></span>
+            <div class="logo"><img src="img/logo.png" /></div>
+            <span class="y"> 欢迎您,<span id="user-name"></span>
+                <span id="school-switch" style="display:none">
+                    <span class="pipe">|</span><a href="##"></a>
+                </span>
+                <span class="pipe">|</span><a href="##">退出</a>
+            </span>
         </div>
         <div class="cont">
             <div class="title title_grey cl">
@@ -54,6 +59,12 @@
             env.merge(JSON.parse(window.localStorage.getItem('env')))
             $('#user-name').html(env.user.userName)
 
+            let schoolName = env.getSchoolName()
+            if (schoolName != undefined) {
+                $('#school-switch').find('a').html(schoolName)
+                $('#school-switch').show()
+            }
+
             let config = JSON.parse(window.localStorage.getItem('image-config'))
             let totalCount;
             imageUtil.on('total', (count) => {

+ 16 - 3
source/view/image.html

@@ -11,8 +11,13 @@
 <body>
     <div class="wp">
         <div class="hd">
-            <div class="logo"><a href="index.html"><img src="img/logo.png" /></a></div>
-            <span class="y"> 欢迎您,<span id="user-name"></span><span class="pipe">|</span><a href="login.html">退出</a></span>
+            <div class="logo"><img src="img/logo.png" /></div>
+            <span class="y"> 欢迎您,<span id="user-name"></span>
+                <span id="school-switch" style="display:none">
+                    <span class="pipe">|</span><a href="school-list.html"></a>
+                </span>
+                <span class="pipe">|</span><a href="login.html">退出</a>
+            </span>
         </div>
         <div class="cont">
             <div class="title cl">
@@ -70,12 +75,20 @@
         const $ = require('jquery')
         const env = require('../lib/env.js')
         const config = require('../lib/config.js')
-        const { dialog } = require('electron').remote
+        const {
+            dialog
+        } = require('electron').remote
 
         $(document).ready(() => {
             env.merge(JSON.parse(window.localStorage.getItem('env')))
             $('#user-name').html(env.user.userName)
 
+            let schoolName = env.getSchoolName()
+            if (schoolName != undefined) {
+                $('#school-switch').find('a').html(schoolName)
+                $('#school-switch').show()
+            }
+
             $('input:radio[name="type"]').change(() => {
                 let type = $('input:radio:checked').val()
                 if (type == '1') {

+ 15 - 3
source/view/index.html

@@ -11,8 +11,13 @@
 <body>
     <div class="wp">
         <div class="hd">
-            <div class="logo"><a href="index.html"><img src="img/logo.png" /></a></div>
-            <span class="y"> 欢迎您,<span id="user-name"></span><span class="pipe">|</span><a href="login.html">退出</a></span>
+            <div class="logo"><img src="img/logo.png" /></div>
+            <span class="y"> 欢迎您,<span id="user-name"></span>
+                <span id="school-switch" style="display:none">
+                    <span class="pipe">|</span><a href="school-list.html"></a>
+                </span>
+                <span class="pipe">|</span><a href="login.html">退出</a>
+            </span>
         </div>
         <div class="cont">
             <div class="title cl" id="exam-title">
@@ -22,7 +27,7 @@
             <div class="list">
                 <h3>功能选择</h3>
                 <ul class="cl">
-                    <li class="l1"><a href="list.html"><span></span>考试切换</a></li>
+                    <li class="l1"><a href="exam-list.html"><span></span>考试切换</a></li>
                     <li class="l2"><a href="sync.html"><span></span>数据同步</a></li>
                     <li class="l3"><a href="image.html"><span></span>图片下载</a></li>
                 </ul>
@@ -38,6 +43,13 @@
         $(document).ready(() => {
             env.merge(JSON.parse(window.localStorage.getItem('env')))
             $('#user-name').html(env.user.userName)
+
+            let schoolName = env.getSchoolName()
+            if (schoolName != undefined) {
+                $('#school-switch').find('a').html(schoolName)
+                $('#school-switch').show()
+            }
+
             $('#exam-title').find('.id').html(env.exam.id)
             $('#exam-title').find('.name').html(env.exam.name)
             $('#exam-title').find('.time').html(env.exam.examTime)

+ 2 - 2
source/view/login.html

@@ -48,7 +48,7 @@
             }
         })
 
-        document.onkeydown = function (event) {
+        document.onkeydown = function(event) {
             var e = event || window.event;
             if (e && e.keyCode == 13) { //回车键的键值为13
                 $('#login-button').click() //调用登录按钮的登录事件
@@ -79,7 +79,7 @@
             api.login().then(user => {
                 env.user = user
                 window.localStorage.setItem('env', JSON.stringify(env))
-                window.location.href = 'list.html'
+                window.location.href = 'exam-list.html'
             }).catch(err => {
                 alert('登陆失败,用户名或密码错误')
             })

+ 129 - 0
source/view/school-list.html

@@ -0,0 +1,129 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <meta charset="UTF-8">
+    <title>云阅卷本地代理工具</title>
+    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
+    <link rel="stylesheet" href="css/style.css">
+</head>
+
+<body>
+    <div class="wp">
+        <div class="hd">
+            <div class="logo"><img src="img/logo.png" /></div>
+            <span class="y"> 欢迎您,<span id="user-name"></span>
+                <span class="pipe">|</span><a href="login.html">退出</a>
+            </span>
+        </div>
+        <div class="cont">
+            <div class="title cl" style="background:#FFF;">
+                <span class="y">共有<b id="total-count">0</b>所学校,请选择</span>
+                <h2>学校列表</h2>
+            </div>
+            <table cellpadding="0" cellspacing="0" width="100%" class="tablelist">
+                <thead>
+                    <th>ID</th>
+                    <th>学校名称</th>
+                    <th>操作</th>
+                </thead>
+                <tbody id="school-list">
+                </tbody>
+            </table>
+            <div class="page">
+                <span class="back" id="previous-button">上页</span>
+                <div id="page-list">
+                </div>
+                <span class="next" id="next-button">下页</span>
+            </div>
+        </div>
+        <div class="ft">Copyright © 2011-2020 www.qmth.com.cn, All Rights Reserved</div>
+    </div>
+
+    <script>
+        const $ = require('jquery')
+        const env = require('../lib/env.js')
+        const api = require('../lib/api.js')
+        const mustache = require('mustache')
+        const schoolTemplate = '<tr><td>{{id}}</td><td>{{name}}</td>\
+            <td><a href="##" data-index="{{index}}">切换学校</a></td></tr>'
+        const pageTemplate = '<a href="##" data-number="{{number}}">{{number}}</a>'
+        const pageSize = 10
+
+        let schoolList = []
+        let currentPage
+        let pageCount
+        $(document).ready(() => {
+            env.merge(JSON.parse(window.localStorage.getItem('env')))
+            $('#user-name').html(env.user.userName)
+
+            schoolList = env.user.schoolList
+            initPage()
+        })
+
+        function initPage() {
+            let totalCount = schoolList.length
+            if (totalCount > 0) {
+                pageCount = totalCount % pageSize == 0 ? parseInt(totalCount / pageSize) : parseInt(totalCount / pageSize) + 1
+            } else {
+                pageCount = 0
+            }
+            $('#total-count').html(totalCount)
+
+            $('#page-list').empty()
+            for (let i = 1; i <= pageCount; i++) {
+                let dom = $(mustache.render(pageTemplate, {
+                    number: i
+                }))
+                $('#page-list').append(dom)
+
+                dom.click(function() {
+                    changePage(parseInt($(this).attr('data-number')))
+                })
+            }
+            $('#previous-button').click(() => {
+                if (currentPage > 1) {
+                    changePage(currentPage - 1)
+                }
+            })
+            $('#next-button').click(() => {
+                if (currentPage < pageCount) {
+                    changePage(currentPage + 1)
+                }
+            })
+            if (pageCount > 0) {
+                changePage(1)
+            }
+        }
+
+        function render() {
+            $('#page-list').find('a').removeClass('on')
+            $('#page-list').find('a[data-number="' + currentPage + '"]').addClass('on')
+
+            $('#school-list').empty()
+            let start = (currentPage - 1) * pageSize
+            let end = start + pageSize
+            for (let i = start; i < end && i < schoolList.length; i++) {
+                schoolList[i].index = i
+                let dom = $(mustache.render(schoolTemplate, schoolList[i]))
+                $('#school-list').append(dom)
+
+                dom.find('a').click(selectSchool)
+            }
+        }
+
+        function selectSchool() {
+            let school = schoolList[parseInt($(this).attr('data-index'))]
+            env.user.schoolId = school.id
+            window.localStorage.setItem('env', JSON.stringify(env))
+            window.location.href = 'exam-list.html'
+        }
+
+        function changePage(pageNumber) {
+            currentPage = pageNumber
+            render()
+        }
+    </script>
+</body>
+
+</html>

+ 13 - 2
source/view/sync-run.html

@@ -11,8 +11,13 @@
 <body>
     <div class="wp">
         <div class="hd">
-            <div class="logo"><a href="##"><img src="img/logo.png" /></a></div>
-            <span class="y"> 欢迎您,<span id="user-name"></span><span class="pipe">|</span><a href="##">退出</a></span>
+            <div class="logo"><img src="img/logo.png" /></div>
+            <span class="y"> 欢迎您,<span id="user-name"></span>
+                <span id="school-switch" style="display:none">
+                    <span class="pipe">|</span><a href="##"></a>
+                </span>
+                <span class="pipe">|</span><a href="##">退出</a>
+            </span>
         </div>
         <div class="cont">
             <div class="title title_grey cl">
@@ -52,6 +57,12 @@
             env.merge(JSON.parse(window.localStorage.getItem('env')))
             $('#user-name').html(env.user.userName)
 
+            let schoolName = env.getSchoolName()
+            if (schoolName != undefined) {
+                $('#school-switch').find('a').html(schoolName)
+                $('#school-switch').show()
+            }
+
             var totalCount = 0;
             sync.on('total', (count) => {
                 totalCount = count

+ 14 - 2
source/view/sync.html

@@ -11,8 +11,13 @@
 <body>
     <div class="wp">
         <div class="hd">
-            <div class="logo"><a href="index.html"><img src="img/logo.png" /></a></div>
-            <span class="y"> 欢迎您,<span id="user-name"></span><span class="pipe">|</span><a href="login.html">退出</a></span>
+            <div class="logo"><img src="img/logo.png" /></div>
+            <span class="y"> 欢迎您,<span id="user-name"></span>
+                <span id="school-switch" style="display:none">
+                    <span class="pipe">|</span><a href="school-list.html"></a>
+                </span>
+                <span class="pipe">|</span><a href="login.html">退出</a>
+            </span>
         </div>
         <div class="cont">
             <div class="title cl">
@@ -37,6 +42,13 @@
         $(document).ready(() => {
             env.merge(JSON.parse(window.localStorage.getItem('env')))
             $('#user-name').html(env.user.userName)
+
+            let schoolName = env.getSchoolName()
+            if (schoolName != undefined) {
+                $('#school-switch').find('a').html(schoolName)
+                $('#school-switch').show()
+            }
+
             $('#last-time').html(config['syncTime'][env.server.host + '_' + env.exam.id])
 
             db.init()