index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <div id="links">
  3. <div class="smallBox">
  4. <div class="dis_x">
  5. <div>友情链接<span>{{listData.length || 0}}条</span></div>
  6. <el-button :size="size" @click="add(1)" type="primary">新增</el-button>
  7. </div>
  8. <el-table :data="listData" style="margin-top: 10px" border max-height="740px">
  9. <el-table-column
  10. v-for="(item, index) in tableSet"
  11. :width="item.width"
  12. :key="index"
  13. :prop="item.prop"
  14. :label="item.label"
  15. align="center"
  16. >
  17. <template slot-scope="scope">
  18. <div v-if="item.scope === 'input'">
  19. <el-input-number
  20. @blur="changeVal(scope.row)"
  21. v-model="scope.row[item.prop]"
  22. :controls="false"
  23. :min="0"
  24. :precision="0"
  25. style="width: 80%"
  26. ></el-input-number>
  27. </div>
  28. <div v-else-if="item.scope === 'set'">
  29. <el-button type="text" @click="add(0, scope.row, scope.$index)"
  30. >修改</el-button
  31. >
  32. <el-button type="text" @click="del(scope.$index)">删除</el-button>
  33. </div>
  34. <div v-else-if="item.scope === 'status'">
  35. <el-switch
  36. v-model="scope.row[item.prop]"
  37. active-color="#13ce66"
  38. inactive-color="#ff4949"
  39. :active-value="1"
  40. :inactive-value="0"
  41. >
  42. </el-switch>
  43. <span style="margin-left:10px;">{{ scope.row[item.prop] == 1 ? "开启" : "关闭" }}</span>
  44. </div>
  45. <div v-else>{{ scope.row[item.prop] }}</div>
  46. </template></el-table-column
  47. >
  48. </el-table>
  49. <div style="text-align: center; margin-top: 20px">
  50. <el-button :size="size" type="primary" @click="submit">保 存</el-button>
  51. </div>
  52. </div>
  53. <el-dialog
  54. @closed="loadingClose"
  55. :visible.sync="dialogVisible"
  56. width="680px"
  57. :show-close="false"
  58. :close-on-click-modal="false"
  59. >
  60. <div slot="title" class="hearders">
  61. <div class="leftTitle">
  62. {{ statusPop === 1 ? "添加" : statusPop === 0 ? "修改" : "详情" }}
  63. </div>
  64. <div class="rightBoxs">
  65. <img src="@/assets/images/Close@2x.png" alt="" @click="close" />
  66. </div>
  67. </div>
  68. <div>
  69. <el-form
  70. label-position="right"
  71. label-width="170px"
  72. :model="boxData"
  73. :rules="rules"
  74. ref="boxData"
  75. >
  76. <el-form-item label="名称" prop="name">
  77. <el-input v-model="boxData.name"></el-input>
  78. </el-form-item>
  79. <el-form-item label="链接地址" prop="url">
  80. <el-input v-model="boxData.url"></el-input>
  81. </el-form-item>
  82. <el-form-item label="状态" prop="status">
  83. <el-radio-group v-model="boxData.status">
  84. <el-radio :label="1">启用</el-radio>
  85. <el-radio :label="0">关闭</el-radio>
  86. </el-radio-group>
  87. </el-form-item>
  88. </el-form>
  89. </div>
  90. <span slot="footer" class="dialog-footer">
  91. <el-button @click="close">取 消</el-button>
  92. <el-button @click="submitForm('boxData')" :loading="disabledBtn"
  93. >确 定</el-button
  94. >
  95. </span>
  96. </el-dialog>
  97. </div>
  98. </template>
  99. <script>
  100. import { listConfig, updateConfig } from "@/api/system/config";
  101. export default {
  102. data() {
  103. return {
  104. disabledBtn: false,
  105. dialogVisible: false,
  106. size: "mini",
  107. tableSet: [
  108. {
  109. label: "排序",
  110. prop: "sort",
  111. scope: "input",
  112. width: "120px",
  113. },
  114. {
  115. label: "名称",
  116. prop: "name",
  117. },
  118. {
  119. label: "链接地址",
  120. prop: "url",
  121. },
  122. {
  123. label: "状态",
  124. prop: "status",
  125. scope: "status",
  126. },
  127. {
  128. label: "操作",
  129. scope: "set",
  130. width: "160px",
  131. },
  132. ],
  133. Nav: [],
  134. initData: {},
  135. listData: [],
  136. statusPop: "",
  137. boxData: {},
  138. rules: {
  139. name: [{ required: true, message: "请填写名称", trigger: "blur" }],
  140. url: [{ required: true, message: "请填写链接地址", trigger: "blur" }],
  141. status: [
  142. {
  143. required: true,
  144. message: "请选择状态",
  145. trigger: "change",
  146. },
  147. ],
  148. },
  149. newIndex: "",
  150. };
  151. },
  152. mounted() {
  153. this.init();
  154. },
  155. methods: {
  156. changeVal(row) {
  157. if (!row.sort && row.sort !== 0) {
  158. this.$message.warning("检测到你没有赋值或赋值异常,已自动赋值为0");
  159. row.sort = 0;
  160. } else {
  161. for (let i = 0; i < this.listData.length; i++) {
  162. if (
  163. this.listData[i].name !== row.name &&
  164. this.listData[i].sort == row.sort
  165. ) {
  166. this.$message.warning("检测到重复值,已自动赋值为0");
  167. row.sort = 0;
  168. }
  169. }
  170. }
  171. this.listData.sort(this.sort);
  172. },
  173. sort(a, b) {
  174. return a.sort - b.sort;
  175. },
  176. loadingClose() {
  177. this.disabledBtn = false;
  178. },
  179. del(index) {
  180. this.listData.splice(index, 1);
  181. },
  182. add(int, row, index) {
  183. this.statusPop = int;
  184. this.newIndex = index;
  185. if (int === 0) {
  186. this.boxData = JSON.parse(JSON.stringify(row));
  187. }
  188. if (int === 1) {
  189. var indexNum = 0;
  190. this.listData.forEach((item) => {
  191. if (item.sort >= indexNum) {
  192. indexNum = item.sort + 1;
  193. }
  194. });
  195. this.boxData = {};
  196. this.boxData.sort = indexNum;
  197. }
  198. this.dialogVisible = true;
  199. this.$nextTick(() => {
  200. this.$refs.boxData.clearValidate();
  201. });
  202. },
  203. close() {
  204. this.dialogVisible = false;
  205. },
  206. submitForm(formName) {
  207. this.$refs[formName].validate((valid) => {
  208. if (valid) {
  209. if (this.statusPop === 1) {
  210. this.listData.push(this.boxData);
  211. } else {
  212. this.listData.splice(this.newIndex, 1, this.boxData);
  213. }
  214. this.dialogVisible = false;
  215. } else {
  216. console.log("error submit!!");
  217. return false;
  218. }
  219. });
  220. },
  221. init() {
  222. listConfig({ configKey: "home.links" }).then((res) => {
  223. if (res.rows.length) {
  224. this.initData = res.rows[0];
  225. this.listData = JSON.parse(res.rows[0].configValue);
  226. }
  227. });
  228. },
  229. submit() {
  230. let data = JSON.parse(JSON.stringify(this.listData));
  231. let copySubmitData = JSON.parse(JSON.stringify(this.initData));
  232. copySubmitData.configValue = JSON.stringify(data);
  233. updateConfig(copySubmitData).then((res) => {
  234. this.$message.success("保存成功");
  235. });
  236. },
  237. },
  238. };
  239. </script>
  240. <style lang="less" scoped>
  241. .dis_x{
  242. display: flex;
  243. align-items: center;
  244. justify-content: space-between;
  245. margin-bottom: 14px;
  246. }
  247. .smallBox {
  248. // width: 900px;
  249. }
  250. /deep/.el-button {
  251. border-radius: 8px;
  252. }
  253. /deep/.el-dialog {
  254. border-radius: 8px;
  255. .el-dialog__header {
  256. padding: 0;
  257. .hearders {
  258. height: 40px;
  259. display: flex;
  260. align-items: center;
  261. justify-content: space-between;
  262. padding: 0px 18px 0px 20px;
  263. border-bottom: 1px solid #e2e2e2;
  264. .leftTitle {
  265. font-size: 14px;
  266. font-weight: bold;
  267. color: #2f4378;
  268. }
  269. .rightBoxs {
  270. display: flex;
  271. align-items: center;
  272. img {
  273. width: 14px;
  274. height: 14px;
  275. margin-left: 13px;
  276. cursor: pointer;
  277. }
  278. }
  279. }
  280. }
  281. .el-dialog__footer {
  282. padding: 0;
  283. .dialog-footer {
  284. padding: 0px 40px;
  285. height: 70px;
  286. border-top: 1px solid #e2e2e2;
  287. display: flex;
  288. align-items: center;
  289. justify-content: flex-end;
  290. }
  291. }
  292. }
  293. .imgBox {
  294. width: 100%;
  295. // height: 210px;
  296. border: 1px solid #e2e2e2;
  297. border-radius: 8px;
  298. padding: 8px 8px 3px;
  299. display: flex;
  300. flex-direction: column;
  301. align-items: center;
  302. .imgLabel {
  303. flex: 1;
  304. width: 100%;
  305. border: 1px dotted #e2e2e2;
  306. color: #999;
  307. font-size: 14px;
  308. cursor: pointer;
  309. border-radius: 8px;
  310. .msPhoto {
  311. display: flex;
  312. justify-content: center;
  313. align-items: center;
  314. max-width: 100%;
  315. max-height: 270px;
  316. img {
  317. max-width: 100%;
  318. max-height: 270px;
  319. }
  320. }
  321. .imgbbx {
  322. display: flex;
  323. flex-direction: column;
  324. align-items: center;
  325. justify-content: center;
  326. width: 100%;
  327. height: 100%;
  328. i {
  329. font-weight: bold;
  330. margin: 14px 0;
  331. font-size: 24px;
  332. }
  333. }
  334. }
  335. p {
  336. margin: 5px 0px;
  337. }
  338. }
  339. .dis_fs {
  340. display: flex;
  341. align-items: center;
  342. justify-content: center;
  343. width: 337.5px;
  344. height: 144px;
  345. border: 1px solid #999;
  346. .imgBoxs {
  347. width: 100%;
  348. height: 100%;
  349. }
  350. }
  351. .styPsty {
  352. margin-top: 10px;
  353. display: flex;
  354. align-items: center;
  355. .btns {
  356. border: 1px solid #999;
  357. font-size: 12px;
  358. height: 28px;
  359. line-height: 28px;
  360. padding: 0px 10px;
  361. border-radius: 4px;
  362. cursor: pointer;
  363. margin-right: 10px;
  364. flex-shrink: 0;
  365. }
  366. }
  367. </style>