PowersModal.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @register="register"
  5. title="设置场景权限"
  6. @cancel="resetFields"
  7. @ok="handleSubmit"
  8. :width="1000"
  9. :min-height="0"
  10. >
  11. <div class="pt-2px pr-3px">{{roleId}}
  12. <BasicForm @register="registerForm" :model="model">
  13. <template #text="{ model, field }">
  14. {{ model[field] }}
  15. </template>
  16. </BasicForm>
  17. <BasicTable v-show="fileFlow.showList" class="powesrTable" @register="registerTable">
  18. <template #toolbar>
  19. <a-button type="primary" v-if="getCheckPerm('scenes-powers-add')" @click="addPowes"> 新增 </a-button>
  20. </template>
  21. <template #action="{ record }">
  22. <TableAction
  23. stopButtonPropagation
  24. :actions="[
  25. {
  26. label: '编辑',
  27. ifShow: getCheckPerm('scenes-powers-edit'),
  28. onClick: handleEdit.bind(null, record),
  29. },
  30. {
  31. label: '删除',
  32. //icon: 'ic:outline-delete-outline',
  33. color: 'error',
  34. ifShow: getCheckPerm('scenes-powers-delete'),
  35. onClick: handleDelete.bind(null, record),
  36. },
  37. ]"
  38. />
  39. </template>
  40. </BasicTable>
  41. <detailModal @register="registerDetail" @update="reload" />
  42. </div>
  43. </BasicModal>
  44. </template>
  45. <script lang="ts">
  46. import { defineComponent, ref, computed, onMounted, reactive } from 'vue';
  47. import { BasicModal, useModalInner } from '/@/components/Modal';
  48. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  49. import { useMessage } from '/@/hooks/web/useMessage';
  50. import { sceneMove } from '/@/api/operate';
  51. import { useModal } from '/@/components/Modal';
  52. import { useI18n } from '/@/hooks/web/useI18n';
  53. import detailModal from './detailModal.vue';
  54. import { usePermissionStore } from '/@/store/modules/permission';
  55. import { getAuthList, getAuthType, setAuthType, delAuth } from '/@/api/operate';
  56. import { BasicTable, useTable, TableAction, BasicColumn } from '/@/components/Table';
  57. import { useUserStore } from '/@/store/modules/user';
  58. import dayjs from 'dayjs';
  59. const { t } = useI18n();
  60. export default defineComponent({
  61. components: { BasicModal, BasicForm, BasicTable, TableAction, detailModal },
  62. props: {
  63. userData: { type: Object },
  64. },
  65. emits: ['update', 'register'],
  66. setup(props, { emit }) {
  67. const modelRef = ref({});
  68. const numRef = ref(null);
  69. const fileFlow = reactive({
  70. showList: true,
  71. });
  72. const [registerDetail, { openModal: openDetaileModal }] = useModal();
  73. const columns: BasicColumn[] = [
  74. {
  75. title: '警员ID',
  76. dataIndex: 'ryId',
  77. width: 150,
  78. },
  79. {
  80. title: '姓名',
  81. dataIndex: 'ryNickName',
  82. width: 180,
  83. },
  84. {
  85. title: '查看权限',
  86. dataIndex: 'lookAuth',
  87. customRender: ({ record }) => {
  88. return record.lookAuth == 1 ? '不限时间' : record.lookAuth == 0 ? '无权' : `${dayjs(record.lookEndTime).format('YYYY-MM-DD HH:mm')} 截止`;
  89. },
  90. width: 150,
  91. },
  92. {
  93. title: '编辑权限',
  94. dataIndex: 'editAuth',
  95. customRender: ({ record }) => {
  96. return record.editAuth == 1 ? '不限时间' : record.editAuth == 0 ? '无权' : `${dayjs(record.editEndTime).format('YYYY-MM-DD HH:mm')} 截止`;
  97. },
  98. width: 150,
  99. },
  100. {
  101. title: '可授权他人',
  102. dataIndex: 'canLook',
  103. customRender: ({ record }) => {
  104. return record.canEditLook == 1 ? '编辑和查看' : record.canAuthLook == 1 ? '查看' : `无权`;
  105. },
  106. width: 120,
  107. },
  108. {
  109. title: '操作',
  110. dataIndex: 'action',
  111. slots: { customRender: 'action' },
  112. ifShow: true,
  113. fixed: 'right',
  114. flag: 'ACTION',
  115. width: 80,
  116. },
  117. ];
  118. const permissionStore = usePermissionStore();
  119. const userStore = useUserStore();
  120. const userName = computed(() => userStore.getUserInfo?.userName);
  121. const roleId = computed(() => userStore.getUserInfo?.roleId);
  122. const { getCheckPerm } = permissionStore;
  123. const { createMessage, createConfirm } = useMessage();
  124. const [registerTable, { reload, getRawDataSource }] = useTable({
  125. api: getAuthList,
  126. title: `已授权列表`,
  127. columns: columns,
  128. useSearchForm: false,
  129. immediate: false,
  130. searchInfo: {
  131. num: numRef,
  132. },
  133. // afterFetch: (T) => {
  134. // let { authType } = getRawDataSource();
  135. // setFieldsValue({
  136. // authType,
  137. // });
  138. // fileFlow.showList = authType ? false : true;
  139. // return T;
  140. // },
  141. showTableSetting: true,
  142. tableSetting: { fullScreen: true },
  143. showIndexColumn: false,
  144. canResize: true,
  145. rowKey: 'id',
  146. fetchSetting: {
  147. pageField: 'pageNum',
  148. sizeField: 'pageSize',
  149. listField: 'list',
  150. totalField: 'total',
  151. },
  152. });
  153. const schemas: FormSchema[] = [
  154. {
  155. field: 'authType',
  156. component: 'RadioGroup',
  157. defaultValue: 0,
  158. componentProps: {
  159. options: [
  160. { label: '授权用户', value: 0 },
  161. { label: '公开浏览', value: 1 },
  162. ],
  163. onChange: (value) => {
  164. fileFlow.showList = value.target.value ? false : true;
  165. console.log('fileFlow.showList', value.target.value, fileFlow.showList);
  166. },
  167. },
  168. label: '授权方式',
  169. colProps: {
  170. span: 24,
  171. },
  172. },
  173. ];
  174. const [registerForm, { validate, resetFields, setFieldsValue, updateSchema }] = useForm({
  175. labelWidth: 80,
  176. schemas,
  177. showActionButtonGroup: false,
  178. actionColOptions: {
  179. span: 24,
  180. },
  181. });
  182. onMounted(() => {});
  183. let addListFunc = () => {};
  184. const [register, { closeModal }] = useModalInner((data) => {
  185. data && onDataReceive(data);
  186. });
  187. async function onDataReceive(data) {
  188. modelRef.value = data;
  189. numRef.value = data.num;
  190. reload();
  191. resetFields();
  192. const { authType } = await getAuthType({num:numRef.value});;
  193. fileFlow.showList = authType ? false : true;
  194. setFieldsValue({
  195. type: data.sceneName,
  196. authType,
  197. });
  198. console.log('roleId', roleId.value, (userName.value != data.userName || roleId.value != 1 || roleId.value != 45));
  199. updateSchema({
  200. field: 'authType',
  201. componentProps: {
  202. disabled: !(userName.value == data.userName || roleId.value == 1 || roleId.value == 45),
  203. },
  204. });
  205. }
  206. const handleSubmit = async () => {
  207. try {
  208. const params = await validate();
  209. console.log('res', params);
  210. const res = await setAuthType({num:numRef.value,...params});
  211. console.log('res', res);
  212. closeModal();
  213. resetFields();
  214. createMessage.success('权限设置成功');
  215. emit('update');
  216. } catch (error) {
  217. console.log('not passing', error);
  218. }
  219. };
  220. function addPowes() {
  221. openDetaileModal(true, { num: modelRef.value.num});
  222. }
  223. function handleEdit(record: Recordable) {
  224. openDetaileModal(true, record);
  225. }
  226. async function handleDelete(record: Recordable) {
  227. createConfirm({
  228. title: '删除',
  229. content: `确定要删除 ${record.ryNickName} 吗?`,
  230. onOk: async () => {
  231. await delAuth({ id: record.id })
  232. createMessage.success('删除成功');
  233. reload();
  234. },
  235. });
  236. }
  237. return {
  238. register,
  239. schemas,
  240. registerForm,
  241. model: modelRef,
  242. fileFlow,
  243. handleSubmit,
  244. addListFunc,
  245. resetFields,
  246. t,
  247. getCheckPerm,
  248. handleEdit,
  249. handleDelete,
  250. registerTable,
  251. registerDetail,
  252. openDetaileModal,
  253. addPowes,
  254. reload,
  255. userName,
  256. };
  257. },
  258. });
  259. </script>
  260. <style lang="less" scoped>
  261. .powesrTable {
  262. }
  263. </style>