License.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <section class="content">
  3. <!-- 正文信息 -->
  4. <div class="part-box">
  5. <h1 class="part-box-title">授权管理</h1>
  6. <div class="part-box-action">
  7. <el-form
  8. class="padding-tb-20 form-tight"
  9. :model="info"
  10. label-width="150px"
  11. >
  12. <el-form-item label="当前信息">
  13. <span class="input">{{ info.activation }}</span>
  14. </el-form-item>
  15. <el-form-item label="人数限制">
  16. <span class="input">{{ info.maxCount }}</span>
  17. </el-form-item>
  18. <el-form-item label="当前人数">
  19. <span class="input">{{ info.onlineCount }}</span>
  20. </el-form-item>
  21. <el-form-item label="过期时间">
  22. <span class="input">{{ info.expire }}</span>
  23. </el-form-item>
  24. <el-form-item label="授权模式">
  25. <span class="input">{{ info.type }}</span>
  26. </el-form-item>
  27. </el-form>
  28. </div>
  29. <el-form
  30. ref="form"
  31. class="padding-tb-20 form-tight"
  32. :rules="rules"
  33. :model="form"
  34. label-width="150px"
  35. >
  36. <el-form-item label="授权模式">
  37. <el-select v-model="form.type" class="input">
  38. <el-option label="在线激活" value="ONLINE"></el-option>
  39. <el-option label="离线激活" value="OFFLINE"></el-option>
  40. </el-select>
  41. </el-form-item>
  42. <el-form-item
  43. v-show="form.type == 'ONLINE'"
  44. label="密匙"
  45. class="input"
  46. prop="accessKey"
  47. >
  48. <el-input v-model="form.accessKey" maxlength="255" />
  49. </el-form-item>
  50. <el-form-item
  51. v-show="form.type == 'ONLINE'"
  52. label="密钥"
  53. class="input"
  54. prop="accessSecret"
  55. >
  56. <el-input v-model="form.accessSecret" maxlength="255" />
  57. </el-form-item>
  58. <el-form-item v-show="form.type == 'OFFLINE'" label="导入授权文件">
  59. <el-upload
  60. ref="upload"
  61. class="form_left"
  62. accept=".lic"
  63. :action="uploadAction"
  64. :headers="uploadHeaders"
  65. :data="uploadData"
  66. :on-success="uploadSuccess"
  67. :on-error="uploadError"
  68. :file-list="fileList"
  69. :auto-upload="false"
  70. :multiple="false"
  71. >
  72. <el-button
  73. slot="trigger"
  74. size="small"
  75. type="primary"
  76. icon="icon icon-search-white"
  77. >
  78. 选择文件
  79. </el-button>
  80. </el-upload>
  81. </el-form-item>
  82. <el-form-item label=" ">
  83. <el-button
  84. v-show="form.type == 'OFFLINE'"
  85. type="primary"
  86. size="small"
  87. @click="exportFile"
  88. >导出硬件信息</el-button
  89. >
  90. <el-button type="primary" size="small" @click="submitForm"
  91. >保存</el-button
  92. >
  93. </el-form-item>
  94. </el-form>
  95. </div>
  96. </section>
  97. </template>
  98. <script>
  99. import { QUESTION_API } from "@/constants/constants";
  100. import { mapState } from "vuex";
  101. export default {
  102. data() {
  103. return {
  104. uploadAction: QUESTION_API + "/system/auth/offline",
  105. uploadHeaders: {},
  106. uploadData: {},
  107. fileList: [],
  108. info: {
  109. activation: "",
  110. expire: "",
  111. type: "",
  112. maxCount: "",
  113. onlineCount: 0,
  114. },
  115. form: {
  116. type: "ONLINE",
  117. accessKey: "",
  118. accessSecret: "",
  119. },
  120. rules: {
  121. accessKey: [
  122. {
  123. required: true,
  124. message: "请输入密匙",
  125. trigger: ["blur", "change"],
  126. },
  127. ],
  128. accessSecret: [
  129. {
  130. required: true,
  131. message: "请输入密钥",
  132. trigger: ["blur", "change"],
  133. },
  134. ],
  135. },
  136. };
  137. },
  138. computed: {
  139. ...mapState({ user: (state) => state.user }),
  140. },
  141. created() {
  142. this.init();
  143. },
  144. methods: {
  145. init() {
  146. this.uploadHeaders = {
  147. key: this.user.key,
  148. token: this.user.token,
  149. };
  150. this.searchForm();
  151. },
  152. searchForm() {
  153. var url = QUESTION_API + "/system/auth/info";
  154. this.$httpWithMsg.get(url).then((response) => {
  155. if (response.data.auth == true) {
  156. this.info.activation = "已授权";
  157. this.info.expire = response.data.expireTime;
  158. this.info.maxCount = response.data.maxOnlineUserCount;
  159. this.info.onlineCount = response.data.onlineUserCount;
  160. this.info.type =
  161. response.data.type == "ONLINE" ? "在线激活" : "离线激活";
  162. } else {
  163. this.info.activation = "未授权";
  164. }
  165. });
  166. },
  167. //提交
  168. submitForm() {
  169. if (this.form.type == "OFFLINE") {
  170. this.submitUpload();
  171. } else {
  172. var url = QUESTION_API + "/system/auth/online";
  173. this.$refs.form.validate((valid) => {
  174. if (valid) {
  175. this.$httpWithMsg.post(url, this.form).then(() => {
  176. this.$notify({
  177. type: "success",
  178. message: "授权成功",
  179. });
  180. this.searchForm();
  181. this.addingDialog = false;
  182. });
  183. } else {
  184. return false;
  185. }
  186. });
  187. }
  188. },
  189. exportFile() {
  190. window.open(
  191. QUESTION_API +
  192. "/system/auth/device/info?$key=" +
  193. this.user.key +
  194. "&$token=" +
  195. this.user.token
  196. );
  197. },
  198. submitUpload() {
  199. this.$refs.upload.submit();
  200. },
  201. uploadSuccess(response) {
  202. if (!response.hasError) {
  203. this.$notify({
  204. message: "授权成功",
  205. type: "success",
  206. });
  207. this.searchForm();
  208. }
  209. },
  210. uploadError(response) {
  211. var json = JSON.parse(response.message);
  212. if (response.status == 500) {
  213. this.$notify({
  214. message: json.desc,
  215. type: "error",
  216. });
  217. }
  218. },
  219. },
  220. };
  221. </script>