language.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. blessingContent: [
  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. proxy
  119. .post("/blessingLanguage/delete", {
  120. id: row.id,
  121. })
  122. .then((res) => {
  123. ElMessage({
  124. message: "删除成功",
  125. type: "success",
  126. });
  127. getList();
  128. });
  129. });
  130. },
  131. },
  132. ];
  133. },
  134. },
  135. ];
  136. });
  137. let formData = reactive({
  138. data: {
  139. coverList: [],
  140. audioList: [],
  141. },
  142. });
  143. const formOption = reactive({
  144. inline: true,
  145. labelWidth: 100,
  146. itemWidth: 100,
  147. rules: [],
  148. });
  149. const byform = ref(null);
  150. const formConfig = computed(() => {
  151. return [
  152. {
  153. type: "select",
  154. prop: "blessingType",
  155. label: "祝福语类型",
  156. data: blessingTypeList.value,
  157. required: true,
  158. },
  159. {
  160. type: "input",
  161. itemType: "textarea",
  162. rows: 10,
  163. prop: "blessingContent",
  164. label: "祝福内容",
  165. required: true,
  166. },
  167. ];
  168. });
  169. const getDictlist = async () => {
  170. proxy.getDictOne(["blessing_type"]).then((res) => {
  171. blessingTypeList.value = res["blessing_type"].map((x) => ({
  172. label: x.dictValue,
  173. value: x.dictKey,
  174. }));
  175. });
  176. };
  177. const getList = async (req) => {
  178. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  179. loading.value = true;
  180. proxy
  181. .post("/blessingLanguage/page", sourceList.value.pagination)
  182. .then((res) => {
  183. sourceList.value.data = res.rows;
  184. sourceList.value.pagination.total = res.total;
  185. setTimeout(() => {
  186. loading.value = false;
  187. }, 200);
  188. });
  189. };
  190. const openModal = () => {
  191. dialogVisible.value = true;
  192. modalType.value = "add";
  193. formData.data = {
  194. content: "",
  195. };
  196. };
  197. const selection = ref({
  198. data: [],
  199. });
  200. const select = (_selection, row) => {
  201. selection.value.data = _selection;
  202. };
  203. const getDtl = (row) => {
  204. modalType.value = "edit";
  205. proxy.post("/blessingLanguage/detail", { id: row.id }).then((res) => {
  206. formData.data = res;
  207. dialogVisible.value = true;
  208. });
  209. };
  210. const submitForm = () => {
  211. byform.value.handleSubmit(() => {
  212. submitLoading.value = true;
  213. proxy.post("/blessingLanguage/" + modalType.value, formData.data).then(
  214. () => {
  215. ElMessage({
  216. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  217. type: "success",
  218. });
  219. dialogVisible.value = false;
  220. submitLoading.value = false;
  221. getList();
  222. },
  223. (err) => {
  224. submitLoading.value = false;
  225. }
  226. );
  227. });
  228. };
  229. getDictlist();
  230. getList();
  231. </script>
  232. <style lang='scss' scoped>
  233. .tenant {
  234. padding: 20px;
  235. .delete-btn {
  236. margin-top: 10px;
  237. margin-left: 25px;
  238. }
  239. }
  240. .avatar-uploader .avatar {
  241. width: 110px;
  242. height: 110px;
  243. display: block;
  244. background-color: black;
  245. }
  246. .avatar-uploader .el-upload {
  247. border: 1px dashed var(--el-border-color);
  248. border-radius: 6px;
  249. cursor: pointer;
  250. position: relative;
  251. overflow: hidden;
  252. transition: var(--el-transition-duration-fast);
  253. }
  254. .avatar-uploader .el-upload:hover {
  255. border-color: var(--el-color-primary);
  256. }
  257. .el-icon.avatar-uploader-icon {
  258. font-size: 28px;
  259. color: #8c939d;
  260. width: 110px;
  261. height: 110px;
  262. text-align: center;
  263. border: 1px dashed var(--el-border-color);
  264. }
  265. .pic {
  266. object-fit: contain;
  267. width: 50px;
  268. height: 50px;
  269. cursor: pointer;
  270. vertical-align: middle;
  271. }
  272. .blessingClass {
  273. background-image: url("../../../assets/victoria/sjk.jpg");
  274. background-size: cover;
  275. height: 600px;
  276. width: 300px;
  277. padding: 40px 19px;
  278. }
  279. </style>