list.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <div>
  3. <Card :bordered="false" dis-hover class="ivu-mt">
  4. <Row type="flex">
  5. <Col v-bind="grid">
  6. <Button type="primary" icon="md-add" @click="add">添加语言</Button>
  7. </Col>
  8. </Row>
  9. <Table
  10. :columns="columns"
  11. :data="list"
  12. ref="table"
  13. class="mt25"
  14. :loading="loading"
  15. highlight-row
  16. no-userFrom-text="暂无数据"
  17. no-filtered-userFrom-text="暂无筛选结果"
  18. >
  19. <template slot-scope="{ row, index }" slot="icons">
  20. <div class="tabBox_img" v-viewer>
  21. <img v-lazy="row.icon" />
  22. </div>
  23. </template>
  24. <template slot-scope="{ row, index }" slot="language_name">
  25. <div class="acea-row row-middle">
  26. <span>{{ row.language_name }}</span>
  27. <Tag class="ml10" color="default" v-if="row.is_default">默认</Tag>
  28. </div>
  29. </template>
  30. <template slot-scope="{ row, index }" slot="status">
  31. <i-switch
  32. v-model="row.status"
  33. :value="row.status"
  34. :true-value="1"
  35. :false-value="0"
  36. @on-change="changeSwitch(row)"
  37. size="large"
  38. >
  39. <span slot="open">开启</span>
  40. <span slot="close">关闭</span>
  41. </i-switch>
  42. </template>
  43. <template slot-scope="{ row, index }" slot="action">
  44. <a @click="edit(row, '编辑语言', index)">编辑</a>
  45. <Divider type="vertical" />
  46. <a @click="del(row, '删除语言', index)">删除</a>
  47. </template>
  48. </Table>
  49. <div class="acea-row row-right page">
  50. <Page :total="total" show-elevator show-total @on-change="pageChange" :page-size="langFrom.limit" />
  51. </div>
  52. </Card>
  53. </div>
  54. </template>
  55. <script>
  56. import { mapState } from 'vuex';
  57. import { langTypeList, langTypeForm, langTypeStatus } from '@/api/setting';
  58. export default {
  59. name: 'user_group',
  60. data() {
  61. return {
  62. grid: {
  63. xl: 7,
  64. lg: 7,
  65. md: 12,
  66. sm: 24,
  67. xs: 24,
  68. },
  69. loading: false,
  70. columns: [
  71. {
  72. title: 'ID',
  73. key: 'id',
  74. width: 200,
  75. },
  76. {
  77. title: '语言名称',
  78. slot: 'language_name',
  79. minWidth: 200,
  80. },
  81. {
  82. title: '浏览器语言识别码',
  83. key: 'file_name',
  84. minWidth: 200,
  85. },
  86. {
  87. title: '状态',
  88. slot: 'status',
  89. width: 100,
  90. filters: [
  91. {
  92. label: '开启',
  93. value: 1,
  94. },
  95. {
  96. label: '关闭',
  97. value: 0,
  98. },
  99. ],
  100. filterMethod(value, row) {
  101. return row.status === value;
  102. },
  103. filterMultiple: false,
  104. },
  105. {
  106. title: '操作',
  107. slot: 'action',
  108. fixed: 'right',
  109. minWidth: 120,
  110. },
  111. ],
  112. langFrom: {
  113. page: 1,
  114. limit: 15,
  115. },
  116. list: [],
  117. total: 0,
  118. };
  119. },
  120. computed: {
  121. ...mapState('media', ['isMobile']),
  122. labelWidth() {
  123. return this.isMobile ? undefined : 75;
  124. },
  125. labelPosition() {
  126. return this.isMobile ? 'top' : 'left';
  127. },
  128. },
  129. created() {
  130. this.getList();
  131. },
  132. methods: {
  133. // 添加
  134. add() {
  135. this.$modalForm(langTypeForm(0)).then(() => this.getList());
  136. },
  137. // 分组列表
  138. getList() {
  139. this.loading = true;
  140. langTypeList(this.langFrom)
  141. .then(async (res) => {
  142. let data = res.data;
  143. this.list = data.list;
  144. this.total = data.count;
  145. this.loading = false;
  146. })
  147. .catch((res) => {
  148. this.loading = false;
  149. this.$Message.error(res.msg);
  150. });
  151. },
  152. pageChange(index) {
  153. this.langFrom.page = index;
  154. this.getList();
  155. },
  156. // 编辑
  157. edit(row) {
  158. this.$modalForm(langTypeForm(row.id)).then(() => this.getList());
  159. },
  160. // 删除
  161. del(row, tit, num) {
  162. let delfromData = {
  163. title: tit,
  164. num: num,
  165. url: `setting/lang_type/del/${row.id}`,
  166. method: 'DELETE',
  167. ids: '',
  168. };
  169. this.$modalSure(delfromData)
  170. .then((res) => {
  171. this.$Message.success(res.msg);
  172. this.list.splice(num, 1);
  173. this.getList();
  174. })
  175. .catch((res) => {
  176. this.$Message.error(res.msg);
  177. });
  178. },
  179. // 修改状态
  180. changeSwitch(row) {
  181. langTypeStatus(row.id, row.status)
  182. .then((res) => {
  183. this.$Message.success(res.msg);
  184. })
  185. .catch((res) => {
  186. row.status = !row.status ? 1 : 0;
  187. this.$Message.error(res.msg);
  188. });
  189. },
  190. },
  191. };
  192. </script>
  193. <style scoped lang="stylus"></style>