王旭
2022-10-10 083b17d07939af29bcb04a27e564664c7280595a
登录验证登出
已修改11个文件
332 ■■■■ 文件已修改
public/config/config.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
public/index.html 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/api.js 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/login.vue 62 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/navMenu.vue 126 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/router/index.js 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/store/index.js 87 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/request.js 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/maintenance/eventlogManage.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/maintenance/logLog.vue 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/maintenance/operationLog.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
public/config/config.js
@@ -1,5 +1,5 @@
const BASE_URL = 'http://192.168.20.55:12316';
// const BASE_URL = 'http://192.168.20.39:12316';
// const BASE_URL = 'http://192.168.20.55:12316';
const BASE_URL = 'http://192.168.20.39:12316';
var gisUrl = 'http://183.162.245.49:3301';
var ifreamUrl = 'http://192.168.20.39:12306/';
public/index.html
@@ -12,6 +12,7 @@
  <script src="./SmartEarthSDK/Cesium/Cesium.js"></script>
  <script src="./SmartEarthSDK/SmartEarth.min.js"></script>
  <script src="./config/config.js"></script>
  <script src="./config/rsa.min.js"></script>
  <style>
    .esriControlsBR {
      display: none;
src/api/api.js
@@ -121,4 +121,19 @@
export function resOpSelectByPageAndCount(params) {
  //请求地址
  return request.get('/resOp/selectByPageAndCount', { params: params });
}
//获取公钥用于加密
export function getPublicKey(params) {
  //请求地址
  return request.get('/sign/getPublicKey', { params: params });
}
//登录
export function login(params) {
  //请求地址
  return request.post('/sign/login',  params );
}
//退出登录
export function logout(params) {
  //请求地址
  return request.get('/sign/logout',  { params: params } );
}
src/components/login.vue
@@ -78,9 +78,9 @@
        ref="loginForm"
        class="loginForm"
      >
        <el-form-item prop="userName">
        <el-form-item prop="uid">
          <el-input
            v-model="loginForm.userName"
            v-model="loginForm.uid"
            placeholder="输入您的账号或手机号"
            class="nobr"
            size="meddle"
@@ -90,10 +90,10 @@
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
        <el-form-item prop="pwd">
          <el-input
            show-password
            v-model="loginForm.password"
            v-model="loginForm.pwd"
            placeholder="输入您的密码"
            class="nobr"
            autocomplete="off"
@@ -141,6 +141,7 @@
              background: #3b4d6e;
              border-radius: 5px;
            "
            :loading="loading"
            @click="submitForm('loginForm')"
            >登录</el-button
          >
@@ -153,6 +154,7 @@
<script>
// import { login } from '../utils/api'
import validCode from "./verificationCode.vue";
import { mapActions } from "vuex";
export default {
  components: { validCode },
@@ -185,33 +187,24 @@
    return {
      validCode: "",
      loading: false,
      loginForm: {
        userName: "admin",
        password: "terra2022",
        uid: "admin",
        pwd: "Admin@123",
      },
      rules: {
        userName: [{ validator: validUserName, trigger: "blur" }],
        password: [{ validator: validPassword, trigger: "blur" }],
        uid: [{ validator: validUserName, trigger: "blur" }],
        pwd: [{ validator: validPassword, trigger: "blur" }],
        validCode: [{ validator: checkValidCode, trigger: "blur" }],
      },
    };
    // return {
    //   validCode: "",
    //   form: {
    //     username: "",
    //     password: "",
    //   },
    //   rules: {
    //     username: [
    //       { required: true, message: "请输入用户名", trigger: "blur" },
    //     ],
    //     password: [{ required: true, message: "请填写密码", trigger: "blur" }],
    //   },
    // };
  },
  mounted() {},
  mounted() {
    this.getpublickey();
  },
  methods: {
    //   获取vuex中Actions里的方法
    ...mapActions(["login", "getpublickey"]),
    getCode(data) {
      console.log(data);
      this.validCode = data; //在data中定义一个 validCode:'',用来记录验证码。
@@ -219,8 +212,17 @@
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          //调用录接口
          this.$router.push("/catalogueManage");
          this.loading = true;
          this.login(this.loginForm)
            .then(response => {
             this.$router.push("/")
              this.loading = false;
              //调用录接口
            })
            .catch(response => {
              this.loading = false;
            });
          //如果登录失败,需要刷新验证码的
          this.$refs.refresh.createdCode();
          this.validCode = ""; //清空验证码输入框的内容
@@ -230,16 +232,8 @@
        }
      });
    },
    // onSubmit() {
    //   this.$refs.form.validate((valid) => {
    //     if (valid) {
    //       this.$router.push("/Home");
    //     } else {
    //       return false;
    //     }
    //   });
    // },
  },
  created() {},
};
</script>
src/components/navMenu.vue
@@ -18,120 +18,120 @@
        >
          <el-submenu index="3" class="faSub">
            <template slot="title">
              <span>{{ $t('synthesis.synthesis') }}</span>
              <span>{{ $t("synthesis.synthesis") }}</span>
            </template>
            <el-menu-item index="Synthesis">{{
              $t('synthesis.synthesis')
              $t("synthesis.synthesis")
            }}</el-menu-item>
            <el-menu-item index="Thematic">{{
              $t('synthesis.themaic')
              $t("synthesis.themaic")
            }}</el-menu-item>
            <el-menu-item index="Archive">{{
              $t('synthesis.archive')
              $t("synthesis.archive")
            }}</el-menu-item>
          </el-submenu>
          <el-submenu index="1" class="faSub">
            <template slot="title">
              <span>{{ $t('dataManage.dataManage') }}</span>
              <span>{{ $t("dataManage.dataManage") }}</span>
            </template>
            <el-menu-item index="catalogueManage">{{
              $t('dataManage.catalogueManage')
              $t("dataManage.catalogueManage")
            }}</el-menu-item>
            <el-menu-item index="dataUpdata">{{
              $t('dataManage.dataUpdata')
              $t("dataManage.dataUpdata")
            }}</el-menu-item>
            <el-menu-item index="metadataManage">{{
              $t('dataManage.metadataManage')
              $t("dataManage.metadataManage")
            }}</el-menu-item>
            <el-menu-item index="dataLoading">{{
              $t('dataManage.dataLoading')
              $t("dataManage.dataLoading")
            }}</el-menu-item>
            <el-menu-item index="SpatialData">{{
              $t('dataManage.SpatialData')
              $t("dataManage.SpatialData")
            }}</el-menu-item>
            <el-menu-item index="versionManage">{{
              $t('dataManage.versionManage')
              $t("dataManage.versionManage")
            }}</el-menu-item>
            <el-menu-item index="dictionaryManage">{{
              $t('dataManage.dictionaryManage')
              $t("dataManage.dictionaryManage")
            }}</el-menu-item>
            <el-menu-item index="styleManage">{{
              $t('dataManage.styleManage')
              $t("dataManage.styleManage")
            }}</el-menu-item>
          </el-submenu>
          <el-submenu index="2" class="faSub">
            <template slot="title">
              <span>{{ $t('operatManage.operatManage') }}</span>
              <span>{{ $t("operatManage.operatManage") }}</span>
            </template>
            <el-submenu index="2-2">
              <template slot="title">{{
                $t('operatManage.systemLayout')
                $t("operatManage.systemLayout")
              }}</template>
              <el-menu-item index="menuSettings">{{
                $t('operatManage.menuSettings')
                $t("operatManage.menuSettings")
              }}</el-menu-item>
              <el-menu-item index="parameterConfiguration">{{
                $t('operatManage.parameterConfiguration')
                $t("operatManage.parameterConfiguration")
              }}</el-menu-item>
              <el-menu-item index="rests">{{
                $t('operatManage.rests')
                $t("operatManage.rests")
              }}</el-menu-item>
            </el-submenu>
            <el-menu-item index="authorityManagement">{{
              $t('operatManage.authorityManagement')
              $t("operatManage.authorityManagement")
            }}</el-menu-item>
            <el-menu-item index="safetyManagement">{{
              $t('operatManage.safetyManagement')
              $t("operatManage.safetyManagement")
            }}</el-menu-item>
            <el-submenu index="2-5">
              <template slot="title">{{
                $t('operatManage.operationMonitoring')
                $t("operatManage.operationMonitoring")
              }}</template>
              <el-menu-item index="eventlogManage">{{
                $t('operatManage.ResourceLog')
                $t("operatManage.ResourceLog")
              }}</el-menu-item>
              <el-menu-item index="logLog">{{
                $t('operatManage.logLog')
                $t("operatManage.logLog")
              }}</el-menu-item>
              <el-menu-item index="operationLog">{{
                $t('operatManage.operationLog')
                $t("operatManage.operationLog")
              }}</el-menu-item>
              <el-menu-item index="databaseMonitoring">{{
                $t('operatManage.databaseMonitoring')
                $t("operatManage.databaseMonitoring")
              }}</el-menu-item>
              <el-menu-item index="systemMonitoring">{{
                $t('operatManage.systemMonitoring')
                $t("operatManage.systemMonitoring")
              }}</el-menu-item>
              <el-menu-item index="blackwhiteList"
                >{{ $t('operatManage.blackwhiteList') }}
                >{{ $t("operatManage.blackwhiteList") }}
              </el-menu-item>
              <el-menu-item index="tokentool">{{
                $t('operatManage.tokentool')
                $t("operatManage.tokentool")
              }}</el-menu-item>
            </el-submenu>
          </el-submenu>
          <el-submenu index="4" class="faSub">
            <template slot="title">
              <span>{{ $t('userManage.userManage') }}</span>
              <span>{{ $t("userManage.userManage") }}</span>
            </template>
            <el-menu-item index="userInfoManage">{{
              $t('userManage.userInfoManage')
              $t("userManage.userInfoManage")
            }}</el-menu-item>
            <el-menu-item index="orgManage">{{
              $t('userManage.orgManage')
              $t("userManage.orgManage")
            }}</el-menu-item>
            <el-menu-item index="userAuditing">{{
              $t('userManage.userAuditing')
              $t("userManage.userAuditing")
            }}</el-menu-item>
            <el-menu-item index="roleManage">{{
              $t('userManage.roleManage')
              $t("userManage.roleManage")
            }}</el-menu-item>
            <el-menu-item index="groupManage">{{
              $t('userManage.groupManage')
              $t("userManage.groupManage")
            }}</el-menu-item>
            <el-menu-item index="authorityManage">{{
              $t('userManage.authorityManage')
              $t("userManage.authorityManage")
            }}</el-menu-item>
          </el-submenu>
          <!-- <el-submenu index="5" class="faSub">
