authorityAppEdit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-11-29 09:18:04
  4. * @LastEditTime: 2022-03-17 14:09:47
  5. * @LastEditors: your name
  6. * @Description: 新增/编辑应用
  7. * @FilePath: \Foshan4A2.0\src\views\authorityManagement\components\addApp.vue
  8. -->
  9. <template>
  10. <div class="addApp flex-wrap">
  11. <!--新增应用-->
  12. <div class="addApp-form r24">
  13. <div class="addApp-form-title flex">
  14. <div class="title">
  15. 编辑应用
  16. <!-- <span class="isqy">
  17. <span>是否启用</span>
  18. <el-radio-group v-model="radio">
  19. <el-radio :label="1">是</el-radio>
  20. <el-radio :label="0">否</el-radio>
  21. </el-radio-group>
  22. </span> -->
  23. </div>
  24. <div class="btn">
  25. <!-- <el-button @click="deleteApp" class="r24" type="danger">删除</el-button> -->
  26. <el-button @click="onSubmit('form')" type="primary">保存</el-button>
  27. </div>
  28. </div>
  29. <div class="addApp-form-content dialog-public-background">
  30. <el-form ref="form" class="form" :rules="rules" :model="form" label-position="right" label-width="80px">
  31. <div class="flex">
  32. <el-form-item prop="name" label="应用名称">
  33. <el-input placeholder="请输入应用名称" v-model.trim="form.name"></el-input>
  34. </el-form-item>
  35. <el-form-item label="请求类型">
  36. <el-select @change="typeChange" v-model="form.id" placeholder="请求类型">
  37. <el-option label="get" :value="1"></el-option>
  38. <el-option label="post" :value="2"></el-option>
  39. </el-select>
  40. <!-- <el-input placeholder="请输入APPID" disabled v-model="form.id"></el-input> -->
  41. </el-form-item>
  42. <el-form-item prop="app" label="参数类型">
  43. <el-select :disabled="typeFlag" v-model="form.app" placeholder="参数类型">
  44. <el-option label="application/json" value="application/json"></el-option>
  45. <el-option label="application/text" value="application/text"></el-option>
  46. </el-select>
  47. <!-- <el-input placeholder="请输入参数类型" v-model.trim="form.app"></el-input> -->
  48. </el-form-item>
  49. </div>
  50. <el-form-item class="url" prop="url" label="应用地址">
  51. <el-input placeholder="请输入应用地址" v-model.trim="form.url"></el-input>
  52. </el-form-item>
  53. <el-form-item prop="desc" class="desc" label="描述">
  54. <el-input type="textarea" rows="3" placeholder="请输入描述" v-model.trim="form.desc"></el-input>
  55. </el-form-item>
  56. </el-form>
  57. <div class="addApp-form-title domain-title flex">
  58. <div class="title">参数管理</div>
  59. <div class="btn">
  60. <el-button @click="addDomain" type="primary">新增</el-button>
  61. </div>
  62. </div>
  63. <div class="addApp-form-content domain">
  64. <el-form :model="dynamicValidateForm" ref="dynamicValidateForm" label-width="85px" class="demo-dynamic">
  65. <div class="flex" v-for="(domain, index) in dynamicValidateForm.domains" :key="index">
  66. <div class="flex-wrap">
  67. <el-form-item label="入参名称" :prop="'domains.' + index + '.name'">
  68. <el-input placeholder="请输入最大64位参数名称" maxlength="64" v-model.trim="domain.AppInputName"></el-input>
  69. </el-form-item>
  70. <el-form-item label="入参类型" :prop="'domains.' + index + '.type'">
  71. <el-select v-model="domain.AppInputType" :disabled="typeFlag" placeholder="参数类型">
  72. <el-option label="string" value="string"></el-option>
  73. <el-option label="int" value="int"></el-option>
  74. </el-select>
  75. <!-- <el-input placeholder="请输入最大8位参数类型" maxlength="8" v-model.trim="domain.AppInputType"></el-input> -->
  76. </el-form-item>
  77. <el-form-item label="入参位置" :prop="'domains.' + index + '.place'">
  78. <el-select v-model="domain.AppInputSite" placeholder="参数位置">
  79. <el-option label="header" value="header"></el-option>
  80. <el-option label="body" value="body"></el-option>
  81. </el-select>
  82. <!-- <el-input placeholder="请输入最大8位参数位置" maxlength="8" v-model.trim="domain.AppInputSite"></el-input> -->
  83. </el-form-item>
  84. </div>
  85. <div>
  86. <el-button size="small" type="danger" @click.prevent="removeDomain(domain)">删除</el-button>
  87. </div>
  88. </div>
  89. </el-form>
  90. </div>
  91. </div>
  92. </div>
  93. <!--上传logo-->
  94. <div class="addApp-upload">
  95. <div class="flex-wrap">
  96. <div class="upload">
  97. <div class="title">上传Logo</div>
  98. <el-upload action="https://jsonplaceholder.typicode.com/posts/" list-type="picture-card" :on-preview="handlePictureCardPreview" :on-remove="handleRemove">
  99. <i class="el-icon-plus"></i>
  100. </el-upload>
  101. </div>
  102. <div class="preview">
  103. <div class="title">预览</div>
  104. <div class="box"></div>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </template>
  110. <script>
  111. import {
  112. GetAppDetails,
  113. EditApp,
  114. UpdateAppStatus,
  115. DeleteApp,
  116. } from "@/api/apiAuthority";
  117. import { lengthValidator } from '@/utils/validate'
  118. export default {
  119. name: "Addapp",
  120. data () {
  121. return {
  122. form: {
  123. //应用表单
  124. name: "",
  125. id: "",
  126. app: "",
  127. url: "",
  128. desc: "",
  129. },
  130. rules: {
  131. //表单验证
  132. name: [
  133. { required: true, message: "请输入应用名称", trigger: "blur" },
  134. { validator: lengthValidator, max: 32, message: '长度在 1 到 32 个字符', trigger: ['change', 'blur'] }
  135. ],
  136. url: [{ validator: lengthValidator, max: 128, message: '长度在 1 到 128 个字符', trigger: ['change', 'blur'] }],
  137. desc: [
  138. // { required: true, message: "请输入描述", trigger: "blur" },
  139. { validator: lengthValidator, max: 128, message: '长度在 1到 128 个字符', trigger: ['change', 'blur'] }
  140. ],
  141. app: [{ validator: lengthValidator, max: 32, message: '长度在 1 到 32 个字符', trigger: ['change', 'blur'] }]
  142. },
  143. radio: 1,
  144. AppId: null,
  145. type: null, //参数类型
  146. dialogImageUrl: "",
  147. dialogVisible: false,
  148. dynamicValidateForm: {
  149. domains: [{
  150. AppInputName: '',
  151. AppInputType: '',
  152. AppInputSite: ''
  153. }]
  154. },
  155. typeFlag: false
  156. };
  157. },
  158. created () {
  159. const { AuthId, Status } = this.$route.query;
  160. this.radio = Status;
  161. this.AppId = AuthId;
  162. this.getAppDetails(AuthId);
  163. },
  164. methods: {
  165. handleRemove (file, fileList) {
  166. console.log(file, fileList);
  167. },
  168. handlePictureCardPreview (file) {
  169. this.dialogImageUrl = file.url;
  170. this.dialogVisible = true;
  171. },
  172. //获取应用详情
  173. async getAppDetails (id) {
  174. try {
  175. const res = await GetAppDetails({
  176. AppId: id,
  177. });
  178. if (res.code === 0) {
  179. const { AppName, AppShowId, AppShowSecret, AppDesc, AppUrl, Inputs, RequestType, BodyType } =
  180. res.returnData;
  181. this.form.name = AppName;
  182. // this.form.id = AppShowId;
  183. // this.form.app = AppShowSecret;
  184. this.form.id = Number(RequestType) || '';
  185. this.form.app = BodyType;
  186. this.form.desc = AppDesc;
  187. this.form.url = AppUrl;
  188. this.dynamicValidateForm.domains = Inputs;
  189. this.typeFlag = this.form.id;
  190. } else {
  191. this.$message.error(res.message);
  192. }
  193. } catch (error) {
  194. console.log("出错了", error);
  195. }
  196. },
  197. //应用状态变更
  198. async handleChange (val) {
  199. try {
  200. const res = await UpdateAppStatus({
  201. AppId: this.AppId,
  202. Status: val,
  203. });
  204. if (res.code === 0) {
  205. this.$message.success(res.message);
  206. } else {
  207. this.$message.error(res.message);
  208. }
  209. } catch (error) {
  210. console.log("出错了", error);
  211. }
  212. },
  213. onSubmit (formName) {
  214. this.$refs[formName].validate((valid) => {
  215. if (valid) {
  216. this.editApp();
  217. } else {
  218. return false;
  219. }
  220. });
  221. },
  222. //应用状态变更
  223. async editApp () {
  224. try {
  225. const res = await EditApp({
  226. AppId: this.AppId,
  227. AppDesc: this.form.desc,
  228. AppName: this.form.name,
  229. AppUrl: this.form.url,
  230. RequestType: this.form.id,
  231. BodyType: this.form.app,
  232. Inputs: this.dynamicValidateForm.domains
  233. });
  234. if (res.code === 0) {
  235. this.$message.success(res.message);
  236. this.$store.dispatch("tagsView/delView", this.$route);
  237. this.$router.push("/authority");
  238. } else {
  239. this.$message.error(res.message);
  240. }
  241. } catch (error) {
  242. console.log("出错了", error);
  243. }
  244. },
  245. //应用删除
  246. async deleteApp () {
  247. try {
  248. const res = await DeleteApp({
  249. AppId: this.AppId,
  250. });
  251. if (res.code === 0) {
  252. this.$message.success(res.message);
  253. setTimeout(() => {
  254. this.$router.push("/authority");
  255. }, 2000);
  256. } else {
  257. this.$message.error(res.message);
  258. }
  259. } catch (error) {
  260. console.log("出错了", error);
  261. }
  262. },
  263. removeDomain (item) {
  264. var index = this.dynamicValidateForm.domains.indexOf(item)
  265. if (index !== -1) {
  266. this.dynamicValidateForm.domains.splice(index, 1)
  267. }
  268. },
  269. addDomain () {
  270. this.dynamicValidateForm.domains.push({
  271. AppInputName: '',
  272. AppInputType: '',
  273. AppInputSite: '',
  274. AppId: this.AppId
  275. });
  276. },
  277. typeChange (val) {
  278. const datas = this.dynamicValidateForm.domains
  279. if (val == 1) {
  280. this.typeFlag = true;
  281. this.form.app = '';
  282. datas.forEach(item => {
  283. item.AppInputType = 'string';
  284. })
  285. } else {
  286. this.typeFlag = false;
  287. }
  288. }
  289. },
  290. };
  291. </script>
  292. <style lang="scss" scoped>
  293. .addApp {
  294. padding: 0 64px;
  295. padding-top: 32px;
  296. .addApp-form {
  297. flex: 1;
  298. background: #ffffff;
  299. box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
  300. border-radius: 16px;
  301. padding: 32px 32px 40px 32px;
  302. .title {
  303. font-size: 24px;
  304. font-family: Microsoft YaHei;
  305. font-weight: bold;
  306. color: #303133;
  307. .isqy {
  308. span {
  309. font-weight: 400;
  310. font-size: 14px;
  311. margin: 0 28px 0 42px;
  312. }
  313. }
  314. }
  315. .addApp-form-content {
  316. margin-top: 40px;
  317. ::v-deep .form {
  318. .el-input__inner {
  319. height: 32px;
  320. line-height: 32px;
  321. }
  322. .content {
  323. .el-form-item__content {
  324. flex: 1;
  325. }
  326. .el-form-item__label {
  327. margin-left: 27px;
  328. }
  329. }
  330. textarea {
  331. resize: none;
  332. }
  333. }
  334. }
  335. .domain {
  336. ::v-deep .demo-dynamic {
  337. .el-input__inner {
  338. height: 32px;
  339. line-height: 32px;
  340. }
  341. .el-button--danger {
  342. position: relative;
  343. top: 4px;
  344. }
  345. }
  346. }
  347. .domain-title {
  348. margin-top: 56px;
  349. }
  350. }
  351. .addApp-upload {
  352. width: 767px;
  353. background: #ffffff;
  354. box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
  355. border-radius: 16px;
  356. padding: 32px 32px 40px 32px;
  357. .title {
  358. font-size: 24px;
  359. font-family: Microsoft YaHei;
  360. font-weight: bold;
  361. color: #303133;
  362. margin-bottom: 22px;
  363. }
  364. ::v-deep .el-upload--picture-card {
  365. height: 160px;
  366. line-height: 160px;
  367. width: 160px;
  368. background: #f5f7fa;
  369. border: 1px dashed #767eba;
  370. border-radius: 4px;
  371. .el-icon-plus {
  372. font-size: 51px;
  373. color: #767eba;
  374. }
  375. }
  376. .preview {
  377. margin-left: 40px;
  378. .box {
  379. width: 160px;
  380. height: 160px;
  381. background: #3b3c3d;
  382. border-radius: 4px;
  383. }
  384. }
  385. }
  386. }
  387. </style>