form.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <!-- 添加或修改项目信息对话框 -->
  3. <div class="el-drawer__wrapper">
  4. <el-drawer :title="title" v-model="visible" direction="rtl" size="100%">
  5. <div class="page-container form-container">
  6. <div class="form-btns-container">
  7. <span class="title-label"
  8. ><el-icon>
  9. <Document />
  10. </el-icon>
  11. 项目信息</span
  12. >
  13. <el-button-group>
  14. <el-button
  15. v-if="editStatus"
  16. type="primary"
  17. size="small"
  18. icon="Finished"
  19. @click="submitForm"
  20. >保存</el-button
  21. >
  22. <el-button
  23. v-else
  24. type="warning"
  25. size="small"
  26. icon="Edit"
  27. @click="editStatus = true"
  28. >编辑</el-button
  29. >
  30. <el-button
  31. v-if="form.id && editStatus"
  32. type="info"
  33. size="small"
  34. icon="Close"
  35. @click="editStatus = false"
  36. >取消编辑</el-button
  37. >
  38. <el-button
  39. v-if="form.id"
  40. type="success"
  41. size="small"
  42. @click="getForm"
  43. >
  44. <i class="fa fa-refresh" aria-hidden="true" /> 刷新
  45. </el-button>
  46. </el-button-group>
  47. <div class="close-btn" @click="cancel">
  48. <i class="fa fa-times" aria-hidden="true" />
  49. <!-- <span>关闭</span> -->
  50. </div>
  51. </div>
  52. <div
  53. class="Y-scrollbar"
  54. style="
  55. position: absolute;
  56. top: 32px;
  57. bottom: 0;
  58. width: 100%;
  59. overflow: auto;
  60. "
  61. ></div>
  62. <el-form
  63. ref="notificationRef"
  64. class="master-container"
  65. :model="form"
  66. :rules="rules"
  67. label-width="120px"
  68. >
  69. <el-row :gutter="30">
  70. <el-col :span="6"
  71. ><el-form-item label="公告标题" prop="title">
  72. <el-input
  73. v-if="editStatus"
  74. v-model="form.title"
  75. placeholder="请输入公告标题"
  76. />
  77. <span v-else>{{ form.title }}</span>
  78. </el-form-item>
  79. <el-form-item label="备注" prop="remark">
  80. <el-input
  81. v-if="editStatus"
  82. v-model="form.remark"
  83. placeholder="请输入备注"
  84. />
  85. <span v-else>{{ form.remark }}</span>
  86. </el-form-item></el-col
  87. >
  88. </el-row>
  89. <el-form-item label="公告内容">
  90. <wangEditor
  91. class="WangEditor"
  92. @select="getRich"
  93. ref="childrenRef"
  94. :editValue="editValue"
  95. />
  96. </el-form-item>
  97. </el-form>
  98. </div>
  99. </el-drawer>
  100. </div>
  101. </template>
  102. <script setup>
  103. import {
  104. getNotification,
  105. addNotification,
  106. updateNotification,
  107. } from "@/api/business/notification";
  108. import "@wangeditor/editor/dist/css/style.css";
  109. import { onMounted, reactive, ref, watch, nextTick } from "vue";
  110. import wangEditor from "./wangEditor";
  111. const { proxy } = getCurrentInstance();
  112. /** 父组件传参 */
  113. const props = defineProps({
  114. getList: {
  115. type: Function,
  116. default: () => {},
  117. },
  118. });
  119. const { getList } = toRefs(props);
  120. /** 字典数组区 */
  121. /** 表单抽屉 页变量 */
  122. const title = ref("");
  123. const loading = ref(false);
  124. const multiple = ref(true);
  125. const visible = ref(false);
  126. const editStatus = ref(false);
  127. const isFullscreen = ref(false);
  128. const editorRef = ref(null);
  129. const webHost = import.meta.env.VITE_APP_BASE_API;
  130. const editValue = ref("");
  131. watch(
  132. props,
  133. (newUser, oldUser) => {
  134. if (props.dataRow && props.dataRow.id) {
  135. // 富文本回显
  136. form.value.content = props.dataRow.content;
  137. editValue.value = form.value.content;
  138. }
  139. },
  140. {
  141. deep: true,
  142. immediate: true,
  143. }
  144. );
  145. const data = reactive({
  146. form: {},
  147. rules: {
  148. title: [{ required: true, message: "公告标题不能为空", trigger: "blur" }],
  149. type: [{ required: true, message: "公告类型不能为空", trigger: "change" }],
  150. content: [{ required: true, message: "公告内容不能为空", trigger: "blur" }],
  151. updateContent: [
  152. { required: true, message: "更新中公告内容不能为空", trigger: "blur" },
  153. ],
  154. status: [
  155. { required: true, message: "公告状态不能为空", trigger: "change" },
  156. ],
  157. },
  158. });
  159. const { form, rules } = toRefs(data);
  160. /*********************** 方法区 ****************************/
  161. /** 打开抽屉 */
  162. function open(id) {
  163. reset();
  164. visible.value = true;
  165. if (id) {
  166. getNotification(id).then((response) => {
  167. form.value = response.data;
  168. editStatus.value = false;
  169. title.value = "修改项目信息";
  170. });
  171. } else {
  172. editStatus.value = true;
  173. title.value = "添加项目信息";
  174. }
  175. }
  176. //当编辑器的内容更新时,获取该值
  177. const getRich = function (value) {
  178. form.value.content = value;
  179. };
  180. /** 取消按钮 */
  181. function cancel() {
  182. visible.value = false;
  183. reset();
  184. }
  185. /** 表单重置 */
  186. function reset() {
  187. form.value = {
  188. id: null,
  189. title: null,
  190. type: null,
  191. content: null,
  192. updateContent: null,
  193. status: null,
  194. createTime: null,
  195. creatorId: null,
  196. updateId: null,
  197. updateTime: null,
  198. remark: null,
  199. deleted: null,
  200. version: null,
  201. };
  202. proxy.resetForm("notificationRef");
  203. }
  204. /** 全屏缩放 */
  205. function handleScreen() {
  206. const dom = document.querySelector(
  207. ".list-container > .el-drawer__wrapper > .el-overlay"
  208. );
  209. isFullscreen.value = !isFullscreen.value;
  210. dom.style.position = isFullscreen.value ? "fixed" : "absolute";
  211. }
  212. /** 提交按钮 */
  213. function submitForm() {
  214. proxy.$refs["notificationRef"].validate((valid) => {
  215. if (valid) {
  216. if (form.value.id != null) {
  217. updateNotification(form.value).then((response) => {
  218. proxy.$modal.msgSuccess("修改成功");
  219. visible.value = false;
  220. getList.value();
  221. });
  222. } else {
  223. addNotification(form.value).then((response) => {
  224. proxy.$modal.msgSuccess("新增成功");
  225. visible.value = false;
  226. getList.value();
  227. });
  228. }
  229. }
  230. });
  231. }
  232. /** 查询表单信息 */
  233. function getForm() {
  234. loading.value = true;
  235. getNotification(form.value.id).then((response) => {
  236. loading.value = false;
  237. form.value = response.data;
  238. });
  239. }
  240. /** 暴露给父组件的方法 */
  241. defineExpose({
  242. open,
  243. });
  244. </script>