index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight">
  5. <el-col :span="24" class="one">
  6. <c-search></c-search>
  7. </el-col>
  8. <el-col :span="24" class="two">
  9. <data-form :fields="fields" :form="form" :rules="{}" @save="toSave" :span="24">
  10. <template #logo_url="{ item }">
  11. <c-upload v-model="form[item.model]" url="/files/projectadmin/imgurl/upload" :limit="1"></c-upload>
  12. </template>
  13. <template #foot_menus="{ item }">
  14. <el-button type="primary" size="small" @click="menusAdd()">添加</el-button>
  15. <data-table :fields="mfields" :opera="mopera" :data="form[item.model]" :usePage="false" @edit="menusEdit" @del="menusDel">
  16. <template #normal="{ row, item }">
  17. <el-image
  18. class="image"
  19. @click="imgView(row[item.model])"
  20. :src="row[item.model] && row[item.model].length > 0 ? row[item.model][0].uri : ''"
  21. ></el-image>
  22. </template>
  23. <template #active="{ row, item }">
  24. <el-image
  25. class="image"
  26. @click="imgView(row[item.model])"
  27. :src="row[item.model] && row[item.model].length > 0 ? row[item.model][0].uri : ''"
  28. ></el-image>
  29. </template>
  30. </data-table>
  31. </template>
  32. <template #account_btn="{ item }">
  33. <el-button type="primary" size="small" @click="abtnAdd()">添加</el-button>
  34. <data-table :fields="acfields" :opera="acopera" :data="form[item.model]" :usePage="false" @edit="acbtnEdit" @del="acbtnDel">
  35. <template #img_url="{ row, item }">
  36. <el-image
  37. class="image"
  38. @click="imgView(row[item.model])"
  39. :src="row[item.model] && row[item.model].length > 0 ? row[item.model][0].uri : ''"
  40. ></el-image>
  41. </template>
  42. </data-table>
  43. </template>
  44. </data-form>
  45. </el-col>
  46. </el-col>
  47. </el-row>
  48. <c-dialog :dialog="dialog" @toClose="toClose">
  49. <template v-slot:info>
  50. <el-col :span="24" class="dialog_one" v-if="dialog.type == '1'">
  51. <data-form :fields="otherFields" :form="otherForm" :rules="{}" @save="dialogSave" :span="24">
  52. <template #normal="{ item }">
  53. <c-upload v-model="otherForm[item.model]" url="/files/projectadmin/imgurl/upload" :limit="1"></c-upload>
  54. </template>
  55. <template #active="{ item }">
  56. <c-upload v-model="otherForm[item.model]" url="/files/projectadmin/imgurl/upload" :limit="1"></c-upload>
  57. </template>
  58. <template #type>
  59. <el-option v-for="i in jumptypeLsit" :key="i._id" :label="i.label" :value="i.value"></el-option>
  60. </template>
  61. <template #is_use>
  62. <el-option v-for="i in isuseList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  63. </template>
  64. </data-form>
  65. </el-col>
  66. <el-col :span="24" class="dialog_two" v-else-if="dialog.type == '2'">
  67. <data-form :fields="acbtnFields" :form="acbtnForm" :rules="{}" @save="acbtnSave" :span="24" @dataChange="dataChange">
  68. <template #img_url="{ item }">
  69. <c-upload v-model="acbtnForm[item.model]" url="/files/projectadmin/imgurl/upload" :limit="1"></c-upload>
  70. </template>
  71. <template #is_jump>
  72. <el-option v-for="i in isnoList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  73. </template>
  74. <template #type>
  75. <el-option v-for="i in jumptypeLsit" :key="i._id" :label="i.label" :value="i.value"></el-option>
  76. </template>
  77. <template #is_use>
  78. <el-option v-for="i in isuseList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  79. </template>
  80. </data-form>
  81. </el-col>
  82. </template>
  83. </c-dialog>
  84. </div>
  85. </template>
  86. <script>
  87. import { mapState, createNamespacedHelpers } from 'vuex';
  88. const { mapActions } = createNamespacedHelpers('appbasic');
  89. const { mapActions: dictdata } = createNamespacedHelpers('dictdata');
  90. const moment = require('moment');
  91. export default {
  92. name: 'index',
  93. props: {},
  94. components: {},
  95. data: function () {
  96. return {
  97. form: { logo_url: [], foot_menus: [], account_btn: [] },
  98. fields: [
  99. { label: '公司名称', model: 'name' },
  100. { label: '公司logo', model: 'logo_url', custom: true },
  101. { label: '底部菜单', model: 'foot_menus', custom: true },
  102. { label: '账号功能按钮', model: 'account_btn', custom: true },
  103. ],
  104. // 底部菜单
  105. mfields: [
  106. { label: '名称', model: 'name' },
  107. { label: '跳转路径', model: 'route' },
  108. {
  109. label: '跳转类型',
  110. model: 'type',
  111. format: (i) => {
  112. let data = this.jumptypeLsit.find((r) => r.value == i);
  113. if (data) return data.label;
  114. else return '暂无';
  115. },
  116. },
  117. { label: '排序', model: 'sort' },
  118. {
  119. label: '是否启用',
  120. model: 'is_use',
  121. format: (i) => {
  122. let data = this.isuseList.find((r) => r.value == i);
  123. if (data) return data.label;
  124. else return '暂无';
  125. },
  126. },
  127. { label: '未选中', model: 'normal', custom: true },
  128. { label: '选中', model: 'active', custom: true },
  129. ],
  130. mopera: [
  131. { label: '修改', method: 'edit' },
  132. { label: '删除', method: 'del', confirm: true, type: 'danger' },
  133. ],
  134. otherFields: [
  135. { label: '名称', model: 'name' },
  136. { label: '跳转路径', model: 'route' },
  137. { label: '跳转类型', model: 'type', type: 'select' },
  138. { label: '排序', model: 'sort', type: 'number' },
  139. { label: '是否启用', model: 'is_use', type: 'select' },
  140. { label: '未选中', model: 'normal', custom: true },
  141. { label: '选中', model: 'active', custom: true },
  142. ],
  143. otherForm: { normal: [], active: [] },
  144. // 账号功能按钮
  145. acfields: [
  146. { label: '名称', model: 'name' },
  147. { label: '图片', model: 'img_url', custom: true },
  148. {
  149. label: '是否跳转',
  150. model: 'is_jump',
  151. format: (i) => {
  152. let data = this.isnoList.find((r) => r.value == i);
  153. if (data) return data.label;
  154. else return '暂无';
  155. },
  156. },
  157. {
  158. label: '跳转类型',
  159. model: 'type',
  160. format: (i) => {
  161. let data = this.jumptypeLsit.find((r) => r.value == i);
  162. if (data) return data.label;
  163. else return '暂无';
  164. },
  165. },
  166. { label: '跳转路径', model: 'route' },
  167. { label: '按钮属性', model: 'nature' },
  168. { label: '排序', model: 'sort' },
  169. {
  170. label: '是否启用',
  171. model: 'is_use',
  172. format: (i) => {
  173. let data = this.isuseList.find((r) => r.value == i);
  174. if (data) return data.label;
  175. else return '暂无';
  176. },
  177. },
  178. ],
  179. acopera: [
  180. { label: '修改', method: 'edit' },
  181. { label: '删除', method: 'del', confirm: true, type: 'danger' },
  182. ],
  183. acbtnFields: [
  184. { label: '名称', model: 'name' },
  185. { label: '图片', model: 'img_url', custom: true },
  186. { label: '是否跳转', model: 'is_jump', type: 'select' },
  187. { label: '排序', model: 'sort', type: 'number' },
  188. { label: '是否启用', model: 'is_use', type: 'select' },
  189. ],
  190. acbtnForm: { img_url: [] },
  191. // 弹框
  192. dialog: { title: '底部菜单', show: false, type: '1' },
  193. // 字典
  194. isuseList: [],
  195. // 跳转类型
  196. jumptypeLsit: [],
  197. // 是否
  198. isnoList: [],
  199. };
  200. },
  201. async created() {
  202. await this.searchOther();
  203. await this.search();
  204. },
  205. methods: {
  206. ...mapActions(['query', 'create', 'update']),
  207. ...dictdata({ dQuery: 'query' }),
  208. async search() {
  209. let res = await this.query();
  210. if (this.$checkRes(res)) {
  211. let data = res.data;
  212. if (!data.logo_url) data.logo_url = [];
  213. if (!data.foot_menus) data.foot_menus = [];
  214. if (data.foot_menus.length > 0) {
  215. data.foot_menus = data.foot_menus.sort((a, b) => {
  216. return a.sort - b.sort;
  217. });
  218. }
  219. if (!data.account_btn) data.account_btn = [];
  220. if (data.account_btn.length > 0) {
  221. data.account_btn = data.account_btn.sort((a, b) => {
  222. return a.sort - b.sort;
  223. });
  224. }
  225. this.$set(this, `form`, data);
  226. }
  227. },
  228. // 保存信息
  229. async toSave({ data }) {
  230. let res;
  231. if (data.id) res = await this.update(data);
  232. else res = await this.create(data);
  233. if (this.$checkRes(res, '维护信息成功', res.errmsg)) this.search();
  234. },
  235. // 菜单添加
  236. menusAdd() {
  237. this.dialog = { title: '底部菜单', show: true, type: '1' };
  238. },
  239. // 修改
  240. menusEdit({ data }) {
  241. this.$set(this, `otherForm`, data);
  242. this.dialog = { title: '底部菜单', show: true, type: '1' };
  243. },
  244. // 删除
  245. menusDel({ data }) {
  246. let foot_menus = this.form.foot_menus.filter((i) => i.id != data.id);
  247. this.$set(this.form, `foot_menus`, foot_menus);
  248. },
  249. // 保存
  250. dialogSave({ data }) {
  251. if (!data.id) {
  252. data.id = moment().valueOf();
  253. this.form.foot_menus = [...this.form.foot_menus, data];
  254. } else {
  255. }
  256. this.toClose();
  257. },
  258. // 账号功能按钮
  259. abtnAdd() {
  260. this.dialog = { title: '账号功能按钮', show: true, type: '2' };
  261. },
  262. // 修改
  263. acbtnEdit({ data }) {
  264. this.$set(this, `acbtnForm`, data);
  265. if (data.is_jump) this.dataChange({ model: 'is_jump', value: data.is_jump });
  266. this.dialog = { title: '账号功能按钮', show: true, type: '2' };
  267. },
  268. // 删除
  269. acbtnDel({ data }) {
  270. let account_btn = this.form.account_btn.filter((i) => i.id != data.id);
  271. this.$set(this.form, `account_btn`, account_btn);
  272. },
  273. dataChange({ model, value }) {
  274. if (model == 'is_jump') {
  275. if (value == '0') {
  276. let other = [{ label: '按钮属性', model: 'nature' }];
  277. this.acbtnFields.splice(3, 0, ...other);
  278. } else if (value == '1') {
  279. let other = [
  280. { label: '跳转类型', model: 'type', type: 'select' },
  281. { label: '跳转路径', model: 'route' },
  282. ];
  283. this.acbtnFields.splice(3, 0, ...other);
  284. }
  285. }
  286. },
  287. acbtnSave({ data }) {
  288. if (!data.id) {
  289. data.id = moment().valueOf();
  290. this.form.account_btn = [...this.form.account_btn, data];
  291. } else {
  292. }
  293. this.toClose();
  294. },
  295. // 关闭弹框
  296. toClose() {
  297. this.otherForm = {};
  298. this.acbtnForm = {};
  299. this.dialog = { title: '底部菜单', show: false, type: '1' };
  300. },
  301. // 字典
  302. async searchOther() {
  303. let res;
  304. // 是否启用
  305. res = await this.dQuery({ type: 'is_use' });
  306. if (this.$checkRes(res)) {
  307. this.$set(this, `isuseList`, res.data);
  308. }
  309. // 跳转类型
  310. res = await this.dQuery({ type: 'jump_type' });
  311. if (this.$checkRes(res)) {
  312. this.$set(this, `jumptypeLsit`, res.data);
  313. }
  314. // 是否
  315. res = await this.dQuery({ type: 'is_no' });
  316. if (this.$checkRes(res)) {
  317. this.$set(this, `isnoList`, res.data);
  318. }
  319. },
  320. // 预览图片
  321. imgView(e) {
  322. if (e && e.length > 0) {
  323. window.open(e[0].uri);
  324. }
  325. },
  326. },
  327. computed: {
  328. ...mapState(['user']),
  329. },
  330. metaInfo() {
  331. return { title: this.$route.meta.title };
  332. },
  333. watch: {
  334. test: {
  335. deep: true,
  336. immediate: true,
  337. handler(val) {},
  338. },
  339. },
  340. };
  341. </script>
  342. <style lang="less" scoped>
  343. .image {
  344. width: 40px;
  345. height: 40px;
  346. border-radius: 5px;
  347. }
  348. </style>