header.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <template>
  2. <div id="header">
  3. <div>
  4. <h5>导航效果预览</h5>
  5. <div class="topSty_home">
  6. <el-row :gutter="20">
  7. <el-col :span="6" style="display: flex; flex-direction: row-reverse">
  8. <div v-if="!listData.companyLogo" class="noLogoImg">logo图片</div>
  9. <img
  10. v-else
  11. style="width: 216px; height: 46px"
  12. :src="$methodsTools.splitImgHost(listData.companyLogo)"
  13. alt="加载失败"
  14. />
  15. </el-col>
  16. <el-col
  17. :span="12"
  18. style="display: flex; flex-direction: column; align-items: center"
  19. >
  20. <div>
  21. <input class="dzStyInput" type="text" />
  22. <div class="btnSty">搜索</div>
  23. </div>
  24. <div>
  25. <ul class="ul_styLI">
  26. <li
  27. v-for="(item, index) in compyList(listData.Nav)"
  28. :key="index"
  29. >
  30. {{ item.name }}
  31. </li>
  32. </ul>
  33. </div>
  34. </el-col>
  35. <el-col :span="6" class="flex_sty" style="font-size: 14px">
  36. <img
  37. style="width: 66px; height: 54px"
  38. src="@/assets/images/telPhoto.png"
  39. alt=""
  40. />
  41. <div style="flex: 1">
  42. <h4 style="margin: 6px 0px">{{ listData.serviceTel.tel }}</h4>
  43. <div>服务时间:{{ listData.serviceTel.time }}</div>
  44. </div>
  45. </el-col>
  46. </el-row>
  47. </div>
  48. </div>
  49. <div>
  50. <h5>企业标识</h5>
  51. <ul style="margin-left: 20px">
  52. <li class="liSty">
  53. <span>模板启用</span>
  54. <div>
  55. <el-radio-group v-model="listData.templateStatus">
  56. <el-radio :label="1">模板一</el-radio>
  57. <el-radio :label="2">模板二</el-radio>
  58. </el-radio-group>
  59. </div>
  60. </li>
  61. <li class="liSty">
  62. <span style="align-self: flex-start">LOGO图片</span>
  63. <div>
  64. <div
  65. style="
  66. width: 216px;
  67. height: 46px;
  68. border: 1px dashed #999;
  69. border-radius: 28px;
  70. line-height: 46px;
  71. text-align: center;
  72. "
  73. v-if="!listData.companyLogo"
  74. >
  75. <label for="uplose">
  76. <i class="el-icon-circle-plus-outline iconStsz"></i
  77. ></label>
  78. <input
  79. ref="file"
  80. type="file"
  81. style="display: none"
  82. id="uplose"
  83. @change="getImgFile"
  84. />
  85. </div>
  86. <div v-else class="flex_sty">
  87. <el-image
  88. style="width: 216px; height: 46px"
  89. :src="$methodsTools.splitImgHost(listData.companyLogo)"
  90. :preview-src-list="[
  91. $methodsTools.splitImgHost(listData.companyLogo),
  92. ]"
  93. >
  94. </el-image>
  95. <el-button
  96. @click="listData.companyLogo = ''"
  97. style="margin-left: 16px"
  98. type="danger"
  99. icon="el-icon-delete"
  100. circle
  101. size="mini"
  102. ></el-button>
  103. </div>
  104. <p style="font-size: 12px; color: #999">
  105. 注:建议上传logo图片是透明底色的png格式,尺寸为216px * 46px
  106. </p>
  107. </div>
  108. </li>
  109. <li class="liSty">
  110. <span style="align-self: flex-start">LOGO图片-浅色</span>
  111. <div>
  112. <div
  113. style="
  114. width: 216px;
  115. height: 46px;
  116. border: 1px dashed #999;
  117. border-radius: 28px;
  118. line-height: 46px;
  119. text-align: center;
  120. "
  121. v-if="!listData.undertone"
  122. >
  123. <label for="uplose1">
  124. <i class="el-icon-circle-plus-outline iconStsz"></i
  125. ></label>
  126. <input
  127. ref="file1"
  128. type="file"
  129. style="display: none"
  130. id="uplose1"
  131. @change="getImgFile1"
  132. />
  133. </div>
  134. <div v-else class="flex_sty" style="background-color: #eee">
  135. <el-image
  136. style="width: 216px; height: 46px"
  137. :src="$methodsTools.splitImgHost(listData.undertone)"
  138. :preview-src-list="[
  139. $methodsTools.splitImgHost(listData.undertone),
  140. ]"
  141. >
  142. </el-image>
  143. <el-button
  144. @click="listData.undertone = ''"
  145. style="margin-left: 16px"
  146. type="danger"
  147. icon="el-icon-delete"
  148. circle
  149. size="mini"
  150. ></el-button>
  151. </div>
  152. <p style="font-size: 12px; color: #999">
  153. 注:建议上传logo图片是透明底色的png格式,尺寸为216px * 46px
  154. </p>
  155. </div>
  156. </li>
  157. <li class="liSty">
  158. <span>公司名称</span>
  159. <div>
  160. <el-input v-model="listData.companyName" :size="size"></el-input>
  161. </div>
  162. </li>
  163. <li class="liSty">
  164. <span>客服电话是否显示</span>
  165. <div>
  166. <el-radio-group v-model="listData.serviceTel.status">
  167. <el-radio :label="1">是</el-radio>
  168. <el-radio :label="0">否</el-radio>
  169. </el-radio-group>
  170. </div>
  171. </li>
  172. <li class="liSty">
  173. <span>电话号码</span>
  174. <div>
  175. <el-input v-model="listData.serviceTel.tel" :size="size"></el-input>
  176. </div>
  177. </li>
  178. <li class="liSty">
  179. <span>客服时间</span>
  180. <div>
  181. <el-input
  182. v-model="listData.serviceTel.time"
  183. :size="size"
  184. ></el-input>
  185. </div>
  186. </li>
  187. </ul>
  188. </div>
  189. <div>
  190. <h5>导航栏菜单设置</h5>
  191. <el-table
  192. :data="listData.Nav"
  193. style="width: 800px; margin-top: 10px"
  194. border
  195. >
  196. <el-table-column
  197. v-for="(item, index) in tableSet"
  198. :width="item.width"
  199. :key="index"
  200. :prop="item.prop"
  201. :label="item.label"
  202. align="center"
  203. >
  204. <template slot-scope="scope">
  205. <div v-if="item.scope === 'input'">
  206. <el-input-number
  207. @blur="changeVal(scope.row)"
  208. v-model="scope.row[item.prop]"
  209. :controls="false"
  210. :min="0"
  211. :precision="0"
  212. style="width: 50%"
  213. ></el-input-number>
  214. </div>
  215. <div v-else-if="item.scope === 'status'" class="disflex_sty">
  216. <el-switch
  217. :size="size"
  218. v-if="scope.row['name'] !== '首页'"
  219. :active-value="1"
  220. :inactive-value="0"
  221. v-model="scope.row[item.prop]"
  222. active-color="#13ce66"
  223. inactive-color="#ff4949"
  224. >
  225. </el-switch>
  226. <span style="margin-left: 14px">
  227. {{
  228. scope.row[item.prop] === 1
  229. ? "开启"
  230. : scope.row[item.prop] === 0
  231. ? "关闭"
  232. : "未知"
  233. }}
  234. </span>
  235. </div>
  236. <div v-else>{{ scope.row[item.prop] }}</div>
  237. </template></el-table-column
  238. >
  239. </el-table>
  240. </div>
  241. <div style="text-align: center; margin-top: 20px">
  242. <el-button :size="size" type="primary" @click="submit">保 存</el-button>
  243. </div>
  244. </div>
  245. </template>
  246. <script>
  247. import { listConfig, updateConfig } from "@/api/system/config";
  248. export default {
  249. data() {
  250. return {
  251. size: "mini",
  252. listData: {
  253. serviceTel: {},
  254. templateStatus: 1,
  255. },
  256. tableSet: [
  257. {
  258. label: "排序",
  259. prop: "sort",
  260. scope: "input",
  261. },
  262. {
  263. label: "导航菜单名称",
  264. prop: "name",
  265. },
  266. {
  267. label: "状态",
  268. prop: "status",
  269. scope: "status",
  270. },
  271. ],
  272. initData: {},
  273. };
  274. },
  275. computed: {
  276. compyList: function () {
  277. return function (arr) {
  278. let ary = [];
  279. if (arr) {
  280. ary = arr.filter((item) => {
  281. return item.status === 1;
  282. });
  283. }
  284. return ary;
  285. };
  286. },
  287. },
  288. mounted() {
  289. this.init();
  290. },
  291. methods: {
  292. changeVal(row) {
  293. if (!row.sort && row.sort !== 0) {
  294. this.$message.warning("检测到你没有赋值或赋值异常,已自动赋值为0");
  295. row.sort = 0;
  296. } else {
  297. for (let i = 0; i < this.listData.Nav.length; i++) {
  298. if (
  299. this.listData.Nav[i].name !== row.name &&
  300. this.listData.Nav[i].sort == row.sort
  301. ) {
  302. this.$message.warning("检测到重复值,已自动赋值为0");
  303. row.sort = 0;
  304. }
  305. }
  306. }
  307. this.listData.Nav.sort(this.sort);
  308. },
  309. submit() {
  310. let data = JSON.parse(JSON.stringify(this.listData));
  311. let copySubmitData = JSON.parse(JSON.stringify(this.initData));
  312. copySubmitData.configValue = JSON.stringify(data);
  313. updateConfig(copySubmitData).then((res) => {
  314. this.$message.success("保存成功");
  315. });
  316. },
  317. sort(a, b) {
  318. return a.sort - b.sort;
  319. },
  320. init() {
  321. listConfig({ configKey: "home.header" }).then((res) => {
  322. if (res.rows.length) {
  323. this.initData = res.rows[0];
  324. let A = JSON.parse(res.rows[0].configValue);
  325. A.undertone = A.undertone || "";
  326. A.templateStatus = A.templateStatus || 1;
  327. this.listData = A;
  328. if (!this.listData.Nav.some((i) => i.name === "讲义资料")) {
  329. this.listData.Nav.push({
  330. name: "讲义资料",
  331. sort: 6,
  332. status: 0,
  333. });
  334. }
  335. if (!this.listData.Nav.some((i) => i.name === "积分商城")) {
  336. this.listData.Nav.push({
  337. name: "积分商城",
  338. sort: 7,
  339. status: 0,
  340. });
  341. }
  342. }
  343. });
  344. },
  345. getImgFile() {
  346. var self = this;
  347. var file = self.$refs.file.files[0];
  348. if (file === undefined) {
  349. self.$set(self.listData, "companyLogo", "");
  350. return;
  351. }
  352. if (file.size > 0.3 * 1024 * 1024) {
  353. self.$message.error("图片不得大于300kb");
  354. return;
  355. }
  356. var type = self.$refs.file.value.toLowerCase().split(".").splice(-1);
  357. if (
  358. type[0] != "jpg" &&
  359. type[0] != "png" &&
  360. type[0] != "jpeg" &&
  361. type[0] != "gif"
  362. ) {
  363. self.$message.error("上传格式需为:.jpg/.png/.jpeg/gif");
  364. self.$refs.file.value = "";
  365. return;
  366. }
  367. this.$upload.upload(file, 0).then((res) => {
  368. self.listData.companyLogo = res;
  369. });
  370. },
  371. getImgFile1() {
  372. var self = this;
  373. var file = self.$refs.file1.files[0];
  374. if (file === undefined) {
  375. self.$set(self.listData, "undertone", "");
  376. return;
  377. }
  378. if (file.size > 0.3 * 1024 * 1024) {
  379. self.$message.error("图片不得大于300kb");
  380. return;
  381. }
  382. var type = self.$refs.file1.value.toLowerCase().split(".").splice(-1);
  383. if (
  384. type[0] != "jpg" &&
  385. type[0] != "png" &&
  386. type[0] != "jpeg" &&
  387. type[0] != "gif"
  388. ) {
  389. self.$message.error("上传格式需为:.jpg/.png/.jpeg/gif");
  390. self.$refs.file1.value = "";
  391. return;
  392. }
  393. this.$upload.upload(file, 0).then((res) => {
  394. self.listData.undertone = res;
  395. });
  396. },
  397. },
  398. };
  399. </script>
  400. <style lang="less" scoped>
  401. /deep/.el-input--mini .el-input__inner {
  402. max-width: 300px;
  403. }
  404. h5 {
  405. font-weight: bold;
  406. }
  407. .liSty {
  408. display: flex;
  409. align-items: center;
  410. font-size: 14px;
  411. margin-bottom: 20px;
  412. span {
  413. width: 140px;
  414. text-align: right;
  415. margin-right: 10px;
  416. }
  417. }
  418. .disflex_sty {
  419. display: flex;
  420. align-items: center;
  421. justify-content: center;
  422. }
  423. .flex_sty {
  424. display: flex;
  425. align-items: center;
  426. }
  427. .iconStsz {
  428. font-size: 20px;
  429. color: #67c23a;
  430. cursor: pointer;
  431. }
  432. .topSty_home {
  433. border-radius: 14px;
  434. padding: 10px;
  435. border: 1px solid #666;
  436. }
  437. .dzStyInput {
  438. width: 400px;
  439. height: 34px;
  440. outline: none;
  441. padding-left: 10px;
  442. font-size: 14px;
  443. border: 1px solid #666;
  444. border-top-left-radius: 6px;
  445. border-bottom-left-radius: 6px;
  446. border-color: rgb(65, 140, 251);
  447. }
  448. .btnSty {
  449. display: inline-block;
  450. height: 34px;
  451. padding: 0px 6px;
  452. border: 1px solid #666;
  453. line-height: 32px;
  454. border-left: none;
  455. background-color: rgb(65, 140, 251);
  456. color: #fff;
  457. font-size: 14px;
  458. border-color: rgb(65, 140, 251);
  459. border-top-right-radius: 6px;
  460. border-bottom-right-radius: 6px;
  461. cursor: pointer;
  462. user-select: none;
  463. }
  464. .noLogoImg {
  465. border: 1px solid #666;
  466. width: 216px;
  467. height: 46px;
  468. text-align: center;
  469. font-size: 14px;
  470. line-height: 46px;
  471. }
  472. .ul_styLI {
  473. width: 400px;
  474. display: flex;
  475. align-items: center;
  476. justify-content: space-around;
  477. font-size: 14px;
  478. user-select: none;
  479. }
  480. </style>