Explorar o código

feat: 平台操作优化
1. 新平台自动提示注册管理员账号功能
2. 新平台自动提示配置sip信息

kindring hai 1 ano
pai
achega
6ceda259d2

+ 2 - 1
src/main/java/com/genersoft/iot/vmp/service/impl/AdminServiceImpl.java

@@ -42,7 +42,8 @@ public class AdminServiceImpl implements IAdminService {
     public boolean registerAdmin(String username, String password) {
         AdminAccount adminAccount = new AdminAccount();
         adminAccount.setUsername(username);
-        adminAccount.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
+        adminAccount.setPassword(password);
+//        adminAccount.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
         //新增用户的pushKey的生成规则为md5(时间戳+用户名)
         adminAccount.setPushKey(DigestUtils.md5DigestAsHex((System.currentTimeMillis() + password).getBytes()));
         adminAccount.setCreateTime(DateUtil.getNow());

+ 0 - 2
src/main/java/com/genersoft/iot/vmp/storager/dao/SipConfigMapper.java

@@ -1,7 +1,6 @@
 package com.genersoft.iot.vmp.storager.dao;
 // class SipUserConfig
 //private int id;
-//private int adminId;
 //private String sipDomain;
 //private String serverId;
 //private String password;
@@ -33,7 +32,6 @@ public interface SipConfigMapper {
             "enableBind," +
             "createTime" +
             ") VALUES (" +
-            "#{adminId}, " +
             "#{sipDomain}, " +
             "#{serverId}, " +
             "#{password}, " +

+ 17 - 0
src/main/java/com/genersoft/iot/vmp/vmanager/server/sipController.java

@@ -63,6 +63,23 @@ public class sipController {
         return WVPResult.success(sipConfigs);
     }
 
+    @GetMapping("/default")
+    @Operation(summary = "判断sip是否为空")
+    public WVPResult<Boolean> isDefaultSipConfigs() {
+        logger.info("[判断sip是否为空] all");
+        String adminId = StpAdminUtil.getLoginId().toString();
+        if (!StpAdminUtil.hasRole("primary")) {
+            WVPResult.fail(ErrorCode.ERROR403);
+        }
+        List<SipUserConfig> sipConfigs = sipConfigService.getAllSipConfigsById(adminId);
+        if (sipConfigs.size() > 0) {
+            return WVPResult.success(false);
+        } else {
+            return WVPResult.success(true);
+        }
+
+    }
+
     @PostMapping("/edit")
     @Parameter(name = "id", description = "sipId", required = true)
     @Operation(summary = "编辑sip配置")

+ 86 - 28
web_src/src/components/Login.vue

@@ -22,9 +22,12 @@
           </div>
 
           <div class="container-login100-form-btn">
-            <div class="wrap-login100-form-btn" :class="{'login-loading': isLoging}" v-loading="isLoging" element-loading-background="rgb(0 0 0 / 0%);" element-loading-custom-class="login-loading-class">
+            <div class="wrap-login100-form-btn" :class="{'login-loading': isLoging}" v-loading="isLoging"
+                 element-loading-background="rgb(0 0 0 / 0%);" element-loading-custom-class="login-loading-class">
               <div class="login100-form-bgbtn"></div>
-              <button class="login100-form-btn" @click="login">登录</button>
+              <button class="login100-form-btn" @click="handleClick">
+                {{ isDefault ? "创建账户" : "登录" }}
+              </button>
             </div>
           </div>
       </div>
@@ -37,44 +40,66 @@
 import crypto from 'crypto'
 import api_user from "@/apiStore/api_user";
 import userService from "./service/UserService";
+import handle from "@/until/handle";
+import querystring from "querystring";
+
 export default {
   name: 'Login',
-  data(){
-  	return {
+  data() {
+    return {
       isLoging: false,
       showPassword: false,
       loginLoading: false,
-  		username: '',
-  		password: ''
-  	}
+      username: '',
+      password: '',
+      isDefault: false,
+    }
   },
-  created(){
+  created() {
     var that = this;
-    document.onkeydown = function(e) {
+    document.onkeydown = function (e) {
       var key = window.event.keyCode;
       if (key == 13) {
-        that.login();
+        that.handleClick();
       }
     }
   },
-  methods:{
+  beforeMount() {
+    this.executeIsDefault()
+  },
+  methods: {
 
-  	//登录逻辑
-  	login(){
-  		if(this.username!=='' && this.password!==''){
-  			this.toLogin();
-  		}else{
-        this.$message.warning("请输入账号密码");
+    async executeIsDefault() {
+      let url = "/api/user/default"
+      let [err, res] = await handle(
+          this.$axios.get(url)
+      )
+      if (err) {
+        this.$message.error(`获取服务器信息失败`);
+        return;
+      }
+      let response = res.data
+      if (response.code !== 0) {
+        this.$message.error(`获取服务器信息失败 ${response.msg}`);
+        return;
+      }
+      if (response.data) {
+        this.$message.success("没有管理员账户, 开始注册管理员账户")
+        this.$notify({
+          title: '提示',
+          message: '没有管理员账户, 请先注册账户',
+          duration: 0
+        });
+        this.isDefault = true;
+      }
+    },
+    //登录请求
+    async toLogin() {
+      //需要想后端发送的登录参数
+      let loginParam = {
+        username: this.username,
+        password: crypto.createHash('md5').update(this.password, "utf8").digest('hex')
       }
-  	},
-
-  	//登录请求
-  	async toLogin(){
-  		//需要想后端发送的登录参数
-  		let loginParam = {
-  			username: this.username,
-  			password: crypto.createHash('md5').update(this.password, "utf8").digest('hex')
-  		}
       let that = this;
       //设置在登录状态
       this.isLoging = true;
@@ -97,7 +122,7 @@ export default {
         //登录成功后
         that.cancelEnterkeyDefaultAction();
         await that.$router.push('/');
-      }else{
+      } else {
         that.isLoging = false;
         that.$message({
           showClose: true,
@@ -106,6 +131,39 @@ export default {
         });
       }
     },
+    async executeRegister() {
+      let url = "/api/user/register"
+      let loginParam = {
+        username: this.username,
+        password: crypto.createHash('md5').update(this.password, "utf8").digest('hex')
+      }
+      loginParam = querystring.stringify(loginParam)
+      let [err, res] = await handle(
+          this.$axios.post(url, loginParam))
+      if (err) {
+        this.$message.error(`注册账户失败`);
+        console.log(err);
+        return;
+      }
+      let response = res.data
+      if (response.code !== 0) {
+        this.$message.error(`注册账户失败 ${response.msg}`);
+        return;
+      }
+      this.$message.success("管理员账户注册成功")
+      this.isDefault = false;
+    },
+    handleClick() {
+      if (this.username == '' || this.password == '') {
+        this.$message.warning("请输入账号密码");
+        return;
+      }
+      if (this.isDefault) {
+        this.executeRegister()
+      } else {
+        this.toLogin()
+      }
+    },
     setCookie: function (cname, cvalue, exdays) {
       let d = new Date();
       d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
@@ -114,7 +172,7 @@ export default {
       document.cookie = cname + "=" + cvalue + "; " + expires;
       console.info(document.cookie);
     },
-    cancelEnterkeyDefaultAction: function() {
+    cancelEnterkeyDefaultAction: function () {
         document.onkeydown = function(e) {
         let key = window.event.keyCode;
         if (key == 13) {

+ 31 - 2
web_src/src/components/console.vue

@@ -70,6 +70,7 @@ import configInfo from './dialog/configInfo.vue'
 
 import echarts from 'echarts';
 import router from "@/router";
+import handle from "@/until/handle";
 
 export default {
   name: 'app',
@@ -96,14 +97,42 @@ export default {
     this.loopForSystemInfo();
 
   },
+  beforeMount() {
+    this.executeIsDefault()
+  },
   destroyed() {
   },
   methods: {
-    loopForSystemInfo: function (){
+    async executeIsDefault() {
+      let url = "/api/sip/default"
+      let [err, res] = await handle(
+          this.$axios.get(url)
+      )
+      if (err) {
+        this.$message.error(`获取sip配置失败`);
+        return;
+      }
+      let response = res.data
+      if (response.code !== 0) {
+        this.$message.error(`获取sip配置失败 ${response.msg}`);
+        return;
+      }
+      if (response.data) {
+        this.$message.success("没有sip配置")
+        this.$notify({
+          title: '提示',
+          message: '没有sip配置, 前往添加',
+          duration: 0
+        });
+
+        await this.$router.push("/sipConfigs")
+      }
+    },
+    loopForSystemInfo: function () {
       if (this.timer != null) {
         window.clearTimeout(this.timer);
       }
-      this.timer = setTimeout(()=>{
+      this.timer = setTimeout(() => {
         if (this.$route.path === "/console") {
           this.getSystemInfo();
           this.getLoad();

+ 5 - 0
web_src/src/components/control.vue

@@ -250,6 +250,7 @@ import uiHeader from '../layout/UiHeader.vue'
 import MediaServer from './service/MediaServer'
 
 import echarts from 'echarts';
+import handle from "@/until/handle";
 
 export default {
   name: 'app',
@@ -292,6 +293,9 @@ export default {
       loadCount: 0,
       mediaServerList: []
     };
+  },
+  beforeMount() {
+
   },
   mounted() {
     this.initTable()
@@ -309,6 +313,7 @@ export default {
     clearInterval(this.chartInterval); //释放定时任务
   },
   methods: {
+
     chooseMediaChange: function (val) {
       this.loadCount = 0
       this.initTable()

+ 1 - 4
web_src/src/pages/index/App.vue

@@ -22,10 +22,7 @@ export default {
     }
   },
   created() {
-    if (userService.getToken() == null){
-      //如果没有登录状态则跳转到登录页
-      this.$router.push('/login');
-    }
+
   },
   //监听路由检查登录
   watch:{