@@ -149,7 +149,7 @@
      <div class="userInfo">
        <img src="../assets/img/user.png" alt="" />
        <span>admin</span>
        <span>注销</span>
        <span @click="logOut">注销</span>
        &nbsp;
        <span @click="switchLang"> 切换语言</span>
      </div>
@@ -162,46 +162,74 @@
</template>
<script>
import { logout } from "@/api/api";
import { removeToken,getToken } from "@/utils/auth";
export default {
  name: 'navMenu',
  name: "navMenu",
  //import引入的组件需要注入到对象中才能使用
  data() {
    return {
      lang: 'en',
      lang: "en",
    };
  },
  methods: {
    logOut() {
      this.$confirm("确认是否退出登录?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const data = await logout({token:getToken()});
          console.log(data);
          if (data.code != 200) {
            return this.$message.error("退出登录失败");
          }
          removeToken();
          this.$router.push("/login");
          this.$message({
            message: "退出登录成功",
            type: "success",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    handleOpen(key, keyPath) {
      if (
        keyPath[1] != 'dataLoading' &&
        keyPath[1] != '2-2' &&
        keyPath[1] != '2-5'
        keyPath[1] != "dataLoading" &&
        keyPath[1] != "2-2" &&
        keyPath[1] != "2-5"
      )
        this.$router.push(keyPath[1]);
    },
    handleClose(key, keyPath) {
      if (
        keyPath[1] != 'dataLoading' &&
        keyPath[1] != '2-5' &&
        keyPath[1] != '2-2'
        keyPath[1] != "dataLoading" &&
        keyPath[1] != "2-5" &&
        keyPath[1] != "2-2"
      )
        this.$router.push(keyPath[1]);
    },
    handleselect(index) {
      if (index != null) {
        this.$emit('shwoMapView', false);
        this.$emit("shwoMapView", false);
      }
    },
    showChange() {
      this.$emit('shwoMapView', true);
      this.$emit("shwoMapView", true);
    },
    switchLang() {
      if (this.lang == 'en') {
      if (this.lang == "en") {
        this.$i18n.locale = this.lang;
        this.lang = 'zh';
        this.lang = "zh";
      } else {
        this.$i18n.locale = this.lang;
        this.lang = 'en';
        this.lang = "en";
      }
    },
  },
src/router/index.js
@@ -1,5 +1,6 @@
import Vue from 'vue';
import VueRouter from 'vue-router';
import { getToken } from "@/utils/auth"; // get token from cookie
import Home from '../views/Home.vue';
import login from '../components/login';
import Synthesis from '../views/Synthesis/index.vue'; //综合展示
@@ -41,14 +42,15 @@
const routes = [
  {
    path: '/',
    path: '/login',
    name: 'login',
    component: login,
  },
  {
    path: '/Home',
    path: '/',
    name: 'Home',
    component: Home,
    redirect: "/Synthesis",
    children: [
      {
        path: '/Synthesis',
@@ -333,5 +335,21 @@
const router = new VueRouter({
  routes,
});
//路由守卫
router.beforeEach((to, from, next) => {
  next();
  if (to.matched.some((auth) => auth.meta.requireAuth)) {
    // 获取token
    let token = getToken();
    if (token) {
      next();
    } else {
      next({
        path: "/login",
      });
    }
  } else {
    next();
  }
});
export default router;
src/store/index.js
@@ -1,6 +1,10 @@
import Vue from 'vue';
import Vuex from 'vuex';
import { getToken, setToken, removeToken } from "@/utils/auth";
import { Loading, Message } from "element-ui";
import { login, getPublicKey } from "@/api/api";
var encrypt = new JSEncrypt();
Vue.use(Vuex);
export default new Vuex.Store({
@@ -11,6 +15,12 @@
    verCateNodes: {},
    styleDirCateNodes: {},
    styleDepCateNodes: {},
    token: getToken(),
    //请求计数
    apiCount: 0,
    //loading实例
    loadingInstance: null,
    key: null
  },
  mutations: {
    // 获取完整面包屑路径
@@ -34,7 +44,82 @@
    styleDirChangeNode(state, msg) {
      state.styleDirCateNodes = msg;
    },
    /* 打开Loading */
    START_LOADING(state, msg) {
      state.loadingInstance = Loading.service({
        lock: true,
        text: msg ? msg : "加载中...",
        background: "rgba(0, 0, 0, 0.7)",
      });
    },
    /* 关闭loading */
    CLOSE_LOADING(state) {
      state.loadingInstance.close();
    },
    /* 更新请求线程池 */
    UPDATE_API_COUNT(state, handle) {
      if (handle == "add") {
        state.apiCount++;
        this.commit("START_LOADING");
      } else {
        state.apiCount--;
        if (state.apiCount <= 0) {
          this.commit("CLOSE_LOADING");
        }
      }
    },
    SET_TOKEN(state, token) {
      state.token = token;
    },
    SET_KEY(state, key) {
      state.key = key;
    },
  },
  actions: {},
  actions: {
    // 用户登录 login
    login({ commit, state }, userInfo) {
      return new Promise((resolve, reject) => {
        var data = {
          uid: encrypt.encrypt(userInfo.uid),
          pwd: encrypt.encrypt(userInfo.pwd)
        };
        login(data)
          .then((response) => {
            const data = response;
            if (data.code !== 200) {
              return Message({
                message: data.msg,
                type: "error",
                duration: 5 * 1000,
              });
            }
            commit("SET_TOKEN", data.result.token);
            setToken(data.result.token);
            resolve(data);
          })
          .catch((error) => {
            reject(error);
          });
      });
    },
    getpublickey({ commit, state }, userInfo) {
      return new Promise((resolve, reject) => {
        getPublicKey(userInfo)
          .then((response) => {
            const data = response;
            commit("SET_KEY", data.result);
            encrypt.setPublicKey(data.result); // 设置公钥
            resolve();
          })
          .catch((error) => {
            reject(error);
          });
      });
    }
  },
  modules: {},
});
src/utils/request.js
@@ -24,8 +24,9 @@
service.interceptors.request.use(
  (config) => {
    // 请求携带token
    if (store.getters.token) {
      config.headers["X-Token"] = getToken();
    let token = getToken();
    if (token) {
      config.headers["token"] = token;
    }
    //加载loading
    store.commit("UPDATE_API_COUNT", "add");
src/views/maintenance/eventlogManage.vue
@@ -232,7 +232,7 @@
      const data = await resOpSelectByPageAndCount(this.listData);
      console.log(data);
      if (data.code != 200) {
        this.$message.error("列表调用失败");
        return this.$message.error("列表调用失败");
      }
      this.tableData = data.result;
      this.count = data.count;
src/views/maintenance/logLog.vue
@@ -219,9 +219,9 @@
    },
    async getList() {
      const data = await loginSelectByPageAndCount(this.listData);
      console.log(data);
      if (data.code != 200) {
        this.$message.error("列表调用失败");
       return this.$message.error("列表调用失败");
      }
      this.tableData = data.result;
      this.count = data.count;
src/views/maintenance/operationLog.vue
@@ -244,7 +244,7 @@
      const data = await operateSelectByPageAndCount(this.listData);
      console.log(data);
      if (data.code != 200) {
        this.$message.error("列表调用失败");
        return this.$message.error("列表调用失败");
      }
      this.tableData = data.result;
      this.count = data.count;