language.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <div class="tenant">
  3. <byTable :source="sourceList.data" :pagination="sourceList.pagination" :config="config" :loading="loading" highlight-current-row
  4. :selectConfig="selectConfig" :table-events="{
  5. select: select,
  6. }" :action-list="[
  7. {
  8. text: '添加祝福语',
  9. action: () => openModal('add'),
  10. },
  11. ]" @get-list="getList">
  12. </byTable>
  13. <el-dialog z-index="1100" :title="modalType == 'add' ? '添加祝福语' : '编辑祝福语'" v-if="dialogVisible" v-model="dialogVisible" width="800px"
  14. v-loading="loading">
  15. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="byform">
  16. </byForm>
  17. <template #footer>
  18. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  19. <el-button type="primary" @click="submitForm" size="large" :loading="submitLoading">确 定</el-button>
  20. </template>
  21. </el-dialog>
  22. </div>
  23. </template>
  24. <script setup>
  25. import { ElMessage, ElMessageBox } from "element-plus";
  26. import byTable from "@/components/byTable/index";
  27. import byForm from "@/components/byForm/index";
  28. import { computed, nextTick, reactive, ref } from "vue";
  29. const { proxy } = getCurrentInstance();
  30. const router = useRouter();
  31. const loading = ref(false);
  32. const blessingTypeList = ref([]);
  33. const submitLoading = ref(false);
  34. const sourceList = ref({
  35. data: [],
  36. pagination: {
  37. total: 0,
  38. pageNum: 1,
  39. pageSize: 10,
  40. },
  41. });
  42. let rules = ref({
  43. blessingType: [
  44. { required: true, message: "请选择祝福语类型", trigger: "change" },
  45. ],
  46. blessing_content: [
  47. { required: true, message: "请输入祝福内容", trigger: "blur" },
  48. ],
  49. });
  50. let dialogVisible = ref(false);
  51. let modalType = ref("add");
  52. const selectConfig = computed(() => {
  53. return [
  54. {
  55. label: "祝福语类型",
  56. prop: "blessingType",
  57. data: blessingTypeList.value,
  58. },
  59. ];
  60. });
  61. const config = computed(() => {
  62. return [
  63. {
  64. attrs: {
  65. label: "祝福语类型",
  66. prop: "blessingType",
  67. width: "240",
  68. align: "left",
  69. },
  70. render(type) {
  71. return proxy.dictValueLabel(type, blessingTypeList.value);
  72. },
  73. },
  74. {
  75. attrs: {
  76. label: "祝福内容",
  77. prop: "blessingContent",
  78. align: "left",
  79. },
  80. },
  81. {
  82. attrs: {
  83. label: "操作",
  84. width: "120",
  85. align: "center",
  86. },
  87. renderHTML(row) {
  88. return [
  89. {
  90. attrs: {
  91. label: "修改",
  92. type: "primary",
  93. text: true,
  94. },
  95. el: "button",
  96. click() {
  97. getDtl(row);
  98. },
  99. },
  100. {
  101. attrs: {
  102. label: "删除",
  103. type: "danger",
  104. text: true,
  105. },
  106. el: "button",
  107. click() {
  108. ElMessageBox.confirm(
  109. "此操作将永久删除该数据, 是否继续?",
  110. "提示",
  111. {
  112. confirmButtonText: "确定",
  113. cancelButtonText: "取消",
  114. type: "warning",
  115. }
  116. ).then(() => {});
  117. },
  118. },
  119. ];
  120. },
  121. },
  122. ];
  123. });
  124. let formData = reactive({
  125. data: {
  126. coverList: [],
  127. audioList: [],
  128. },
  129. });
  130. const formOption = reactive({
  131. inline: true,
  132. labelWidth: 100,
  133. itemWidth: 100,
  134. rules: [],
  135. });
  136. const byform = ref(null);
  137. const formConfig = computed(() => {
  138. return [
  139. {
  140. type: "select",
  141. prop: "blessingType",
  142. label: "祝福语类型",
  143. data: blessingTypeList.value,
  144. required: true,
  145. },
  146. {
  147. type: "input",
  148. itemType: "textarea",
  149. rows: 10,
  150. prop: "blessingContent",
  151. label: "祝福内容",
  152. required: true,
  153. },
  154. ];
  155. });
  156. const getDictlist = async () => {
  157. proxy.getDictOne(["blessing_type"]).then((res) => {
  158. blessingTypeList.value = res["blessing_type"].map((x) => ({
  159. label: x.dictValue,
  160. value: x.dictKey,
  161. }));
  162. });
  163. };
  164. const getList = async (req) => {
  165. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  166. loading.value = true;
  167. proxy
  168. .post("/blessingLanguage/page", sourceList.value.pagination)
  169. .then((res) => {
  170. sourceList.value.data = res.rows;
  171. sourceList.value.pagination.total = res.total;
  172. setTimeout(() => {
  173. loading.value = false;
  174. }, 200);
  175. });
  176. };
  177. const openModal = () => {
  178. dialogVisible.value = true;
  179. modalType.value = "add";
  180. formData.data = {
  181. content: "",
  182. };
  183. };
  184. const selection = ref({
  185. data: [],
  186. });
  187. const select = (_selection, row) => {
  188. selection.value.data = _selection;
  189. };
  190. const getDtl = (row) => {
  191. modalType.value = "edit";
  192. proxy.post("/blessingLanguage/detail", { id: row.id }).then((res) => {
  193. formData.data = res;
  194. dialogVisible.value = true;
  195. });
  196. };
  197. const submitForm = () => {
  198. byform.value.handleSubmit(() => {
  199. submitLoading.value = true;
  200. proxy.post("/blessingLanguage/" + modalType.value, formData.data).then(
  201. () => {
  202. ElMessage({
  203. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  204. type: "success",
  205. });
  206. dialogVisible.value = false;
  207. submitLoading.value = false;
  208. getList();
  209. },
  210. (err) => {
  211. console.log(err);
  212. submitLoading.value = false;
  213. }
  214. );
  215. });
  216. };
  217. getDictlist();
  218. getList();
  219. </script>
  220. <style lang='scss' scoped>
  221. .tenant {
  222. padding: 20px;
  223. .delete-btn {
  224. margin-top: 10px;
  225. margin-left: 25px;
  226. }
  227. }
  228. .avatar-uploader .avatar {
  229. width: 110px;
  230. height: 110px;
  231. display: block;
  232. background-color: black;
  233. }
  234. .avatar-uploader .el-upload {
  235. border: 1px dashed var(--el-border-color);
  236. border-radius: 6px;
  237. cursor: pointer;
  238. position: relative;
  239. overflow: hidden;
  240. transition: var(--el-transition-duration-fast);
  241. }
  242. .avatar-uploader .el-upload:hover {
  243. border-color: var(--el-color-primary);
  244. }
  245. .el-icon.avatar-uploader-icon {
  246. font-size: 28px;
  247. color: #8c939d;
  248. width: 110px;
  249. height: 110px;
  250. text-align: center;
  251. border: 1px dashed var(--el-border-color);
  252. }
  253. .pic {
  254. object-fit: contain;
  255. width: 50px;
  256. height: 50px;
  257. cursor: pointer;
  258. vertical-align: middle;
  259. }
  260. .blessingClass {
  261. background-image: url("../../../assets/victoria/sjk.jpg");
  262. background-size: cover;
  263. height: 600px;
  264. width: 300px;
  265. padding: 40px 19px;
  266. }
  267. </style>