clientConfig.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <template>
  2. <el-container>
  3. <el-main class="el-main-padding">
  4. <el-form
  5. :model="ruleForm"
  6. :rules="rules"
  7. ref="ruleForm"
  8. label-width="120px"
  9. class="demo-ruleForm"
  10. :inline-message="true"
  11. >
  12. <el-form-item label="系统名称" prop="OE_STUDENT_SYS_NAME">
  13. <el-input
  14. v-model="ruleForm.OE_STUDENT_SYS_NAME"
  15. placeholder="请输入系统名称"
  16. class="input-width"
  17. ></el-input>
  18. </el-form-item>
  19. <el-form-item label="学校logo" prop="LOGO_FILE_URL">
  20. <el-upload
  21. class="upload-width"
  22. ref="upload"
  23. accept=".png"
  24. :action="uploadAction"
  25. :headers="uploadHeaders"
  26. :data="uploadData"
  27. :before-upload="beforeUpload"
  28. :on-progress="uploadProgress"
  29. :on-success="uploadSuccess"
  30. :on-error="uploadError"
  31. :on-remove="handleRemove"
  32. :file-list="fileList"
  33. :auto-upload="false"
  34. :multiple="false"
  35. :limit="1"
  36. :on-exceed="handleExceed"
  37. list-type="picture"
  38. >
  39. <el-button size="small" slot="trigger" type="primary"
  40. >选择文件</el-button
  41. >&nbsp;
  42. <el-button size="small" type="success" @click="submitUpload"
  43. >确认上传</el-button
  44. >
  45. <el-button size="small" type="danger" @click="removeFile"
  46. >清空文件</el-button
  47. >
  48. <div slot="tip" class="el-upload__tip">
  49. 图片大小(长*宽)为400*100的png文件
  50. </div>
  51. </el-upload>
  52. <el-input v-show="false" v-model="ruleForm.LOGO_FILE_URL"></el-input>
  53. </el-form-item>
  54. <el-form-item label="登录方式选择" prop="loginType">
  55. <el-checkbox-group v-model="ruleForm.loginType">
  56. <el-checkbox
  57. v-for="lt in loginTypes"
  58. name="loginType"
  59. :label="lt.code"
  60. v-model="lt.code"
  61. :key="lt.code"
  62. >{{ lt.name }}</el-checkbox
  63. >
  64. </el-checkbox-group>
  65. </el-form-item>
  66. <el-form-item label="防作弊配置" prop="preventCheatingConfig">
  67. <el-checkbox-group v-model="ruleForm.preventCheatingConfig">
  68. <el-checkbox
  69. v-for="pcc in preventCheatingConfigs"
  70. name="preventCheatingConfig"
  71. :label="pcc.code"
  72. v-model="pcc.code"
  73. :key="pcc.code"
  74. >{{ pcc.name }}</el-checkbox
  75. >
  76. </el-checkbox-group>
  77. </el-form-item>
  78. <el-form-item
  79. v-show="false"
  80. label="窗口默认大小"
  81. prop="STUDENT_CLIENT_DEFAULT_SIZE"
  82. >
  83. <el-input
  84. v-model="ruleForm.STUDENT_CLIENT_DEFAULT_SIZE"
  85. placeholder="窗口大小格式为:宽度*高度"
  86. class="input-width"
  87. ></el-input>
  88. </el-form-item>
  89. <el-form-item label="控制台配置" prop="STUDENT_CLIENT_CONSOLE_CONFIG">
  90. <el-input
  91. v-model="ruleForm.STUDENT_CLIENT_CONSOLE_CONFIG"
  92. placeholder="系统预留,无需配置"
  93. class="input-width"
  94. ></el-input>
  95. </el-form-item>
  96. <el-form-item>
  97. <el-button type="primary" @click="submitForm('ruleForm')"
  98. >保 存</el-button
  99. >
  100. <!-- <el-button class="btn-margin-left" @click="resetForm('ruleForm')">取 消</el-button> -->
  101. </el-form-item>
  102. </el-form>
  103. </el-main>
  104. </el-container>
  105. </template>
  106. <script>
  107. import { mapState } from "vuex";
  108. import {
  109. LOGIN_TYPE,
  110. PREVENT_CHEATING_CONFIG,
  111. CORE_API
  112. } from "@/constants/constants.js";
  113. export default {
  114. data() {
  115. return {
  116. rootOrgId: null,
  117. loginTypes: LOGIN_TYPE,
  118. propertyGroupId: "",
  119. preventCheatingConfigs: PREVENT_CHEATING_CONFIG,
  120. ruleForm: {
  121. relatedPropertyGroupIdList: [],
  122. orgId: null,
  123. OE_STUDENT_SYS_NAME: "",
  124. LOGO_FILE_URL: "",
  125. LOGIN_TYPE: "",
  126. PREVENT_CHEATING_CONFIG: "",
  127. STUDENT_CLIENT_DEFAULT_SIZE: "",
  128. STUDENT_CLIENT_CONSOLE_CONFIG: "",
  129. properties: {
  130. OE_STUDENT_SYS_NAME: "",
  131. LOGO_FILE_URL: "",
  132. LOGIN_TYPE: "",
  133. PREVENT_CHEATING_CONFIG: "",
  134. STUDENT_CLIENT_DEFAULT_SIZE: "",
  135. STUDENT_CLIENT_CONSOLE_CONFIG: ""
  136. },
  137. loginType: [],
  138. preventCheatingConfig: []
  139. },
  140. logoDialog: false,
  141. uploadAction: "",
  142. uploadHeaders: {},
  143. uploadData: {},
  144. fileList: [],
  145. rules: {
  146. OE_STUDENT_SYS_NAME: [
  147. { required: true, message: "请输入系统名称", trigger: "blur" },
  148. { min: 1, max: 50, message: "长度在 1 到 50 个字符", trigger: "blur" }
  149. ],
  150. LOGO_FILE_URL: [
  151. { required: true, message: "请上传学校logo", trigger: "change" }
  152. ],
  153. loginType: [
  154. {
  155. type: "array",
  156. required: true,
  157. message: "请至少选择一个登录方式",
  158. trigger: "change"
  159. }
  160. ],
  161. STUDENT_CLIENT_DEFAULT_SIZE: [
  162. { required: true, message: "请输入客户端默认大小", trigger: "blur" }
  163. ]
  164. }
  165. };
  166. },
  167. methods: {
  168. submitForm(formName) {
  169. this.$refs[formName].validate(valid => {
  170. if (valid) {
  171. this.ruleForm.properties.OE_STUDENT_SYS_NAME = this.ruleForm.OE_STUDENT_SYS_NAME;
  172. this.ruleForm.properties.LOGO_FILE_URL = this.ruleForm.LOGO_FILE_URL;
  173. this.ruleForm.properties.STUDENT_CLIENT_DEFAULT_SIZE = this.ruleForm.STUDENT_CLIENT_DEFAULT_SIZE;
  174. this.ruleForm.properties.STUDENT_CLIENT_CONSOLE_CONFIG = this.ruleForm.STUDENT_CLIENT_CONSOLE_CONFIG;
  175. this.ruleForm.properties.LOGIN_TYPE = this.ruleForm.LOGIN_TYPE = this.ruleForm.loginType.join(
  176. ","
  177. );
  178. if (
  179. this.ruleForm.preventCheatingConfig == null ||
  180. this.ruleForm.preventCheatingConfig.length == 0
  181. ) {
  182. this.ruleForm.properties.PREVENT_CHEATING_CONFIG = this.ruleForm.PREVENT_CHEATING_CONFIG =
  183. "NONE";
  184. } else {
  185. this.ruleForm.properties.PREVENT_CHEATING_CONFIG = this.ruleForm.PREVENT_CHEATING_CONFIG = this.ruleForm.preventCheatingConfig.join(
  186. ","
  187. );
  188. }
  189. this.$httpWithMsg
  190. .put(CORE_API + "/org/saveOrgProperties", this.ruleForm)
  191. .then(
  192. () => {
  193. this.$notify({
  194. message: "保存成功",
  195. type: "success"
  196. });
  197. },
  198. () => {}
  199. );
  200. } else {
  201. console.log("error submit!!");
  202. return false;
  203. }
  204. });
  205. },
  206. initForm() {
  207. this.ruleForm.orgId = this.user.rootOrgId;
  208. this.ruleForm.STUDENT_CLIENT_DEFAULT_SIZE = "1400*900";
  209. this.ruleForm.relatedPropertyGroupIdList = ["studentClientConfig"];
  210. var url =
  211. CORE_API +
  212. "/org/getOrgPropertiesByGroupWithoutCache/" +
  213. this.rootOrgId +
  214. "/" +
  215. this.propertyGroupId;
  216. this.$httpWithMsg.get(url).then(response => {
  217. console.log(response);
  218. if (response) {
  219. this.ruleForm.properties = response.data;
  220. // if (this.ruleForm.properties.OE_STUDENT_SYS_NAME) {
  221. this.ruleForm.OE_STUDENT_SYS_NAME =
  222. this.ruleForm.properties.OE_STUDENT_SYS_NAME ||
  223. this.ruleForm.OE_STUDENT_SYS_NAME;
  224. // }
  225. this.ruleForm.LOGO_FILE_URL =
  226. this.ruleForm.properties.LOGO_FILE_URL ||
  227. this.ruleForm.LOGO_FILE_URL;
  228. this.ruleForm.LOGIN_TYPE =
  229. this.ruleForm.properties.LOGIN_TYPE || this.ruleForm.LOGIN_TYPE;
  230. this.ruleForm.PREVENT_CHEATING_CONFIG =
  231. this.ruleForm.properties.PREVENT_CHEATING_CONFIG ||
  232. this.ruleForm.PREVENT_CHEATING_CONFIG;
  233. this.ruleForm.STUDENT_CLIENT_DEFAULT_SIZE =
  234. this.ruleForm.properties.STUDENT_CLIENT_DEFAULT_SIZE ||
  235. this.ruleForm.STUDENT_CLIENT_DEFAULT_SIZE;
  236. this.ruleForm.STUDENT_CLIENT_CONSOLE_CONFIG =
  237. this.ruleForm.properties.STUDENT_CLIENT_CONSOLE_CONFIG ||
  238. this.ruleForm.STUDENT_CLIENT_CONSOLE_CONFIG;
  239. if (this.ruleForm.properties.LOGIN_TYPE) {
  240. this.ruleForm.loginType = this.ruleForm.properties.LOGIN_TYPE.split(
  241. ","
  242. );
  243. } else {
  244. let defaultValue = [];
  245. for (let lt of LOGIN_TYPE) {
  246. defaultValue.push(lt.code);
  247. }
  248. this.ruleForm.loginType = defaultValue;
  249. console.log(defaultValue);
  250. }
  251. if (this.ruleForm.properties.PREVENT_CHEATING_CONFIG) {
  252. this.ruleForm.preventCheatingConfig = this.ruleForm.properties.PREVENT_CHEATING_CONFIG.split(
  253. ","
  254. );
  255. } else {
  256. let defaultValue = [];
  257. for (let lt of PREVENT_CHEATING_CONFIG) {
  258. defaultValue.push(lt.code);
  259. }
  260. this.ruleForm.preventCheatingConfig = defaultValue;
  261. console.log(defaultValue);
  262. }
  263. let fileUrl = response.data.LOGO_FILE_URL;
  264. let fname = "";
  265. if (fileUrl) {
  266. let lastIndex = fileUrl.lastIndexOf("/");
  267. let len = fileUrl.length;
  268. fname = fileUrl.substr(lastIndex + 1, len - lastIndex);
  269. this.fileList = [{ name: fname, url: this.ruleForm.LOGO_FILE_URL }];
  270. } else {
  271. this.fileList = [];
  272. }
  273. } else {
  274. this.$notify({
  275. message: "学生客户端信息暂未初始化,请立即初始化",
  276. type: "warning"
  277. });
  278. }
  279. });
  280. },
  281. // resetForm(formName) {
  282. // this.$refs[formName].resetFields();
  283. // },
  284. initUpload() {
  285. this.fileList = [];
  286. },
  287. beforeUpload(file) {
  288. if (!this.checkUpload()) {
  289. return false;
  290. }
  291. console.log(file);
  292. },
  293. uploadProgress() {
  294. console.log("uploadProgress");
  295. },
  296. uploadSuccess(response) {
  297. console.log("uploadSuccess");
  298. console.log(response);
  299. if (response && response.length > 0) {
  300. this.$notify({
  301. message: "上传成功",
  302. type: "success"
  303. });
  304. let fileUrl = response;
  305. this.ruleForm.LOGO_FILE_URL = this.ruleForm.properties.LOGO_FILE_URL = fileUrl;
  306. } else {
  307. this.errDialog = true;
  308. }
  309. this.fileLoading = false;
  310. this.logoDialog = false;
  311. // this.removeFile();
  312. },
  313. uploadError(response) {
  314. let json = JSON.parse(response.message);
  315. if (response.status == 500) {
  316. this.$notify({
  317. message: json.desc,
  318. type: "error"
  319. });
  320. }
  321. this.fileLoading = false;
  322. },
  323. //确定上传
  324. submitUpload() {
  325. if (!this.checkUpload()) {
  326. return false;
  327. }
  328. this.$refs.upload.submit();
  329. this.fileLoading = true;
  330. },
  331. checkUpload() {
  332. var fileList = this.$refs.upload.uploadFiles;
  333. if (fileList.length == 0) {
  334. this.$notify({
  335. message: "上传文件不能为空",
  336. type: "error"
  337. });
  338. return false;
  339. }
  340. if (fileList.length > 1) {
  341. this.$notify({
  342. message: "每次只能上传一个文件",
  343. type: "error"
  344. });
  345. return false;
  346. }
  347. for (let file of fileList) {
  348. var fileName = file.name;
  349. if (
  350. // !fileName.endsWith(".jpg") &&
  351. // !fileName.endsWith(".gif") &&
  352. !fileName.endsWith(".png")
  353. ) {
  354. this.$notify({
  355. message: "上传文件格式必须为[png]",
  356. type: "error"
  357. });
  358. this.initUpload();
  359. return false;
  360. }
  361. }
  362. return true;
  363. },
  364. //清空文件
  365. removeFile() {
  366. this.fileList = [];
  367. this.ruleForm.LOGO_FILE_URL = this.ruleForm.properties.LOGO_FILE_URL = "";
  368. if (this.$refs.upload) {
  369. this.$refs.upload.clearFiles();
  370. }
  371. },
  372. handleRemove(file, fileList) {
  373. console.log(file, fileList);
  374. this.removeFile();
  375. },
  376. handleExceed() {
  377. this.$notify({
  378. message: "当前限制选择 1 个文件,请先清空文件再试",
  379. type: "error"
  380. });
  381. }
  382. },
  383. created() {
  384. this.rootOrgId = this.user.rootOrgId;
  385. this.propertyGroupId = "studentClientConfig4Edit";
  386. this.uploadAction = CORE_API + "/org/importLogo/" + this.rootOrgId;
  387. this.uploadHeaders = {
  388. key: this.user.key,
  389. token: this.user.token
  390. };
  391. console.log(this.propertyGroupId);
  392. this.initForm();
  393. },
  394. computed: {
  395. ...mapState({ user: state => state.user })
  396. }
  397. };
  398. </script>
  399. <style scoped>
  400. .input-width {
  401. width: 638px;
  402. }
  403. .upload-width {
  404. width: 638px;
  405. }
  406. /* .btn-margin-left {
  407. margin-left: 20px;
  408. } */
  409. </style>